Skip to content

Commit

Permalink
fix(typescript): account for rootDir when predicting json output paths (
Browse files Browse the repository at this point in the history
#3348)

Fixes #3330
  • Loading branch information
alexeagle authored Mar 1, 2022
1 parent cacf522 commit bd36cd0
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 4 deletions.
7 changes: 4 additions & 3 deletions packages/typescript/internal/ts_project.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,12 @@ def _ts_project_impl(ctx):
# tsc will only produce .json if it also produces .js
if len(js_outs):
pkg_len = len(ctx.label.package) + 1 if len(ctx.label.package) else 0
json_outs = [
ctx.actions.declare_file(_lib.join(ctx.attr.out_dir, src.short_path[pkg_len:]))
rootdir_replace_pattern = ctx.attr.root_dir + "/" if ctx.attr.root_dir else ""
json_outs = _declare_outputs(ctx, [
_lib.join(ctx.attr.out_dir, src.short_path[pkg_len:].replace(rootdir_replace_pattern, ""))
for src in ctx.files.srcs
if src.basename.endswith(".json") and src.is_source
]
])
else:
json_outs = []

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ load("//packages/typescript:index.bzl", "ts_project")
# Ensure that subdir/a.ts produces outDir/a.js
SRCS = [
"subdir/a.ts",
"subdir/file.json",
]

ts_project(
name = "transpile",
srcs = SRCS,
args = ["--listEmittedFiles"],
resolve_json_module = True,
root_dir = "subdir",
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export const a: string = 'hello';
import data from './file.json';
export const a: string = 'hello' + JSON.stringify(data);
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[{
"a": "b"
}]

Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{
"compilerOptions": {
"resolveJsonModule": true,
"esModuleInterop": true,
}
}

0 comments on commit bd36cd0

Please sign in to comment.