Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: set npm config to read NPM_AUTH_TOKEN #923

Merged
merged 1 commit into from Sep 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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