Repository navigation
fix(cli): respect Vite dev server config host+port - #2379
Conversation
|
/bigbonk review for issues |
commit: |
|
Performance benchmarksCompared 0 improved · 0 regressed · 6 within ±1.5%
View detailed results and traces 🟢 improvement · 🔴 regression · ⚫ change below 1.5% · paired base/head |
There was a problem hiding this comment.
Review: respect Vite dev server config
I reviewed the change end-to-end (read cli.ts, cli-dev-config.ts, dev-lockfile.ts, ran the PR tests + vp check, and empirically validated the Vite config-hook precedence with a Vite 8 resolveConfig harness). Overall this is a clean, well-scoped fix that does what the PR description claims. Tests and checks pass locally.
What works well
- Precedence is correct. I verified empirically against Vite 8
resolveConfig:- No CLI flags + values in
vite.config.ts→ config values are respected (e.g.5555/config.example.test). - CLI flags present → they override the config (e.g.
--port 4000 --hostname 0.0.0.0wins). - Nothing set anywhere → vinext defaults (
3000/localhost) win, not Vite's default5173. The?? 3000/?? "localhost"fallbacks inapplyDevServerDefaultsare load-bearing here — without them users would silently get5173. Good catch keeping the vinext default.
- No CLI flags + values in
normalizeDevServerHostnamecorrectly maps Vite'shost: true→0.0.0.0andfalse/undefined→localhost, matching Vite semantics and the existing wildcard-display logic.- Lockfile safety. The new intermediate
update()betweencreateServer()andlisten()is safe:release()keys off the owner PID, so a laterrelease()in thecatchstill cleans up correctly regardless of intervening updates. - Field shapes line up:
parseArgsreturns{ port?, hostname? }, exactly matchingDevServerCliOptions, so passingparseddirectly is fine.
Issues / suggestions
1. (minor, edge case) CLI flags can be overridden by a user config hook ordered after the vinext plugin.
The plugin applies CLI flags inside a config hook with order: "post". If a user's own plugin also uses a config hook with order: "post" and resolves after the vinext plugin, it overrides the explicit CLI flags. I confirmed this with a harness:
plugins: [createDevServerConfigPlugin({ port: 4000 }), userPostPlugin /* sets 9999 */]
=> resolved server.port = 9999 // CLI --port 4000 lost
In the real dev() path the vinext plugin is pushed last into the inline config, which makes this unlikely in practice, but it's a real divergence from "CLI flags are highest precedence." The PR's own test only passes because the vinext plugin is positioned last in the array. This is probably acceptable as a known limitation, but worth a one-line comment noting that CLI-flag precedence relies on the vinext plugin running last among post config hooks.
2. (nit) enforce: "post" is redundant for a config hook. Config-hook ordering is governed by the hook's own order: "post", not the plugin's enforce. The enforce: "post" doesn't affect the config hook here. Harmless, but it can be dropped to avoid implying it controls config ordering.
3. (nit) The intermediate lockfile update() is largely redundant with the post-listen update — it only matters in the brief window before listen() resolves. Not a problem, just noting it adds a third write path; fine to keep for accuracy during startup.
Verification
vp test run tests/cli-dev-config.test.ts tests/cli-args.test.ts tests/dev-lockfile.test.ts→ 79 passedvp check packages/vinext/src/cli.ts packages/vinext/src/cli-dev-config.ts tests/cli-dev-config.test.ts→ clean (format, lint, types)
No blocking issues. The two nits and the edge-case note are optional. LGTM with a suggestion to document the precedence assumption in #1.
|
Review posted to PR #2379. SummaryI reviewed PR #2379 ( Verdict: LGTM, no blocking issues. Tests (79 passed) and checks (format/lint/types) are clean. Key findings:
Non-blocking notes I raised:
|
|
/bigbonk review for issues |
There was a problem hiding this comment.
Review: respect Vite dev server config (re-review @ 82311ee)
I re-reviewed the latest state including the new 82311ee ("docs(cli): clarify Vite config hook ordering"). I read cli.ts, cli-dev-config.ts, dev-lockfile.ts, cli-args.ts, ran the PR tests + vp check, and empirically validated the plugin-ordering precedence against @voidzero-dev/vite-plus-core (Vite 8) resolveConfig in the real-world shape (user plugin loaded via configFile, vinext plugin appended to the inline config).
Verdict: LGTM, no blocking issues. vp check is clean (format/lint/types) and the targeted tests pass (79 passed).
Verification
vp test run tests/cli-dev-config.test.ts tests/cli-args.test.ts tests/dev-lockfile.test.ts→ 79 passedvp check packages/vinext/src/cli.ts packages/vinext/src/cli-dev-config.ts tests/cli-dev-config.test.ts→ clean
What's correct
- Precedence holds in the real path. I reproduced the actual
dev()shape: uservite.configexports a plugin withenforce: "post"+ aconfighook withorder: "post"that setsport: 9999, and vinext's plugin is appended to the inline config. Result:server.port = 4000,host = 127.0.0.1— CLI flags win even against a maximally-aggressive userpostplugin. The combination of inline placement +enforce: "post"+config order: "post"is what makes vinext run last. ?? 3000/?? "localhost"are load-bearing — without them users silently get Vite's5173default. Good.normalizeDevServerHostnamemapstrue → 0.0.0.0,false/undefined → localhost, matching Vite semantics and the wildcard-display substitution.- Lockfile safety.
release()keys off the PID captured at acquire time (dev-lockfile.ts:243), so the new intermediateupdate()betweencreateServer()andlisten()cannot break cleanup on alisten()failure. Confirmed. - Type shape.
ParsedArgs({ port?: number; hostname?: string; ... }) structurally satisfiesDevServerCliOptions, so passingparseddirectly is sound; the extra fields are ignored. - The new
82311eecomment incli-dev-config.tsaccurately documents the two-level ordering requirement, and the addedcreateDevServerConfigPlugintest exercises the late-user-config case. This resolves the precedence-documentation concern from the prior review.
One correction to the prior review
The earlier review's nit #2 — "enforce: "post" is redundant for a config hook" — is incorrect. It only holds for plugins in the same inline array. In the actual dev() path the user's plugins are loaded from configFile and vinext's plugin is appended to the inline config. I verified empirically:
- vinext plugin without
enforce: "post"(configorder: "post"only), userpostplugin viaconfigFile→ resolvedport = 9999(CLI flag lost). - vinext plugin with
enforce: "post"→ resolvedport = 4000(CLI flag wins).
So enforce: "post" is load-bearing, not redundant — it's required to order vinext's config hook after a user's config-file plugin that also enforces post. The new comment in cli-dev-config.ts ("Both levels are required…") captures this correctly. Do not drop enforce: "post".
Non-blocking nits
- The intermediate lockfile
update()(beforelisten()) writes the configured port, which the post-listenupdate()later corrects to the actual bound port. Redundant but intentional/harmless for startup accuracy. - Minor inconsistency: acquire uses
cwd: rootwhile the updates usecwd: process.cwd(). Equivalent (root === process.cwd()), purely cosmetic.
No changes required to merge.
|
Review posted to PR #2379. SummaryI re-reviewed PR #2379 at its current tip ( Verdict: LGTM, no blocking issues. 79 tests pass; Key findings:
The new commit resolves the prior review's precedence-documentation concern (added comment + test). Only two cosmetic non-blocking nits remain. No changes required to merge. |
Summary
server.hostandserver.portfrom the project's Vite config when runningvinext devTesting
vp test run tests/cli-dev-config.test.ts tests/cli-args.test.ts tests/dev-lockfile.test.tsvp check packages/vinext/src/cli.ts packages/vinext/src/cli-dev-config.ts tests/cli-dev-config.test.tsvp run vinext#build