Skip to content

Commit c5270c2

Browse files
committed
fix(create): use cwd as rootDir for non-monorepo vp create
When running `vp create` from a subdirectory that has a plain package.json (without workspaces) somewhere up the tree, detectWorkspace would walk up and set rootDir to that parent directory. This caused projects to be created at the parent root instead of the user's current directory. Reset rootDir to cwd when isMonorepo is false, since the parent root is only meaningful for monorepo workspace resolution.
1 parent 5ff8f5a commit c5270c2

5 files changed

Lines changed: 27 additions & 0 deletions

File tree

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"name": "parent-project",
3+
"version": "0.0.0"
4+
}

packages/cli/snap-tests-global/create-from-nonworkspace-subdir/scripts/.keep

Whitespace-only changes.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
> cd scripts && vp create --no-interactive vite:application # from non-monorepo subdir
2+
> test -f scripts/vite-plus-application/package.json && echo 'Created at scripts/vite-plus-application' || echo 'NOT at scripts/'
3+
Created at scripts/vite-plus-application
4+
5+
> test ! -f vite-plus-application/package.json && echo 'Not at parent root' || echo 'BUG: created at parent root'
6+
Not at parent root
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"commands": [
3+
{
4+
"command": "cd scripts && vp create --no-interactive vite:application # from non-monorepo subdir",
5+
"ignoreOutput": true
6+
},
7+
"test -f scripts/vite-plus-application/package.json && echo 'Created at scripts/vite-plus-application' || echo 'NOT at scripts/'",
8+
"test ! -f vite-plus-application/package.json && echo 'Not at parent root' || echo 'BUG: created at parent root'"
9+
]
10+
}

packages/cli/src/create/bin.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,13 @@ Use \`vp create --list\` to list all available templates, or run \`vp create --h
188188
const cwd = process.cwd();
189189
const workspaceInfoOptional = await detectWorkspace(cwd);
190190
const isMonorepo = workspaceInfoOptional.isMonorepo;
191+
192+
// For non-monorepo, always use cwd as rootDir.
193+
// detectWorkspace walks up to find the nearest package.json, but for `vp create`
194+
// in standalone mode, the project should be created relative to where the user is.
195+
if (!isMonorepo) {
196+
workspaceInfoOptional.rootDir = cwd;
197+
}
191198
const cwdRelativeToRoot =
192199
isMonorepo && workspaceInfoOptional.rootDir !== cwd
193200
? displayRelative(cwd, workspaceInfoOptional.rootDir)

0 commit comments

Comments
 (0)