Skip to content

Commit 51c56df

Browse files
authored
Use source-map-support that's vendored in (bazel-contrib#476)
Changed source-map-support to support bazel workspaces to produces shorter readable stacks that help in navigating to the code directly in an editor like VSCode. Tested with angular/angular repo and VSCode.
1 parent 3338d53 commit 51c56df

27 files changed

Lines changed: 4269 additions & 16 deletions

‎internal/jasmine_node_test/test/BUILD.bazel‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ jasmine_node_test(
2626

2727
nodejs_test(
2828
name = "no_jasmine_test",
29-
entry_point = "build_bazel_rules_nodejs/internal/jasmine_node_test/test/no_jasmine_test.js",
3029
data = [
3130
"no_jasmine_test.js",
32-
"//internal/jasmine_node_test:jasmine_runner.js"
31+
"//internal/jasmine_node_test:jasmine_runner.js",
3332
],
33+
entry_point = "build_bazel_rules_nodejs/internal/jasmine_node_test/test/no_jasmine_test.js",
3434
)

‎internal/node/node.bzl‎

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ def _nodejs_binary_impl(ctx):
152152
executable = ctx.outputs.script,
153153
runfiles = ctx.runfiles(
154154
transitive_files = runfiles,
155-
files = [node, ctx.outputs.loader] + node_modules + sources,
155+
files = [node, ctx.outputs.loader] + ctx.files._source_map_support_files + node_modules + sources,
156156
collect_data = True,
157157
),
158158
)]
@@ -284,6 +284,14 @@ _NODEJS_EXECUTABLE_ATTRS = {
284284
default = Label("@nodejs//:bin/node_args.sh"),
285285
allow_single_file = True,
286286
),
287+
"_source_map_support_files": attr.label_list(
288+
default = [
289+
Label("//third_party/github.com/buffer-from:contents"),
290+
Label("//third_party/github.com/source-map:contents"),
291+
Label("//third_party/github.com/source-map-support:contents"),
292+
],
293+
allow_files = True,
294+
),
287295
}
288296

