-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: verify authentication for default npm registry only
- Loading branch information
Showing
3 changed files
with
31 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,25 @@ | ||
const execa = require('execa'); | ||
const normalizeUrl = require('normalize-url'); | ||
const SemanticReleaseError = require('@semantic-release/error'); | ||
const getRegistry = require('./get-registry'); | ||
const setNpmrcAuth = require('./set-npmrc-auth'); | ||
|
||
module.exports = async (pluginConfig, pkg, logger) => { | ||
const DEFAULT_NPM_REGISTRY = 'https://registry.npmjs.org/'; | ||
|
||
module.exports = async ( | ||
pluginConfig, | ||
pkg, | ||
logger, | ||
defaultRegistry = process.env.DEFAULT_NPM_REGISTRY || DEFAULT_NPM_REGISTRY | ||
) => { | ||
const registry = await getRegistry(pkg.publishConfig, pkg.name); | ||
await setNpmrcAuth(registry, logger); | ||
try { | ||
await execa('npm', ['whoami', '--registry', registry]); | ||
} catch (err) { | ||
throw new SemanticReleaseError('Invalid npm token.', 'EINVALIDNPMTOKEN'); | ||
|
||
if (normalizeUrl(registry) === normalizeUrl(defaultRegistry)) { | ||
try { | ||
await execa('npm', ['whoami', '--registry', registry]); | ||
} catch (err) { | ||
throw new SemanticReleaseError('Invalid npm token.', 'EINVALIDNPMTOKEN'); | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters