Skip to content

Commit 02495c3

Browse files
committed
feat: transpile using --noCheck when isolatedDeclarations
Ref #88 Ref #374
1 parent f1b733c commit 02495c3

File tree

11 files changed

+119
-52
lines changed

11 files changed

+119
-52
lines changed

docs/rules.md

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

examples/isolated_declarations/README.md

Lines changed: 0 additions & 13 deletions
This file was deleted.

examples/isolated_declarations/backend/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ load("@aspect_rules_ts//ts:defs.bzl", "ts_project")
44
ts_project(
55
name = "backend",
66
declaration = True,
7+
isolated_declarations = True,
78
tsconfig = "//examples/isolated_declarations:tsconfig",
89
deps = ["//examples/isolated_declarations/core"],
910
)

examples/isolated_declarations/core/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ load("@aspect_rules_ts//ts:defs.bzl", "ts_project")
33
ts_project(
44
name = "core",
55
declaration = True,
6+
isolated_declarations = True,
67
tsconfig = "//examples/isolated_declarations:tsconfig",
78
visibility = ["//examples/isolated_declarations:__subpackages__"],
89
)

examples/isolated_declarations/core/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,9 @@ type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (
1212
type UnionType = { a: number } | { b: string } | { c: boolean }
1313

1414
export type IntersectionType = UnionToIntersection<UnionType>
15+
16+
export const MyIntersectingType: IntersectionType = {
17+
a: 1,
18+
b: '2',
19+
c: true,
20+
}

examples/isolated_declarations/frontend/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ ts_project(
55
tsconfig = {
66
"compilerOptions": {
77
"declaration": True,
8+
"isolatedDeclarations": True,
89
},
910
},
1011
deps = ["//examples/isolated_declarations/core"],

ts/defs.bzl

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ def ts_project(
4040
assets = [],
4141
extends = None,
4242
allow_js = False,
43+
isolated_declarations = None,
4344
declaration = False,
4445
source_map = False,
4546
declaration_map = False,
@@ -152,6 +153,10 @@ def ts_project(
152153
See https://www.typescriptlang.org/docs/handbook/compiler-options.html#compiler-options
153154
Typically useful arguments for debugging are `--listFiles` and `--listEmittedFiles`.
154155
156+
isolated_declarations: Whether to enforce that declaration output (.d.ts file) can be produced for a
157+
single source file at a time. Requires some additional explicit types on exported symbols.
158+
See https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-5.html#isolated-declarations
159+
155160
transpiler: A custom transpiler tool to run that produces the JavaScript outputs instead of `tsc`.
156161
157162
Under `--@aspect_rules_ts//ts:default_to_tsc_transpiler`, the default is to use `tsc` to produce
@@ -280,6 +285,8 @@ def ts_project(
280285
allow_js = compiler_options.setdefault("allowJs", allow_js)
281286
if resolve_json_module != None:
282287
resolve_json_module = compiler_options.setdefault("resolveJsonModule", resolve_json_module)
288+
if isolated_declarations != None:
289+
isolated_declarations = compiler_options.setdefault("isolatedDeclarations", isolated_declarations)
283290

284291
# These options are always passed on the tsc command line so don't include them
285292
# in the tsconfig. At best they're redundant, but at worst we'll have a conflict
@@ -321,8 +328,9 @@ def ts_project(
321328
else:
322329
# To stitch together a tree of ts_project where transpiler is a separate rule,
323330
# we have to produce a few targets
324-
tsc_target_name = "%s_typings" % name
331+
tsc_target_name = "%s_tsc" % name
325332
transpile_target_name = "%s_transpile" % name
333+
typings_target_name = "%s_typings" % name
326334
typecheck_target_name = "%s_typecheck" % name
327335
test_target_name = "%s_typecheck_test" % name
328336

@@ -342,14 +350,31 @@ def ts_project(
342350
else:
343351
fail("transpiler attribute should be a rule/macro or a skylib partial. Got " + type(transpiler))
344352

345-
# Users should build this target to get a failed build when typechecking fails
346-
native.filegroup(
347-
name = typecheck_target_name,
348-
srcs = [tsc_target_name],
349-
# This causes the types to be produced, which in turn triggers the tsc action to typecheck
350-
output_group = "types",
351-
**common_kwargs
352-
)
353+
if isolated_declarations:
354+
# Users should build this target to get a failed build when typechecking fails
355+
native.filegroup(
356+
name = typecheck_target_name,
357+
srcs = [tsc_target_name],
358+
output_group = "typecheck",
359+
**common_kwargs
360+
)
361+
362+
native.filegroup(
363+
name = typings_target_name,
364+
srcs = [tsc_target_name],
365+
# This causes the types to be produced, which in turn triggers the tsc action to typecheck
366+
output_group = "types",
367+
**common_kwargs
368+
)
369+
else:
370+
# Users should build this target to get a failed build when typechecking fails
371+
native.filegroup(
372+
name = typecheck_target_name,
373+
srcs = [tsc_target_name],
374+
# This causes the types to be produced, which in turn triggers the tsc action to typecheck
375+
output_group = "types",
376+
**common_kwargs
377+
)
353378

354379
# Ensures the typecheck target gets built under `bazel test --build_tests_only`
355380
build_test(
@@ -389,6 +414,7 @@ def ts_project(
389414
incremental = incremental,
390415
preserve_jsx = preserve_jsx,
391416
composite = composite,
417+
isolated_declarations = isolated_declarations,
392418
declaration = declaration,
393419
declaration_dir = declaration_dir,
394420
source_map = source_map,

ts/private/ts_lib.bzl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ COMPILER_OPTION_ATTRS = {
108108
"composite": attr.bool(
109109
doc = "https://www.typescriptlang.org/tsconfig#composite",
110110
),
111+
"isolated_declarations": attr.bool(
112+
doc = "https://www.typescriptlang.org/tsconfig/#isolatedDeclarations",
113+
),
111114
"declaration": attr.bool(
112115
doc = "https://www.typescriptlang.org/tsconfig#declaration",
113116
),

0 commit comments

Comments
 (0)