Repository navigation
Conversation
|
After reviewing, I think Vite Task should document how it parses commands first, so these docs can link to it instead of describing internals. This goes beyond env prefixes: it decides cross-platform behavior and whether I'll open a vite-task issue to spec it alongside |
|
cc @wan9chi |
|
|
||
| ### Environment Variable Prefixes | ||
|
|
||
| Vite Task parses simple commands and `&&` chains itself, including environment variable prefixes such as `FOO=bar command`. These work on every platform, including Windows, without `cross-env`: |
There was a problem hiding this comment.
Shouldn't the Vite Task parsing be placed on the top of vpr docs (e.g. as a note block)?
I don't think this explanation applies to "Environment Variable Prefixes" only.
| ```json [package.json] | ||
| { | ||
| "scripts": { | ||
| "build": "NODE_ENV=production vp build" |
There was a problem hiding this comment.
Why not use a vanilla non-vp command inside the build script?
| A prefix applies only to the command it precedes. In `FOO=1 a && b`, `FOO` is set for `a` but not for `b`. | ||
|
|
||
| If any part of a command uses other shell syntax, such as pipes, redirects, or variable expansion, the whole command runs in the system shell instead: `/bin/sh -c` on macOS and Linux, and `cmd.exe /d /s /c` on Windows. In that case, `FOO=bar command` does not work on Windows, so use `cross-env` there. |
There was a problem hiding this comment.
These seem to be implementation details. It would be nice if Vite Task had documentation of these that can be linked to? Or at least it should be converted to a warning block, etc.
| - **Type:** `string | string[]` | ||
|
|
||
| Defines the shell command to run for the task. The string is interpreted by a shell, so spaces, quoting, `&&`, pipes, and redirects all work as written on the command line. | ||
| Defines the command to run for the task. Quoting, `&&`, pipes, and redirects all work as written on the command line. Vite Task runs simple commands and `&&` chains directly, and falls back to the system shell for other shell syntax. See [Environment Variable Prefixes](/guide/run#environment-variable-prefixes) for details. |
There was a problem hiding this comment.
"Work as written" isn't true on Windows when it falls back to cmd.exe (e.g. single quotes, $VAR). Same as the guide, it'd be nice to link to Vite Task docs for the parsing rules. Until then, how about:
| Defines the command to run for the task. Quoting, `&&`, pipes, and redirects all work as written on the command line. Vite Task runs simple commands and `&&` chains directly, and falls back to the system shell for other shell syntax. See [Environment Variable Prefixes](/guide/run#environment-variable-prefixes) for details. | |
| Defines the command to run for the task. Vite Task parses simple commands and `&&` chains itself, so they behave the same on every platform. Other shell syntax, such as pipes and redirects, runs in the system shell: `/bin/sh` on macOS and Linux, and `cmd.exe` on Windows. See [Environment Variable Prefixes](/guide/run#environment-variable-prefixes) for details. |
| - **Type:** `string | string[]` | ||
|
|
||
| Defines the shell command to run for the task. The string is interpreted by a shell, so spaces, quoting, `&&`, pipes, and redirects all work as written on the command line. | ||
| Defines the command to run for the task. Quoting, `&&`, pipes, and redirects all work as written on the command line. Vite Task runs simple commands and `&&` chains directly, and falls back to the system shell for other shell syntax. See [Environment Variable Prefixes](/guide/run#environment-variable-prefixes) for details. |
There was a problem hiding this comment.
Line 120 is now inconsistent: && is only split into cached sub-tasks when parsed, not on shell fallback. Array entries are always split. Maybe update it too?
|
@jong-kyung How should we proceed? I would love to out-link Vite Task behaviors as mentioned above. The PR can be polished for review once it is decided. |
|
Personally, I think it would be better not to link to the Vite Task docs |
|
Thanks for the quick reply. We'll drop the detailed Vite Task behavior and keep the PR focused on:
|
Closes #3140
FOO=bar commandworks on Windows withoutcross-envfor commands Vite Task parses directly.&&chains./bin/sh -c/cmd.exe /d /s /c) and that it applies to the whole command.commandreference, which implied every command runs through a shell.Behavior is based on the vite-task source (
9ba4cc9, linked in the issue). Not tested on Windows.