Skip to content

Commit d58d1a9

Browse files
committed
fix: use cmd.exe /c on windows to spawn npm/pnpm safely without shell: true
1 parent fb2a79a commit d58d1a9

File tree

2 files changed

+21
-17
lines changed

2 files changed

+21
-17
lines changed

src/workspace-dev.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -189,17 +189,19 @@ export class WorkspaceDevRunner {
189189
}
190190
this.visiting[node] = true;
191191

192-
const child = spawn(
193-
process.platform === 'win32' ? 'npm.cmd' : 'npm',
194-
['run', command],
195-
{
196-
cwd: path,
197-
env: {
198-
...process.env,
199-
FORCE_COLOR: '3',
200-
},
192+
const spawnCommand = process.platform === 'win32' ? 'cmd.exe' : 'npm';
193+
const spawnArgs =
194+
process.platform === 'win32'
195+
? ['/c', 'npm', 'run', command]
196+
: ['run', command];
197+
198+
const child = spawn(spawnCommand, spawnArgs, {
199+
cwd: path,
200+
env: {
201+
...process.env,
202+
FORCE_COLOR: '3',
201203
},
202-
);
204+
});
203205

204206
child.stdout.on('data', async (data) => {
205207
const stdout = data.toString();

test/index.pw.test.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@ test('should run dev succeed', async ({ page }) => {
1414
let testCompleted = false;
1515
let serverStarted = false;
1616

17-
const child = spawn(
18-
process.platform === 'win32' ? 'pnpm.cmd' : 'pnpm',
19-
['run', 'dev'],
20-
{
21-
cwd,
22-
},
23-
);
17+
const command = process.platform === 'win32' ? 'cmd.exe' : 'pnpm';
18+
const args =
19+
process.platform === 'win32'
20+
? ['/c', 'pnpm', 'run', 'dev']
21+
: ['run', 'dev'];
22+
23+
const child = spawn(command, args, {
24+
cwd,
25+
});
2426

2527
child.stdout.on('data', async (data) => {
2628
const output = data.toString();

0 commit comments

Comments
 (0)