Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
}

25 changes: 25 additions & 0 deletions examples/ts_js_interop/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
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 = "src",
srcs = [
"a.js",
"b.ts",
],
allow_js = True,
declaration = True,
emit_declaration_only = True,
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_srcs",
srcs = ["b.js"],
)
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)
47 changes: 47 additions & 0 deletions examples/ts_js_interop/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"compilerOptions": {
"emitDeclarationOnly": true,
"declaration": true,
"jsx": "react",
"moduleResolution": "node",
"forceConsistentCasingInFileNames": true,
"noImplicitReturns": true,
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"experimentalDecorators": true,
"lib": ["dom", "es2022", "dom.iterable"],
"baseUrl": "./",
"paths": {
"wkspc/*": ["*", "bazel-out/k8-opt/bin/*"]
},
"esModuleInterop": true,
"downlevelIteration": true,
"module": "esnext",
"target": "es2020",
"skipLibCheck": true,
"resolveJsonModule": true,
"rootDirs": [
".",
// Add all possible bazel-out directories
// See https://github.com/microsoft/TypeScript/issues/37257
"./bazel-out/darwin-dbg/bin",
"./bazel-out/darwin-fastbuild/bin",
"./bazel-out/k8-dbg/bin",
"./bazel-out/k8-fastbuild/bin",
"./bazel-out/k8-opt/bin",
"./bazel-out/k8-opt-arm64/bin",
"./bazel-out/x64_windows-dbg/bin",
"./bazel-out/x64_windows-fastbuild/bin"
],
"allowJs": true,
"useUnknownInCatchVariables": false,
"isolatedModules": true
},
"exclude": [
// Some typescript dependencies that get pulled in
// when you set allowJs to true.
"bazel-out/host/bin/external/npm/typescript/*",
"bazel-out/*exec*/bin/external/npm/typescript/*"
]
}