Commit e90b4ae
feat: support for multi-linked first party dependencies
Adds the ability to link first party deps to subdirectories and adds a new `links` to `yarn_install` and `npm_install` which simplifies linking first party deps into `yarn_install` and `npm_install` managed `node_modules` trees.
The first release of the multi-linker, which landed in 3.2.0, supported linking only 3rd party deps to subdirectories.
------------------------------
This new feature is enabled by new `npm_link` which can add a `LinkablePackageInfo` to any target.
If a target already provides a `LinkablePackageInfo`, it provides a new `LinkablePackageInfo` with a new provided values for `package_path` and `package_name` which informs the linker into which `${package_path}/node_modules/${package_name}` folder to link the package into.
For example, given
```
lib_a/BUILD.bazel:
js_library(
name = "lib_a",
srcs = [
"index.js",
"package.json",
],
package_name = "@somescope/lib-a"
)
```
which makes `//lib_a:lib_a` link to the root node_modules at `node_modules/@somescope/lib-a`
`npm_link` can be used to create a new `lib_a` target that links elsewhere:
```
sub/BUILD.bazel:
npm_link(
name = "lib_a",
target = "//lib_a",
package_path = "sub",
package_name = "@somescope/lib-a",
)
```
which makes `//sub:lib_a` linked to `sub/node_modules/@somescope/lib-a`.
Note: a target may depend on both `//lib_a:lib_a` and `//sub:lib_a` in its `deps` and the linker will link the library to both
`node_modules/@somescope/lib-a` and `sub/node_modules/@somescope/lib-a` respectively.
Alternately, `npm_link` can add a `LinkablePackageInfo` provider to a target that doesn't yet have a `package_name` associated with it,
For example,
```
lib_b/BUILD.bazel:
js_library(
name = "lib_b",
srcs = [
"index.js",
"package.json",
],
)
```
```
sub/BUILD.bazel:
npm_link(
name = "lib_b",
target = "//lib_b",
package_path = "sub",
package_name = "@somescope/lib-b",
)
```
which makes `//sub:lib_b` linked to `sub/node_modules/@somescope/lib-b` while `//lib_b:lib_b` is not linked at all.
The linked target can be of any type, including a simple filegroup. For example,
```
lib_c/BUILD.bazel:
filegroup(
name = "lib_c",
srcs = [
"index.js",
"package.json",
],
)
```
```
sub/BUILD.bazel:
npm_link(
name = "lib_c",
target = "//lib_c",
package_path = "sub",
package_name = "@somescope/lib-c",
)
```
which makes `//sub:lib_c` linked to `sub/node_modules/@somescope/lib-c` while `//lib_c:lib_c` is not linked at all.
------------------------------
With the above abilities, we've also added syntactical sugar to `yarn_install` and `npm_install` which uses `npm_link` under the hood.
For example, given a `sub/package.json` we can define its `yarn_install` as,
```
WORKSPACE:
yarn_install(
name = “@sub_npm_deps”,
package_json = "//sub:package.json",
package_path = "sub",
links = {
"@somescope/lib-a": "//lib_a:lib_a",
"@somescope/lib-b": "//lib_b:lib_b",
}
)
```
which generates two `npm_link` under the hood:
```
@sub_npm_deps//@somescope/lib-a:BUILD.bazel:
npm_link(
name = "lib-a",
target = "//lib_a:lib_a",
package_path = "sub",
package_name = "@somescope/lib-a",
)
```
```
@sub_npm_deps//@somescope/lib-b:BUILD.bazel:
npm_link(
name = "lib-b",
target = "//lib_b:lib_b",
package_path = "sub",
package_name = "@somescope/lib-b",
)
```
which are both linked to `sub/node_modules` (`sub/node_modules/@somescope/lib-a` and `sub/node_modules/@somescope/lib-b` respectively).
This allows the downstream syntactical sugar of depending on first party deps by their package names from the external workspace they are "linked" to.
```
sub/BUILD.bazel:
nodejs_binary(
name = "bin",
entry_point = "bin.js",
data = [
"bin.js"
"@sub_npm_deps//@somescope/lib-a",
"@sub_npm_deps//@somescope/lib-b",
]
)
```
and those deps will be available to the application in `sub/node_modules` where you would expect them to be if they had been defined in the `sub/package.json` itself using yarn workspaces outside of bazel.
`sub/bin.js` can then require those libs with,
```
const liba = require('@somescope/lib-a')
const libb = require('@somescope/lib-b')
```
and those will be resolved to `sub/node_modules/@somescope/lib-a/index.js` and `sub/node_modules/@somescope/lib-b/index.js` with standard node_modules resolution.1 parent be184c2 commit e90b4ae
File tree
119 files changed
+12786
-446
lines changed- examples/user_managed_deps
- internal
- js_library
- linker
- test
- multi_linker
- lib_a
- lib_b
- lib_c
- lib
- lib_d
- onep_a
- onep_b
- onepa
- onepb
- sub
- dev
- test_a
- test_b
- test_c
- test_d
- node
- npm_install
- test
- golden_multi_linked
- @angular/core
- @gregmagolan
- test-a
- bin
- test-b
- @some-scope
- some-target-b2
- some-target-b
- ajv
- jasmine
- bin
- rxjs
- some-target-a2
- some-target-a
- unidiff
- zone.js
- golden
- @angular/core
- @gregmagolan
- test-a
- test-b
- @some-scope
- some-target-b2
- some-target-b
- ajv
- jasmine
- rxjs
- some-target-a2
- some-target-a
- unidiff
- zone.js
- pkg_npm
- providers
- packages
- esbuild
- typescript/internal
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
119 files changed
+12786
-446
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| 21 | + | |
21 | 22 | | |
22 | | - | |
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| |||
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
57 | 67 | | |
58 | 68 | | |
59 | 69 | | |
60 | 70 | | |
61 | 71 | | |
62 | | - | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
63 | 83 | | |
64 | 84 | | |
| 85 | + | |
65 | 86 | | |
66 | 87 | | |
67 | 88 | | |
68 | 89 | | |
69 | | - | |
70 | | - | |
71 | | - | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
72 | 137 | | |
73 | | - | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
74 | 196 | | |
75 | 197 | | |
76 | 198 | | |
| |||
273 | 395 | | |
274 | 396 | | |
275 | 397 | | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
276 | 453 | | |
277 | 454 | | |
278 | 455 | | |
| |||
293 | 470 | | |
294 | 471 | | |
295 | 472 | | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
296 | 477 | | |
297 | 478 | | |
298 | 479 | | |
| 480 | + | |
299 | 481 | | |
300 | 482 | | |
301 | 483 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
4 | | - | |
5 | | - | |
6 | | - | |
7 | | - | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
10 | 13 | | |
11 | 14 | | |
12 | 15 | | |
| |||
25 | 28 | | |
26 | 29 | | |
27 | 30 | | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
| |||
0 commit comments