Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix: set npm config to read NPM_AUTH_TOKEN (#923)
Co-authored-by: shipjs <shipjs@test.com>
  • Loading branch information
Eunjae Lee and shipjs committed Sep 10, 2020
1 parent de3df55 commit 1c935a3
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
29 changes: 25 additions & 4 deletions packages/shipjs/src/step/release/__tests__/runPublish.spec.js
Expand Up @@ -19,8 +19,15 @@ describe('runPublish', () => {
dir: '.',
dryRun: false,
});
expect(run).toHaveBeenCalledTimes(1);
expect(run).toHaveBeenCalledTimes(2);
expect(run.mock.calls[0][0]).toMatchInlineSnapshot(`
Object {
"command": "npm config set \\"//registry.npmjs.org/:_authToken\\" \\"\\\\\${NPM_AUTH_TOKEN}\\"",
"dir": ".",
"dryRun": false,
}
`);
expect(run.mock.calls[1][0]).toMatchInlineSnapshot(`
Object {
"command": "npm_config_registry=https://registry.npmjs.org/ npm publish --tag latest",
"dir": ".",
Expand All @@ -39,8 +46,15 @@ describe('runPublish', () => {
dir: '.',
dryRun: false,
});
expect(run).toHaveBeenCalledTimes(1);
expect(run).toHaveBeenCalledTimes(2);
expect(run.mock.calls[0][0]).toMatchInlineSnapshot(`
Object {
"command": "npm config set \\"//registry.npmjs.org/:_authToken\\" \\"\\\\\${NPM_AUTH_TOKEN}\\"",
"dir": ".",
"dryRun": false,
}
`);
expect(run.mock.calls[1][0]).toMatchInlineSnapshot(`
Object {
"command": "npm publish --tag latest",
"dir": ".",
Expand Down Expand Up @@ -73,15 +87,22 @@ describe('runPublish', () => {
"Running the following at /package-b",
]
`);
expect(run).toHaveBeenCalledTimes(2);
expect(run).toHaveBeenCalledTimes(3);
expect(run.mock.calls[0][0]).toMatchInlineSnapshot(`
Object {
"command": "npm config set \\"//registry.npmjs.org/:_authToken\\" \\"\\\\\${NPM_AUTH_TOKEN}\\"",
"dir": ".",
"dryRun": false,
}
`);
expect(run.mock.calls[1][0]).toMatchInlineSnapshot(`
Object {
"command": "npm_config_registry=https://registry.npmjs.org/ npm publish --tag latest",
"dir": "/package-a",
"dryRun": false,
}
`);
expect(run.mock.calls[1][0]).toMatchInlineSnapshot(`
expect(run.mock.calls[2][0]).toMatchInlineSnapshot(`
Object {
"command": "npm_config_registry=https://registry.npmjs.org/ npm publish --tag latest",
"dir": "/package-b",
Expand Down
8 changes: 8 additions & 0 deletions packages/shipjs/src/step/release/runPublish.js
Expand Up @@ -8,6 +8,14 @@ export default ({ isYarn, config, releaseTag: tag, dir, dryRun }) =>
runStep({ title: 'Publishing.' }, () => {
const { publishCommand, monorepo } = config;

// This adds the following line to ~/.npmrc
// > registry.npmjs.org/:_authToken=${NPM_AUTH_TOKEN}
run({
command: `npm config set "//registry.npmjs.org/:_authToken" "\\\${NPM_AUTH_TOKEN}"`,
dir,
dryRun,
});

if (monorepo) {
const { packagesToPublish } = monorepo;
const packageList = expandPackageList(packagesToPublish, dir);
Expand Down

0 comments on commit 1c935a3

Please sign in to comment.