npmrc 同一范围的多个注册表
npmrc multiple registries for the same scope
是否可以为同一范围包含多个注册表?在我的公司,我们对 public NPM 注册表和内部注册表都使用 @mycompany
范围。
我试过
@mycompany:registry=https://company.registry.com
@mycompany:registry=https://registry.npmjs.org
但这没有用。
不,你不能。不幸的是 npm
只能处理一个作用域对等注册表。但是您可以使用代理作为 Verdaccio 来为您处理分发。
https://verdaccio.org/docs/en/uplinks
我将使用 Verdaccio:
模拟一个配置示例
我嘲笑了一个没有外部访问权限的 "company registry" (http://localhost:5000/)。
storage: /Users/test/.local/share/verdaccio/storage_company_registry
auth:
htpasswd:
file: ./htpasswd
packages:
'@*/*':
access: $all
publish: $authenticated
'**':
access: $all
publish: $all
middlewares:
audit:
enabled: true
logs:
- {type: stdout, format: pretty, level: http}
如您所见,没有配置遥控器(上行链路),它完全处于离线状态。
然后我会 运行 我的建议,Verdaccio (http://localhost:4873/) 首先询问公司注册处,如果在那里找不到包,它将从 public 注册处获取(npmjs).
storage: /Users/test/.local/share/verdaccio/storage_proxy
auth:
htpasswd:
file: ./htpasswd
uplinks:
npmjs:
url: https://registry.npmjs.org/
company:
url: https://company.registry.com
packages:
'@company/*':
access: $all
publish: $authenticated
proxy: company npmjs
'**':
access: $all
publish: $authenticated
proxy: npmjs
middlewares:
audit:
enabled: true
logs:
- {type: stdout, format: pretty, level: http}
作为 PoC(我正在通过 @babel 切换@company)我 运行 npm install @babel/types --registry http://localhost:4873/
。结果如下
warn --- config file - /Users/test/.config/verdaccio/config.yaml
warn --- Plugin successfully loaded: htpasswd
warn --- Plugin successfully loaded: audit
warn --- http address - http://localhost:4873/ - verdaccio/4.0.0-alpha.4
http --> 404, req: 'GET http://localhost:5000/@babel%2Ftypes' (streaming)
http --> 404, req: 'GET http://localhost:5000/@babel%2Ftypes', bytes: 0/43
http --> 200, req: 'GET https://registry.npmjs.org/@babel%2Ftypes' (streaming)
http --> 200, req: 'GET https://registry.npmjs.org/@babel%2Ftypes', bytes: 0/93375
http <-- 200, user: null(127.0.0.1), req: 'GET /@babel%2ftypes', bytes: 0/22072
http --> 200, req: 'GET https://registry.npmjs.org/esutils' (streaming)
http --> 200, req: 'GET https://registry.npmjs.org/esutils', bytes: 0/23169
http <-- 200, user: null(127.0.0.1), req: 'GET /esutils', bytes: 0/3854
http --> 200, req: 'GET https://registry.npmjs.org/to-fast-properties' (streaming)
http --> 200, req: 'GET https://registry.npmjs.org/to-fast-properties', bytes: 0/8239
http <-- 200, user: null(127.0.0.1), req: 'GET /to-fast-properties', bytes: 0/1725
http --> 200, req: 'GET https://registry.npmjs.org/lodash' (streaming)
http --> 200, req: 'GET https://registry.npmjs.org/lodash', bytes: 0/185410
http <-- 200, user: null(127.0.0.1), req: 'GET /lodash', bytes: 0/14307
http <-- 200, user: null(127.0.0.1), req: 'POST /-/npm/v1/security/audits/quick', bytes: 474/146
您的节点包管理器将与 (http://localhost:4873/) 交谈,Verdaccio 将尝试从内部注册表中获取包,结果为 404,在第二次迭代中将从 npmjs 中获取包,从而导致200.
拥有代理注册表可以使您的团队的流程更加透明,一切都集中且更有效率,ihmo。
希望对您有所帮助。
是否可以为同一范围包含多个注册表?在我的公司,我们对 public NPM 注册表和内部注册表都使用 @mycompany
范围。
我试过
@mycompany:registry=https://company.registry.com
@mycompany:registry=https://registry.npmjs.org
但这没有用。
不,你不能。不幸的是 npm
只能处理一个作用域对等注册表。但是您可以使用代理作为 Verdaccio 来为您处理分发。
https://verdaccio.org/docs/en/uplinks
我将使用 Verdaccio:
模拟一个配置示例我嘲笑了一个没有外部访问权限的 "company registry" (http://localhost:5000/)。
storage: /Users/test/.local/share/verdaccio/storage_company_registry
auth:
htpasswd:
file: ./htpasswd
packages:
'@*/*':
access: $all
publish: $authenticated
'**':
access: $all
publish: $all
middlewares:
audit:
enabled: true
logs:
- {type: stdout, format: pretty, level: http}
如您所见,没有配置遥控器(上行链路),它完全处于离线状态。
然后我会 运行 我的建议,Verdaccio (http://localhost:4873/) 首先询问公司注册处,如果在那里找不到包,它将从 public 注册处获取(npmjs).
storage: /Users/test/.local/share/verdaccio/storage_proxy
auth:
htpasswd:
file: ./htpasswd
uplinks:
npmjs:
url: https://registry.npmjs.org/
company:
url: https://company.registry.com
packages:
'@company/*':
access: $all
publish: $authenticated
proxy: company npmjs
'**':
access: $all
publish: $authenticated
proxy: npmjs
middlewares:
audit:
enabled: true
logs:
- {type: stdout, format: pretty, level: http}
作为 PoC(我正在通过 @babel 切换@company)我 运行 npm install @babel/types --registry http://localhost:4873/
。结果如下
warn --- config file - /Users/test/.config/verdaccio/config.yaml
warn --- Plugin successfully loaded: htpasswd
warn --- Plugin successfully loaded: audit
warn --- http address - http://localhost:4873/ - verdaccio/4.0.0-alpha.4
http --> 404, req: 'GET http://localhost:5000/@babel%2Ftypes' (streaming)
http --> 404, req: 'GET http://localhost:5000/@babel%2Ftypes', bytes: 0/43
http --> 200, req: 'GET https://registry.npmjs.org/@babel%2Ftypes' (streaming)
http --> 200, req: 'GET https://registry.npmjs.org/@babel%2Ftypes', bytes: 0/93375
http <-- 200, user: null(127.0.0.1), req: 'GET /@babel%2ftypes', bytes: 0/22072
http --> 200, req: 'GET https://registry.npmjs.org/esutils' (streaming)
http --> 200, req: 'GET https://registry.npmjs.org/esutils', bytes: 0/23169
http <-- 200, user: null(127.0.0.1), req: 'GET /esutils', bytes: 0/3854
http --> 200, req: 'GET https://registry.npmjs.org/to-fast-properties' (streaming)
http --> 200, req: 'GET https://registry.npmjs.org/to-fast-properties', bytes: 0/8239
http <-- 200, user: null(127.0.0.1), req: 'GET /to-fast-properties', bytes: 0/1725
http --> 200, req: 'GET https://registry.npmjs.org/lodash' (streaming)
http --> 200, req: 'GET https://registry.npmjs.org/lodash', bytes: 0/185410
http <-- 200, user: null(127.0.0.1), req: 'GET /lodash', bytes: 0/14307
http <-- 200, user: null(127.0.0.1), req: 'POST /-/npm/v1/security/audits/quick', bytes: 474/146
您的节点包管理器将与 (http://localhost:4873/) 交谈,Verdaccio 将尝试从内部注册表中获取包,结果为 404,在第二次迭代中将从 npmjs 中获取包,从而导致200.
拥有代理注册表可以使您的团队的流程更加透明,一切都集中且更有效率,ihmo。
希望对您有所帮助。