Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0126704

Browse files
committed
feat: allow to configure the registry viaNPM_CONFIG_REGISTRY
1 parent07247ca commit0126704

File tree

3 files changed

+24
-13
lines changed

3 files changed

+24
-13
lines changed

‎README.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@ Use either `NPM_TOKEN` for token authentication or `NPM_USERNAME`, `NPM_PASSWORD
7272

7373
The plugin uses the[`npm` CLI](https://github.com/npm/cli) which will read the configuration from[`.npmrc`](https://docs.npmjs.com/files/npmrc). See[`npm config`](https://docs.npmjs.com/misc/config) for the option list.
7474

75-
The[`registry`](https://docs.npmjs.com/misc/registry) and[`dist-tag`](https://docs.npmjs.com/cli/dist-tag) can be configured in the`package.json` and will take precedence over the configuration in`.npmrc`:
75+
The[`registry`](https://docs.npmjs.com/misc/registry) can be configured via the npm environment variable`NPM_CONFIG_REGISTRY` and will take precedence over the configuration in`.npmrc`.
76+
77+
The[`registry`](https://docs.npmjs.com/misc/registry) and[`dist-tag`](https://docs.npmjs.com/cli/dist-tag) can be configured in the`package.json` and will take precedence over the configuration in`.npmrc` and`NPM_CONFIG_REGISTRY`:
7678
```json
7779
{
7880
"publishConfig": {

‎lib/get-registry.js‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ const path = require('path');
22
constrc=require('rc');
33
constgetRegistryUrl=require('registry-auth-token/registry-url');
44

5-
module.exports=({publishConfig:{registry}={}, name},{cwd})=>
6-
registry
7-
?registry
8-
:getRegistryUrl(
9-
name.split('/')[0],
10-
rc('npm',{registry:'https://registry.npmjs.org/'},{config:path.resolve(cwd,'.npmrc')})
11-
);
5+
module.exports=({publishConfig:{registry}={}, name},{cwd, env})=>
6+
registry||
7+
env.NPM_CONFIG_REGISTRY||
8+
getRegistryUrl(
9+
name.split('/')[0],
10+
rc('npm',{registry:'https://registry.npmjs.org/'},{config:path.resolve(cwd,'.npmrc')})
11+
);

‎test/get-registry.test.js‎

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,39 @@ import getRegistry from '../lib/get-registry';
66

77
test('Get default registry',t=>{
88
constcwd=tempy.directory();
9-
t.is(getRegistry({name:'package-name'},{cwd}),'https://registry.npmjs.org/');
10-
t.is(getRegistry({name:'package-name',publishConfig:{}},{cwd}),'https://registry.npmjs.org/');
9+
t.is(getRegistry({name:'package-name'},{cwd,env:{}}),'https://registry.npmjs.org/');
10+
t.is(getRegistry({name:'package-name',publishConfig:{}},{cwd,env:{}}),'https://registry.npmjs.org/');
1111
});
1212

1313
test('Get the registry configured in ".npmrc" and normalize trailing slash',asynct=>{
1414
constcwd=tempy.directory();
1515
awaitappendFile(path.resolve(cwd,'.npmrc'),'registry = https://custom1.registry.com');
1616

17-
t.is(getRegistry({name:'package-name'},{cwd}),'https://custom1.registry.com/');
17+
t.is(getRegistry({name:'package-name'},{cwd,env:{}}),'https://custom1.registry.com/');
1818
});
1919

2020
test('Get the registry configured from "publishConfig"',asynct=>{
2121
constcwd=tempy.directory();
2222
awaitappendFile(path.resolve(cwd,'.npmrc'),'registry = https://custom2.registry.com');
2323

2424
t.is(
25-
getRegistry({name:'package-name',publishConfig:{registry:'https://custom3.registry.com/'}},{cwd}),
25+
getRegistry({name:'package-name',publishConfig:{registry:'https://custom3.registry.com/'}},{cwd,env:{}}),
2626
'https://custom3.registry.com/'
2727
);
2828
});
2929

30+
test('Get the registry configured in "NPM_CONFIG_REGISTRY"',t=>{
31+
constcwd=tempy.directory();
32+
33+
t.is(
34+
getRegistry({name:'package-name'},{cwd,env:{NPM_CONFIG_REGISTRY:'https://custom1.registry.com/'}}),
35+
'https://custom1.registry.com/'
36+
);
37+
});
38+
3039
test('Get the registry configured in ".npmrc" for scoped package',asynct=>{
3140
constcwd=tempy.directory();
3241
awaitappendFile(path.resolve(cwd,'.npmrc'),'@scope:registry = https://custom3.registry.com');
3342

34-
t.is(getRegistry({name:'@scope/package-name'},{cwd}),'https://custom3.registry.com/');
43+
t.is(getRegistry({name:'@scope/package-name'},{cwd,env:{}}),'https://custom3.registry.com/');
3544
});

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp