Skip to content

Commit 6189ee7

Browse files
committed
fix: avoid adding unnecessary new line to .npmrc
1 parent de677ea commit 6189ee7

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

lib/set-npmrc-auth.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,16 @@ module.exports = async (
2525
}
2626

2727
if (NPM_USERNAME && NPM_PASSWORD && NPM_EMAIL) {
28-
await outputFile(npmrc, `${currentConfig}\n_auth = \${LEGACY_TOKEN}\nemail = \${NPM_EMAIL}`);
28+
await outputFile(
29+
npmrc,
30+
`${currentConfig ? `${currentConfig}\n` : ''}_auth = \${LEGACY_TOKEN}\nemail = \${NPM_EMAIL}`
31+
);
2932
logger.log(`Wrote NPM_USERNAME, NPM_PASSWORD and NPM_EMAIL to ${npmrc}`);
3033
} else if (NPM_TOKEN) {
31-
await outputFile(npmrc, `${currentConfig}\n${nerfDart(registry)}:_authToken = \${NPM_TOKEN}`);
34+
await outputFile(
35+
npmrc,
36+
`${currentConfig ? `${currentConfig}\n` : ''}${nerfDart(registry)}:_authToken = \${NPM_TOKEN}`
37+
);
3238
logger.log(`Wrote NPM_TOKEN to ${npmrc}`);
3339
} else {
3440
throw new AggregateError([getError('ENONPMTOKEN', {registry})]);

test/set-npmrc-auth.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ test.serial('Set auth with "NPM_USERNAME", "NPM_PASSWORD" and "NPM_EMAIL"', asyn
4444

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

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

0 commit comments

Comments
 (0)