Commit 1ffb0f8
fix: embed node version requirement at compile time (#1412)
There is for an edge case about `vp upgrade`.
If you are using an incompatible node version and you run `vp upgrade`,
it will not block your upgrading and install a broken vp cli (Node
version outside the scope of `engine.node` would prevent package manager
from downloading binary bindings)
Theoretically, the logic added in #1360 should resolve this problem, but
as the code below, the node version is read at runtime not compile time.
https://github.com/voidzero-dev/vite-plus/blob/2e2c4c6d6f56a8f42efa59ebbf25d02a0ef41c00/crates/vite_global_cli/src/js_executor.rs#L123-L128
As `vp upgrade` would delegate the cli installing task to the new
downloaded vp binary, who has no valid package.json to read, it skips
the node version's requirement check and causes this bug.
---
A solution is to inject the node version at compile time as a
enhancement for #1360.
This PR simply used `include_str!()` to read package.json and the
parsing is still at runtime. It is not the best way for performance.
`build.rs` is required if we need even better runtime performance for
it.
Co-authored-by: MK (fengmk2) <fengmk2@gmail.com>1 parent 1ad7203 commit 1ffb0f8
1 file changed
+11
-17
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
| 16 | + | |
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| |||
117 | 117 | | |
118 | 118 | | |
119 | 119 | | |
120 | | - | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | | - | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
127 | 125 | | |
128 | 126 | | |
129 | 127 | | |
| |||
256 | 254 | | |
257 | 255 | | |
258 | 256 | | |
259 | | - | |
| 257 | + | |
260 | 258 | | |
261 | 259 | | |
262 | 260 | | |
| |||
572 | 570 | | |
573 | 571 | | |
574 | 572 | | |
575 | | - | |
576 | | - | |
577 | | - | |
578 | | - | |
579 | | - | |
580 | | - | |
581 | | - | |
582 | | - | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
583 | 577 | | |
584 | 578 | | |
585 | 579 | | |
| |||
0 commit comments