From d00d06037263c863c970f9f06999be954855e3a0 Mon Sep 17 00:00:00 2001 From: JongKyung Lee Date: Tue, 17 Nov 2026 17:29:42 +0900 Subject: [PATCH 1/3] refactor(create): run remote templates through vp dlx Replace the package runner table in create with `vp dlx`, which already owns the same resolution in vp_pm_cli. Pass the selected package manager through VP_PACKAGE_MANAGER because `vp dlx` detects it from the working directory and defaults to pnpm outside a project. --- .../create_react_router_no_git_init.md | 2 +- .../cli/src/create/__tests__/command.spec.ts | 23 +---------- packages/cli/src/create/command.ts | 41 ------------------- packages/cli/src/create/templates/remote.ts | 21 +++++----- 4 files changed, 12 insertions(+), 75 deletions(-) diff --git a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/create_react_router_no_git_init/snapshots/create_react_router_no_git_init.md b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/create_react_router_no_git_init/snapshots/create_react_router_no_git_init.md index fc57206bc7..b2440d24b3 100644 --- a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/create_react_router_no_git_init/snapshots/create_react_router_no_git_init.md +++ b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/create_react_router_no_git_init/snapshots/create_react_router_no_git_init.md @@ -10,7 +10,7 @@ Vite+ passes --no-git-init to the generator and completes integration ● pnpm@10.18.0 installing... ● pnpm@10.18.0 installed ◇ Generating project… -● Running: pnpm dlx create-react-router@8.5.1 app --template ./template --yes --no-install --no-agent-skills --no-motion --no-git-init +● Running: vp dlx create-react-router@8.5.1 app --template ./template --yes --no-install --no-agent-skills --no-motion --no-git-init create-react-router ◼ Directory: Using app as project directory diff --git a/packages/cli/src/create/__tests__/command.spec.ts b/packages/cli/src/create/__tests__/command.spec.ts index 607aeecfac..89c9fdb05e 100644 --- a/packages/cli/src/create/__tests__/command.spec.ts +++ b/packages/cli/src/create/__tests__/command.spec.ts @@ -12,12 +12,7 @@ vi.mock('../../../binding/index.js', () => ({ runCommand: mockRunCommand, })); -const { formatDlxCommand, runCommandAndDetectProjectDir } = await import('../command.js'); - -type DlxWorkspaceInfo = Parameters[2]; - -const yarn = (packageManagerVersion: string) => - ({ packageManager: 'yarn', packageManagerVersion }) as DlxWorkspaceInfo; +const { runCommandAndDetectProjectDir } = await import('../command.js'); const tempDirs: string[] = []; @@ -27,22 +22,6 @@ function makeTempDir() { return dir; } -describe('formatDlxCommand', () => { - it('falls back to npx for Yarn 1, which has no dlx command', () => { - expect(formatDlxCommand('create-vite@latest', ['app'], yarn('1.22.22'))).toEqual({ - command: 'npx', - args: ['--yes', 'create-vite@latest', 'app'], - }); - }); - - it('uses yarn dlx for Yarn 2 and later', () => { - expect(formatDlxCommand('create-vite@latest', ['app'], yarn('4.18.1'))).toEqual({ - command: 'yarn', - args: ['dlx', 'create-vite@latest', 'app'], - }); - }); -}); - describe('runCommandAndDetectProjectDir', () => { beforeEach(() => { mockRunCommand.mockReset(); diff --git a/packages/cli/src/create/command.ts b/packages/cli/src/create/command.ts index 9f21db5192..85fcb39879 100644 --- a/packages/cli/src/create/command.ts +++ b/packages/cli/src/create/command.ts @@ -1,10 +1,7 @@ import fs from 'node:fs/promises'; import path from 'node:path'; -import { coerce } from 'verkit'; - import { runCommand as runCommandWithFspy } from '../../binding/index.js'; -import type { WorkspaceInfo } from '../types/index.ts'; import type { ExecutionResult, RunCommandOptions } from '../utils/command.ts'; /** Set by `runCommandAndDetectProjectDir` and the template executors @@ -89,44 +86,6 @@ export async function runCommandAndDetectProjectDir( }; } -// Get the package runner command for each package manager -export function getPackageRunner(workspaceInfo: WorkspaceInfo) { - switch (workspaceInfo.packageManager) { - case 'pnpm': - return { - command: 'pnpm', - args: ['dlx'], - }; - case 'yarn': - // Yarn 1 has no `dlx`; same npx fallback as `vp dlx` in vp_pm_cli. - if (coerce(workspaceInfo.packageManagerVersion)?.major === 1) { - return { command: 'npx', args: ['--yes'] }; - } - return { - command: 'yarn', - args: ['dlx'], - }; - case 'bun': - return { command: 'bun', args: ['x'] }; - case 'npm': - default: - return { command: 'npx', args: [] }; - } -} - -// TODO: will use `vp dlx` instead, see https://github.com/voidzero-dev/vite-task/issues/27 -export function formatDlxCommand( - packageName: string, - args: string[], - workspaceInfo: WorkspaceInfo, -) { - const runner = getPackageRunner(workspaceInfo); - return { - command: runner.command, - args: [...runner.args, packageName, ...args], - }; -} - export function prependToPathToEnvs(extraPath: string, envs: NodeJS.ProcessEnv) { const delimiter = path.delimiter; const pathKey = Object.keys(envs).find((key) => key.toLowerCase() === 'path') ?? 'PATH'; diff --git a/packages/cli/src/create/templates/remote.ts b/packages/cli/src/create/templates/remote.ts index 62c8c640a2..e11e7e9dc5 100644 --- a/packages/cli/src/create/templates/remote.ts +++ b/packages/cli/src/create/templates/remote.ts @@ -2,13 +2,9 @@ import * as prompts from '@voidzero-dev/vite-plus-prompts'; import colors from 'picocolors'; import type { WorkspaceInfo } from '../../types/index.ts'; -import { runCommand, runCommandSilently } from '../../utils/command.ts'; +import { getVpCommand, runCommand, runCommandSilently } from '../../utils/command.ts'; import { checkNpmPackageExists } from '../../utils/package.ts'; -import { - type ExecutionWithProjectDir, - formatDlxCommand, - runCommandAndDetectProjectDir, -} from '../command.ts'; +import { type ExecutionWithProjectDir, runCommandAndDetectProjectDir } from '../command.ts'; import type { TemplateInfo } from './types.ts'; const { gray, yellow } = colors; @@ -85,12 +81,15 @@ export async function runRemoteTemplateCommand( silent = false, ): Promise { autoFixRemoteTemplateCommand(templateInfo, workspaceInfo); - const remotePackageName = templateInfo.command; - const execArgs = [...templateInfo.args]; - const envs = templateInfo.envs; - const { command, args } = formatDlxCommand(remotePackageName, execArgs, workspaceInfo); + const dlxArgs = ['dlx', templateInfo.command, ...templateInfo.args]; + // `vp dlx` detects the package manager from cwd and defaults to pnpm outside a project. + const envs = { + ...templateInfo.envs, + VP_PACKAGE_MANAGER: `${workspaceInfo.packageManager}@${workspaceInfo.packageManagerVersion}`, + }; + const { command, args } = getVpCommand(dlxArgs); if (!silent) { - prompts.log.info(`Running: ${gray(`${command} ${args.join(' ')}`)}`); + prompts.log.info(`Running: ${gray(`vp ${dlxArgs.join(' ')}`)}`); } if (detectCreatedProjectDir) { return await runCommandAndDetectProjectDir( From dd25243292eb59f14e3a3c82f728889958fad8d0 Mon Sep 17 00:00:00 2001 From: JongKyung Lee Date: Tue, 17 Nov 2026 17:39:31 +0900 Subject: [PATCH 2/3] fix(create): keep the package manager override for vp dlx A VP_PACKAGE_MANAGER override can carry an integrity hash, and vp_pm_cli stores a hashed install in a separate verified directory. Replacing the override with a bare name and version made `vp dlx` download the package manager again without the hash and run that copy. Keep the user's value so the template runs with the install that create verified. --- packages/cli/src/create/templates/remote.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/cli/src/create/templates/remote.ts b/packages/cli/src/create/templates/remote.ts index e11e7e9dc5..482db049b2 100644 --- a/packages/cli/src/create/templates/remote.ts +++ b/packages/cli/src/create/templates/remote.ts @@ -83,9 +83,12 @@ export async function runRemoteTemplateCommand( autoFixRemoteTemplateCommand(templateInfo, workspaceInfo); const dlxArgs = ['dlx', templateInfo.command, ...templateInfo.args]; // `vp dlx` detects the package manager from cwd and defaults to pnpm outside a project. + // A user override is kept as given: its hash selects the verified install create downloaded. const envs = { ...templateInfo.envs, - VP_PACKAGE_MANAGER: `${workspaceInfo.packageManager}@${workspaceInfo.packageManagerVersion}`, + VP_PACKAGE_MANAGER: + templateInfo.envs.VP_PACKAGE_MANAGER?.trim() || + `${workspaceInfo.packageManager}@${workspaceInfo.packageManagerVersion}`, }; const { command, args } = getVpCommand(dlxArgs); if (!silent) { From 4945ec9ce60dd14b28f044903b99e1e59a40a65c Mon Sep 17 00:00:00 2001 From: JongKyung Lee Date: Tue, 17 Nov 2026 18:56:24 +0900 Subject: [PATCH 3/3] fix(create): terminate vp options before the template command Without the terminator, the global CLI read a template's --help as a request for vp dlx help, so the generator never ran. --- .../snapshots/create_react_router_no_git_init.md | 2 +- packages/cli/src/create/templates/remote.ts | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/create_react_router_no_git_init/snapshots/create_react_router_no_git_init.md b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/create_react_router_no_git_init/snapshots/create_react_router_no_git_init.md index b2440d24b3..6ea7c2302d 100644 --- a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/create_react_router_no_git_init/snapshots/create_react_router_no_git_init.md +++ b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/create_react_router_no_git_init/snapshots/create_react_router_no_git_init.md @@ -10,7 +10,7 @@ Vite+ passes --no-git-init to the generator and completes integration ● pnpm@10.18.0 installing... ● pnpm@10.18.0 installed ◇ Generating project… -● Running: vp dlx create-react-router@8.5.1 app --template ./template --yes --no-install --no-agent-skills --no-motion --no-git-init +● Running: vp dlx -- create-react-router@8.5.1 app --template ./template --yes --no-install --no-agent-skills --no-motion --no-git-init create-react-router ◼ Directory: Using app as project directory diff --git a/packages/cli/src/create/templates/remote.ts b/packages/cli/src/create/templates/remote.ts index 482db049b2..0f6904f927 100644 --- a/packages/cli/src/create/templates/remote.ts +++ b/packages/cli/src/create/templates/remote.ts @@ -81,7 +81,8 @@ export async function runRemoteTemplateCommand( silent = false, ): Promise { autoFixRemoteTemplateCommand(templateInfo, workspaceInfo); - const dlxArgs = ['dlx', templateInfo.command, ...templateInfo.args]; + // `--` keeps the global CLI from reading a template's `--help` as its own. + const dlxArgs = ['dlx', '--', templateInfo.command, ...templateInfo.args]; // `vp dlx` detects the package manager from cwd and defaults to pnpm outside a project. // A user override is kept as given: its hash selects the verified install create downloaded. const envs = {