@angular/cli 21.0.0-next.1 → 21.0.0-next.3
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/lib/code-examples.db +0 -0
- package/lib/config/schema.json +34 -3
- package/lib/config/workspace-schema.d.ts +39 -0
- package/lib/config/workspace-schema.js +12 -1
- package/package.json +19 -19
- package/src/command-builder/architect-command-module.js +11 -5
- package/src/command-builder/utilities/json-schema.js +1 -1
- package/src/commands/add/cli.js +65 -26
- package/src/commands/mcp/mcp-server.d.ts +3 -3
- package/src/commands/mcp/mcp-server.js +36 -4
- package/src/commands/mcp/tools/best-practices.js +15 -5
- package/src/commands/mcp/tools/doc-search.d.ts +18 -1
- package/src/commands/mcp/tools/doc-search.js +94 -37
- package/src/commands/mcp/tools/examples.d.ts +34 -1
- package/src/commands/mcp/tools/examples.js +295 -44
- package/src/commands/mcp/tools/modernize.js +28 -17
- package/src/commands/mcp/tools/onpush-zoneless-migration/analyze_for_unsupported_zone_uses.d.ts +17 -0
- package/src/commands/mcp/tools/onpush-zoneless-migration/analyze_for_unsupported_zone_uses.js +61 -0
- package/src/commands/mcp/tools/onpush-zoneless-migration/migrate_single_file.d.ts +12 -0
- package/src/commands/mcp/tools/onpush-zoneless-migration/migrate_single_file.js +72 -0
- package/src/commands/mcp/tools/onpush-zoneless-migration/migrate_test_file.d.ts +11 -0
- package/src/commands/mcp/tools/onpush-zoneless-migration/migrate_test_file.js +105 -0
- package/src/commands/mcp/tools/onpush-zoneless-migration/prompts.d.ts +15 -0
- package/src/commands/mcp/tools/onpush-zoneless-migration/prompts.js +236 -0
- package/src/commands/mcp/tools/onpush-zoneless-migration/send_debug_message.d.ts +10 -0
- package/src/commands/mcp/tools/onpush-zoneless-migration/send_debug_message.js +19 -0
- package/src/commands/mcp/tools/onpush-zoneless-migration/ts_utils.d.ts +36 -0
- package/src/commands/mcp/tools/onpush-zoneless-migration/ts_utils.js +135 -0
- package/src/commands/mcp/tools/onpush-zoneless-migration/types.d.ts +13 -0
- package/src/commands/mcp/tools/onpush-zoneless-migration/types.js +9 -0
- package/src/commands/mcp/tools/onpush-zoneless-migration/zoneless-migration.d.ts +14 -0
- package/src/commands/mcp/tools/onpush-zoneless-migration/zoneless-migration.js +205 -0
- package/src/commands/mcp/tools/projects.d.ts +47 -16
- package/src/commands/mcp/tools/projects.js +155 -30
- package/src/commands/mcp/tools/tool-registry.d.ts +2 -1
- package/src/commands/mcp/tools/tool-registry.js +3 -2
- package/src/utilities/package-manager.d.ts +12 -0
- package/src/utilities/package-manager.js +31 -22
- package/src/utilities/version.js +1 -1
|
@@ -0,0 +1,36 @@
|
|
|
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 type { ImportSpecifier, NodeArray, SourceFile } from 'typescript';
|
|
9
|
+
import type ts from 'typescript';
|
|
10
|
+
export declare function loadTypescript(): Promise<typeof ts>;
|
|
11
|
+
/**
|
|
12
|
+
* Gets a top-level import specifier with a specific name that is imported from a particular module.
|
|
13
|
+
* E.g. given a file that looks like:
|
|
14
|
+
*
|
|
15
|
+
* ```ts
|
|
16
|
+
* import { Component, Directive } from '@angular/core';
|
|
17
|
+
* import { Foo } from './foo';
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* Calling `getImportSpecifier(sourceFile, '@angular/core', 'Directive')` will yield the node
|
|
21
|
+
* referring to `Directive` in the top import.
|
|
22
|
+
*
|
|
23
|
+
* @param sourceFile File in which to look for imports.
|
|
24
|
+
* @param moduleName Name of the import's module.
|
|
25
|
+
* @param specifierName Original name of the specifier to look for. Aliases will be resolved to
|
|
26
|
+
* their original name.
|
|
27
|
+
*/
|
|
28
|
+
export declare function getImportSpecifier(sourceFile: SourceFile, moduleName: string | RegExp, specifierName: string): Promise<ImportSpecifier | null>;
|
|
29
|
+
/**
|
|
30
|
+
* Finds an import specifier with a particular name.
|
|
31
|
+
* @param nodes Array of import specifiers to search through.
|
|
32
|
+
* @param specifierName Name of the specifier to look for.
|
|
33
|
+
*/
|
|
34
|
+
export declare function findImportSpecifier(nodes: NodeArray<ImportSpecifier>, specifierName: string): ImportSpecifier | undefined;
|
|
35
|
+
/** Creates a TypeScript source file from a file path. */
|
|
36
|
+
export declare function createSourceFile(file: string): Promise<SourceFile>;
|
|
@@ -0,0 +1,135 @@
|
|
|
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.loadTypescript = loadTypescript;
|
|
44
|
+
exports.getImportSpecifier = getImportSpecifier;
|
|
45
|
+
exports.findImportSpecifier = findImportSpecifier;
|
|
46
|
+
exports.createSourceFile = createSourceFile;
|
|
47
|
+
const fs = __importStar(require("node:fs"));
|
|
48
|
+
let typescriptModule;
|
|
49
|
+
async function loadTypescript() {
|
|
50
|
+
return (typescriptModule ??= await Promise.resolve().then(() => __importStar(require('typescript'))));
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Gets a top-level import specifier with a specific name that is imported from a particular module.
|
|
54
|
+
* E.g. given a file that looks like:
|
|
55
|
+
*
|
|
56
|
+
* ```ts
|
|
57
|
+
* import { Component, Directive } from '@angular/core';
|
|
58
|
+
* import { Foo } from './foo';
|
|
59
|
+
* ```
|
|
60
|
+
*
|
|
61
|
+
* Calling `getImportSpecifier(sourceFile, '@angular/core', 'Directive')` will yield the node
|
|
62
|
+
* referring to `Directive` in the top import.
|
|
63
|
+
*
|
|
64
|
+
* @param sourceFile File in which to look for imports.
|
|
65
|
+
* @param moduleName Name of the import's module.
|
|
66
|
+
* @param specifierName Original name of the specifier to look for. Aliases will be resolved to
|
|
67
|
+
* their original name.
|
|
68
|
+
*/
|
|
69
|
+
async function getImportSpecifier(sourceFile, moduleName, specifierName) {
|
|
70
|
+
return (getImportSpecifiers(sourceFile, moduleName, specifierName, await loadTypescript())[0] ?? null);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Gets top-level import specifiers with specific names that are imported from a particular module.
|
|
74
|
+
* E.g. given a file that looks like:
|
|
75
|
+
*
|
|
76
|
+
* ```ts
|
|
77
|
+
* import { Component, Directive } from '@angular/core';
|
|
78
|
+
* import { Foo } from './foo';
|
|
79
|
+
* ```
|
|
80
|
+
*
|
|
81
|
+
* Calling `getImportSpecifiers(sourceFile, '@angular/core', ['Directive', 'Component'])` will
|
|
82
|
+
* yield the nodes referring to `Directive` and `Component` in the top import.
|
|
83
|
+
*
|
|
84
|
+
* @param sourceFile File in which to look for imports.
|
|
85
|
+
* @param moduleName Name of the import's module.
|
|
86
|
+
* @param specifierOrSpecifiers Original name of the specifier to look for, or an array of such
|
|
87
|
+
* names. Aliases will be resolved to their original name.
|
|
88
|
+
*/
|
|
89
|
+
function getImportSpecifiers(sourceFile, moduleName, specifierOrSpecifiers, { isNamedImports, isImportDeclaration, isStringLiteral }) {
|
|
90
|
+
const matches = [];
|
|
91
|
+
for (const node of sourceFile.statements) {
|
|
92
|
+
if (!isImportDeclaration(node) || !isStringLiteral(node.moduleSpecifier)) {
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
const namedBindings = node.importClause?.namedBindings;
|
|
96
|
+
const isMatch = typeof moduleName === 'string'
|
|
97
|
+
? node.moduleSpecifier.text === moduleName
|
|
98
|
+
: moduleName.test(node.moduleSpecifier.text);
|
|
99
|
+
if (!isMatch || !namedBindings || !isNamedImports(namedBindings)) {
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
if (typeof specifierOrSpecifiers === 'string') {
|
|
103
|
+
const match = findImportSpecifier(namedBindings.elements, specifierOrSpecifiers);
|
|
104
|
+
if (match) {
|
|
105
|
+
matches.push(match);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
for (const specifierName of specifierOrSpecifiers) {
|
|
110
|
+
const match = findImportSpecifier(namedBindings.elements, specifierName);
|
|
111
|
+
if (match) {
|
|
112
|
+
matches.push(match);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return matches;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Finds an import specifier with a particular name.
|
|
121
|
+
* @param nodes Array of import specifiers to search through.
|
|
122
|
+
* @param specifierName Name of the specifier to look for.
|
|
123
|
+
*/
|
|
124
|
+
function findImportSpecifier(nodes, specifierName) {
|
|
125
|
+
return nodes.find((element) => {
|
|
126
|
+
const { name, propertyName } = element;
|
|
127
|
+
return propertyName ? propertyName.text === specifierName : name.text === specifierName;
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
/** Creates a TypeScript source file from a file path. */
|
|
131
|
+
async function createSourceFile(file) {
|
|
132
|
+
const content = fs.readFileSync(file, 'utf8');
|
|
133
|
+
const ts = await loadTypescript();
|
|
134
|
+
return ts.createSourceFile(file, content, ts.ScriptTarget.Latest, true);
|
|
135
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
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
|
+
export type MigrationResponse = {
|
|
9
|
+
content: {
|
|
10
|
+
type: 'text';
|
|
11
|
+
text: string;
|
|
12
|
+
}[];
|
|
13
|
+
};
|
|
@@ -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
|
+
}
|
|
@@ -7,23 +7,54 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import z from 'zod';
|
|
9
9
|
export declare const LIST_PROJECTS_TOOL: import("./tool-registry").McpToolDeclaration<z.ZodRawShape, {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
10
|
+
workspaces: z.ZodArray<z.ZodObject<{
|
|
11
|
+
path: z.ZodString;
|
|
12
|
+
projects: z.ZodArray<z.ZodObject<{
|
|
13
|
+
name: z.ZodString;
|
|
14
|
+
type: z.ZodOptional<z.ZodEnum<["application", "library"]>>;
|
|
15
|
+
root: z.ZodString;
|
|
16
|
+
sourceRoot: z.ZodString;
|
|
17
|
+
selectorPrefix: z.ZodOptional<z.ZodString>;
|
|
18
|
+
}, "strip", z.ZodTypeAny, {
|
|
19
|
+
name: string;
|
|
20
|
+
root: string;
|
|
21
|
+
sourceRoot: string;
|
|
22
|
+
type?: "application" | "library" | undefined;
|
|
23
|
+
selectorPrefix?: string | undefined;
|
|
24
|
+
}, {
|
|
25
|
+
name: string;
|
|
26
|
+
root: string;
|
|
27
|
+
sourceRoot: string;
|
|
28
|
+
type?: "application" | "library" | undefined;
|
|
29
|
+
selectorPrefix?: string | undefined;
|
|
30
|
+
}>, "many">;
|
|
16
31
|
}, "strip", z.ZodTypeAny, {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
32
|
+
path: string;
|
|
33
|
+
projects: {
|
|
34
|
+
name: string;
|
|
35
|
+
root: string;
|
|
36
|
+
sourceRoot: string;
|
|
37
|
+
type?: "application" | "library" | undefined;
|
|
38
|
+
selectorPrefix?: string | undefined;
|
|
39
|
+
}[];
|
|
22
40
|
}, {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
41
|
+
path: string;
|
|
42
|
+
projects: {
|
|
43
|
+
name: string;
|
|
44
|
+
root: string;
|
|
45
|
+
sourceRoot: string;
|
|
46
|
+
type?: "application" | "library" | undefined;
|
|
47
|
+
selectorPrefix?: string | undefined;
|
|
48
|
+
}[];
|
|
28
49
|
}>, "many">;
|
|
50
|
+
parsingErrors: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
51
|
+
filePath: z.ZodString;
|
|
52
|
+
message: z.ZodString;
|
|
53
|
+
}, "strip", z.ZodTypeAny, {
|
|
54
|
+
message: string;
|
|
55
|
+
filePath: string;
|
|
56
|
+
}, {
|
|
57
|
+
message: string;
|
|
58
|
+
filePath: string;
|
|
59
|
+
}>, "many">>;
|
|
29
60
|
}>;
|