Skip to content
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
20 changes: 7 additions & 13 deletions internal/node/launcher.sh
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ else
fi
fi

MAIN="${RUNFILES}/TEMPLATED_entry_point_manifest"

# Export the location of the runfiles helpers script
export BAZEL_NODE_RUNFILES_HELPER=$(rlocation "TEMPLATED_runfiles_helper_script")
# Paths can be with lower and upper case on windows because of the msys64 package in the powershell
Expand Down Expand Up @@ -214,6 +216,11 @@ for ARG in ${ALL_ARGS[@]+"${ALL_ARGS[@]}"}; do
--bazel_node_working_dir=*) NODE_WORKING_DIR="${ARG#--bazel_node_working_dir=}" ;;
# Let users pass through arguments to node itself
--node_options=*) USER_NODE_OPTIONS+=( "${ARG#--node_options=}" ) ;;
# Legacy execroot references
--bazel_use_legacy_execroot_paths__variant_rlocation_main) \
MAIN=$(rlocation "TEMPLATED_entry_point_manifest") ;;
--bazel_use_legacy_execroot_paths__variant_execroot_main) \
MAIN="${PWD}/"TEMPLATED_entry_point_execroot_path ;;
# Remaining argv is collected to pass to the program
*) ARGS+=( "$ARG" )
esac
Expand Down Expand Up @@ -348,22 +355,9 @@ if [ "$PATCH_REQUIRE" = true ]; then
# Change the entry point to be the loader.js script so we run code before node
MAIN=$(rlocation "TEMPLATED_loader_script")
else
# Entry point is the user-supplied script
MAIN="${PWD}/"TEMPLATED_entry_point_execroot_path
# TODO: after we link-all-bins we should not need this extra lookup
if [[ ! -f "$MAIN" ]]; then
if [ "$FROM_EXECROOT" = true ]; then
MAIN="$EXECROOT/"TEMPLATED_entry_point_execroot_path
else
MAIN=TEMPLATED_entry_point_manifest_path
fi
fi
# Always set up source-map-support using our vendored copy, just like the require_patch_script
register_source_map_support=$(rlocation build_bazel_rules_nodejs/third_party/github.com/source-map-support/register.js)
LAUNCHER_NODE_OPTIONS+=( "--require" "${register_source_map_support}" )
if [[ -n "TEMPLATED_entry_point_main" ]]; then
MAIN="${MAIN}/"TEMPLATED_entry_point_main
fi
fi

# The EXPECTED_EXIT_CODE lets us write bazel tests which assert that
Expand Down
3 changes: 1 addition & 2 deletions internal/node/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ if (require.main === module) {
// argv[0] == node, argv[1] == entry point.
// NB: 'TEMPLATED_entry_point_path' & 'TEMPLATED_entry_point' below are replaced during the build process.
var entryPointPath = 'TEMPLATED_entry_point_path';
var entryPointMain = 'TEMPLATED_entry_point_main';
var mainScript = process.argv[1] = entryPointMain ? `${entryPointPath}/${entryPointMain}` : entryPointPath;
var mainScript = process.argv[1] = entryPointPath;
try {
module.constructor._load(mainScript, this, /*isMain=*/true);
} catch (e) {
Expand Down
17 changes: 4 additions & 13 deletions internal/node/node.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,7 @@ def _write_loader_script(ctx):
substitutions = {}
substitutions["TEMPLATED_entry_point_path"] = _ts_to_js(_to_manifest_path(ctx, _get_entry_point_file(ctx)))
if DirectoryFilePathInfo in ctx.attr.entry_point:
substitutions["TEMPLATED_entry_point_main"] = ctx.attr.entry_point[DirectoryFilePathInfo].path
else:
substitutions["TEMPLATED_entry_point_main"] = ""
fail("Not supported")

ctx.actions.expand_template(
template = ctx.file._loader_template,
Expand Down Expand Up @@ -317,18 +315,11 @@ fi
"TEMPLATED_vendored_node": "" if is_builtin else strip_external(ctx.file._node.path),
}

# TODO when we have "link_all_bins" we will only need to look in one place for the entry point
#if ctx.file.entry_point.is_source:
# substitutions["TEMPLATED_script_path"] = "\"%s\"" % _to_execroot_path(ctx, ctx.file.entry_point)
#else:
# substitutions["TEMPLATED_script_path"] = "$(rlocation \"%s\")" % _to_manifest_path(ctx, ctx.file.entry_point)
# For now we need to look in both places
substitutions["TEMPLATED_entry_point_manifest"] = _ts_to_js(_to_manifest_path(ctx, _get_entry_point_file(ctx)))
# Needed for tests using legacy implementation
substitutions["TEMPLATED_entry_point_execroot_path"] = "\"%s\"" % _ts_to_js(_to_execroot_path(ctx, _get_entry_point_file(ctx)))
substitutions["TEMPLATED_entry_point_manifest_path"] = "$(rlocation \"%s\")" % _ts_to_js(_to_manifest_path(ctx, _get_entry_point_file(ctx)))
if DirectoryFilePathInfo in ctx.attr.entry_point:
substitutions["TEMPLATED_entry_point_main"] = ctx.attr.entry_point[DirectoryFilePathInfo].path
else:
substitutions["TEMPLATED_entry_point_main"] = ""
fail("Not supported")

ctx.actions.expand_template(
template = ctx.file._launcher_template,
Expand Down