-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Pass registry URL to
npm
CLI with --registry
The environment variable `npm_config_registry` takes precedence to the registry configured in `.npmrc` when running `npm` commands. Yarn set this variable to `https://registry.yarnpkg.com` creating an `EINVALIDNPMTOKEN` error when running `semantic-release` with Yarn. Passing `--registry` with the value retrieved from `.npmrc` or `package.json` override the `npm_config_registry` set by Yarn.
- Loading branch information
Showing
7 changed files
with
82 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,12 @@ | ||
const execa = require('execa'); | ||
const getRegistry = require('./get-registry'); | ||
const updatePackageVersion = require('./update-package-version'); | ||
|
||
module.exports = async (version, logger) => { | ||
module.exports = async ({publishConfig, name}, version, logger) => { | ||
const registry = await getRegistry(publishConfig, name); | ||
await updatePackageVersion(version, logger); | ||
|
||
logger.log('Publishing version %s to npm registry', version); | ||
const shell = await execa('npm', ['publish']); | ||
const shell = await execa('npm', ['publish', '--registry', registry]); | ||
process.stdout.write(shell.stdout); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import test from 'ava'; | ||
import {appendFile} from 'fs-extra'; | ||
import tempy from 'tempy'; | ||
import getRegistry from '../lib/get-registry'; | ||
|
||
test.beforeEach(t => { | ||
// Save the current process.env | ||
t.context.env = Object.assign({}, process.env); | ||
// Save the current working diretory | ||
t.context.cwd = process.cwd(); | ||
// Change current working directory to a temp directory | ||
process.chdir(tempy.directory()); | ||
}); | ||
|
||
test.afterEach.always(t => { | ||
// Restore the current working directory | ||
process.chdir(t.context.cwd); | ||
}); | ||
|
||
test.serial('Get default registry', async t => { | ||
const registry = await getRegistry({}, 'package-name'); | ||
|
||
t.is(registry, 'https://registry.npmjs.org/'); | ||
}); | ||
|
||
test.serial('Get the registry configured in ".npmrc" and normalize trailing slash', async t => { | ||
await appendFile('./.npmrc', 'registry = https://custom1.registry.com'); | ||
const registry = await getRegistry({}, 'package-name'); | ||
|
||
t.is(registry, 'https://custom1.registry.com/'); | ||
}); | ||
|
||
test.serial('Get the registry configured from "publishConfig"', async t => { | ||
const registry = await getRegistry({registry: 'https://custom2.registry.com/'}, 'package-name'); | ||
|
||
t.is(registry, 'https://custom2.registry.com/'); | ||
}); | ||
|
||
test.serial('Get the registry configured in ".npmrc" for scoped package', async t => { | ||
await appendFile('./.npmrc', '@scope:registry = https://custom3.registry.com'); | ||
const registry = await getRegistry({}, '@scope/package-name'); | ||
|
||
t.is(registry, 'https://custom3.registry.com/'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters