Skip to content

Commit 7e77057

Browse files
authored
Prefer --token over NPM_TOKEN (#1213)
1 parent 95b33fe commit 7e77057

3 files changed

Lines changed: 24 additions & 1 deletion

File tree

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"changes": [
3+
{
4+
"type": "patch",
5+
"comment": "Prefer `--token`/`-n` over `process.env.NPM_TOKEN`",
6+
"packageName": "beachball",
7+
"email": "elcraig@microsoft.com",
8+
"dependentChangeType": "patch"
9+
}
10+
]
11+
}

packages/beachball/src/__functional__/options/getCliOptions.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,16 @@ describe('getCliOptions', () => {
214214
expect(options).toEqual({ ...defaults, token: 'fake-token' });
215215
});
216216

217+
it('prefers CLI token over NPM_TOKEN environment variable', () => {
218+
const options = getCliOptionsTest(['--token', 'cli-token'], undefined, { NPM_TOKEN: 'env-token' });
219+
expect(options).toEqual({ ...defaults, token: 'cli-token' });
220+
});
221+
222+
it('prefers empty string CLI token over NPM_TOKEN environment variable', () => {
223+
const options = getCliOptionsTest(['--token', ''], undefined, { NPM_TOKEN: 'env-token' });
224+
expect(options).toEqual({ ...defaults, token: '' });
225+
});
226+
217227
describe('config command', () => {
218228
it('parses config get with setting name', () => {
219229
const options = getCliOptionsTest(['config', 'get', 'branch']);

packages/beachball/src/options/getCliOptions.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,9 @@ export function getCliOptions(processOrArgv: ProcessInfo | string[]): ParsedOpti
208208
cliOptions._extraPositionalArgs = extraPositionalArgs;
209209
}
210210

211-
if (processInfo.env.NPM_TOKEN) {
211+
// If both --token and NPM_TOKEN are provided, prefer the CLI token (could go either way, but
212+
// this is safer for compatibility in case anyone was already using that env name another way)
213+
if (processInfo.env.NPM_TOKEN && cliOptions.token === undefined) {
212214
cliOptions.token = processInfo.env.NPM_TOKEN;
213215
}
214216

0 commit comments

Comments
 (0)