npmverdaccio

How to configure save-prefix for own npm registries


I have 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) it does not append the prefix:

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

From this question I learned, that the save-prefix is a local thing and is not influenced by registry or package.json.

Do I have to locally configure the save-prefix for my registry? If so: how/where?

Any other ideas on why the '^' is not prepended for packages from my own registry?

My .npmrc looks like this:

@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

Solution

  • Currently npm treats versions of the form 0.0.x as not being a valid SemVer (https://npm.community/t/save-prefix-is-not-prepended-for-major-version-0/4618).

    I expressed my disagreement in that bug report, but for now, the answer is:

    Do not use versions below 0.1.0 with npm.

    Even though they are valid SemVer as of SemVer specification 2.0.0, npm treats them differently. For reference this is the code excerpt posted by the npm developer on their bug report:

    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
    }