Skip to content

Commit 43cebe7

Browse files
gregmagolanalexeagle
authored andcommitted
fix(builtin): fix for symlinked node_modules issue bazel-contrib#802
This will fix the bazel-contrib#802 case of deleting and manually re-creating node_modules by no longer writing any files under node_modules. A few keys caveats: 1. The downside of this is that the root @npm BUILD file grows huge again as all files under node_modules need to be added to exports_files([...]). If Bazel had a method to export all files without explicitly listing them such as exports_files_all() that would solve this problem. 2. npm package that ships with BUILD files would now cause issues with labels used by yarn_install & npm_install generated targets. With this change, packages such as @bazel/typescript which install bazel workspaces now ship with _BUILD.bazel files. The bazel workspaces installer is already looking for files of this name since the current repo rule renames BUILD files for the same reason. To solve (2), I propose publishing a tool that could be added as a postinstall step to rename all BUILD files under node_modules and prefix them with _. This should not be a common case as most npm packages don't ship with BUILD files but there are a few that do. For example, rxjs < 6.5.0 had build files for a few releases to support building it from source.
1 parent 08b231a commit 43cebe7

File tree

65 files changed

+10556
-6044
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+10556
-6044
lines changed

BUILD.bazel

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ npm_package(
3838
"defs.bzl",
3939
"package.bzl",
4040
],
41+
# Don't rename BUILD files as this package is not published to npm
42+
# but is compressed in "release" below and published as a .tar.gz to GitHub
43+
rename_build_files = False,
4144
# Don't replace the default 0.0.0-PLACEHOLDER for this npm_package since
4245
# we are packaging up the packager itself and this replacement will break it
4346
replace_with_version = "",

WORKSPACE

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -169,15 +169,6 @@ filegroup(
169169
"//unidiff/bin:BUILD.bazel",
170170
"//unidiff:BUILD.bazel",
171171
"//zone.js:BUILD.bazel",
172-
"//node_modules/@angular/core:BUILD.bazel",
173-
"//node_modules/@gregmagolan:BUILD.bazel",
174-
"//node_modules/@gregmagolan/test-a:BUILD.bazel",
175-
"//node_modules/@gregmagolan/test-b:BUILD.bazel",
176-
"//node_modules/ajv:BUILD.bazel",
177-
"//node_modules/jasmine:BUILD.bazel",
178-
"//node_modules/rxjs:BUILD.bazel",
179-
"//node_modules/unidiff:BUILD.bazel",
180-
"//node_modules/zone.js:BUILD.bazel",
181172
],
182173
)""",
183174
package_json = "//internal/npm_install/test:package.json",

docs/node/node.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ <h3 id="nodejs_binary_args">Attributes</h3>
369369
```
370370
nodejs_binary(
371371
name = "history-server",
372-
entry_point = "@npm//node_modules/history-server:modules/cli.js",
372+
entry_point = "@npm//:node_modules/history-server/modules/cli.js",
373373
data = ["@npm//history-server"],
374374
)
375375
```
@@ -591,7 +591,7 @@ <h3 id="nodejs_test_args">Attributes</h3>
591591
```
592592
nodejs_binary(
593593
name = "history-server",
594-
entry_point = "@npm//node_modules/history-server:modules/cli.js",
594+
entry_point = "@npm//:node_modules/history-server/modules/cli.js",
595595
data = ["@npm//history-server"],
596596
)
597597
```

e2e/bazel_bin/test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ else
2727
fi
2828
# --- end runfiles.bash initialization ---
2929

30-
readonly OUT=$($(rlocation "npm/node_modules/testy/testy__bin"))
30+
readonly OUT=$($(rlocation "npm/testy/bin/testy"))
3131

3232
if [ "$OUT" != "Hello world" ]; then
3333
echo "Expected output 'Hello world' but was $OUT"

e2e/karma_typescript/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ filegroup(
7272
name = "rxjs_umd_modules",
7373
srcs = [
7474
# do not sort
75-
"@npm//node_modules/rxjs:bundles/rxjs.umd.js",
75+
"@npm//:node_modules/rxjs/bundles/rxjs.umd.js",
7676
":rxjs_shims.js",
7777
],
7878
)

e2e/karma_typescript/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"@bazel/typescript": "file:../../dist/npm_bazel_typescript",
55
"@types/jasmine": "^3.3.12",
66
"jasmine": "^3.4.0",
7-
"rxjs": "^6.4.0",
7+
"rxjs": "6.5.0",
88
"typescript": "2.9.2"
99
},
1010
"scripts": {

e2e/ts_devserver/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ ts_devserver(
3030
entry_module = "e2e_ts_devserver/app",
3131
port = 8080,
3232
scripts = [
33-
"@npm//node_modules/date-fns:date-fns.umd.js",
33+
"@npm//date-fns:date-fns.umd.js",
3434
],
3535
# We'll collect all the devmode JS sources from these TypeScript libraries
3636
deps = [":app"],

e2e/ts_library/WORKSPACE

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ yarn_install(
3030
filegroup(
3131
name = "node_modules_filegroup",
3232
srcs = [
33-
"//node_modules/@types/hammerjs:hammerjs__files",
34-
"//node_modules/@types/jasmine:jasmine__files",
35-
"//node_modules/typescript:typescript__files",
33+
"//@types/hammerjs:hammerjs__files",
34+
"//@types/jasmine:jasmine__files",
35+
"//typescript:typescript__files",
3636
],
3737
)""",
3838
package_json = "//:package.json",

e2e/ts_library/googmodule/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ nodejs_binary(
1313
"@npm//@bazel/typescript",
1414
"@npm//tsickle",
1515
],
16-
entry_point = "@npm//node_modules/@bazel/typescript:internal/tsc_wrapped/tsc_wrapped.js",
16+
entry_point = "@npm//:node_modules/@bazel/typescript/internal/tsc_wrapped/tsc_wrapped.js",
1717
install_source_map_support = False,
1818
)
1919

examples/protocol_buffers/BUILD.bazel

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ rollup_bundle(
8585
genrule(
8686
name = "protobufjs",
8787
srcs = [
88-
"@build_bazel_rules_typescript_protobufs_compiletime_deps//node_modules/protobufjs:dist/minimal/protobuf.min.js",
89-
"@build_bazel_rules_typescript_protobufs_compiletime_deps//node_modules/long:dist/long.js",
88+
"@build_bazel_rules_typescript_protobufs_compiletime_deps//:node_modules/protobufjs/dist/minimal/protobuf.min.js",
89+
"@build_bazel_rules_typescript_protobufs_compiletime_deps//:node_modules/long/dist/long.js",
9090
],
9191
outs = [
9292
"protobuf.min.js",

0 commit comments

Comments
 (0)