From 5a4b58c1b784c9c646e515e92b4bea87b24cc49a Mon Sep 17 00:00:00 2001 From: James Chen-Smith Date: Wed, 17 Mar 2021 01:01:06 -0500 Subject: [PATCH] fix: honor explicit prefix Honors explicit prefix. Signed-off-by: James Chen-Smith PR-URL: https://github.com/npm/arborist/pull/254 Credit: @jameschensmith Close: #254 Reviewed-by: @isaacs --- lib/arborist/reify.js | 2 +- .../test-arborist-reify.js-TAP.test.js | 11 +++++++++++ test/arborist/reify.js | 19 +++++++++++++++---- 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/lib/arborist/reify.js b/lib/arborist/reify.js index 803fb9782..000804552 100644 --- a/lib/arborist/reify.js +++ b/lib/arborist/reify.js @@ -890,7 +890,7 @@ module.exports = cls => class Reifier extends cls { const root = this.idealTree const pkg = root.package for (const { name } of this[_resolvedAdd]) { - const req = npa(root.edgesOut.get(name).spec, root.realpath) + const req = npa.resolve(name, root.edgesOut.get(name).spec, root.realpath) const {rawSpec, subSpec} = req const spec = subSpec ? subSpec.rawSpec : rawSpec diff --git a/tap-snapshots/test-arborist-reify.js-TAP.test.js b/tap-snapshots/test-arborist-reify.js-TAP.test.js index 9b54ddf4c..ed3803fca 100644 --- a/tap-snapshots/test-arborist-reify.js-TAP.test.js +++ b/tap-snapshots/test-arborist-reify.js-TAP.test.js @@ -29029,6 +29029,11 @@ Object { "extraneous": true, "resolved": "https://registry.npmjs.org/g/-/g-1.2.3.tgz", }, + "h": Object { + "extraneous": true, + "resolved": "https://registry.npmjs.org/h/-/h-1.2.3.tgz", + "version": "1.2.3", + }, }, "lockfileVersion": 2, "name": "reify-saving-the-ideal-tree-save-some-stuff", @@ -29046,6 +29051,7 @@ Object { "e": "file:e", "f": "git+https://user:pass@github.com/baz/quux.git#asdf", "g": "*", + "h": "~1.2.3", }, "devDependencies": Object { "c": "git+ssh://git@githost.com:a/b/c.git#master", @@ -29092,6 +29098,11 @@ Object { "extraneous": true, "resolved": "https://registry.npmjs.org/g/-/g-1.2.3.tgz", }, + "node_modules/h": Object { + "extraneous": true, + "resolved": "https://registry.npmjs.org/h/-/h-1.2.3.tgz", + "version": "1.2.3", + }, }, "requires": true, } diff --git a/test/arborist/reify.js b/test/arborist/reify.js index f5e789cc0..29be07c6d 100644 --- a/test/arborist/reify.js +++ b/test/arborist/reify.js @@ -808,11 +808,12 @@ t.test('saving the ideal tree', t => { dependencies: { a: 'git+ssh://git@github.com:foo/bar#baz', b: '', - d: 'd@npm:c@1.x <1.9.9', + d: 'npm:c@1.x <1.9.9', // XXX: should we remove dependencies that are also workspaces? e: 'file:e', f: 'git+https://user:pass@github.com/baz/quux#asdf', g: '', + h: '~1.2.3', }, devDependencies: { c: `git+ssh://git@githost.com:a/b/c.git#master`, @@ -891,6 +892,16 @@ t.test('saving the ideal tree', t => { }, parent: tree, }) + new Node({ + name: 'h', + resolved: 'https://registry.npmjs.org/h/-/h-1.2.3.tgz', + pkg: { + name: 'h', + version: '1.2.3', + }, + parent: tree, + }) + const target = new Node({ name: 'e', pkg: { @@ -917,12 +928,11 @@ t.test('saving the ideal tree', t => { npa('e'), npa('f@git+https://user:pass@github.com/baz/quux#asdf'), npa('g'), + npa('h@~1.2.3'), ] // NB: these are all going to be marked as extraneous, because we're // skipping the actual buildIdealTree step that flags them properly - return a[kSaveIdealTree]({ - savePrefix: '~', - }) + return a[kSaveIdealTree]({}) }).then(() => { t.matchSnapshot(require(path + '/package-lock.json'), 'lock after save') t.strictSame(require(path + '/package.json'), { @@ -934,6 +944,7 @@ t.test('saving the ideal tree', t => { e: 'file:e', f: 'git+https://user:pass@github.com/baz/quux.git#asdf', g: '*', + h: '~1.2.3', }, workspaces: [ 'e',