Skip to content

Commit

Permalink
fix: streamline workspace loading code
Browse files Browse the repository at this point in the history
  • Loading branch information
wraithgar authored and lukekarrys committed Jan 10, 2023
1 parent 35c94e0 commit 2ba1171
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 20 deletions.
4 changes: 2 additions & 2 deletions workspaces/arborist/lib/arborist/load-virtual.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// mixin providing the loadVirtual method
const localeCompare = require('@isaacs/string-locale-compare')('en')
const mapWorkspaces = require('@npmcli/map-workspaces')

const { resolve } = require('path')

Expand All @@ -21,7 +22,6 @@ const loadRoot = Symbol('loadRoot')
const loadNode = Symbol('loadVirtualNode')
const loadLink = Symbol('loadVirtualLink')
const loadWorkspaces = Symbol.for('loadWorkspaces')
const loadWorkspacesVirtual = Symbol.for('loadWorkspacesVirtual')
const flagsSuspect = Symbol.for('flagsSuspect')
const reCalcDepFlags = Symbol('reCalcDepFlags')
const checkRootEdges = Symbol('checkRootEdges')
Expand Down Expand Up @@ -157,7 +157,7 @@ module.exports = cls => class VirtualLoader extends cls {
}

const lockWS = []
const workspaces = this[loadWorkspacesVirtual]({
const workspaces = mapWorkspaces.virtual({
cwd: this.path,
lockfile: s.data,
})
Expand Down
22 changes: 4 additions & 18 deletions workspaces/arborist/lib/arborist/load-workspaces.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,19 @@
const mapWorkspaces = require('@npmcli/map-workspaces')

const _appendWorkspaces = Symbol('appendWorkspaces')
// shared ref used by other mixins/Arborist
const _loadWorkspaces = Symbol.for('loadWorkspaces')
const _loadWorkspacesVirtual = Symbol.for('loadWorkspacesVirtual')

module.exports = cls => class MapWorkspaces extends cls {
[_appendWorkspaces] (node, workspaces) {
if (node && workspaces.size) {
node.workspaces = workspaces
}

return node
}

async [_loadWorkspaces] (node) {
if (node.workspaces) {
return node
}

const workspaces = await mapWorkspaces({
cwd: node.path,
pkg: node.package,
})

return this[_appendWorkspaces](node, workspaces)
}
if (node && workspaces.size) {
node.workspaces = workspaces
}

[_loadWorkspacesVirtual] (opts) {
return mapWorkspaces.virtual(opts)
return node
}
}

0 comments on commit 2ba1171

Please sign in to comment.