Skip to content

Commit e48234a

Browse files
authored
fix: avoid Windows command shim launches (#591)
1 parent f2863af commit e48234a

3 files changed

Lines changed: 22 additions & 8 deletions

File tree

.changeset/steady-windows-bins.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@moonshot-ai/kimi-code": patch
3+
"@moonshot-ai/kimi-code-sdk": patch
4+
---
5+
6+
Fix Windows builds and development launches that could fail when package binaries resolve to command shims.

apps/kimi-code/scripts/dev.mjs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
#!/usr/bin/env node
22
import { spawn } from 'node:child_process';
3+
import { createRequire } from 'node:module';
34
import { dirname, resolve } from 'node:path';
45
import { fileURLToPath } from 'node:url';
56

67
import { startPluginMarketplaceServer } from './dev-plugin-marketplace-server.mjs';
78

9+
const require = createRequire(import.meta.url);
810
const SCRIPT_DIR = dirname(fileURLToPath(import.meta.url));
911
const APP_ROOT = resolve(SCRIPT_DIR, '..');
1012
const MARKETPLACE_ENV = 'KIMI_CODE_PLUGIN_MARKETPLACE_URL';
@@ -18,12 +20,12 @@ if (env[MARKETPLACE_ENV] === undefined || env[MARKETPLACE_ENV]?.trim().length ==
1820
console.error(`Plugin marketplace dev server: ${marketplaceServer.marketplaceUrl}`);
1921
}
2022

21-
const tsxBin = process.platform === 'win32' ? 'tsx.cmd' : 'tsx';
23+
const tsxCli = require.resolve('tsx/cli');
2224
const cliArgs = process.argv.slice(2);
2325
if (cliArgs[0] === '--') cliArgs.shift();
2426
const child = spawn(
25-
tsxBin,
26-
['--import', '../../build/register-raw-text-loader.mjs', './src/main.ts', ...cliArgs],
27+
process.execPath,
28+
[tsxCli, '--import', '../../build/register-raw-text-loader.mjs', './src/main.ts', ...cliArgs],
2729
{
2830
cwd: APP_ROOT,
2931
env,

packages/node-sdk/scripts/build-dts.mjs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
import { spawn } from 'node:child_process';
22
import { existsSync } from 'node:fs';
33
import { mkdir, readdir, readFile, rm, writeFile } from 'node:fs/promises';
4+
import { createRequire } from 'node:module';
45
import path from 'node:path';
56

7+
const require = createRequire(import.meta.url);
68
const packageRoot = path.resolve(import.meta.dirname, '..');
79
const tempDir = path.join(packageRoot, '.tmp-api-extractor');
810
const dtsRoot = path.join(tempDir, 'dts');
911
const providerClientShimPath = path.join(dtsRoot, 'provider-clients.d.ts');
12+
const tscBinPath = packageBinPath('typescript', 'bin/tsc');
13+
const apiExtractorBinPath = packageBinPath('@microsoft/api-extractor', 'bin/api-extractor');
1014

1115
const packageDirs = new Set(['agent-core', 'kaos', 'kosong', 'node-sdk', 'oauth']);
1216
const workspacePackages = new Map([
@@ -18,19 +22,21 @@ const workspacePackages = new Map([
1822

1923
try {
2024
await rm(tempDir, { recursive: true, force: true });
21-
await run('tsc', ['-p', 'tsconfig.dts.json']);
25+
await run('tsc', tscBinPath, ['-p', 'tsconfig.dts.json']);
2226
await writeProviderClientShim();
2327
await rewriteWorkspaceSpecifiers();
24-
await run('api-extractor', ['run', '--local']);
28+
await run('api-extractor', apiExtractorBinPath, ['run', '--local']);
2529
} finally {
2630
await rm(tempDir, { recursive: true, force: true });
2731
}
2832

29-
function run(command, args) {
30-
const executable = process.platform === 'win32' ? `${command}.cmd` : command;
33+
function packageBinPath(packageName, binPath) {
34+
return path.join(path.dirname(require.resolve(`${packageName}/package.json`)), binPath);
35+
}
3136

37+
function run(command, binPath, args) {
3238
return new Promise((resolve, reject) => {
33-
const child = spawn(executable, args, {
39+
const child = spawn(process.execPath, [binPath, ...args], {
3440
cwd: packageRoot,
3541
stdio: 'inherit',
3642
});

0 commit comments

Comments
 (0)