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

Updated typescript versions #353

Merged
merged 2 commits into from
Apr 28, 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
10 changes: 6 additions & 4 deletions docs/rules.md

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

5 changes: 3 additions & 2 deletions e2e/test/common.bats
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ local_repository(
path = "$rules_ts_path",
)

load("@aspect_rules_ts//ts:repositories.bzl", "LATEST_VERSION", "rules_ts_dependencies")
load("@aspect_rules_ts//ts:repositories.bzl", "rules_ts_dependencies")

rules_ts_dependencies(ts_version = LATEST_VERSION)
# TODO(#361): upgrade to 5.x
rules_ts_dependencies(ts_version = "4.9.5")

# Fetch and register node, if you haven't already
load("@rules_nodejs//nodejs:repositories.bzl", "DEFAULT_NODE_VERSION", "nodejs_register_toolchains")
Expand Down
6 changes: 4 additions & 2 deletions e2e/worker/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ local_repository(
path = "../..",
)

load("@aspect_rules_ts//ts:repositories.bzl", "LATEST_VERSION", "rules_ts_dependencies")
rules_ts_dependencies(ts_version = LATEST_VERSION)
load("@aspect_rules_ts//ts:repositories.bzl", "rules_ts_dependencies")

# TODO(#361): upgrade to 5.x
rules_ts_dependencies(ts_version = "4.9.5")

# Fetch and register node, if you haven't already
load("@rules_nodejs//nodejs:repositories.bzl", "DEFAULT_NODE_VERSION", "nodejs_register_toolchains")
Expand Down
14 changes: 14 additions & 0 deletions ts/BUILD.typescript
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,20 @@ load("@aspect_rules_js//npm:defs.bzl", "npm_link_package")
load("@aspect_bazel_lib//lib:directory_path.bzl", "directory_path")
load("@bazel_skylib//rules:copy_file.bzl", "copy_file")
load("@bazel_skylib//rules:write_file.bzl", "write_file")
load("@bazel_skylib//rules:common_settings.bzl", "bool_setting")

bool_setting(
name = "is_typescript_5_or_greater_flag",
build_setting_default = is_ts_5,
visibility = ["//visibility:public"],
)

config_setting(
name = "is_typescript_5_or_greater",
flag_values = {
":is_typescript_5_or_greater_flag": "true",
},
)

npm_package_internal(
name = "npm_typescript",
Expand Down
9 changes: 6 additions & 3 deletions ts/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -236,11 +236,11 @@ def ts_project(

supports_workers: Whether the worker protocol is enabled.
To disable worker mode for a particular target set `supports_workers` to `False`.

Note that value of this attribute always preferred over `--@aspect_rules_ts//ts:supports_workers` flag
unless the `supports_workers` attribute is not set explicitly.

Worker mode can be disabled workspace wide by using the `--@aspect_rules_ts//ts:supports_workers` flag.
Worker mode can be disabled workspace wide by using the `--@aspect_rules_ts//ts:supports_workers` flag.
To disable worker mode globally, insert `build --@aspect_rules_ts//ts:supports_workers=false` into the .bazelrc.

Alternatively, worker mode can be controlled via `--strategy`.
Expand Down Expand Up @@ -398,7 +398,6 @@ def ts_project(
data = data,
**common_kwargs
)


# Disable workers if a custom tsc was provided but not a custom tsc_worker.
if tsc != _tsc and tsc_worker == _tsc_worker:
Expand Down Expand Up @@ -433,6 +432,10 @@ def ts_project(
tsc_worker = tsc_worker,
transpile = not transpiler,
supports_workers = supports_workers,
is_typescript_5_or_greater = select({
"@npm_typescript//:is_typescript_5_or_greater": True,
"//conditions:default": False,
}),
internal_do_not_depend_supports_workers_is_none = supports_workers == None,
**kwargs
)
8 changes: 7 additions & 1 deletion ts/private/npm_repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,13 @@ def _http_archive_version_impl(rctx):
url = [u.format(version) for u in rctx.attr.urls],
integrity = integrity,
)
build_file_substitutions = {"ts_version": version}
build_file_substitutions = {
"ts_version": version,
# Note: we can't depend on bazel_skylib because this code is called from
# rules_ts_dependencies so it's not "in scope" yet.
# So we can't use versions.bzl to parse the version
"is_ts_5": str(int(version.split(".")[0]) >= 5),
}
build_file_substitutions.update(**rctx.attr.build_file_substitutions)
rctx.template(
"BUILD.bazel",
Expand Down
10 changes: 7 additions & 3 deletions ts/private/ts_lib.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ See more details on the `assets` parameter of the `ts_project` macro.
doc = "Whether the tsc compiler understands Bazel's persistent worker protocol",
default = False,
),
# TODO(2.0): remove this and make supports_workers a tri-state int.
"is_typescript_5_or_greater": attr.bool(
doc = "Whether TypeScript version is >= 5.0.0",
default = False,
),
# TODO(2.0): remove this and make supports_workers a tri-state int.
"internal_do_not_depend_supports_workers_is_none": attr.bool(
doc = "Internal. DO NOT DEPEND!",
default = False,
Expand All @@ -86,8 +90,8 @@ See more details on the `assets` parameter of the `ts_project` macro.
allow_single_file = [".json"],
),
"_options": attr.label(
default = "@aspect_rules_ts//ts:options"
)
default = "@aspect_rules_ts//ts:options",
),
}

