Skip to content

Commit 5b78598

Browse files
authored
fix(create): block vite:generator template outside a monorepo (#775)
The generator template uses `catalog:` dependencies that only resolve inside a monorepo with pnpm-workspace.yaml. Add a guard in non-interactive mode to show a helpful error instead of failing at pnpm install time.
1 parent 0d14055 commit 5b78598

5 files changed

Lines changed: 21 additions & 2 deletions

File tree

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"name": "standalone-project",
3+
"version": "0.0.0"
4+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[1]> vp create vite:generator --no-interactive
2+
3+
The vite:generator template requires a monorepo workspace.
4+
Run this command inside a Vite+ monorepo, or create one first with `vp create vite:monorepo`
5+
Cannot create a generator outside a monorepo
6+
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"commands": ["vp create vite:generator --no-interactive"]
3+
}

packages/cli/snap-tests-global/new-check/snap.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ Vite+ Built-in Templates:
6161
vite:monorepo Create a new monorepo
6262
vite:application Create a new application
6363
vite:library Create a new library
64-
vite:generator Scaffold a new code generator
64+
vite:generator Scaffold a new code generator (monorepo only)
6565

6666
Popular Templates (shorthand):
6767
vite Official Vite templates (create-vite)

packages/cli/src/create/bin.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ const listTemplatesMessage = renderCliDoc({
139139
{ label: 'vite:monorepo', description: 'Create a new monorepo' },
140140
{ label: 'vite:application', description: 'Create a new application' },
141141
{ label: 'vite:library', description: 'Create a new library' },
142-
{ label: 'vite:generator', description: 'Scaffold a new code generator' },
142+
{ label: 'vite:generator', description: 'Scaffold a new code generator (monorepo only)' },
143143
],
144144
},
145145
{
@@ -529,6 +529,12 @@ Use \`vp create --list\` to list all available templates, or run \`vp create --h
529529
);
530530
cancelAndExit('Cannot create a monorepo inside an existing monorepo', 1);
531531
}
532+
if (selectedTemplateName === BuiltinTemplate.generator && !isMonorepo) {
533+
prompts.log.info(
534+
'The vite:generator template requires a monorepo workspace.\nRun this command inside a Vite+ monorepo, or create one first with `vp create vite:monorepo`',
535+
);
536+
cancelAndExit('Cannot create a generator outside a monorepo', 1);
537+
}
532538

533539
if (isInSubdirectory && !compactOutput) {
534540
prompts.log.info(`Detected monorepo root at ${accent(workspaceInfoOptional.rootDir)}`);

0 commit comments

Comments
 (0)