Skip to content

Commit

Permalink
fix: avoid adding unnecessary new line to .npmrc
Browse files Browse the repository at this point in the history
  • Loading branch information
pvdlg committed Nov 2, 2019
1 parent de677ea commit 6189ee7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 8 additions & 2 deletions lib/set-npmrc-auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,16 @@ module.exports = async (
}

if (NPM_USERNAME && NPM_PASSWORD && NPM_EMAIL) {
await outputFile(npmrc, `${currentConfig}\n_auth = \${LEGACY_TOKEN}\nemail = \${NPM_EMAIL}`);
await outputFile(
npmrc,
`${currentConfig ? `${currentConfig}\n` : ''}_auth = \${LEGACY_TOKEN}\nemail = \${NPM_EMAIL}`
);
logger.log(`Wrote NPM_USERNAME, NPM_PASSWORD and NPM_EMAIL to ${npmrc}`);
} else if (NPM_TOKEN) {
await outputFile(npmrc, `${currentConfig}\n${nerfDart(registry)}:_authToken = \${NPM_TOKEN}`);
await outputFile(
npmrc,
`${currentConfig ? `${currentConfig}\n` : ''}${nerfDart(registry)}:_authToken = \${NPM_TOKEN}`
);
logger.log(`Wrote NPM_TOKEN to ${npmrc}`);
} else {
throw new AggregateError([getError('ENONPMTOKEN', {registry})]);
Expand Down
2 changes: 1 addition & 1 deletion test/set-npmrc-auth.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ test.serial('Set auth with "NPM_USERNAME", "NPM_PASSWORD" and "NPM_EMAIL"', asyn

await require('../lib/set-npmrc-auth')(npmrc, 'http://custom.registry.com', {cwd, env, logger: t.context.logger});

t.is((await readFile(npmrc)).toString(), `\n_auth = \${LEGACY_TOKEN}\nemail = \${NPM_EMAIL}`);
t.is((await readFile(npmrc)).toString(), `_auth = \${LEGACY_TOKEN}\nemail = \${NPM_EMAIL}`);
t.deepEqual(t.context.log.args[1], [`Wrote NPM_USERNAME, NPM_PASSWORD and NPM_EMAIL to ${npmrc}`]);
});

Expand Down

0 comments on commit 6189ee7

Please sign in to comment.