File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -42,14 +42,32 @@ const getOptionalInput = (name: string) => core.getInput(name) || undefined;
4242 "No changesets found, attempting to publish any unpublished packages to npm"
4343 ) ;
4444
45- let npmrcPath = `${ process . env . HOME } /.npmrc` ;
46- if ( fs . existsSync ( npmrcPath ) ) {
47- console . log ( "Found existing .npmrc file" ) ;
45+ let userNpmrcPath = `${ process . env . HOME } /.npmrc` ;
46+ if ( fs . existsSync ( userNpmrcPath ) ) {
47+ console . log ( "Found existing user .npmrc file" ) ;
48+ const userNpmrcContent = await fs . readFile ( userNpmrcPath , "utf8" ) ;
49+ const authLine = userNpmrcContent . split ( "\n" ) . find ( ( line ) => {
50+ // check based on https://github.com/npm/cli/blob/8f8f71e4dd5ee66b3b17888faad5a7bf6c657eed/test/lib/adduser.js#L103-L105
51+ return / ^ \/ \/ r e g i s t r y \. n p m j s \. o r g \/ : [ _ - ] a u t h T o k e n = / i. test ( line ) ;
52+ } ) ;
53+ if ( authLine ) {
54+ console . log (
55+ "Found existing auth token for the npm registry in the user .npmrc file"
56+ ) ;
57+ } else {
58+ console . log (
59+ "Didn't find existing auth token for the npm registry in the user .npmrc file, creating one"
60+ ) ;
61+ fs . appendFileSync (
62+ userNpmrcPath ,
63+ `\n//registry.npmjs.org/:_authToken=${ process . env . NPM_TOKEN } \n`
64+ ) ;
65+ }
4866 } else {
49- console . log ( "No .npmrc file found, creating one" ) ;
67+ console . log ( "No user .npmrc file found, creating one" ) ;
5068 fs . writeFileSync (
51- npmrcPath ,
52- `//registry.npmjs.org/:_authToken=${ process . env . NPM_TOKEN } `
69+ userNpmrcPath ,
70+ `//registry.npmjs.org/:_authToken=${ process . env . NPM_TOKEN } \n `
5371 ) ;
5472 }
5573
You can’t perform that action at this time.
0 commit comments