diff --git a/packages/web-templates/build.mjs b/packages/web-templates/build.mjs index c01646232..eb7bd0d25 100644 --- a/packages/web-templates/build.mjs +++ b/packages/web-templates/build.mjs @@ -23,10 +23,14 @@ const assetBuilds = [ const runCommand = ({ command, args, cwd, label }) => new Promise((resolve, reject) => { - const child = spawn(command, args, { + const useShell = process.platform === 'win32'; + // On Windows, quote the command path to handle spaces (e.g., "C:\Program Files\nodejs\node.exe") + const quotedCommand = useShell ? `"${command}"` : command; + + const child = spawn(quotedCommand, args, { cwd, stdio: 'inherit', - shell: process.platform === 'win32', + shell: useShell, }); child.on('error', reject); diff --git a/scripts/dev.js b/scripts/dev.js index 8432a32ce..32f4a2280 100644 --- a/scripts/dev.js +++ b/scripts/dev.js @@ -15,18 +15,15 @@ */ import { spawn } from 'node:child_process'; -import { dirname, join, resolve } from 'node:path'; +import { dirname, join } from 'node:path'; import { fileURLToPath, pathToFileURL } from 'node:url'; import { writeFileSync, mkdtempSync, rmSync } from 'node:fs'; -import { tmpdir } from 'node:os'; +import { tmpdir, platform } from 'node:os'; const __dirname = dirname(fileURLToPath(import.meta.url)); const root = join(__dirname, '..'); const cliPackageDir = join(root, 'packages', 'cli'); -// Resolve tsx from node_modules -const tsxPath = resolve(root, 'node_modules', '.bin', 'tsx'); - // Entry point for the CLI const cliEntry = join(cliPackageDir, 'index.ts'); @@ -79,12 +76,16 @@ const env = { NODE_OPTIONS: `${existingNodeOptions} ${importFlag}`.trim(), }; -const nodeArgs = [tsxPath, cliEntry, ...process.argv.slice(2)]; +// On Windows, use tsx.cmd; on Unix, use tsx directly +const isWin = platform() === 'win32'; +const tsxCmd = isWin ? 'tsx.cmd' : 'tsx'; +const tsxArgs = [cliEntry, ...process.argv.slice(2)]; -const child = spawn('node', nodeArgs, { +const child = spawn(tsxCmd, tsxArgs, { stdio: 'inherit', env, cwd: process.cwd(), + shell: isWin, // Use shell on Windows to resolve .cmd files }); child.on('error', (err) => {