Files
actions-ansi-to-html/node_modules/@semantic-release/npm/lib/verify-auth.js
T
2025-11-11 06:53:11 -05:00

34 lines
1.0 KiB
JavaScript

const execa = require('execa');
const normalizeUrl = require('normalize-url');
const AggregateError = require('aggregate-error');
const getError = require('./get-error');
const getRegistry = require('./get-registry');
const setNpmrcAuth = require('./set-npmrc-auth');
module.exports = async (npmrc, pkg, context) => {
const {
cwd,
env: {DEFAULT_NPM_REGISTRY = 'https://registry.npmjs.org/', ...env},
stdout,
stderr,
} = context;
const registry = getRegistry(pkg, context);
await setNpmrcAuth(npmrc, registry, context);
if (normalizeUrl(registry) === normalizeUrl(DEFAULT_NPM_REGISTRY)) {
try {
const whoamiResult = execa('npm', ['whoami', '--userconfig', npmrc, '--registry', registry], {
cwd,
env,
preferLocal: true,
});
whoamiResult.stdout.pipe(stdout, {end: false});
whoamiResult.stderr.pipe(stderr, {end: false});
await whoamiResult;
} catch {
throw new AggregateError([getError('EINVALIDNPMTOKEN', {registry})]);
}
}
};