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

Save provided range if not a subset of savePrefix #145

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions lib/arborist/reify.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const pacote = require('pacote')
const rpj = require('read-package-json-fast')
const { orderDeps, updateDepSpec } = require('../dep-spec.js')
const AuditReport = require('../audit-report.js')
const {subset} = require('semver')

const {dirname, resolve, relative} = require('path')
const {depth: dfwalk} = require('treeverse')
Expand Down Expand Up @@ -788,12 +789,21 @@ module.exports = cls => class Reifier extends cls {
const root = this.idealTree
const pkg = root.package
for (const req of this[_resolvedAdd]) {
const {name} = req
const {name, rawSpec, subSpec} = req
const spec = subSpec ? subSpec.rawSpec : rawSpec
const child = root.children.get(name)

if (req.registry) {
const version = child.version
const range = this[_savePrefix] + version
const prefixRange = 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
// would allow versions outside the requested range. Tags and
// specific versions save with the save-prefix.
const isRange = (subSpec || req).type === 'range'
const range = !isRange || subset(prefixRange, spec, { loose: true })
? prefixRange : spec
const pname = child.package.name
const alias = name !== pname
updateDepSpec(pkg, name, (alias ? `npm:${pname}@` : '') + range)
Expand Down
2 changes: 1 addition & 1 deletion tap-snapshots/test-arborist-reify.js-TAP.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27051,7 +27051,7 @@ Object {
"dependencies": Object {
"a": "github:foo/bar#baz",
"b": "^1.2.3",
"d": "npm:c@^1.2.3",
"d": "npm:c@1.x <1.9.9",
},
"devDependencies": Object {
"c": "git+ssh://[email protected]:a/b/c.git#master",
Expand Down
6 changes: 3 additions & 3 deletions test/arborist/reify.js
Original file line number Diff line number Diff line change
Expand Up @@ -816,7 +816,7 @@ t.test('saving the ideal tree', t => {
dependencies: {
a: 'git+ssh://[email protected]:foo/bar#baz',
b: '',
d: 'd@npm:[email protected]',
d: 'd@npm:[email protected] <1.9.9',
},
devDependencies: {
c: `git+ssh://[email protected]:a/b/c.git#master`,
Expand Down Expand Up @@ -870,7 +870,7 @@ t.test('saving the ideal tree', t => {
a[kResolvedAdd] = [
npa('a@git+ssh://[email protected]:foo/bar#baz'),
npa('b'),
npa('d@npm:[email protected]'),
npa('d@npm:[email protected] <1.9.9'),
npa(`c@git+ssh://[email protected]:a/b/c.git#master`),
]
return a[kSaveIdealTree]({
Expand All @@ -883,7 +883,7 @@ t.test('saving the ideal tree', t => {
dependencies: {
a: 'github:foo/bar#baz',
b: '^1.2.3',
d: 'npm:c@^1.2.3',
d: 'npm:c@1.x <1.9.9',
},
devDependencies: {
c: 'git+ssh://[email protected]:a/b/c.git#master',
Expand Down