aspect-build / aspect-build/rules_ts
[Bug]: JSON files isn't available to downstream ts_library type checking
- Dominant language
- Starlark
- Stars
- 138
- Forks
- 87
- Avg merge
- 2d 8h
- Merged PRs (30d)
- 3
Description
### What happened?
When `resolveJsonModule` is set, TypeScript type check will read JSON files to infer the types. For example:
```starlark
# foo/BUILD.bazel
ts_library(
name = "foo",
srcs = ["foo.ts", "data.json"],
data = ["data.json"]
declaration = True,
tsconfig = "//:tsconfig", # resolveJsonModule is true in this file
visibility = ["//visibility:public"],
)
# bar/BUILD.bazel
ts_library(
name = "bar",
deps = ["//bar"]
srcs = ["bar.ts"],
declaration = True,
tsconfig = "//:tsconfig",
)
```
```js
// foo/foo.js
import data from './data.json';
export type Data = typeof Data;
// bar/bar.js
import type {Data} from '../foo/foo';
```
Type checking `//bar` will throw an error that `data.json` cannot be resolved. The file is not present in the runfiles because only `.d.ts` files of `foo` are present.
### Version
Development (host) and target OS/architectures:
Output of `bazel --version`: aspect 5.8.19
Version of the Aspect rules, or other relevant rules from your
`WORKSPACE` or `MODULE.bazel` file: rules_ts 2.1.0, rules_js 1.34.0
Language(s) and/or frameworks involved: TypeScript
### How to reproduce
Minimal repro: https://github.com/pyrocat101/ts-json-repro
```shell
bazel build //bar
```
### Any other information?
_No response_
Contributor guide
Research direction
Start with the minimal repro linked in the issue and run `bazel build //bar`. Inspect the `foo/BUILD.bazel` and `bar/BUILD.bazel` targets, their `tsconfig` settings, and the files available in runfiles during downstream declaration checking. Done means `//bar` type-checks successfully when `foo` imports `data.json` with `resolveJsonModule` enabled.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100