@angular/core 21.0.0-next.8 → 21.0.0-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/fesm2022/_attribute-chunk.mjs +2 -14
- package/fesm2022/_attribute-chunk.mjs.map +1 -1
- package/fesm2022/_debug_node-chunk.mjs +15214 -28375
- package/fesm2022/_debug_node-chunk.mjs.map +1 -1
- package/fesm2022/_effect-chunk.mjs +402 -120
- package/fesm2022/_effect-chunk.mjs.map +1 -1
- package/fesm2022/_effect-chunk2.mjs +2951 -0
- package/fesm2022/_effect-chunk2.mjs.map +1 -0
- package/fesm2022/_not_found-chunk.mjs +18 -35
- package/fesm2022/_not_found-chunk.mjs.map +1 -1
- package/fesm2022/_resource-chunk.mjs +316 -563
- package/fesm2022/_resource-chunk.mjs.map +1 -1
- package/fesm2022/_untracked-chunk.mjs +96 -0
- package/fesm2022/_untracked-chunk.mjs.map +1 -0
- package/fesm2022/_weak_ref-chunk.mjs +2 -4
- package/fesm2022/_weak_ref-chunk.mjs.map +1 -1
- package/fesm2022/core.mjs +2466 -4309
- package/fesm2022/core.mjs.map +1 -1
- package/fesm2022/primitives-di.mjs +9 -9
- package/fesm2022/primitives-di.mjs.map +1 -1
- package/fesm2022/primitives-event-dispatch.mjs +626 -1460
- package/fesm2022/primitives-event-dispatch.mjs.map +1 -1
- package/fesm2022/primitives-signals.mjs +157 -191
- package/fesm2022/primitives-signals.mjs.map +1 -1
- package/fesm2022/rxjs-interop.mjs +208 -308
- package/fesm2022/rxjs-interop.mjs.map +1 -1
- package/fesm2022/testing.mjs +2305 -3164
- package/fesm2022/testing.mjs.map +1 -1
- package/package.json +8 -2
- package/resources/best-practices.md +56 -0
- package/schematics/bundles/add-bootstrap-context-to-server-main.cjs +7 -25
- package/schematics/bundles/application-config-core.cjs +8 -19
- package/schematics/bundles/{apply_import_manager-CBLmogDD.cjs → apply_import_manager-1Zs_gpB6.cjs} +4 -5
- package/schematics/bundles/bootstrap-options-migration.cjs +93 -132
- package/schematics/bundles/cleanup-unused-imports.cjs +9 -13
- package/schematics/bundles/common-to-standalone-migration.cjs +381 -0
- package/schematics/bundles/{compiler_host-T6xncpiw.cjs → compiler_host-DBwYMlTo.cjs} +10 -11
- package/schematics/bundles/control-flow-migration.cjs +29 -31
- package/schematics/bundles/{imports-DwPXlGFl.cjs → imports-DP72APSx.cjs} +1 -23
- package/schematics/bundles/{index-DWSaRJdz.cjs → index-B7I9sIUx.cjs} +36 -37
- package/schematics/bundles/inject-migration.cjs +9 -26
- package/schematics/bundles/leading_space-D9nQ8UQC.cjs +1 -1
- package/schematics/bundles/{migrate_ts_type_references-Cu-FR4L5.cjs → migrate_ts_type_references-UGIUl7En.cjs} +458 -24
- package/schematics/bundles/{ng_component_template-BkWiUuGG.cjs → ng_component_template-Dsuq1Lw7.cjs} +4 -5
- package/schematics/bundles/{ng_decorators-BI0uV7KI.cjs → ng_decorators-DSFlWYQY.cjs} +2 -2
- package/schematics/bundles/ngclass-to-class-migration.cjs +16 -19
- package/schematics/bundles/ngstyle-to-style-migration.cjs +15 -18
- package/schematics/bundles/nodes-B16H9JUd.cjs +1 -1
- package/schematics/bundles/output-migration.cjs +16 -19
- package/schematics/bundles/{parse_html-C97tKKp3.cjs → parse_html-8VLCL37B.cjs} +5 -5
- package/schematics/bundles/{project_paths-C6g3lqjX.cjs → project_paths-DvD50ouC.cjs} +14 -247
- package/schematics/bundles/project_tsconfig_paths-CDVxT6Ov.cjs +90 -0
- package/schematics/bundles/property_name-BBwFuqMe.cjs +1 -1
- package/schematics/bundles/route-lazy-loading.cjs +9 -25
- package/schematics/bundles/router-current-navigation.cjs +6 -17
- package/schematics/bundles/router-last-successful-navigation.cjs +6 -17
- package/schematics/bundles/router-testing-module-migration.cjs +7 -18
- package/schematics/bundles/self-closing-tags-migration.cjs +14 -17
- package/schematics/bundles/signal-input-migration.cjs +23 -26
- package/schematics/bundles/signal-queries-migration.cjs +22 -25
- package/schematics/bundles/signals.cjs +10 -13
- package/schematics/bundles/standalone-migration.cjs +22 -56
- package/schematics/bundles/symbol-BObKoqes.cjs +1 -1
- package/schematics/collection.json +6 -0
- package/schematics/migrations/common-to-standalone-migration/schema.json +14 -0
- package/types/_api-chunk.d.ts +1 -1
- package/types/_chrome_dev_tools_performance-chunk.d.ts +20 -12
- package/types/_discovery-chunk.d.ts +18 -14
- package/types/_effect-chunk.d.ts +1 -1
- package/types/_event_dispatcher-chunk.d.ts +1 -1
- package/types/_formatter-chunk.d.ts +4 -3
- package/types/_weak_ref-chunk.d.ts +1 -1
- package/types/core.d.ts +49 -100
- package/types/primitives-di.d.ts +1 -1
- package/types/primitives-event-dispatch.d.ts +1 -1
- package/types/primitives-signals.d.ts +2 -2
- package/types/rxjs-interop.d.ts +1 -1
- package/types/testing.d.ts +1 -1
- package/fesm2022/_root_effect_scheduler-chunk.mjs +0 -4630
- package/fesm2022/_root_effect_scheduler-chunk.mjs.map +0 -1
- package/fesm2022/_signal-chunk.mjs +0 -581
- package/fesm2022/_signal-chunk.mjs.map +0 -1
- package/schematics/bundles/index-BnmACOsq.cjs +0 -22319
- package/schematics/bundles/project_tsconfig_paths-CdhVNYMk.cjs +0 -51583
|
@@ -0,0 +1,381 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/**
|
|
3
|
+
* @license Angular v21.0.0-rc.0
|
|
4
|
+
* (c) 2010-2025 Google LLC. https://angular.io/
|
|
5
|
+
* License: MIT
|
|
6
|
+
*/
|
|
7
|
+
'use strict';
|
|
8
|
+
|
|
9
|
+
var ts = require('typescript');
|
|
10
|
+
require('@angular/compiler-cli');
|
|
11
|
+
var migrations = require('@angular/compiler-cli/private/migrations');
|
|
12
|
+
require('node:path');
|
|
13
|
+
var project_paths = require('./project_paths-DvD50ouC.cjs');
|
|
14
|
+
var ng_component_template = require('./ng_component_template-Dsuq1Lw7.cjs');
|
|
15
|
+
var ng_decorators = require('./ng_decorators-DSFlWYQY.cjs');
|
|
16
|
+
var apply_import_manager = require('./apply_import_manager-1Zs_gpB6.cjs');
|
|
17
|
+
var imports = require('./imports-DP72APSx.cjs');
|
|
18
|
+
require('@angular-devkit/core');
|
|
19
|
+
require('node:path/posix');
|
|
20
|
+
require('@angular-devkit/schematics');
|
|
21
|
+
require('./project_tsconfig_paths-CDVxT6Ov.cjs');
|
|
22
|
+
require('./property_name-BBwFuqMe.cjs');
|
|
23
|
+
|
|
24
|
+
const commonModuleStr = 'CommonModule';
|
|
25
|
+
const angularCommonStr = '@angular/common';
|
|
26
|
+
const PATTERN_IMPORTS = [
|
|
27
|
+
// Structural directives
|
|
28
|
+
{ pattern: /\*ngIf\b/g, imports: ['NgIf'] },
|
|
29
|
+
{ pattern: /\*ngFor\b/g, imports: ['NgFor'] },
|
|
30
|
+
{ pattern: /\[ngForOf]\b/g, imports: ['NgForOf'] },
|
|
31
|
+
{ pattern: /\[ngPlural\]/g, imports: ['NgPlural'] },
|
|
32
|
+
// Match ngPluralCase as structural (*ngPluralCase) or attribute (ngPluralCase="value")
|
|
33
|
+
{ pattern: /(\*ngPluralCase\b|\s+ngPluralCase\s*=)/g, imports: ['NgPluralCase'] },
|
|
34
|
+
// Match ngSwitchCase as structural (*ngSwitchCase) or attribute (ngSwitchCase="value")
|
|
35
|
+
{ pattern: /(\*ngSwitchCase\b|\s+ngSwitchCase\s*=)/g, imports: ['NgSwitchCase'] },
|
|
36
|
+
// Match ngSwitchDefault as structural (*ngSwitchDefault) or standalone attribute (ngSwitchDefault>)
|
|
37
|
+
{ pattern: /(\*ngSwitchDefault\b|\s+ngSwitchDefault(?=\s*>))/g, imports: ['NgSwitchDefault'] },
|
|
38
|
+
{ pattern: /\[ngClass\]/g, imports: ['NgClass'] },
|
|
39
|
+
{ pattern: /\[ngStyle\]/g, imports: ['NgStyle'] },
|
|
40
|
+
// Match ngSwitch as property binding [ngSwitch] or attribute ngSwitch="value"
|
|
41
|
+
{ pattern: /(\[ngSwitch\]|\s+ngSwitch\s*=)/g, imports: ['NgSwitch'] },
|
|
42
|
+
{ pattern: /\[ngTemplateOutlet\]/g, imports: ['NgTemplateOutlet'] },
|
|
43
|
+
{ pattern: /\[ngComponentOutlet\]/g, imports: ['NgComponentOutlet'] },
|
|
44
|
+
// Common pipes
|
|
45
|
+
{ pattern: /\|\s*async\b/g, imports: ['AsyncPipe'] },
|
|
46
|
+
{ pattern: /\|\s*json\b/g, imports: ['JsonPipe'] },
|
|
47
|
+
{ pattern: /\|\s*date\b/g, imports: ['DatePipe'] },
|
|
48
|
+
{ pattern: /\|\s*currency\b/g, imports: ['CurrencyPipe'] },
|
|
49
|
+
{ pattern: /\|\s*number\b/g, imports: ['DecimalPipe'] },
|
|
50
|
+
{ pattern: /\|\s*percent\b/g, imports: ['PercentPipe'] },
|
|
51
|
+
{ pattern: /\|\s*lowercase\b/g, imports: ['LowerCasePipe'] },
|
|
52
|
+
{ pattern: /\|\s*uppercase\b/g, imports: ['UpperCasePipe'] },
|
|
53
|
+
{ pattern: /\|\s*titlecase\b/g, imports: ['TitleCasePipe'] },
|
|
54
|
+
{ pattern: /\|\s*slice\b/g, imports: ['SlicePipe'] },
|
|
55
|
+
{ pattern: /\|\s*keyvalue\b/g, imports: ['KeyValuePipe'] },
|
|
56
|
+
{ pattern: /\|\s*i18nPlural\b/g, imports: ['I18nPluralPipe'] },
|
|
57
|
+
{ pattern: /\|\s*i18nSelect\b/g, imports: ['I18nSelectPipe'] },
|
|
58
|
+
];
|
|
59
|
+
function analyzeTemplateWithRegex(template, neededImports) {
|
|
60
|
+
PATTERN_IMPORTS.forEach(({ pattern, imports }) => {
|
|
61
|
+
// Reset regex lastIndex to avoid state issues with global flag
|
|
62
|
+
pattern.lastIndex = 0;
|
|
63
|
+
if (pattern.test(template)) {
|
|
64
|
+
imports.forEach((imp) => neededImports.add(imp));
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
function migrateCommonModuleUsage(template, componentNode, typeChecker) {
|
|
69
|
+
const analysis = analyzeTemplateContent(template);
|
|
70
|
+
const hasCommonModule = hasCommonModuleInImports(componentNode, typeChecker);
|
|
71
|
+
return {
|
|
72
|
+
migrated: template,
|
|
73
|
+
changed: hasCommonModule,
|
|
74
|
+
replacementCount: hasCommonModule ? 1 : 0,
|
|
75
|
+
canRemoveCommonModule: hasCommonModule,
|
|
76
|
+
neededImports: Array.from(analysis.neededImports),
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
function createCommonModuleImportsArrayRemoval(classNode, file, typeChecker, neededImports) {
|
|
80
|
+
const reflector = new migrations.TypeScriptReflectionHost(typeChecker);
|
|
81
|
+
const decorators = reflector.getDecoratorsOfDeclaration(classNode);
|
|
82
|
+
if (!decorators) {
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
const decorator = decorators.find((decorator) => decorator.name === 'Component');
|
|
86
|
+
if (!decorator?.node) {
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
const decoratorNode = decorator.node;
|
|
90
|
+
if (!ts.isDecorator(decoratorNode) ||
|
|
91
|
+
!ts.isCallExpression(decoratorNode.expression) ||
|
|
92
|
+
decoratorNode.expression.arguments.length === 0 ||
|
|
93
|
+
!ts.isObjectLiteralExpression(decoratorNode.expression.arguments[0])) {
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
const metadata = decoratorNode.expression.arguments[0];
|
|
97
|
+
const importsProperty = metadata.properties.find((p) => ts.isPropertyAssignment(p) && p.name?.getText() === 'imports');
|
|
98
|
+
if (!importsProperty || !ts.isArrayLiteralExpression(importsProperty.initializer)) {
|
|
99
|
+
return null;
|
|
100
|
+
}
|
|
101
|
+
const importsArray = importsProperty.initializer;
|
|
102
|
+
const originalElements = importsArray.elements;
|
|
103
|
+
const filteredElements = originalElements.filter((el) => {
|
|
104
|
+
if (!ts.isIdentifier(el))
|
|
105
|
+
return true;
|
|
106
|
+
return !isCommonModuleFromAngularCommon(typeChecker, el);
|
|
107
|
+
});
|
|
108
|
+
const newElements = [
|
|
109
|
+
...filteredElements,
|
|
110
|
+
...neededImports.sort().map((imp) => ts.factory.createIdentifier(imp)),
|
|
111
|
+
];
|
|
112
|
+
if (newElements.length === originalElements.length && neededImports.length === 0) {
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
|
+
if (newElements.length === 0) {
|
|
116
|
+
// For standalone components, keep imports: [] instead of removing the property entirely
|
|
117
|
+
const printer = ts.createPrinter();
|
|
118
|
+
const emptyArray = ts.factory.createArrayLiteralExpression([]);
|
|
119
|
+
const newText = printer.printNode(ts.EmitHint.Unspecified, emptyArray, classNode.getSourceFile());
|
|
120
|
+
return new project_paths.Replacement(file, new project_paths.TextUpdate({
|
|
121
|
+
position: importsArray.getStart(),
|
|
122
|
+
end: importsArray.getEnd(),
|
|
123
|
+
toInsert: newText,
|
|
124
|
+
}));
|
|
125
|
+
}
|
|
126
|
+
const printer = ts.createPrinter();
|
|
127
|
+
const newArray = ts.factory.updateArrayLiteralExpression(importsArray, newElements);
|
|
128
|
+
const newText = printer.printNode(ts.EmitHint.Unspecified, newArray, classNode.getSourceFile());
|
|
129
|
+
return new project_paths.Replacement(file, new project_paths.TextUpdate({
|
|
130
|
+
position: importsArray.getStart(),
|
|
131
|
+
end: importsArray.getEnd(),
|
|
132
|
+
toInsert: newText,
|
|
133
|
+
}));
|
|
134
|
+
}
|
|
135
|
+
function analyzeTemplateContent(templateContent) {
|
|
136
|
+
const neededImports = new Set();
|
|
137
|
+
const errors = [];
|
|
138
|
+
try {
|
|
139
|
+
analyzeTemplateWithRegex(templateContent, neededImports);
|
|
140
|
+
}
|
|
141
|
+
catch (error) {
|
|
142
|
+
errors.push(`Failed to analyze template: ${error}`);
|
|
143
|
+
}
|
|
144
|
+
return { neededImports, errors };
|
|
145
|
+
}
|
|
146
|
+
function hasCommonModuleInImports(componentNode, typeChecker) {
|
|
147
|
+
// First check if there's a CommonModule in the imports array
|
|
148
|
+
const reflector = new migrations.TypeScriptReflectionHost(typeChecker);
|
|
149
|
+
const decorators = reflector.getDecoratorsOfDeclaration(componentNode);
|
|
150
|
+
if (!decorators) {
|
|
151
|
+
return false;
|
|
152
|
+
}
|
|
153
|
+
const decorator = decorators.find((decorator) => decorator.name === 'Component');
|
|
154
|
+
if (!decorator?.node) {
|
|
155
|
+
return false;
|
|
156
|
+
}
|
|
157
|
+
const decoratorNode = decorator.node;
|
|
158
|
+
if (!ts.isDecorator(decoratorNode) ||
|
|
159
|
+
!ts.isCallExpression(decoratorNode.expression) ||
|
|
160
|
+
decoratorNode.expression.arguments.length === 0 ||
|
|
161
|
+
!ts.isObjectLiteralExpression(decoratorNode.expression.arguments[0])) {
|
|
162
|
+
return false;
|
|
163
|
+
}
|
|
164
|
+
const metadata = decoratorNode.expression.arguments[0];
|
|
165
|
+
const importsProperty = metadata.properties.find((p) => ts.isPropertyAssignment(p) && p.name?.getText() === 'imports');
|
|
166
|
+
if (!importsProperty || !ts.isArrayLiteralExpression(importsProperty.initializer)) {
|
|
167
|
+
return false;
|
|
168
|
+
}
|
|
169
|
+
const importsArray = importsProperty.initializer;
|
|
170
|
+
return importsArray.elements.some((el) => {
|
|
171
|
+
if (!ts.isIdentifier(el))
|
|
172
|
+
return false;
|
|
173
|
+
return isCommonModuleFromAngularCommon(typeChecker, el);
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
function isCommonModuleFromAngularCommon(typeChecker, identifier) {
|
|
177
|
+
const importInfo = imports.getImportOfIdentifier(typeChecker, identifier);
|
|
178
|
+
return (importInfo !== null &&
|
|
179
|
+
importInfo.name === commonModuleStr &&
|
|
180
|
+
importInfo.importModule === angularCommonStr);
|
|
181
|
+
}
|
|
182
|
+
function processResolvedTemplate(template, componentNode, info, typeChecker, replacements, filesWithNeededImports) {
|
|
183
|
+
const result = migrateCommonModuleUsage(template.content, componentNode, typeChecker);
|
|
184
|
+
if (result.changed) {
|
|
185
|
+
const sourceFile = componentNode.getSourceFile();
|
|
186
|
+
const file = project_paths.projectFile(sourceFile, info);
|
|
187
|
+
filesWithNeededImports.set(sourceFile.fileName, result.neededImports);
|
|
188
|
+
const replacement = createCommonModuleImportsArrayRemoval(componentNode, file, typeChecker, result.neededImports);
|
|
189
|
+
if (replacement) {
|
|
190
|
+
replacements.push(replacement);
|
|
191
|
+
}
|
|
192
|
+
const importManager = new migrations.ImportManager({
|
|
193
|
+
shouldUseSingleQuotes: () => true,
|
|
194
|
+
});
|
|
195
|
+
// Always remove 'CommonModule' regardless of whether it's aliased or not
|
|
196
|
+
// ImportManager handles removing the correct import specifier
|
|
197
|
+
importManager.removeImport(sourceFile, commonModuleStr, angularCommonStr);
|
|
198
|
+
if (result.neededImports.length > 0) {
|
|
199
|
+
result.neededImports.forEach((importName) => {
|
|
200
|
+
importManager.addImport({
|
|
201
|
+
exportSymbolName: importName,
|
|
202
|
+
exportModuleSpecifier: angularCommonStr,
|
|
203
|
+
requestedFile: sourceFile,
|
|
204
|
+
});
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
const importReplacements = [];
|
|
208
|
+
apply_import_manager.applyImportManagerChanges(importManager, importReplacements, [sourceFile], info);
|
|
209
|
+
replacements.push(...importReplacements);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Angular Common to Standalone migration.
|
|
215
|
+
*
|
|
216
|
+
* This migration converts standalone components and Angular modules from using
|
|
217
|
+
* CommonModule to importing individual directives and pipes.
|
|
218
|
+
*/
|
|
219
|
+
class CommonToStandaloneMigration extends project_paths.TsurgeFunnelMigration {
|
|
220
|
+
config;
|
|
221
|
+
constructor(config = {}) {
|
|
222
|
+
super();
|
|
223
|
+
this.config = config;
|
|
224
|
+
}
|
|
225
|
+
async analyze(info) {
|
|
226
|
+
const fileReplacements = [];
|
|
227
|
+
const references = [];
|
|
228
|
+
const filesWithNeededImports = new Map();
|
|
229
|
+
for (const sf of info.sourceFiles) {
|
|
230
|
+
const file = project_paths.projectFile(sf, info);
|
|
231
|
+
if (this.config.shouldMigrate && !this.config.shouldMigrate(file)) {
|
|
232
|
+
continue;
|
|
233
|
+
}
|
|
234
|
+
this.visitSourceFile(sf, info, fileReplacements, references, filesWithNeededImports);
|
|
235
|
+
}
|
|
236
|
+
return project_paths.confirmAsSerializable({
|
|
237
|
+
replacements: fileReplacements,
|
|
238
|
+
references,
|
|
239
|
+
filesWithNeededImports,
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
visitSourceFile(sourceFile, info, replacements, references, filesWithNeededImports) {
|
|
243
|
+
const typeChecker = info.program.getTypeChecker();
|
|
244
|
+
const visit = (node) => {
|
|
245
|
+
const hasNode = ts.isClassDeclaration(node) && node.name;
|
|
246
|
+
if (!hasNode) {
|
|
247
|
+
ts.forEachChild(node, visit);
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
const nodeDecorators = ts.getDecorators(node);
|
|
251
|
+
if (!nodeDecorators) {
|
|
252
|
+
ts.forEachChild(node, visit);
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
const decorators = ng_decorators.getAngularDecorators(typeChecker, nodeDecorators);
|
|
256
|
+
const hasComponentDecorator = decorators.some((d) => d.name === 'Component');
|
|
257
|
+
if (!hasComponentDecorator) {
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
const ref = this.analyzeClass(node, typeChecker);
|
|
261
|
+
if (!ref) {
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
references.push(ref);
|
|
265
|
+
const templateVisitor = new ng_component_template.NgComponentTemplateVisitor(typeChecker);
|
|
266
|
+
templateVisitor.visitNode(node);
|
|
267
|
+
for (const template of templateVisitor.resolvedTemplates) {
|
|
268
|
+
processResolvedTemplate(template, node, info, typeChecker, replacements, filesWithNeededImports);
|
|
269
|
+
}
|
|
270
|
+
// Component has CommonModule in imports but no template content to analyze
|
|
271
|
+
// We still need to process these cases to remove unused CommonModule imports
|
|
272
|
+
if (templateVisitor.resolvedTemplates.length === 0) {
|
|
273
|
+
processResolvedTemplate({ content: ''}, node, info, typeChecker, replacements, filesWithNeededImports);
|
|
274
|
+
}
|
|
275
|
+
ts.forEachChild(node, visit);
|
|
276
|
+
};
|
|
277
|
+
visit(sourceFile);
|
|
278
|
+
}
|
|
279
|
+
analyzeClass(node, typeChecker) {
|
|
280
|
+
const nodeDecorators = ts.getDecorators(node);
|
|
281
|
+
if (!nodeDecorators)
|
|
282
|
+
return null;
|
|
283
|
+
const decorators = ng_decorators.getAngularDecorators(typeChecker, nodeDecorators);
|
|
284
|
+
// Only process Component decorators, not Directive or other Angular decorators
|
|
285
|
+
for (const decorator of decorators) {
|
|
286
|
+
if (decorator.name === 'Component') {
|
|
287
|
+
return this.analyzeComponentDecorator(node, decorator, typeChecker);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
return null;
|
|
291
|
+
}
|
|
292
|
+
analyzeComponentDecorator(node, decorator, typeChecker) {
|
|
293
|
+
const decoratorNode = decorator.node;
|
|
294
|
+
if (!ts.isCallExpression(decoratorNode.expression)) {
|
|
295
|
+
return null;
|
|
296
|
+
}
|
|
297
|
+
const config = decoratorNode.expression.arguments[0];
|
|
298
|
+
if (!ts.isObjectLiteralExpression(config)) {
|
|
299
|
+
return null;
|
|
300
|
+
}
|
|
301
|
+
if (hasCommonModuleInImports(node, typeChecker)) {
|
|
302
|
+
return { node };
|
|
303
|
+
}
|
|
304
|
+
return null;
|
|
305
|
+
}
|
|
306
|
+
async combine(unitA, unitB) {
|
|
307
|
+
const combinedFilesWithNeededImports = new Map(unitA.filesWithNeededImports);
|
|
308
|
+
for (const [fileName, imports] of unitB.filesWithNeededImports) {
|
|
309
|
+
if (combinedFilesWithNeededImports.has(fileName)) {
|
|
310
|
+
const existingImports = combinedFilesWithNeededImports.get(fileName) || [];
|
|
311
|
+
const mergedImports = Array.from(new Set([...existingImports, ...imports]));
|
|
312
|
+
combinedFilesWithNeededImports.set(fileName, mergedImports);
|
|
313
|
+
}
|
|
314
|
+
else {
|
|
315
|
+
combinedFilesWithNeededImports.set(fileName, imports);
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
return project_paths.confirmAsSerializable({
|
|
319
|
+
replacements: [...unitA.replacements, ...unitB.replacements],
|
|
320
|
+
references: [...unitA.references, ...unitB.references],
|
|
321
|
+
filesWithNeededImports: combinedFilesWithNeededImports,
|
|
322
|
+
});
|
|
323
|
+
}
|
|
324
|
+
async globalMeta(combinedData) {
|
|
325
|
+
return project_paths.confirmAsSerializable(combinedData);
|
|
326
|
+
}
|
|
327
|
+
async stats(globalMetadata) {
|
|
328
|
+
const stats = {
|
|
329
|
+
counters: {
|
|
330
|
+
replacements: globalMetadata.replacements.length,
|
|
331
|
+
references: globalMetadata.references.length,
|
|
332
|
+
},
|
|
333
|
+
};
|
|
334
|
+
return stats;
|
|
335
|
+
}
|
|
336
|
+
async migrate(globalData) {
|
|
337
|
+
return {
|
|
338
|
+
replacements: globalData.replacements,
|
|
339
|
+
};
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
function migrate(options) {
|
|
344
|
+
return async (tree, context) => {
|
|
345
|
+
await project_paths.runMigrationInDevkit({
|
|
346
|
+
tree,
|
|
347
|
+
getMigration: (fs) => new CommonToStandaloneMigration({
|
|
348
|
+
shouldMigrate: (file) => {
|
|
349
|
+
return (file.rootRelativePath.startsWith(fs.normalize(options.path)) &&
|
|
350
|
+
!/(^|\/)node_modules\//.test(file.rootRelativePath));
|
|
351
|
+
},
|
|
352
|
+
}),
|
|
353
|
+
beforeProgramCreation: (tsconfigPath, stage) => {
|
|
354
|
+
if (stage === project_paths.MigrationStage.Analysis) {
|
|
355
|
+
context.logger.info(`Preparing analysis for: ${tsconfigPath}...`);
|
|
356
|
+
}
|
|
357
|
+
else {
|
|
358
|
+
context.logger.info(`Running migration for: ${tsconfigPath}...`);
|
|
359
|
+
}
|
|
360
|
+
},
|
|
361
|
+
beforeUnitAnalysis: (tsconfigPath) => {
|
|
362
|
+
context.logger.info(`Scanning for CommonModule usage: ${tsconfigPath}...`);
|
|
363
|
+
},
|
|
364
|
+
afterAllAnalyzed: () => {
|
|
365
|
+
context.logger.info(``);
|
|
366
|
+
context.logger.info(`Processing analysis data between targets...`);
|
|
367
|
+
context.logger.info(``);
|
|
368
|
+
},
|
|
369
|
+
afterAnalysisFailure: () => {
|
|
370
|
+
context.logger.error('Migration failed unexpectedly with no analysis data');
|
|
371
|
+
},
|
|
372
|
+
whenDone: (stats) => {
|
|
373
|
+
context.logger.info('');
|
|
374
|
+
context.logger.info(`Successfully migrated CommonModule to standalone imports 🎉`);
|
|
375
|
+
context.logger.info(` -> Migrated ${stats.counters.replacements} CommonModule references affecting ${stats.counters.references} components.`);
|
|
376
|
+
},
|
|
377
|
+
});
|
|
378
|
+
};
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
exports.migrate = migrate;
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
/**
|
|
3
|
-
* @license Angular v21.0.0-
|
|
3
|
+
* @license Angular v21.0.0-rc.0
|
|
4
4
|
* (c) 2010-2025 Google LLC. https://angular.io/
|
|
5
5
|
* License: MIT
|
|
6
6
|
*/
|
|
7
7
|
'use strict';
|
|
8
8
|
|
|
9
9
|
var ts = require('typescript');
|
|
10
|
-
var
|
|
11
|
-
require('
|
|
12
|
-
var p = require('path');
|
|
10
|
+
var migrations = require('@angular/compiler-cli/private/migrations');
|
|
11
|
+
var path = require('path');
|
|
13
12
|
|
|
14
13
|
function _interopNamespaceDefault(e) {
|
|
15
14
|
var n = Object.create(null);
|
|
@@ -28,7 +27,7 @@ function _interopNamespaceDefault(e) {
|
|
|
28
27
|
return Object.freeze(n);
|
|
29
28
|
}
|
|
30
29
|
|
|
31
|
-
var
|
|
30
|
+
var path__namespace = /*#__PURE__*/_interopNamespaceDefault(path);
|
|
32
31
|
|
|
33
32
|
/** Tracks changes that have to be made for specific files. */
|
|
34
33
|
class ChangeTracker {
|
|
@@ -40,7 +39,7 @@ class ChangeTracker {
|
|
|
40
39
|
constructor(_printer, _importRemapper) {
|
|
41
40
|
this._printer = _printer;
|
|
42
41
|
this._importRemapper = _importRemapper;
|
|
43
|
-
this._importManager = new
|
|
42
|
+
this._importManager = new migrations.ImportManager({
|
|
44
43
|
shouldUseSingleQuotes: (file) => this._getQuoteKind(file) === 0 /* QuoteKind.SINGLE */,
|
|
45
44
|
});
|
|
46
45
|
}
|
|
@@ -227,7 +226,7 @@ function parseTsconfigFile(tsconfigPath, basePath) {
|
|
|
227
226
|
// Throw if incorrect arguments are passed to this function. Passing relative base paths
|
|
228
227
|
// results in root directories not being resolved and in later type checking runtime errors.
|
|
229
228
|
// More details can be found here: https://github.com/microsoft/TypeScript/issues/37731.
|
|
230
|
-
if (!
|
|
229
|
+
if (!path__namespace.isAbsolute(basePath)) {
|
|
231
230
|
throw Error('Unexpected relative base path has been specified.');
|
|
232
231
|
}
|
|
233
232
|
return ts.parseJsonConfigFileContent(config, parseConfigHost, basePath, {});
|
|
@@ -261,8 +260,8 @@ function createProgramOptions(tree, tsconfigPath, basePath, fakeFileRead, additi
|
|
|
261
260
|
// Resolve the tsconfig path to an absolute path. This is needed as TypeScript otherwise
|
|
262
261
|
// is not able to resolve root directories in the given tsconfig. More details can be found
|
|
263
262
|
// in the following issue: https://github.com/microsoft/TypeScript/issues/37731.
|
|
264
|
-
tsconfigPath =
|
|
265
|
-
const parsed = parseTsconfigFile(tsconfigPath,
|
|
263
|
+
tsconfigPath = path.resolve(basePath, tsconfigPath);
|
|
264
|
+
const parsed = parseTsconfigFile(tsconfigPath, path.dirname(tsconfigPath));
|
|
266
265
|
const options = optionOverrides ? { ...parsed.options, ...optionOverrides } : parsed.options;
|
|
267
266
|
const host = createMigrationCompilerHost(tree, options, basePath, fakeFileRead);
|
|
268
267
|
return { rootNames: parsed.fileNames.concat([]), options, host };
|
|
@@ -275,7 +274,7 @@ function createMigrationCompilerHost(tree, options, basePath, fakeRead) {
|
|
|
275
274
|
// if we run multiple migrations we might have intersecting changes and
|
|
276
275
|
// source files.
|
|
277
276
|
host.readFile = (fileName) => {
|
|
278
|
-
const treeRelativePath =
|
|
277
|
+
const treeRelativePath = path.relative(basePath, fileName);
|
|
279
278
|
let result = fakeRead?.(treeRelativePath);
|
|
280
279
|
if (typeof result !== 'string') {
|
|
281
280
|
// If the relative path resolved to somewhere outside of the tree, fall back to
|
|
@@ -309,7 +308,7 @@ function canMigrateFile(basePath, sourceFile, program) {
|
|
|
309
308
|
// project. We can't migrate files outside of the project, because our file system interactions
|
|
310
309
|
// go through the CLI's `Tree` which assumes that all files are within the project. See:
|
|
311
310
|
// https://github.com/angular/angular-cli/blob/0b0961c9c233a825b6e4bb59ab7f0790f9b14676/packages/angular_devkit/schematics/src/tree/host-tree.ts#L131
|
|
312
|
-
return !
|
|
311
|
+
return !path.relative(basePath, sourceFile.fileName).startsWith('..');
|
|
313
312
|
}
|
|
314
313
|
|
|
315
314
|
exports.ChangeTracker = ChangeTracker;
|
|
@@ -1,21 +1,19 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
/**
|
|
3
|
-
* @license Angular v21.0.0-
|
|
3
|
+
* @license Angular v21.0.0-rc.0
|
|
4
4
|
* (c) 2010-2025 Google LLC. https://angular.io/
|
|
5
5
|
* License: MIT
|
|
6
6
|
*/
|
|
7
7
|
'use strict';
|
|
8
8
|
|
|
9
9
|
var schematics = require('@angular-devkit/schematics');
|
|
10
|
-
var
|
|
11
|
-
var compiler_host = require('./compiler_host-
|
|
12
|
-
var
|
|
10
|
+
var path = require('path');
|
|
11
|
+
var compiler_host = require('./compiler_host-DBwYMlTo.cjs');
|
|
12
|
+
var compiler = require('@angular/compiler');
|
|
13
13
|
var ts = require('typescript');
|
|
14
|
-
var parse_html = require('./parse_html-
|
|
15
|
-
require('
|
|
16
|
-
require('
|
|
17
|
-
require('module');
|
|
18
|
-
require('url');
|
|
14
|
+
var parse_html = require('./parse_html-8VLCL37B.cjs');
|
|
15
|
+
var project_tsconfig_paths = require('./project_tsconfig_paths-CDVxT6Ov.cjs');
|
|
16
|
+
require('@angular/compiler-cli/private/migrations');
|
|
19
17
|
require('@angular-devkit/core');
|
|
20
18
|
|
|
21
19
|
function lookupIdentifiersInSourceFile(sourceFile, names) {
|
|
@@ -275,7 +273,7 @@ class AnalyzedFile {
|
|
|
275
273
|
}
|
|
276
274
|
}
|
|
277
275
|
/** Finds all non-control flow elements from common module. */
|
|
278
|
-
class CommonCollector extends
|
|
276
|
+
class CommonCollector extends compiler.RecursiveVisitor {
|
|
279
277
|
count = 0;
|
|
280
278
|
visitElement(el) {
|
|
281
279
|
if (el.attrs.length > 0) {
|
|
@@ -314,7 +312,7 @@ class CommonCollector extends project_tsconfig_paths.RecursiveVisitor$1 {
|
|
|
314
312
|
}
|
|
315
313
|
}
|
|
316
314
|
/** Finds all elements that represent i18n blocks. */
|
|
317
|
-
class i18nCollector extends
|
|
315
|
+
class i18nCollector extends compiler.RecursiveVisitor {
|
|
318
316
|
elements = [];
|
|
319
317
|
visitElement(el) {
|
|
320
318
|
if (el.attrs.find((a) => a.name === 'i18n') !== undefined) {
|
|
@@ -324,7 +322,7 @@ class i18nCollector extends project_tsconfig_paths.RecursiveVisitor$1 {
|
|
|
324
322
|
}
|
|
325
323
|
}
|
|
326
324
|
/** Finds all elements with ngif structural directives. */
|
|
327
|
-
class ElementCollector extends
|
|
325
|
+
class ElementCollector extends compiler.RecursiveVisitor {
|
|
328
326
|
_attributes;
|
|
329
327
|
elements = [];
|
|
330
328
|
constructor(_attributes = []) {
|
|
@@ -377,7 +375,7 @@ class ElementCollector extends project_tsconfig_paths.RecursiveVisitor$1 {
|
|
|
377
375
|
}
|
|
378
376
|
}
|
|
379
377
|
/** Finds all elements with ngif structural directives. */
|
|
380
|
-
class TemplateCollector extends
|
|
378
|
+
class TemplateCollector extends compiler.RecursiveVisitor {
|
|
381
379
|
elements = [];
|
|
382
380
|
templates = new Map();
|
|
383
381
|
visitElement(el) {
|
|
@@ -550,8 +548,8 @@ function analyzeDecorators(node, sourceFile, analyzedFiles) {
|
|
|
550
548
|
case 'templateUrl':
|
|
551
549
|
// Leave the end as undefined which means that the range is until the end of the file.
|
|
552
550
|
if (ts.isStringLiteralLike(prop.initializer)) {
|
|
553
|
-
const path =
|
|
554
|
-
AnalyzedFile.addRange(path, sourceFile, analyzedFiles, {
|
|
551
|
+
const path$1 = path.join(path.dirname(sourceFile.fileName), prop.initializer.text);
|
|
552
|
+
AnalyzedFile.addRange(path$1, sourceFile, analyzedFiles, {
|
|
555
553
|
start: 0,
|
|
556
554
|
node: prop,
|
|
557
555
|
type: 'templateUrl',
|
|
@@ -601,7 +599,7 @@ function validateMigratedTemplate(migrated, fileName) {
|
|
|
601
599
|
}
|
|
602
600
|
function validateI18nStructure(parsed, fileName) {
|
|
603
601
|
const visitor = new i18nCollector();
|
|
604
|
-
|
|
602
|
+
compiler.visitAll(visitor, parsed.rootNodes);
|
|
605
603
|
const parents = visitor.elements.filter((el) => el.children.length > 0);
|
|
606
604
|
for (const p of parents) {
|
|
607
605
|
for (const el of visitor.elements) {
|
|
@@ -681,7 +679,7 @@ function getTemplates(template) {
|
|
|
681
679
|
const parsed = parse_html.parseTemplate(template);
|
|
682
680
|
if (parsed.tree !== undefined) {
|
|
683
681
|
const visitor = new TemplateCollector();
|
|
684
|
-
|
|
682
|
+
compiler.visitAll(visitor, parsed.tree.rootNodes);
|
|
685
683
|
for (let [key, tmpl] of visitor.templates) {
|
|
686
684
|
tmpl.count = countTemplateUsage(parsed.tree.rootNodes, key);
|
|
687
685
|
tmpl.generateContents(template);
|
|
@@ -785,7 +783,7 @@ function analyzeTemplateUsage(nodes, templateName) {
|
|
|
785
783
|
if (node.attrs) {
|
|
786
784
|
for (const attr of node.attrs) {
|
|
787
785
|
if ((attr.name === '*ngTemplateOutlet' || attr.name === '[ngTemplateOutlet]') &&
|
|
788
|
-
attr.value === templateName) {
|
|
786
|
+
attr.value?.split(';')[0] === templateName) {
|
|
789
787
|
isReferencedInTemplateOutlet = true;
|
|
790
788
|
}
|
|
791
789
|
if (attr.name.trim() === templateNameWithHash) {
|
|
@@ -888,7 +886,7 @@ function canRemoveCommonModule(template) {
|
|
|
888
886
|
let removeCommonModule = false;
|
|
889
887
|
if (parsed.tree !== undefined) {
|
|
890
888
|
const visitor = new CommonCollector();
|
|
891
|
-
|
|
889
|
+
compiler.visitAll(visitor, parsed.tree.rootNodes);
|
|
892
890
|
removeCommonModule = visitor.count === 0;
|
|
893
891
|
}
|
|
894
892
|
return removeCommonModule;
|
|
@@ -1011,7 +1009,7 @@ function generateI18nMarkers(tmpl) {
|
|
|
1011
1009
|
let parsed = parse_html.parseTemplate(tmpl);
|
|
1012
1010
|
if (parsed.tree !== undefined) {
|
|
1013
1011
|
const visitor = new i18nCollector();
|
|
1014
|
-
|
|
1012
|
+
compiler.visitAll(visitor, parsed.tree.rootNodes);
|
|
1015
1013
|
for (const [ix, el] of visitor.elements.entries()) {
|
|
1016
1014
|
// we only care about elements with children and i18n tags
|
|
1017
1015
|
// elements without children have nothing to translate
|
|
@@ -1213,7 +1211,7 @@ function migrateCase(template) {
|
|
|
1213
1211
|
}
|
|
1214
1212
|
let result = template;
|
|
1215
1213
|
const visitor = new ElementCollector(cases);
|
|
1216
|
-
|
|
1214
|
+
compiler.visitAll(visitor, parsed.tree.rootNodes);
|
|
1217
1215
|
calculateNesting(visitor, hasLineBreaks(template));
|
|
1218
1216
|
// this tracks the character shift from different lengths of blocks from
|
|
1219
1217
|
// the prior directives so as to adjust for nested block replacement during
|
|
@@ -1310,7 +1308,7 @@ function migrateFor(template) {
|
|
|
1310
1308
|
}
|
|
1311
1309
|
let result = template;
|
|
1312
1310
|
const visitor = new ElementCollector(fors);
|
|
1313
|
-
|
|
1311
|
+
compiler.visitAll(visitor, parsed.tree.rootNodes);
|
|
1314
1312
|
calculateNesting(visitor, hasLineBreaks(template));
|
|
1315
1313
|
// this tracks the character shift from different lengths of blocks from
|
|
1316
1314
|
// the prior directives so as to adjust for nested block replacement during
|
|
@@ -1515,7 +1513,7 @@ function migrateIf(template) {
|
|
|
1515
1513
|
}
|
|
1516
1514
|
let result = template;
|
|
1517
1515
|
const visitor = new ElementCollector(ifs);
|
|
1518
|
-
|
|
1516
|
+
compiler.visitAll(visitor, parsed.tree.rootNodes);
|
|
1519
1517
|
calculateNesting(visitor, hasLineBreaks(template));
|
|
1520
1518
|
// this tracks the character shift from different lengths of blocks from
|
|
1521
1519
|
// the prior directives so as to adjust for nested block replacement during
|
|
@@ -1708,7 +1706,7 @@ function migrateSwitch(template) {
|
|
|
1708
1706
|
}
|
|
1709
1707
|
let result = template;
|
|
1710
1708
|
const visitor = new ElementCollector(switches);
|
|
1711
|
-
|
|
1709
|
+
compiler.visitAll(visitor, parsed.tree.rootNodes);
|
|
1712
1710
|
calculateNesting(visitor, hasLineBreaks(template));
|
|
1713
1711
|
// this tracks the character shift from different lengths of blocks from
|
|
1714
1712
|
// the prior directives so as to adjust for nested block replacement during
|
|
@@ -1739,11 +1737,11 @@ function migrateSwitch(template) {
|
|
|
1739
1737
|
}
|
|
1740
1738
|
function assertValidSwitchStructure(children) {
|
|
1741
1739
|
for (const child of children) {
|
|
1742
|
-
if (child instanceof
|
|
1740
|
+
if (child instanceof compiler.Text && child.value.trim() !== '') {
|
|
1743
1741
|
throw new Error(`Text node: "${child.value}" would result in invalid migrated @switch block structure. ` +
|
|
1744
1742
|
`@switch can only have @case or @default as children.`);
|
|
1745
1743
|
}
|
|
1746
|
-
else if (child instanceof
|
|
1744
|
+
else if (child instanceof compiler.Element) {
|
|
1747
1745
|
let hasCase = false;
|
|
1748
1746
|
for (const attr of child.attrs) {
|
|
1749
1747
|
if (cases.includes(attr.name)) {
|
|
@@ -1850,7 +1848,7 @@ function migrate(options) {
|
|
|
1850
1848
|
if (options.path.startsWith('..')) {
|
|
1851
1849
|
throw new schematics.SchematicsException('Cannot run control flow migration outside of the current project.');
|
|
1852
1850
|
}
|
|
1853
|
-
pathToMigrate = compiler_host.normalizePath(
|
|
1851
|
+
pathToMigrate = compiler_host.normalizePath(path.join(basePath, options.path));
|
|
1854
1852
|
if (pathToMigrate.trim() !== '') {
|
|
1855
1853
|
allPaths.push(pathToMigrate);
|
|
1856
1854
|
}
|
|
@@ -1893,10 +1891,10 @@ function runControlFlowMigration(tree, sourceFiles, basePath, schematicOptions)
|
|
|
1893
1891
|
// sort files with .html files first
|
|
1894
1892
|
// this ensures class files know if it's safe to remove CommonModule
|
|
1895
1893
|
const paths = sortFilePaths([...analysis.keys()]);
|
|
1896
|
-
for (const path of paths) {
|
|
1897
|
-
const file = analysis.get(path);
|
|
1894
|
+
for (const path$1 of paths) {
|
|
1895
|
+
const file = analysis.get(path$1);
|
|
1898
1896
|
const ranges = file.getSortedRanges();
|
|
1899
|
-
const relativePath =
|
|
1897
|
+
const relativePath = path.relative(basePath, path$1);
|
|
1900
1898
|
const content = tree.readText(relativePath);
|
|
1901
1899
|
const update = tree.beginUpdate(relativePath);
|
|
1902
1900
|
for (const { start, end, node, type } of ranges) {
|
|
@@ -1908,7 +1906,7 @@ function runControlFlowMigration(tree, sourceFiles, basePath, schematicOptions)
|
|
|
1908
1906
|
update.insertLeft(start, migrated);
|
|
1909
1907
|
}
|
|
1910
1908
|
if (errors.length > 0) {
|
|
1911
|
-
migrateErrors.set(path, errors);
|
|
1909
|
+
migrateErrors.set(path$1, errors);
|
|
1912
1910
|
}
|
|
1913
1911
|
}
|
|
1914
1912
|
tree.commitUpdate(update);
|