Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support --noCheck for transpiling without type-checking
Browse files Browse the repository at this point in the history
jbedard committed Sep 24, 2024

Verified

This commit was signed with the committer’s verified signature. The key has expired.
ripcurlx Christoph Atteneder
1 parent 7cdd9a5 commit 724716f
Showing 14 changed files with 208 additions and 50 deletions.
21 changes: 12 additions & 9 deletions docs/rules.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions examples/isolated_typecheck/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
load("@aspect_rules_ts//ts:defs.bzl", "ts_config")

ts_config(
name = "tsconfig",
src = "tsconfig.json",
visibility = [":__subpackages__"],
)
16 changes: 16 additions & 0 deletions examples/isolated_typecheck/backend/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
load("@aspect_bazel_lib//lib:testing.bzl", "assert_outputs")
load("@aspect_rules_ts//ts:defs.bzl", "ts_project")

ts_project(
name = "backend",
declaration = True,
isolated_typecheck = True,
tsconfig = "//examples/isolated_typecheck:tsconfig",
deps = ["//examples/isolated_typecheck/core"],
)

assert_outputs(
name = "test_backend_default_outputs",
actual = "backend",
expected = ["examples/isolated_typecheck/backend/index.js"],
)
10 changes: 10 additions & 0 deletions examples/isolated_typecheck/backend/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import type { IntersectionType } from '../core'

// Example object of IntersectionType
const myObject: IntersectionType = {
a: 42,
b: 'backend',
c: true,
}

console.log(myObject)
9 changes: 9 additions & 0 deletions examples/isolated_typecheck/core/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
load("@aspect_rules_ts//ts:defs.bzl", "ts_project")

ts_project(
name = "core",
declaration = True,
isolated_typecheck = True,
tsconfig = "//examples/isolated_typecheck:tsconfig",
visibility = ["//examples/isolated_typecheck:__subpackages__"],
)
20 changes: 20 additions & 0 deletions examples/isolated_typecheck/core/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* A file with some non-trivial types, so type-checking it may take some time.
* This helps to motivate the example: we'd like to be able to type-check the frontend and backend in parallel with this file.
*/
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (
k: infer I
) => void
? I
: never

// Example usage
type UnionType = { a: number } | { b: string } | { c: boolean }

export type IntersectionType = UnionToIntersection<UnionType>

export const MyIntersectingValue: IntersectionType = {
a: 1,
b: '2',
c: true,
}
13 changes: 13 additions & 0 deletions examples/isolated_typecheck/frontend/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
load("@aspect_rules_ts//ts:defs.bzl", "ts_project")

ts_project(
name = "frontend",
isolated_typecheck = True,
tsconfig = {
"compilerOptions": {
"declaration": True,
"isolatedDeclarations": True,
},
},
deps = ["//examples/isolated_typecheck/core"],
)
13 changes: 13 additions & 0 deletions examples/isolated_typecheck/frontend/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import type { IntersectionType } from '../core'
import { MyIntersectingValue } from '../core'

// Example object of IntersectionType
const myObject: IntersectionType = {
a: 42,
b: 'frontend',
c: true,
}

const otherObject = MyIntersectingValue

console.log(myObject, otherObject, myObject === otherObject)
8 changes: 8 additions & 0 deletions examples/isolated_typecheck/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"compilerOptions": {
"isolatedDeclarations": true,
"declaration": true
},
// Workaround https://github.com/microsoft/TypeScript/issues/59036
"exclude": []
}
8 changes: 7 additions & 1 deletion ts/defs.bzl
Original file line number Diff line number Diff line change
@@ -40,6 +40,7 @@ def ts_project(
assets = [],
extends = None,
allow_js = False,
isolated_typecheck = False,
declaration = False,
source_map = False,
declaration_map = False,
@@ -153,6 +154,10 @@ def ts_project(
See https://www.typescriptlang.org/docs/handbook/compiler-options.html#compiler-options
Typically useful arguments for debugging are `--listFiles` and `--listEmittedFiles`.
isolated_typecheck: Whether to type-check asynchronously as a separate bazel action.
Requires https://devblogs.microsoft.com/typescript/announcing-typescript-5-6/#the---nocheck-option6
Requires https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-5.html#isolated-declarations
transpiler: A custom transpiler tool to run that produces the JavaScript outputs instead of `tsc`.
Under `--@aspect_rules_ts//ts:default_to_tsc_transpiler`, the default is to use `tsc` to produce
@@ -217,7 +222,7 @@ def ts_project(
incremental: Whether the `incremental` bit is set in the tsconfig.
Instructs Bazel to expect a `.tsbuildinfo` output.
no_emit: Whether the `noEmit` bit is set in the tsconfig.
Instructs Bazel *not* to expect any outputs. Only a validation action is used.
Instructs Bazel *not* to expect any outputs.
emit_declaration_only: Whether the `emitDeclarationOnly` bit is set in the tsconfig.
Instructs Bazel *not* to expect `.js` or `.js.map` outputs for `.ts` sources.
ts_build_info_file: The user-specified value of `tsBuildInfoFile` from the tsconfig.
@@ -416,6 +421,7 @@ def ts_project(
incremental = incremental,
preserve_jsx = preserve_jsx,
composite = composite,
isolated_typecheck = isolated_typecheck,
declaration = declaration,
declaration_dir = declaration_dir,
source_map = source_map,
12 changes: 12 additions & 0 deletions ts/private/ts_lib.bzl
Original file line number Diff line number Diff line change
@@ -87,6 +87,18 @@ https://docs.aspect.build/rulesets/aspect_rules_js/docs/js_library#deps for more
mandatory = True,
allow_single_file = [".json"],
),
"isolated_typecheck": attr.bool(
doc = """\
Whether type-checking should be a separate action.
This allows the transpilation action to run without waiting for typings from dependencies.
Requires the typescript 5.6 [noCheck](https://www.typescriptlang.org/tsconfig#noCheck).
Requires tsconfig [isolatedDeclarations](https://www.typescriptlang.org/tsconfig#isolatedDeclarations)
to allow declarations to be emitted without dependencies.
""",
),
"validate": attr.bool(
doc = """whether to add a Validation Action to verify the other attributes match
settings in the tsconfig.json file""",
Loading

0 comments on commit 724716f

Please sign in to comment.