如何为自己的 npm 注册表配置保存前缀

How to configure save-prefix for own npm registries

我有 save-prefix configured as per default to add '^' as version prefix. This works well for (unscoped and scoped) packages which I install from npmjs. However for packages which come from my own registry (verdaccio) 它没有附加前缀:

> npm install --save @my-scope/my-package
> cat package.json
...
"dependencies": {
  "@my-scope/my-package": "0.0.42",
}

我了解到,保存前缀是本地事物,不受注册表或 package.json 的影响。

我是否必须在本地为我的注册表配置保存前缀?如果是:how/where?

关于为什么我自己的注册表中的包没有预先添加“^”的任何其他想法?

我的 .npmrc 看起来像这样:

@oblamatik:registry=https://npm.dev.***********.ch
//npm.dev.oblamatik.ch/:_password="***************"
//npm.dev.oblamatik.ch/:username=ci
//npm.dev.oblamatik.ch/:email=ci@***********.ch
//npm.dev.oblamatik.ch/:always-auth=true

目前 npm 将 0.0.x 形式的版本视为无效的 SemVer (https://npm.community/t/save-prefix-is-not-prepended-for-major-version-0/4618).

我在错误报告中表达了我的不同意见,但现在的答案是:

不要将低于 0.1.0 的版本与 npm 一起使用。

尽管从 SemVer specification 2.0.0 开始它们是有效的 SemVer,但 npm 以不同的方式对待它们。作为参考,这是 npm 开发人员在其错误报告中发布的代码摘录:

if (isRegistry(requested)) {
    var version = child.package.version
    var rangeDescriptor = ''
    if (semver.valid(version, true) &&
        semver.gte(version, '0.1.0', true) &&
        !npm.config.get('save-exact')) {
      rangeDescriptor = npm.config.get('save-prefix')
    }
    return rangeDescriptor + version
}