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.
There was a problem hiding this comment.
Moved to an info block at the top of the page.
| ```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.
There was a problem hiding this comment.
Dropped the shell details and the Vite Task link per the discussion, and replaced them with a short warning that points to cross-env.
| - **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. |
There was a problem hiding this comment.
Applied your suggestion without the /bin/sh / cmd.exe part to keep internals out. Verified on Windows; see the updated PR description.
| - **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?
There was a problem hiding this comment.
Updated line 120, and the matching sentence in Compound Commands in the guide.
|
@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:
|
- Move the note that Vite Task parses simple commands to the top of the run guide - Use a non-`vp` command in the env prefix example - Replace shell fallback internals with a short warning that points to `cross-env` - Reword the `command` reference and the `&&` sub-task notes to match
hyunbinseo
left a comment
There was a problem hiding this comment.
- Consistency. Reuse a single well phrased Vite Task explanation. (e.g. in a blockquote form)
- Generalization. The vanilla Vite docs does mention
dotenv-expandbut it's purely because its codes are used. Here, Vite Task handles it by itself.cross-envand Windows can be mentioned as an example but it can be shortened and generalized.
| - **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. Vite Task parses simple commands and `&&` chains itself, so they behave the same on every platform. Other shell syntax, such as pipes and redirects, may behave differently across platforms. See [Environment Variable Prefixes](/guide/run#environment-variable-prefixes) for details. |
There was a problem hiding this comment.
Why not drop [Environment Variable Prefixes] hyperlink? It only illustrates a single example.
| Each task defined in `vite.config.ts` must include its own `command`. You cannot define a task in both `vite.config.ts` and `package.json` with the same task name. | ||
|
|
||
| Commands joined with `&&` (or supplied as an array) are automatically split into independently cached sub-tasks. See [Compound Commands](/guide/run#compound-commands). | ||
| Array entries, and `&&` chains without other shell syntax, are automatically split into independently cached sub-tasks. See [Compound Commands](/guide/run#compound-commands). |
There was a problem hiding this comment.
Inconsistent hyperlink with what guide/run.md uses this. What is the correct one?
[`&&` chains](#compound-commands)There was a problem hiding this comment.
Kept the existing See [Compound Commands] link and removed the inline one.
| `vpr` is available as a standalone shorthand for `vp run`. All examples below work with both `vp run` and `vpr`. | ||
| ::: | ||
|
|
||
| ::: info |
There was a problem hiding this comment.
Why not make it identical to config/run.md? So similar yet different in few words.
Also, can't we use the same block syntax in that file as well? Seems much cleaner.
Defines the command to run for the task.
::: info
...|
|
||
| ### Environment Variable Prefixes | ||
|
|
||
| Because Vite Task parses simple commands itself, environment variable prefixes such as `FOO=bar command` work on every platform, including Windows, without `cross-env`: |
There was a problem hiding this comment.
cross-env is a third party package. Can we emphasize that it's an example?
There was a problem hiding this comment.
Changed to "extra tools like cross-env".
| A prefix applies only to the command it directly precedes. In `FOO=1 a && b`, `FOO` is set for `a` but not for `b`. | ||
|
|
||
| ::: warning | ||
| If a command also uses other shell syntax, such as pipes or redirects, environment variable prefixes may not work on Windows. Verify such commands at runtime, and use `cross-env` if needed. |
There was a problem hiding this comment.
Why not tighten and make it more general.
|
Thanks! Moved the explanation into a shared info block and generalized the prefix section. |
Closes #3140
&&chains itself, so they behave the same on every platform.FOO=bar commandworks on Windows withoutcross-env.&&chains are split into cached sub-tasks only when they don't use other shell syntax.commandreference, which implied every command runs through a shell.Shell fallback details are intentionally left out, per the discussion above.
Verified on Windows 11 with vite-plus 1.4.0: prefixes work in simple commands and
&&chains and apply only to the next command. With a pipe, the prefix fails undercmd.exeand the&&chain is not split into sub-tasks.