@expo/cli 55.0.30 → 55.0.31
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/build/bin/cli +1 -1
- package/build/src/events/index.js +1 -1
- package/build/src/export/embed/exportEmbedAsync.js +1 -1
- package/build/src/export/embed/exportEmbedAsync.js.map +1 -1
- package/build/src/export/embed/exportServer.js +1 -1
- package/build/src/export/embed/exportServer.js.map +1 -1
- package/build/src/export/exportApp.js +1 -1
- package/build/src/export/exportApp.js.map +1 -1
- package/build/src/export/publicFolder.js +19 -1
- package/build/src/export/publicFolder.js.map +1 -1
- package/build/src/run/android/resolveLaunchProps.js +4 -1
- package/build/src/run/android/resolveLaunchProps.js.map +1 -1
- package/build/src/start/server/DevToolsPlugin.js +26 -1
- package/build/src/start/server/DevToolsPlugin.js.map +1 -1
- package/build/src/start/server/DevToolsPluginCliExtensionExecutor.js +57 -22
- package/build/src/start/server/DevToolsPluginCliExtensionExecutor.js.map +1 -1
- package/build/src/start/server/DevToolsPluginCliExtensionResults.js +29 -0
- package/build/src/start/server/DevToolsPluginCliExtensionResults.js.map +1 -1
- package/build/src/start/server/MCPDevToolsPluginCLIExtensions.js +15 -5
- package/build/src/start/server/MCPDevToolsPluginCLIExtensions.js.map +1 -1
- package/build/src/start/server/createMCPDevToolsExtensionSchema.js +13 -1
- package/build/src/start/server/createMCPDevToolsExtensionSchema.js.map +1 -1
- package/build/src/start/server/metro/createServerComponentsMiddleware.js +5 -12
- package/build/src/start/server/metro/createServerComponentsMiddleware.js.map +1 -1
- package/build/src/start/server/metro/dev-server/createMessageSocket.js +13 -2
- package/build/src/start/server/metro/dev-server/createMessageSocket.js.map +1 -1
- package/build/src/start/server/metro/dev-server/createMetroMiddleware.js +2 -1
- package/build/src/start/server/metro/dev-server/createMetroMiddleware.js.map +1 -1
- package/build/src/start/server/metro/instantiateMetro.js +5 -4
- package/build/src/start/server/metro/instantiateMetro.js.map +1 -1
- package/build/src/start/server/metro/router.js +10 -1
- package/build/src/start/server/metro/router.js.map +1 -1
- package/build/src/start/server/middleware/ServeStaticMiddleware.js +2 -9
- package/build/src/start/server/middleware/ServeStaticMiddleware.js.map +1 -1
- package/build/src/start/server/webTemplate.js +3 -5
- package/build/src/start/server/webTemplate.js.map +1 -1
- package/build/src/utils/tar.js +2 -2
- package/build/src/utils/tar.js.map +1 -1
- package/build/src/utils/telemetry/clients/FetchClient.js +1 -1
- package/build/src/utils/telemetry/utils/context.js +1 -1
- package/package.json +5 -5
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/start/server/DevToolsPlugin.ts"],"sourcesContent":["import { DevToolsPluginInfo, PluginSchema } from './DevToolsPlugin.schema';\nimport { DevToolsPluginCliExtensionExecutor } from './DevToolsPluginCliExtensionExecutor';\nimport { DevToolsPluginEndpoint } from './DevToolsPluginManager';\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../../src/start/server/DevToolsPlugin.ts"],"sourcesContent":["import fs from 'node:fs';\n\nimport { DevToolsPluginInfo, PluginSchema } from './DevToolsPlugin.schema';\nimport { DevToolsPluginCliExtensionExecutor } from './DevToolsPluginCliExtensionExecutor';\nimport { DevToolsPluginEndpoint } from './DevToolsPluginManager';\nimport { isPathInside } from '../../utils/dir';\n\nconst maybeRealpath = (target: string): string => {\n try {\n return fs.realpathSync(target);\n } catch {\n return target;\n }\n};\n\n/**\n * Class that represents a DevTools plugin with CLI and/or web extensions\n *\n * Responsibilities:\n * - Validates plugin configuration against schema\n * - Provides access to plugin metadata (name, description\n * , endpoints)\n * - Manages CLI command execution via DevToolsPluginExecutor\n * - Lazily initializes executor when needed\n * - Constructs web endpoint URLs based on server configuration\n */\nexport class DevToolsPlugin {\n constructor(\n private plugin: DevToolsPluginInfo,\n public readonly projectRoot: string\n ) {\n const result = PluginSchema.safeParse(plugin);\n if (!result.success) {\n throw new Error(`Invalid plugin configuration: ${result.error.message}`, {\n cause: result.error,\n });\n }\n\n if (plugin.webpageRoot != null) {\n const webpageRoot = maybeRealpath(plugin.webpageRoot);\n if (!isPathInside(webpageRoot, plugin.packageRoot)) {\n throw new Error(\n `webpageRoot (${plugin.webpageRoot}) is not inside packageRoot (${plugin.packageRoot}).`\n );\n }\n }\n }\n\n private _executor: DevToolsPluginCliExtensionExecutor | undefined = undefined;\n\n get packageName(): string {\n return this.plugin.packageName;\n }\n\n get packageRoot(): string {\n return this.plugin.packageRoot;\n }\n\n get webpageEndpoint(): string | undefined {\n return this.plugin?.webpageRoot\n ? `${DevToolsPluginEndpoint}/${this.plugin?.packageName}`\n : undefined;\n }\n\n get webpageRoot(): string | undefined {\n return this.plugin?.webpageRoot;\n }\n\n get description(): string {\n return this.plugin.cliExtensions?.description ?? '';\n }\n\n get cliExtensions(): DevToolsPluginInfo['cliExtensions'] {\n return this.plugin.cliExtensions;\n }\n\n get executor(): DevToolsPluginCliExtensionExecutor | undefined {\n if (!this.plugin.cliExtensions?.entryPoint) {\n return undefined;\n }\n\n if (!this._executor) {\n this._executor = new DevToolsPluginCliExtensionExecutor(this.plugin, this.projectRoot);\n }\n\n return this._executor;\n }\n}\n"],"names":["DevToolsPlugin","maybeRealpath","target","fs","realpathSync","constructor","plugin","projectRoot","_executor","undefined","result","PluginSchema","safeParse","success","Error","error","message","cause","webpageRoot","isPathInside","packageRoot","packageName","webpageEndpoint","DevToolsPluginEndpoint","description","cliExtensions","executor","entryPoint","DevToolsPluginCliExtensionExecutor"],"mappings":";;;;+BA0BaA;;;eAAAA;;;;gEA1BE;;;;;;sCAEkC;oDACE;uCACZ;qBACV;;;;;;AAE7B,MAAMC,gBAAgB,CAACC;IACrB,IAAI;QACF,OAAOC,iBAAE,CAACC,YAAY,CAACF;IACzB,EAAE,OAAM;QACN,OAAOA;IACT;AACF;AAaO,MAAMF;IACXK,YACE,AAAQC,MAA0B,EAClC,AAAgBC,WAAmB,CACnC;aAFQD,SAAAA;aACQC,cAAAA;aAmBVC,YAA4DC;QAjBlE,MAAMC,SAASC,kCAA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AC,IAAI,CAACD,SAAS,EAAE;YACnB,IAAI,CAACA,SAAS,GAAG,IAAIoB,sEAAkC,CAAC,IAAI,CAACtB,MAAM,EAAE,IAAI,CAACC,WAAW;QACvF;QAEA,OAAO,IAAI,CAACC,SAAS;IACvB;AACF"}
|
|
@@ -23,6 +23,7 @@ function _path() {
|
|
|
23
23
|
return data;
|
|
24
24
|
}
|
|
25
25
|
const _DevToolsPluginCliExtensionResults = require("./DevToolsPluginCliExtensionResults");
|
|
26
|
+
const _dir = require("../../utils/dir");
|
|
26
27
|
function _interop_require_default(obj) {
|
|
27
28
|
return obj && obj.__esModule ? obj : {
|
|
28
29
|
default: obj
|
|
@@ -45,27 +46,50 @@ class DevToolsPluginCliExtensionExecutor {
|
|
|
45
46
|
command,
|
|
46
47
|
args
|
|
47
48
|
});
|
|
48
|
-
return new Promise(
|
|
49
|
-
// Set up the command and its arguments
|
|
50
|
-
const tool = _path().default.join(this.plugin.packageRoot, this.plugin.cliExtensions.entryPoint);
|
|
51
|
-
const child = this.spawnFunc('node', [
|
|
52
|
-
tool,
|
|
53
|
-
command,
|
|
54
|
-
`${JSON.stringify(args)}`,
|
|
55
|
-
`${metroServerOrigin}`
|
|
56
|
-
], {
|
|
57
|
-
cwd: this.projectRoot,
|
|
58
|
-
env: {
|
|
59
|
-
...process.env
|
|
60
|
-
}
|
|
61
|
-
});
|
|
49
|
+
return new Promise((resolve)=>{
|
|
62
50
|
let finished = false;
|
|
51
|
+
let timeout;
|
|
63
52
|
const pluginResults = new _DevToolsPluginCliExtensionResults.DevToolsPluginCliExtensionResults(onOutput);
|
|
53
|
+
// process.execPath instead of 'node' so the child can't be redirected by a PATH shim.
|
|
54
|
+
let child;
|
|
55
|
+
try {
|
|
56
|
+
child = this.spawnFunc(process.execPath, [
|
|
57
|
+
this.resolvedEntryPoint,
|
|
58
|
+
command,
|
|
59
|
+
`${JSON.stringify(args)}`,
|
|
60
|
+
`${metroServerOrigin}`
|
|
61
|
+
], {
|
|
62
|
+
cwd: this.projectRoot,
|
|
63
|
+
env: {
|
|
64
|
+
...process.env
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
} catch (err) {
|
|
68
|
+
var _err_toString;
|
|
69
|
+
// spawn can throw synchronously; resolve with an error result instead of hanging.
|
|
70
|
+
pluginResults.append((err == null ? void 0 : (_err_toString = err.toString) == null ? void 0 : _err_toString.call(err)) ?? String(err), 'error');
|
|
71
|
+
resolve(pluginResults.getOutput());
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
const finishOnTruncation = ()=>{
|
|
75
|
+
if (pluginResults.isTruncated() && !finished) {
|
|
76
|
+
finished = true;
|
|
77
|
+
if (timeout) clearTimeout(timeout);
|
|
78
|
+
child.kill('SIGKILL');
|
|
79
|
+
resolve(pluginResults.getOutput());
|
|
80
|
+
}
|
|
81
|
+
};
|
|
64
82
|
// Collect output/error data
|
|
65
|
-
child.stdout.on('data', (data)=>
|
|
66
|
-
|
|
83
|
+
child.stdout.on('data', (data)=>{
|
|
84
|
+
pluginResults.append(data.toString());
|
|
85
|
+
finishOnTruncation();
|
|
86
|
+
});
|
|
87
|
+
child.stderr.on('data', (data)=>{
|
|
88
|
+
pluginResults.append(data.toString(), 'error');
|
|
89
|
+
finishOnTruncation();
|
|
90
|
+
});
|
|
67
91
|
// Setup timeout
|
|
68
|
-
|
|
92
|
+
timeout = setTimeout(()=>{
|
|
69
93
|
if (!finished) {
|
|
70
94
|
finished = true;
|
|
71
95
|
child.kill('SIGKILL');
|
|
@@ -75,14 +99,14 @@ class DevToolsPluginCliExtensionExecutor {
|
|
|
75
99
|
}, this.timeoutMs);
|
|
76
100
|
child.on('close', (code)=>{
|
|
77
101
|
if (finished) return;
|
|
78
|
-
clearTimeout(timeout);
|
|
102
|
+
if (timeout) clearTimeout(timeout);
|
|
79
103
|
finished = true;
|
|
80
104
|
pluginResults.exit(code);
|
|
81
105
|
resolve(pluginResults.getOutput());
|
|
82
106
|
});
|
|
83
107
|
child.on('error', (err)=>{
|
|
84
108
|
if (finished) return;
|
|
85
|
-
clearTimeout(timeout);
|
|
109
|
+
if (timeout) clearTimeout(timeout);
|
|
86
110
|
finished = true;
|
|
87
111
|
pluginResults.append(err.toString(), 'error');
|
|
88
112
|
resolve(pluginResults.getOutput());
|
|
@@ -93,6 +117,12 @@ class DevToolsPluginCliExtensionExecutor {
|
|
|
93
117
|
if (!((_this_plugin_cliExtensions = this.plugin.cliExtensions) == null ? void 0 : _this_plugin_cliExtensions.entryPoint)) {
|
|
94
118
|
throw new Error(`Plugin ${this.plugin.packageName} has no CLI extensions`);
|
|
95
119
|
}
|
|
120
|
+
// Reject entryPoints that escape packageRoot (e.g. "../../other-pkg/dist/cli.js").
|
|
121
|
+
const resolved = _path().default.resolve(this.plugin.packageRoot, this.plugin.cliExtensions.entryPoint);
|
|
122
|
+
if (!(0, _dir.isPathInside)(resolved, this.plugin.packageRoot)) {
|
|
123
|
+
throw new Error(`Plugin ${this.plugin.packageName} entryPoint "${this.plugin.cliExtensions.entryPoint}" ` + `escapes packageRoot (${this.plugin.packageRoot}); must be a relative path inside the package.`);
|
|
124
|
+
}
|
|
125
|
+
this.resolvedEntryPoint = resolved;
|
|
96
126
|
}
|
|
97
127
|
validate({ command, args }) {
|
|
98
128
|
var _this_plugin_cliExtensions, _commandElement_parameters;
|
|
@@ -106,12 +136,17 @@ class DevToolsPluginCliExtensionExecutor {
|
|
|
106
136
|
// Quick check to see if the lengths match
|
|
107
137
|
throw new Error(`Expected ${paramLength} parameter(s), but got ${argsLength} argument(s) for the command "${command}".`);
|
|
108
138
|
}
|
|
109
|
-
const
|
|
139
|
+
const argsObj = args ?? {};
|
|
110
140
|
for (const param of commandElement.parameters ?? []){
|
|
111
|
-
|
|
112
|
-
if (!found) {
|
|
141
|
+
if (!Object.prototype.hasOwnProperty.call(argsObj, param.name)) {
|
|
113
142
|
throw new Error(`Parameter "${param.name}" not found in command "${command}" of plugin ${this.plugin.packageName}`);
|
|
114
143
|
}
|
|
144
|
+
// Enforce declared parameter type; don't rely on upstream Zod validation alone.
|
|
145
|
+
const expected = param.type === 'confirm' ? 'boolean' : param.type === 'number' ? 'number' : 'string';
|
|
146
|
+
const actual = typeof argsObj[param.name];
|
|
147
|
+
if (actual !== expected) {
|
|
148
|
+
throw new Error(`Parameter "${param.name}" of "${command}" expected ${expected} (declared "${param.type}"), got ${actual}.`);
|
|
149
|
+
}
|
|
115
150
|
}
|
|
116
151
|
}
|
|
117
152
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/start/server/DevToolsPluginCliExtensionExecutor.ts"],"sourcesContent":["import { spawn } from 'child_process';\nimport path from 'path';\n\nimport {\n DevToolsPluginExecutorArguments,\n DevToolsPluginInfo,\n DevToolsPluginOutput,\n} from './DevToolsPlugin.schema';\nimport { DevToolsPluginCliExtensionResults } from './DevToolsPluginCliExtensionResults';\n\nconst DEFAULT_TIMEOUT_MS = 10_000; // 10 seconds\n\n/**\n * Class that executes CLI Extension commands for a given plugin\n *\n * ## Responsibilities:\n * - Verifies that requested commands exist and have correct parameters\n * - Validates that provided arguments match expected parameter schema\n * - Spawns and manages child processes for command execution\n * - Captures and streams stdout/stderr data from executed commands\n * - Manages process errors, timeouts, and unexpected failures\n * - Enforces execution time limits to prevent hanging processes\n * - Configures proper execution environment with color support\n * - Ensures proper cleanup of processes and timeouts\n * - Provides structured output with exit codes and error states\n */\nexport class DevToolsPluginCliExtensionExecutor {\n constructor(\n private plugin: DevToolsPluginInfo,\n private projectRoot: string,\n private spawnFunc: typeof spawn = spawn, // Used for injection when testing,\n private timeoutMs = DEFAULT_TIMEOUT_MS // Timeout for command execution\n ) {\n // Validate that this is a plugin with cli extensions\n if (!this.plugin.cliExtensions?.entryPoint) {\n throw new Error(`Plugin ${this.plugin.packageName} has no CLI extensions`);\n }\n }\n\n public validate({ command, args }: Omit<DevToolsPluginExecutorArguments, 'metroServerOrigin'>) {\n const commandElement = this.plugin.cliExtensions?.commands.find((c) => c.name === command);\n if (!commandElement) {\n throw new Error(`Command \"${command}\" not found in plugin ${this.plugin.packageName}`);\n }\n\n const paramLength = commandElement.parameters?.length ?? 0;\n const argsLength = Object.keys(args ?? {}).length;\n if (paramLength !== argsLength) {\n // Quick check to see if the lengths match\n throw new Error(\n `Expected ${paramLength} parameter(s), but got ${argsLength} argument(s) for the command \"${command}\".`\n );\n }\n\n const argsKeys = Object.keys(args ?? {});\n for (const param of commandElement.parameters ?? []) {\n const found = argsKeys.find((key) => key === param.name);\n if (!found) {\n throw new Error(\n `Parameter \"${param.name}\" not found in command \"${command}\" of plugin ${this.plugin.packageName}`\n );\n }\n }\n }\n\n /** this function is used for testing and showing the command in UI */\n public getCommandString = ({\n command,\n args,\n }: Omit<DevToolsPluginExecutorArguments, 'metroServerOrigin'>) => {\n return `node ${this.plugin.cliExtensions!.entryPoint} ${command}${Object.keys(args ?? {}).length > 0 ? ' ' + JSON.stringify(args) : ''}`;\n };\n\n public execute = async ({\n command,\n args,\n metroServerOrigin,\n onOutput,\n }: DevToolsPluginExecutorArguments): Promise<DevToolsPluginOutput> => {\n this.validate({ command, args });\n return new Promise<DevToolsPluginOutput>(async (resolve) => {\n // Set up the command and its arguments\n const tool = path.join(this.plugin.packageRoot, this.plugin.cliExtensions!.entryPoint);\n const child = this.spawnFunc(\n 'node',\n [tool, command, `${JSON.stringify(args)}`, `${metroServerOrigin}`],\n {\n cwd: this.projectRoot,\n env: { ...process.env },\n }\n );\n\n let finished = false;\n const pluginResults = new DevToolsPluginCliExtensionResults(onOutput);\n\n // Collect output/error data\n child.stdout.on('data', (data) => pluginResults.append(data.toString()));\n child.stderr.on('data', (data) => pluginResults.append(data.toString(), 'error'));\n\n // Setup timeout\n const timeout = setTimeout(() => {\n if (!finished) {\n finished = true;\n child.kill('SIGKILL');\n pluginResults.append('Command timed out', 'error');\n resolve(pluginResults.getOutput());\n }\n }, this.timeoutMs);\n\n child.on('close', (code: number) => {\n if (finished) return;\n clearTimeout(timeout);\n finished = true;\n pluginResults.exit(code);\n resolve(pluginResults.getOutput());\n });\n\n child.on('error', (err: Error) => {\n if (finished) return;\n clearTimeout(timeout);\n finished = true;\n pluginResults.append(err.toString(), 'error');\n resolve(pluginResults.getOutput());\n });\n });\n };\n}\n"],"names":["DevToolsPluginCliExtensionExecutor","DEFAULT_TIMEOUT_MS","constructor","plugin","projectRoot","spawnFunc","spawn","timeoutMs","getCommandString","command","args","cliExtensions","entryPoint","Object","keys","length","JSON","stringify","execute","metroServerOrigin","onOutput","validate","Promise","resolve","tool","path","join","packageRoot","child","cwd","env","process","finished","pluginResults","DevToolsPluginCliExtensionResults","stdout","on","data","append","toString","stderr","timeout","setTimeout","kill","getOutput","code","clearTimeout","exit","err","Error","packageName","commandElement","commands","find","c","name","paramLength","parameters","argsLength","argsKeys","param","found","key"],"mappings":";;;;+BA0BaA;;;eAAAA;;;;yBA1BS;;;;;;;gEACL;;;;;;mDAOiC;;;;;;AAElD,MAAMC,qBAAqB,OAAQ,aAAa;AAgBzC,MAAMD;IACXE,YACE,AAAQC,MAA0B,EAClC,AAAQC,WAAmB,EAC3B,AAAQC,YAA0BC,sBAAK,EACvC,AAAQC,YAAYN,mBAAmB,gCAAgC;IAAjC,CACtC;YAEK;aANGE,SAAAA;aACAC,cAAAA;aACAC,YAAAA;aACAE,YAAAA;aAmCHC,mBAAmB,CAAC,EACzBC,OAAO,EACPC,IAAI,EACuD;YAC3D,OAAO,CAAC,KAAK,EAAE,IAAI,CAACP,MAAM,CAACQ,aAAa,CAAEC,UAAU,CAAC,CAAC,EAAEH,UAAUI,OAAOC,IAAI,CAACJ,QAAQ,CAAC,GAAGK,MAAM,GAAG,IAAI,MAAMC,KAAKC,SAAS,CAACP,QAAQ,IAAI;QAC1I;aAEOQ,UAAU,OAAO,EACtBT,OAAO,EACPC,IAAI,EACJS,iBAAiB,EACjBC,QAAQ,EACwB;YAChC,IAAI,CAACC,QAAQ,CAAC;gBAAEZ;gBAASC;YAAK;YAC9B,OAAO,IAAI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;QACF;IACF;AA+DF"}
|
|
1
|
+
{"version":3,"sources":["../../../../src/start/server/DevToolsPluginCliExtensionExecutor.ts"],"sourcesContent":["import { spawn, type ChildProcessWithoutNullStreams } from 'child_process';\nimport path from 'path';\n\nimport {\n DevToolsPluginExecutorArguments,\n DevToolsPluginInfo,\n DevToolsPluginOutput,\n} from './DevToolsPlugin.schema';\nimport { DevToolsPluginCliExtensionResults } from './DevToolsPluginCliExtensionResults';\nimport { isPathInside } from '../../utils/dir';\n\nconst DEFAULT_TIMEOUT_MS = 10_000; // 10 seconds\n\n/**\n * Class that executes CLI Extension commands for a given plugin\n *\n * ## Responsibilities:\n * - Verifies that requested commands exist and have correct parameters\n * - Validates that provided arguments match expected parameter schema\n * - Spawns and manages child processes for command execution\n * - Captures and streams stdout/stderr data from executed commands\n * - Manages process errors, timeouts, and unexpected failures\n * - Enforces execution time limits to prevent hanging processes\n * - Configures proper execution environment with color support\n * - Ensures proper cleanup of processes and timeouts\n * - Provides structured output with exit codes and error states\n */\nexport class DevToolsPluginCliExtensionExecutor {\n private readonly resolvedEntryPoint: string;\n\n constructor(\n private plugin: DevToolsPluginInfo,\n private projectRoot: string,\n private spawnFunc: typeof spawn = spawn, // Used for injection when testing,\n private timeoutMs = DEFAULT_TIMEOUT_MS // Timeout for command execution\n ) {\n // Validate that this is a plugin with cli extensions\n if (!this.plugin.cliExtensions?.entryPoint) {\n throw new Error(`Plugin ${this.plugin.packageName} has no CLI extensions`);\n }\n // Reject entryPoints that escape packageRoot (e.g. \"../../other-pkg/dist/cli.js\").\n const resolved = path.resolve(this.plugin.packageRoot, this.plugin.cliExtensions.entryPoint);\n if (!isPathInside(resolved, this.plugin.packageRoot)) {\n throw new Error(\n `Plugin ${this.plugin.packageName} entryPoint \"${this.plugin.cliExtensions.entryPoint}\" ` +\n `escapes packageRoot (${this.plugin.packageRoot}); must be a relative path inside the package.`\n );\n }\n this.resolvedEntryPoint = resolved;\n }\n\n public validate({ command, args }: Omit<DevToolsPluginExecutorArguments, 'metroServerOrigin'>) {\n const commandElement = this.plugin.cliExtensions?.commands.find((c) => c.name === command);\n if (!commandElement) {\n throw new Error(`Command \"${command}\" not found in plugin ${this.plugin.packageName}`);\n }\n\n const paramLength = commandElement.parameters?.length ?? 0;\n const argsLength = Object.keys(args ?? {}).length;\n if (paramLength !== argsLength) {\n // Quick check to see if the lengths match\n throw new Error(\n `Expected ${paramLength} parameter(s), but got ${argsLength} argument(s) for the command \"${command}\".`\n );\n }\n\n const argsObj = (args ?? {}) as Record<string, unknown>;\n for (const param of commandElement.parameters ?? []) {\n if (!Object.prototype.hasOwnProperty.call(argsObj, param.name)) {\n throw new Error(\n `Parameter \"${param.name}\" not found in command \"${command}\" of plugin ${this.plugin.packageName}`\n );\n }\n // Enforce declared parameter type; don't rely on upstream Zod validation alone.\n const expected =\n param.type === 'confirm' ? 'boolean' : param.type === 'number' ? 'number' : 'string';\n const actual = typeof argsObj[param.name];\n if (actual !== expected) {\n throw new Error(\n `Parameter \"${param.name}\" of \"${command}\" expected ${expected} (declared \"${param.type}\"), got ${actual}.`\n );\n }\n }\n }\n\n /** this function is used for testing and showing the command in UI */\n public getCommandString = ({\n command,\n args,\n }: Omit<DevToolsPluginExecutorArguments, 'metroServerOrigin'>) => {\n return `node ${this.plugin.cliExtensions!.entryPoint} ${command}${Object.keys(args ?? {}).length > 0 ? ' ' + JSON.stringify(args) : ''}`;\n };\n\n public execute = async ({\n command,\n args,\n metroServerOrigin,\n onOutput,\n }: DevToolsPluginExecutorArguments): Promise<DevToolsPluginOutput> => {\n this.validate({ command, args });\n return new Promise<DevToolsPluginOutput>((resolve) => {\n let finished = false;\n let timeout: ReturnType<typeof setTimeout> | undefined;\n const pluginResults = new DevToolsPluginCliExtensionResults(onOutput);\n\n // process.execPath instead of 'node' so the child can't be redirected by a PATH shim.\n let child: ChildProcessWithoutNullStreams;\n try {\n child = this.spawnFunc(\n process.execPath,\n [this.resolvedEntryPoint, command, `${JSON.stringify(args)}`, `${metroServerOrigin}`],\n {\n cwd: this.projectRoot,\n env: { ...process.env },\n }\n );\n } catch (err: any) {\n // spawn can throw synchronously; resolve with an error result instead of hanging.\n pluginResults.append(err?.toString?.() ?? String(err), 'error');\n resolve(pluginResults.getOutput());\n return;\n }\n\n const finishOnTruncation = () => {\n if (pluginResults.isTruncated() && !finished) {\n finished = true;\n if (timeout) clearTimeout(timeout);\n child.kill('SIGKILL');\n resolve(pluginResults.getOutput());\n }\n };\n\n // Collect output/error data\n child.stdout.on('data', (data) => {\n pluginResults.append(data.toString());\n finishOnTruncation();\n });\n child.stderr.on('data', (data) => {\n pluginResults.append(data.toString(), 'error');\n finishOnTruncation();\n });\n\n // Setup timeout\n timeout = setTimeout(() => {\n if (!finished) {\n finished = true;\n child.kill('SIGKILL');\n pluginResults.append('Command timed out', 'error');\n resolve(pluginResults.getOutput());\n }\n }, this.timeoutMs);\n\n child.on('close', (code: number) => {\n if (finished) return;\n if (timeout) clearTimeout(timeout);\n finished = true;\n pluginResults.exit(code);\n resolve(pluginResults.getOutput());\n });\n\n child.on('error', (err: Error) => {\n if (finished) return;\n if (timeout) clearTimeout(timeout);\n finished = true;\n pluginResults.append(err.toString(), 'error');\n resolve(pluginResults.getOutput());\n });\n });\n };\n}\n"],"names":["DevToolsPluginCliExtensionExecutor","DEFAULT_TIMEOUT_MS","constructor","plugin","projectRoot","spawnFunc","spawn","timeoutMs","getCommandString","command","args","cliExtensions","entryPoint","Object","keys","length","JSON","stringify","execute","metroServerOrigin","onOutput","validate","Promise","resolve","finished","timeout","pluginResults","DevToolsPluginCliExtensionResults","child","process","execPath","resolvedEntryPoint","cwd","env","err","append","toString","String","getOutput","finishOnTruncation","isTruncated","clearTimeout","kill","stdout","on","data","stderr","setTimeout","code","exit","Error","packageName","resolved","path","packageRoot","isPathInside","commandElement","commands","find","c","name","paramLength","parameters","argsLength","argsObj","param","prototype","hasOwnProperty","call","expected","type","actual"],"mappings":";;;;+BA2BaA;;;eAAAA;;;;yBA3B8C;;;;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;QAEA,MAAMuD,UAAWtD,QAAQ,CAAC;QAC1B,KAAK,MAAMuD,SAAST,eAAeM,UAAU,IAAI,EAAE,CAAE;YACnD,IAAI,CAACjD,OAAOqD,SAAS,CAACC,cAAc,CAACC,IAAI,CAACJ,SAASC,MAAML,IAAI,GAAG;gBAC9D,MAAM,IAAIV,MACR,CAAC,WAAW,EAAEe,MAAML,IAAI,CAAC,wBAAwB,EAAEnD,QAAQ,YAAY,EAAE,IAAI,CAACN,MAAM,CAACgD,WAAW,EAAE;YAEtG;YACA,gFAAgF;YAChF,MAAMkB,WACJJ,MAAMK,IAAI,KAAK,YAAY,YAAYL,MAAMK,IAAI,KAAK,WAAW,WAAW;YAC9E,MAAMC,SAAS,OAAOP,OAAO,CAACC,MAAML,IAAI,CAAC;YACzC,IAAIW,WAAWF,UAAU;gBACvB,MAAM,IAAInB,MACR,CAAC,WAAW,EAAEe,MAAML,IAAI,CAAC,MAAM,EAAEnD,QAAQ,WAAW,EAAE4D,SAAS,YAAY,EAAEJ,MAAMK,IAAI,CAAC,QAAQ,EAAEC,OAAO,CAAC,CAAC;YAE/G;QACF;IACF;AAsFF"}
|
|
@@ -8,17 +8,46 @@ Object.defineProperty(exports, "DevToolsPluginCliExtensionResults", {
|
|
|
8
8
|
return DevToolsPluginCliExtensionResults;
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
|
+
function _nodebuffer() {
|
|
12
|
+
const data = require("node:buffer");
|
|
13
|
+
_nodebuffer = function() {
|
|
14
|
+
return data;
|
|
15
|
+
};
|
|
16
|
+
return data;
|
|
17
|
+
}
|
|
11
18
|
const _DevToolsPluginschema = require("./DevToolsPlugin.schema");
|
|
19
|
+
// Cap accumulated output at V8's max single-string length to bound heap growth.
|
|
20
|
+
const MAX_OUTPUT_LENGTH = _nodebuffer().constants.MAX_STRING_LENGTH;
|
|
12
21
|
class DevToolsPluginCliExtensionResults {
|
|
13
22
|
constructor(onOutput){
|
|
14
23
|
this.onOutput = onOutput;
|
|
15
24
|
this._output = [];
|
|
25
|
+
this._totalLength = 0;
|
|
26
|
+
this._truncated = false;
|
|
16
27
|
}
|
|
17
28
|
append(output, level = 'info') {
|
|
29
|
+
if (this._truncated) return;
|
|
30
|
+
if (this._totalLength + output.length > MAX_OUTPUT_LENGTH) {
|
|
31
|
+
this._truncated = true;
|
|
32
|
+
const message = {
|
|
33
|
+
type: 'text',
|
|
34
|
+
text: `Output truncated: plugin exceeded V8's max string length (${MAX_OUTPUT_LENGTH} chars). Reduce output, paginate, or write to a file.`,
|
|
35
|
+
level: 'error'
|
|
36
|
+
};
|
|
37
|
+
this._output.push(message);
|
|
38
|
+
this.onOutput == null ? void 0 : this.onOutput.call(this, [
|
|
39
|
+
message
|
|
40
|
+
]);
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
this._totalLength += output.length;
|
|
18
44
|
const results = this.parseOutputText(output, level);
|
|
19
45
|
this._output.push(...results);
|
|
20
46
|
this.onOutput == null ? void 0 : this.onOutput.call(this, results);
|
|
21
47
|
}
|
|
48
|
+
isTruncated() {
|
|
49
|
+
return this._truncated;
|
|
50
|
+
}
|
|
22
51
|
exit(code) {
|
|
23
52
|
if (code === 0) return;
|
|
24
53
|
this.append(`Process exited with code ${code}`, 'error');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/start/server/DevToolsPluginCliExtensionResults.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"sources":["../../../../src/start/server/DevToolsPluginCliExtensionResults.ts"],"sourcesContent":["import { constants as bufferConstants } from 'node:buffer';\n\nimport type { DevToolsPluginOutput } from './DevToolsPlugin.schema';\nimport { DevToolsPluginOutputSchema } from './DevToolsPlugin.schema';\n\n// Cap accumulated output at V8's max single-string length to bound heap growth.\nconst MAX_OUTPUT_LENGTH = bufferConstants.MAX_STRING_LENGTH;\n\n/**\n * Class that collects and manages output from executed plugin commands\n *\n * Responsibilities:\n * - Collects output data from executed commands\n * - Parses and validates output data against expected schema\n * - Provides methods to append new output entries\n * - Handles exit codes and appends relevant messages\n * - Handles streaming of output via optional callback\n */\nexport class DevToolsPluginCliExtensionResults {\n constructor(private onOutput?: (output: DevToolsPluginOutput) => void) {}\n\n private _output: DevToolsPluginOutput = [];\n private _totalLength = 0;\n private _truncated = false;\n\n public append(output: string, level: 'info' | 'warning' | 'error' = 'info') {\n if (this._truncated) return;\n if (this._totalLength + output.length > MAX_OUTPUT_LENGTH) {\n this._truncated = true;\n const message = {\n type: 'text' as const,\n text: `Output truncated: plugin exceeded V8's max string length (${MAX_OUTPUT_LENGTH} chars). Reduce output, paginate, or write to a file.`,\n level: 'error' as const,\n };\n this._output.push(message);\n this.onOutput?.([message]);\n return;\n }\n this._totalLength += output.length;\n const results = this.parseOutputText(output, level);\n this._output.push(...results);\n this.onOutput?.(results);\n }\n\n public isTruncated(): boolean {\n return this._truncated;\n }\n\n public exit(code: number) {\n if (code === 0) return;\n this.append(`Process exited with code ${code}`, 'error');\n }\n\n public getOutput(): DevToolsPluginOutput {\n return this._output;\n }\n\n private parseOutputText(\n txt: string,\n level: 'info' | 'warning' | 'error' = 'info'\n ): DevToolsPluginOutput {\n // Validate against schema\n try {\n const result = DevToolsPluginOutputSchema.safeParse(JSON.parse(txt));\n if (!result.success) {\n return [\n {\n type: 'text',\n text: `Invalid JSON: ${result.error.issues.map((issue) => issue.message).join(', ')}`,\n level: 'error',\n },\n ];\n }\n return result.data;\n } catch {\n // Not JSON, treat as plain text\n const lines = txt.split('\\n');\n const results: DevToolsPluginOutput = [];\n for (const line of lines) {\n if (line) {\n results.push({ type: 'text', text: line, level });\n }\n }\n return results;\n }\n }\n}\n"],"names":["DevToolsPluginCliExtensionResults","MAX_OUTPUT_LENGTH","bufferConstants","MAX_STRING_LENGTH","constructor","onOutput","_output","_totalLength","_truncated","append","output","level","length","message","type","text","push","results","parseOutputText","isTruncated","exit","code","getOutput","txt","result","DevToolsPluginOutputSchema","safeParse","JSON","parse","success","error","issues","map","issue","join","data","lines","split","line"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KAAK,CAACL;YAC/D,IAAI,CAACC,OAAOK,OAAO,EAAE;gBACnB,OAAO;oBACL;wBACEf,MAAM;wBACNC,MAAM,CAAC,cAAc,EAAES,OAAOM,KAAK,CAACC,MAAM,CAACC,GAAG,CAAC,CAACC,QAAUA,MAAMpB,OAAO,EAAEqB,IAAI,CAAC,OAAO;wBACrFvB,OAAO;oBACT;iBACD;YACH;YACA,OAAOa,OAAOW,IAAI;QACpB,EAAE,OAAM;YACN,gCAAgC;YAChC,MAAMC,QAAQb,IAAIc,KAAK,CAAC;YACxB,MAAMpB,UAAgC,EAAE;YACxC,KAAK,MAAMqB,QAAQF,MAAO;gBACxB,IAAIE,MAAM;oBACRrB,QAAQD,IAAI,CAAC;wBAAEF,MAAM;wBAAQC,MAAMuB;wBAAM3B;oBAAM;gBACjD;YACF;YACA,OAAOM;QACT;IACF;AACF"}
|
|
@@ -17,15 +17,25 @@ async function addMcpCapabilities(mcpServer, devServerManager) {
|
|
|
17
17
|
const plugins = await devServerManager.devtoolsPluginManager.queryPluginsAsync();
|
|
18
18
|
for (const plugin of plugins){
|
|
19
19
|
if (plugin.cliExtensions) {
|
|
20
|
-
const
|
|
20
|
+
const mcpCommands = (plugin.cliExtensions.commands ?? []).filter((p)=>{
|
|
21
21
|
var _p_environments;
|
|
22
22
|
return (_p_environments = p.environments) == null ? void 0 : _p_environments.includes('mcp');
|
|
23
23
|
});
|
|
24
|
-
if (
|
|
24
|
+
if (mcpCommands.length === 0) {
|
|
25
25
|
continue;
|
|
26
26
|
}
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
// Build an MCP-scoped descriptor so the schema enum and the executor's
|
|
28
|
+
// existence check both reject commands that were not declared MCP-enabled.
|
|
29
|
+
const mcpPlugin = {
|
|
30
|
+
packageName: plugin.packageName,
|
|
31
|
+
packageRoot: plugin.packageRoot,
|
|
32
|
+
cliExtensions: {
|
|
33
|
+
...plugin.cliExtensions,
|
|
34
|
+
commands: mcpCommands
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
const schema = (0, _createMCPDevToolsExtensionSchema.createMCPDevToolsExtensionSchema)(mcpPlugin);
|
|
38
|
+
debug(`Installing MCP CLI extension for plugin: ${plugin.packageName} - found ${mcpCommands.length} commands`);
|
|
29
39
|
mcpServer.registerTool(plugin.packageName, {
|
|
30
40
|
title: plugin.packageName,
|
|
31
41
|
description: plugin.description,
|
|
@@ -36,7 +46,7 @@ async function addMcpCapabilities(mcpServer, devServerManager) {
|
|
|
36
46
|
try {
|
|
37
47
|
const { command, ...args } = parameters;
|
|
38
48
|
const metroServerOrigin = devServerManager.getDefaultDevServer().getJsInspectorBaseUrl();
|
|
39
|
-
const results = await new _DevToolsPluginCliExtensionExecutor.DevToolsPluginCliExtensionExecutor(
|
|
49
|
+
const results = await new _DevToolsPluginCliExtensionExecutor.DevToolsPluginCliExtensionExecutor(mcpPlugin, devServerManager.projectRoot).execute({
|
|
40
50
|
command,
|
|
41
51
|
args,
|
|
42
52
|
metroServerOrigin
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/start/server/MCPDevToolsPluginCLIExtensions.ts"],"sourcesContent":["import { DevServerManager } from './DevServerManager';\nimport { DevToolsPluginOutputSchema } from './DevToolsPlugin.schema';\nimport { DevToolsPluginCliExtensionExecutor } from './DevToolsPluginCliExtensionExecutor';\nimport { McpServer } from './MCP';\nimport { createMCPDevToolsExtensionSchema } from './createMCPDevToolsExtensionSchema';\nimport { Log } from '../../log';\n\nconst debug = require('debug')('expo:start:server:devtools:mcp');\n\nexport async function addMcpCapabilities(mcpServer: McpServer, devServerManager: DevServerManager) {\n const plugins = await devServerManager.devtoolsPluginManager.queryPluginsAsync();\n\n for (const plugin of plugins) {\n if (plugin.cliExtensions) {\n const
|
|
1
|
+
{"version":3,"sources":["../../../../src/start/server/MCPDevToolsPluginCLIExtensions.ts"],"sourcesContent":["import type { DevServerManager } from './DevServerManager';\nimport type { DevToolsPluginInfo } from './DevToolsPlugin.schema';\nimport { DevToolsPluginOutputSchema } from './DevToolsPlugin.schema';\nimport { DevToolsPluginCliExtensionExecutor } from './DevToolsPluginCliExtensionExecutor';\nimport { McpServer } from './MCP';\nimport { createMCPDevToolsExtensionSchema } from './createMCPDevToolsExtensionSchema';\nimport { Log } from '../../log';\n\nconst debug = require('debug')('expo:start:server:devtools:mcp');\n\nexport async function addMcpCapabilities(mcpServer: McpServer, devServerManager: DevServerManager) {\n const plugins = await devServerManager.devtoolsPluginManager.queryPluginsAsync();\n\n for (const plugin of plugins) {\n if (plugin.cliExtensions) {\n const mcpCommands = (plugin.cliExtensions.commands ?? []).filter((p) =>\n p.environments?.includes('mcp')\n );\n if (mcpCommands.length === 0) {\n continue;\n }\n\n // Build an MCP-scoped descriptor so the schema enum and the executor's\n // existence check both reject commands that were not declared MCP-enabled.\n const mcpPlugin: DevToolsPluginInfo = {\n packageName: plugin.packageName,\n packageRoot: plugin.packageRoot,\n cliExtensions: {\n ...plugin.cliExtensions,\n commands: mcpCommands,\n },\n };\n\n const schema = createMCPDevToolsExtensionSchema(mcpPlugin);\n\n debug(\n `Installing MCP CLI extension for plugin: ${plugin.packageName} - found ${mcpCommands.length} commands`\n );\n\n mcpServer.registerTool(\n plugin.packageName,\n {\n title: plugin.packageName,\n description: plugin.description,\n inputSchema: { parameters: schema },\n },\n async ({ parameters }) => {\n try {\n const { command, ...args } = parameters;\n\n const metroServerOrigin = devServerManager\n .getDefaultDevServer()\n .getJsInspectorBaseUrl();\n\n const results = await new DevToolsPluginCliExtensionExecutor(\n mcpPlugin,\n devServerManager.projectRoot\n ).execute({ command, args, metroServerOrigin });\n\n const parsedResults = DevToolsPluginOutputSchema.safeParse(results);\n if (parsedResults.success === false) {\n throw new Error(\n `Invalid output from CLI command: ${parsedResults.error.issues\n .map((issue) => issue.message)\n .join(', ')}`\n );\n }\n return {\n content: parsedResults.data\n .map((line) => {\n const { type } = line;\n if (type === 'text') {\n return { type, text: line.text, level: line.level, url: line.url };\n } else if (line.type === 'image' || line.type === 'audio') {\n // We could present this as a resource_link, but it seems not to be well supported in MCP clients,\n // so we'll return a text with the link instead.\n return {\n type: 'text',\n text: `${type} resource: ${line.url}${line.text ? ' (' + line.text + ')' : ''}`,\n } as const;\n }\n return null;\n })\n .filter((line): line is Exclude<typeof line, null> => line !== null),\n };\n } catch (e: any) {\n Log.error('Error executing MCP CLI command:', e);\n return {\n content: [{ type: 'text', text: `Error executing command: ${e.toString()}` }],\n isError: true,\n };\n }\n }\n );\n }\n }\n}\n"],"names":["addMcpCapabilities","debug","require","mcpServer","devServerManager","plugins","devtoolsPluginManager","queryPluginsAsync","plugin","cliExtensions","mcpCommands","commands","filter","p","environments","includes","length","mcpPlugin","packageName","packageRoot","schema","createMCPDevToolsExtensionSchema","registerTool","title","description","inputSchema","parameters","command","args","metroServerOrigin","getDefaultDevServer","getJsInspectorBaseUrl","results","DevToolsPluginCliExtensionExecutor","projectRoot","execute","parsedResults","DevToolsPluginOutputSchema","safeParse","success","Error","error","issues","map","issue","message","join","content","data","line","type","text","level","url","e","Log","toString","isError"],"mappings":";;;;+BAUsBA;;;eAAAA;;;sCARqB;oDACQ;kDAEF;qBAC7B;AAEpB,MAAMC,QAAQC,QAAQ,SAAS;AAExB,eAAeF,mBAAmBG,SAAoB,EAAEC,gBAAkC;IAC/F,MAAMC,UAAU,MAAMD,iBAAiBE,qBAAqB,CAACC,iBAAiB;IAE9E,KAAK,MAAMC,UAAUH,QAAS;QAC5B,IAAIG,OAAOC,aAAa,EAAE;YACxB,MAAMC,cAAc,AAACF,CAAAA,OAAOC,aAAa,CAACE,QAAQ,IAAI,EAAE,AAAD,EAAGC,MAAM,CAAC,CAACC;oBAChEA;wBAAAA,kBAAAA,EAAEC,YAAY,qBAAdD,gBAAgBE,QAAQ,CAAC;;YAE3B,IAAIL,YAAYM,MAAM,KAAK,GAAG;gBAC5B;YACF;YAEA,uEAAuE;YACvE,2EAA2E;YAC3E,MAAMC,YAAgC;gBACpCC,aAAaV,OAAOU,WA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,KAAK,SAAS;gCACzD,kGAAkG;gCAClG,gDAAgD;gCAChD,OAAO;oCACLA,MAAM;oCACNC,MAAM,GAAGD,KAAK,WAAW,EAAED,KAAKI,GAAG,GAAGJ,KAAKE,IAAI,GAAG,OAAOF,KAAKE,IAAI,GAAG,MAAM,IAAI;gCACjF;4BACF;4BACA,OAAO;wBACT,GACCvC,MAAM,CAAC,CAACqC,OAA6CA,SAAS;oBACnE;gBACF,EAAE,OAAOK,GAAQ;oBACfC,QAAG,CAACd,KAAK,CAAC,oCAAoCa;oBAC9C,OAAO;wBACLP,SAAS;4BAAC;gCAAEG,MAAM;gCAAQC,MAAM,CAAC,yBAAyB,EAAEG,EAAEE,QAAQ,IAAI;4BAAC;yBAAE;wBAC7EC,SAAS;oBACX;gBACF;YACF;QAEJ;IACF;AACF"}
|
|
@@ -33,12 +33,14 @@ function createMCPDevToolsExtensionSchema(plugin) {
|
|
|
33
33
|
// Track which commands use each parameter for documentation
|
|
34
34
|
const parameterCommandMap = {};
|
|
35
35
|
const parameterDescriptions = {};
|
|
36
|
+
const parameterTypes = {};
|
|
36
37
|
for (const command of commands){
|
|
37
38
|
if (command.parameters && command.parameters.length > 0) {
|
|
38
39
|
for (const param of command.parameters){
|
|
39
40
|
if (!parameterCommandMap[param.name]) {
|
|
40
41
|
parameterCommandMap[param.name] = [];
|
|
41
42
|
parameterDescriptions[param.name] = param.description || '';
|
|
43
|
+
parameterTypes[param.name] = param.type;
|
|
42
44
|
}
|
|
43
45
|
parameterCommandMap[param.name].push(command.name);
|
|
44
46
|
}
|
|
@@ -51,7 +53,7 @@ function createMCPDevToolsExtensionSchema(plugin) {
|
|
|
51
53
|
const commandsUsingParam = commandList.length === commands.length ? 'all commands' : commandList.map((c)=>`"${c}"`).join(', ');
|
|
52
54
|
// Include command context in the description so LLMs know when to use each parameter
|
|
53
55
|
const fullDescription = baseDescription ? `${baseDescription} (Used by: ${commandsUsingParam})` : `Parameter for: ${commandsUsingParam}`;
|
|
54
|
-
allParameters[paramName] =
|
|
56
|
+
allParameters[paramName] = paramTypeToZod(parameterTypes[paramName]).optional().describe(fullDescription);
|
|
55
57
|
}
|
|
56
58
|
// Build the command description with clear instructions for the LLM
|
|
57
59
|
const hasParameters = Object.keys(allParameters).length > 0;
|
|
@@ -63,5 +65,15 @@ function createMCPDevToolsExtensionSchema(plugin) {
|
|
|
63
65
|
}).strict(); // .strict() adds additionalProperties: false
|
|
64
66
|
return schema;
|
|
65
67
|
}
|
|
68
|
+
function paramTypeToZod(type) {
|
|
69
|
+
switch(type){
|
|
70
|
+
case 'number':
|
|
71
|
+
return _zod().z.number();
|
|
72
|
+
case 'confirm':
|
|
73
|
+
return _zod().z.boolean();
|
|
74
|
+
case 'text':
|
|
75
|
+
return _zod().z.string();
|
|
76
|
+
}
|
|
77
|
+
}
|
|
66
78
|
|
|
67
79
|
//# sourceMappingURL=createMCPDevToolsExtensionSchema.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/start/server/createMCPDevToolsExtensionSchema.ts"],"sourcesContent":["import { z } from 'zod';\n\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../../src/start/server/createMCPDevToolsExtensionSchema.ts"],"sourcesContent":["import { z } from 'zod';\n\nimport type { DevToolsPluginCommandParameter, DevToolsPluginInfo } from './DevToolsPlugin.schema';\n\n/**\n * Creates an MCP-compatible JSON schema for a DevTools plugin's CLI extensions.\n *\n * LLM agents have varying support for complex JSON schema features like `anyOf`/`oneOf`\n * discriminated unions. This implementation uses a flat schema with an enum for the\n * command name, which provides the best compatibility across different LLM providers:\n *\n * - OpenAI: Supports `anyOf` but requires `additionalProperties: false` and all fields `required`\n * - Claude/Anthropic: Works best with simple flat schemas with enums\n * - Other providers: Generally have limited or inconsistent support for discriminated unions\n *\n * To compensate for the lack of discriminated unions, parameter descriptions include\n * which command(s) they belong to, and command descriptions include their parameters.\n *\n * The resulting schema structure is:\n * ```json\n * {\n * \"type\": \"object\",\n * \"properties\": {\n * \"command\": {\n * \"type\": \"string\",\n * \"enum\": [\"cmd1\", \"cmd2\", ...],\n * \"description\": \"The command to execute. Available commands: \\\"cmd1\\\" - Title 1 (params: foo); ...\"\n * },\n * \"foo\": { \"type\": \"string\", \"description\": \"Foo description (Used by: \\\"cmd1\\\")\" },\n * ...\n * },\n * \"required\": [\"command\"],\n * \"additionalProperties\": false\n * }\n * ```\n */\nexport function createMCPDevToolsExtensionSchema(plugin: DevToolsPluginInfo) {\n if (plugin.cliExtensions == null || plugin.cliExtensions?.commands.length === 0) {\n throw new Error(\n `Plugin ${plugin.packageName} has no commands defined. Please define at least one command.`\n );\n }\n\n const commands = plugin.cliExtensions.commands;\n\n // Build a rich description that explains each command and its parameters\n const commandDescriptions = commands\n .map((c) => {\n const params = c.parameters?.map((p) => p.name).join(', ');\n return params ? `\"${c.name}\": ${c.title} (params: ${params})` : `\"${c.name}\": ${c.title}`;\n })\n .join('. ');\n\n // Create enum of command names for clear LLM selection\n const commandNames = commands.map((c) => c.name) as [string, ...string[]];\n\n // Collect all unique parameters across all commands\n // Track which commands use each parameter for documentation\n const parameterCommandMap: Record<string, string[]> = {};\n const parameterDescriptions: Record<string, string> = {};\n const parameterTypes: Record<string, DevToolsPluginCommandParameter['type']> = {};\n\n for (const command of commands) {\n if (command.parameters && command.parameters.length > 0) {\n for (const param of command.parameters) {\n if (!parameterCommandMap[param.name]) {\n parameterCommandMap[param.name] = [];\n parameterDescriptions[param.name] = param.description || '';\n parameterTypes[param.name] = param.type;\n }\n parameterCommandMap[param.name].push(command.name);\n }\n }\n }\n\n // Build parameters with descriptions that indicate which command(s) they belong to\n const allParameters: Record<string, z.ZodTypeAny> = {};\n for (const [paramName, commandList] of Object.entries(parameterCommandMap)) {\n const baseDescription = parameterDescriptions[paramName];\n const commandsUsingParam =\n commandList.length === commands.length\n ? 'all commands'\n : commandList.map((c) => `\"${c}\"`).join(', ');\n\n // Include command context in the description so LLMs know when to use each parameter\n const fullDescription = baseDescription\n ? `${baseDescription} (Used by: ${commandsUsingParam})`\n : `Parameter for: ${commandsUsingParam}`;\n\n allParameters[paramName] = paramTypeToZod(parameterTypes[paramName]!)\n .optional()\n .describe(fullDescription);\n }\n\n // Build the command description with clear instructions for the LLM\n const hasParameters = Object.keys(allParameters).length > 0;\n const commandDescription = hasParameters\n ? `Required. The command to execute. You must select exactly one command from the enum values. ` +\n `Each command may require specific parameters - only include parameters that belong to the selected command. ` +\n `Commands: ${commandDescriptions}.`\n : `Required. The command to execute. Select exactly one from the available options. ` +\n `Commands: ${commandDescriptions}.`;\n\n // Build the flat schema with additionalProperties: false for LLM compatibility\n const schema = z\n .object({\n command: z.enum(commandNames).describe(commandDescription),\n ...allParameters,\n })\n .strict(); // .strict() adds additionalProperties: false\n\n return schema;\n}\n\nfunction paramTypeToZod(type: DevToolsPluginCommandParameter['type']) {\n switch (type) {\n case 'number':\n return z.number();\n case 'confirm':\n return z.boolean();\n case 'text':\n return z.string();\n }\n}\n"],"names":["createMCPDevToolsExtensionSchema","plugin","cliExtensions","commands","length","Error","packageName","commandDescriptions","map","c","params","parameters","p","name","join","title","commandNames","parameterCommandMap","parameterDescriptions","parameterTypes","command","param","description","type","push","allParameters","paramName","commandList","Object","entries","baseDescription","commandsUsingParam","fullDescription","paramTypeToZod","optional","describe","hasParameters","keys","commandDescription","schema","z","object","enum","strict","number","boolean","string"],"mappings":";;;;+BAoCgBA;;;eAAAA;;;;yBApCE;;;;;;AAoCX,SAASA,iCAAiCC,MAA0B;QACrCA;IAApC,IAAIA,OAAOC,aAAa,IAAI,QAAQD,EAAAA,wBAAAA,OAAOC,aAAa,qBAApBD,sBAAsBE,QAAQ,CAACC,MAAM,MAAK,GAAG;QAC/E,MAAM,IAAIC,MACR,CAAC,OAAO,EAAEJ,OAAOK,WAAW,CAAC,6DAA6D,CAAC;IAE/F;IAEA,MAAMH,WAAWF,OAAOC,aAAa,CAACC,QAAQ;IAE9C,yEAAyE;IACzE,MAAMI,sBAAsBJ,SACzBK,GAAG,C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,MAAM,KAAKD,SAASC,MAAM,GAClC,iBACAuB,YAAYnB,GAAG,CAAC,CAACC,IAAM,CAAC,CAAC,EAAEA,EAAE,CAAC,CAAC,EAAEK,IAAI,CAAC;QAE5C,qFAAqF;QACrF,MAAMkB,kBAAkBF,kBACpB,GAAGA,gBAAgB,WAAW,EAAEC,mBAAmB,CAAC,CAAC,GACrD,CAAC,eAAe,EAAEA,oBAAoB;QAE1CN,aAAa,CAACC,UAAU,GAAGO,eAAed,cAAc,CAACO,UAAU,EAChEQ,QAAQ,GACRC,QAAQ,CAACH;IACd;IAEA,oEAAoE;IACpE,MAAMI,gBAAgBR,OAAOS,IAAI,CAACZ,eAAerB,MAAM,GAAG;IAC1D,MAAMkC,qBAAqBF,gBACvB,CAAC,4FAA4F,CAAC,GAC9F,CAAC,4GAA4G,CAAC,GAC9G,CAAC,UAAU,EAAE7B,oBAAoB,CAAC,CAAC,GACnC,CAAC,iFAAiF,CAAC,GACnF,CAAC,UAAU,EAAEA,oBAAoB,CAAC,CAAC;IAEvC,+EAA+E;IAC/E,MAAMgC,SAASC,QAAC,CACbC,MAAM,CAAC;QACNrB,SAASoB,QAAC,CAACE,IAAI,CAAC1B,cAAcmB,QAAQ,CAACG;QACvC,GAAGb,aAAa;IAClB,GACCkB,MAAM,IAAI,6CAA6C;IAE1D,OAAOJ;AACT;AAEA,SAASN,eAAeV,IAA4C;IAClE,OAAQA;QACN,KAAK;YACH,OAAOiB,QAAC,CAACI,MAAM;QACjB,KAAK;YACH,OAAOJ,QAAC,CAACK,OAAO;QAClB,KAAK;YACH,OAAOL,QAAC,CAACM,MAAM;IACnB;AACF"}
|
|
@@ -365,23 +365,14 @@ function createServerComponentsMiddleware(projectRoot, { rscPath, instanceMetroO
|
|
|
365
365
|
rscRendererCache.set(platform, renderer);
|
|
366
366
|
return renderer;
|
|
367
367
|
}
|
|
368
|
-
const rscRenderContext = new Map();
|
|
369
|
-
function getRscRenderContext(platform) {
|
|
370
|
-
// NOTE(EvanBacon): We memoize this now that there's a persistent server storage cache for Server Actions.
|
|
371
|
-
if (rscRenderContext.has(platform)) {
|
|
372
|
-
return rscRenderContext.get(platform);
|
|
373
|
-
}
|
|
374
|
-
const context = {};
|
|
375
|
-
rscRenderContext.set(platform, context);
|
|
376
|
-
return context;
|
|
377
|
-
}
|
|
378
368
|
async function renderRscToReadableStream({ input, headers, method, platform, body, engine, contentType, ssrManifest, decodedBody, routerOptions }, isExporting = instanceMetroOptions.isExporting) {
|
|
379
369
|
(0, _assert().default)(isExporting != null, 'The server must be started before calling renderRscToReadableStream.');
|
|
380
370
|
if (method === 'POST') {
|
|
381
371
|
(0, _assert().default)(body, 'Server request must be provided when method is POST (server actions)');
|
|
382
372
|
}
|
|
383
|
-
const context =
|
|
384
|
-
|
|
373
|
+
const context = {
|
|
374
|
+
__expo_requestHeaders: headers
|
|
375
|
+
};
|
|
385
376
|
const { renderRsc } = await getRscRendererAsync(platform);
|
|
386
377
|
return renderRsc({
|
|
387
378
|
body,
|
|
@@ -389,6 +380,8 @@ function createServerComponentsMiddleware(projectRoot, { rscPath, instanceMetroO
|
|
|
389
380
|
context,
|
|
390
381
|
config: {},
|
|
391
382
|
input,
|
|
383
|
+
method,
|
|
384
|
+
headers: Object.fromEntries(headers.entries()),
|
|
392
385
|
contentType
|
|
393
386
|
}, {
|
|
394
387
|
isExporting,
|