-
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ filegroup( | |
srcs = [ | ||
"a.ts", | ||
"b.ts", | ||
"sub/c.ts", | ||
], | ||
) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const c: string = "c"; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const c: string = "c"; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
{ | ||
"private": true | ||
"private": true, | ||
"dependencies": { | ||
"source-map-support": "^0.5.21" | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ swc( | |
srcs = [ | ||
"src/a.ts", | ||
"src/b.ts", | ||
"src/sub/c.ts", | ||
], | ||
out_dir = "out", | ||
root_dir = "src", | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const c: string = "c"; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
load("@aspect_bazel_lib//lib:copy_to_bin.bzl", "copy_to_bin") | ||
|
||
exports_files([ | ||
"defs.bzl", | ||
]) | ||
|
||
copy_to_bin( | ||
name = "stack-trace-support", | ||
srcs = ["stack-trace-support.js"], | ||
visibility = ["//visibility:public"], | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
""" | ||
Macro wrappers around rules_js's `js_binary` and `js_test` that improve the DX of stack traces by automatically | ||
registering source-map-support and removing the runfiles directory prefix. | ||
Use them wherever you would use rules_js's `js_binary` and `js_test`. | ||
""" | ||
|
||
load("@aspect_rules_js//js:defs.bzl", _js_binary = "js_binary", _js_test = "js_test") | ||
|
||
def js_binary(data = [], node_options = [], **kwargs): | ||
_js_binary( | ||
data = [ | ||
"//examples:node_modules/source-map-support", | ||
"//examples/source_map_support:stack-trace-support", | ||
] + data, | ||
node_options = ["--require", "$$RUNFILES/aspect_rules_swc/examples/source_map_support/stack-trace-support"] + node_options, | ||
**kwargs | ||
) | ||
|
||
def js_test(data = [], node_options = [], **kwargs): | ||
_js_test( | ||
data = [ | ||
"//examples:node_modules/source-map-support", | ||
"//examples/source_map_support:stack-trace-support", | ||
] + data, | ||
node_options = ["--require", "$$RUNFILES/aspect_rules_swc/examples/source_map_support/stack-trace-support"] + node_options, | ||
**kwargs | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// See defs.bzl for where this is used and what it does. | ||
|
||
require('source-map-support/register') | ||
|
||
let basePath = process.env.RUNFILES | ||
? `${process.env.RUNFILES}/${process.env.JS_BINARY__WORKSPACE}` | ||
: process.cwd() | ||
|
||
if (!basePath.endsWith('/')) { | ||
basePath = basePath + '/' | ||
} | ||
|
||
/* | ||
Before: | ||
Error: test | ||
at foo (/private/var/tmp/_bazel_john/67beefda950d56283b98d96980e6e332/execroot/figma/bazel-out/darwin_arm64-fastbuild/bin/bazel/js/test/stack_trace_support.sh.runfiles/figma/bazel/js/test/b.js:2:11) | ||
at Object.<anonymous> (/private/var/tmp/_bazel_john/67beefda950d56283b98d96980e6e332/execroot/figma/bazel-out/darwin_arm64-fastbuild/bin/bazel/js/test/stack_trace_support.sh.runfiles/figma/bazel/js/test/a.js:4:1) | ||
... | ||
After: | ||
Error: test | ||
at foo (bazel/js/test/b.ts:2:9) | ||
at Object.<anonymous> (bazel/js/test/a.ts:5:1) | ||
... | ||
*/ | ||
|
||
const basePathRegex = new RegExp( | ||
`(at | \\()${basePath | ||
.replace(/\\/g, '/') | ||
// Escape regex meta-characters. | ||
.replace(/[|\\{}()[\]^$+*?.]/g, '\\$&') | ||
.replace(/-/g, '\\x2d')}`, | ||
'g', | ||
) | ||
|
||
const prepareStackTrace = Error.prepareStackTrace | ||
Error.prepareStackTrace = function (error, stack) { | ||
return prepareStackTrace(error, stack) | ||
.split('\n') | ||
.map((line) => line.replace(basePathRegex, '$1')) | ||
.join('\n') | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
load("@aspect_rules_swc//swc:defs.bzl", "swc") | ||
load("//examples/source_map_support:defs.bzl", "js_test") | ||
|
||
swc( | ||
name = "compile", | ||
srcs = [ | ||
"a.ts", | ||
"b.ts", | ||
], | ||
source_maps = True, | ||
) | ||
|
||
js_test( | ||
name = "stack_trace_support_test", | ||
data = [":compile"], | ||
entry_point = ":a.js", | ||
) | ||
|
||
js_test( | ||
name = "stack_trace_support_with_chdir_test", | ||
chdir = "examples", | ||
data = [":compile"], | ||
entry_point = ":a.js", | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
try { | ||
require('./b')() | ||
} catch (e) { | ||
const assert = require('assert') | ||
const frames = e.stack | ||
.split('\n') | ||
.slice(1) | ||
.map((s) => s.trim()) | ||
assert.deepEqual( | ||
frames.filter((f) => f.includes('source_map_support/test/a')), | ||
[`at Object.<anonymous> (examples/source_map_support/test/a.ts:2:11)`], | ||
) | ||
assert.deepEqual( | ||
frames.filter((f) => f.includes('source_map_support/test/b')), | ||
[`at foo (examples/source_map_support/test/b.ts:2:9)`], | ||
) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = function foo() { | ||
throw new Error('test') | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.