Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
2593b1d
fix(create-void): merge pnpm build policy into workspace config
yuikisaito Nov 21, 2026
f97f7ab
test(create-void): cover pnpm build policy merging
yuikisaito Nov 21, 2026
d511f39
feat(create-void): support --no-install
yuikisaito Nov 21, 2026
74e28a9
feat(void): support --no-install in init
yuikisaito Nov 21, 2026
72cefb4
test(create-void): cover CLI bootstrap commands
yuikisaito Nov 21, 2026
4325273
test(init): cover --no-install scaffolding
yuikisaito Nov 21, 2026
3c5325b
fix(create-void): support no-install with Yarn Classic
yuikisaito Nov 21, 2026
802eadf
revert(create-void): roll back bootstrap and no-install changes
yuikisaito Nov 22, 2026
2e2d917
fix(create-void): run matching Void CLI version via dlx
yuikisaito Nov 22, 2026
2b78392
refactor(create-void): delegate scaffolding to void init
yuikisaito Nov 22, 2026
5828f32
test(create-void): test dlx delegation
yuikisaito Nov 22, 2026
1d59fae
test(create-void): test init delegation
yuikisaito Nov 22, 2026
3aa9ab7
fix(create-void): preserve delegated package manager
yuikisaito Nov 25, 2026
21727f1
fix(init): report skipped migration
yuikisaito Nov 25, 2026
835b15c
Merge main
yuikisaito Nov 25, 2026
3e7724e
style(create-void): fix lint errors
yuikisaito Nov 25, 2026
92bb09b
feat(init): record package manager in devEngines for Vite+ starters
yuikisaito Nov 26, 2026
f2620e3
feat(create-void): default to Vite+ toolchain when invoked from vp
yuikisaito Nov 26, 2026
f3b8b82
fix(create-void): fix the logic for determining whether to insert dev…
yuikisaito Nov 26, 2026
fe860c4
fix(create-void): honor --package-manager when scaffolding Vite+ star…
yuikisaito Nov 26, 2026
f4b03f9
fix(create-void): skip install when invoked from vp
yuikisaito Nov 26, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 3 additions & 24 deletions packages/create-void/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from 'node:fs';
import { existsSync, mkdirSync, readdirSync, readFileSync } from 'node:fs';
import { cancel, isCancel, log, outro, text } from '@voidzero-dev/vite-plus-prompts';
import { resolve } from 'pathslash';
import pc from 'picocolors';
import { parseCreateArgs, validateProjectName } from './args.ts';
import { detectPM, pmExec, pmInstall, run, writePnpmBuildPolicy } from './pm.ts';
import { detectPM, runVoidInit } from './pm.ts';

const pm = detectPM();

