Skip to content

Instantly share code, notes, and snippets.

@isaacs
Created March 3, 2020 22:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save isaacs/bf87b822a0ffdebe3b010684e27d0856 to your computer and use it in GitHub Desktop.
Save isaacs/bf87b822a0ffdebe3b010684e27d0856 to your computer and use it in GitHub Desktop.
diff --git a/lib/arborist/build-ideal-tree.js b/lib/arborist/build-ideal-tree.js
index 9464772..5a4f8d7 100644
--- a/lib/arborist/build-ideal-tree.js
+++ b/lib/arborist/build-ideal-tree.js
@@ -208,7 +208,8 @@ module.exports = cls => class IdealTreeBuilder extends Tracker(Virtual(Actual(cl
}
[_rootNodeFromPackage] (pkg) {
- return new Node({
+ const Cls = pkg.workspaces ? Workspace : Node
+ return this[_mapWorkspaces](new Cls({
path: this.path,
pkg,
extraneous: false,
@@ -217,7 +218,15 @@ module.exports = cls => class IdealTreeBuilder extends Tracker(Virtual(Actual(cl
peer: false,
optional: false,
global: this[_global],
- })
+ }))
+ }
+
+ [_mapWorkspaces] (node) {
+ if (!node.isWorkspace)
+ return node
+
+ return doGlobStuffReturnPromise(.....)
+ .then(() => node)
}
// process the add/rm requests by modifying the root node, and the
diff --git a/notes/workspace.md b/notes/workspace.md
index 289705a..b0d0711 100644
--- a/notes/workspace.md
+++ b/notes/workspace.md
@@ -35,15 +35,30 @@ what pre-arborist `npm link ../foo` would generate.
```
root
++-- node_modules
+| +-- app => app
+| +-- a => pkgs/a
+| +-- b => pkgs/b
+| +-- c => pkgs/c
+| +-- x
+| +-- y
+| +-- z
+| +-- i
+| +-- n ?
++-- app
+| +-- node_modules
+| +-- a => pkgs/a
+| +-- b => pkgs/b
+| +-- c => pkgs/c
+| +-- i
+-- pkgs
- +-- app
- | +-- node_modules
- | +-- a => pkgs/a
- | +-- b => pkgs/b
- | +-- c => pkgs/c
- | +-- i
- +-- a (b, c, x)
+ +-- a (b, c, x, m@file:./m)
+ | +-- m (n)
+ | | +-- node_modules
+ | | +-- n ?
| +-- node_modules
+ | +-- n ?
+ | +-- m => pkgs/a/m
| +-- x
| +-- b => pkgs/b
| +-- c => pkgs/c
@@ -53,8 +68,42 @@ root
| +-- a => pkgs/a
| +-- c => pkgs/c
+-- c (a, b, z)
- +-- node_modules
- +-- z
- +-- a => pkgs/a
- +-- b => pkgs/b
+ | +-- node_modules
+ | +-- z
+ | +-- a => pkgs/a
+ | +-- b => pkgs/b
+ +-- w (nested workspace) wsParent = root
+ +-- pkgs
+ +-- i (wsParent = pkgs/w, root = ./, parent = null, fsParent = pkgs/w)
+ +-- j
+ +-- k
```
+
+root/package.json
+
+```json
+{
+ "workspaces": [
+ "pkgs/*",
+ "app"
+ ]
+}
+```
+
+root `Node`
+
+- know it's a workspace
+- 4 Edges in edgesOut with type=workspace, referencing workspace children
+ - that means we create a link node in root.children.get('app')
+ targetting `./app` Node, etc.
+- during buildIdeal:
+ - need to know that app is in root's workspace
+ - app.wsParent = root
+ - root.wsChildren.add(app)
+ - if any dep CAN be satisfied by a named dep in the workspace, then
+ create a Link targetting that workspace child node
+ - resolving: _first_ check this.wsParent.get('dep-name'), and if
+ that's ok, then resolve with a link to that target.
+ - no hoisting by default: when doing `_canPlaceDep`, if target is
+ node.wsParent, AND we're not hoisting, THEN: return CONFLICT
+- When setting Node.parent or Node.fsParent, set wsParent = parent.wsParent
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment