fix: 修复 OpenCode 运行时启动与本地打包

This commit is contained in:
2026-08-09 00:02:49 +08:00
parent d092132d86
commit a6fe14a8d6
20 changed files with 1847 additions and 154 deletions

View File

@@ -6,19 +6,14 @@ const moduleRequire = createRequire(import.meta.url);
export const PLAYWRIGHT_MCP_SERVER_ID = 'playwright';
export const PLAYWRIGHT_MCP_PACKAGE = '@playwright/mcp';
export const PLAYWRIGHT_MCP_VERSION = '0.0.78';
function fallbackPlaywrightMcpServer(): OpencodeMcpServerEntry {
return {
type: 'local',
command: ['npx', '-y', `${PLAYWRIGHT_MCP_PACKAGE}@${PLAYWRIGHT_MCP_VERSION}`],
enabled: true,
};
}
type ResolvePackageJson = () => string;
export function resolvePlaywrightMcpServer(): OpencodeMcpServerEntry {
export function resolvePlaywrightMcpServer(
resolvePackageJson: ResolvePackageJson = () => moduleRequire.resolve(`${PLAYWRIGHT_MCP_PACKAGE}/package.json`),
): OpencodeMcpServerEntry {
try {
const packageJsonPath = moduleRequire.resolve(`${PLAYWRIGHT_MCP_PACKAGE}/package.json`);
const packageJsonPath = resolvePackageJson();
return {
type: 'local',
command: [process.execPath, join(dirname(packageJsonPath), 'cli.js')],
@@ -27,7 +22,10 @@ export function resolvePlaywrightMcpServer(): OpencodeMcpServerEntry {
ELECTRON_RUN_AS_NODE: '1',
},
};
} catch {
return fallbackPlaywrightMcpServer();
} catch (error) {
throw new Error(
`Bundled ${PLAYWRIGHT_MCP_PACKAGE} is missing; Makelore does not download runtime dependencies with npx`,
{ cause: error },
);
}
}