Skip to content

Commit 185b780

Browse files
devversionthePunderWoman
authored andcommitted
build: migrate packages/core/schematics to ts_project (#61420)
Migrates `packages/core/schematics` to `ts_project`. As part of this, this commit cleans up some of the mixed module types and tsconfigs in the folder. A single tsconfig (and it's test variant) are now used. For the shipped schematics, we explicitly use the `.cjs` extension, so that the bundles are properly recognized as CommonJS; even if they are part of the `type: module` `@angular/core` package. The `package.json` with `type: commonjs` is removed from `packages/core/schematics` as it's no longer needed given the explicit extension & caused issues as schematics are compiled with ESM but are only later bundled for shipping & some tests as ESM. PR Close #61420
1 parent f07ef54 commit 185b780

File tree

40 files changed

+266
-362
lines changed

40 files changed

+266
-362
lines changed

packages/common/http/test/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ ts_library(
99
# Visible to //:saucelabs_unit_tests_poc target
1010
visibility = ["//:__pkg__"],
1111
deps = [
12+
"//packages:types",
1213
"//packages/common",
1314
"//packages/common/http",
1415
"//packages/common/http/testing",

packages/core/schematics/BUILD.bazel

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,37 @@
1-
load("@aspect_bazel_lib//lib:copy_to_bin.bzl", "copy_to_bin")
21
load("@npm//@bazel/rollup:index.bzl", "rollup_bundle")
32
load("//tools:defaults.bzl", "pkg_npm")
3+
load("//tools:defaults2.bzl", "ts_config")
44

55
exports_files([
66
"tsconfig.json",
77
"migrations.json",
88
"collection.json",
99
])
1010

11-
copy_to_bin(
12-
name = "package_json",
13-
srcs = ["package.json"],
14-
visibility = ["//packages/core/schematics/test:__subpackages__"],
11+
ts_config(
12+
name = "tsconfig_build",
13+
src = "tsconfig.json",
14+
visibility = ["//packages/core/schematics:__subpackages__"],
15+
deps = [
16+
"//:node_modules/@types/node",
17+
],
18+
)
19+
20+
ts_config(
21+
name = "tsconfig_test",
22+
src = "tsconfig-test.json",
23+
visibility = ["//packages/core/schematics:__subpackages__"],
24+
deps = [
25+
":tsconfig_build",
26+
"//:node_modules/@types/jasmine",
27+
],
1528
)
1629

1730
pkg_npm(
1831
name = "npm_package",
1932
srcs = [
2033
"collection.json",
2134
"migrations.json",
22-
"package.json",
2335
"//packages/core/schematics/ng-generate/cleanup-unused-imports:static_files",
2436
"//packages/core/schematics/ng-generate/control-flow-migration:static_files",
2537
"//packages/core/schematics/ng-generate/inject-migration:static_files",

packages/core/schematics/collection.json

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,59 +2,59 @@
22
"schematics": {
33
"standalone-migration": {
44
"description": "Converts the entire application or a part of it to standalone",
5-
"factory": "./bundles/standalone-migration#migrate",
5+
"factory": "./bundles/standalone-migration.cjs#migrate",
66
"schema": "./ng-generate/standalone-migration/schema.json",
77
"aliases": ["standalone"]
88
},
99
"control-flow-migration": {
1010
"description": "Converts the entire application to block control flow syntax",
11-
"factory": "./bundles/control-flow-migration#migrate",
11+
"factory": "./bundles/control-flow-migration.cjs#migrate",
1212
"schema": "./ng-generate/control-flow-migration/schema.json",
1313
"aliases": ["control-flow"]
1414
},
1515
"inject-migration": {
1616
"description": "Converts usages of constructor-based injection to the inject() function",
17-
"factory": "./bundles/inject-migration#migrate",
17+
"factory": "./bundles/inject-migration.cjs#migrate",
1818
"schema": "./ng-generate/inject-migration/schema.json",
1919
"aliases": ["inject"]
2020
},
2121
"route-lazy-loading-migration": {
2222
"description": "Updates route definitions to use lazy-loading of components instead of eagerly referencing them",
23-
"factory": "./bundles/route-lazy-loading#migrate",
23+
"factory": "./bundles/route-lazy-loading.cjs#migrate",
2424
"schema": "./ng-generate/route-lazy-loading/schema.json",
2525
"aliases": ["route-lazy-loading"]
2626
},
2727
"signal-input-migration": {
2828
"description": "Updates `@Input` declarations to signal inputs, while also migrating all relevant references.",
29-
"factory": "./bundles/signal-input-migration#migrate",
29+
"factory": "./bundles/signal-input-migration.cjs#migrate",
3030
"schema": "./ng-generate/signal-input-migration/schema.json",
3131
"aliases": ["signal-inputs", "signal-input"]
3232
},
3333
"signal-queries-migration": {
3434
"description": "Updates query declarations to signal queries, while also migrating all relevant references.",
35-
"factory": "./bundles/signal-queries-migration#migrate",
35+
"factory": "./bundles/signal-queries-migration.cjs#migrate",
3636
"schema": "./ng-generate/signal-queries-migration/schema.json",
3737
"aliases": ["signal-queries", "signal-query", "signal-query-migration"]
3838
},
3939
"output-migration": {
4040
"description": "Updates @output declarations to the functional equivalent, while also migrating all relevant references.",
41-
"factory": "./bundles/output-migration#migrate",
41+
"factory": "./bundles/output-migration.cjs#migrate",
4242
"schema": "./ng-generate/output-migration/schema.json",
4343
"aliases": ["outputs"]
4444
},
4545
"signals": {
4646
"description": "Combines all signals-related migrations into a single migration",
47-
"factory": "./bundles/signals#migrate",
47+
"factory": "./bundles/signals.cjs#migrate",
4848
"schema": "./ng-generate/signals/schema.json"
4949
},
5050
"cleanup-unused-imports": {
5151
"description": "Removes unused imports from standalone components.",
52-
"factory": "./bundles/cleanup-unused-imports#migrate",
52+
"factory": "./bundles/cleanup-unused-imports.cjs#migrate",
5353
"schema": "./ng-generate/cleanup-unused-imports/schema.json"
5454
},
5555
"self-closing-tags-migration": {
5656
"description": "Updates the components templates to use self-closing tags where possible",
57-
"factory": "./bundles/self-closing-tags-migration#migrate",
57+
"factory": "./bundles/self-closing-tags-migration.cjs#migrate",
5858
"schema": "./ng-generate/self-closing-tags-migration/schema.json",
5959
"aliases": ["self-closing-tag"]
6060
}

packages/core/schematics/migrations.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@
33
"explicit-standalone-flag": {
44
"version": "19.0.0",
55
"description": "Updates non-standalone Directives, Component and Pipes to 'standalone:false' and removes 'standalone:true' from those who are standalone",
6-
"factory": "./bundles/explicit-standalone-flag#migrate"
6+
"factory": "./bundles/explicit-standalone-flag.cjs#migrate"
77
},
88
"pending-tasks": {
99
"version": "19.0.0",
1010
"description": "Updates ExperimentalPendingTasks to PendingTasks",
11-
"factory": "./bundles/pending-tasks#migrate"
11+
"factory": "./bundles/pending-tasks.cjs#migrate"
1212
},
1313
"provide-initializer": {
1414
"version": "19.0.0",
1515
"description": "Replaces `APP_INITIALIZER`, `ENVIRONMENT_INITIALIZER` & `PLATFORM_INITIALIZER` respectively with `provideAppInitializer`, `provideEnvironmentInitializer` & `providePlatformInitializer`.",
16-
"factory": "./bundles/provide-initializer#migrate",
16+
"factory": "./bundles/provide-initializer.cjs#migrate",
1717
"optional": true
1818
}
1919
}
Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
load("//tools:defaults.bzl", "ts_library")
1+
load("//tools:defaults2.bzl", "ts_project")
22

33
package(
44
default_visibility = [
@@ -7,14 +7,12 @@ package(
77
],
88
)
99

10-
ts_library(
10+
ts_project(
1111
name = "explicit-standalone-flag",
1212
srcs = glob(["**/*.ts"]),
13-
tsconfig = "//packages/core/schematics:tsconfig.json",
1413
deps = [
15-
"//packages/core/schematics/utils",
16-
"@npm//@angular-devkit/schematics",
17-
"@npm//@types/node",
18-
"@npm//typescript",
14+
"//:node_modules/@angular-devkit/schematics",
15+
"//:node_modules/typescript",
16+
"//packages/core/schematics/utils:utils_rjs",
1917
],
2018
)

packages/core/schematics/migrations/output-migration/BUILD.bazel

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
1-
load("//tools:defaults.bzl", "jasmine_node_test", "ts_library")
1+
load("//tools:defaults.bzl", "jasmine_node_test")
2+
load("//tools:defaults2.bzl", "ts_project")
23

3-
ts_library(
4+
ts_project(
45
name = "migration",
56
srcs = glob(
67
["**/*.ts"],
78
exclude = ["*.spec.ts"],
89
),
9-
visibility = [
10-
"//packages/core/schematics/ng-generate/output-migration:__pkg__",
11-
"//packages/language-service/src/refactorings:__pkg__",
12-
],
13-
deps = [
10+
interop_deps = [
1411
"//packages/compiler",
1512
"//packages/compiler-cli",
1613
"//packages/compiler-cli/private",
@@ -21,23 +18,30 @@ ts_library(
2118
"//packages/compiler-cli/src/ngtsc/reflection",
2219
"//packages/core/schematics/migrations/signal-migration/src",
2320
"//packages/core/schematics/utils/tsurge",
24-
"@npm//@types/node",
25-
"@npm//typescript",
21+
],
22+
visibility = [
23+
"//packages/core/schematics/ng-generate/output-migration:__pkg__",
24+
"//packages/language-service/src/refactorings:__pkg__",
25+
],
26+
deps = [
27+
"//:node_modules/@types/node",
28+
"//:node_modules/typescript",
2629
],
2730
)
2831

29-
ts_library(
32+
ts_project(
3033
name = "test_lib",
3134
testonly = True,
3235
srcs = glob(
3336
["**/*.spec.ts"],
3437
),
35-
deps = [
38+
interop_deps = [
3639
":migration",
3740
"//packages/compiler-cli",
3841
"//packages/compiler-cli/src/ngtsc/file_system/testing",
3942
"//packages/core/schematics/utils/tsurge",
4043
],
44+
deps = [],
4145
)
4246

4347
jasmine_node_test(
Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
load("//tools:defaults.bzl", "ts_library")
1+
load("//tools:defaults2.bzl", "ts_project")
22

33
package(
44
default_visibility = [
@@ -7,14 +7,12 @@ package(
77
],
88
)
99

10-
ts_library(
10+
ts_project(
1111
name = "pending-tasks",
1212
srcs = glob(["**/*.ts"]),
13-
tsconfig = "//packages/core/schematics:tsconfig.json",
1413
deps = [
15-
"//packages/core/schematics/utils",
16-
"@npm//@angular-devkit/schematics",
17-
"@npm//@types/node",
18-
"@npm//typescript",
14+
"//:node_modules/@angular-devkit/schematics",
15+
"//:node_modules/typescript",
16+
"//packages/core/schematics/utils:utils_rjs",
1917
],
2018
)
Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
load("//tools:defaults.bzl", "ts_library")
1+
load("//tools:defaults2.bzl", "ts_project")
22

33
package(
44
default_visibility = [
@@ -7,14 +7,12 @@ package(
77
],
88
)
99

10-
ts_library(
10+
ts_project(
1111
name = "provide-initializer",
1212
srcs = glob(["**/*.ts"]),
13-
tsconfig = "//packages/core/schematics:tsconfig.json",
1413
deps = [
15-
"//packages/core/schematics/utils",
16-
"@npm//@angular-devkit/schematics",
17-
"@npm//@types/node",
18-
"@npm//typescript",
14+
"//:node_modules/@angular-devkit/schematics",
15+
"//:node_modules/typescript",
16+
"//packages/core/schematics/utils:utils_rjs",
1917
],
2018
)

packages/core/schematics/migrations/self-closing-tags-migration/BUILD.bazel

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
1-
load("//tools:defaults.bzl", "jasmine_node_test", "ts_library")
1+
load("//tools:defaults.bzl", "jasmine_node_test")
2+
load("//tools:defaults2.bzl", "ts_project")
23

3-
ts_library(
4+
ts_project(
45
name = "migration",
56
srcs = glob(
67
["**/*.ts"],
78
exclude = ["*.spec.ts"],
89
),
9-
visibility = [
10-
"//packages/core/schematics/ng-generate/self-closing-tags-migration:__pkg__",
11-
"//packages/language-service/src/refactorings:__pkg__",
12-
],
13-
deps = [
10+
interop_deps = [
1411
"//packages/compiler",
1512
"//packages/compiler-cli",
1613
"//packages/compiler-cli/private",
@@ -22,23 +19,30 @@ ts_library(
2219
"//packages/compiler-cli/src/ngtsc/reflection",
2320
"//packages/core/schematics/utils",
2421
"//packages/core/schematics/utils/tsurge",
25-
"@npm//@types/node",
26-
"@npm//typescript",
22+
],
23+
visibility = [
24+
"//packages/core/schematics/ng-generate/self-closing-tags-migration:__pkg__",
25+
"//packages/language-service/src/refactorings:__pkg__",
26+
],
27+
deps = [
28+
"//:node_modules/@types/node",
29+
"//:node_modules/typescript",
2730
],
2831
)
2932

30-
ts_library(
33+
ts_project(
3134
name = "test_lib",
3235
testonly = True,
3336
srcs = glob(
3437
["**/*.spec.ts"],
3538
),
36-
deps = [
39+
interop_deps = [
3740
":migration",
3841
"//packages/compiler-cli",
3942
"//packages/compiler-cli/src/ngtsc/file_system/testing",
4043
"//packages/core/schematics/utils/tsurge",
4144
],
45+
deps = [],
4246
)
4347

4448
jasmine_node_test(

packages/core/schematics/migrations/signal-migration/src/BUILD.bazel

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,13 @@
1-
load("//tools:defaults.bzl", "nodejs_binary", "ts_library")
1+
load("//tools:defaults.bzl", "nodejs_binary")
2+
load("//tools:defaults2.bzl", "ts_project")
23

3-
ts_library(
4+
ts_project(
45
name = "src",
56
srcs = glob(
67
["**/*.ts"],
78
exclude = ["test/**"],
89
),
9-
visibility = [
10-
"//packages/core/schematics/migrations/output-migration:__pkg__",
11-
"//packages/core/schematics/migrations/signal-migration/test:__pkg__",
12-
"//packages/core/schematics/migrations/signal-queries-migration:__pkg__",
13-
"//packages/core/schematics/ng-generate/signal-input-migration:__pkg__",
14-
"//packages/language-service:__subpackages__",
15-
],
16-
deps = [
10+
interop_deps = [
1711
"//packages/compiler",
1812
"//packages/compiler-cli",
1913
"//packages/compiler-cli/src/ngtsc/annotations",
@@ -38,22 +32,31 @@ ts_library(
3832
"//packages/core/schematics/utils",
3933
"//packages/core/schematics/utils/tsurge",
4034
"//packages/core/schematics/utils/tsurge/helpers/ast",
41-
"@npm//@types/node",
42-
"@npm//magic-string",
43-
"@npm//typescript",
35+
],
36+
visibility = [
37+
"//packages/core/schematics/migrations/output-migration:__pkg__",
38+
"//packages/core/schematics/migrations/signal-migration/test:__pkg__",
39+
"//packages/core/schematics/migrations/signal-queries-migration:__pkg__",
40+
"//packages/core/schematics/ng-generate/signal-input-migration:__pkg__",
41+
"//packages/language-service:__subpackages__",
42+
],
43+
deps = [
44+
"//:node_modules/@types/node",
45+
"//:node_modules/magic-string",
46+
"//:node_modules/typescript",
4447
],
4548
)
4649

4750
nodejs_binary(
4851
name = "bin",
4952
data = [":src"],
50-
entry_point = ":cli.ts",
53+
entry_point = ":cli.js",
5154
visibility = ["//packages/core/schematics/migrations/signal-migration/test:__pkg__"],
5255
)
5356

5457
nodejs_binary(
5558
name = "batch_test_bin",
5659
data = [":src"],
57-
entry_point = ":batch/test_bin.ts",
60+
entry_point = ":batch/test_bin.js",
5861
visibility = ["//packages/core/schematics/migrations/signal-migration/test:__pkg__"],
5962
)

0 commit comments

Comments
 (0)