-
Notifications
You must be signed in to change notification settings - Fork 520
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support for nested node_modules in linker
This PR adds support for nested node_modules folders in the linker, which allows targets to depend on npm packages from multiple yarn_install & npm_install repository rules (max one per directory in the workspace). This is an opt-in feature which is enabled by specifying package_path in yarn_install or npm_install for nested package.json files. Setting package_path informs the linker to link the external npm repository to a node_modules folder in the package_path sub-directory specified. For example, given two yarn_install rules: ``` yarn_install( name = "npm", package_json = "//:package.json", yarn_lock = "//:yarn.lock", ) yarn_install( name = "npm_subdir", package_json = "//subdir:package.json", package_path = "subdir", yarn_lock = "//subdir:yarn.lock", ) ``` a target may depend on npm packages from both, ``` jasmine_node_test( name = "test", srcs = ["test.js"], deps = [ "@npm//foo", "@npm_subdir//bar", ], ) ``` and the linker will link multiple 3rd party node_modules folders, ``` /node_modules => @npm//:node_modules /subdir/node_modules => @npm_subdir/:node_modules ``` making the 3rd party npm deps foo & bar available at ``` /node_modules/foo /subdir/node_modules/bar ``` This feature is opt-in as package_path currently defaults to "". In a future major release (4.0.0), package_path will default to the directory the package.json file is in, which will turn it on by default. This feature is an alternative to yarn workspaces & npm workspaces, which also lay out node_modules in multiple directories from multiple package.json files. To date, targets have been limited to depending on and resolving form a single yarn_install or npm_install workspace which was always linked to a node_modules folder at the root of the workspace. With this change, the linker is able to link to both the root of the workspace as well as sub-directories in the workspace so targets may now resolve 3rd party npm deps from multiple package.json files which correspond to multiple node_modules folders in the tree. 1st party deps are still always linked to the root node_modules folder as they were before this change. NB: depending on multiple npm workspaces will not be supported by ts_library as its resolution logic is limited to a single node_modules root NB: pre-linker node require patches (deprecated as of 3.0.0) will only include root node_modules; no nested node_modules shall included in require patch resolution
- Loading branch information
1 parent
f557f9d
commit 2c2cc6e
Showing
49 changed files
with
974 additions
and
701 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
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
Oops, something went wrong.