Skip to content

Commit 764dd2d

Browse files
committed
fix(create): honor create.defaultTemplate in --no-interactive mode
The early-exit "template name is required" guard fired before `getConfiguredDefaultTemplate` ran, so `vp create --no-interactive` in a repo with `create.defaultTemplate: '@your-org'` exited with a generic "template name required" message instead of reading the configured default. The documented precedence (CLI arg > create.defaultTemplate > interactive picker) was silently broken for all non-interactive / CI usage. Fix: move the guard to after the full resolution chain (CLI arg → create.defaultTemplate → @org manifest). Only error if `selectedTemplateName` is still empty once every input source has had a chance to fill it. If the configured default is an @org scope, the manifest resolver's own `--no-interactive` branch prints the manifest table — exactly what a user expects when the config was supposed to pick the org. New snap-test `create-org-config-default` locks in the fix: a fixture with `create: { defaultTemplate: '@your-org' }` in vite.config.ts runs bare `vp create --no-interactive` and verifies the @your-org manifest table prints instead of the generic missing-argument error. Reported by Cursor Bugbot on #1398.
1 parent b8ecbaa commit 764dd2d

6 files changed

Lines changed: 76 additions & 17 deletions

File tree

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"@your-org/create": {
3+
"name": "@your-org/create",
4+
"dist-tags": { "latest": "1.0.0" },
5+
"versions": {
6+
"1.0.0": {
7+
"version": "1.0.0",
8+
"dist": {
9+
"tarball": "{REGISTRY}/@your-org/create/-/create-1.0.0.tgz",
10+
"integrity": "sha512-fake"
11+
},
12+
"vp": {
13+
"templates": [
14+
{
15+
"name": "web",
16+
"description": "Web app template",
17+
"template": "@your-org/template-web"
18+
}
19+
]
20+
}
21+
}
22+
}
23+
}
24+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "config-default-fixture",
3+
"private": true,
4+
"type": "module"
5+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[1]> node $SNAP_CASES_DIR/.shared/mock-npm-registry.mjs -- vp create --no-interactive # bare vp create picks up create.defaultTemplate from vite.config.ts
2+
3+
A template name is required when running `vp create @your-org` in non-interactive mode.
4+
5+
Available templates in @your-org/create:
6+
7+
NAME DESCRIPTION TEMPLATE
8+
web Web app template @your-org/template-web
9+
10+
Examples:
11+
# Scaffold a specific template from the org
12+
vp create @your-org/web --no-interactive
13+
14+
# Or use a Vite+ built-in template
15+
vp create vite:application --no-interactive
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"commands": [
3+
"node $SNAP_CASES_DIR/.shared/mock-npm-registry.mjs -- vp create --no-interactive # bare vp create picks up create.defaultTemplate from vite.config.ts"
4+
]
5+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { defineConfig } from 'vite-plus';
2+
3+
export default defineConfig({
4+
create: {
5+
defaultTemplate: '@your-org',
6+
},
7+
});

packages/cli/src/create/bin.ts

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -392,23 +392,6 @@ async function main() {
392392
}
393393
// #endregion
394394

395-
// #region Handle required arguments
396-
if (!templateName && !options.interactive) {
397-
console.error(`
398-
A template name is required when running in non-interactive mode
399-
400-
Usage: vp create [TEMPLATE] [OPTIONS] [-- TEMPLATE_OPTIONS]
401-
402-
Example:
403-
${muted('# Create a new application in non-interactive mode with a custom target directory')}
404-
vp create vite:application --no-interactive --directory=apps/my-app
405-
406-
Use \`vp create --list\` to list all available templates, or run \`vp create --help\` for more information.
407-
`);
408-
process.exit(1);
409-
}
410-
// #endregion
411-
412395
// #region Prepare Stage
413396
if (options.interactive) {
414397
prompts.intro(vitePlusHeader());
@@ -484,6 +467,26 @@ Use \`vp create --list\` to list all available templates, or run \`vp create --h
484467
}
485468
}
486469

470+
// Guard only after the CLI arg → `create.defaultTemplate` → @org manifest
471+
// chain has had a chance to fill `selectedTemplateName`. A user in a repo
472+
// with `create.defaultTemplate` set should be able to run `vp create
473+
// --no-interactive` and hit the configured default (which itself may
474+
// print its own manifest table for an @org scope).
475+
if (!selectedTemplateName && !options.interactive) {
476+
console.error(`
477+
A template name is required when running in non-interactive mode
478+
479+
Usage: vp create [TEMPLATE] [OPTIONS] [-- TEMPLATE_OPTIONS]
480+
481+
Example:
482+
${muted('# Create a new application in non-interactive mode with a custom target directory')}
483+
vp create vite:application --no-interactive --directory=apps/my-app
484+
485+
Use \`vp create --list\` to list all available templates, or run \`vp create --help\` for more information.
486+
`);
487+
process.exit(1);
488+
}
489+
487490
if (!selectedTemplateName) {
488491
const template = await prompts.select({
489492
message: '',

0 commit comments

Comments
 (0)