Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "create-yarn1-parent",
"private": true,
"packageManager": "yarn@1.22.22"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[[case]]
name = "create_yarn1_npx_fallback"
vp = "local"
comment = "Yarn 1 has no dlx command, so create runs the template through npx."
steps = [
{ argv = ["vp", "create", "vite:application", "--directory", "app", "--no-interactive", "--no-git", "--no-agent", "--no-editor", "--no-hooks"], snapshot = false, timeout = 180000 },
{ argv = ["vpt", "stat-file", "app/package.json", "--assert", "file"], comment = "the application was scaffolded" },
{ argv = ["vpt", "grep-file", "app/package.json", "\"version\": \"1.22.22\""], comment = "the project keeps the Yarn 1 pin" },
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# create_yarn1_npx_fallback

Yarn 1 has no dlx command, so create runs the template through npx.

## `vp create vite:application --directory app --no-interactive --no-git --no-agent --no-editor --no-hooks`


## `vpt stat-file app/package.json --assert file`

the application was scaffolded

```
app/package.json: file
```

## `vpt grep-file app/package.json '"version": "1.22.22"'`

the project keeps the Yarn 1 pin

```
app/package.json: found "\"version\": \"1.22.22\""
```
23 changes: 22 additions & 1 deletion packages/cli/src/create/__tests__/command.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ vi.mock('../../../binding/index.js', () => ({
runCommand: mockRunCommand,
}));

const { runCommandAndDetectProjectDir } = await import('../command.js');
const { formatDlxCommand, runCommandAndDetectProjectDir } = await import('../command.js');

type DlxWorkspaceInfo = Parameters<typeof formatDlxCommand>[2];

const yarn = (packageManagerVersion: string) =>
({ packageManager: 'yarn', packageManagerVersion }) as DlxWorkspaceInfo;

const tempDirs: string[] = [];

Expand All @@ -22,6 +27,22 @@ 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();
Expand Down
6 changes: 6 additions & 0 deletions packages/cli/src/create/command.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
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';
Expand Down Expand Up @@ -96,6 +98,10 @@ export function getPackageRunner(workspaceInfo: WorkspaceInfo) {
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'],
Expand Down
Loading