-
Notifications
You must be signed in to change notification settings - Fork 64
feat(rebuild): add lifecycle scripts dependencies #303
feat(rebuild): add lifecycle scripts dependencies #303
Conversation
094466d
to
0e71ba8
Compare
Adds the ability for lifecycle scripts of Link nodes to depend on each other, such that a `prepare` script of linked module A can make use of files that are a result of a `prepare` script of a linked package B. This is important in order to unlock workflows in which a workspace needs to make use of another workspace but they all have transpilation steps (very common in Typescript projects) so tracking the order (and completion) in which the dependencies lifecycle scripts runs becomes necessary. Fixes: npm/cli#3034
0e71ba8
to
b4689eb
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This encounters a deadlock when there is a cycle between link dependencies. Example to reproduce it:
diff --git a/test/arborist/rebuild.js b/test/arborist/rebuild.js
index 77c38623..53993201 100644
--- a/test/arborist/rebuild.js
+++ b/test/arborist/rebuild.js
@@ -790,6 +790,7 @@ t.test('scripts dependencies between Link nodes', async t => {
// at least 20ms prior to writing that file
prepare: "node -e \"setTimeout(() => { require('fs').writeFileSync(require('path').resolve('index.js'), 'module.exports = function HELLO() {}.name;') }, 20)\"",
},
+ dependencies: { b: '' },
}),
},
d: {
The need is clearly valid, but we have to be able to determine the case where a dependency is waiting on something that exists in a cycle. Also, I think we can probably address it without needing a class to manage references and polling? At the very least, the Script class here needs to be a standalone thing with unit tests.
We hit this issue afer updating to npm@7.20 and |
Maybe what we need is a mechanism to detect a cyclic dependency and raise a warning? Since 7.20, we can't use workspace with lerna anymore since npm would try to run |
Workaround for those who might run into it: explicitly list the order of items in:
|
@ruyadorno Closing this in order to archive the repo. |
Adds the ability for lifecycle scripts of Link nodes to depend
on each other, such that a
prepare
script of linked module Acan make use of files that are a result of a
prepare
script ofa linked package B.
This is important in order to unlock workflows in which a workspace
needs to make use of another workspace but they all have transpilation
steps (very common in Typescript projects) so tracking the order
(and completion) in which the dependencies lifecycle scripts runs
becomes necessary.
References
Fixes: npm/cli#3034