Skip to content

Commit cf851ba

Browse files
acozzetteclaude
andcommitted
refactor: move bundler configs into tool runfiles for exec/target platform separation
For webpack and rollup invocations, configs and their npm plugin/loader dependencies now live in the tool binary's runfiles rather than being passed as target-platform action inputs. This ensures all exec-platform code runs from the same runfiles tree, avoiding resolution failures in cross-platform builds. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 2d7992c commit cf851ba

3 files changed

Lines changed: 66 additions & 37 deletions

File tree

examples/webpack_cli/BUILD.bazel

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
load("@aspect_rules_js//js:defs.bzl", "js_library", "js_test")
1+
load("@aspect_rules_js//js:defs.bzl", "js_library", "js_run_binary", "js_test")
22
load("@npm//:defs.bzl", "npm_link_all_packages")
33
load("@npm//webpack_cli:webpack-cli/package_json.bzl", "bin")
44

@@ -13,27 +13,37 @@ js_library(
1313
],
1414
deps = [
1515
":node_modules/@vanilla-extract/css",
16+
":node_modules/mathjs",
17+
],
18+
)
19+
20+
js_library(
21+
name = "webpack-config",
22+
srcs = ["webpack.config.js"],
23+
deps = [
1624
":node_modules/@vanilla-extract/webpack-plugin",
1725
":node_modules/css-loader",
18-
":node_modules/mathjs",
1926
":node_modules/mini-css-extract-plugin",
2027
],
2128
)
2229

23-
bin.webpack_cli(
24-
name = "bundle",
25-
srcs = [
26-
":lib",
27-
":webpack.config.js",
28-
],
29-
outs = [
30-
"dist/main.js",
31-
],
32-
args = [
33-
"--config webpack.config.js",
30+
bin.webpack_cli_binary(
31+
name = "webpack_cli_binary",
32+
data = [":webpack-config"],
33+
fixed_args = [
34+
"--config",
35+
"$$RUNFILES_DIR/$(rlocationpath :webpack-config)",
3436
],
37+
)
38+
39+
js_run_binary(
40+
name = "bundle",
41+
srcs = [":lib"],
42+
outs = ["dist/main.js"],
3543
chdir = package_name(),
3644
log_level = "debug",
45+
tool = ":webpack_cli_binary",
46+
use_execroot_entry_point = False,
3747
)
3848

3949
js_test(

js/private/worker/src/BUILD.bazel

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,48 @@
11
load("@npm//:defs.bzl", "npm_link_all_packages")
2+
load("//js:defs.bzl", "js_library", "js_run_binary")
23
load("@npm//js/private/worker/src:rollup/package_json.bzl", rollup_bin = "bin")
34

45
npm_link_all_packages()
56

6-
rollup_bin.rollup(
7-
name = "bundle",
8-
srcs = [
9-
"index.ts",
10-
"rollup.config.mjs",
11-
"size.ts",
12-
"worker_protocol.ts",
7+
js_library(
8+
name = "config",
9+
srcs = ["rollup.config.mjs"],
10+
deps = [
1311
":node_modules/@rollup/plugin-commonjs",
1412
":node_modules/@rollup/plugin-json",
1513
":node_modules/@rollup/plugin-node-resolve",
1614
":node_modules/@rollup/plugin-typescript",
1715
":node_modules/@types/google-protobuf",
1816
":node_modules/@types/node",
19-
":node_modules/google-protobuf",
2017
":node_modules/tslib",
2118
],
22-
outs = [
23-
"bundle.js",
24-
],
25-
args = [
19+
)
20+
21+
rollup_bin.rollup_binary(
22+
name = "rollup_binary",
23+
data = [":config"],
24+
fixed_args = [
2625
"index.ts",
2726
"--config",
28-
"rollup.config.mjs",
27+
"$$RUNFILES_DIR/$(rlocationpath :config)",
2928
"--format",
3029
"cjs",
3130
"--file",
3231
"bundle.js",
3332
],
33+
)
34+
35+
js_run_binary(
36+
name = "bundle",
37+
srcs = [
38+
"index.ts",
39+
"size.ts",
40+
"worker_protocol.ts",
41+
":node_modules/google-protobuf",
42+
],
43+
outs = ["bundle.js"],
3444
chdir = package_name(),
45+
tool = ":rollup_binary",
46+
use_execroot_entry_point = False,
3547
visibility = ["//js/private/worker:__pkg__"],
3648
)
Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
load("//js:defs.bzl", "js_run_binary")
12
load("@npm//npm/private/lifecycle:rollup/package_json.bzl", rollup_bin = "bin")
23

34
# Bundle our program with its dependencies, because they're large:
@@ -12,25 +13,31 @@ load("@npm//npm/private/lifecycle:rollup/package_json.bzl", rollup_bin = "bin")
1213
# └─────────────────┴──────────────┴────────┘
1314
# This avoids users having to fetch all those packages just to run the postinstall hooks.
1415

15-
rollup_bin.rollup(
16+
rollup_bin.rollup_binary(
17+
name = "rollup_binary",
18+
data = ["//npm/private/lifecycle:rollup_config"],
19+
fixed_args = [
20+
"lifecycle-hooks.js",
21+
"--config",
22+
"$$RUNFILES_DIR/$(rlocationpath //npm/private/lifecycle:rollup_config)",
23+
"--format",
24+
"cjs",
25+
"--file",
26+
"index.min.js",
27+
],
28+
)
29+
30+
js_run_binary(
1631
name = "bundle",
1732
srcs = [
1833
"lifecycle-hooks.js",
1934
"//npm/private/lifecycle:node_modules/@pnpm/lifecycle",
2035
"//npm/private/lifecycle:node_modules/@pnpm/logger",
2136
"//npm/private/lifecycle:node_modules/@pnpm/read-package-json",
22-
"//npm/private/lifecycle:rollup_config",
2337
],
2438
outs = ["index.min.js"],
25-
args = [
26-
"lifecycle-hooks.js",
27-
"--config",
28-
"../rollup.config.mjs",
29-
"--format",
30-
"cjs",
31-
"--file",
32-
"index.min.js",
33-
],
3439
chdir = package_name(),
40+
tool = ":rollup_binary",
41+
use_execroot_entry_point = False,
3542
visibility = ["//npm/private/lifecycle:__subpackages__"],
3643
)

0 commit comments

Comments
 (0)