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

Commit

Permalink
workspaces wip: added mapWorkspaces.virtual to loadVirtual
Browse files Browse the repository at this point in the history
  • Loading branch information
ruyadorno committed Apr 3, 2020
1 parent 92ab28d commit e8d9497
Show file tree
Hide file tree
Showing 4 changed files with 211 additions and 7 deletions.
14 changes: 13 additions & 1 deletion lib/arborist/load-virtual.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// mixin providing the loadVirtual method

const {resolve} = require('path')
const mapWorkspaces = require('@npmcli/map-workspaces')

const consistentResolve = require('../consistent-resolve.js')
const Shrinkwrap = require('../shrinkwrap.js')
Expand All @@ -14,6 +15,7 @@ const resolveLinks = Symbol('resolveLinks')
const assignParentage = Symbol('assignParentage')
const loadNode = Symbol('loadVirtualNode')
const loadLink = Symbol('loadVirtualLink')
const loadWorkspaces = Symbol('loadWorkspaces')

module.exports = cls => class VirtualLoader extends cls {
constructor (options) {
Expand All @@ -38,7 +40,7 @@ module.exports = cls => class VirtualLoader extends cls {
// when building the ideal tree, we pass in a root node to this function
// otherwise, load it from the root package in the lockfile
const {
root = this[loadNode]('', s.data.packages[''])
root = this[loadWorkspaces](this[loadNode]('', s.data.packages['']), s)
} = options

return this[loadFromShrinkwrap](s, root)
Expand Down Expand Up @@ -143,6 +145,16 @@ module.exports = cls => class VirtualLoader extends cls {
return node
}

[loadWorkspaces] (node, s) {
const workspaces = mapWorkspaces.virtual({
cwd: node.path,
lockfile: s.data
})
if (workspaces.size)
node.workspaces = workspaces
return node
}

[loadLink] (location, targetLoc, target, meta) {
const path = resolve(this.path, location)
const link = new Link({
Expand Down
196 changes: 192 additions & 4 deletions tap-snapshots/test-arborist-load-virtual.js-TAP.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13531,6 +13531,14 @@ exports[`test/arborist/load-virtual.js TAP workspaces load a simple example > vi
Node {
"children": Map {
"a" => Link {
"edgesIn": Set {
Edge {
"from": "",
"name": "a",
"spec": "file:{CWD}/test/fixtures/workspaces-simple-virtual/a",
"type": "workspace",
},
},
"location": "node_modules/a",
"name": "a",
"resolved": "file:../a",
Expand All @@ -13541,6 +13549,12 @@ Node {
},
"b" => Link {
"edgesIn": Set {
Edge {
"from": "",
"name": "b",
"spec": "file:{CWD}/test/fixtures/workspaces-simple-virtual/b",
"type": "workspace",
},
Edge {
"from": "a",
"name": "b",
Expand All @@ -13557,6 +13571,20 @@ Node {
},
},
},
"edgesOut": Map {
"a" => Edge {
"name": "a",
"spec": "file:{CWD}/test/fixtures/workspaces-simple-virtual/a",
"to": "node_modules/a",
"type": "workspace",
},
"b" => Edge {
"name": "b",
"spec": "file:{CWD}/test/fixtures/workspaces-simple-virtual/b",
"to": "node_modules/b",
"type": "workspace",
},
},
"location": "",
"name": "workspaces-simple-virtual",
"resolved": null,
Expand All @@ -13567,6 +13595,14 @@ exports[`test/arborist/load-virtual.js TAP workspaces load conflicting dep versi
Node {
"children": Map {
"a" => Link {
"edgesIn": Set {
Edge {
"from": "",
"name": "a",
"spec": "file:{CWD}/test/fixtures/workspaces-conflicting-versions-virtual/packages/a",
"type": "workspace",
},
},
"location": "node_modules/a",
"name": "a",
"resolved": "file:../packages/a",
Expand Down Expand Up @@ -13603,6 +13639,14 @@ Node {
"resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz",
},
"b" => Link {
"edgesIn": Set {
Edge {
"from": "",
"name": "b",
"spec": "file:{CWD}/test/fixtures/workspaces-conflicting-versions-virtual/packages/b",
"type": "workspace",
},
},
"location": "node_modules/b",
"name": "b",
"resolved": "file:../packages/b",
Expand All @@ -13613,12 +13657,24 @@ Node {
},
},
"edgesOut": Map {
"a" => Edge {
"name": "a",
"spec": "file:{CWD}/test/fixtures/workspaces-conflicting-versions-virtual/packages/a",
"to": "node_modules/a",
"type": "workspace",
},
"abbrev" => Edge {
"name": "abbrev",
"spec": "^1.1.1",
"to": "node_modules/abbrev",
"type": "prod",
},
"b" => Edge {
"name": "b",
"spec": "file:{CWD}/test/fixtures/workspaces-conflicting-versions-virtual/packages/b",
"to": "node_modules/b",
"type": "workspace",
},
},
"location": "",
"name": "workspaces-conflicting-versions-virtual",
Expand All @@ -13630,6 +13686,14 @@ exports[`test/arborist/load-virtual.js TAP workspaces load installed from regist
Node {
"children": Map {
"a" => Link {
"edgesIn": Set {
Edge {
"from": "",
"name": "a",
"spec": "file:{CWD}/test/fixtures/workspaces-version-unsatisfied-virtual/packages/a",
"type": "workspace",
},
},
"location": "node_modules/a",
"name": "a",
"resolved": "file:../packages/a",
Expand All @@ -13640,6 +13704,12 @@ Node {
},
"abbrev" => Link {
"edgesIn": Set {
Edge {
"from": "",
"name": "abbrev",
"spec": "file:{CWD}/test/fixtures/workspaces-version-unsatisfied-virtual/packages/abbrev",
"type": "workspace",
},
Edge {
"error": "INVALID",
"from": "packages/a",
Expand All @@ -13657,6 +13727,20 @@ Node {
},
},
},
"edgesOut": Map {
"a" => Edge {
"name": "a",
"spec": "file:{CWD}/test/fixtures/workspaces-version-unsatisfied-virtual/packages/a",
"to": "node_modules/a",
"type": "workspace",
},
"abbrev" => Edge {
"name": "abbrev",
"spec": "file:{CWD}/test/fixtures/workspaces-version-unsatisfied-virtual/packages/abbrev",
"to": "node_modules/abbrev",
"type": "workspace",
},
},
"location": "",
"name": "workspaces-version-unsatisfied-virtual",
"resolved": null,
Expand All @@ -13667,6 +13751,14 @@ exports[`test/arborist/load-virtual.js TAP workspaces load installed tree with i
Node {
"children": Map {
"a" => Link {
"edgesIn": Set {
Edge {
"from": "",
"name": "a",
"spec": "file:{CWD}/test/fixtures/workspaces-ignore-nm-virtual/packages/a",
"type": "workspace",
},
},
"location": "node_modules/a",
"name": "a",
"resolved": "file:../packages/a",
Expand All @@ -13676,6 +13768,14 @@ Node {
},
},
},
"edgesOut": Map {
"a" => Edge {
"name": "a",
"spec": "file:{CWD}/test/fixtures/workspaces-ignore-nm-virtual/packages/a",
"to": "node_modules/a",
"type": "workspace",
},
},
"location": "",
"name": "workspaces-ignore-nm-virtual",
"resolved": null,
Expand All @@ -13686,6 +13786,14 @@ exports[`test/arborist/load-virtual.js TAP workspaces load installed workspace w
Node {
"children": Map {
"a" => Link {
"edgesIn": Set {
Edge {
"from": "",
"name": "a",
"spec": "file:{CWD}/test/fixtures/workspaces-transitive-deps-virtual/packages/a",
"type": "workspace",
},
},
"location": "node_modules/a",
"name": "a",
"resolved": "file:../packages/a",
Expand Down Expand Up @@ -13731,6 +13839,14 @@ Node {
"resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
},
},
"edgesOut": Map {
"a" => Edge {
"name": "a",
"spec": "file:{CWD}/test/fixtures/workspaces-transitive-deps-virtual/packages/a",
"to": "node_modules/a",
"type": "workspace",
},
},
"location": "",
"name": "workspaces-transitive-deps-virtual",
"resolved": null,
Expand All @@ -13745,8 +13861,8 @@ Node {
Edge {
"from": "",
"name": "a",
"spec": "^1.0.0",
"type": "prod",
"spec": "file:{CWD}/test/fixtures/workspaces-top-level-link-virtual/packages/a",
"type": "workspace",
},
},
"location": "node_modules/a",
Expand All @@ -13761,9 +13877,9 @@ Node {
"edgesOut": Map {
"a" => Edge {
"name": "a",
"spec": "^1.0.0",
"spec": "file:{CWD}/test/fixtures/workspaces-top-level-link-virtual/packages/a",
"to": "node_modules/a",
"type": "prod",
"type": "workspace",
},
},
"location": "",
Expand All @@ -13776,6 +13892,14 @@ exports[`test/arborist/load-virtual.js TAP workspaces load prefer linking nested
Node {
"children": Map {
"a" => Link {
"edgesIn": Set {
Edge {
"from": "",
"name": "a",
"spec": "file:{CWD}/test/fixtures/workspaces-prefer-linking-virtual/packages/a",
"type": "workspace",
},
},
"location": "node_modules/a",
"name": "a",
"resolved": "file:../packages/a",
Expand All @@ -13786,6 +13910,12 @@ Node {
},
"abbrev" => Link {
"edgesIn": Set {
Edge {
"from": "",
"name": "abbrev",
"spec": "file:{CWD}/test/fixtures/workspaces-prefer-linking-virtual/packages/abbrev",
"type": "workspace",
},
Edge {
"from": "packages/a",
"name": "abbrev",
Expand All @@ -13802,6 +13932,20 @@ Node {
},
},
},
"edgesOut": Map {
"a" => Edge {
"name": "a",
"spec": "file:{CWD}/test/fixtures/workspaces-prefer-linking-virtual/packages/a",
"to": "node_modules/a",
"type": "workspace",
},
"abbrev" => Edge {
"name": "abbrev",
"spec": "file:{CWD}/test/fixtures/workspaces-prefer-linking-virtual/packages/abbrev",
"to": "node_modules/abbrev",
"type": "workspace",
},
},
"location": "",
"name": "workspaces-prefer-linking-virtual",
"resolved": null,
Expand All @@ -13812,6 +13956,14 @@ exports[`test/arborist/load-virtual.js TAP workspaces load shared dependencies e
Node {
"children": Map {
"a" => Link {
"edgesIn": Set {
Edge {
"from": "",
"name": "a",
"spec": "file:{CWD}/test/fixtures/workspaces-shared-deps-virtual/packages/a",
"type": "workspace",
},
},
"location": "node_modules/a",
"name": "a",
"resolved": "file:../packages/a",
Expand Down Expand Up @@ -13840,6 +13992,14 @@ Node {
"resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz",
},
"b" => Link {
"edgesIn": Set {
Edge {
"from": "",
"name": "b",
"spec": "file:{CWD}/test/fixtures/workspaces-shared-deps-virtual/packages/b",
"type": "workspace",
},
},
"location": "node_modules/b",
"name": "b",
"resolved": "file:../packages/b",
Expand All @@ -13849,6 +14009,14 @@ Node {
},
},
"c" => Link {
"edgesIn": Set {
Edge {
"from": "",
"name": "c",
"spec": "file:{CWD}/test/fixtures/workspaces-shared-deps-virtual/packages/c",
"type": "workspace",
},
},
"location": "node_modules/c",
"name": "c",
"resolved": "file:../packages/c",
Expand All @@ -13871,6 +14039,26 @@ Node {
"resolved": "https://registry.npmjs.org/uuid/-/uuid-3.3.3.tgz",
},
},
"edgesOut": Map {
"a" => Edge {
"name": "a",
"spec": "file:{CWD}/test/fixtures/workspaces-shared-deps-virtual/packages/a",
"to": "node_modules/a",
"type": "workspace",
},
"b" => Edge {
"name": "b",
"spec": "file:{CWD}/test/fixtures/workspaces-shared-deps-virtual/packages/b",
"to": "node_modules/b",
"type": "workspace",
},
"c" => Edge {
"name": "c",
"spec": "file:{CWD}/test/fixtures/workspaces-shared-deps-virtual/packages/c",
"to": "node_modules/c",
"type": "workspace",
},
},
"location": "",
"name": "workspaces-shared-deps-virtual",
"resolved": null,
Expand Down
Loading

0 comments on commit e8d9497

Please sign in to comment.