Skip to content

Commit d6b8938

Browse files
committed
Do not rely on the published Vite+ version in our test suite.
1 parent 357d071 commit d6b8938

10 files changed

Lines changed: 434 additions & 43 deletions

File tree

‎.github/scripts/packed-consumer.mjs‎

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -277,22 +277,31 @@ try {
277277
if (useVitePlus) {
278278
assert.equal(
279279
manifest.devDependencies['vite-plus'],
280-
`^${vitePlusVersion}`,
280+
vitePlusVersion,
281281
'Vite+ init must match the tested workspace toolchain',
282282
);
283283
assert.equal(
284284
manifest.devDependencies.vite,
285-
`npm:@voidzero-dev/vite-plus-core@^${vitePlusCoreVersion}`,
285+
`npm:@voidzero-dev/vite-plus-core@${vitePlusCoreVersion}`,
286286
'Vite+ init must use the matching core alias',
287287
);
288288
const installedVitePlus = JSON.parse(
289289
readFileSync(join(fixture, 'node_modules/vite-plus/package.json'), 'utf8'),
290290
);
291291
assert.equal(installedVitePlus.name, 'vite-plus');
292292
assert.equal(
293-
installedVitePlus.version.split('.')[0],
294-
vitePlusVersion.split('.')[0],
295-
'The consumer must use a compatible Vite+ release',
293+
installedVitePlus.version,
294+
vitePlusVersion,
295+
'The consumer must use the tested Vite+ release',
296+
);
297+
const installedCore = JSON.parse(
298+
readFileSync(join(fixture, 'node_modules/vite/package.json'), 'utf8'),
299+
);
300+
assert.equal(installedCore.version, vitePlusCoreVersion);
301+
assert.equal(
302+
installedVitePlus.dependencies.vite,
303+
`npm:@voidzero-dev/vite-plus-core@${installedCore.version}`,
304+
'The installed CLI and core must belong to the same toolchain release',
296305
);
297306
} else {
298307
assert(

‎packages/void/AGENTS.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ generated entries must preserve the module-boundary rules below.
125125
- **Plugin entry imports**: Every `vp dev` and `vp build` imports the plugin entry before it starts. Import dependencies that only some apps or commands use (feature codegen, CLI-only helpers) where they are used, so other apps don't load them at startup. `test/unit/plugin-entry-imports.test.ts` guards this; add a mock there when you move a heavy import out.
126126
- **pnpm scaffold build policy**: Keep `create-void` and `void init` aligned with the repository: `better-sqlite3: false` uses version 13's bundled Node-API binaries; `esbuild`, `sharp`, and `workerd` have approved builds. Do not require an unnecessary node-gyp rebuild in fresh applications.
127127
- **Scaffold dependency installation**: Vite+ projects install through local/global `vp`, bootstrapping with `npx` when neither is available. Preserve existing package-manager pins and lockfiles; fresh Vite+ projects select pnpm through the build-policy YAML without adding a version pin. Plain Vite projects use their selected package manager. Do not run a global package manager directly for Vite+ installs.
128+
- **Vite+ starter versions**: Bundle the build-time `vite-plus/package.json` metadata into the CLI and scaffold its exact CLI/core pairing, including package-manager overrides. Preserve existing Vite+ pairings and catalogs. Bootstrap with the project's selected version; upgrades belong to `vp migrate`, which coordinates the toolchain.
128129
- **Prerender discovery and environment validation**: Only `POST /__void/prerender-paths` bypasses whole-schema boot validation, because path discovery runs without remote production secrets. Discovery answers only when the build-time runner marks the request (the `__VOID_PRERENDER` Miniflare binding on Cloudflare, the Hono env argument on Node/Bun/Deno), never on a deployed app or dev server. Keep validation on readiness, application requests, page rendering, and event handlers.
129130
- **Pre-resolved paths in codegen**: Generated virtual module code uses absolute paths for `hono` and `void/response` (resolved via `import.meta.resolve()`). Virtual modules have no filesystem location, so bare specifiers can't resolve from them. void/db never imports its pg or mysql2 driver itself: drizzle builds the pool from `connection`, and the worker prebundle serves drizzle's bare driver import. Bundles that never run Void's Vite plugins, Nitro (through `void/nitro`) and the deploy cron/queue handler build, get the same module from `voidDbBundlerPlugin`, which resolves `@schema` through the bundler so a schema folder works. Their Worker builds import the driver that `bundleWorkerSqlDriver` builds like the migration handler: Nitro's CommonJS handling and Node stubs break pg and mysql2 in workerd. Each `pg`/`mysql2` import gets its own build of the copy the bundler resolves for it, looked up as a `require` so Rollup's CommonJS plugin neither wraps nor loads the raw driver, so Void's drizzle-orm and an app's own driver import keep their own versions. An import of `mysql2/promise` gets that copy's promise API from the same build, so it shares the driver's modules as in Node. A pg older than 8.11 has no `pg-cloudflare` socket and a mysql2 older than 3.13 has no `disableEval` option, so the lookup fails the build with an error that names the driver version and the importer. In an npm, Yarn or Bun install, Void's hoisted drizzle-orm loads the hoisted driver, which is the app's own copy when the app lists one. For pg and MySQL, `void/nitro` also runs each request in `withRuntimeEnv` (as the Class A wrapper does) and keeps Void's `node:async_hooks` native in workerd builds, because Nitro's unenv AsyncLocalStorage drops the store after the first await. Nitro turns on `cloudflare.nodeCompat` only from a `wrangler.*` file, so `void/nitro` sets it for pg/MySQL Worker builds (every deploy adds `nodejs_compat` for them) and for D1 only when the flags a deploy gives the Worker list `nodejs_compat` (the Cloudflare config's, which a managed deploy replaces with `worker.compatibility_flags` when set): a Worker built that way does not start without the flag. Nuxt and Analog also build server code with Vite (Analog's page server loads, Nuxt's app renderer), and Nitro bundles that output: Void's Vite plugin leaves a pg/MySQL `void/db` import there external, so Nitro serves one module and one driver copy, or the package's D1 client and its `void/nitro` hint when the module is missing. The deploy handler build likewise runs each cron event and queue batch in `withRuntimeEnv`.
130131
- **CF plugin API**: Worker config (`main`, `d1_databases`, `kv_namespaces`, `r2_buckets`) goes inside the `config` option of `cloudflare()`, NOT as top-level properties. `persistState` takes `{ path: string }`, not a raw string. The `config` option uses a **function form** `(resolved: WorkerConfig) => Partial<WorkerConfig>` so that bindings from the user's `wrangler.json` (if present) take precedence over inferred placeholder bindings.

‎packages/void/src/cli/init-vite-plus.ts‎

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,43 @@
11
import { existsSync, readFileSync, writeFileSync } from 'node:fs';
2-
import { join } from 'pathslash';
2+
import { dirname, join } from 'pathslash';
33
import { parseDocument } from 'yaml';
4+
import { getPackageDependencies, readPackageJson } from '../shared/package-json.ts';
45
import { SCAFFOLD_VITE_PLUS_DEV_DEPENDENCIES } from './template.ts';
56

67
type JsonObject = Record<string, unknown>;
78

9+
/** Resolve a project's catalog reference before invoking npx outside its workspace. */
10+
export function resolveVitePlusBootstrapSpec(root: string, pkg: JsonObject): string {
11+
const spec = getPackageDependencies(pkg)['vite-plus'];
12+
if (spec && !spec.startsWith('catalog:')) {
13+
return spec;
14+
}
15+
if (spec) {
16+
const catalog = spec.slice('catalog:'.length);
17+
let directory = root;
18+
while (true) {
19+
const workspace = join(directory, 'pnpm-workspace.yaml');
20+
const config = existsSync(workspace)
21+
? parseDocument(readFileSync(workspace, 'utf8')).toJS()
22+
: readPackageJson(directory);
23+
const entries = catalog
24+
? (config?.catalogs?.[catalog] ?? config?.workspaces?.catalogs?.[catalog])
25+
: (config?.catalog ?? config?.workspaces?.catalog);
26+
const version = entries?.['vite-plus'];
27+
if (typeof version === 'string' && version && !version.startsWith('catalog:')) {
28+
return version;
29+
}
30+
if (existsSync(workspace) || config?.workspaces || dirname(directory) === directory) {
31+
break;
32+
}
33+
directory = dirname(directory);
34+
}
35+
}
36+
throw new Error(
37+
'Could not resolve the project’s Vite+ version. Install its dependencies before running void init.',
38+
);
39+
}
40+
841
/** Keep every Vite consumer on the core used by the selected Vite+ toolchain. */
942
export function configureVitePlusScaffold(
1043
root: string,

‎packages/void/src/cli/init.ts‎

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import { detectFramework, type DetectedFramework } from '../plugin-inference.ts'
2525
import { readProjectPaths } from '../project-paths.ts';
2626
import { ensureGitignoreLines } from '../shared/gitignore.ts';
2727
import {
28+
getPackageDependencies,
2829
hasPackageDependency,
2930
readPackageJson,
3031
type PackageDependencyField,
@@ -36,7 +37,7 @@ import { maybeScaffoldEnvTs } from './env-scaffold.ts';
3637
import { migrateFrameworkAdapterPaths } from './framework-config-migrate.ts';
3738
import { initialCommitCommand, setupGit } from './init-git.ts';
3839
import { commandInProject } from './init-shell.ts';
39-
import { configureVitePlusScaffold } from './init-vite-plus.ts';
40+
import { configureVitePlusScaffold, resolveVitePlusBootstrapSpec } from './init-vite-plus.ts';
4041
import { migrateLegacyVoidConfig } from './migrate.ts';
4142
import { formatUrl, note, printSuccess } from './output.ts';
4243
import { discoverPlatform, saveDiscoveredPlatform } from './platform-cmd.ts';
@@ -56,7 +57,6 @@ import {
5657
SCAFFOLD_FRAMEWORK_OPTIONS,
5758
SCAFFOLD_GITIGNORE_LINES,
5859
SCAFFOLD_TOOLCHAIN_OPTIONS,
59-
SCAFFOLD_VITE_PLUS_DEV_DEPENDENCIES,
6060
type ScaffoldFramework,
6161
type ScaffoldStarterMode,
6262
type ScaffoldToolchain,
@@ -2181,7 +2181,7 @@ export function installProjectDependencies(
21812181
// npx void init must also work without a globally installed vp. Avoid
21822182
// asking an older pnpm to switch itself to a pinned native pnpm 12.
21832183
command = 'npx';
2184-
const packageArg = `--package=vite-plus@${SCAFFOLD_VITE_PLUS_DEV_DEPENDENCIES['vite-plus']}`;
2184+
const packageArg = `--package=vite-plus@${resolveVitePlusBootstrapSpec(root, pkg!)}`;
21852185
args = [
21862186
'--yes',
21872187
// cmd.exe treats the semver caret as an escape outside quotes.
@@ -2301,6 +2301,19 @@ function scaffoldPagesApp(
23012301
pkg.dependencies = dependencies;
23022302
pkg.devDependencies = devDependencies;
23032303

2304+
let existingDependencies = getPackageDependencies(pkg);
2305+
const workspace = resolveWorkspaceDeferral(root, pkg);
2306+
if (!existingDependencies['vite-plus'] && workspace) {
2307+
const workspacePackage = readPackageJson(workspace.workspaceRoot);
2308+
if (workspacePackage) {
2309+
existingDependencies = getPackageDependencies(workspacePackage);
2310+
}
2311+
}
2312+
const existingVite = existingDependencies.vite;
2313+
const preserveVitePlus =
2314+
!!existingDependencies['vite-plus'] &&
2315+
(existingVite?.startsWith('npm:@voidzero-dev/vite-plus-core@') ||
2316+
existingVite?.startsWith('catalog:'));
23042317
let dependencyAdded = false;
23052318
const ensureDependency = (
23062319
group: 'dependencies' | 'devDependencies',
@@ -2310,11 +2323,16 @@ function scaffoldPagesApp(
23102323
const otherGroup = group === 'dependencies' ? 'devDependencies' : 'dependencies';
23112324
const targetGroup = group === 'dependencies' ? dependencies : devDependencies;
23122325
const sourceGroup = otherGroup === 'dependencies' ? dependencies : devDependencies;
2313-
const existing = targetGroup[name] ?? sourceGroup[name];
2314-
const selectToolchainVersion =
2326+
const isVitePlusDependency =
23152327
toolchain === 'vite-plus' && (name === 'vite' || name === 'vite-plus');
2316-
if (!targetGroup[name] || (selectToolchainVersion && existing !== fallbackVersion)) {
2317-
targetGroup[name] = selectToolchainVersion ? fallbackVersion : (existing ?? fallbackVersion);
2328+
const existing =
2329+
isVitePlusDependency && preserveVitePlus
2330+
? existingDependencies[name]
2331+
: (targetGroup[name] ?? sourceGroup[name]);
2332+
const selectToolchainVersion = isVitePlusDependency && !preserveVitePlus;
2333+
const version = selectToolchainVersion ? fallbackVersion : (existing ?? fallbackVersion);
2334+
if (targetGroup[name] !== version) {
2335+
targetGroup[name] = version;
23182336
dependencyAdded = true;
23192337
}
23202338
if (sourceGroup[name]) {
@@ -2336,7 +2354,7 @@ function scaffoldPagesApp(
23362354
ensurePnpmAllowBuilds(root, pkg);
23372355
}
23382356

2339-
if (toolchain === 'vite-plus') {
2357+
if (toolchain === 'vite-plus' && !preserveVitePlus) {
23402358
configureVitePlusScaffold(
23412359
packageManager === 'pnpm' ? resolvePnpmConfigRoot(root, pkg) : root,
23422360
packageManager,

‎packages/void/src/cli/template.ts‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { readFileSync } from 'node:fs';
22
import { join } from 'pathslash';
3+
import vitePlus from 'vite-plus/package.json' with { type: 'json' };
34
import { renderVoidConfig } from '../config-write.ts';
45
import { getPackageDir } from './agents.ts';
56
import starterStyles from './starter-ui.css?raw';
@@ -30,10 +31,12 @@ export const SCAFFOLD_BASE_DEV_DEPENDENCIES = {
3031
typescript: '^7.0.2',
3132
} as const;
3233

33-
export const SCAFFOLD_VITE_PLUS_DEV_DEPENDENCIES = {
34-
vite: 'npm:@voidzero-dev/vite-plus-core@^8.3.8000',
35-
'vite-plus': '^1.7.0',
36-
} as const;
34+
// Bundle the tested release's metadata into the CLI: Vite+ and its core must
35+
// upgrade together, and their version numbers need not match.
36+
export const SCAFFOLD_VITE_PLUS_DEV_DEPENDENCIES: Readonly<Record<'vite' | 'vite-plus', string>> = {
37+
vite: vitePlus.dependencies.vite,
38+
'vite-plus': vitePlus.version,
39+
};
3740

3841
export const SCAFFOLD_TOOLCHAIN_OPTIONS = [
3942
{

‎packages/void/test/integration/init-install.test.ts‎

Lines changed: 75 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -71,21 +71,82 @@ describe('init dependency installation (real subprocesses)', () => {
7171
);
7272
});
7373

74-
it('bootstraps Vite+ when neither a local nor a global vp is installed', () => {
75-
executable('npx');
76-
executable('pnpm', 1);
77-
78-
installProjectDependencies(root, 'pnpm');
74+
it.each(['1.6.0', '^1.3.0'])(
75+
'bootstraps the project-selected Vite+ %s without a local or global vp',
76+
(version) => {
77+
const pkg = JSON.parse(readFileSync(join(root, 'package.json'), 'utf8'));
78+
pkg.devDependencies['vite-plus'] = version;
79+
writeFileSync(join(root, 'package.json'), JSON.stringify(pkg));
80+
executable('npx');
81+
executable('pnpm', 1);
82+
83+
installProjectDependencies(root, 'pnpm');
84+
85+
// Assert the received argv: Windows cmd.exe must preserve the semver caret.
86+
expect(calls()).toEqual([
87+
{
88+
command: 'npx',
89+
args: [
90+
'--yes',
91+
`--package=vite-plus@${version}`,
92+
'vp',
93+
'install',
94+
'--no-frozen-lockfile',
95+
],
96+
cwd: root,
97+
},
98+
]);
99+
},
100+
);
79101

80-
// Assert the received argv: Windows cmd.exe must preserve the semver caret.
81-
expect(calls()).toEqual([
82-
{
83-
command: 'npx',
84-
args: ['--yes', '--package=vite-plus@^1.7.0', 'vp', 'install', '--no-frozen-lockfile'],
85-
cwd: root,
86-
},
87-
]);
88-
});
102+
it.each([
103+
['pnpm', ''],
104+
['pnpm', 'tools'],
105+
['bun', ''],
106+
['bun', 'tools'],
107+
] as const)(
108+
'bootstraps the Vite+ version from the %s workspace catalog (%s)',
109+
(manager, catalog) => {
110+
const member = join(root, 'packages/app');
111+
mkdirSync(member, { recursive: true });
112+
writeFileSync(
113+
join(member, 'package.json'),
114+
JSON.stringify({
115+
devDependencies: { 'vite-plus': 'catalog:' + catalog },
116+
}),
117+
);
118+
if (manager === 'pnpm') {
119+
writeFileSync(
120+
join(root, 'pnpm-workspace.yaml'),
121+
'packages: [packages/*]\n' +
122+
(catalog
123+
? 'catalogs: { tools: { vite-plus: "1.6.0" } }\n'
124+
: 'catalog: { vite-plus: "1.6.0" }\n'),
125+
);
126+
} else {
127+
writeFileSync(
128+
join(root, 'package.json'),
129+
JSON.stringify({
130+
workspaces: {
131+
packages: ['packages/*'],
132+
...(catalog
133+
? { catalogs: { tools: { 'vite-plus': '1.6.0' } } }
134+
: { catalog: { 'vite-plus': '1.6.0' } }),
135+
},
136+
}),
137+
);
138+
}
139+
executable('npx');
140+
installProjectDependencies(member, manager);
141+
expect(calls()).toEqual([
142+
{
143+
command: 'npx',
144+
args: ['--yes', '--package=vite-plus@1.6.0', 'vp', 'install', '--no-frozen-lockfile'],
145+
cwd: member,
146+
},
147+
]);
148+
},
149+
);
89150

90151
it('reports a Vite+ install failure without retrying through another installer', () => {
91152
executable('vp', 7);

0 commit comments

Comments
 (0)