Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test case for ts/js interop. #712

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ bazel_dep(name = "rules_go", version = "0.46.0", dev_dependency = True, repo_nam
bazel_dep(name = "rules_nodejs", version = "6.2.0", dev_dependency = True)
bazel_dep(name = "stardoc", version = "0.6.2", dev_dependency = True, repo_name = "io_bazel_stardoc")
bazel_dep(name = "toolchains_protoc", version = "0.3.0", dev_dependency = True)
bazel_dep(name = "aspect_rules_swc", version = "2.0.0", dev_dependency = True)

# Should not be required, stardoc leaks a dependency
bazel_dep(name = "rules_java", version = "7.6.1", dev_dependency = True)
Expand Down
15 changes: 15 additions & 0 deletions examples/ts_js_interop/.swcrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"$schema": "https://json.schemastore.org/swcrc",
"jsc": {
"parser": {
"syntax": "typescript",
"tsx": true
},
"target": "es2018"
},
"module": {
"type": "commonjs"
},
"minify": false
}

45 changes: 45 additions & 0 deletions examples/ts_js_interop/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
load("@aspect_rules_ts//ts:defs.bzl", "ts_project")
load("@aspect_rules_swc//swc:defs.bzl", "swc")
load("@bazel_skylib//lib:partial.bzl", "partial")

ts_project(
name = "a_b",
srcs = [
"a.js",
"b.ts",
],
allow_js = True,
declaration = True,
emit_declaration_only = True,
jbedard marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When using emitDeclarationOnly the transpiler won't run at all, tsc or a custom transpiler like swc, so b.js should not be expected at all

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, I figured as much. So this test case can be deleted and clearly does not solve my problem. I only included it to point out that this is one way to avoid the conflict error, but I need b.js to be produced in my environment.

resolve_json_module = True,
transpiler = partial.make(
swc,
swcrc = ":.swcrc",
),
tsconfig = ":tsconfig.json",
)

filegroup(
name = "transpiled_a_b",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these filegroup targets are never used.

Can we replace those with build_test targets so bazel test //... triggers them and they showup in the test results?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not familiar with build_test targets, but probably? Have changes gone in that allow these filegroups to build successfully now?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Search for build_test in other tests for examples and try switching these filegroup to test targets.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

build_test is a trivial test that always passes.

I see, makes sense. It's a trivial test that will always pass as long as it builds.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, I've almost exclusively used it for testing rules just like this test you've written.

# Expect this source to be generated by swc transpilation.
srcs = ["b.js"],
)

# Expect not to get:
# ERROR: file 'examples/ts_js_interop/c.js' is generated by these conflicting actions:
# Label: //examples/ts_js_interop:c_d_tsc, //examples/ts_js_interop:c_d_transpile
ts_project(
name = "c_d",
srcs = [
"c.js",
"d.ts",
],
allow_js = True,
declaration = True,
resolve_json_module = True,
transpiler = partial.make(
swc,
swcrc = ":.swcrc",
),
tsconfig = ":tsconfig.emit.json",
)
2 changes: 2 additions & 0 deletions examples/ts_js_interop/a.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const a = 1;
export default a;
2 changes: 2 additions & 0 deletions examples/ts_js_interop/a.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const a = 1;
export default a;
3 changes: 3 additions & 0 deletions examples/ts_js_interop/b.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import a from './a'

console.log(a)
2 changes: 2 additions & 0 deletions examples/ts_js_interop/c.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const c = 1
export default c
3 changes: 3 additions & 0 deletions examples/ts_js_interop/d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import c from './c'

console.log(c)
12 changes: 12 additions & 0 deletions examples/ts_js_interop/tsconfig.emit.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"compilerOptions": {
"declaration": true,
"moduleResolution": "node",
"baseUrl": "./",
"esModuleInterop": true,
"rootDirs": ["."],
"allowJs": true,
"resolveJsonModule": true
},
"exclude": []
}
13 changes: 13 additions & 0 deletions examples/ts_js_interop/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"compilerOptions": {
"emitDeclarationOnly": true,
"declaration": true,
"moduleResolution": "node",
"baseUrl": "./",
"esModuleInterop": true,
"rootDirs": ["."],
"allowJs": true,
"resolveJsonModule": true
},
"exclude": []
}
Loading