Skip to content

Commit

Permalink
fix: running commands with spaces on windows (#715)
Browse files Browse the repository at this point in the history
Closes #692
  • Loading branch information
vladfrangu committed Dec 24, 2024
1 parent 9822755 commit 44e3956
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/lib/exec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { type SpawnOptions, type SpawnOptionsWithoutStdio, spawn } from 'node:child_process';
import { isAbsolute } from 'node:path';

import { run } from './outputs.js';

Expand All @@ -11,8 +12,10 @@ const windowsOptions: SpawnOptions = {
* Run child process and returns stdout and stderr to user stout
*/
const spawnPromised = async (cmd: string, args: string[], opts: SpawnOptionsWithoutStdio) => {
const escapedCommand = isAbsolute(cmd) && process.platform === 'win32' ? `"${cmd}"` : cmd;

// NOTE: Pipes stderr, stdout to main process
const childProcess = spawn(cmd, args, {
const childProcess = spawn(escapedCommand, args, {
...opts,
stdio: process.env.APIFY_NO_LOGS_IN_TESTS ? 'ignore' : 'inherit',
...(process.platform === 'win32' ? windowsOptions : {}),
Expand Down
31 changes: 31 additions & 0 deletions test/commands/windows/create.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { existsSync } from 'node:fs';

import { useTempPath } from '../../__setup__/hooks/useTempPath.js';

const actName = 'create-my-spaced-actor';
const { beforeAllCalls, afterAllCalls, joinPath } = useTempPath('spaced actor', {
create: true,
remove: true,
cwd: true,
cwdParent: false,
});

const { CreateCommand } = await import('../../../src/commands/create.js');

describe.runIf(process.env.FORCE_WINDOWS_TESTS || process.platform === 'win32')('apify create on windows', () => {
beforeEach(async () => {
await beforeAllCalls();
});

afterEach(async () => {
await afterAllCalls();
});

it('works for creating an actor when the folder path contains spaces', async () => {
const ACT_TEMPLATE = 'python-playwright';
await CreateCommand.run([actName, '--template', ACT_TEMPLATE], import.meta.url);

// check files structure
expect(existsSync(joinPath(actName))).toBeTruthy();
});
});

0 comments on commit 44e3956

Please sign in to comment.