Skip to content
This repository has been archived by the owner on Jan 20, 2022. It is now read-only.

Commit

Permalink
Do not save with ^ and no version
Browse files Browse the repository at this point in the history
Fix: npm/cli#2320

PR-URL: #192
Credit: @isaacs
Close: #192
Reviewed-by: @ruyadorno
  • Loading branch information
isaacs committed Dec 11, 2020
1 parent efb5d3e commit 8b457c2
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/arborist/reify.js
Original file line number Diff line number Diff line change
Expand Up @@ -808,7 +808,7 @@ module.exports = cls => class Reifier extends cls {

if (req.registry) {
const version = child.version
const prefixRange = this[_savePrefix] + version
const prefixRange = version ? this[_savePrefix] + version : '*'
// if we installed a range, then we save the range specified
// if it is not a subset of the ^x.y.z. eg, installing a range
// of `1.x <1.2.3` will not be saved as `^1.2.0`, because that
Expand Down
14 changes: 14 additions & 0 deletions tap-snapshots/test-arborist-reify.js-TAP.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27202,6 +27202,9 @@ Object {
"resolved": "https://registry.npmjs.org/c/-/c-1.2.3.tgz",
"version": "npm:[email protected]",
},
"e": Object {
"version": "file:e",
},
},
"lockfileVersion": 2,
"name": "reify-saving-the-ideal-tree-save-some-stuff",
Expand All @@ -27216,10 +27219,17 @@ Object {
"a": "github:foo/bar#baz",
"b": "^1.2.3",
"d": "npm:[email protected] <1.9.9",
"e": "*",
},
"devDependencies": Object {
"c": "git+ssh://[email protected]:a/b/c.git#master",
},
"workspaces": Array [
"e",
],
},
"e": Object {
"extraneous": true,
},
"node_modules/a": Object {
"extraneous": true,
Expand All @@ -27243,6 +27253,10 @@ Object {
"resolved": "https://registry.npmjs.org/c/-/c-1.2.3.tgz",
"version": "1.2.3",
},
"node_modules/e": Object {
"link": true,
"resolved": "e",
},
},
"requires": true,
}
Expand Down
42 changes: 40 additions & 2 deletions test/arborist/reify.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,20 @@ const warningTracker = () => {
}

const Node = requireInject('../../lib/node.js', { fs: fsMock })
const Link = requireInject('../../lib/link.js', {
fs: fsMock,
'../../lib/node.js': Node,
})
const Shrinkwrap = requireInject('../../lib/shrinkwrap.js', {
fs: fsMock,
'../../lib/node.js': Node,
'../../lib/link.js': Link,
})
const Arborist = requireInject('../../lib/arborist', {
rimraf: rimrafMock,
fs: fsMock,
'../../lib/node.js': Node,
'../../lib/link.js': Link,
})

const registryServer = require('../fixtures/registry-mocks/server.js')
Expand Down Expand Up @@ -837,16 +843,26 @@ t.test('saving the ideal tree', t => {
a: 'git+ssh://[email protected]:foo/bar#baz',
b: '',
d: 'd@npm:[email protected] <1.9.9',
e: 'file:e',
},
devDependencies: {
c: `git+ssh://[email protected]:a/b/c.git#master`,
},
workspaces: [
'e',
],
}

const npa = require('npm-package-arg')
const kResolvedAdd = Symbol.for('resolvedAdd')
const path = t.testdir({
'package.json': JSON.stringify(pkg)
'package.json': JSON.stringify(pkg),
e: {
'package.json': JSON.stringify({name: 'e'}),
},
node_modules: {
e: t.fixture('symlink', '../e'),
},
})
const a = newArb({ path })
const hash = '71f3ccfefba85d2048484569dba8c1829f6f41d7'
Expand Down Expand Up @@ -886,12 +902,30 @@ t.test('saving the ideal tree', t => {
},
parent: tree,
})
const target = new Node({
name: 'e',
pkg: {
name: 'e',
},
path: resolve(tree.path, 'e'),
fsParent: tree,
})
new Link({
name: 'e',
realpath: target.path,
path: resolve(tree.path, 'node_modules/e'),
resolved: 'file:../e',
pkg: {
name: 'e',
},
})

a[kResolvedAdd] = [
npa('a@git+ssh://[email protected]:foo/bar#baz'),
npa('b'),
npa('d@npm:[email protected] <1.9.9'),
npa(`c@git+ssh://[email protected]:a/b/c.git#master`),
npa('c@git+ssh://[email protected]:a/b/c.git#master'),
npa('e'),
]
return a[kSaveIdealTree]({
savePrefix: '~',
Expand All @@ -904,7 +938,11 @@ t.test('saving the ideal tree', t => {
a: 'github:foo/bar#baz',
b: '^1.2.3',
d: 'npm:[email protected] <1.9.9',
e: '*',
},
workspaces: [
'e',
],
devDependencies: {
c: 'git+ssh://[email protected]:a/b/c.git#master',
},
Expand Down

0 comments on commit 8b457c2

Please sign in to comment.