-
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: align pre-calculated outputs with rules_ts
- Loading branch information
Showing
4 changed files
with
135 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"jsc": { | ||
"parser": { | ||
"syntax": "typescript" | ||
} | ||
}, | ||
"sourceMaps": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
load("@aspect_rules_swc//swc:defs.bzl", "swc") | ||
load("@bazel_skylib//rules:build_test.bzl", "build_test") | ||
|
||
genrule( | ||
name = "a", | ||
outs = ["a.ts"], | ||
cmd = "echo 'export const a: string = \"a\";' > $@", | ||
) | ||
|
||
genrule( | ||
name = "b", | ||
outs = ["b.ts"], | ||
cmd = "echo 'export const b: string = \"b\";' > $@", | ||
) | ||
|
||
genrule( | ||
name = "c", | ||
outs = ["sub/c.ts"], | ||
cmd = "echo 'export const c: string = \"c\";' > $@", | ||
) | ||
|
||
swc( | ||
name = "compile", | ||
srcs = [ | ||
"b.ts", | ||
":a", | ||
":sub/c.ts", | ||
], # reference by label, output file, :outputfile | ||
source_maps = True, | ||
swcrc = ".swcrc", | ||
) | ||
|
||
build_test( | ||
name = "predeclared_test", | ||
targets = [ | ||
"b.js", | ||
"b.js.map", | ||
"sub/c.js", | ||
"sub/c.js.map", | ||
], | ||
) | ||
|
||
# Since the srcs were in a filegroup, the swc macro cannot pre-declare the outputs. | ||
# So there is no label ":a.js" that we can reference from the build file. | ||
# However, a.js is still produced as one of the default outputs of the compile rule. | ||
# We can verify this in an action that depends on the ":compile" rule and reads the files. | ||
sh_test( | ||
name = "check_outputs", | ||
srcs = ["check_outputs.sh"], | ||
data = [":compile"], | ||
) | ||
|
||
swc( | ||
name = "compile2", | ||
srcs = [ | ||
"b.ts", | ||
":a", | ||
":sub/c.ts", | ||
], | ||
out_dir = "out2", | ||
source_maps = True, | ||
swcrc = ".swcrc", | ||
) | ||
|
||
build_test( | ||
name = "out_dir_predeclared_test", | ||
targets = [ | ||
"out2/b.js", | ||
"out2/b.js.map", | ||
"out2/sub/c.js", | ||
"out2/sub/c.js.map", | ||
], | ||
) | ||
|
||
sh_test( | ||
name = "check_out_dir_outputs", | ||
srcs = ["check_outputs.sh"], | ||
args = ["out2"], | ||
data = [":compile"], | ||
) | ||
|
||
swc( | ||
name = "compile3", | ||
srcs = [ | ||
"sub/c.ts", | ||
], | ||
out_dir = "out3", | ||
root_dir = "sub", | ||
source_maps = True, | ||
swcrc = ".swcrc", | ||
) | ||
|
||
build_test( | ||
name = "root_out_predeclared_test", | ||
targets = [ | ||
"out3/c.js", | ||
"out3/c.js.map", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/usr/bin/env bash | ||
set -o errexit | ||
|
||
dir="genrule" | ||
if $1; then | ||
dir="genrule/$1" | ||
fi | ||
|
||
cd "$TEST_SRCDIR/$TEST_WORKSPACE/$(dirname $TEST_TARGET)" | ||
|
||
grep "export var a" $dir/a.js | ||
grep "sourceMappingURL=a.js.map" $dir/a.js | ||
grep -v --fixed-strings '"sourceRoot"' $dir/a.js.map | ||
grep --fixed-strings '"sources":["a.ts"]' $dir/a.js.map | ||
|
||
grep "export var b" $dir/b.js | ||
grep "sourceMappingURL=b.js.map" $dir/b.js | ||
grep -v --fixed-strings '"sourceRoot"' $dir/b.js.map | ||
grep --fixed-strings '"sources":["b.ts"]' $dir/b.js.map | ||
|
||
grep "export var c" $dir/sub/c.js | ||
grep "sourceMappingURL=c.js.map" $dir/sub/c.js | ||
grep -v --fixed-strings '"sourceRoot"' $dir/sub/c.js.map | ||
grep --fixed-strings '"sources":["c.ts"]' $dir/sub/c.js.map |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters