@angular/cli 20.2.1 → 20.2.2

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.
Files changed (29) hide show
  1. package/lib/code-examples.db +0 -0
  2. package/package.json +14 -14
  3. package/src/command-builder/architect-command-module.js +11 -5
  4. package/src/command-builder/utilities/json-schema.js +1 -1
  5. package/src/commands/mcp/mcp-server.d.ts +12 -2
  6. package/src/commands/mcp/mcp-server.js +6 -1
  7. package/src/commands/mcp/tools/best-practices.js +15 -5
  8. package/src/commands/mcp/tools/doc-search.d.ts +18 -1
  9. package/src/commands/mcp/tools/doc-search.js +94 -37
  10. package/src/commands/mcp/tools/examples.d.ts +9 -1
  11. package/src/commands/mcp/tools/examples.js +38 -12
  12. package/src/commands/mcp/tools/modernize.js +28 -17
  13. package/src/commands/mcp/tools/onpush-zoneless-migration/analyze_for_unsupported_zone_uses.d.ts +17 -0
  14. package/src/commands/mcp/tools/onpush-zoneless-migration/analyze_for_unsupported_zone_uses.js +61 -0
  15. package/src/commands/mcp/tools/onpush-zoneless-migration/migrate_single_file.d.ts +12 -0
  16. package/src/commands/mcp/tools/onpush-zoneless-migration/migrate_single_file.js +72 -0
  17. package/src/commands/mcp/tools/onpush-zoneless-migration/migrate_test_file.d.ts +11 -0
  18. package/src/commands/mcp/tools/onpush-zoneless-migration/migrate_test_file.js +105 -0
  19. package/src/commands/mcp/tools/onpush-zoneless-migration/prompts.d.ts +15 -0
  20. package/src/commands/mcp/tools/onpush-zoneless-migration/prompts.js +236 -0
  21. package/src/commands/mcp/tools/onpush-zoneless-migration/send_debug_message.d.ts +10 -0
  22. package/src/commands/mcp/tools/onpush-zoneless-migration/send_debug_message.js +19 -0
  23. package/src/commands/mcp/tools/onpush-zoneless-migration/ts_utils.d.ts +36 -0
  24. package/src/commands/mcp/tools/onpush-zoneless-migration/ts_utils.js +135 -0
  25. package/src/commands/mcp/tools/onpush-zoneless-migration/types.d.ts +13 -0
  26. package/src/commands/mcp/tools/onpush-zoneless-migration/types.js +9 -0
  27. package/src/commands/mcp/tools/onpush-zoneless-migration/zoneless-migration.d.ts +14 -0
  28. package/src/commands/mcp/tools/onpush-zoneless-migration/zoneless-migration.js +205 -0
  29. package/src/utilities/version.js +1 -1
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ /**
3
+ * @license
4
+ * Copyright Google LLC All Rights Reserved.
5
+ *
6
+ * Use of this source code is governed by an MIT-style license that can be
7
+ * found in the LICENSE file at https://angular.dev/license
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,14 @@
1
+ /**
2
+ * @license
3
+ * Copyright Google LLC All Rights Reserved.
4
+ *
5
+ * Use of this source code is governed by an MIT-style license that can be
6
+ * found in the LICENSE file at https://angular.dev/license
7
+ */
8
+ import { RequestHandlerExtra } from '@modelcontextprotocol/sdk/shared/protocol';
9
+ import { ServerNotification, ServerRequest } from '@modelcontextprotocol/sdk/types';
10
+ import { z } from 'zod';
11
+ export declare const ZONELESS_MIGRATION_TOOL: import("../tool-registry").McpToolDeclaration<{
12
+ fileOrDirPath: z.ZodString;
13
+ }, z.ZodRawShape>;
14
+ export declare function registerZonelessMigrationTool(fileOrDirPath: string, extras: RequestHandlerExtra<ServerRequest, ServerNotification>): Promise<import("./types").MigrationResponse>;
@@ -0,0 +1,205 @@
1
+ "use strict";
2
+ /**
3
+ * @license
4
+ * Copyright Google LLC All Rights Reserved.
5
+ *
6
+ * Use of this source code is governed by an MIT-style license that can be
7
+ * found in the LICENSE file at https://angular.dev/license
8
+ */
9
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ var desc = Object.getOwnPropertyDescriptor(m, k);
12
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
13
+ desc = { enumerable: true, get: function() { return m[k]; } };
14
+ }
15
+ Object.defineProperty(o, k2, desc);
16
+ }) : (function(o, m, k, k2) {
17
+ if (k2 === undefined) k2 = k;
18
+ o[k2] = m[k];
19
+ }));
20
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
21
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
22
+ }) : function(o, v) {
23
+ o["default"] = v;
24
+ });
25
+ var __importStar = (this && this.__importStar) || (function () {
26
+ var ownKeys = function(o) {
27
+ ownKeys = Object.getOwnPropertyNames || function (o) {
28
+ var ar = [];
29
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
30
+ return ar;
31
+ };
32
+ return ownKeys(o);
33
+ };
34
+ return function (mod) {
35
+ if (mod && mod.__esModule) return mod;
36
+ var result = {};
37
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
38
+ __setModuleDefault(result, mod);
39
+ return result;
40
+ };
41
+ })();
42
+ Object.defineProperty(exports, "__esModule", { value: true });
43
+ exports.ZONELESS_MIGRATION_TOOL = void 0;
44
+ exports.registerZonelessMigrationTool = registerZonelessMigrationTool;
45
+ const fs = __importStar(require("node:fs"));
46
+ const promises_1 = require("node:fs/promises");
47
+ const zod_1 = require("zod");
48
+ const tool_registry_1 = require("../tool-registry");
49
+ const analyze_for_unsupported_zone_uses_1 = require("./analyze_for_unsupported_zone_uses");
50
+ const migrate_single_file_1 = require("./migrate_single_file");
51
+ const migrate_test_file_1 = require("./migrate_test_file");
52
+ const prompts_1 = require("./prompts");
53
+ const send_debug_message_1 = require("./send_debug_message");
54
+ const ts_utils_1 = require("./ts_utils");
55
+ exports.ZONELESS_MIGRATION_TOOL = (0, tool_registry_1.declareTool)({
56
+ name: 'onpush-zoneless-migration',
57
+ title: 'Plan migration to OnPush and/or zoneless',
58
+ description: `
59
+ <Purpose>
60
+ Analyzes Angular code and provides a step-by-step, iterative plan to migrate it to \`OnPush\`
61
+ change detection, a prerequisite for a zoneless application. This tool identifies the next single
62
+ most important action to take in the migration journey.
63
+ </Purpose>
64
+ <Use Cases>
65
+ * **Step-by-Step Migration:** Running the tool repeatedly to get the next instruction for a full
66
+ migration to \`OnPush\`.
67
+ * **Pre-Migration Analysis:** Checking a component or directory for unsupported \`NgZone\` APIs that
68
+ would block a zoneless migration.
69
+ * **Generating Component Migrations:** Getting the exact instructions for converting a single
70
+ component from the default change detection strategy to \`OnPush\`.
71
+ </Use Cases>
72
+ <Operational Notes>
73
+ * **Execution Model:** This tool **DOES NOT** modify code. It **PROVIDES INSTRUCTIONS** for a
74
+ single action at a time. You **MUST** apply the changes it suggests, and then run the tool
75
+ again to get the next step.
76
+ * **Iterative Process:** The migration process is iterative. You must call this tool repeatedly,
77
+ applying the suggested fix after each call, until the tool indicates that no more actions are
78
+ needed.
79
+ * **Relationship to \`modernize\`:** This tool is the specialized starting point for the zoneless/OnPush
80
+ migration. For other migrations (like signal inputs), you should use the \`modernize\` tool first,
81
+ as the zoneless migration may depend on them as prerequisites.
82
+ * **Input:** The tool can operate on either a single file or an entire directory. Provide the
83
+ absolute path.
84
+ </Operational Notes>`,
85
+ isReadOnly: true,
86
+ isLocalOnly: true,
87
+ inputSchema: {
88
+ fileOrDirPath: zod_1.z
89
+ .string()
90
+ .describe('The absolute path of the directory or file with the component(s), directive(s), or service(s) to migrate.' +
91
+ ' The contents are read with fs.readFileSync.'),
92
+ },
93
+ factory: () => ({ fileOrDirPath }, requestHandlerExtra) => registerZonelessMigrationTool(fileOrDirPath, requestHandlerExtra),
94
+ });
95
+ async function registerZonelessMigrationTool(fileOrDirPath, extras) {
96
+ let files = [];
97
+ const componentTestFiles = new Set();
98
+ const filesWithComponents = new Set();
99
+ const zoneFiles = new Set();
100
+ if (fs.statSync(fileOrDirPath).isDirectory()) {
101
+ const allFiles = (0, promises_1.glob)(`${fileOrDirPath}/**/*.ts`);
102
+ for await (const file of allFiles) {
103
+ files.push(await (0, ts_utils_1.createSourceFile)(file));
104
+ }
105
+ }
106
+ else {
107
+ files = [await (0, ts_utils_1.createSourceFile)(fileOrDirPath)];
108
+ const maybeTestFile = await getTestFilePath(fileOrDirPath);
109
+ if (maybeTestFile) {
110
+ componentTestFiles.add(await (0, ts_utils_1.createSourceFile)(maybeTestFile));
111
+ }
112
+ }
113
+ for (const sourceFile of files) {
114
+ const content = sourceFile.getFullText();
115
+ const componentSpecifier = await (0, ts_utils_1.getImportSpecifier)(sourceFile, '@angular/core', 'Component');
116
+ const zoneSpecifier = await (0, ts_utils_1.getImportSpecifier)(sourceFile, '@angular/core', 'NgZone');
117
+ const testBedSpecifier = await (0, ts_utils_1.getImportSpecifier)(sourceFile, /(@angular\/core)?\/testing/, 'TestBed');
118
+ if (testBedSpecifier) {
119
+ componentTestFiles.add(sourceFile);
120
+ }
121
+ else if (componentSpecifier) {
122
+ if (!content.includes('changeDetectionStrategy: ChangeDetectionStrategy.OnPush') &&
123
+ !content.includes('changeDetectionStrategy: ChangeDetectionStrategy.Default')) {
124
+ filesWithComponents.add(sourceFile);
125
+ }
126
+ else {
127
+ (0, send_debug_message_1.sendDebugMessage)(`Component file already has change detection strategy: ${sourceFile.fileName}. Skipping migration.`, extras);
128
+ }
129
+ const testFilePath = await getTestFilePath(sourceFile.fileName);
130
+ if (testFilePath) {
131
+ componentTestFiles.add(await (0, ts_utils_1.createSourceFile)(testFilePath));
132
+ }
133
+ }
134
+ else if (zoneSpecifier) {
135
+ zoneFiles.add(sourceFile);
136
+ }
137
+ }
138
+ if (zoneFiles.size > 0) {
139
+ for (const file of zoneFiles) {
140
+ const result = await (0, analyze_for_unsupported_zone_uses_1.analyzeForUnsupportedZoneUses)(file);
141
+ if (result !== null) {
142
+ return result;
143
+ }
144
+ }
145
+ }
146
+ if (filesWithComponents.size > 0) {
147
+ const rankedFiles = filesWithComponents.size > 1
148
+ ? await rankComponentFilesForMigration(extras, Array.from(filesWithComponents))
149
+ : Array.from(filesWithComponents);
150
+ for (const file of rankedFiles) {
151
+ const result = await (0, migrate_single_file_1.migrateSingleFile)(file, extras);
152
+ if (result !== null) {
153
+ return result;
154
+ }
155
+ }
156
+ }
157
+ for (const file of componentTestFiles) {
158
+ const result = await (0, migrate_test_file_1.migrateTestFile)(file);
159
+ if (result !== null) {
160
+ return result;
161
+ }
162
+ }
163
+ return (0, prompts_1.createTestDebuggingGuideForNonActionableInput)(fileOrDirPath);
164
+ }
165
+ async function rankComponentFilesForMigration({ sendRequest }, componentFiles) {
166
+ try {
167
+ const response = await sendRequest({
168
+ method: 'sampling/createMessage',
169
+ params: {
170
+ messages: [
171
+ {
172
+ role: 'user',
173
+ content: {
174
+ type: 'text',
175
+ text: `The following files are components that need to be migrated to OnPush change detection.` +
176
+ ` Please rank them based on which ones are most likely to be shared or common components.` +
177
+ ` The most likely shared component should be first.
178
+ ${componentFiles.map((f) => f.fileName).join('\n ')}
179
+ Respond ONLY with the ranked list of files, one file per line.`,
180
+ },
181
+ },
182
+ ],
183
+ systemPrompt: 'You are a helpful assistant that helps migrate identify shared Angular components.',
184
+ maxTokens: 2000,
185
+ },
186
+ }, zod_1.z.object({ sortedFiles: zod_1.z.array(zod_1.z.string()) }));
187
+ const rankedFiles = response.sortedFiles
188
+ .map((line) => line.trim())
189
+ .map((fileName) => componentFiles.find((f) => f.fileName === fileName))
190
+ .filter((f) => !!f);
191
+ // Ensure the ranking didn't mess up the list of files
192
+ if (rankedFiles.length === componentFiles.length) {
193
+ return rankedFiles;
194
+ }
195
+ }
196
+ catch { }
197
+ return componentFiles; // Fallback to original order if the response fails
198
+ }
199
+ async function getTestFilePath(filePath) {
200
+ const testFilePath = filePath.replace(/\.ts$/, '.spec.ts');
201
+ if (fs.existsSync(testFilePath)) {
202
+ return testFilePath;
203
+ }
204
+ return undefined;
205
+ }
@@ -22,4 +22,4 @@ class Version {
22
22
  this.patch = patch;
23
23
  }
24
24
  }
25
- exports.VERSION = new Version('20.2.1');
25
+ exports.VERSION = new Version('20.2.2');