fix(arborist): expose store node_modules via NODE_PATH for linked-strategy install scripts#9551
Open
manzoorwanijk wants to merge 1 commit into
Open
Conversation
1ed9016 to
afa52bd
Compare
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In continuation of our exploration of using
install-strategy=linkedin the Gutenberg monorepo, which powers the WordPress Block Editor.Under
install-strategy=linked, a package whose install script invokes a separate helper bin to locate a native binding fails (e.g.unrs-resolvervianapi-postinstall, and the widernapi-postinstallfamily). The helper bin is reached via a.binsymlink, so Node resolves it to its own realpath in its own store dir, from which it can'trequire.resolvethe host's binding — so it declares it missing and re-downloads (fatal on a restricted registry/proxy). Hoisted works because the binding is hoisted onto the helper's resolution path.How
When running a store node's lifecycle script, set
NODE_PATHto the host package's storenode_modulesso a script-invoked bin can resolve the host's sibling deps:NODE_PATHis fallback-only (can't shadow working resolution), added only to the script's env (neverprocess.env), and scoped to the store-localnode_modules— install-time only, runtime isolation untouched.Tests
test/arborist/reify.js: regression test asserts a linked store node's script envNODE_PATHpoints at the storenode_modules. Fails before, passes after.@npmcli/arboristsuite passes at 100% coverage.References
Fixes #9549