Skip to content

Commit a307cbe

Browse files
lofczfengmk2
andauthored
fix(core): vp dev crashes on startup when experimental.bundledDev is enabled (#2384)
The core build rewrites `CLIENT_ENTRY` and `ENV_ENTRY` to `dist/vite/client/`, but left `BUNDLED_DEV_CLIENT_ENTRY` at `dist/client/bundledDevClient.mjs`. Vite reads that path with `fs.readFileSync`, so `vp dev` with `experimental.bundledDev: true` fails at startup with `ENOENT`. Rewrite the constant to the packaged layout and document it in `BUNDLING.md`. Add a PTY snapshot case (`command_dev_bundled_dev`) that starts `vp dev` with `experimental.bundledDev` enabled; it fails without the rewrite and passes with it. `vp dev` with `experimental.bundledDev: true`, before: ``` error when starting dev server: Error: ENOENT: no such file or directory, open '/path/to/project/node_modules/@voidzero-dev/vite-plus-core/dist/client/bundledDevClient.mjs' at Object.readFileSync (node:fs:484:20) at getHmrImplementation (…/dist/vite/node/chunks/node.js) at BundledDev.listen (…/dist/vite/node/chunks/node.js) ``` After: ``` VITE+ v0.2.8 ➜ Local: http://localhost:5173/ ➜ Network: use --host to expose ``` --------- Co-authored-by: MK <fengmk2@gmail.com>
1 parent f07e7ff commit a307cbe

8 files changed

Lines changed: 83 additions & 1 deletion

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<!doctype html>
2+
<html>
3+
<body>
4+
<div id="app"></div>
5+
<script type="module" src="/src/main.ts"></script>
6+
</body>
7+
</html>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"name": "command-dev-bundled-dev-test",
3+
"private": true
4+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Regression test for PR #2384: the core build rewrites CLIENT_ENTRY and
2+
# ENV_ENTRY to dist/vite/client/, but it left BUNDLED_DEV_CLIENT_ENTRY at
3+
# dist/client/. With `experimental.bundledDev` enabled, Vite reads that
4+
# path with fs.readFileSync, so `vp dev` fails at startup with ENOENT.
5+
[[case]]
6+
name = "command_dev_bundled_dev"
7+
vp = "local"
8+
skip-platforms = ["windows"]
9+
steps = [
10+
{ argv = ["vp", "dev", "--host", "127.0.0.1", "--port", "0"], comment = "dev server with experimental.bundledDev enabled starts and serves the bundled dev client", continue-on-failure = true, interactions = [
11+
{ "expect-milestone" = "dev-server:ready" },
12+
{ "write-key" = "ctrl-c" },
13+
] },
14+
]
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# command_dev_bundled_dev
2+
3+
## `vp dev --host 127.0.0.1 --port 0`
4+
5+
dev server with experimental.bundledDev enabled starts and serves the bundled dev client
6+
7+
**Exit code:** 130
8+
9+
**→ expect-milestone:** `dev-server:ready`
10+
11+
```
12+
13+
VITE+ <version>
14+
15+
➜ Local: http://127.0.0.1:<port>/
16+
➜ press h + enter to show help
17+
```
18+
19+
**← write-key:** `ctrl-c`
20+
21+
```
22+
23+
VITE+ <version>
24+
25+
➜ Local: http://127.0.0.1:<port>/
26+
➜ press h + enter to show help
27+
28+
```
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
document.querySelector('#app')!.textContent = 'hello';
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
export default {
2+
clearScreen: false,
3+
experimental: {
4+
bundledDev: true,
5+
},
6+
plugins: [
7+
{
8+
name: 'dev-server-ready-milestone',
9+
configureServer(server) {
10+
server.httpServer?.once('listening', () => {
11+
// Let Vite print its startup banner after server.listen() resolves.
12+
setImmediate(() => {
13+
const name = Buffer.from('dev-server:ready').toString('base64url');
14+
process.stdout.write(`\x1b]2;pty-terminal-test:${'0'.repeat(32)}:${name}\x1b\\`);
15+
});
16+
});
17+
},
18+
},
19+
],
20+
};

packages/core/BUNDLING.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ This is the most complex step, using the upstream `vite-rolldown.config` with mo
5555

5656
1. **Filter externals** - Bundles `picomatch`, `tinyglobby`, `fdir`, `rolldown`, `yaml` instead of keeping them external
5757
2. **Add RewriteImportsPlugin** - Rewrites vite/rolldown imports at build time
58-
3. **Rewrite static paths** - Fixes `VITE_PACKAGE_DIR`, `CLIENT_ENTRY`, `ENV_ENTRY` constants
58+
3. **Rewrite static paths** - Fixes `VITE_PACKAGE_DIR`, `CLIENT_ENTRY`, `BUNDLED_DEV_CLIENT_ENTRY`, `ENV_ENTRY` constants
5959
4. **Copy additional files** - `misc/`, `.d.ts` files, `types/`, `client.d.ts`
6060

6161
**Input**: `vite/packages/vite/`
@@ -219,6 +219,7 @@ dist/
219219
│ │ ├── module-runner.js
220220
│ │ └── chunks/
221221
│ ├── client/
222+
│ │ ├── bundledDevClient.mjs
222223
│ │ ├── client.mjs
223224
│ │ └── env.mjs
224225
│ ├── misc/

packages/core/build.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,13 @@ async function buildVite() {
180180
)`,
181181
`export const CLIENT_ENTRY = path.join(VITE_PACKAGE_DIR, 'dist/vite/client/client.mjs')`,
182182
);
183+
magicString.replace(
184+
`export const BUNDLED_DEV_CLIENT_ENTRY: string = resolve(
185+
VITE_PACKAGE_DIR,
186+
'dist/client/bundledDevClient.mjs',
187+
)`,
188+
`export const BUNDLED_DEV_CLIENT_ENTRY = path.join(VITE_PACKAGE_DIR, 'dist/vite/client/bundledDevClient.mjs')`,
189+
);
183190
magicString.replace(
184191
`export const ENV_ENTRY: string = resolve(
185192
VITE_PACKAGE_DIR,

0 commit comments

Comments
 (0)