This commit is contained in:
Sigurd Fosseng 2026-03-04 22:40:19 +00:00 committed by GitHub
commit e5cac72dab
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 11 additions and 8 deletions

View file

@ -123,7 +123,7 @@ describe('authutil tests', () => {
await auth.configAuthentication('https://registry.npmjs.org/');
const contents = fs.readFileSync(rcFile, {encoding: 'utf8'});
expect(contents).toBe(
`//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN}${os.EOL}registry=https://registry.npmjs.org/`
`//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN}${os.EOL}registry=https://registry.npmjs.org/${os.EOL}`
);
});
@ -132,7 +132,7 @@ describe('authutil tests', () => {
await auth.configAuthentication('https://registry.npmjs.org/');
const contents = fs.readFileSync(rcFile, {encoding: 'utf8'});
expect(contents).toBe(
`@myscope:registry=MMM${os.EOL}//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN}${os.EOL}registry=https://registry.npmjs.org/`
`@myscope:registry=MMM${os.EOL}//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN}${os.EOL}registry=https://registry.npmjs.org/${os.EOL}`
);
});
@ -141,7 +141,7 @@ describe('authutil tests', () => {
await auth.configAuthentication('https://registry.npmjs.org/');
const contents = fs.readFileSync(rcFile, {encoding: 'utf8'});
expect(contents).toBe(
`@myscope:registry=NNN${os.EOL}//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN}${os.EOL}registry=https://registry.npmjs.org/`
`@myscope:registry=NNN${os.EOL}//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN}${os.EOL}registry=https://registry.npmjs.org/${os.EOL}`
);
});
@ -151,7 +151,7 @@ describe('authutil tests', () => {
await auth.configAuthentication('https://registry.npmjs.org/');
const contents = fs.readFileSync(rcFile, {encoding: 'utf8'});
expect(contents).toBe(
`//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN}${os.EOL}@myscope:registry=https://registry.npmjs.org/`
`//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN}${os.EOL}@myscope:registry=https://registry.npmjs.org/${os.EOL}`
);
});
@ -161,7 +161,7 @@ describe('authutil tests', () => {
await auth.configAuthentication('https://registry.npmjs.org/');
const contents = fs.readFileSync(rcFile, {encoding: 'utf8'});
expect(contents).toBe(
`registry=NNN${os.EOL}//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN}${os.EOL}@myscope:registry=https://registry.npmjs.org/`
`registry=NNN${os.EOL}//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN}${os.EOL}@myscope:registry=https://registry.npmjs.org/${os.EOL}`
);
});
@ -171,7 +171,7 @@ describe('authutil tests', () => {
await auth.configAuthentication('https://registry.npmjs.org/');
const contents = fs.readFileSync(rcFile, {encoding: 'utf8'});
expect(contents).toBe(
`registry=MMM${os.EOL}//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN}${os.EOL}@myscope:registry=https://registry.npmjs.org/`
`registry=MMM${os.EOL}//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN}${os.EOL}@myscope:registry=https://registry.npmjs.org/${os.EOL}`
);
});
@ -184,7 +184,7 @@ describe('authutil tests', () => {
await auth.configAuthentication('https://registry.npmjs.org/');
const contents = fs.readFileSync(rcFile, {encoding: 'utf8'});
expect(contents).toBe(
`@otherscope:registry=NNN${os.EOL}//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN}${os.EOL}@myscope:registry=https://registry.npmjs.org/`
`@otherscope:registry=NNN${os.EOL}//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN}${os.EOL}@myscope:registry=https://registry.npmjs.org/${os.EOL}`
);
});
@ -194,7 +194,7 @@ describe('authutil tests', () => {
await auth.configAuthentication('https://registry.npmjs.org/');
const contents = fs.readFileSync(rcFile, {encoding: 'utf8'});
expect(contents).toBe(
`@otherscope:registry=MMM${os.EOL}//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN}${os.EOL}@myscope:registry=https://registry.npmjs.org/`
`@otherscope:registry=MMM${os.EOL}//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN}${os.EOL}@myscope:registry=https://registry.npmjs.org/${os.EOL}`
);
});
});

View file

@ -44,6 +44,9 @@ function writeRegistryToFile(registryUrl: string, fileLocation: string) {
registryUrl.replace(/(^\w+:|^)/, '') + ':_authToken=${NODE_AUTH_TOKEN}';
const registryString = `${scope}registry=${registryUrl}`;
newContents += `${authString}${os.EOL}${registryString}`;
if (newContents && !newContents.endsWith(os.EOL)) {
newContents += os.EOL;
}
fs.writeFileSync(fileLocation, newContents);
core.exportVariable('NPM_CONFIG_USERCONFIG', fileLocation);
// Export empty node_auth_token if didn't exist so npm doesn't complain about not being able to find it