fix: 修复 OpenCode 运行时启动与本地打包
This commit is contained in:
@@ -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 },
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user