5

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
gyc
  • 3,986
  • 4
  • 29
  • 42
Michael K
  • 683
  • 1
  • 4
  • 20
  • Does it work for a non-`0.x` package from your own registry? – ᆼᆺᆼ Jan 11 '19 at 10:37
  • I had to create one as we are still in early development. But, yes, for non-0.x packages this works. Any information on why that is the case? – Michael K Jan 14 '19 at 12:44
  • I think you might want to raise a bug with npm. The prefix behaviour is different for 0.x and that's either wrong or if intentional the docs should mention this. – ᆼᆺᆼ Jan 14 '19 at 12:48
  • Posted it here, so everyone feel free to take part in that discussion: https://npm.community/t/save-prefix-is-not-prepended-for-major-version-0/4618 – Michael K Jan 15 '19 at 05:32

1 Answers1

3

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
}
Michael K
  • 683
  • 1
  • 4
  • 20