Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(builtin): fix for nodejs_binary entry point in bazel-out logic #1739

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
5 changes: 4 additions & 1 deletion internal/node/launcher.sh
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,10 @@ for ARG in "${ALL_ARGS[@]:-}"; do
case "$ARG" in
--bazel_node_modules_manifest=*) MODULES_MANIFEST="${ARG#--bazel_node_modules_manifest=}" ;;
--nobazel_patch_module_resolver)
MAIN="TEMPLATED_script_path"
declare MAIN=$(rlocation "TEMPLATED_entry_point_manifest_path")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How did we never see this bug before?? We've had entry_point pointing to bazel-out for a while haven't we? or is this the first time we are trying to do that without the patched module resolver?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know. I was surprised as well. We always had main.ts as the entry point of which was renamed to main.js by the rule & the parched resolver always found it.

if [[ ! -f "$MAIN" ]]; then
MAIN="TEMPLATED_entry_point_execroot_path"
fi
LAUNCHER_NODE_OPTIONS=( "--require" "$node_patches_script" )

# In this case we should always run the linker
Expand Down
3 changes: 2 additions & 1 deletion internal/node/node.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,8 @@ def _nodejs_binary_impl(ctx):
expand_location_into_runfiles(ctx, a, ctx.attr.data)
for a in ctx.attr.templated_args
]),
"TEMPLATED_entry_point_execroot_path": _to_execroot_path(ctx, ctx.file.entry_point),
"TEMPLATED_entry_point_manifest_path": _to_manifest_path(ctx, ctx.file.entry_point),
"TEMPLATED_env_vars": env_vars,
"TEMPLATED_expected_exit_code": str(expected_exit_code),
"TEMPLATED_link_modules_script": _to_manifest_path(ctx, ctx.file._link_modules_script),
Expand All @@ -225,7 +227,6 @@ def _nodejs_binary_impl(ctx):
"TEMPLATED_repository_args": _to_manifest_path(ctx, ctx.file._repository_args),
"TEMPLATED_require_patch_script": _to_manifest_path(ctx, ctx.outputs.require_patch_script),
"TEMPLATED_runfiles_helper_script": _to_manifest_path(ctx, ctx.file._runfiles_helper_script),
"TEMPLATED_script_path": _to_execroot_path(ctx, ctx.file.entry_point),
"TEMPLATED_vendored_node": "" if is_builtin else strip_external(ctx.file._node.path),
}
ctx.actions.expand_template(
Expand Down
26 changes: 26 additions & 0 deletions internal/node/test/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
load("@build_bazel_rules_nodejs//:index.bzl", "nodejs_binary", "nodejs_test", "npm_package_bin")
load("@build_bazel_rules_nodejs//internal/golden_file_test:golden_file_test.bzl", "golden_file_test")
load("@npm//typescript:index.bzl", "tsc")
load("//internal/js_library:js_library.bzl", "js_library")
load("//internal/node:node_repositories.bzl", "BUILT_IN_NODE_PLATFORMS")
load("//third_party/github.com/bazelbuild/bazel-skylib:rules/copy_file.bzl", "copy_file")
Expand Down Expand Up @@ -342,3 +343,28 @@ nodejs_test(
entry_point = "empty_args_fail.js",
expected_exit_code = 0,
)

tsc(
name = "main_lib",
outs = [
"main.js",
],
args = [
"-p",
"$(execpath tsconfig.json)",
"--outDir",
# $(RULEDIR) is a shorthand for the dist/bin directory where Bazel requires we write outputs
"$(RULEDIR)",
],
data = [
"main.ts",
"tsconfig.json",
],
)

nodejs_test(
name = "main_test",
data = [":main_lib"],
entry_point = ":main.js",
templated_args = ["--nobazel_patch_module_resolver"],
)
1 change: 1 addition & 0 deletions internal/node/test/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('hello world' as string);
3 changes: 3 additions & 0 deletions internal/node/test/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"include": ["main.ts"]
}