@angular/cli 21.0.0-next.0 → 21.0.0-next.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 (43) hide show
  1. package/lib/code-examples.db +0 -0
  2. package/lib/config/schema.json +37 -5
  3. package/lib/config/workspace-schema.d.ts +41 -2
  4. package/lib/config/workspace-schema.js +13 -2
  5. package/package.json +19 -19
  6. package/src/command-builder/architect-command-module.js +11 -5
  7. package/src/command-builder/schematics-command-module.js +7 -2
  8. package/src/command-builder/utilities/json-schema.js +5 -1
  9. package/src/command-builder/utilities/schematic-engine-host.js +4 -6
  10. package/src/commands/add/cli.d.ts +2 -1
  11. package/src/commands/add/cli.js +178 -94
  12. package/src/commands/mcp/mcp-server.d.ts +12 -2
  13. package/src/commands/mcp/mcp-server.js +6 -1
  14. package/src/commands/mcp/tools/best-practices.js +15 -5
  15. package/src/commands/mcp/tools/doc-search.d.ts +18 -1
  16. package/src/commands/mcp/tools/doc-search.js +94 -37
  17. package/src/commands/mcp/tools/examples.d.ts +9 -1
  18. package/src/commands/mcp/tools/examples.js +38 -12
  19. package/src/commands/mcp/tools/modernize.js +28 -27
  20. package/src/commands/mcp/tools/onpush-zoneless-migration/analyze_for_unsupported_zone_uses.d.ts +17 -0
  21. package/src/commands/mcp/tools/onpush-zoneless-migration/analyze_for_unsupported_zone_uses.js +61 -0
  22. package/src/commands/mcp/tools/onpush-zoneless-migration/migrate_single_file.d.ts +12 -0
  23. package/src/commands/mcp/tools/onpush-zoneless-migration/migrate_single_file.js +72 -0
  24. package/src/commands/mcp/tools/onpush-zoneless-migration/migrate_test_file.d.ts +11 -0
  25. package/src/commands/mcp/tools/onpush-zoneless-migration/migrate_test_file.js +105 -0
  26. package/src/commands/mcp/tools/onpush-zoneless-migration/prompts.d.ts +15 -0
  27. package/src/commands/mcp/tools/onpush-zoneless-migration/prompts.js +236 -0
  28. package/src/commands/mcp/tools/onpush-zoneless-migration/send_debug_message.d.ts +10 -0
  29. package/src/commands/mcp/tools/onpush-zoneless-migration/send_debug_message.js +19 -0
  30. package/src/commands/mcp/tools/onpush-zoneless-migration/ts_utils.d.ts +36 -0
  31. package/src/commands/mcp/tools/onpush-zoneless-migration/ts_utils.js +135 -0
  32. package/src/commands/mcp/tools/onpush-zoneless-migration/types.d.ts +13 -0
  33. package/src/commands/mcp/tools/onpush-zoneless-migration/types.js +9 -0
  34. package/src/commands/mcp/tools/onpush-zoneless-migration/zoneless-migration.d.ts +14 -0
  35. package/src/commands/mcp/tools/onpush-zoneless-migration/zoneless-migration.js +205 -0
  36. package/src/commands/mcp/tools/projects.d.ts +47 -16
  37. package/src/commands/mcp/tools/projects.js +155 -30
  38. package/src/commands/mcp/tools/tool-registry.d.ts +2 -1
  39. package/src/commands/mcp/tools/tool-registry.js +3 -2
  40. package/src/commands/update/schematic/schema.d.ts +0 -1
  41. package/src/commands/update/schematic/schema.js +0 -1
  42. package/src/commands/update/schematic/schema.json +1 -1
  43. package/src/utilities/version.js +1 -1
@@ -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
- projects: z.ZodArray<z.ZodObject<{
11
- name: z.ZodString;
12
- type: z.ZodOptional<z.ZodEnum<["application", "library"]>>;
13
- root: z.ZodString;
14
- sourceRoot: z.ZodString;
15
- selectorPrefix: z.ZodOptional<z.ZodString>;
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
- name: string;
18
- root: string;
19
- sourceRoot: string;
20
- type?: "application" | "library" | undefined;
21
- selectorPrefix?: string | undefined;
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
- name: string;
24
- root: string;
25
- sourceRoot: string;
26
- type?: "application" | "library" | undefined;
27
- selectorPrefix?: string | undefined;
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
  }>;
@@ -11,15 +11,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
11
11
  };
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
13
  exports.LIST_PROJECTS_TOOL = void 0;
14
+ const promises_1 = require("node:fs/promises");
14
15
  const node_path_1 = __importDefault(require("node:path"));
16
+ const node_url_1 = require("node:url");
15
17
  const zod_1 = __importDefault(require("zod"));
18
+ const config_1 = require("../../../utilities/config");
19
+ const error_1 = require("../../../utilities/error");
16
20
  const tool_registry_1 = require("./tool-registry");
17
- exports.LIST_PROJECTS_TOOL = (0, tool_registry_1.declareTool)({
18
- name: 'list_projects',
19
- title: 'List Angular Projects',
20
- description: 'Lists the names of all applications and libraries defined within an Angular workspace. ' +
21
- 'It reads the `angular.json` configuration file to identify the projects. ',
22
- outputSchema: {
21
+ const listProjectsOutputSchema = {
22
+ workspaces: zod_1.default.array(zod_1.default.object({
23
+ path: zod_1.default.string().describe('The path to the `angular.json` file for this workspace.'),
23
24
  projects: zod_1.default.array(zod_1.default.object({
24
25
  name: zod_1.default
25
26
  .string()
@@ -40,15 +41,152 @@ exports.LIST_PROJECTS_TOOL = (0, tool_registry_1.declareTool)({
40
41
  .describe('The prefix to use for component selectors.' +
41
42
  ` For example, a prefix of 'app' would result in selectors like '<app-my-component>'.`),
42
43
  })),
43
- },
44
+ })),
45
+ parsingErrors: zod_1.default
46
+ .array(zod_1.default.object({
47
+ filePath: zod_1.default.string().describe('The path to the file that could not be parsed.'),
48
+ message: zod_1.default.string().describe('The error message detailing why parsing failed.'),
49
+ }))
50
+ .default([])
51
+ .describe('A list of files that looked like workspaces but failed to parse.'),
52
+ };
53
+ exports.LIST_PROJECTS_TOOL = (0, tool_registry_1.declareTool)({
54
+ name: 'list_projects',
55
+ title: 'List Angular Projects',
56
+ description: `
57
+ <Purpose>
58
+ Provides a comprehensive overview of all Angular workspaces and projects within a monorepo.
59
+ It is essential to use this tool as a first step before performing any project-specific actions to understand the available projects,
60
+ their types, and their locations.
61
+ </Purpose>
62
+ <Use Cases>
63
+ * Finding the correct project name to use in other commands (e.g., \`ng generate component my-comp --project=my-app\`).
64
+ * Identifying the \`root\` and \`sourceRoot\` of a project to read, analyze, or modify its files.
65
+ * Determining if a project is an \`application\` or a \`library\`.
66
+ * Getting the \`selectorPrefix\` for a project before generating a new component to ensure it follows conventions.
67
+ </Use Cases>
68
+ <Operational Notes>
69
+ * **Working Directory:** Shell commands for a project (like \`ng generate\`) **MUST**
70
+ be executed from the parent directory of the \`path\` field for the relevant workspace.
71
+ * **Disambiguation:** A monorepo may contain multiple workspaces (e.g., for different applications or even in output directories).
72
+ Use the \`path\` of each workspace to understand its context and choose the correct project.
73
+ </Operational Notes>`,
74
+ outputSchema: listProjectsOutputSchema,
44
75
  isReadOnly: true,
45
76
  isLocalOnly: true,
46
- shouldRegister: (context) => !!context.workspace,
47
77
  factory: createListProjectsHandler,
48
78
  });
49
- function createListProjectsHandler({ workspace }) {
79
+ const EXCLUDED_DIRS = new Set(['node_modules', 'dist', 'out', 'coverage']);
80
+ /**
81
+ * Iteratively finds all 'angular.json' files with controlled concurrency and directory exclusions.
82
+ * This non-recursive implementation is suitable for very large directory trees
83
+ * and prevents file descriptor exhaustion (`EMFILE` errors).
84
+ * @param rootDir The directory to start the search from.
85
+ * @returns An async generator that yields the full path of each found 'angular.json' file.
86
+ */
87
+ async function* findAngularJsonFiles(rootDir) {
88
+ const CONCURRENCY_LIMIT = 50;
89
+ const queue = [rootDir];
90
+ while (queue.length > 0) {
91
+ const batch = queue.splice(0, CONCURRENCY_LIMIT);
92
+ const foundFilesInBatch = [];
93
+ const promises = batch.map(async (dir) => {
94
+ try {
95
+ const entries = await (0, promises_1.readdir)(dir, { withFileTypes: true });
96
+ const subdirectories = [];
97
+ for (const entry of entries) {
98
+ const fullPath = node_path_1.default.join(dir, entry.name);
99
+ if (entry.isDirectory()) {
100
+ // Exclude dot-directories, build/cache directories, and node_modules
101
+ if (entry.name.startsWith('.') || EXCLUDED_DIRS.has(entry.name)) {
102
+ continue;
103
+ }
104
+ subdirectories.push(fullPath);
105
+ }
106
+ else if (entry.name === 'angular.json') {
107
+ foundFilesInBatch.push(fullPath);
108
+ }
109
+ }
110
+ return subdirectories;
111
+ }
112
+ catch (error) {
113
+ (0, error_1.assertIsError)(error);
114
+ if (error.code === 'EACCES' || error.code === 'EPERM') {
115
+ return []; // Silently ignore permission errors.
116
+ }
117
+ throw error;
118
+ }
119
+ });
120
+ const nestedSubdirs = await Promise.all(promises);
121
+ queue.push(...nestedSubdirs.flat());
122
+ yield* foundFilesInBatch;
123
+ }
124
+ }
125
+ /**
126
+ * Loads, parses, and transforms a single angular.json file into the tool's output format.
127
+ * It checks a set of seen paths to avoid processing the same workspace multiple times.
128
+ * @param configFile The path to the angular.json file.
129
+ * @param seenPaths A Set of absolute paths that have already been processed.
130
+ * @returns A promise resolving to the workspace data or a parsing error.
131
+ */
132
+ async function loadAndParseWorkspace(configFile, seenPaths) {
133
+ try {
134
+ const resolvedPath = node_path_1.default.resolve(configFile);
135
+ if (seenPaths.has(resolvedPath)) {
136
+ return { workspace: null, error: null }; // Already processed, skip.
137
+ }
138
+ seenPaths.add(resolvedPath);
139
+ const ws = await config_1.AngularWorkspace.load(configFile);
140
+ const projects = [];
141
+ for (const [name, project] of ws.projects.entries()) {
142
+ projects.push({
143
+ name,
144
+ type: project.extensions['projectType'],
145
+ root: project.root,
146
+ sourceRoot: project.sourceRoot ?? node_path_1.default.posix.join(project.root, 'src'),
147
+ selectorPrefix: project.extensions['prefix'],
148
+ });
149
+ }
150
+ return { workspace: { path: configFile, projects }, error: null };
151
+ }
152
+ catch (error) {
153
+ let message;
154
+ if (error instanceof Error) {
155
+ message = error.message;
156
+ }
157
+ else {
158
+ message = 'An unknown error occurred while parsing the file.';
159
+ }
160
+ return { workspace: null, error: { filePath: configFile, message } };
161
+ }
162
+ }
163
+ async function createListProjectsHandler({ server }) {
50
164
  return async () => {
51
- if (!workspace) {
165
+ const workspaces = [];
166
+ const parsingErrors = [];
167
+ const seenPaths = new Set();
168
+ let searchRoots;
169
+ const clientCapabilities = server.server.getClientCapabilities();
170
+ if (clientCapabilities?.roots) {
171
+ const { roots } = await server.server.listRoots();
172
+ searchRoots = roots?.map((r) => node_path_1.default.normalize((0, node_url_1.fileURLToPath)(r.uri))) ?? [];
173
+ }
174
+ else {
175
+ // Fallback to the current working directory if client does not support roots
176
+ searchRoots = [process.cwd()];
177
+ }
178
+ for (const root of searchRoots) {
179
+ for await (const configFile of findAngularJsonFiles(root)) {
180
+ const { workspace, error } = await loadAndParseWorkspace(configFile, seenPaths);
181
+ if (workspace) {
182
+ workspaces.push(workspace);
183
+ }
184
+ if (error) {
185
+ parsingErrors.push(error);
186
+ }
187
+ }
188
+ }
189
+ if (workspaces.length === 0 && parsingErrors.length === 0) {
52
190
  return {
53
191
  content: [
54
192
  {
@@ -58,30 +196,17 @@ function createListProjectsHandler({ workspace }) {
58
196
  ' could not be located in the current directory or any of its parent directories.',
59
197
  },
60
198
  ],
61
- structuredContent: { projects: [] },
199
+ structuredContent: { workspaces: [] },
62
200
  };
63
201
  }
64
- const projects = [];
65
- // Convert to output format
66
- for (const [name, project] of workspace.projects.entries()) {
67
- projects.push({
68
- name,
69
- type: project.extensions['projectType'],
70
- root: project.root,
71
- sourceRoot: project.sourceRoot ?? node_path_1.default.posix.join(project.root, 'src'),
72
- selectorPrefix: project.extensions['prefix'],
73
- });
202
+ let text = `Found ${workspaces.length} workspace(s).\n${JSON.stringify({ workspaces })}`;
203
+ if (parsingErrors.length > 0) {
204
+ text += `\n\nWarning: The following ${parsingErrors.length} file(s) could not be parsed and were skipped:\n`;
205
+ text += parsingErrors.map((e) => `- ${e.filePath}: ${e.message}`).join('\n');
74
206
  }
75
- // The structuredContent field is newer and may not be supported by all hosts.
76
- // A text representation of the content is also provided for compatibility.
77
207
  return {
78
- content: [
79
- {
80
- type: 'text',
81
- text: `Projects in the Angular workspace:\n${JSON.stringify(projects)}`,
82
- },
83
- ],
84
- structuredContent: { projects },
208
+ content: [{ type: 'text', text }],
209
+ structuredContent: { workspaces, parsingErrors },
85
210
  };
86
211
  };
87
212
  }
@@ -10,6 +10,7 @@ import { ZodRawShape } from 'zod';
10
10
  import type { AngularWorkspace } from '../../../utilities/config';
11
11
  type ToolConfig = Parameters<McpServer['registerTool']>[1];
12
12
  export interface McpToolContext {
13
+ server: McpServer;
13
14
  workspace?: AngularWorkspace;
14
15
  logger: {
15
16
  warn(text: string): void;
@@ -31,5 +32,5 @@ export interface McpToolDeclaration<TInput extends ZodRawShape, TOutput extends
31
32
  }
32
33
  export type AnyMcpToolDeclaration = McpToolDeclaration<any, any>;
33
34
  export declare function declareTool<TInput extends ZodRawShape, TOutput extends ZodRawShape>(declaration: McpToolDeclaration<TInput, TOutput>): McpToolDeclaration<TInput, TOutput>;
34
- export declare function registerTools(server: McpServer, context: McpToolContext, declarations: AnyMcpToolDeclaration[]): Promise<void>;
35
+ export declare function registerTools(server: McpServer, context: Omit<McpToolContext, 'server'>, declarations: AnyMcpToolDeclaration[]): Promise<void>;
35
36
  export {};
@@ -14,11 +14,12 @@ function declareTool(declaration) {
14
14
  }
15
15
  async function registerTools(server, context, declarations) {
16
16
  for (const declaration of declarations) {
17
- if (declaration.shouldRegister && !(await declaration.shouldRegister(context))) {
17
+ const toolContext = { ...context, server };
18
+ if (declaration.shouldRegister && !(await declaration.shouldRegister(toolContext))) {
18
19
  continue;
19
20
  }
20
21
  const { name, factory, shouldRegister, isReadOnly, isLocalOnly, ...config } = declaration;
21
- const handler = await factory(context);
22
+ const handler = await factory(toolContext);
22
23
  // Add declarative characteristics to annotations
23
24
  config.annotations ??= {};
24
25
  if (isReadOnly !== undefined) {
@@ -45,7 +45,6 @@ export type Schema = {
45
45
  */
46
46
  export declare enum PackageManager {
47
47
  Bun = "bun",
48
- Cnpm = "cnpm",
49
48
  Npm = "npm",
50
49
  Pnpm = "pnpm",
51
50
  Yarn = "yarn"
@@ -9,7 +9,6 @@ exports.PackageManager = void 0;
9
9
  var PackageManager;
10
10
  (function (PackageManager) {
11
11
  PackageManager["Bun"] = "bun";
12
- PackageManager["Cnpm"] = "cnpm";
13
12
  PackageManager["Npm"] = "npm";
14
13
  PackageManager["Pnpm"] = "pnpm";
15
14
  PackageManager["Yarn"] = "yarn";
@@ -57,7 +57,7 @@
57
57
  "description": "The preferred package manager configuration files to use for registry settings.",
58
58
  "type": "string",
59
59
  "default": "npm",
60
- "enum": ["npm", "yarn", "cnpm", "pnpm", "bun"]
60
+ "enum": ["npm", "yarn", "pnpm", "bun"]
61
61
  }
62
62
  },
63
63
  "required": []
@@ -22,4 +22,4 @@ class Version {
22
22
  this.patch = patch;
23
23
  }
24
24
  }
25
- exports.VERSION = new Version('21.0.0-next.0');
25
+ exports.VERSION = new Version('21.0.0-next.2');