Skip to content

Commit b04439b

Browse files
authored
test: add resolve_json_module with esm imports of package.json (#711)
1 parent bdd0fa9 commit b04439b

File tree

8 files changed

+63
-10
lines changed

8 files changed

+63
-10
lines changed

.bazelignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ examples/linked_consumer/node_modules
99
examples/linked_empty_node_modules/node_modules
1010
examples/linked_tsconfig/node_modules
1111
examples/linked_tsconfig_consumer/node_modules
12+
examples/resolve_json_module_esm/node_modules

.prettierignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ docs/*.md
33
**/*_pb.d.ts
44
**/*_connect.d.ts
55
.github/workflows/.aspect-workflows-reusable.yaml
6-
6+
examples/resolve_json_module_esm/index.mts

examples/pnpm-lock.yaml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/pnpm-workspace.yaml

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,2 @@
11
packages:
2-
- connect_node
3-
- linked_pkg
4-
- linked_lib
5-
- linked_consumer
6-
- linked_empty_node_modules
7-
- linked_tsconfig
8-
- linked_tsconfig_consumer
9-
- lib_nocompile_linked
10-
- proto_grpc
2+
- ./*
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
"""Shows how https://www.typescriptlang.org/tsconfig/#resolveJsonModule can be used."""
2+
3+
load("@aspect_bazel_lib//lib:testing.bzl", "assert_contains")
4+
load("@aspect_rules_js//js:defs.bzl", "js_test")
5+
load("@aspect_rules_ts//ts:defs.bzl", "ts_project")
6+
load("@npm//:defs.bzl", "npm_link_all_packages")
7+
8+
npm_link_all_packages(name = "node_modules")
9+
10+
ts_project(
11+
name = "ts",
12+
srcs = [
13+
"index.mts",
14+
"package.json",
15+
],
16+
resolve_json_module = True,
17+
deps = [
18+
":node_modules/@aspect-test/e",
19+
],
20+
)
21+
22+
assert_contains(
23+
name = "test",
24+
actual = "index.mjs",
25+
expected = """Hello from """,
26+
)
27+
28+
js_test(
29+
# Test that the json is available at runtime.
30+
name = "ts-with-json",
31+
data = [":ts"],
32+
entry_point = "index.mjs",
33+
)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import pkg from '@aspect-test/e/package.json' with { type: "json" };
2+
3+
export const a: string = `Hello from ${pkg.name}@${pkg.version}`;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"name": "@lib/test-json-esm",
3+
"type": "module",
4+
"private": true,
5+
"dependencies": {
6+
"@aspect-test/e": "1.0.0"
7+
}
8+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"compilerOptions": {
3+
"allowSyntheticDefaultImports": true,
4+
"module": "esnext",
5+
"moduleResolution": "node",
6+
"resolveJsonModule": true
7+
},
8+
// Workaround https://github.com/microsoft/TypeScript/issues/59036
9+
"exclude": []
10+
}

0 commit comments

Comments
 (0)