@angular/core 21.0.0-next.0 → 21.0.0-next.10
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 +12 -0
- package/fesm2022/_attribute-chunk.mjs.map +1 -0
- package/fesm2022/_debug_node-chunk.mjs +18469 -0
- package/fesm2022/_debug_node-chunk.mjs.map +1 -0
- package/fesm2022/_effect-chunk.mjs +423 -0
- package/fesm2022/_effect-chunk.mjs.map +1 -0
- package/fesm2022/_effect-chunk2.mjs +2951 -0
- package/fesm2022/_effect-chunk2.mjs.map +1 -0
- package/fesm2022/_not_found-chunk.mjs +39 -0
- package/fesm2022/_not_found-chunk.mjs.map +1 -0
- package/fesm2022/_resource-chunk.mjs +378 -0
- package/fesm2022/_resource-chunk.mjs.map +1 -0
- package/fesm2022/_untracked-chunk.mjs +96 -0
- package/fesm2022/_untracked-chunk.mjs.map +1 -0
- package/fesm2022/_weak_ref-chunk.mjs +10 -0
- package/fesm2022/_weak_ref-chunk.mjs.map +1 -0
- package/fesm2022/core.mjs +2499 -4185
- package/fesm2022/core.mjs.map +1 -1
- package/fesm2022/primitives-di.mjs +23 -0
- package/fesm2022/primitives-di.mjs.map +1 -0
- package/fesm2022/primitives-event-dispatch.mjs +788 -0
- package/fesm2022/primitives-event-dispatch.mjs.map +1 -0
- package/fesm2022/primitives-signals.mjs +187 -0
- package/fesm2022/primitives-signals.mjs.map +1 -0
- package/fesm2022/rxjs-interop.mjs +210 -308
- package/fesm2022/rxjs-interop.mjs.map +1 -1
- package/fesm2022/testing.mjs +2309 -3170
- package/fesm2022/testing.mjs.map +1 -1
- package/package.json +18 -12
- package/resources/best-practices.md +56 -0
- package/schematics/bundles/add-bootstrap-context-to-server-main.cjs +117 -0
- package/schematics/bundles/application-config-core.cjs +84 -0
- package/schematics/bundles/{apply_import_manager-DR9xXCle.cjs → apply_import_manager-1Zs_gpB6.cjs} +4 -5
- package/schematics/bundles/bootstrap-options-migration.cjs +598 -0
- package/schematics/bundles/cleanup-unused-imports.cjs +9 -13
- package/schematics/bundles/common-to-standalone-migration.cjs +381 -0
- package/schematics/bundles/{compiler_host-BXBP7CE2.cjs → compiler_host-DBwYMlTo.cjs} +10 -11
- package/schematics/bundles/control-flow-migration.cjs +122 -119
- package/schematics/bundles/{imports-CIX-JgAN.cjs → imports-DP72APSx.cjs} +6 -1
- package/schematics/bundles/{index-CfTQUOiz.cjs → index-B7I9sIUx.cjs} +36 -39
- package/schematics/bundles/inject-migration.cjs +148 -70
- package/schematics/bundles/leading_space-D9nQ8UQC.cjs +1 -1
- package/schematics/bundles/{migrate_ts_type_references-6NtAj-Wk.cjs → migrate_ts_type_references-UGIUl7En.cjs} +500 -24
- package/schematics/bundles/ng_component_template-Dsuq1Lw7.cjs +185 -0
- package/schematics/bundles/{ng_decorators-B5HCqr20.cjs → ng_decorators-DSFlWYQY.cjs} +2 -2
- package/schematics/bundles/ngclass-to-class-migration.cjs +542 -0
- package/schematics/bundles/ngstyle-to-style-migration.cjs +487 -0
- package/schematics/bundles/nodes-B16H9JUd.cjs +1 -1
- package/schematics/bundles/output-migration.cjs +16 -19
- package/schematics/bundles/parse_html-8VLCL37B.cjs +132 -0
- package/schematics/bundles/{project_paths-DcaODbky.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 +54 -26
- package/schematics/bundles/router-current-navigation.cjs +7 -18
- package/schematics/bundles/router-last-successful-navigation.cjs +7 -18
- package/schematics/bundles/router-testing-module-migration.cjs +502 -0
- package/schematics/bundles/self-closing-tags-migration.cjs +17 -216
- package/schematics/bundles/signal-input-migration.cjs +93 -29
- package/schematics/bundles/signal-queries-migration.cjs +22 -25
- package/schematics/bundles/signals.cjs +10 -13
- package/schematics/bundles/standalone-migration.cjs +135 -102
- package/schematics/bundles/{symbol-VPWguRxr.cjs → symbol-BObKoqes.cjs} +3 -2
- package/schematics/collection.json +23 -0
- package/schematics/migrations/common-to-standalone-migration/schema.json +14 -0
- package/schematics/migrations/ngclass-to-class-migration/schema.json +20 -0
- package/schematics/migrations/ngstyle-to-style-migration/schema.json +20 -0
- package/schematics/migrations/router-testing-module-migration/schema.json +14 -0
- package/schematics/migrations.json +16 -2
- package/{api.d.d.ts → types/_api-chunk.d.ts} +9 -6
- package/{chrome_dev_tools_performance.d.d.ts → types/_chrome_dev_tools_performance-chunk.d.ts} +26 -31
- package/{discovery.d.d.ts → types/_discovery-chunk.d.ts} +135 -98
- package/{signal.d.d.ts → types/_effect-chunk.d.ts} +14 -5
- package/{event_dispatcher.d.d.ts → types/_event_dispatcher-chunk.d.ts} +2 -2
- package/{graph.d.d.ts → types/_formatter-chunk.d.ts} +40 -7
- package/{weak_ref.d.d.ts → types/_weak_ref-chunk.d.ts} +2 -2
- package/{index.d.ts → types/core.d.ts} +233 -305
- package/{primitives/di/index.d.ts → types/primitives-di.d.ts} +2 -2
- package/{primitives/event-dispatch/index.d.ts → types/primitives-event-dispatch.d.ts} +4 -4
- package/{primitives/signals/index.d.ts → types/primitives-signals.d.ts} +7 -8
- package/{rxjs-interop/index.d.ts → types/rxjs-interop.d.ts} +8 -6
- package/{testing/index.d.ts → types/testing.d.ts} +7 -7
- package/fesm2022/attribute.mjs +0 -24
- package/fesm2022/attribute.mjs.map +0 -1
- package/fesm2022/debug_node.mjs +0 -31833
- package/fesm2022/debug_node.mjs.map +0 -1
- package/fesm2022/not_found.mjs +0 -56
- package/fesm2022/not_found.mjs.map +0 -1
- package/fesm2022/primitives/di.mjs +0 -23
- package/fesm2022/primitives/di.mjs.map +0 -1
- package/fesm2022/primitives/event-dispatch.mjs +0 -1622
- package/fesm2022/primitives/event-dispatch.mjs.map +0 -1
- package/fesm2022/primitives/signals.mjs +0 -89
- package/fesm2022/primitives/signals.mjs.map +0 -1
- package/fesm2022/resource.mjs +0 -633
- package/fesm2022/resource.mjs.map +0 -1
- package/fesm2022/root_effect_scheduler.mjs +0 -4007
- package/fesm2022/root_effect_scheduler.mjs.map +0 -1
- package/fesm2022/signal.mjs +0 -560
- package/fesm2022/signal.mjs.map +0 -1
- package/fesm2022/untracked.mjs +0 -117
- package/fesm2022/untracked.mjs.map +0 -1
- package/fesm2022/weak_ref.mjs +0 -12
- package/fesm2022/weak_ref.mjs.map +0 -1
- package/schematics/bundles/index-esqfDjNB.cjs +0 -22074
- package/schematics/bundles/project_tsconfig_paths-CS-eSeHC.cjs +0 -51062
|
@@ -0,0 +1,381 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/**
|
|
3
|
+
* @license Angular v21.0.0-next.10
|
|
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-next.
|
|
3
|
+
* @license Angular v21.0.0-next.10
|
|
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;
|