@@ -2,6 +2,12 @@ import { execa } from "execa";
22import normalizeUrl from "normalize-url" ;
33import AggregateError from "aggregate-error" ;
44import getRegistry from "./get-registry.js" ;
5+ import setNpmrcAuth from "./set-npmrc-auth.js" ;
6+ import getError from "./get-error.js" ;
7+
8+ function registryIsDefault ( registry , DEFAULT_NPM_REGISTRY ) {
9+ return normalizeUrl ( registry ) === normalizeUrl ( DEFAULT_NPM_REGISTRY ) ;
10+ }
511
612export default async function ( npmrc , pkg , context ) {
713 const {
@@ -14,7 +20,7 @@ export default async function (npmrc, pkg, context) {
1420
1521 // await setNpmrcAuth(npmrc, registry, context);
1622
17- if ( normalizeUrl ( registry ) === normalizeUrl ( DEFAULT_NPM_REGISTRY ) ) {
23+ if ( registryIsDefault ( registry , DEFAULT_NPM_REGISTRY ) ) {
1824 // try {
1925 const publishDryRunResult = execa ( "npm" , [ "publish" , "--dry-run" , "--tag=semantic-release-auth-check" ] , { cwd, env, preferLocal : true , lines : true } ) ;
2026 // const whoamiResult = execa("npm", ["whoami", "--userconfig", npmrc, "--registry", registry], {
@@ -27,14 +33,14 @@ export default async function (npmrc, pkg, context) {
2733 // await whoamiResult;
2834 publishDryRunResult . stdout . pipe ( stdout , { end : false } ) ;
2935 publishDryRunResult . stderr . pipe ( stderr , { end : false } ) ;
30- const { stderr : execaStderr } = await publishDryRunResult ;
31- execaStderr . forEach ( ( line ) => {
32- if ( line . includes ( "This command requires you to be logged in to https://registry.npmjs.org/ " ) ) {
33- throw new AggregateError ( [ new Error ( 'no auth context' ) ] ) ;
36+
37+ ( await publishDryRunResult ) . stderr . forEach ( ( line ) => {
38+ if ( line . includes ( "This command requires you to be logged in to " ) ) {
39+ throw new AggregateError ( [ getError ( "EINVALIDNPMAUTH" ) ] ) ;
3440 }
3541 } )
3642 // } catch {
37- // throw new AggregateError([getError("EINVALIDNPMTOKEN ", { registry })]);
43+ // throw new AggregateError([getError("EINVALIDNPMAUTH ", { registry })]);
3844 // }
3945 }
4046}
0 commit comments