Skip to content

Commit 801e7e0

Browse files
authored
build: set up schematics for v20 (#30591)
Sets up the schematics for v20.
1 parent 5b56aa4 commit 801e7e0

File tree

11 files changed

+21
-708
lines changed

11 files changed

+21
-708
lines changed

src/cdk/schematics/migration.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"$schema": "./node_modules/@angular-devkit/schematics/collection-schema.json",
33
"schematics": {
4-
"migration-v19": {
5-
"version": "19.0.0-0",
6-
"description": "Updates the Angular CDK to v19",
7-
"factory": "./ng-update/index#updateToV19"
4+
"migration-v20": {
5+
"version": "20.0.0-0",
6+
"description": "Updates the Angular CDK to v20",
7+
"factory": "./ng-update/index#updateToV20"
88
},
99
"ng-post-update": {
1010
"description": "Prints out results after ng-update.",

src/cdk/schematics/ng-update/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ import {createMigrationSchematicRule, NullableDevkitMigration} from './devkit-mi
1313

1414
const cdkMigrations: NullableDevkitMigration[] = [];
1515

16-
/** Entry point for the migration schematics with target of Angular CDK 18.0.0 */
17-
export function updateToV19(): Rule {
16+
/** Entry point for the migration schematics with target of Angular CDK 20.0.0 */
17+
export function updateToV20(): Rule {
1818
return createMigrationSchematicRule(
19-
TargetVersion.V19,
19+
TargetVersion.V20,
2020
cdkMigrations,
2121
cdkUpgradeData,
2222
onMigrationComplete,

src/cdk/schematics/update-tool/target-version.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
// tslint:disable-next-line:prefer-const-enum
1212
export enum TargetVersion {
13-
V19 = 'version 19',
13+
V20 = 'version 20',
1414
}
1515

1616
/**
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
22
"schematics": {
3-
"migration-v19": {
4-
"version": "19.0.0-0",
5-
"description": "Updates the Angular Google Maps package to v19",
6-
"factory": "./ng-update/index_bundled#updateToV19"
3+
"migration-v20": {
4+
"version": "20.0.0-0",
5+
"description": "Updates the Angular Google Maps package to v20",
6+
"factory": "./ng-update/index_bundled#updateToV20"
77
}
88
}
99
}
Lines changed: 1 addition & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
load("//tools:defaults.bzl", "esbuild", "jasmine_node_test", "spec_bundle", "ts_library")
1+
load("//tools:defaults.bzl", "esbuild", "ts_library")
22

33
## THIS ONE IS ESM
44
# By default everything is ESM
@@ -38,42 +38,3 @@ esbuild(
3838
visibility = ["//src/google-maps/schematics:__pkg__"],
3939
deps = [":ng_update_lib"],
4040
)
41-
42-
ts_library(
43-
name = "test_lib",
44-
testonly = True,
45-
srcs = glob(["**/*.spec.ts"]),
46-
deps = [
47-
":ng_update_lib",
48-
"@npm//@angular-devkit/core",
49-
"@npm//@angular-devkit/schematics",
50-
"@npm//@bazel/runfiles",
51-
"@npm//@types/jasmine",
52-
"@npm//@types/node",
53-
"@npm//@types/shelljs",
54-
],
55-
)
56-
57-
spec_bundle(
58-
name = "spec_bundle",
59-
external = [
60-
"*/paths.js",
61-
"shelljs",
62-
"@angular-devkit/core/node",
63-
],
64-
platform = "cjs-legacy",
65-
target = "es2020",
66-
deps = [":test_lib"],
67-
)
68-
69-
jasmine_node_test(
70-
name = "test",
71-
data = [
72-
":ng_update_index",
73-
"//src/google-maps/schematics:schematics_assets",
74-
"@npm//shelljs",
75-
],
76-
deps = [
77-
":spec_bundle",
78-
],
79-
)

src/google-maps/schematics/ng-update/index.ts

Lines changed: 2 additions & 138 deletions
Original file line numberDiff line numberDiff line change
@@ -6,141 +6,5 @@
66
* found in the LICENSE file at https://angular.dev/license
77
*/
88

9-
import {Path} from '@angular-devkit/core';
10-
import {Rule, Tree} from '@angular-devkit/schematics';
11-
import ts from 'typescript';
12-
13-
/** Tag name of the clusterer component. */
14-
const TAG_NAME = 'map-marker-clusterer';
15-
16-
/** Module from which the clusterer is being imported. */
17-
const MODULE_NAME = '@angular/google-maps';
18-
19-
/** Old name of the clusterer class. */
20-
const CLASS_NAME = 'MapMarkerClusterer';
21-
22-
/** New name of the clusterer class. */
23-
const DEPRECATED_CLASS_NAME = 'DeprecatedMapMarkerClusterer';
24-
25-
/** Entry point for the migration schematics with target of Angular Material v19 */
26-
export function updateToV19(): Rule {
27-
return tree => {
28-
tree.visit(path => {
29-
if (path.includes('node_modules')) {
30-
return;
31-
}
32-
33-
if (path.endsWith('.html')) {
34-
const content = tree.read(path)?.toString();
35-
36-
if (content && content.includes('<' + TAG_NAME)) {
37-
tree.overwrite(path, migrateHtml(content));
38-
}
39-
} else if (path.endsWith('.ts') && !path.endsWith('.d.ts')) {
40-
migrateTypeScript(path, tree);
41-
}
42-
});
43-
};
44-
}
45-
46-
/** Migrates an HTML template from the old tag name to the new one. */
47-
function migrateHtml(content: string): string {
48-
return content
49-
.replace(/<map-marker-clusterer/g, '<deprecated-map-marker-clusterer')
50-
.replace(/<\/map-marker-clusterer/g, '</deprecated-map-marker-clusterer');
51-
}
52-
53-
/** Migrates a TypeScript file from the old tag and class names to the new ones. */
54-
function migrateTypeScript(path: Path, tree: Tree) {
55-
const content = tree.read(path)?.toString();
56-
57-
// Exit early if none of the symbols we're looking for are mentioned.
58-
if (
59-
!content ||
60-
(!content.includes('<' + TAG_NAME) &&
61-
!content.includes(MODULE_NAME) &&
62-
!content.includes(CLASS_NAME))
63-
) {
64-
return;
65-
}
66-
67-
const sourceFile = ts.createSourceFile(path, content, ts.ScriptTarget.Latest, true);
68-
const toMigrate = findTypeScriptNodesToMigrate(sourceFile);
69-
70-
if (toMigrate.length === 0) {
71-
return;
72-
}
73-
74-
const printer = ts.createPrinter();
75-
const update = tree.beginUpdate(path);
76-
77-
for (const node of toMigrate) {
78-
let replacement: ts.Node;
79-
80-
if (ts.isStringLiteralLike(node)) {
81-
// Strings should be migrated as if they're HTML.
82-
if (ts.isStringLiteral(node)) {
83-
replacement = ts.factory.createStringLiteral(
84-
migrateHtml(node.text),
85-
node.getText()[0] === `'`,
86-
);
87-
} else {
88-
replacement = ts.factory.createNoSubstitutionTemplateLiteral(migrateHtml(node.text));
89-
}
90-
} else {
91-
// Imports/exports should preserve the old name, but import the clusterer using the new one.
92-
const propertyName = ts.factory.createIdentifier(DEPRECATED_CLASS_NAME);
93-
const name = node.name as ts.Identifier;
94-
95-
replacement = ts.isImportSpecifier(node)
96-
? ts.factory.updateImportSpecifier(node, node.isTypeOnly, propertyName, name)
97-
: ts.factory.updateExportSpecifier(node, node.isTypeOnly, propertyName, name);
98-
}
99-
100-
update
101-
.remove(node.getStart(), node.getWidth())
102-
.insertLeft(
103-
node.getStart(),
104-
printer.printNode(ts.EmitHint.Unspecified, replacement, sourceFile),
105-
);
106-
}
107-
108-
tree.commitUpdate(update);
109-
}
110-
111-
/** Finds the TypeScript nodes that need to be migrated from a specific file. */
112-
function findTypeScriptNodesToMigrate(sourceFile: ts.SourceFile) {
113-
const results: (ts.StringLiteralLike | ts.ImportSpecifier | ts.ExportSpecifier)[] = [];
114-
115-
sourceFile.forEachChild(function walk(node) {
116-
// Most likely a template using the clusterer.
117-
if (ts.isStringLiteral(node) && node.text.includes('<' + TAG_NAME)) {
118-
results.push(node);
119-
} else if (
120-
// Import/export referencing the clusterer.
121-
(ts.isImportDeclaration(node) || ts.isExportDeclaration(node)) &&
122-
node.moduleSpecifier &&
123-
ts.isStringLiteralLike(node.moduleSpecifier) &&
124-
node.moduleSpecifier.text === MODULE_NAME
125-
) {
126-
const bindings = ts.isImportDeclaration(node)
127-
? node.importClause?.namedBindings
128-
: node.exportClause;
129-
130-
if (bindings && (ts.isNamedImports(bindings) || ts.isNamedExports(bindings))) {
131-
bindings.elements.forEach(element => {
132-
const symbolName = element.propertyName || element.name;
133-
134-
if (ts.isIdentifier(symbolName) && symbolName.text === CLASS_NAME) {
135-
results.push(element);
136-
}
137-
});
138-
}
139-
} else {
140-
node.forEachChild(walk);
141-
}
142-
});
143-
144-
// Sort the results in reverse order to make applying the updates easier.
145-
return results.sort((a, b) => b.getStart() - a.getStart());
146-
}
9+
/** Entry point for the migration schematics with target of Angular Material v20 */
10+
export function updateToV20(): void {}

0 commit comments

Comments
 (0)