Skip to content

Commit d06286d

Browse files
Merge pull request #205 from zodman/main
Check for NODE_AUTH_TOKEN overwritten
2 parents 27082ce + d8c1b59 commit d06286d

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

__tests__/authutil.test.ts

+9
Original file line numberDiff line numberDiff line change
@@ -123,4 +123,13 @@ describe('authutil tests', () => {
123123
expect(rc['registry']).toBe('https://registry.npmjs.org/');
124124
expect(rc['always-auth']).toBe('true');
125125
});
126+
it('It is already set the NODE_AUTH_TOKEN export it ', async () => {
127+
process.env.NODE_AUTH_TOKEN = 'foobar';
128+
await auth.configAuthentication('npm.pkg.github.com', 'false');
129+
expect(fs.statSync(rcFile)).toBeDefined();
130+
let rc = readRcFile(rcFile);
131+
expect(rc['@ownername:registry']).toBe('npm.pkg.github.com/');
132+
expect(rc['always-auth']).toBe('false');
133+
expect(process.env.NODE_AUTH_TOKEN).toEqual('foobar');
134+
});
126135
});

dist/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -4803,8 +4803,8 @@ function writeRegistryToFile(registryUrl, fileLocation, alwaysAuth) {
48034803
newContents += `${authString}${os.EOL}${registryString}${os.EOL}${alwaysAuthString}`;
48044804
fs.writeFileSync(fileLocation, newContents);
48054805
core.exportVariable('NPM_CONFIG_USERCONFIG', fileLocation);
4806-
// Export empty node_auth_token so npm doesn't complain about not being able to find it
4807-
core.exportVariable('NODE_AUTH_TOKEN', 'XXXXX-XXXXX-XXXXX-XXXXX');
4806+
// Export empty node_auth_token if didn't exist so npm doesn't complain about not being able to find it
4807+
core.exportVariable('NODE_AUTH_TOKEN', process.env.NODE_AUTH_TOKEN || 'XXXXX-XXXXX-XXXXX-XXXXX');
48084808
}
48094809
//# sourceMappingURL=authutil.js.map
48104810

src/authutil.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ function writeRegistryToFile(
5353
newContents += `${authString}${os.EOL}${registryString}${os.EOL}${alwaysAuthString}`;
5454
fs.writeFileSync(fileLocation, newContents);
5555
core.exportVariable('NPM_CONFIG_USERCONFIG', fileLocation);
56-
// Export empty node_auth_token so npm doesn't complain about not being able to find it
57-
core.exportVariable('NODE_AUTH_TOKEN', 'XXXXX-XXXXX-XXXXX-XXXXX');
56+
// Export empty node_auth_token if didn't exist so npm doesn't complain about not being able to find it
57+
core.exportVariable(
58+
'NODE_AUTH_TOKEN',
59+
process.env.NODE_AUTH_TOKEN || 'XXXXX-XXXXX-XXXXX-XXXXX'
60+
);
5861
}

0 commit comments

Comments
 (0)