build: migrate symbol-extractor to ts_project (#61209)

Migrates the symbol-extractor code to `ts_project`.

PR Close #61209
This commit is contained in:
Paul Gschwendtner 2025-05-07 06:50:28 +00:00 committed by Alex Rickabaugh
parent 1312eb1600
commit d37f5085e4
13 changed files with 69 additions and 76 deletions

View file

@ -258,7 +258,7 @@ setup_dependencies_2()
git_repository(
name = "rules_angular",
commit = "f47fe935fecac02f02fe1337274207f00146a765",
commit = "e35da7371d02d0c8d165c518d532d66be7afb8a6",
remote = "https://github.com/devversion/rules_angular.git",
)

View file

@ -35,7 +35,7 @@ ts_config(
)
rules_js_tsconfig(
name = "build-tsconfig",
name = "tsconfig_build",
src = "tsconfig-build.json",
deps = [
"//:node_modules/tslib",
@ -43,10 +43,10 @@ rules_js_tsconfig(
)
rules_js_tsconfig(
name = "test-tsconfig",
name = "tsconfig_test",
src = "tsconfig-test.json",
deps = [
":build-tsconfig",
":tsconfig_build",
"//:node_modules/@types/jasmine",
],
)

View file

@ -1,3 +1,4 @@
load("@aspect_rules_ts//ts:defs.bzl", rules_js_tsconfig = "ts_config")
load("//tools:defaults.bzl", "ts_config")
package(default_visibility = ["//visibility:public"])
@ -13,6 +14,21 @@ ts_config(
deps = ["tsconfig.json"],
)
rules_js_tsconfig(
name = "tsconfig_build",
src = "tsconfig.json",
deps = ["//:node_modules/@types/node"],
)
rules_js_tsconfig(
name = "tsconfig_test",
src = "tsconfig-test.json",
deps = [
":tsconfig_build",
"//:node_modules/@types/jasmine",
],
)
platform(
name = "rbe_ubuntu1604-angular",
parents = ["@rbe_ubuntu1604_angular//config:platform"],

View file

@ -106,7 +106,8 @@ def ts_project(
tsconfig = None,
testonly = False,
visibility = None,
ignore_strict_deps = False,
# TODO: Enable this for all `ts_project` targets at end of migration.
ignore_strict_deps = True,
enable_runtime_rnjs_interop = True,
rule_impl = _ts_project,
**kwargs):

View file

@ -11,7 +11,7 @@ def ts_project(
module_name = kwargs.pop("module_name", compute_module_name(testonly))
if tsconfig == None and native.package_name().startswith("packages"):
tsconfig = "//packages:test-tsconfig" if testonly else "//packages:build-tsconfig"
tsconfig = "//packages:tsconfig_test" if testonly else "//packages:tsconfig_build"
_ts_project(
name,
@ -31,7 +31,7 @@ def ng_project(
module_name = kwargs.pop("module_name", compute_module_name(testonly))
if tsconfig == None and native.package_name().startswith("packages"):
tsconfig = "//packages:test-tsconfig" if testonly else "//packages:build-tsconfig"
tsconfig = "//packages:tsconfig_test" if testonly else "//packages:tsconfig_build"
_ts_project(
name,
source_map = source_map,

View file

@ -1,8 +1,9 @@
load("//tools:defaults.bzl", "jasmine_node_test", "ts_library")
load("//tools:defaults.bzl", "jasmine_node_test")
load("//tools:defaults2.bzl", "ts_project")
package(default_visibility = ["//visibility:public"])
ts_library(
ts_project(
name = "lib",
testonly = True,
srcs = glob(
@ -12,25 +13,26 @@ ts_library(
"**/*_spec",
],
),
tsconfig = "//tools:tsconfig_build",
deps = [
"//packages:types",
"@npm//@bazel/runfiles",
"@npm//typescript",
"//:node_modules/@bazel/runfiles",
"//:node_modules/@types/jasmine",
"//:node_modules/typescript",
],
)
ts_library(
ts_project(
name = "test_lib",
testonly = 1,
srcs = glob(
["**/*_spec.ts"],
exclude = ["symbol_extractor_spec/**"],
),
tsconfig = "//tools:tsconfig_test",
deps = [
":lib",
"//packages:types",
"@npm//@bazel/runfiles",
"@npm//typescript",
":lib_rjs",
"//:node_modules/@bazel/runfiles",
"//:node_modules/typescript",
],
)

View file

@ -3,7 +3,7 @@
# Use of this source code is governed by an MIT-style license that can be
# found in the LICENSE file at https://angular.dev/license
load("//tools:defaults.bzl", "nodejs_binary", "nodejs_test")
load("@aspect_rules_js//js:defs.bzl", "js_binary", "js_test")
"""
This test verifies that a set of top level symbols from a javascript file match a gold file.
@ -13,27 +13,26 @@ def js_expected_symbol_test(name, src, golden, data = [], **kwargs):
"""This test verifies that a set of top level symbols from a javascript file match a gold file.
"""
all_data = data + [
Label("//tools/symbol-extractor:lib"),
Label("@npm//typescript"),
Label("//tools/symbol-extractor:lib_rjs"),
src,
golden,
]
entry_point = "//tools/symbol-extractor:cli.ts"
entry_point = "//tools/symbol-extractor:cli.js"
nodejs_test(
js_test(
name = name,
data = all_data,
entry_point = entry_point,
tags = kwargs.pop("tags", []) + ["symbol_extractor"],
templated_args = ["$(rootpath %s)" % src, "$(rootpath %s)" % golden],
fixed_args = ["$(rootpath %s)" % src, "$(rootpath %s)" % golden],
**kwargs
)
nodejs_binary(
js_binary(
name = name + ".accept",
testonly = True,
data = all_data,
entry_point = entry_point,
templated_args = ["$(rootpath %s)" % src, "$(rootpath %s)" % golden, "--accept"],
fixed_args = ["$(rootpath %s)" % src, "$(rootpath %s)" % golden, "--accept"],
**kwargs
)

View file

@ -6,6 +6,8 @@
* found in the LICENSE file at https://angular.dev/license
*/
/// <reference types="jasmine" />
import ts from 'typescript';
export class SymbolExtractor {

View file

@ -49,7 +49,7 @@ describe('scenarios', () => {
it('should properly capture classes in TypeScript ES2015 class output', () => {
const jsFileContent = fs.readFileSync(
runfiles.resolve(
'angular/tools/symbol-extractor/symbol_extractor_spec/es2015_class_output.mjs',
'angular/tools/symbol-extractor/symbol_extractor_spec/es2015_class_output.js',
),
'utf8',
);

View file

@ -1,16 +1,11 @@
load("//tools:defaults.bzl", "ts_library")
load("//tools:defaults2.bzl", "ts_project")
package(default_visibility = ["//visibility:public"])
ts_library(
name = "es2015_class_output_lib",
srcs = ["es2015_class_output.ts"],
)
filegroup(
ts_project(
name = "es2015_class_output",
srcs = [":es2015_class_output_lib"],
output_group = "es6_sources",
srcs = ["es2015_class_output.ts"],
tsconfig = "tsconfig.json",
)
filegroup(

View file

@ -0,0 +1,9 @@
{
"compilerOptions": {
"strict": true,
"module": "ESNext",
"target": "ES2022",
"sourceMap": true,
"declaration": true
}
}

View file

@ -1,9 +1,6 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"types": [
"node",
"jasmine"
]
},
}
"types": ["node", "jasmine"]
}
}

View file

@ -1,40 +1,12 @@
{
// This tsconfig is only used by IDEs, no actual builds.
"compilerOptions": {
"baseUrl": ".",
"declaration": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"module": "commonjs",
"esModuleInterop": true,
"moduleResolution": "node",
"outDir": "../dist/tools/",
"noImplicitAny": true,
"noFallthroughCasesInSwitch": true,
"paths": {
"@angular/*": ["../packages/*"]
},
"rootDirs": [".", ".."],
"sourceMap": true,
"inlineSources": true,
"lib": [
"es6",
"dom"
],
"target": "es5",
"strict": true,
"skipLibCheck": true,
"types": [
"node"
]
},
"exclude": [
"testing",
"node_modules",
"typings-test",
"public_api_guard",
"docs"
],
"bazelOptions": {
"suppressTsconfigOverrideWarnings": true
"declaration": true,
"esModuleInterop": true,
"sourceMap": true,
"module": "CommonJS",
"moduleResolution": "node10",
"types": ["node"]
}
}