Skip to content

Commit

Permalink
fix(builtin): always install source-map-support
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.

Fixes bazel-contrib#2520
  • Loading branch information
Alex Eagle committed Mar 17, 2021
1 parent 09be982 commit 8009917
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 0 deletions.
1 change: 1 addition & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ pkg_npm(
"BUILD.bazel",
"LICENSE",
"rules_sass.issue127.patch",
"WORKSPACE",
],
substitutions = COMMON_REPLACEMENTS,
deps = [
Expand Down
4 changes: 4 additions & 0 deletions internal/node/launcher.sh
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,10 @@ else
MAIN=TEMPLATED_entry_point_manifest_path
fi
fi
# Just like the require_patch_script always sets up source-map-support,
# do the same here.
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",
)
4 changes: 4 additions & 0 deletions internal/node/test/sourcemap/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
'use strict';
throw new Error('here');
//#
// sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsTUFBTSxJQUFJLEtBQUssQ0FBQyxNQUFNLENBQUMsQ0FBQyIsInNvdXJjZXNDb250ZW50IjpbInRocm93IG5ldyBFcnJvcihcImhlcmVcIik7XG4iXX0=
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'})

0 comments on commit 8009917

Please sign in to comment.