Skip to content

Commit 1c935a3

Browse files
Eunjae Leeshipjs
andauthored
fix: set npm config to read NPM_AUTH_TOKEN (#923)
Co-authored-by: shipjs <shipjs@test.com>
1 parent de3df55 commit 1c935a3

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed

packages/shipjs/src/step/release/__tests__/runPublish.spec.js

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,15 @@ describe('runPublish', () => {
1919
dir: '.',
2020
dryRun: false,
2121
});
22-
expect(run).toHaveBeenCalledTimes(1);
22+
expect(run).toHaveBeenCalledTimes(2);
2323
expect(run.mock.calls[0][0]).toMatchInlineSnapshot(`
24+
Object {
25+
"command": "npm config set \\"//registry.npmjs.org/:_authToken\\" \\"\\\\\${NPM_AUTH_TOKEN}\\"",
26+
"dir": ".",
27+
"dryRun": false,
28+
}
29+
`);
30+
expect(run.mock.calls[1][0]).toMatchInlineSnapshot(`
2431
Object {
2532
"command": "npm_config_registry=https://registry.npmjs.org/ npm publish --tag latest",
2633
"dir": ".",
@@ -39,8 +46,15 @@ describe('runPublish', () => {
3946
dir: '.',
4047
dryRun: false,
4148
});
42-
expect(run).toHaveBeenCalledTimes(1);
49+
expect(run).toHaveBeenCalledTimes(2);
4350
expect(run.mock.calls[0][0]).toMatchInlineSnapshot(`
51+
Object {
52+
"command": "npm config set \\"//registry.npmjs.org/:_authToken\\" \\"\\\\\${NPM_AUTH_TOKEN}\\"",
53+
"dir": ".",
54+
"dryRun": false,
55+
}
56+
`);
57+
expect(run.mock.calls[1][0]).toMatchInlineSnapshot(`
4458
Object {
4559
"command": "npm publish --tag latest",
4660
"dir": ".",
@@ -73,15 +87,22 @@ describe('runPublish', () => {
7387
"Running the following at /package-b",
7488
]
7589
`);
76-
expect(run).toHaveBeenCalledTimes(2);
90+
expect(run).toHaveBeenCalledTimes(3);
7791
expect(run.mock.calls[0][0]).toMatchInlineSnapshot(`
92+
Object {
93+
"command": "npm config set \\"//registry.npmjs.org/:_authToken\\" \\"\\\\\${NPM_AUTH_TOKEN}\\"",
94+
"dir": ".",
95+
"dryRun": false,
96+
}
97+
`);
98+
expect(run.mock.calls[1][0]).toMatchInlineSnapshot(`
7899
Object {
79100
"command": "npm_config_registry=https://registry.npmjs.org/ npm publish --tag latest",
80101
"dir": "/package-a",
81102
"dryRun": false,
82103
}
83104
`);
84-
expect(run.mock.calls[1][0]).toMatchInlineSnapshot(`
105+
expect(run.mock.calls[2][0]).toMatchInlineSnapshot(`
85106
Object {
86107
"command": "npm_config_registry=https://registry.npmjs.org/ npm publish --tag latest",
87108
"dir": "/package-b",

packages/shipjs/src/step/release/runPublish.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ export default ({ isYarn, config, releaseTag: tag, dir, dryRun }) =>
88
runStep({ title: 'Publishing.' }, () => {
99
const { publishCommand, monorepo } = config;
1010

11+
// This adds the following line to ~/.npmrc
12+
// > registry.npmjs.org/:_authToken=${NPM_AUTH_TOKEN}
13+
run({
14+
command: `npm config set "//registry.npmjs.org/:_authToken" "\\\${NPM_AUTH_TOKEN}"`,
15+
dir,
16+
dryRun,
17+
});
18+
1119
if (monorepo) {
1220
const { packagesToPublish } = monorepo;
1321
const packageList = expandPackageList(packagesToPublish, dir);

0 commit comments

Comments
 (0)