Skip to content

Commit 97b3886

Browse files
authored
fix(builtin): always install source-map-support (#2538)
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
1 parent bfd74e5 commit 97b3886

File tree

7 files changed

+44
-0
lines changed

7 files changed

+44
-0
lines changed

internal/node/launcher.sh

+3
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,9 @@ else
353353
MAIN=TEMPLATED_entry_point_manifest_path
354354
fi
355355
fi
356+
# Always set up source-map-support using our vendored copy, just like the require_patch_script
357+
register_source_map_support=$(rlocation build_bazel_rules_nodejs/third_party/github.com/source-map-support/register.js)
358+
LAUNCHER_NODE_OPTIONS+=( "--require" "${register_source_map_support}" )
356359
fi
357360

358361
# The EXPECTED_EXIT_CODE lets us write bazel tests which assert that

internal/node/npm_package_bin.bzl

+6
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ def npm_package_bin(
103103
env = {},
104104
outs = [],
105105
args = [],
106+
stderr = None,
107+
stdout = None,
108+
exit_code_out = None,
106109
output_dir = False,
107110
link_workspace_root = False,
108111
chdir = None,
@@ -220,6 +223,9 @@ def npm_package_bin(
220223
args = args,
221224
chdir = chdir,
222225
env = env,
226+
stdout = stdout,
227+
stderr = stderr,
228+
exit_code_out = exit_code_out,
223229
output_dir = output_dir,
224230
tool = tool,
225231
link_workspace_root = link_workspace_root,
+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
load("@build_bazel_rules_nodejs//:index.bzl", "nodejs_binary", "nodejs_test", "npm_package_bin")
2+
3+
nodejs_binary(
4+
name = "bin",
5+
entry_point = "index.js",
6+
)
7+
8+
npm_package_bin(
9+
name = "run",
10+
# throw away the exit code, so this action succeeds despite the program exiting 1
11+
exit_code_out = "ignore_exit_code",
12+
# this is where the stack trace appears
13+
stderr = "actual",
14+
stdout = "ignore_stdout",
15+
tool = "bin",
16+
)
17+
18+
nodejs_test(
19+
name = "test",
20+
data = ["actual"],
21+
entry_point = "test.js",
22+
)

internal/node/test/sourcemap/index.js

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/node/test/sourcemap/test.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
const runfiles = require(process.env['BAZEL_NODE_RUNFILES_HELPER']);
2+
3+
const actual = require('fs').readFileSync(runfiles.resolvePackageRelative('actual'));
4+
5+
require('assert').ok(actual.includes('index.ts:1'), `source map support is not installed
6+
expected stack trace to point to line 1 of index.ts but instead got
7+
${actual}
8+
`);

third_party/github.com/source-map-support/BUILD.bazel

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ exports_files(["LICENSE"])
88

99
_CONTENT = [
1010
"package.json",
11+
"register.js",
1112
"source-map-support.js",
1213
]
1314

Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
require('./').install({environment: 'node'})

0 commit comments

Comments
 (0)