289297
_NODEJS_EXECUTABLE_OUTPUTS = {
@@ -355,9 +363,11 @@ def nodejs_binary_macro(name, data = [], args = [], visibility = None, tags = []
355363
testonly: applied to nodejs_binary and wrapper binary
356364
**kwargs: passed to the nodejs_binary
357365
"""
366+
all_data = data + ["@bazel_tools//tools/bash/runfiles"]
367+
358368
nodejs_binary(
359369
name = "%s_bin" % name,
360-
data = data + ["@bazel_tools//tools/bash/runfiles"],
370+
data = all_data,
361371
testonly = testonly,
362372
visibility = ["//visibility:private"],
363373
**kwargs
@@ -387,9 +397,11 @@ def nodejs_test_macro(name, data = [], args = [], visibility = None, tags = [],
387397
tags: applied to the wrapper binary
388398
**kwargs: passed to the nodejs_test
389399
"""
400+
all_data = data + ["@bazel_tools//tools/bash/runfiles"]
401+
390402
nodejs_test(
391403
name = "%s_bin" % name,
392-
data = data + ["@bazel_tools//tools/bash/runfiles"],
404+
data = all_data,
393405
testonly = 1,
394406
tags = ["manual"],
395407
**kwargs

‎internal/node/node_loader.js‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -459,12 +459,16 @@ module.constructor._resolveFilename = function(request, parent) {
459459
// source-map-support.
460460
if (TEMPLATED_install_source_map_support) {
461461
try {
462-
require('source-map-support').install();
463-
} catch (e) {
464-
console.error(`WARNING: source-map-support module not installed.
465-
Stack traces from languages like TypeScript will point to generated .js files.
466-
Set install_source_map_support = False in TEMPLATED_target to turn off this warning.
467-
`);
462+
const sourcemap_support_package = path.resolve(process.cwd(),
463+
'../build_bazel_rules_nodejs/third_party/github.com/source-map-support');
464+
require(sourcemap_support_package).install();
465+
} catch (_) {
466+
if (DEBUG) {
467+
console.error(`WARNING: source-map-support module not installed.
468+
Stack traces from languages like TypeScript will point to generated .js files.
469+
Set install_source_map_support = False in TEMPLATED_target to turn off this warning.
470+
`);
471+
}
468472
}
469473
}
470474
// Load all bootstrap modules before loading the entrypoint.

‎internal/node/node_repositories.bzl‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -405,18 +405,21 @@ if %errorlevel% neq 0 exit /b %errorlevel%
405405
]), executable = True)
406406

407407
# Generate build file for this repository - exposes the node runtime and utilities generated above.
408-
repository_ctx.template("generate_build_file.js",
409-
repository_ctx.path(Label("//internal/node:generate_build_file.js")), {
410-
"TEMPLATED_is_windows": 'true' if is_windows else 'false',
408+
repository_ctx.template(
409+
"generate_build_file.js",
410+
repository_ctx.path(Label("//internal/node:generate_build_file.js")),
411+
{
412+
"TEMPLATED_is_windows": "true" if is_windows else "false",
411413
"TEMPLATED_node_actual": node_entry,
412414
"TEMPLATED_node_dir": NODE_DIR,
413415
"TEMPLATED_npm_actual": npm_node_repositories_entry,
414416
"TEMPLATED_yarn_actual": yarn_node_repositories_entry,
415417
"TEMPLATED_yarn_dir": YARN_DIR,
416-
})
418+
},
419+
)
417420
result = repository_ctx.execute([node_entry, "generate_build_file.js"])
418421
if result.return_code:
419-
fail("node failed: \nSTDOUT:\n%s\nSTDERR:\n%s" % (result.stdout, result.stderr))
422+
fail("node failed: \nSTDOUT:\n%s\nSTDERR:\n%s" % (result.stdout, result.stderr))
420423

421424
def _nodejs_repo_impl(repository_ctx):
422425
_download_node(repository_ctx)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
## Stub BUILD file to export all contents.
2+
3+
package(default_visibility = ["//visibility:public"])
4+
5+
licenses(["notice"])
6+
7+
exports_files(["LICENSE"])
8+
9+
_CONTENT = [
10+
"package.json",
11+
"index.js",
12+
]
13+
14+
filegroup(
15+
name = "contents",
16+
srcs = _CONTENT,
17+
)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2016, 2018 Linus Unnebäck
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
var toString = Object.prototype.toString
2+
3+
var isModern = (
4+
typeof Buffer.alloc === 'function' &&
5+
typeof Buffer.allocUnsafe === 'function' &&
6+
typeof Buffer.from === 'function'
7+
)
8+
9+
function isArrayBuffer (input) {
10+
return toString.call(input).slice(8, -1) === 'ArrayBuffer'
11+
}
12+
13+
function fromArrayBuffer (obj, byteOffset, length) {
14+
byteOffset >>>= 0
15+
16+
var maxLength = obj.byteLength - byteOffset
17+
18+
if (maxLength < 0) {
19+
throw new RangeError("'offset' is out of bounds")
20+
}
21+
22+
if (length === undefined) {
23+
length = maxLength
24+
} else {
25+
length >>>= 0
26+
27+
if (length > maxLength) {
28+
throw new RangeError("'length' is out of bounds")
29+
}
30+
}
31+
32+
return isModern
33+
? Buffer.from(obj.slice(byteOffset, byteOffset + length))
34+
: new Buffer(new Uint8Array(obj.slice(byteOffset, byteOffset + length)))
35+
}
36+
37+
function fromString (string, encoding) {
38+
if (typeof encoding !== 'string' || encoding === '') {
39+
encoding = 'utf8'
40+
}
41+
42+
if (!Buffer.isEncoding(encoding)) {
43+
throw new TypeError('"encoding" must be a valid string encoding')
44+
}
45+
46+
return isModern
47+
? Buffer.from(string, encoding)
48+
: new Buffer(string, encoding)
49+
}
50+
51+
function bufferFrom (value, encodingOrOffset, length) {
52+
if (typeof value === 'number') {
53+
throw new TypeError('"value" argument must not be a number')
54+
}
55+
56+
if (isArrayBuffer(value)) {
57+
return fromArrayBuffer(value, encodingOrOffset, length)
58+
}
59+
60+
if (typeof value === 'string') {
61+
return fromString(value, encodingOrOffset)
62+
}
63+
64+
return isModern
65+
? Buffer.from(value)
66+
: new Buffer(value)
67+
}
68+
69+
module.exports = bufferFrom
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
{
2+
"_from": "buffer-from@^1.0.0",
3+
"_id": "buffer-from@1.1.1",
4+
"_inBundle": false,
5+
"_integrity": "sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A==",
6+
"_location": "/buffer-from",
7+
"_phantomChildren": {},
8+
"_requested": {
9+
"type": "range",
10+
"registry": true,
11+
"raw": "buffer-from@^1.0.0",
12+
"name": "buffer-from",
13+
"escapedName": "buffer-from",
14+
"rawSpec": "^1.0.0",
15+
"saveSpec": null,
16+
"fetchSpec": "^1.0.0"
17+
},
18+
"_requiredBy": [
19+
"/source-map-support"
20+
],
21+
"_resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.1.tgz",
22+
"_shasum": "32713bc028f75c02fdb710d7c7bcec1f2c6070ef",
23+
"_spec": "buffer-from@^1.0.0",
24+
"_where": "/Users/viks/rules_nodejs/node_modules/source-map-support",
25+
"bugs": {
26+
"url": "https://github.com/LinusU/buffer-from/issues"
27+
},
28+
"bundleDependencies": false,
29+
"deprecated": false,
30+
"description": "A [ponyfill](https://ponyfill.com) for `Buffer.from`, uses native implementation if available.",
31+
"devDependencies": {
32+
"standard": "^7.1.2"
33+
},
34+
"files": [
35+
"index.js"
36+
],
37+
"homepage": "https://github.com/LinusU/buffer-from#readme",
38+
"keywords": [
39+
"buffer",
40+
"buffer from"
41+
],
42+
"license": "MIT",
43+
"name": "buffer-from",
44+
"repository": {
45+
"type": "git",
46+
"url": "git+https://github.com/LinusU/buffer-from.git"
47+
},
48+
"scripts": {
49+
"test": "standard && node test"
50+
},
51+
"version": "1.1.1"
52+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
## Stub BUILD file to export all contents.
2+
3+
package(default_visibility = ["//visibility:public"])
4+
5+
licenses(["notice"])
6+
7+
exports_files(["LICENSE"])
8+
9+
_CONTENT = [
10+
"package.json",
11+
"source-map-support.js",
12+
]
13+
14+
filegroup(
15+
name = "contents",
16+
srcs = _CONTENT,
17+
)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2014 Evan Wallace
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

0 commit comments

Comments
 (0)