Expand Down Expand Up @@ -59,29 +59,8 @@ async function main() {

mkdirSync(targetDir, { recursive: true });

const pkg = {
name: appName,
private: true,
type: 'module',
devDependencies: {
void: voidVersion,
},
};

writeFileSync(resolve(targetDir, 'package.json'), JSON.stringify(pkg, null, 2) + '\n');
// pnpm 12 fails the first install when a dependency has an unapproved build
// script. Write Void's narrow policy before installing the CLI so a fresh
// project can bootstrap without disabling pnpm's build-script protection.
writePnpmBuildPolicy(targetDir, pm);

log.step('Installing Void...');
await run(pmInstall(pm), targetDir);

log.step('Scaffolding starter...');
await run([...pmExec(pm), 'void', 'init', ...createArgs.initArgs], targetDir);

log.step('Installing starter dependencies...');
await run(pmInstall(pm), targetDir);
await runVoidInit(pm, voidVersion, createArgs.initArgs, targetDir);
Comment thread
yuikisaito marked this conversation as resolved.
Resolved

outro(`\n${pc.green(`✓ Created ${appName}`)}`, { withGuide: false });
outro(`cd ${appName} && ${pm === 'npm' ? 'npm run' : pm} dev`);
Expand Down
71 changes: 54 additions & 17 deletions packages/create-void/src/pm.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,7 @@
import { spawn } from 'node:child_process';
import { writeFileSync } from 'node:fs';
import { join } from 'pathslash';

export type PM = 'npm' | 'pnpm' | 'yarn' | 'bun';

const VOID_PNPM_ALLOWED_BUILDS = ['esbuild', 'sharp', 'workerd'] as const;

/** Write the explicit build-script policy required by a new pnpm project. */
export function writePnpmBuildPolicy(root: string, pm: PM): void {
if (pm !== 'pnpm') {
return;
}
writeFileSync(
join(root, 'pnpm-workspace.yaml'),
// better-sqlite3 13 ships Node-API binaries and declares gypfile:false.
// Match the repository policy instead of invoking pnpm's implicit rebuild.
`allowBuilds:\n better-sqlite3: false\n${VOID_PNPM_ALLOWED_BUILDS.map((name) => ` ${name}: true`).join('\n')}\n`,
);
}

export function detectPM(): PM {
const agent = process.env.npm_config_user_agent;
if (agent) {
Expand Down Expand Up @@ -54,6 +37,60 @@ export function pmExec(pm: PM): ReadonlyArray<string> {
}
}

function isYarnClassic(userAgent = process.env.npm_config_user_agent): boolean {
return /^yarn\/1(?:\.|$)/.test(userAgent ?? '');
}

/** Run the matching Void CLI without adding it to the generated project. */
export function pmDlx(pm: PM, version: string): ReadonlyArray<string> {
const pkg = `void@${version}`;
switch (isYarnClassic() ? 'npm' : pm) {
case 'npm':
return ['npm', 'exec', '--yes', `--package=${pkg}`, '--', 'void'];
case 'pnpm':
return ['pnpm', 'dlx', pkg];
case 'yarn':
return ['yarn', 'dlx', pkg];
case 'bun':
return ['bunx', pkg];
}
}

export function pmInitCommand(
pm: PM,
version: string,
initArgs: ReadonlyArray<string>,
): ReadonlyArray<string> {
const hasToolchain = initArgs.some(
(arg) => arg === '--toolchain' || arg.startsWith('--toolchain='),
);
const hasInstallOption = initArgs.some((arg) => arg === '--install' || arg === '--no-install');
const invokedByVitePlus = process.env.VP_USER_AGENT?.startsWith('vp/') ?? false;

return [
...pmDlx(pm, version),
'init',
'--package-manager',
pm,
...initArgs,
...(invokedByVitePlus && !hasToolchain ? ['--toolchain', 'vite-plus'] : []),
...(invokedByVitePlus && !hasInstallOption ? ['--no-install'] : []),
...(invokedByVitePlus ? ['--vp-create'] : []),
];
}

export type InitCommandRunner = (argv: ReadonlyArray<string>, cwd?: string) => Promise<void>;

export function runVoidInit(
pm: PM,
version: string,
initArgs: ReadonlyArray<string>,
cwd: string,
runner: InitCommandRunner = run,
): Promise<void> {
return runner(pmInitCommand(pm, version, initArgs), cwd);
}

export function run(argv: ReadonlyArray<string>, cwd?: string): Promise<void> {
return new Promise((resolve, reject) => {
const [cmd, ...args] = argv;
Expand Down
131 changes: 131 additions & 0 deletions packages/create-void/test/unit/delegation.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
import { existsSync, mkdtempSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vite-plus/test';
import { parseInitArgs, runInitCommand } from '../../../void/src/cli/init.ts';
import { detectPM, runVoidInit } from '../../src/pm.ts';

const VOID_VERSION = JSON.parse(
readFileSync(join(import.meta.dirname, '..', '..', 'package.json'), 'utf8'),
) as { version: string };

describe('create-void delegation', () => {
beforeEach(() => vi.stubEnv('VP_USER_AGENT', ''));
afterEach(() => vi.unstubAllEnvs());

it('writes the npm package manager for an npm create void Vite+ starter', async () => {
vi.stubEnv('VP_USER_AGENT', '');
vi.stubEnv('npm_config_user_agent', 'npm/11.0.0 node/v24.22.1');
const root = mkdtempSync(join(tmpdir(), 'create-void-npm-'));
try {
expect(detectPM()).toBe('npm');

await runVoidInit(
detectPM(),
VOID_VERSION.version,
[
'--toolchain',
'vite-plus',
'--framework',
'react',
'--starter',
'static',
'--deploy',
'none',
'--no-install',
],
root,
async (argv, cwd) => {
expect(argv).toContain('--package-manager');
expect(argv[argv.indexOf('--package-manager') + 1]).toBe('npm');
await runInitCommand(cwd!, parseInitArgs(argv.slice(argv.indexOf('init') + 1)));
},
);

const pkg = JSON.parse(readFileSync(join(root, 'package.json'), 'utf8'));
expect(pkg.devEngines.packageManager).toEqual({ name: 'npm' });
} finally {
rmSync(root, { recursive: true, force: true });
}
});

it('delegates to void init in a pnpm workspace member and forwards --no-install', async () => {
const root = mkdtempSync(join(tmpdir(), 'create-void-workspace-'));
try {
const appDirectory = join(root, 'apps', 'my-app');
mkdirSync(appDirectory, { recursive: true });
writeFileSync(join(root, 'package.json'), JSON.stringify({ name: 'fixture', private: true }));
writeFileSync(
join(root, 'pnpm-workspace.yaml'),
[
'# Keep this workspace comment',
'packages:',
' - apps/*',
'allowBuilds:',
' esbuild: false # Keep this approval decision',
' custom-build: true',
'',
].join('\n'),
);

let invoked = false;
await runVoidInit(
'pnpm',
VOID_VERSION.version,
[
'--toolchain',
'vite',
'--framework',
'react',
'--starter',
'static',
'--deploy',
'none',
'--no-install',
],
appDirectory,
async (argv, cwd) => {
invoked = true;
expect(argv).toEqual([
'pnpm',
'dlx',
`void@${VOID_VERSION.version}`,
'init',
'--package-manager',
'pnpm',
'--toolchain',
'vite',
'--framework',
'react',
'--starter',
'static',
'--deploy',
'none',
'--no-install',
]);
expect(cwd).toBe(appDirectory);
await runInitCommand(cwd!, parseInitArgs(argv.slice(4)));
},
);
expect(invoked).toBe(true);

expect(existsSync(join(appDirectory, 'package.json'))).toBe(true);
expect(existsSync(join(appDirectory, 'pages', 'index.tsx'))).toBe(true);
expect(existsSync(join(appDirectory, 'pnpm-workspace.yaml'))).toBe(false);
expect(existsSync(join(appDirectory, 'pnpm-lock.yaml'))).toBe(false);
expect(existsSync(join(appDirectory, 'package-lock.json'))).toBe(false);
expect(existsSync(join(appDirectory, 'node_modules'))).toBe(false);

const updatedWorkspaceConfig = readFileSync(join(root, 'pnpm-workspace.yaml'), 'utf8');
expect(updatedWorkspaceConfig).toContain('# Keep this workspace comment');
expect(updatedWorkspaceConfig).toContain('esbuild: false # Keep this approval decision');
expect(updatedWorkspaceConfig).toContain('custom-build: true');
expect(updatedWorkspaceConfig).toContain('better-sqlite3: false');
expect(updatedWorkspaceConfig).toContain('sharp: true');
expect(updatedWorkspaceConfig).toContain('workerd: true');
expect(existsSync(join(root, 'pnpm-lock.yaml'))).toBe(false);
} finally {
rmSync(root, { recursive: true, force: true });
}
});
});
Loading