-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: streamline workspace loading code
- Loading branch information
1 parent
35c94e0
commit 2ba1171
Showing
2 changed files
with
6 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |