From b3905a4f9e1426b589bae90064ffcfff2056a6b2 Mon Sep 17 00:00:00 2001 From: Greg Magolan Date: Fri, 19 Apr 2024 16:24:19 -0700 Subject: [PATCH] feat: upgrade to rules_js 2.0 --- .aspect/bazelrc/ci.bazelrc | 7 - .aspect/bazelrc/javascript.bazelrc | 1 + MODULE.bazel | 8 +- WORKSPACE | 8 +- docs/rules.md | 4 +- docs/transpiler.md | 4 +- e2e/bzlmod/MODULE.bazel | 5 +- e2e/bzlmod/pnpm-lock.yaml | 86 ++-- e2e/external_dep/MODULE.bazel | 4 +- e2e/external_dep/WORKSPACE | 10 +- e2e/external_dep/app/MODULE.bazel | 4 +- e2e/external_dep/app/WORKSPACE | 10 +- e2e/test/common.bats | 368 ++++++++++++------ e2e/worker/MODULE.bazel | 6 +- e2e/worker/WORKSPACE | 10 +- e2e/workspace/WORKSPACE | 12 +- examples/BUILD.bazel | 8 +- examples/deps_lib/BUILD.bazel | 8 +- examples/deps_lib_transpiler/BUILD.bazel | 8 +- examples/dts_lib/BUILD.bazel | 2 +- examples/js_lib/BUILD.bazel | 6 +- examples/linked/BUILD.bazel | 6 +- examples/linked_consumer/BUILD.bazel | 2 +- .../linked_empty_node_modules/BUILD.bazel | 6 +- examples/linked_tsconfig/BUILD.bazel | 2 +- ts/BUILD.bazel | 8 +- ts/defs.bzl | 2 +- ts/private/BUILD.bazel | 6 - ts/private/is_bazel_7_or_greater.bzl | 7 - ts/private/ts_config.bzl | 30 +- ts/private/ts_lib.bzl | 18 +- ts/private/ts_project.bzl | 52 ++- ts/private/ts_proto_library.bzl | 7 +- ts/private/ts_validate_options.bzl | 6 +- ts/repositories.bzl | 21 +- ts/test/transpiler_tests.bzl | 16 +- ts/test/ts_project_test.bzl | 44 +-- 37 files changed, 438 insertions(+), 374 deletions(-) delete mode 100644 ts/private/is_bazel_7_or_greater.bzl diff --git a/.aspect/bazelrc/ci.bazelrc b/.aspect/bazelrc/ci.bazelrc index 4d91ee09..11aae33d 100644 --- a/.aspect/bazelrc/ci.bazelrc +++ b/.aspect/bazelrc/ci.bazelrc @@ -1,10 +1,3 @@ -# We recommend enforcing a policy that keeps your CI from being slowed down -# by individual test targets that should be optimized -# or split up into multiple test targets with sharding or manually. -# Set this flag to exclude targets that have their timeout set to eternal (>15m) from running on CI. -# Docs: https://bazel.build/docs/user-manual#test-timeout-filters -test --test_timeout_filters=-eternal - # Set this flag to enable re-tries of failed tests on CI. # When any test target fails, try one or more times. This applies regardless of whether the "flaky" # tag appears on the target definition. diff --git a/.aspect/bazelrc/javascript.bazelrc b/.aspect/bazelrc/javascript.bazelrc index 474ec632..ace9d604 100644 --- a/.aspect/bazelrc/javascript.bazelrc +++ b/.aspect/bazelrc/javascript.bazelrc @@ -8,3 +8,4 @@ # details. # Docs: https://nodejs.org/en/docs/guides/debugging-getting-started/#command-line-options run:debug -- --node_options=--inspect-brk +test:debug --test_env=NODE_OPTIONS=--inspect-brk diff --git a/MODULE.bazel b/MODULE.bazel index a11afc30..4b7d54e1 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -7,9 +7,9 @@ module( ) # Lower-bounds (minimum) versions for direct runtime dependencies -bazel_dep(name = "aspect_bazel_lib", version = "1.40.2") -bazel_dep(name = "aspect_rules_js", version = "1.34.0") -bazel_dep(name = "bazel_skylib", version = "1.4.1") +bazel_dep(name = "aspect_bazel_lib", version = "2.7.3") +bazel_dep(name = "aspect_rules_js", version = "2.0.0-alpha.6") +bazel_dep(name = "bazel_skylib", version = "1.5.0") bazel_dep(name = "platforms", version = "0.0.5") # TODO(4.x): remove support for non-toolchainized protoc @@ -26,7 +26,7 @@ bazel_dep(name = "bazel_skylib_gazelle_plugin", version = "1.5.0", dev_dependenc bazel_dep(name = "buildifier_prebuilt", version = "6.4.0", dev_dependency = True) bazel_dep(name = "gazelle", version = "0.36.0", dev_dependency = True, repo_name = "bazel_gazelle") bazel_dep(name = "rules_go", version = "0.46.0", dev_dependency = True, repo_name = "io_bazel_rules_go") -bazel_dep(name = "rules_nodejs", version = "5.8.2", dev_dependency = True) +bazel_dep(name = "rules_nodejs", version = "6.1.0", dev_dependency = True) bazel_dep(name = "stardoc", version = "0.6.2", dev_dependency = True, repo_name = "io_bazel_stardoc") npm = use_extension("@aspect_rules_js//npm:extensions.bzl", "npm", dev_dependency = True) diff --git a/WORKSPACE b/WORKSPACE index 90316e51..9846900e 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -16,11 +16,9 @@ load("@aspect_rules_js//js:repositories.bzl", "rules_js_dependencies") rules_js_dependencies() -load("@aspect_bazel_lib//lib:repositories.bzl", "aspect_bazel_lib_dependencies", "register_coreutils_toolchains") +load("@aspect_rules_js//js:toolchains.bzl", "DEFAULT_NODE_VERSION", "rules_js_register_toolchains") -aspect_bazel_lib_dependencies() - -register_coreutils_toolchains() +rules_js_register_toolchains(node_version = DEFAULT_NODE_VERSION) load("@rules_nodejs//nodejs:repositories.bzl", "nodejs_register_toolchains") @@ -85,7 +83,7 @@ buildifier_prebuilt_register_toolchains() ########################################### # A pnpm workspace so we can test 3p deps -load("@aspect_rules_js//npm:npm_import.bzl", "npm_translate_lock") +load("@aspect_rules_js//npm:repositories.bzl", "npm_translate_lock") npm_translate_lock( name = "npm", diff --git a/docs/rules.md b/docs/rules.md index 5c652d78..b55873ff 100644 --- a/docs/rules.md +++ b/docs/rules.md @@ -55,9 +55,9 @@ for srcs and tsconfig, and pre-declaring output files. | Name | Description | Type | Mandatory | Default | | :------------- | :------------- | :------------- | :------------- | :------------- | | name | A unique name for this target. | Name | required | | -| deps | List of targets that produce TypeScript typings (`.d.ts` files)

If this list contains linked npm packages, npm package store targets or other targets that provide `JsInfo`, `NpmPackageStoreInfo` providers are gathered from `JsInfo`. This is done directly from the `npm_package_store_deps` field of these. For linked npm package targets, the underlying `npm_package_store` target(s) that back the links is used. Gathered `NpmPackageStoreInfo` providers are propagated to the direct dependencies of downstream linked `npm_package` targets.

NB: Linked npm package targets that are "dev" dependencies do not forward their underlying `npm_package_store` target(s) through `npm_package_store_deps` and will therefore not be propagated to the direct dependencies of downstream linked `npm_package` targets. npm packages that come in from `npm_translate_lock` are considered "dev" dependencies if they are have `dev: true` set in the pnpm lock file. This should be all packages that are only listed as "devDependencies" in all `package.json` files within the pnpm workspace. This behavior is intentional to mimic how `devDependencies` work in published npm packages. | List of labels | optional | `[]` | +| deps | List of targets that produce TypeScript typings (`.d.ts` files)

Follows the same runfiles semantics as `js_library` `deps` attribute. See https://docs.aspect.build/rulesets/aspect_rules_js/docs/js_library#deps for more info. | List of labels | optional | `[]` | | srcs | TypeScript source files | List of labels | required | | -| data | Runtime dependencies to include in binaries/tests that depend on this target.

The transitive npm dependencies, transitive sources, default outputs and runfiles of targets in the `data` attribute are added to the runfiles of this target. They should appear in the '*.runfiles' area of any executable which has a runtime dependency on this target.

If this list contains linked npm packages, npm package store targets or other targets that provide `JsInfo`, `NpmPackageStoreInfo` providers are gathered from `JsInfo`. This is done directly from the `npm_package_store_deps` field of these. For linked npm package targets, the underlying `npm_package_store` target(s) that back the links is used. Gathered `NpmPackageStoreInfo` providers are propagated to the direct dependencies of downstream linked `npm_package` targets.

NB: Linked npm package targets that are "dev" dependencies do not forward their underlying `npm_package_store` target(s) through `npm_package_store_deps` and will therefore not be propagated to the direct dependencies of downstream linked `npm_package` targets. npm packages that come in from `npm_translate_lock` are considered "dev" dependencies if they are have `dev: true` set in the pnpm lock file. This should be all packages that are only listed as "devDependencies" in all `package.json` files within the pnpm workspace. This behavior is intentional to mimic how `devDependencies` work in published npm packages. | List of labels | optional | `[]` | +| data | Runtime dependencies to include in binaries/tests that depend on this target.

Follows the same semantics as `js_library` `data` attribute. See https://docs.aspect.build/rulesets/aspect_rules_js/docs/js_library#data for more info. | List of labels | optional | `[]` | | allow_js | https://www.typescriptlang.org/tsconfig#allowJs | Boolean | optional | `False` | | args | https://www.typescriptlang.org/docs/handbook/compiler-options.html | List of strings | optional | `[]` | | assets | Files which are needed by a downstream build step such as a bundler.

See more details on the `assets` parameter of the `ts_project` macro. | List of labels | optional | `[]` | diff --git a/docs/transpiler.md b/docs/transpiler.md index f94eb427..00558b8c 100644 --- a/docs/transpiler.md +++ b/docs/transpiler.md @@ -143,11 +143,11 @@ ts_project(name = a) --foo.d.ts--> npm_package ---> npm_link_package ---> ts_pro In this diagram, we'd like to be able to change the TypeScript sources of `a` and then re-run the test target, without waiting for type-checking. However, since `foo.d.ts` is declared as an input to the `npm_package` rule, Bazel needs to produce it. -To solve this, you can add the flag `--@aspect_rules_js//npm:exclude_declarations_from_npm_packages` to your `bazel` command. +To solve this, you can add the flag `--@aspect_rules_js//npm:exclude_types_from_npm_packages` to your `bazel` command. Use this flag only for local development! You can add a line to your `.bazelrc` to make this easier to type, for example: ``` # Run bazel --config=dev to choose these options: -build:dev --@aspect_rules_js//npm:exclude_declarations_from_npm_packages +build:dev --@aspect_rules_js//npm:exclude_types_from_npm_packages ``` diff --git a/e2e/bzlmod/MODULE.bazel b/e2e/bzlmod/MODULE.bazel index dfe11843..7245afa5 100644 --- a/e2e/bzlmod/MODULE.bazel +++ b/e2e/bzlmod/MODULE.bazel @@ -4,9 +4,8 @@ local_path_override( path = "../..", ) -# repeated here only because we use the platforms definitions for rbe -bazel_dep(name = "aspect_rules_js", version = "1.34.0", dev_dependency = True) -bazel_dep(name = "bazel_skylib", version = "1.4.1", dev_dependency = True) +bazel_dep(name = "aspect_rules_js", version = "2.0.0-alpha.6", dev_dependency = True) # repeated here only because we use the platforms definitions for rbe +bazel_dep(name = "bazel_skylib", version = "1.5.0", dev_dependency = True) bazel_dep(name = "rules_proto", version = "5.3.0-21.7", dev_dependency = True) bazel_dep(name = "toolchains_protoc", version = "0.2.4", dev_dependency = True) diff --git a/e2e/bzlmod/pnpm-lock.yaml b/e2e/bzlmod/pnpm-lock.yaml index 74cdd656..3eb24b3f 100644 --- a/e2e/bzlmod/pnpm-lock.yaml +++ b/e2e/bzlmod/pnpm-lock.yaml @@ -1,69 +1,63 @@ -lockfileVersion: 5.3 +lockfileVersion: '6.0' -specifiers: - '@bufbuild/protobuf': 1.3.0 - '@bufbuild/protoc-gen-es': 1.3.0 - typescript: 4.8.4 +settings: + autoInstallPeers: true + excludeLinksFromLockfile: false dependencies: - '@bufbuild/protobuf': registry.npmjs.org/@bufbuild/protobuf/1.3.0 + '@bufbuild/protobuf': + specifier: 1.8.0 + version: 1.8.0 devDependencies: - '@bufbuild/protoc-gen-es': registry.npmjs.org/@bufbuild/protoc-gen-es/1.3.0_@bufbuild+protobuf@1.3.0 - typescript: registry.npmjs.org/typescript/4.8.4 + '@bufbuild/protoc-gen-es': + specifier: 1.8.0 + version: 1.8.0(@bufbuild/protobuf@1.8.0) + typescript: + specifier: 4.8.4 + version: 4.8.4 packages: - registry.npmjs.org/@bufbuild/protobuf/1.3.0: - resolution: {integrity: sha512-G372ods0pLt46yxVRsnP/e2btVPuuzArcMPFpIDeIwiGPuuglEs9y75iG0HMvZgncsj5TvbYRWqbVyOe3PLCWQ==, registry: https://registry.npmjs.com/, tarball: https://registry.npmjs.org/@bufbuild/protobuf/-/protobuf-1.3.0.tgz} - name: '@bufbuild/protobuf' - version: 1.3.0 + /@bufbuild/protobuf@1.8.0: + resolution: {integrity: sha512-qR9FwI8QKIveDnUYutvfzbC21UZJJryYrLuZGjeZ/VGz+vXelUkK+xgkOHsvPEdYEdxtgUUq4313N8QtOehJ1Q==} - registry.npmjs.org/@bufbuild/protoc-gen-es/1.3.0_@bufbuild+protobuf@1.3.0: - resolution: {integrity: sha512-XxGZwpXMYlwoSyJwCTFb7SZ2xKmv2iCRM022t1wszhY3kNL7rjpyj+3GbpCOjaM1T7NAoLnW0Hyb/M0b0XDb3Q==, registry: https://registry.npmjs.com/, tarball: https://registry.npmjs.org/@bufbuild/protoc-gen-es/-/protoc-gen-es-1.3.0.tgz} - id: registry.npmjs.org/@bufbuild/protoc-gen-es/1.3.0 - name: '@bufbuild/protoc-gen-es' - version: 1.3.0 + /@bufbuild/protoc-gen-es@1.8.0(@bufbuild/protobuf@1.8.0): + resolution: {integrity: sha512-jnvBKwHq3o/iOgfKxaxn5Za7ay4oAs8KWgoHiDc9Fsb0g+/d1z+mHlHvmevOiCPcVZsnH6V3LImOJvGStPONpA==} engines: {node: '>=14'} hasBin: true peerDependencies: - '@bufbuild/protobuf': 1.3.0 + '@bufbuild/protobuf': 1.8.0 peerDependenciesMeta: '@bufbuild/protobuf': optional: true dependencies: - '@bufbuild/protobuf': registry.npmjs.org/@bufbuild/protobuf/1.3.0 - '@bufbuild/protoplugin': registry.npmjs.org/@bufbuild/protoplugin/1.3.0 + '@bufbuild/protobuf': 1.8.0 + '@bufbuild/protoplugin': 1.8.0 transitivePeerDependencies: - supports-color dev: true - registry.npmjs.org/@bufbuild/protoplugin/1.3.0: - resolution: {integrity: sha512-zye8CfJb9VWzaHR/f1qcEkddaRh9De+u6fORsj92Ten8EJUcyhiY5BivET+RMTissAKXKrp/f2zSBCV0dlFxPw==, registry: https://registry.npmjs.com/, tarball: https://registry.npmjs.org/@bufbuild/protoplugin/-/protoplugin-1.3.0.tgz} - name: '@bufbuild/protoplugin' - version: 1.3.0 + /@bufbuild/protoplugin@1.8.0: + resolution: {integrity: sha512-Pb89cTshW+I577qh27VvxGYvZEvQ3zJ8La1OfzPCKugP9d4A4P65WStkAY+aSCiDHk68m1/+mtBb6elfiLPuFg==} dependencies: - '@bufbuild/protobuf': registry.npmjs.org/@bufbuild/protobuf/1.3.0 - '@typescript/vfs': registry.npmjs.org/@typescript/vfs/1.5.0 - typescript: registry.npmjs.org/typescript/4.5.2 + '@bufbuild/protobuf': 1.8.0 + '@typescript/vfs': 1.5.0 + typescript: 4.5.2 transitivePeerDependencies: - supports-color dev: true - registry.npmjs.org/@typescript/vfs/1.5.0: - resolution: {integrity: sha512-AJS307bPgbsZZ9ggCT3wwpg3VbTKMFNHfaY/uF0ahSkYYrPF2dSSKDNIDIQAHm9qJqbLvCsSJH7yN4Vs/CsMMg==, registry: https://registry.npmjs.com/, tarball: https://registry.npmjs.org/@typescript/vfs/-/vfs-1.5.0.tgz} - name: '@typescript/vfs' - version: 1.5.0 + /@typescript/vfs@1.5.0: + resolution: {integrity: sha512-AJS307bPgbsZZ9ggCT3wwpg3VbTKMFNHfaY/uF0ahSkYYrPF2dSSKDNIDIQAHm9qJqbLvCsSJH7yN4Vs/CsMMg==} dependencies: - debug: registry.npmjs.org/debug/4.3.4 + debug: 4.3.4 transitivePeerDependencies: - supports-color dev: true - registry.npmjs.org/debug/4.3.4: - resolution: {integrity: sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==, registry: https://registry.npmjs.com/, tarball: https://registry.npmjs.org/debug/-/debug-4.3.4.tgz} - name: debug - version: 4.3.4 + /debug@4.3.4: + resolution: {integrity: sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==} engines: {node: '>=6.0'} peerDependencies: supports-color: '*' @@ -71,27 +65,21 @@ packages: supports-color: optional: true dependencies: - ms: registry.npmjs.org/ms/2.1.2 + ms: 2.1.2 dev: true - registry.npmjs.org/ms/2.1.2: - resolution: {integrity: sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==, registry: https://registry.npmjs.com/, tarball: https://registry.npmjs.org/ms/-/ms-2.1.2.tgz} - name: ms - version: 2.1.2 + /ms@2.1.2: + resolution: {integrity: sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==} dev: true - registry.npmjs.org/typescript/4.5.2: - resolution: {integrity: sha512-5BlMof9H1yGt0P8/WF+wPNw6GfctgGjXp5hkblpyT+8rkASSmkUKMXrxR0Xg8ThVCi/JnHQiKXeBaEwCeQwMFw==, registry: https://registry.npmjs.com/, tarball: https://registry.npmjs.org/typescript/-/typescript-4.5.2.tgz} - name: typescript - version: 4.5.2 + /typescript@4.5.2: + resolution: {integrity: sha512-5BlMof9H1yGt0P8/WF+wPNw6GfctgGjXp5hkblpyT+8rkASSmkUKMXrxR0Xg8ThVCi/JnHQiKXeBaEwCeQwMFw==} engines: {node: '>=4.2.0'} hasBin: true dev: true - registry.npmjs.org/typescript/4.8.4: - resolution: {integrity: sha512-QCh+85mCy+h0IGff8r5XWzOVSbBO+KfeYrMQh7NJ58QujwcE22u+NUSmUxqF+un70P9GXKxa2HCNiTTMJknyjQ==, registry: https://registry.npmjs.com/, tarball: https://registry.npmjs.org/typescript/-/typescript-4.8.4.tgz} - name: typescript - version: 4.8.4 + /typescript@4.8.4: + resolution: {integrity: sha512-QCh+85mCy+h0IGff8r5XWzOVSbBO+KfeYrMQh7NJ58QujwcE22u+NUSmUxqF+un70P9GXKxa2HCNiTTMJknyjQ==} engines: {node: '>=4.2.0'} hasBin: true dev: true diff --git a/e2e/external_dep/MODULE.bazel b/e2e/external_dep/MODULE.bazel index 7c1fdd45..c82cadb1 100644 --- a/e2e/external_dep/MODULE.bazel +++ b/e2e/external_dep/MODULE.bazel @@ -11,8 +11,8 @@ local_path_override( # no such package '@[unknown repo 'aspect_rules_js' requested from @]//platforms': # The repository '@[unknown repo 'aspect_rules_js' requested from @]' could not be resolved: # No repository visible as '@aspect_rules_js' from main repository -bazel_dep(name = "aspect_rules_js", version = "1.37.1", dev_dependency = True) -bazel_dep(name = "bazel_skylib", version = "1.4.2", dev_dependency = True) +bazel_dep(name = "aspect_rules_js", version = "2.0.0-alpha.6", dev_dependency = True) +bazel_dep(name = "bazel_skylib", version = "1.5.0", dev_dependency = True) rules_ts_ext = use_extension("@aspect_rules_ts//ts:extensions.bzl", "ext", dev_dependency = True) rules_ts_ext.deps() diff --git a/e2e/external_dep/WORKSPACE b/e2e/external_dep/WORKSPACE index 4231c172..45365e72 100644 --- a/e2e/external_dep/WORKSPACE +++ b/e2e/external_dep/WORKSPACE @@ -11,15 +11,11 @@ load("@aspect_rules_js//js:repositories.bzl", "rules_js_dependencies") rules_js_dependencies() -# Fetch and register node, if you haven't already -load("@rules_nodejs//nodejs:repositories.bzl", "DEFAULT_NODE_VERSION", "nodejs_register_toolchains") +load("@aspect_rules_js//js:toolchains.bzl", "DEFAULT_NODE_VERSION", "rules_js_register_toolchains") -nodejs_register_toolchains( - name = "node", - node_version = DEFAULT_NODE_VERSION, -) +rules_js_register_toolchains(node_version = DEFAULT_NODE_VERSION) -load("@aspect_rules_js//npm:npm_import.bzl", "npm_translate_lock") +load("@aspect_rules_js//npm:repositories.bzl", "npm_translate_lock") npm_translate_lock( name = "npm", diff --git a/e2e/external_dep/app/MODULE.bazel b/e2e/external_dep/app/MODULE.bazel index 5443f6b2..0b736add 100644 --- a/e2e/external_dep/app/MODULE.bazel +++ b/e2e/external_dep/app/MODULE.bazel @@ -5,8 +5,8 @@ local_path_override( ) # TODO: see note on rules_js in the parent MODULE.bazel -bazel_dep(name = "aspect_rules_js", version = "1.37.1", dev_dependency = True) -bazel_dep(name = "bazel_skylib", version = "1.4.1", dev_dependency = True) +bazel_dep(name = "aspect_rules_js", version = "2.0.0-alpha.6", dev_dependency = True) +bazel_dep(name = "bazel_skylib", version = "1.5.0", dev_dependency = True) rules_ts_ext = use_extension("@aspect_rules_ts//ts:extensions.bzl", "ext", dev_dependency = True) rules_ts_ext.deps() diff --git a/e2e/external_dep/app/WORKSPACE b/e2e/external_dep/app/WORKSPACE index 1d8627bb..327f1c16 100644 --- a/e2e/external_dep/app/WORKSPACE +++ b/e2e/external_dep/app/WORKSPACE @@ -16,15 +16,11 @@ load("@aspect_rules_js//js:repositories.bzl", "rules_js_dependencies") rules_js_dependencies() -# Fetch and register node, if you haven't already -load("@rules_nodejs//nodejs:repositories.bzl", "DEFAULT_NODE_VERSION", "nodejs_register_toolchains") +load("@aspect_rules_js//js:toolchains.bzl", "DEFAULT_NODE_VERSION", "rules_js_register_toolchains") -nodejs_register_toolchains( - name = "node", - node_version = DEFAULT_NODE_VERSION, -) +rules_js_register_toolchains(node_version = DEFAULT_NODE_VERSION) -load("@aspect_rules_js//npm:npm_import.bzl", "npm_translate_lock") +load("@aspect_rules_js//npm:repositories.bzl", "npm_translate_lock") npm_translate_lock( name = "npm", diff --git a/e2e/test/common.bats b/e2e/test/common.bats index c2efa261..dc17f085 100644 --- a/e2e/test/common.bats +++ b/e2e/test/common.bats @@ -2,18 +2,24 @@ bats_load_library "bats-support" bats_load_library "bats-assert" function workspace() { - local rules_ts_path="$(realpath $BATS_TEST_DIRNAME/../../)" - local -i is_npm_translate_lock=0 - local -i no_convenience_symlinks=0 - while (( $# > 0 )); do - case "$1" in - -t|--npm-translate-lock) is_npm_translate_lock=1; shift ;; - -t|--noconvenience-symlinks) no_convenience_symlinks=1; shift ;; - *) break ;; - esac - done - - cat > WORKSPACE < 0)); do + case "$1" in + -t | --npm-translate-lock) + is_npm_translate_lock=1 + shift + ;; + -t | --noconvenience-symlinks) + no_convenience_symlinks=1 + shift + ;; + *) break ;; + esac + done + + cat >WORKSPACE < .bazelrc << EOF + cat >.bazelrc <>.bazelrc + fi - if (( no_convenience_symlinks )); then - echo "build --noexperimental_convenience_symlinks" >> .bazelrc - fi - - if (( is_npm_translate_lock )); then - cat >> WORKSPACE <>WORKSPACE < 0 )); do - case "$1" in - --path) shift; path="$1"; shift ;; - --no-implicit-any) no_implicit_any="true"; shift ;; - --isolated-modules) isolated_modules="true"; shift ;; - --source-map) source_map="true"; shift ;; - --declaration) declaration="true"; shift ;; - --composite) composite="true"; shift ;; - --target) shift; target="$1"; shift ;; - --module-resolution) shift; module_resolution="$1"; shift ;; - --trace-resolution) trace_resolution="true"; shift ;; - --extended-diagnostics) extended_diagnostics="true"; shift ;; - *) break ;; - esac - done - cat > "$path/tsconfig.json" < 0)); do + case "$1" in + --path) + shift + path="$1" + shift + ;; + --no-implicit-any) + no_implicit_any="true" + shift + ;; + --isolated-modules) + isolated_modules="true" + shift + ;; + --source-map) + source_map="true" + shift + ;; + --declaration) + declaration="true" + shift + ;; + --composite) + composite="true" + shift + ;; + --target) + shift + target="$1" + shift + ;; + --module-resolution) + shift + module_resolution="$1" + shift + ;; + --trace-resolution) + trace_resolution="true" + shift + ;; + --extended-diagnostics) + extended_diagnostics="true" + shift + ;; + *) break ;; + esac + done + cat >"$path/tsconfig.json" < 0 )); do - case "$1" in - --path) shift; path="$1"; shift ;; - --out_dir) shift; out_dir="$1"; shift ;; - --tsconfig) shift; tsconfig="$1"; shift ;; - -n|--name) shift; name="$1"; shift ;; - -l|--npm-link-all-packages) npm_link_all_packages=""; shift ;; - -d|--dep) shift; deps+=( "\"$1"\" ); shift ;; - -s|--src) shift; srcs+=( "\"$1\"" ); shift ;; - --arg) shift; args+=( "\"$1\"" "\"$2\"" ); shift; shift ;; - --source-map) shift; source_map="source_map = True," ;; - --declaration) shift; declaration="declaration = True," ;; - --composite) shift; composite="composite = True," ;; - --) shift; break ;; - *) break ;; - esac - done - local deps_joined=$(IFS=, ; echo "${deps[*]}") - local srcs_joined=$(IFS=, ; echo "${srcs[*]}") - local args_joined=$(IFS=, ; echo "${args[*]}") - cat > "$path/BUILD.bazel" < 0)); do + case "$1" in + --path) + shift + path="$1" + shift + ;; + --out_dir) + shift + out_dir="$1" + shift + ;; + --tsconfig) + shift + tsconfig="$1" + shift + ;; + -n | --name) + shift + name="$1" + shift + ;; + -l | --npm-link-all-packages) + npm_link_all_packages="" + shift + ;; + -d | --dep) + shift + deps+=("\"$1"\") + shift + ;; + -s | --src) + shift + srcs+=("\"$1\"") + shift + ;; + --arg) + shift + args+=("\"$1\"" "\"$2\"") + shift + shift + ;; + --source-map) + shift + source_map="source_map = True," + ;; + --declaration) + shift + declaration="declaration = True," + ;; + --composite) + shift + composite="composite = True," + ;; + --) + shift + break + ;; + *) break ;; + esac + done + local deps_joined=$( + IFS=, + echo "${deps[*]}" + ) + local srcs_joined=$( + IFS=, + echo "${srcs[*]}" + ) + local args_joined=$( + IFS=, + echo "${args[*]}" + ) + cat >"$path/BUILD.bazel" < 0 )); do - case "$1" in - --path) shift; path="$1"; shift ;; - -n|--name) shift; name="$1"; shift ;; - -s|--src) shift; srcs+=( "\"$1\"" ); shift ;; - -l|--npm-link-all-packages) npm_link_all_packages=""; shift ;; - --) shift; break ;; - *) break ;; - esac - done - local -a srcs_joined=$(IFS=, ; echo "${srcs[*]}") - cat > "$path/BUILD.bazel" < 0)); do + case "$1" in + --path) + shift + path="$1" + shift + ;; + -n | --name) + shift + name="$1" + shift + ;; + -s | --src) + shift + srcs+=("\"$1\"") + shift + ;; + -l | --npm-link-all-packages) + npm_link_all_packages="" + shift + ;; + --) + shift + break + ;; + *) break ;; + esac + done + local -a srcs_joined=$( + IFS=, + echo "${srcs[*]}" + ) + cat >"$path/BUILD.bazel" < 0 )); do - case "$1" in - --path) shift; path="$1"; shift ;; - -n|--name) shift; name="$1"; shift ;; - -s|--src) shift; srcs+=( "\"$1\"" ); shift ;; - --) shift; break ;; - *) break ;; - esac - done - local -a srcs_joined=$(IFS=, ; echo "${srcs[*]}") - cat >> "$path/BUILD.bazel" < 0)); do + case "$1" in + --path) + shift + path="$1" + shift + ;; + -n | --name) + shift + name="$1" + shift + ;; + -s | --src) + shift + srcs+=("\"$1\"") + shift + ;; + --) + shift + break + ;; + *) break ;; + esac + done + local -a srcs_joined=$( + IFS=, + echo "${srcs[*]}" + ) + cat >>"$path/BUILD.bazel" <= 2.0.0 and < 2.2.0. - # TODO(2.0): remove this and switch to the upstream function and bump minimum aspect_bazel_lib version to 2.2.0 - return "apple_binary" not in dir(native) and "cc_host_toolchain_alias" not in dir(native) diff --git a/ts/private/ts_config.bzl b/ts/private/ts_config.bzl index af6227ce..12d30ab3 100644 --- a/ts/private/ts_config.bzl +++ b/ts/private/ts_config.bzl @@ -34,30 +34,32 @@ def _ts_config_impl(ctx): transitive_deps = [ depset(copy_files_to_bin_actions(ctx, ctx.files.deps)), - js_lib_helpers.gather_files_from_js_providers( + js_lib_helpers.gather_files_from_js_infos( targets = ctx.attr.deps, + include_sources = True, + include_types = True, include_transitive_sources = True, - include_declarations = True, - include_npm_linked_packages = True, + include_transitive_types = True, + include_npm_sources = True, ), ] # TODO: now that ts_config.bzl provides a JsInfo, we should be able to remove TsConfigInfo in the future - # since transitive files will now be passed through transitive_declarations in JsInfo + # since transitive files will now be passed through transitive_types in JsInfo for dep in ctx.attr.deps: if TsConfigInfo in dep: transitive_deps.append(dep[TsConfigInfo].deps) transitive_sources = js_lib_helpers.gather_transitive_sources([], ctx.attr.deps) - transitive_declarations = js_lib_helpers.gather_transitive_declarations(files, ctx.attr.deps) + transitive_types = js_lib_helpers.gather_transitive_types(files, ctx.attr.deps) - npm_linked_packages = js_lib_helpers.gather_npm_linked_packages( + npm_sources = js_lib_helpers.gather_npm_sources( srcs = [], deps = ctx.attr.deps, ) - npm_package_store_deps = js_lib_helpers.gather_npm_package_store_deps( + npm_package_store_infos = js_lib_helpers.gather_npm_package_store_infos( targets = ctx.attr.deps, ) @@ -76,17 +78,15 @@ def _ts_config_impl(ctx): runfiles = runfiles, ), js_info( - # provide tsconfig.json file via `declarations` and not `sources` since they are only needed + # provide tsconfig.json file via `types` and not `sources` since they are only needed # for downstream ts_project rules and not in downstream runtime binary rules - declarations = files_depset, - npm_linked_package_files = npm_linked_packages.direct_files, - npm_linked_packages = npm_linked_packages.direct, - npm_package_store_deps = npm_package_store_deps, + target = ctx.label, sources = depset(), - transitive_declarations = transitive_declarations, - transitive_npm_linked_package_files = npm_linked_packages.transitive_files, - transitive_npm_linked_packages = npm_linked_packages.transitive, + types = files_depset, transitive_sources = transitive_sources, + transitive_types = transitive_types, + npm_sources = npm_sources, + npm_package_store_infos = npm_package_store_infos, ), TsConfigInfo(deps = depset(files, transitive = transitive_deps)), ] diff --git a/ts/private/ts_lib.bzl b/ts/private/ts_lib.bzl index 75bffb07..de720e58 100644 --- a/ts/private/ts_lib.bzl +++ b/ts/private/ts_lib.bzl @@ -1,8 +1,5 @@ "Utilities functions for selecting and filtering ts and other files" -load("@aspect_rules_js//js:libs.bzl", "js_lib_helpers") -load("@aspect_rules_js//js:providers.bzl", "JsInfo") - # Attributes common to all TypeScript rules STD_ATTRS = { "assets": attr.label_list( @@ -15,16 +12,23 @@ See more details on the `assets` parameter of the `ts_project` macro. "args": attr.string_list( doc = "https://www.typescriptlang.org/docs/handbook/compiler-options.html", ), - "data": js_lib_helpers.JS_LIBRARY_DATA_ATTR, + "data": attr.label_list( + doc = """Runtime dependencies to include in binaries/tests that depend on this target. + +Follows the same semantics as `js_library` `data` attribute. See +https://docs.aspect.build/rulesets/aspect_rules_js/docs/js_library#data for more info. +""", + allow_files = True, + ), "declaration_dir": attr.string( doc = "https://www.typescriptlang.org/tsconfig#declarationDir", ), "deps": attr.label_list( doc = """List of targets that produce TypeScript typings (`.d.ts` files) -{downstream_linked_npm_deps} -""".format(downstream_linked_npm_deps = js_lib_helpers.DOWNSTREAM_LINKED_NPM_DEPS_DOCSTRING), - providers = [JsInfo], +Follows the same runfiles semantics as `js_library` `deps` attribute. See +https://docs.aspect.build/rulesets/aspect_rules_js/docs/js_library#deps for more info. +""", ), "out_dir": attr.string( doc = "https://www.typescriptlang.org/tsconfig#outDir", diff --git a/ts/private/ts_project.bzl b/ts/private/ts_project.bzl index fcdf651a..f4807ea8 100644 --- a/ts/private/ts_project.bzl +++ b/ts/private/ts_project.bzl @@ -6,7 +6,6 @@ load("@aspect_bazel_lib//lib:paths.bzl", "to_output_relative_path") load("@aspect_bazel_lib//lib:platform_utils.bzl", "platform_utils") load("@aspect_rules_js//js:libs.bzl", "js_lib_helpers") load("@aspect_rules_js//js:providers.bzl", "JsInfo", "js_info") -load("@aspect_rules_js//npm:providers.bzl", "NpmPackageStoreInfo") load("@bazel_skylib//lib:dicts.bzl", "dicts") load(":options.bzl", "OptionsInfo", "transpiler_selection_required") load(":ts_config.bzl", "TsConfigInfo") @@ -14,23 +13,18 @@ load(":ts_lib.bzl", "COMPILER_OPTION_ATTRS", "OUTPUT_ATTRS", "STD_ATTRS", _lib = load(":ts_validate_options.bzl", _validate_lib = "lib") # Forked from js_lib_helpers.js_lib_helpers.gather_files_from_js_providers to not -# include any sources; only transitive declarations & npm linked packages -def _gather_declarations_from_js_providers(targets): +# include any sources; only transitive types & npm sources +def _gather_types_from_js_infos(targets): files_depsets = [] files_depsets.extend([ - target[JsInfo].transitive_declarations + target[JsInfo].transitive_types for target in targets - if JsInfo in target and hasattr(target[JsInfo], "transitive_declarations") + if JsInfo in target and hasattr(target[JsInfo], "transitive_types") ]) files_depsets.extend([ - target[JsInfo].transitive_npm_linked_package_files + target[JsInfo].npm_sources for target in targets - if JsInfo in target and hasattr(target[JsInfo], "transitive_npm_linked_package_files") - ]) - files_depsets.extend([ - target[NpmPackageStoreInfo].transitive_files - for target in targets - if NpmPackageStoreInfo in target and hasattr(target[NpmPackageStoreInfo], "transitive_files") + if JsInfo in target and hasattr(target[JsInfo], "npm_sources") ]) return depset([], transitive = files_depsets) @@ -215,29 +209,29 @@ This might be because This is an error because Bazel does not run actions unless their outputs are needed for the requested targets to build. """) - output_declarations = typings_outs + typing_maps_outs + typings_srcs + output_types = typings_outs + typing_maps_outs + typings_srcs # Default outputs (DefaultInfo files) is what you see on the command-line for a built # library, and determines what files are used by a simple non-provider-aware downstream # library. Only the JavaScript outputs are intended for use in non-TS-aware dependents. if ctx.attr.transpile != 0: # Special case case where there are no source outputs and we don't have a custom - # transpiler so we add output_declarations to the default outputs - default_outputs = output_sources[:] if len(output_sources) else output_declarations[:] + # transpiler so we add output_types to the default outputs + default_outputs = output_sources[:] if len(output_sources) else output_types[:] else: # We must avoid tsc writing any JS files in this case, as tsc was only run for typings, and some other # action will try to write the JS files. We must avoid collisions where two actions write the same file. arguments.add("--emitDeclarationOnly") # We don't produce any DefaultInfo outputs in this case, because we avoid running the tsc action - # unless the output_declarations are requested. + # unless the output_types are requested. default_outputs = [] inputs_depset = depset() if len(outputs) > 0: inputs_depset = depset( copy_files_to_bin_actions(ctx, inputs), - transitive = transitive_inputs + [_gather_declarations_from_js_providers(ctx.attr.srcs + [ctx.attr.tsconfig] + ctx.attr.deps)], + transitive = transitive_inputs + [_gather_types_from_js_infos(ctx.attr.srcs + [ctx.attr.tsconfig] + ctx.attr.deps)], ) if ctx.attr.transpile != 0 and not ctx.attr.emit_declaration_only: @@ -270,18 +264,18 @@ This is an error because Bazel does not run actions unless their outputs are nee transitive_sources = js_lib_helpers.gather_transitive_sources(output_sources, ctx.attr.srcs + [ctx.attr.tsconfig] + ctx.attr.deps) - transitive_declarations = js_lib_helpers.gather_transitive_declarations(output_declarations, ctx.attr.srcs + [ctx.attr.tsconfig] + ctx.attr.deps) + transitive_types = js_lib_helpers.gather_transitive_types(output_types, ctx.attr.srcs + [ctx.attr.tsconfig] + ctx.attr.deps) - npm_linked_packages = js_lib_helpers.gather_npm_linked_packages( + npm_sources = js_lib_helpers.gather_npm_sources( srcs = ctx.attr.srcs + [ctx.attr.tsconfig], deps = ctx.attr.deps, ) - npm_package_store_deps = js_lib_helpers.gather_npm_package_store_deps( - targets = ctx.attr.data + ctx.attr.deps, + npm_package_store_infos = js_lib_helpers.gather_npm_package_store_infos( + targets = ctx.attr.srcs + ctx.attr.data + ctx.attr.deps, ) - output_declarations_depset = depset(output_declarations) + output_types_depset = depset(output_types) output_sources_depset = depset(output_sources) runfiles = js_lib_helpers.gather_runfiles( @@ -297,15 +291,13 @@ This is an error because Bazel does not run actions unless their outputs are nee runfiles = runfiles, ), js_info( - declarations = output_declarations_depset, - npm_linked_package_files = npm_linked_packages.direct_files, - npm_linked_packages = npm_linked_packages.direct, - npm_package_store_deps = npm_package_store_deps, + target = ctx.label, sources = output_sources_depset, - transitive_declarations = transitive_declarations, - transitive_npm_linked_package_files = npm_linked_packages.transitive_files, - transitive_npm_linked_packages = npm_linked_packages.transitive, + types = output_types_depset, transitive_sources = transitive_sources, + transitive_types = transitive_types, + npm_sources = npm_sources, + npm_package_store_infos = npm_package_store_infos, ), TsConfigInfo(deps = depset(tsconfig_inputs, transitive = [ dep[TsConfigInfo].deps @@ -313,7 +305,7 @@ This is an error because Bazel does not run actions unless their outputs are nee if TsConfigInfo in dep ])), OutputGroupInfo( - types = output_declarations_depset, + types = output_types_depset, # make the inputs to the tsc action available for analysis testing _action_inputs = inputs_depset, # https://bazel.build/extending/rules#validations_output_group diff --git a/ts/private/ts_proto_library.bzl b/ts/private/ts_proto_library.bzl index 6fa8c30f..4fead054 100644 --- a/ts/private/ts_proto_library.bzl +++ b/ts/private/ts_proto_library.bzl @@ -96,10 +96,11 @@ def _ts_proto_library_impl(ctx): ), OutputGroupInfo(types = direct_decls), js_info( - declarations = direct_decls, + target = ctx.label, + types = direct_decls, sources = direct_srcs, - transitive_declarations = js_lib_helpers.gather_transitive_declarations( - declarations = dts_outs, + transitive_types = js_lib_helpers.gather_transitive_types( + types = dts_outs, targets = ctx.attr.deps, ), transitive_sources = js_lib_helpers.gather_transitive_sources( diff --git a/ts/private/ts_validate_options.bzl b/ts/private/ts_validate_options.bzl index 6d979a4c..4739b200 100644 --- a/ts/private/ts_validate_options.bzl +++ b/ts/private/ts_validate_options.bzl @@ -25,10 +25,10 @@ def _validate_options_impl(ctx): # Provider validation if not ctx.attr.allow_js: for d in ctx.attr.deps: - if not d[JsInfo].declarations: + if not d[JsInfo].types: fail("""\ -ts_project '{1}' dependency '{0}' does does not contain any declarations (.d.ts or other type-check files). -Generally, targets which produce no declarations aren't useful as dependencies to the TypeScript type-checker. +ts_project '{1}' dependency '{0}' does does not contain any types (.d.ts or other type-check files). +Generally, targets which produce no types aren't useful as dependencies to the TypeScript type-checker. This likely means you forgot to set 'declaration = true' in the compilerOptions for that target. To disable this check, set the validate attribute to False: diff --git a/ts/repositories.bzl b/ts/repositories.bzl index ea11f90e..502b5c23 100644 --- a/ts/repositories.bzl +++ b/ts/repositories.bzl @@ -24,28 +24,29 @@ def http_archive(**kwargs): def rules_ts_bazel_dependencies(): http_archive( name = "bazel_skylib", - sha256 = "b8a1527901774180afc798aeb28c4634bdccf19c4d98e7bdd1ce79d1fe9aaad7", - urls = ["https://github.com/bazelbuild/bazel-skylib/releases/download/1.4.1/bazel-skylib-1.4.1.tar.gz"], + sha256 = "cd55a062e763b9349921f0f5db8c3933288dc8ba4f76dd9416aac68acee3cb94", + urls = ["https://github.com/bazelbuild/bazel-skylib/releases/download/1.5.0/bazel-skylib-1.5.0.tar.gz"], ) http_archive( name = "aspect_bazel_lib", - sha256 = "04feedcd06f71d0497a81fdd3220140a373ff9d2bff94620fbd50b774f96d8e0", - strip_prefix = "bazel-lib-1.40.2", - url = "https://github.com/aspect-build/bazel-lib/releases/download/v1.40.2/bazel-lib-v1.40.2.tar.gz", + sha256 = "87ab4ec479ebeb00d286266aca2068caeef1bb0b1765e8f71c7b6cfee6af4226", + strip_prefix = "bazel-lib-2.7.3", + url = "https://github.com/aspect-build/bazel-lib/releases/download/v2.7.3/bazel-lib-v2.7.3.tar.gz", ) http_archive( name = "aspect_rules_js", - sha256 = "d9ceb89e97bb5ad53b278148e01a77a3e9100db272ce4ebdcd59889d26b9076e", - strip_prefix = "rules_js-1.34.0", - url = "https://github.com/aspect-build/rules_js/releases/download/v1.34.0/rules_js-v1.34.0.tar.gz", + sha256 = "03d9e0c1da0ee9dd8ff52ba0f6ee5d173848c00ef4c85ec558aad0a9cf56ac46", + strip_prefix = "rules_js-2.0.0-alpha.6", + url = "https://github.com/aspect-build/rules_js/releases/download/v2.0.0-alpha.6/rules_js-v2.0.0-alpha.6.tar.gz", ) http_archive( name = "rules_nodejs", - sha256 = "764a3b3757bb8c3c6a02ba3344731a3d71e558220adcb0cf7e43c9bba2c37ba8", - urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/5.8.2/rules_nodejs-core-5.8.2.tar.gz"], + sha256 = "dddd60acc3f2f30359bef502c9d788f67e33814b0ddd99aa27c5a15eb7a41b8c", + strip_prefix = "rules_nodejs-6.1.0", + url = "https://github.com/bazelbuild/rules_nodejs/releases/download/v6.1.0/rules_nodejs-v6.1.0.tar.gz", ) def rules_ts_dependencies(ts_version_from = None, ts_version = None, ts_integrity = None): diff --git a/ts/test/transpiler_tests.bzl b/ts/test/transpiler_tests.bzl index caf5256c..76d35d9c 100644 --- a/ts/test/transpiler_tests.bzl +++ b/ts/test/transpiler_tests.bzl @@ -11,15 +11,15 @@ def _impl0(ctx): env = unittest.begin(ctx) decls = [] - for decl in ctx.attr.lib[JsInfo].declarations.to_list(): + for decl in ctx.attr.lib[JsInfo].types.to_list(): decls.append(decl.basename) - asserts.equals(env, ctx.attr.expected_declarations, sorted(decls)) + asserts.equals(env, ctx.attr.expected_types, sorted(decls)) return unittest.end(env) -transitive_declarations_test = unittest.make(_impl0, attrs = { +transitive_types_test = unittest.make(_impl0, attrs = { "lib": attr.label(default = ":transpile"), - "expected_declarations": attr.string_list(default = ["big.d.ts"]), + "expected_types": attr.string_list(default = ["big.d.ts"]), }) def _impl1(ctx): @@ -61,16 +61,16 @@ def _impl3(ctx): asserts.equals(env, ctx.attr.expected_js, sorted(js_files)) decls = [] - for decl in ctx.attr.lib[JsInfo].declarations.to_list(): + for decl in ctx.attr.lib[JsInfo].types.to_list(): decls.append(decl.basename) - asserts.equals(env, ctx.attr.expected_declarations, sorted(decls)) + asserts.equals(env, ctx.attr.expected_types, sorted(decls)) return unittest.end(env) transitive_filegroup_test = unittest.make(_impl3, attrs = { "lib": attr.label(default = ":transpile_filegroup"), "expected_js": attr.string_list(default = ["src_fg_a.js", "src_fg_a.js.map", "src_fg_b.js", "src_fg_b.js.map"]), - "expected_declarations": attr.string_list(default = ["src_fg_a.d.ts", "src_fg_b.d.ts"]), + "expected_types": attr.string_list(default = ["src_fg_a.d.ts", "src_fg_b.d.ts"]), }) # buildifier: disable=function-docstring @@ -201,7 +201,7 @@ def transpiler_test_suite(): tsconfig = _TSCONFIG, ) - unittest.suite("t0", transitive_declarations_test) + unittest.suite("t0", transitive_types_test) unittest.suite("t1", transpile_with_failing_typecheck_test) unittest.suite("t2", transpile_with_dts_test) unittest.suite("t3", transitive_filegroup_test) diff --git a/ts/test/ts_project_test.bzl b/ts/test/ts_project_test.bzl index a77e69f9..ab4e11a5 100644 --- a/ts/test/ts_project_test.bzl +++ b/ts/test/ts_project_test.bzl @@ -29,18 +29,18 @@ def _dir_test_impl(ctx): asserts.true(env, transitive_sources[0].path.find("/dir.js") != -1) asserts.true(env, transitive_sources[1].path.find("/dir.js.map") != -1) - # declarations should only have the source declarations - declarations = target_under_test[JsInfo].declarations.to_list() - asserts.equals(env, 1, len(declarations)) - asserts.true(env, declarations[0].path.find("/dir.d.ts") != -1) + # types should only have the source types + types = target_under_test[JsInfo].types.to_list() + asserts.equals(env, 1, len(types)) + asserts.true(env, types[0].path.find("/dir.d.ts") != -1) - # transitive_declarations should have the source declarations and transitive declarations - transitive_declarations = target_under_test[JsInfo].transitive_declarations.to_list() - asserts.equals(env, 1, len(transitive_declarations)) - asserts.true(env, transitive_declarations[0].path.find("/dir.d.ts") != -1) + # transitive_types should have the source types and transitive types + transitive_types = target_under_test[JsInfo].transitive_types.to_list() + asserts.equals(env, 1, len(transitive_types)) + asserts.true(env, transitive_types[0].path.find("/dir.d.ts") != -1) - # types OutputGroupInfo should be the same as declarations - asserts.equals(env, declarations, target_under_test[OutputGroupInfo].types.to_list()) + # types OutputGroupInfo should be the same as types + asserts.equals(env, types, target_under_test[OutputGroupInfo].types.to_list()) return analysistest.end(env) @@ -53,7 +53,7 @@ def _use_dir_test_impl(ctx): # assert the inputs to the tsc action are what we expect; # the inputs should *NOT* includes the sources from any deps or transitive deps; - # only declarations from deps should be included as action inputs. + # only types from deps should be included as action inputs. action_inputs = target_under_test[OutputGroupInfo]._action_inputs.to_list() asserts.equals(env, 3, len(action_inputs)) asserts.true(env, action_inputs[0].path.find("/dir.d.ts") != -1) @@ -74,19 +74,19 @@ def _use_dir_test_impl(ctx): asserts.true(env, transitive_sources[2].path.find("/dir.js") != -1) asserts.true(env, transitive_sources[3].path.find("/dir.js.map") != -1) - # declarations should only have the source declarations - declarations = target_under_test[JsInfo].declarations.to_list() - asserts.equals(env, 1, len(declarations)) - asserts.true(env, declarations[0].path.find("/use_dir.d.ts") != -1) + # types should only have the source types + types = target_under_test[JsInfo].types.to_list() + asserts.equals(env, 1, len(types)) + asserts.true(env, types[0].path.find("/use_dir.d.ts") != -1) - # transitive_declarations should have the source declarations and transitive declarations - transitive_declarations = target_under_test[JsInfo].transitive_declarations.to_list() - asserts.equals(env, 2, len(transitive_declarations)) - asserts.true(env, transitive_declarations[0].path.find("/use_dir.d.ts") != -1) - asserts.true(env, transitive_declarations[1].path.find("/dir.d.ts") != -1) + # transitive_types should have the source types and transitive types + transitive_types = target_under_test[JsInfo].transitive_types.to_list() + asserts.equals(env, 2, len(transitive_types)) + asserts.true(env, transitive_types[0].path.find("/use_dir.d.ts") != -1) + asserts.true(env, transitive_types[1].path.find("/dir.d.ts") != -1) - # types OutputGroupInfo should be the same as declarations - asserts.equals(env, declarations, target_under_test[OutputGroupInfo].types.to_list()) + # types OutputGroupInfo should be the same as types + asserts.equals(env, types, target_under_test[OutputGroupInfo].types.to_list()) return analysistest.end(env)