# These attrs are shared between the validate and the ts_project rules
Expand Down
15 changes: 12 additions & 3 deletions ts/private/ts_project.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ def _ts_project_impl(ctx):
executable = ctx.executable.tsc

supports_workers = ctx.attr.supports_workers
# workers can be enabled/disabled globally. if no supports_workers attribute is set explicitly for this target,

# workers can be enabled/disabled globally. if no supports_workers attribute is set explicitly for this target,
# which is indicated by internal_do_not_depend_supports_workers_is_none attribute, then set it to global supports_workers config
# TODO(2.0): remove this
if ctx.attr.internal_do_not_depend_supports_workers_is_none:
Expand All @@ -80,9 +80,18 @@ def _ts_project_impl(ctx):
supports_workers = False

# buildifier: disable=print
print("""
print("""\
WARNING: disabling ts_project workers which are not currently supported on Windows hosts.
See https://github.com/aspect-build/rules_ts/issues/228 for more details.
""")

if ctx.attr.is_typescript_5_or_greater and supports_workers:
supports_workers = False

# buildifier: disable=print
print("""\
WARNING: disabling ts_project workers which are not currently supported with TS >= 5.0.0.
See https://github.com/aspect-build/rules_ts/issues/361 for more details.
""")

if supports_workers:
Expand Down
3 changes: 3 additions & 0 deletions ts/private/versions.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -148,4 +148,7 @@ TOOL_VERSIONS = {
"4.9.3": "sha512-CIfGzTelbKNEnLpLdGFgdyKhG23CKdKgQPOBc+OUNrkJ2vr+KSzsSV5kq5iWhEQbok+quxgGzrAtGWCyU7tHnA==",
"4.9.4": "sha512-Uz+dTXYzxXXbsFpM86Wh3dKCxrQqUcVMxwU54orwlJjOpO3ao8L7j5lH+dWfTwgCwIuM9GQ2kvVotzYJMXTBZg==",
"4.9.5": "sha512-1FXk9E2Hm+QzZQ7z+McJiHL4NW1F2EzMu9Nq9i3zAaGqibafqYwCVU6WyWAuyQRRzOlxou8xZSyXLEN8oKj24g==",
"5.0.2": "sha512-wVORMBGO/FAs/++blGNeAVdbNKtIh1rbBL2EyQ1+J9lClJ93KiiKe8PmFIVdXhHcyv44SL9oglmfeSsndo0jRw==",
"5.0.3": "sha512-xv8mOEDnigb/tN9PSMTwSEqAnUvkoXMQlicOb0IUVDBSQCgBSaAAROUZYy2IcUy5qU6XajK5jjjO7TMWqBTKZA==",
"5.0.4": "sha512-cW9T5W9xY37cc+jfEnaUvX91foxtHkza3Nw3wkoF4sSlKn0MONdkdEndig/qPBWXNkmplh3NzayQzCiHM4/hqw==",
}