Skip to content

Commit

Permalink
feat: skipLibCheck take 2 (#350)
Browse files Browse the repository at this point in the history
* feat: skipLibCheck take 2

Fixes #348

* refactor: use bool flags, finish error msg

* refactor: use string_flag instead of pair of bool_flag

* Update ts/defs.bzl

Co-authored-by: Sahin Yort <[email protected]>

* Update defs.bzl

---------

Co-authored-by: Sahin Yort <[email protected]>
  • Loading branch information
alexeagle and thesayyn authored Apr 3, 2023
1 parent dab5e3f commit ed9d26c
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 1 deletion.
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

0 comments on commit ed9d26c

Please sign in to comment.