Skip to content

Commit d1c207a

Browse files
authored
fix: running commands with spaces on windows (#715)
Closes #692
1 parent 7a637b3 commit d1c207a

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

src/lib/exec.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { type SpawnOptions, type SpawnOptionsWithoutStdio, spawn } from 'node:child_process';
2+
import { isAbsolute } from 'node:path';
23

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

@@ -11,8 +12,10 @@ const windowsOptions: SpawnOptions = {
1112
* Run child process and returns stdout and stderr to user stout
1213
*/
1314
const spawnPromised = async (cmd: string, args: string[], opts: SpawnOptionsWithoutStdio) => {
15+
const escapedCommand = isAbsolute(cmd) && process.platform === 'win32' ? `"${cmd}"` : cmd;
16+
1417
// NOTE: Pipes stderr, stdout to main process
15-
const childProcess = spawn(cmd, args, {
18+
const childProcess = spawn(escapedCommand, args, {
1619
...opts,
1720
stdio: process.env.APIFY_NO_LOGS_IN_TESTS ? 'ignore' : 'inherit',
1821
...(process.platform === 'win32' ? windowsOptions : {}),
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { existsSync } from 'node:fs';
2+
3+
import { useTempPath } from '../../__setup__/hooks/useTempPath.js';
4+
5+
const actName = 'create-my-spaced-actor';
6+
const { beforeAllCalls, afterAllCalls, joinPath } = useTempPath('spaced actor', {
7+
create: true,
8+
remove: true,
9+
cwd: true,
10+
cwdParent: false,
11+
});
12+
13+
const { CreateCommand } = await import('../../../src/commands/create.js');
14+
15+
describe.runIf(process.env.FORCE_WINDOWS_TESTS || process.platform === 'win32')('apify create on windows', () => {
16+
beforeEach(async () => {
17+
await beforeAllCalls();
18+
});
19+
20+
afterEach(async () => {
21+
await afterAllCalls();
22+
});
23+
24+
it('works for creating an actor when the folder path contains spaces', async () => {
25+
const ACT_TEMPLATE = 'python-playwright';
26+
await CreateCommand.run([actName, '--template', ACT_TEMPLATE], import.meta.url);
27+
28+
// check files structure
29+
expect(existsSync(joinPath(actName))).toBeTruthy();
30+
});
31+
});

0 commit comments

Comments
 (0)