From e48234af576e41e630736450c66b690226707bc3 Mon Sep 17 00:00:00 2001 From: 7Sageer <12210216@mail.sustech.edu.cn> Date: Tue, 9 Jun 2026 20:20:44 +0800 Subject: [PATCH] fix: avoid Windows command shim launches (#591) --- .changeset/steady-windows-bins.md | 6 ++++++ apps/kimi-code/scripts/dev.mjs | 8 +++++--- packages/node-sdk/scripts/build-dts.mjs | 16 +++++++++++----- 3 files changed, 22 insertions(+), 8 deletions(-) create mode 100644 .changeset/steady-windows-bins.md diff --git a/.changeset/steady-windows-bins.md b/.changeset/steady-windows-bins.md new file mode 100644 index 000000000..b4923ec44 --- /dev/null +++ b/.changeset/steady-windows-bins.md @@ -0,0 +1,6 @@ +--- +"@moonshot-ai/kimi-code": patch +"@moonshot-ai/kimi-code-sdk": patch +--- + +Fix Windows builds and development launches that could fail when package binaries resolve to command shims. diff --git a/apps/kimi-code/scripts/dev.mjs b/apps/kimi-code/scripts/dev.mjs index 5bf5d460a..0e6be4cf2 100644 --- a/apps/kimi-code/scripts/dev.mjs +++ b/apps/kimi-code/scripts/dev.mjs @@ -1,10 +1,12 @@ #!/usr/bin/env node import { spawn } from 'node:child_process'; +import { createRequire } from 'node:module'; import { dirname, resolve } from 'node:path'; import { fileURLToPath } from 'node:url'; import { startPluginMarketplaceServer } from './dev-plugin-marketplace-server.mjs'; +const require = createRequire(import.meta.url); const SCRIPT_DIR = dirname(fileURLToPath(import.meta.url)); const APP_ROOT = resolve(SCRIPT_DIR, '..'); const MARKETPLACE_ENV = 'KIMI_CODE_PLUGIN_MARKETPLACE_URL'; @@ -18,12 +20,12 @@ if (env[MARKETPLACE_ENV] === undefined || env[MARKETPLACE_ENV]?.trim().length == console.error(`Plugin marketplace dev server: ${marketplaceServer.marketplaceUrl}`); } -const tsxBin = process.platform === 'win32' ? 'tsx.cmd' : 'tsx'; +const tsxCli = require.resolve('tsx/cli'); const cliArgs = process.argv.slice(2); if (cliArgs[0] === '--') cliArgs.shift(); const child = spawn( - tsxBin, - ['--import', '../../build/register-raw-text-loader.mjs', './src/main.ts', ...cliArgs], + process.execPath, + [tsxCli, '--import', '../../build/register-raw-text-loader.mjs', './src/main.ts', ...cliArgs], { cwd: APP_ROOT, env, diff --git a/packages/node-sdk/scripts/build-dts.mjs b/packages/node-sdk/scripts/build-dts.mjs index 2c90f4461..b25ac114b 100644 --- a/packages/node-sdk/scripts/build-dts.mjs +++ b/packages/node-sdk/scripts/build-dts.mjs @@ -1,12 +1,16 @@ import { spawn } from 'node:child_process'; import { existsSync } from 'node:fs'; import { mkdir, readdir, readFile, rm, writeFile } from 'node:fs/promises'; +import { createRequire } from 'node:module'; import path from 'node:path'; +const require = createRequire(import.meta.url); const packageRoot = path.resolve(import.meta.dirname, '..'); const tempDir = path.join(packageRoot, '.tmp-api-extractor'); const dtsRoot = path.join(tempDir, 'dts'); const providerClientShimPath = path.join(dtsRoot, 'provider-clients.d.ts'); +const tscBinPath = packageBinPath('typescript', 'bin/tsc'); +const apiExtractorBinPath = packageBinPath('@microsoft/api-extractor', 'bin/api-extractor'); const packageDirs = new Set(['agent-core', 'kaos', 'kosong', 'node-sdk', 'oauth']); const workspacePackages = new Map([ @@ -18,19 +22,21 @@ const workspacePackages = new Map([ try { await rm(tempDir, { recursive: true, force: true }); - await run('tsc', ['-p', 'tsconfig.dts.json']); + await run('tsc', tscBinPath, ['-p', 'tsconfig.dts.json']); await writeProviderClientShim(); await rewriteWorkspaceSpecifiers(); - await run('api-extractor', ['run', '--local']); + await run('api-extractor', apiExtractorBinPath, ['run', '--local']); } finally { await rm(tempDir, { recursive: true, force: true }); } -function run(command, args) { - const executable = process.platform === 'win32' ? `${command}.cmd` : command; +function packageBinPath(packageName, binPath) { + return path.join(path.dirname(require.resolve(`${packageName}/package.json`)), binPath); +} +function run(command, binPath, args) { return new Promise((resolve, reject) => { - const child = spawn(executable, args, { + const child = spawn(process.execPath, [binPath, ...args], { cwd: packageRoot, stdio: 'inherit', });