Skip to content

Commit

Permalink
fix(builtin): always install source-map-support (#2538)
Browse files Browse the repository at this point in the history
We previously did this when patch_module_resolver was the default, because it had some extra (unrelated) logic at the end to install it.
When we flipped the default in 3.0, we accidentally dropped the feature.

This just reinstates it using the source-map-support/register feature.
Similarly to our prior implementation, we just call our own vendored source-map-support so users don't have to think about it.

Also fix missing docs for npm_package_bin attrs stdout,stderr,exit_code_out

Fixes #2520
  • Loading branch information
alexeagle authored Mar 17, 2021
1 parent bfd74e5 commit 97b3886
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 0 deletions.
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}
`);
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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require('./').install({environment: 'node'})

0 comments on commit 97b3886

Please sign in to comment.