Skip to content
This repository was archived by the owner on Oct 4, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion nodejs/rules.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,11 @@ def _nodejs_binary_impl(ctx):
runfiles = runfiles,
)

return [default_info]
# PnP resolves this binary's modules without materializing node_modules, so
# a filesystem view of the package tree no longer exists. Forward the
# CommonJS graph -- in the binary's own configuration -- for rules that
# still need one, such as webpack_server.
return [default_info] + ([cjs_dep] if cjs_dep else [])

def _nodejs_transition_impl(settings, attrs):
return {"//javascript:module": "node"}
Expand Down
1 change: 1 addition & 0 deletions webpack/providers.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ WebpackInfo = provider(
fields = {
"bin": "Webpack executable",
"server": "Webpack server executable",
"server_cjs": "Webpack server CommonJS packages",
"client_cjs": "Webpack dev server lib",
"client_js": "Webpack dev server lib",
"config_path": "Config path",
Expand Down
23 changes: 23 additions & 0 deletions webpack/rules.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,15 @@ def _webpack_impl(ctx):
config = ctx.attr.config
config_dep = ctx.attr.config_dep[CjsInfo]
server = ctx.attr.server[DefaultInfo]
server_cjs = ctx.attr.server[CjsInfo]

webpack_info = WebpackInfo(
bin = bin,
client_cjs = client_cjs,
client_js = client_js,
config_path = "%s/%s" % (to_rlocation_path(ctx, config_dep.package), config),
server = server,
server_cjs = server_cjs,
)

return [webpack_info]
Expand Down Expand Up @@ -76,6 +78,7 @@ webpack = rule(
cfg = "exec",
executable = True,
mandatory = True,
providers = [CjsInfo],
),
"client": attr.label_list(
mandatory = True,
Expand Down Expand Up @@ -270,6 +273,7 @@ def _webpack_server_impl(ctx):
source_map = ctx.attr._source_map[BuildSettingInfo].value
webpack = ctx.split_attr.webpack["tool"][WebpackInfo]
webpack_client = ctx.split_attr.webpack["browser"][WebpackInfo]
server_cjs = webpack.server_cjs
dep_js = ctx.attr.dep[0][JsInfo]
dep_cjs = ctx.attr.dep[0][CjsInfo]
name = ctx.attr.name
Expand Down Expand Up @@ -299,6 +303,23 @@ def _webpack_server_impl(ctx):
package_path = package_path,
)

def node_package_path(package):
return to_rlocation_path(rlocation_ctx, package)

# The webpack tools resolve their own modules through PnP, but the dev
# server bundles files out of that tree -- webpack's hot client and the
# entries plugins inject -- and webpack resolves those from the filesystem.
# The shim links the tree back in from this manifest.
node_package_manifest = actions.declare_file("%s-node-packages.json" % name)
gen_manifest(
actions = actions,
manifest_bin = ctx.attr._manifest[DefaultInfo],
manifest = node_package_manifest,
packages = server_cjs.transitive_packages,
deps = server_cjs.transitive_links,
package_path = node_package_path,
)

js_info = JsInfo(
transitive_files = depset(transitive = [js_info.transitive_files for js_info in [dep_js] + webpack_client.client_js]),
)
Expand All @@ -320,6 +341,7 @@ def _webpack_server_impl(ctx):
"%{digest}": shell.quote(to_rlocation_path(ctx, src_digest)),
"%{input_root}": shell.quote(package_path(dep_cjs.package)),
"%{js_source_map}": shell.quote(json.encode(source_map)),
"%{node_package_manifest}": shell.quote(to_rlocation_path(ctx, node_package_manifest)),
"%{package_manifest}": shell.quote(to_rlocation_path(ctx, package_manifest)),
"%{runtime}": shell.quote(to_rlocation_path(ctx, runtime)),
"%{shim}": shell.quote(to_rlocation_path(ctx, shim)),
Expand All @@ -339,6 +361,7 @@ def _webpack_server_impl(ctx):

runfiles = ctx.runfiles(
files = [
node_package_manifest,
package_manifest,
runtime,
shim,
Expand Down
1 change: 1 addition & 0 deletions webpack/server-runner.sh.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ function abspath () {
export COMPILATION_MODE=%{compilation_mode}
export NODE_OPTIONS_APPEND="-r $(abspath "$RUNFILES_DIR"/%{runtime}/index.js) -r $(abspath "$RUNFILES_DIR"/%{shim}/index.js)"
export JS_SOURCE_MAP=%{js_source_map}
export NODE_PACKAGE_MANIFEST="$RUNFILES_DIR"/%{node_package_manifest}
export WATCHPACK_POLLING=130929
export WEBPACK_CONFIG="$RUNFILES_DIR"/%{config}
export WEBPACK_DIGEST="$RUNFILES_DIR"/%{digest}
Expand Down
Loading