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

feat: skipLibCheck take 2 #350

Merged
merged 5 commits into from
Apr 3, 2023
Merged
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
26 changes: 26 additions & 0 deletions ts/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,10 +1,36 @@
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
load("@bazel_skylib//rules:common_settings.bzl", "string_flag")

exports_files(
glob(["*.bzl"]),
visibility = ["//docs:__pkg__"],
)

# Users can enable with --@aspect_rules_ts//ts:skipLibCheck=always
string_flag(
# Note: this name is chosen to be searchable when users look for "skipLibCheck" in their repo,
# as that's the way it appears in tsconfig.json or tsc command line.
name = "skipLibCheck",
# TODO(2.0): change default to "unspecified"
build_setting_default = "honor_tsconfig",
values = [
"always",
"honor_tsconfig",
"unspecified",
],
)

# Note, users could use a Transition to make a subgraph of their depgraph opt-in to skipLibCheck.
config_setting(
name = "skip_lib_check.always",
flag_values = {":skipLibCheck": "always"},
)

config_setting(
name = "skip_lib_check.honor_tsconfig",
flag_values = {":skipLibCheck": "honor_tsconfig"},
)

bzl_library(
name = "defs",
srcs = ["defs.bzl"],
Expand Down
39 changes: 38 additions & 1 deletion ts/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,37 @@ load("//ts/private:ts_lib.bzl", _lib = "lib")
ts_config = _ts_config
TsConfigInfo = _TsConfigInfo

_skip_lib_check_selection_required = """

######## Required Typecheck Performance Selection ########

TypeScript's type-checking exposes a flag `--skipLibCheck`:
https://www.typescriptlang.org/tsconfig#skipLibCheck

Using this flag saves substantial time during type-checking.
Rather than doing a full check of all d.ts files, TypeScript will only type-check the code you
specifically refer to in your app's source code.
We recommend this for most rules_ts users.

HOWEVER this performance improvement comes at the expense of type-system accuracy.
For example, two packages could define two copies of the same type in an inconsistent way.
If you publish a library from your repository, your incorrect types may result in errors for your users.

You must choose exactly one of the following flags:

1. To choose the faster performance, put this in /.bazelrc:

# passes an argument `--skipLibCheck` to *every* spawn of tsc
build --@aspect_rules_ts//ts:skipLibCheck=always

2. To choose more correct typechecks, put this in /.bazelrc:

# honor the setting of `skipLibCheck` in the tsconfig.json file
build --@aspect_rules_ts//ts:skipLibCheck=honor_tsconfig

##########################################################
"""

validate_options = rule(
doc = """Validates that some tsconfig.json properties match attributes on ts_project.
See the documentation of [`ts_project`](#ts_project) for more information.""",
Expand Down Expand Up @@ -400,7 +431,13 @@ def ts_project(
ts_project_rule(
name = tsc_target_name,
srcs = srcs,
args = args,
args = args + select(
{
"@aspect_rules_ts//ts:skip_lib_check.always": ["--skipLibCheck"],
"@aspect_rules_ts//ts:skip_lib_check.honor_tsconfig": [],
},
no_match_error = _skip_lib_check_selection_required,
),
assets = assets,
data = data,
deps = tsc_deps,
Expand Down