Skip to content

Commit 881b6ca

Browse files
build: split material ng-update schematics to a separate bundle (#25379)
* build: split material ng-update schematics to a separate bundle * split material ng-update schematics to a separate bundle * delete `resolveBazelPath` and uses of `__dirname` and replace w/ `runfiles.resolve...` * export gesture config template as a variable instead of having to use fs readFile * fixup! build: split material ng-update schematics to a separate bundle Co-authored-by: Paul Gschwendtner <[email protected]>
1 parent baefbb4 commit 881b6ca

26 files changed

+728
-614
lines changed

src/cdk/schematics/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ ts_library(
8585
"//src/cdk/schematics/update-tool",
8686
"//src/cdk/testing/private",
8787
"@npm//@angular-devkit/schematics",
88+
"@npm//@bazel/runfiles",
8889
"@npm//@schematics/angular",
8990
"@npm//@types/jasmine",
9091
"@npm//@types/node",

src/cdk/schematics/ng-update/test-cases/misc/external-resource-resolution.spec.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {resolveBazelPath} from '@angular/cdk/schematics/testing';
1+
import {runfiles} from '@bazel/runfiles';
22
import {MIGRATION_PATH} from '../../../paths';
33
import {createTestCaseSetup} from '../../../testing';
44

@@ -7,7 +7,11 @@ describe('ng-update external resource resolution', () => {
77
const {runFixers, writeFile, appTree} = await createTestCaseSetup(
88
'migration-v6',
99
MIGRATION_PATH,
10-
[resolveBazelPath(__dirname, './external-resource-resolution_input.ts')],
10+
[
11+
runfiles.resolvePackageRelative(
12+
'ng-update/test-cases/misc/external-resource-resolution_input.ts',
13+
),
14+
],
1115
);
1216

1317
const testContent = `<div cdk-connected-overlay [origin]="test"></div>`;

src/cdk/schematics/ng-update/test-cases/misc/global-stylesheets.spec.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {resolveBazelPath} from '@angular/cdk/schematics/testing';
1+
import {runfiles} from '@bazel/runfiles';
22
import {readFileSync} from 'fs';
33
import {MIGRATION_PATH} from '../../../paths';
44
import {createTestCaseSetup} from '../../../testing';
@@ -8,7 +8,7 @@ describe('global stylesheets migration', () => {
88
const {runFixers, writeFile, appTree} = await createTestCaseSetup(
99
'migration-v6',
1010
MIGRATION_PATH,
11-
[resolveBazelPath(__dirname, './global-stylesheets_input.ts')],
11+
[runfiles.resolvePackageRelative('ng-update/test-cases/misc/global-stylesheets_input.ts')],
1212
);
1313

1414
const testStylesheetPath = 'projects/cdk-testing/src/test-cases/global-stylesheets-test.scss';
@@ -17,7 +17,10 @@ describe('global stylesheets migration', () => {
1717
// be picked up by the update-tool.
1818
writeFile(
1919
testStylesheetPath,
20-
readFileSync(resolveBazelPath(__dirname, './global-stylesheets-test.scss'), 'utf8'),
20+
readFileSync(
21+
runfiles.resolvePackageRelative('ng-update/test-cases/misc/global-stylesheets-test.scss'),
22+
'utf8',
23+
),
2124
);
2225
writeFile('/projects/cdk-testing/third_party/materialize.css/bundle.css', '');
2326

src/cdk/schematics/ng-update/test-cases/misc/method-call-checks.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import {resolveBazelPath} from '@angular/cdk/schematics/testing';
1+
import {runfiles} from '@bazel/runfiles';
22
import {MIGRATION_PATH} from '../../../paths';
33
import {createTestCaseSetup} from '../../../testing';
44

55
describe('v6 method call checks', () => {
66
it('should properly report invalid method calls', async () => {
77
const {runFixers} = await createTestCaseSetup('migration-v6', MIGRATION_PATH, [
8-
resolveBazelPath(__dirname, './method-call-checks_input.ts'),
8+
runfiles.resolvePackageRelative('ng-update/test-cases/misc/method-call-checks_input.ts'),
99
]);
1010

1111
const {logOutput} = await runFixers();

src/cdk/schematics/testing/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,3 @@ export * from './test-app';
1111
export * from './test-case-setup';
1212
export * from './test-library';
1313
export * from './file-content';
14-
export * from './resolve-bazel-path';

src/cdk/schematics/testing/resolve-bazel-path.ts

Lines changed: 0 additions & 46 deletions
This file was deleted.

src/material/schematics/BUILD.bazel

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,24 @@ load("//tools:defaults.bzl", "jasmine_node_test", "pkg_npm", "ts_library")
44
package(default_visibility = ["//visibility:public"])
55

66
copy_to_bin(
7-
name = "schematics_assets",
7+
name = "collection_assets",
88
srcs = [
9-
"ng-update/migrations/hammer-gestures-v9/gesture-config.template",
10-
] + glob([
9+
"collection.json",
10+
"migration.json",
11+
],
12+
)
13+
14+
copy_to_bin(
15+
name = "ng_generate_assets",
16+
srcs = glob([
1117
"ng-generate/*/files/**/*",
12-
"**/*.json",
18+
]),
19+
)
20+
21+
copy_to_bin(
22+
name = "schema_assets",
23+
srcs = glob([
24+
"**/schema.json",
1325
]),
1426
)
1527

@@ -19,12 +31,12 @@ ts_library(
1931
["**/*.ts"],
2032
exclude = [
2133
"**/*.spec.ts",
22-
"ng-update/test-cases/**/*.ts",
34+
"paths.ts",
2335
"ng-generate/*/files/**/*.ts",
2436
],
2537
),
26-
# Schematics do not need to run in browsers and can use `commonjs`
27-
# as format instead the default `umd` format.
38+
# Schematics can not yet run in ESM module. For now we continue to use CommonJS.
39+
# TODO(ESM): remove this once the Angular CLI supports ESM schematics.
2840
devmode_module = "commonjs",
2941
prodmode_module = "commonjs",
3042
tsconfig = ":tsconfig.json",
@@ -41,6 +53,23 @@ ts_library(
4153
],
4254
)
4355

56+
ts_library(
57+
name = "paths",
58+
testonly = True,
59+
srcs = ["paths.ts"],
60+
data = [
61+
":collection_assets",
62+
],
63+
# Schematics can not yet run in ESM module. For now we continue to use CommonJS.
64+
# TODO(ESM): remove this once the Angular CLI supports ESM schematics.
65+
devmode_module = "commonjs",
66+
prodmode_module = "commonjs",
67+
tsconfig = ":tsconfig.json",
68+
deps = [
69+
"@npm//@bazel/runfiles",
70+
],
71+
)
72+
4473
# This package is intended to be combined into the main @angular/material package as a dep.
4574
pkg_npm(
4675
name = "npm_package",
@@ -49,8 +78,11 @@ pkg_npm(
4978
"//src/material/schematics/ng-generate/mdc-migration:npm_package",
5079
],
5180
deps = [
81+
":collection_assets",
82+
":ng_generate_assets",
83+
":schema_assets",
5284
":schematics",
53-
":schematics_assets",
85+
"//src/material/schematics/ng-update:ng_update_index",
5486
],
5587
)
5688

@@ -60,7 +92,9 @@ jasmine_node_test(
6092
name = "unit_tests",
6193
srcs = [":unit_test_sources"],
6294
data = [
63-
":schematics_assets",
95+
":collection_assets",
96+
":ng_generate_assets",
97+
":schema_assets",
6498
":schematics_test_cases",
6599
],
66100
)
@@ -81,6 +115,7 @@ ts_library(
81115
prodmode_module = "commonjs",
82116
tsconfig = ":tsconfig.json",
83117
deps = [
118+
":paths",
84119
":schematics",
85120
"//src/cdk/schematics",
86121
"//src/cdk/schematics/testing",

src/material/schematics/migration.json

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,57 +4,52 @@
44
"migration-v6": {
55
"version": "6.0.0",
66
"description": "Updates Angular Material to v6",
7-
"factory": "./ng-update/index#updateToV6"
7+
"factory": "./ng-update/index_bundled#updateToV6"
88
},
99
"migration-v7": {
1010
"version": "7.0.0",
1111
"description": "Updates Angular Material to v7",
12-
"factory": "./ng-update/index#updateToV7"
12+
"factory": "./ng-update/index_bundled#updateToV7"
1313
},
1414
"migration-v8": {
1515
"version": "8.0.0",
1616
"description": "Updates Angular Material to v8",
17-
"factory": "./ng-update/index#updateToV8"
17+
"factory": "./ng-update/index_bundled#updateToV8"
1818
},
1919
"migration-v9": {
2020
"version": "9.0.0-0",
2121
"description": "Updates Angular Material to v9",
22-
"factory": "./ng-update/index#updateToV9"
22+
"factory": "./ng-update/index_bundled#updateToV9"
2323
},
2424
"migration-v10": {
2525
"version": "10.0.0-0",
2626
"description": "Updates Angular Material to v10",
27-
"factory": "./ng-update/index#updateToV10"
27+
"factory": "./ng-update/index_bundled#updateToV10"
2828
},
2929
"migration-v11": {
3030
"version": "11.0.0-0",
3131
"description": "Updates Angular Material to v11",
32-
"factory": "./ng-update/index#updateToV11"
32+
"factory": "./ng-update/index_bundled#updateToV11"
3333
},
3434
"migration-v12": {
3535
"version": "12.0.0-0",
3636
"description": "Updates Angular Material to v12",
37-
"factory": "./ng-update/index#updateToV12"
37+
"factory": "./ng-update/index_bundled#updateToV12"
3838
},
3939
"migration-v13": {
4040
"version": "13.0.0-0",
4141
"description": "Updates Angular Material to v13",
42-
"factory": "./ng-update/index#updateToV13"
42+
"factory": "./ng-update/index_bundled#updateToV13"
4343
},
4444
"migration-v14": {
4545
"version": "14.0.0-0",
4646
"description": "Updates the Angular Material to v14",
47-
"factory": "./ng-update/index#updateToV14"
47+
"factory": "./ng-update/index_bundled#updateToV14"
4848
},
4949
"migration-v15": {
5050
"version": "15.0.0-0",
5151
"description": "Updates the Angular Material to v15",
52-
"factory": "./ng-update/index#updateToV15"
53-
},
54-
"ng-post-update": {
55-
"description": "Prints out results after ng-update.",
56-
"factory": "./ng-update/index#postUpdate",
57-
"private": true
52+
"factory": "./ng-update/index_bundled#updateToV15"
5853
}
5954
}
6055
}

src/material/schematics/ng-generate/mdc-migration/BUILD.bazel

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ jasmine_node_test(
8888
data = [
8989
":mdc_migration_bundle",
9090
":unit_tests_assets",
91-
"//src/material/schematics:schematics_assets",
91+
"//src/material/schematics:collection_assets",
92+
"//src/material/schematics:ng_generate_assets",
9293
],
9394
deps = [
9495
":unit_tests_bundle",
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
load("//tools:defaults.bzl", "esbuild", "jasmine_node_test", "spec_bundle", "ts_library")
2+
3+
## THIS ONE IS ESM
4+
# By default everything is ESM
5+
# ESBUild needs ESM for bundling. Cannot reliably use CJS as input.
6+
ts_library(
7+
name = "ng_update_lib",
8+
srcs = glob(
9+
["**/*.ts"],
10+
exclude = [
11+
"test-cases/**/*.ts",
12+
],
13+
),
14+
# Schematics can not yet run in ESM module. For now we continue to use CommonJS.
15+
# TODO(ESM): remove this once the Angular CLI supports ESM schematics.
16+
devmode_module = "commonjs",
17+
deps = [
18+
"//src/cdk/schematics",
19+
"@npm//@angular-devkit/core",
20+
"@npm//@angular-devkit/schematics",
21+
"@npm//@schematics/angular",
22+
"@npm//@types/node",
23+
"@npm//typescript",
24+
],
25+
)
26+
27+
esbuild(
28+
name = "ng_update_index",
29+
entry_point = ":index.ts",
30+
external = [
31+
"@angular/cdk/schematics",
32+
"@schematics/angular",
33+
"@angular-devkit/schematics",
34+
"@angular-devkit/core",
35+
"typescript",
36+
],
37+
# TODO: Switch to ESM when Angular CLI supports it.
38+
format = "cjs",
39+
output = "index_bundled.js",
40+
platform = "node",
41+
target = "es2015",
42+
visibility = ["//src/material/schematics:__pkg__"],
43+
deps = [":ng_update_lib"],
44+
)
45+
46+
#################
47+
## Specs
48+
#################
49+
50+
filegroup(
51+
name = "schematics_test_cases",
52+
testonly = True,
53+
srcs = glob([
54+
"test-cases/**/*_input.ts",
55+
"test-cases/**/*_expected_output.ts",
56+
]),
57+
)
58+
59+
# This one is now ESM, the default in the repository
60+
# Needs to be ESM because we import frm `ng_update_lib` (which is also ESM)
61+
ts_library(
62+
name = "test_lib",
63+
testonly = True,
64+
srcs = glob(["**/*.spec.ts"]),
65+
deps = [
66+
":ng_update_lib",
67+
"//src/cdk/schematics",
68+
"//src/cdk/schematics/testing",
69+
"//src/material/schematics:paths",
70+
"@npm//@angular-devkit/schematics",
71+
"@npm//@bazel/runfiles",
72+
"@npm//@types/jasmine",
73+
"@npm//@types/node",
74+
],
75+
)
76+
77+
spec_bundle(
78+
name = "spec_bundle",
79+
external = ["*/paths.js"],
80+
platform = "cjs-legacy",
81+
deps = [":test_lib"],
82+
)
83+
84+
jasmine_node_test(
85+
name = "test",
86+
data = [
87+
":ng_update_index",
88+
":schematics_test_cases",
89+
"//src/cdk/schematics",
90+
"//src/material/schematics:collection_assets",
91+
],
92+
shard_count = 4,
93+
deps = [
94+
":spec_bundle",
95+
],
96+
)

0 commit comments

Comments
 (0)