Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion genkit-tools/cli/src/utils/runtime-detector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,10 @@ export function detectRuntime(): RuntimeInfo {
if (hasBunVersion || execMatchesBun || argv0MatchesBun) {
// Check if this is a Bun-compiled binary
// Bun compiled binaries have virtual paths like /$bunfs/root/...
if (argv1 && argv1.startsWith('/$bunfs/')) {
if (
argv1 &&
(argv1.startsWith('/$bunfs/') || /^[A-Za-z]:[\\/]+~BUN[\\/]+/.test(argv1))
) {
// This is a Bun-compiled binary
type = RUNTIME_COMPILED;
scriptPath = undefined;
Expand Down
13 changes: 11 additions & 2 deletions genkit-tools/cli/src/utils/spawn-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ export interface SpawnConfig {
*/
export async function validateExecutablePath(path: string): Promise<boolean> {
try {
await access(path, constants.F_OK | constants.X_OK);
// Remove surrounding quotes if present (handle quotation)
const normalizedPath =
path.startsWith('"') && path.endsWith('"') ? path.slice(1, -1) : path;
await access(normalizedPath, constants.F_OK | constants.X_OK);
return true;
} catch {
return false;
Expand Down Expand Up @@ -91,7 +94,7 @@ export function buildServerHarnessSpawnConfig(
throw new Error('Log path is required');
}

const command = runtime.execPath;
let command = runtime.execPath;
let args: string[];

if (runtime.type === 'compiled-binary') {
Expand All @@ -112,6 +115,12 @@ export function buildServerHarnessSpawnConfig(
shell: runtime.platform === 'win32',
};

// Handles spaces in the command and arguments on Windows
if (runtime.platform === 'win32') {
command = `"${command}"`;
args = args.map((arg) => `"${arg}"`);
}

return {
command,
args,
Expand Down
14 changes: 7 additions & 7 deletions genkit-tools/cli/tests/utils/spawn-config_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@ describe('spawn-config', () => {
mockLogPath
);

expect(config.command).toBe('C:\\Program Files\\nodejs\\node.exe');
expect(config.command).toBe('"C:\\Program Files\\nodejs\\node.exe"');
expect(config.args).toEqual([
'C:\\Users\\dev\\AppData\\Roaming\\npm\\node_modules\\genkit-cli\\dist\\bin\\genkit.js',
SERVER_HARNESS_COMMAND,
'4000',
'/path/to/devui.log',
'"C:\\Users\\dev\\AppData\\Roaming\\npm\\node_modules\\genkit-cli\\dist\\bin\\genkit.js"',
'"' + SERVER_HARNESS_COMMAND + '"',
'"4000"',
'"/path/to/devui.log"',
]);
expect(config.options.shell).toBe(true); // Shell enabled on Windows
});
Expand Down Expand Up @@ -180,7 +180,7 @@ describe('spawn-config', () => {
mockLogPath
);

expect(config.command).toBe('C:\\Program Files\\Bun\\bun.exe');
expect(config.command).toBe('"C:\\Program Files\\Bun\\bun.exe"');
expect(config.options.shell).toBe(true);
});
});
Expand Down Expand Up @@ -227,7 +227,7 @@ describe('spawn-config', () => {
mockLogPath
);

expect(config.command).toBe('C:\\Tools\\genkit.exe');
expect(config.command).toBe('"C:\\Tools\\genkit.exe"');
expect(config.options.shell).toBe(true);
});

Expand Down
Loading