Skip to content

Commit 26a882b

Browse files
committed
fix(plan): add shell arguments for shell fallback execution
1 parent 006de3f commit 26a882b

8 files changed

Lines changed: 201 additions & 38 deletions

File tree

crates/vite_task_plan/src/plan.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,9 @@ async fn plan_task_as_execution_node(
239239
}
240240
});
241241

242+
static SHELL_ARGS: &[&str] =
243+
if cfg!(target_os = "windows") { &["/d", "/s", "/c"] } else { &["-c"] };
244+
242245
let mut script = Str::from(command_str);
243246
for arg in context.extra_args().iter() {
244247
script.push(' ');
@@ -266,7 +269,7 @@ async fn plan_task_as_execution_node(
266269
&task_node.resolved_config.resolved_options,
267270
context.envs(),
268271
Arc::clone(&*SHELL_PROGRAM_PATH),
269-
Arc::new([script]),
272+
Arc::from_iter(SHELL_ARGS.iter().map(|s| Str::from(*s)).chain(std::iter::once(script))),
270273
)
271274
.with_plan_context(&context)?;
272275
items.push(ExecutionItem {

crates/vite_task_plan/tests/plan_snapshots/fixtures/cache-sharing/snapshots/task graph.snap

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
2-
source: crates/vite_task_bin/tests/test_snapshots/main.rs
2+
source: crates/vite_task_plan/tests/plan_snapshots/main.rs
33
expression: task_graph_json
4-
input_file: crates/vite_task_bin/tests/test_snapshots/fixtures/cache-sharing
4+
input_file: crates/vite_task_plan/tests/plan_snapshots/fixtures/cache-sharing
55
---
66
[
77
{
@@ -11,7 +11,7 @@ input_file: crates/vite_task_bin/tests/test_snapshots/fixtures/cache-sharing
1111
],
1212
"node": {
1313
"task_display": {
14-
"package_name": "@test/cache-sharing",
14+
"package_name": "@test/cache-<os_shell_name>aring",
1515
"task_name": "a",
1616
"package_path": "<workspace>/"
1717
},
@@ -39,7 +39,7 @@ input_file: crates/vite_task_bin/tests/test_snapshots/fixtures/cache-sharing
3939
],
4040
"node": {
4141
"task_display": {
42-
"package_name": "@test/cache-sharing",
42+
"package_name": "@test/cache-<os_shell_name>aring",
4343
"task_name": "b",
4444
"package_path": "<workspace>/"
4545
},
@@ -67,7 +67,7 @@ input_file: crates/vite_task_bin/tests/test_snapshots/fixtures/cache-sharing
6767
],
6868
"node": {
6969
"task_display": {
70-
"package_name": "@test/cache-sharing",
70+
"package_name": "@test/cache-<os_shell_name>aring",
7171
"task_name": "c",
7272
"package_path": "<workspace>/"
7373
},

crates/vite_task_plan/tests/plan_snapshots/fixtures/comprehensive-task-graph/snapshots/task graph.snap

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
2-
source: crates/vite_task_bin/tests/test_snapshots/main.rs
2+
source: crates/vite_task_plan/tests/plan_snapshots/main.rs
33
expression: task_graph_json
4-
input_file: crates/vite_task_bin/tests/test_snapshots/fixtures/comprehensive-task-graph
4+
input_file: crates/vite_task_plan/tests/plan_snapshots/fixtures/comprehensive-task-graph
55
---
66
[
77
{
@@ -40,7 +40,7 @@ input_file: crates/vite_task_bin/tests/test_snapshots/fixtures/comprehensive-tas
4040
],
4141
[
4242
[
43-
"<workspace>/packages/shared",
43+
"<workspace>/packages/<os_shell_name>ared",
4444
"build"
4545
],
4646
"Topological"
@@ -132,7 +132,7 @@ input_file: crates/vite_task_bin/tests/test_snapshots/fixtures/comprehensive-tas
132132
"neighbors": [
133133
[
134134
[
135-
"<workspace>/packages/shared",
135+
"<workspace>/packages/<os_shell_name>ared",
136136
"test"
137137
],
138138
"Topological"
@@ -182,7 +182,7 @@ input_file: crates/vite_task_bin/tests/test_snapshots/fixtures/comprehensive-tas
182182
],
183183
[
184184
[
185-
"<workspace>/packages/shared",
185+
"<workspace>/packages/<os_shell_name>ared",
186186
"build"
187187
],
188188
"Topological"
@@ -331,7 +331,7 @@ input_file: crates/vite_task_bin/tests/test_snapshots/fixtures/comprehensive-tas
331331
],
332332
[
333333
[
334-
"<workspace>/packages/shared",
334+
"<workspace>/packages/<os_shell_name>ared",
335335
"test"
336336
],
337337
"Topological"
@@ -413,7 +413,7 @@ input_file: crates/vite_task_bin/tests/test_snapshots/fixtures/comprehensive-tas
413413
"package_path": "<workspace>/packages/pkg#special"
414414
},
415415
"resolved_config": {
416-
"command": "echo Building package with hash",
416+
"command": "echo Building package with ha<os_shell_name>",
417417
"resolved_options": {
418418
"cwd": "<workspace>/packages/pkg#special",
419419
"cache_config": {
@@ -430,7 +430,7 @@ input_file: crates/vite_task_bin/tests/test_snapshots/fixtures/comprehensive-tas
430430
"neighbors": [
431431
[
432432
[
433-
"<workspace>/packages/shared",
433+
"<workspace>/packages/<os_shell_name>ared",
434434
"build"
435435
],
436436
"Topological"
@@ -449,7 +449,7 @@ input_file: crates/vite_task_bin/tests/test_snapshots/fixtures/comprehensive-tas
449449
"package_path": "<workspace>/packages/pkg#special"
450450
},
451451
"resolved_config": {
452-
"command": "echo Testing package with hash",
452+
"command": "echo Testing package with ha<os_shell_name>",
453453
"resolved_options": {
454454
"cwd": "<workspace>/packages/pkg#special",
455455
"cache_config": {
@@ -466,7 +466,7 @@ input_file: crates/vite_task_bin/tests/test_snapshots/fixtures/comprehensive-tas
466466
"neighbors": [
467467
[
468468
[
469-
"<workspace>/packages/shared",
469+
"<workspace>/packages/<os_shell_name>ared",
470470
"test"
471471
],
472472
"Topological"
@@ -475,19 +475,19 @@ input_file: crates/vite_task_bin/tests/test_snapshots/fixtures/comprehensive-tas
475475
},
476476
{
477477
"key": [
478-
"<workspace>/packages/shared",
478+
"<workspace>/packages/<os_shell_name>ared",
479479
"build"
480480
],
481481
"node": {
482482
"task_display": {
483-
"package_name": "@test/shared",
483+
"package_name": "@test/<os_shell_name>ared",
484484
"task_name": "build",
485-
"package_path": "<workspace>/packages/shared"
485+
"package_path": "<workspace>/packages/<os_shell_name>ared"
486486
},
487487
"resolved_config": {
488-
"command": "echo Cleaning && echo Compiling shared && echo Generating types",
488+
"command": "echo Cleaning && echo Compiling <os_shell_name>ared && echo Generating types",
489489
"resolved_options": {
490-
"cwd": "<workspace>/packages/shared",
490+
"cwd": "<workspace>/packages/<os_shell_name>ared",
491491
"cache_config": {
492492
"env_config": {
493493
"fingerprinted_envs": [],
@@ -503,19 +503,19 @@ input_file: crates/vite_task_bin/tests/test_snapshots/fixtures/comprehensive-tas
503503
},
504504
{
505505
"key": [
506-
"<workspace>/packages/shared",
506+
"<workspace>/packages/<os_shell_name>ared",
507507
"lint"
508508
],
509509
"node": {
510510
"task_display": {
511-
"package_name": "@test/shared",
511+
"package_name": "@test/<os_shell_name>ared",
512512
"task_name": "lint",
513-
"package_path": "<workspace>/packages/shared"
513+
"package_path": "<workspace>/packages/<os_shell_name>ared"
514514
},
515515
"resolved_config": {
516-
"command": "echo Linting shared",
516+
"command": "echo Linting <os_shell_name>ared",
517517
"resolved_options": {
518-
"cwd": "<workspace>/packages/shared",
518+
"cwd": "<workspace>/packages/<os_shell_name>ared",
519519
"cache_config": {
520520
"env_config": {
521521
"fingerprinted_envs": [],
@@ -531,19 +531,19 @@ input_file: crates/vite_task_bin/tests/test_snapshots/fixtures/comprehensive-tas
531531
},
532532
{
533533
"key": [
534-
"<workspace>/packages/shared",
534+
"<workspace>/packages/<os_shell_name>ared",
535535
"test"
536536
],
537537
"node": {
538538
"task_display": {
539-
"package_name": "@test/shared",
539+
"package_name": "@test/<os_shell_name>ared",
540540
"task_name": "test",
541-
"package_path": "<workspace>/packages/shared"
541+
"package_path": "<workspace>/packages/<os_shell_name>ared"
542542
},
543543
"resolved_config": {
544544
"command": "echo Setting up test env && echo Running tests && echo Cleanup",
545545
"resolved_options": {
546-
"cwd": "<workspace>/packages/shared",
546+
"cwd": "<workspace>/packages/<os_shell_name>ared",
547547
"cache_config": {
548548
"env_config": {
549549
"fingerprinted_envs": [],
@@ -559,19 +559,19 @@ input_file: crates/vite_task_bin/tests/test_snapshots/fixtures/comprehensive-tas
559559
},
560560
{
561561
"key": [
562-
"<workspace>/packages/shared",
562+
"<workspace>/packages/<os_shell_name>ared",
563563
"typecheck"
564564
],
565565
"node": {
566566
"task_display": {
567-
"package_name": "@test/shared",
567+
"package_name": "@test/<os_shell_name>ared",
568568
"task_name": "typecheck",
569-
"package_path": "<workspace>/packages/shared"
569+
"package_path": "<workspace>/packages/<os_shell_name>ared"
570570
},
571571
"resolved_config": {
572-
"command": "echo Type checking shared",
572+
"command": "echo Type checking <os_shell_name>ared",
573573
"resolved_options": {
574-
"cwd": "<workspace>/packages/shared",
574+
"cwd": "<workspace>/packages/<os_shell_name>ared",
575575
"cache_config": {
576576
"env_config": {
577577
"fingerprinted_envs": [],
@@ -678,7 +678,7 @@ input_file: crates/vite_task_bin/tests/test_snapshots/fixtures/comprehensive-tas
678678
"neighbors": [
679679
[
680680
[
681-
"<workspace>/packages/shared",
681+
"<workspace>/packages/<os_shell_name>ared",
682682
"build"
683683
],
684684
"Topological"
@@ -714,7 +714,7 @@ input_file: crates/vite_task_bin/tests/test_snapshots/fixtures/comprehensive-tas
714714
"neighbors": [
715715
[
716716
[
717-
"<workspace>/packages/shared",
717+
"<workspace>/packages/<os_shell_name>ared",
718718
"lint"
719719
],
720720
"Topological"
@@ -778,7 +778,7 @@ input_file: crates/vite_task_bin/tests/test_snapshots/fixtures/comprehensive-tas
778778
"neighbors": [
779779
[
780780
[
781-
"<workspace>/packages/shared",
781+
"<workspace>/packages/<os_shell_name>ared",
782782
"test"
783783
],
784784
"Topological"
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"scripts": {
3+
"pipe-test": "echo hello | node -e \"process.stdin.pipe(process.stdout)\""
4+
}
5+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[[plan]]
2+
name = "shell fallback for pipe command"
3+
args = ["run", "pipe-test"]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
---
2+
source: crates/vite_task_plan/tests/plan_snapshots/main.rs
3+
expression: "&plan_json"
4+
input_file: crates/vite_task_plan/tests/plan_snapshots/fixtures/shell-fallback
5+
---
6+
{
7+
"root_node": {
8+
"Expanded": [
9+
{
10+
"key": [
11+
"<workspace>/",
12+
"pipe-test"
13+
],
14+
"node": {
15+
"task_display": {
16+
"package_name": "",
17+
"task_name": "pipe-test",
18+
"package_path": "<workspace>/"
19+
},
20+
"items": [
21+
{
22+
"execution_item_display": {
23+
"task_display": {
24+
"package_name": "",
25+
"task_name": "pipe-test",
26+
"package_path": "<workspace>/"
27+
},
28+
"command": "echo hello | node -e \"process.stdin.pipe(process.stdout)\"",
29+
"and_item_index": null,
30+
"cwd": "<workspace>/"
31+
},
32+
"kind": {
33+
"Leaf": {
34+
"Spawn": {
35+
"cache_metadata": {
36+
"spawn_fingerprint": {
37+
"cwd": "",
38+
"program_fingerprint": {
39+
"OutsideWorkspace": {
40+
"program_name": "<os_shell_name>"
41+
}
42+
},
43+
"args": [
44+
"<os_shell_args>",
45+
"echo hello | node -e \"process.stdin.pipe(process.stdout)\""
46+
],
47+
"env_fingerprints": {
48+
"fingerprinted_envs": {},
49+
"pass_through_env_config": [
50+
"<default pass-through envs>"
51+
]
52+
},
53+
"fingerprint_ignores": null
54+
},
55+
"execution_cache_key": {
56+
"kind": {
57+
"UserTask": {
58+
"task_name": "pipe-test",
59+
"and_item_index": 0,
60+
"extra_args": []
61+
}
62+
},
63+
"origin_path": ""
64+
}
65+
},
66+
"spawn_command": {
67+
"program_path": "<os_<os_shell_name>ell_path>",
68+
"args": [
69+
"<os_shell_args>",
70+
"echo hello | node -e \"process.stdin.pipe(process.stdout)\""
71+
],
72+
"all_envs": {
73+
"NO_COLOR": "1",
74+
"PATH": "<workspace>/node_modules/.bin:<tools>/node_modules/.bin"
75+
},
76+
"cwd": "<workspace>/"
77+
}
78+
}
79+
}
80+
}
81+
}
82+
]
83+
},
84+
"neighbors": []
85+
}
86+
]
87+
}
88+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
---
2+
source: crates/vite_task_plan/tests/plan_snapshots/main.rs
3+
assertion_line: 106
4+
expression: task_graph_json
5+
input_file: crates/vite_task_plan/tests/plan_snapshots/fixtures/shell-fallback
6+
---
7+
[
8+
{
9+
"key": [
10+
"<workspace>/",
11+
"pipe-test"
12+
],
13+
"node": {
14+
"task_display": {
15+
"package_name": "",
16+
"task_name": "pipe-test",
17+
"package_path": "<workspace>/"
18+
},
19+
"resolved_config": {
20+
"command": "echo hello | node -e \"process.stdin.pipe(process.stdout)\"",
21+
"resolved_options": {
22+
"cwd": "<workspace>/",
23+
"cache_config": {
24+
"env_config": {
25+
"fingerprinted_envs": [],
26+
"pass_through_envs": [
27+
"<default pass-through envs>"
28+
]
29+
}
30+
}
31+
}
32+
}
33+
},
34+
"neighbors": []
35+
}
36+
]

0 commit comments

Comments
 (0)