Skip to content

Commit

Permalink
fix: log the path of existing .npmrc files
Browse files Browse the repository at this point in the history
  • Loading branch information
pvdlg committed Nov 2, 2019
1 parent 6189ee7 commit a0120d2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
5 changes: 5 additions & 0 deletions lib/set-npmrc-auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ module.exports = async (
{registry: 'https://registry.npmjs.org/'},
{config: NPM_CONFIG_USERCONFIG || path.resolve(cwd, '.npmrc')}
);

if (configs) {
logger.log('Reading npm config from %s', configs.join(', '));
}

const currentConfig = configs ? (await Promise.all(configs.map(config => readFile(config)))).join('\n') : '';

if (getAuthToken(registry, {npmrc: rcConfig})) {
Expand Down
24 changes: 19 additions & 5 deletions test/set-npmrc-auth.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@ test.serial('Preserve home ".npmrc"', async t => {
await require('../lib/set-npmrc-auth')(npmrc, 'http://custom.registry.com', {cwd, env, logger: t.context.logger});

t.is((await readFile(npmrc)).toString(), `home_config = test\n//custom.registry.com/:_authToken = \${NPM_TOKEN}`);
t.deepEqual(t.context.log.args[1], [`Wrote NPM_TOKEN to ${npmrc}`]);
t.deepEqual(t.context.log.args[1], [
'Reading npm config from %s',
[path.resolve(process.env.HOME, '.npmrc')].join(', '),
]);
t.deepEqual(t.context.log.args[2], [`Wrote NPM_TOKEN to ${npmrc}`]);
});

test.serial('Preserve home and local ".npmrc"', async t => {
Expand All @@ -79,7 +83,11 @@ test.serial('Preserve home and local ".npmrc"', async t => {
(await readFile(npmrc)).toString(),
`home_config = test\ncwd_config = test\n//custom.registry.com/:_authToken = \${NPM_TOKEN}`
);
t.deepEqual(t.context.log.args[1], [`Wrote NPM_TOKEN to ${npmrc}`]);
t.deepEqual(t.context.log.args[1], [
'Reading npm config from %s',
[path.resolve(process.env.HOME, '.npmrc'), path.resolve(cwd, '.npmrc')].join(', '),
]);
t.deepEqual(t.context.log.args[2], [`Wrote NPM_TOKEN to ${npmrc}`]);
});

test.serial('Preserve all ".npmrc" if auth is already configured', async t => {
Expand All @@ -94,7 +102,10 @@ test.serial('Preserve all ".npmrc" if auth is already configured', async t => {
await require('../lib/set-npmrc-auth')(npmrc, 'http://custom.registry.com', {cwd, env: {}, logger: t.context.logger});

t.is((await readFile(npmrc)).toString(), `home_config = test\n//custom.registry.com/:_authToken = \${NPM_TOKEN}`);
t.is(t.context.log.callCount, 1);
t.deepEqual(t.context.log.args[1], [
'Reading npm config from %s',
[path.resolve(process.env.HOME, '.npmrc'), path.resolve(cwd, '.npmrc')].join(', '),
]);
});

test.serial('Preserve ".npmrc" if auth is already configured for a scoped package', async t => {
Expand All @@ -115,7 +126,10 @@ test.serial('Preserve ".npmrc" if auth is already configured for a scoped packag
(await readFile(npmrc)).toString(),
`home_config = test\n@scope:registry=http://custom.registry.com\n//custom.registry.com/:_authToken = \${NPM_TOKEN}`
);
t.is(t.context.log.callCount, 1);
t.deepEqual(t.context.log.args[1], [
'Reading npm config from %s',
[path.resolve(process.env.HOME, '.npmrc'), path.resolve(cwd, '.npmrc')].join(', '),
]);
});

test.serial('Throw error if "NPM_TOKEN" is missing', async t => {
Expand Down Expand Up @@ -148,7 +162,7 @@ test.serial('Emulate npm config resolution if "NPM_CONFIG_USERCONFIG" is set', a
});

t.is((await readFile(npmrc)).toString(), `//custom.registry.com/:_authToken = \${NPM_TOKEN}`);
t.is(t.context.log.callCount, 1);
t.deepEqual(t.context.log.args[1], ['Reading npm config from %s', [path.resolve(cwd, '.custom-npmrc')].join(', ')]);
});

test.serial('Throw error if "NPM_USERNAME" is missing', async t => {
Expand Down

0 comments on commit a0120d2

Please sign in to comment.