Skip to content

Commit 4f7ae85

Browse files
committed
fix: rootdir calculation was still incorrect
In the case of a non-ts input, we still added a bazel-out/arch/bin segment to rootdir, which is wrong since that's the working dir
1 parent 7c824bb commit 4f7ae85

File tree

5 files changed

+28
-14
lines changed

5 files changed

+28
-14
lines changed

examples/json/BUILD.bazel

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
load("@aspect_rules_ts//ts:defs.bzl", "ts_project")
2+
3+
# Demonstrates the --resolveJsonModule feature of TypeScript
4+
ts_project(
5+
name = "ts",
6+
srcs = [
7+
"data.json",
8+
"index.ts",
9+
],
10+
out_dir = "build",
11+
resolve_json_module = True,
12+
)

examples/json/data.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[
2+
{
3+
"a": "b"
4+
}
5+
]

examples/json/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import data from './data.json'
2+
export const a: string = 'hello' + JSON.stringify(data)

examples/json/tsconfig.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"compilerOptions": {
3+
"esModuleInterop": true,
4+
"resolveJsonModule": true,
5+
// we can't use the current directory as outDir, because typescript wants to write a data.json file
6+
// and that would collide with the source file we pass it.
7+
"outDir": "build"
8+
}
9+
}

ts/private/ts_lib.bzl

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -211,21 +211,7 @@ def _calculate_typing_maps_outs(srcs, typings_out_dir, root_dir, declaration_map
211211
return _out_paths(srcs, typings_out_dir, root_dir, allow_js, exts)
212212

213213
def _calculate_root_dir(ctx):
214-
root_path = None
215-
216-
# Note we don't have access to the ts_project macro allow_js param here.
217-
# For error-handling purposes, we can assume that any .js/.jsx
218-
# input is meant to be in the rootDir alongside .ts/.tsx sources,
219-
# whether the user meant for them to be sources or not.
220-
# It's a non-breaking change to relax this constraint later, but would be
221-
# a breaking change to restrict it further.
222-
allow_js = True
223-
for src in ctx.files.srcs:
224-
if not _is_ts_src(src.path, allow_js):
225-
root_path = ctx.bin_dir.path
226-
227214
return _join(
228-
root_path,
229215
ctx.label.workspace_root,
230216
ctx.label.package,
231217
ctx.attr.root_dir,

0 commit comments

Comments
 (0)