diff options
author | Luke Karrys <luke@lukekarrys.com> | 2022-11-10 20:52:30 +0300 |
---|---|---|
committer | Luke Karrys <luke@lukekarrys.com> | 2022-11-10 20:52:30 +0300 |
commit | cafd435b931143936812f3c095334aa99e0c044e (patch) | |
tree | b063c1b647c8ea08e6f539a75e6f3055fd8c1d11 | |
parent | 1192d89d4c8585e0f12e2381ca3c5cb5ee473841 (diff) |
wip: add a smoke test and an ideanlf/tweak-relative-paths-for-install-links
-rw-r--r-- | smoke-tests/test/install-links.js | 52 | ||||
-rw-r--r-- | workspaces/arborist/lib/arborist/build-ideal-tree.js | 21 | ||||
-rw-r--r-- | workspaces/arborist/lib/dep-valid.js | 1 |
3 files changed, 71 insertions, 3 deletions
diff --git a/smoke-tests/test/install-links.js b/smoke-tests/test/install-links.js new file mode 100644 index 000000000..4ae659f51 --- /dev/null +++ b/smoke-tests/test/install-links.js @@ -0,0 +1,52 @@ +const t = require('tap') +const { join } = require('path') +const setup = require('./fixtures/setup.js') + +t.test('workspaces + file deps + non-deduping abbrev', async t => { + const abbrevs = ['1.0.3', '1.0.4', '1.0.5', '1.0.6'] + + const { npm, registry, paths } = await setup(t, { + debug: true, + testdir: { + a: { + 'package.json': { name: 'a', dependencies: { abbrev: abbrevs[0], b: 'file:./b' } }, + }, + b: { + 'package.json': { name: 'b', dependencies: { abbrev: abbrevs[1] } }, + }, + packages: abbrevs.reduce((acc, v) => { + acc[`abbrev-${v}`] = { 'package.json': { name: 'abbrev', version: v } } + return acc + }, {}), + }, + }) + + await npm('init', '-y') + await npm('init', '-y', '--workspace=workspaces/ws-a') + await npm('init', '-y', '--workspace=workspaces/ws-b') + + // set root deps + await npm('pkg', 'set', `dependencies.ws-a=1.0.0`) + await npm('pkg', 'set', `dependencies.a=file:../a`) + + // set workspace a deps + await npm('pkg', 'set', `dependencies.abbrev=${abbrevs[2]}`, '--workspace=ws-a') + await npm('pkg', 'set', `dependencies.ws-b=1.0.0`, '--workspace=ws-a') + + // set workspace b deps + await npm('pkg', 'set', `dependencies.abbrev=${abbrevs[3]}`, '--workspace=ws-b') + + await registry.package({ + manifest: registry.manifest({ name: 'abbrev', versions: abbrevs }), + tarballs: abbrevs.reduce((acc, v) => { + acc[v] = join(paths.root, 'packages', `abbrev-${v}`) + return acc + }, {}), + times: 2, + + }) + + // this should not fail and all 4 abbrevs should get installed + // with no mocks remaining + await npm('install', '--install-links=true') +}) diff --git a/workspaces/arborist/lib/arborist/build-ideal-tree.js b/workspaces/arborist/lib/arborist/build-ideal-tree.js index b79bfe8f4..6c4401f8f 100644 --- a/workspaces/arborist/lib/arborist/build-ideal-tree.js +++ b/workspaces/arborist/lib/arborist/build-ideal-tree.js @@ -1115,7 +1115,6 @@ This is a one-time fix-up, please be patient... legacyPeerDeps: this.legacyPeerDeps, overrides: node.overrides, }) - // also need to set up any targets from any link deps, so that // they are properly reflected in the virtual environment for (const child of node.children.values()) { @@ -1234,7 +1233,7 @@ This is a one-time fix-up, please be patient... // spec is a directory, link it unless installLinks is set or it's a workspace if (spec.type === 'directory') { - return this[_linkFromSpec](name, spec, parent, edge) + return this[_linkFromSpec](name, spec, parent) } // if the spec matches a workspace name, then see if the workspace node will @@ -1268,7 +1267,7 @@ This is a one-time fix-up, please be patient... }) } - [_linkFromSpec] (name, spec, parent, edge) { + [_linkFromSpec] (name, spec, parent) { const realpath = spec.fetchSpec const { installLinks, legacyPeerDeps } = this return rpj(realpath + '/package.json').catch(() => ({})).then(pkg => { @@ -1415,6 +1414,22 @@ This is a one-time fix-up, please be patient... continue } + // XXX: maybe we need to replace the link with its target + // at this stage so it gets treated as a regular node at + // reified correctly inside node_modules? + // if (link.installLinks && !link.isWorkspace) { + // // console.log(link)edg + // // console.log(link.name) + // // console.log(link.parent) + // // console.log(link.path) + // // console.log(link.realpath) + // // console.log(link.pkg) + // const target = link.target + // link.replaceWith(target) + // this.addTracker('idealTree', target.name, target.location) + // this[_depsQueue].push(target) + // continue + // } // if installLinks is set then we want to install deps no matter what if (link.installLinks) { this.addTracker('idealTree', link.target.name, link.target.location) diff --git a/workspaces/arborist/lib/dep-valid.js b/workspaces/arborist/lib/dep-valid.js index 9c1bc7d3f..4d2d9d0fe 100644 --- a/workspaces/arborist/lib/dep-valid.js +++ b/workspaces/arborist/lib/dep-valid.js @@ -108,6 +108,7 @@ const depValid = (child, requested, requestor) => { const linkValid = (child, requested, requestor) => { const isLink = !!child.isLink + // if we're installing links and the node is a link, then it's invalid because we want // a real node to be there. Except for workspaces. They are always links. if (requestor.installLinks && !child.isWorkspace) { |