Skip to content

Commit 77cc75d

Browse files
committed
build: workaround for creating ng_package on windows
Workaround for angular/angular#32603
1 parent 03d3c18 commit 77cc75d

File tree

3 files changed

+70
-0
lines changed

3 files changed

+70
-0
lines changed

WORKSPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ yarn_install(
4444
"//:angular-tsconfig.json",
4545
"//:tools/bazel/flat_module_factory_resolution.patch",
4646
"//:tools/bazel/postinstall-patches.js",
47+
"//:tools/bazel/rollup_windows_arguments.patch",
4748
"//:tools/npm/check-npm.js",
4849
],
4950
package_json = "//:package.json",

tools/bazel/postinstall-patches.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,9 @@ shelljs.sed('-i',
8181
shelljs.sed('-i', /("metadata": outs.metadata),/,
8282
`$1 + [m for dep in ctx.attr.deps if hasattr(dep, "angular") for m in dep.angular.metadata],`,
8383
'node_modules/@angular/bazel/src/ng_module.bzl');
84+
85+
// Workaround for https://github.com/angular/angular/issues/32603. Note that we don't
86+
// want to apply the patch if it has been applied already.
87+
if (!shelljs.test('-f', 'node_modules/@angular/bazel/src/ng_package/rollup_bin.js')) {
88+
shelljs.cat(path.join(__dirname, './rollup_windows_arguments.patch')).exec('patch -p0');
89+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
diff --git node_modules/@angular/bazel/src/ng_package/_BUILD.bazel node_modules/@angular/bazel/src/ng_package/_BUILD.bazel
2+
index e7cf3d9..1887e95 100644
3+
--- node_modules/@angular/bazel/src/ng_package/_BUILD.bazel
4+
+++ node_modules/@angular/bazel/src/ng_package/_BUILD.bazel
5+
@@ -2,6 +2,14 @@ package(default_visibility = ["//visibility:public"])
6+
7+
load("@build_bazel_rules_nodejs//:defs.bzl", "nodejs_binary")
8+
9+
+nodejs_binary(
10+
+ name = "rollup_bin",
11+
+ entry_point = "rollup_bin.js",
12+
+ data = [
13+
+ "rollup_bin.js",
14+
+ ],
15+
+ node_modules = "@build_bazel_rules_nodejs_rollup_deps//:node_modules",
16+
+)
17+
18+
nodejs_binary(
19+
name = "packager",
20+
diff --git node_modules/@angular/bazel/src/ng_package/ng_package.bzl node_modules/@angular/bazel/src/ng_package/ng_package.bzl
21+
index f3104f0..bb0c04f 100644
22+
--- node_modules/@angular/bazel/src/ng_package/ng_package.bzl
23+
+++ node_modules/@angular/bazel/src/ng_package/ng_package.bzl
24+
@@ -102,6 +102,13 @@ def _rollup(ctx, bundle_name, rollup_config, entry_point, inputs, js_output, for
25+
map_output = ctx.actions.declare_file(js_output.basename + ".map", sibling = js_output)
26+
27+
args = ctx.actions.args()
28+
+
29+
+ # Pass arguments through a parameter file. This is necessary because on Windows there is
30+
+ # an argument limit and we there might be a lot of globals which need to be passed to
31+
+ # rollup. We always enable it because Bazel is not able to properly detect the argument limit.
32+
+ # Read more here: https://docs.bazel.build/versions/master/skylark/lib/Args.html#use_param_file
33+
+ args.use_param_file(param_file_arg = "%s", use_always = True)
34+
+
35+
args.add("--config", rollup_config)
36+
37+
args.add("--input", entry_point)
38+
@@ -435,7 +442,7 @@ NG_PACKAGE_ATTRS = dict(NPM_PACKAGE_ATTRS, **dict(ROLLUP_ATTRS, **{
39+
cfg = "host",
40+
),
41+
"_rollup": attr.label(
42+
- default = Label("@build_bazel_rules_nodejs//internal/rollup"),
43+
+ default = Label("@npm_angular_bazel//src/ng_package:rollup_bin"),
44+
executable = True,
45+
cfg = "host",
46+
),
47+
diff --git node_modules/@angular/bazel/src/ng_package/rollup_bin.js node_modules/@angular/bazel/src/ng_package/rollup_bin.js
48+
new file mode 100644
49+
index 0000000..9395677
50+
--- /dev/null
51+
+++ b/rollup_bin.js
52+
@@ -0,0 +1,11 @@
53+
+const fs = require('fs');
54+
+
55+
+const args = process.argv.slice(2);
56+
+const rollupArgs = fs.readFileSync(args[0], 'utf8').trim().split('\n');
57+
+
58+
+// Overwrite the process arguments so that the rollup binary uses the
59+
+// proper argument passed from the Bazel action.
60+
+process.argv = [process.argv[0], process.argv[1], ...rollupArgs];
61+
+
62+
+// Run rollup by requiring the binary entry-point.
63+
+require('rollup/bin/rollup');

0 commit comments

Comments
 (0)