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): always install source-map-support #2538

Merged
merged 1 commit into from
Mar 17, 2021
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
3 changes: 3 additions & 0 deletions internal/node/launcher.sh
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,9 @@ 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}" )
fi

# The EXPECTED_EXIT_CODE lets us write bazel tests which assert that
Expand Down
6 changes: 6 additions & 0 deletions internal/node/npm_package_bin.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ def npm_package_bin(
env = {},
outs = [],
args = [],
stderr = None,
stdout = None,
exit_code_out = None,
output_dir = False,
link_workspace_root = False,
chdir = None,
Expand Down Expand Up @@ -220,6 +223,9 @@ def npm_package_bin(
args = args,
chdir = chdir,
env = env,
stdout = stdout,
stderr = stderr,
exit_code_out = exit_code_out,
output_dir = output_dir,
tool = tool,
link_workspace_root = link_workspace_root,
Expand Down
22 changes: 22 additions & 0 deletions internal/node/test/sourcemap/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
load("@build_bazel_rules_nodejs//:index.bzl", "nodejs_binary", "nodejs_test", "npm_package_bin")

nodejs_binary(
name = "bin",
entry_point = "index.js",
)

npm_package_bin(
name = "run",
# throw away the exit code, so this action succeeds despite the program exiting 1
exit_code_out = "ignore_exit_code",
# this is where the stack trace appears
stderr = "actual",
stdout = "ignore_stdout",
tool = "bin",
)

nodejs_test(
name = "test",
data = ["actual"],
entry_point = "test.js",
)
3 changes: 3 additions & 0 deletions internal/node/test/sourcemap/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions internal/node/test/sourcemap/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const runfiles = require(process.env['BAZEL_NODE_RUNFILES_HELPER']);

const actual = require('fs').readFileSync(runfiles.resolvePackageRelative('actual'));

require('assert').ok(actual.includes('index.ts:1'), `source map support is not installed
expected stack trace to point to line 1 of index.ts but instead got
${actual}
`);
1 change: 1 addition & 0 deletions third_party/github.com/source-map-support/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ exports_files(["LICENSE"])

_CONTENT = [
"package.json",
"register.js",
"source-map-support.js",
]

Expand Down
1 change: 1 addition & 0 deletions third_party/github.com/source-map-support/register.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require('./').install({environment: 'node'})