fix: avoid Windows command shim launches (#591)

This commit is contained in:
7Sageer 2026-06-09 20:20:44 +08:00 committed by GitHub
parent f2863af267
commit e48234af57
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 22 additions and 8 deletions

View file

@ -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.

View file

@ -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,

View file

@ -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',
});