Skip to content

Commit 3901dfb

Browse files
authored
fix(create): improve UX when running vp create from monorepo subdirectories (#662)
## Summary - Show "Detected monorepo root at <path>" info message when running `vp create` from a monorepo subdirectory - In interactive mode, add a "current directory" option to the parent dir selector when the user's cwd is not under a standard workspace pattern dir, and default to it - In non-interactive mode, show a hint about using `--directory` - Fix `rootDir` reset to cwd for non-monorepo `vp create` (previously walked up to a parent with `package.json`) - Fix "Package name:" prompt to accept Enter without typing (treat `undefined` as "use the default") - Rename "other" to "other directory" in monorepo parent dir prompt for clarity ## Test plan - [x] Add snap test covering: workspace subdir, workspace parent dir, non-workspace dir, and `--directory` from a subdir
1 parent cf0e522 commit 3901dfb

12 files changed

Lines changed: 147 additions & 19 deletions

File tree

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"name": "website",
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+
{
2+
"name": "test-monorepo",
3+
"version": "0.0.0",
4+
"private": true,
5+
"packageManager": "pnpm@10.12.1"
6+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
packages:
2+
- apps/*
3+
- packages/*
4+
- tools/*
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"name": "helper",
3+
"version": "0.0.0"
4+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
> cd apps/website && vp create --no-interactive vite:generator # from workspace subdir
2+
> test -f tools/vite-plus-generator/package.json && echo 'Created at tools/vite-plus-generator' || echo 'NOT at tools/'
3+
Created at tools/vite-plus-generator
4+
5+
> test ! -f apps/website/tools/vite-plus-generator/package.json && echo 'Not in apps/website/' || echo 'BUG: in apps/website/'
6+
Not in apps/website/
7+
8+
> cd apps && vp create --no-interactive vite:application # from workspace parent dir
9+
> test -f apps/vite-plus-application/package.json && echo 'Created at apps/vite-plus-application' || echo 'NOT at apps/'
10+
Created at apps/vite-plus-application
11+
12+
> cd scripts/helper && vp create --no-interactive vite:library # from non-workspace dir
13+
> test -f packages/vite-plus-library/package.json && echo 'Created at packages/vite-plus-library' || echo 'NOT at packages/'
14+
Created at packages/vite-plus-library
15+
16+
> test ! -f scripts/helper/packages/vite-plus-library/package.json && echo 'Not in scripts/helper/' || echo 'BUG: in scripts/helper/'
17+
Not in scripts/helper/
18+
19+
> cd scripts/helper && vp create --no-interactive vite:application --directory apps/custom-app # --directory from non-workspace dir
20+
> test -f apps/custom-app/package.json && echo 'Created at apps/custom-app with --directory' || echo 'NOT at apps/custom-app'
21+
Created at apps/custom-app with --directory
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"commands": [
3+
{
4+
"command": "cd apps/website && vp create --no-interactive vite:generator # from workspace subdir",
5+
"ignoreOutput": true
6+
},
7+
"test -f tools/vite-plus-generator/package.json && echo 'Created at tools/vite-plus-generator' || echo 'NOT at tools/'",
8+
"test ! -f apps/website/tools/vite-plus-generator/package.json && echo 'Not in apps/website/' || echo 'BUG: in apps/website/'",
9+
10+
{
11+
"command": "cd apps && vp create --no-interactive vite:application # from workspace parent dir",
12+
"ignoreOutput": true
13+
},
14+
"test -f apps/vite-plus-application/package.json && echo 'Created at apps/vite-plus-application' || echo 'NOT at apps/'",
15+
16+
{
17+
"command": "cd scripts/helper && vp create --no-interactive vite:library # from non-workspace dir",
18+
"ignoreOutput": true
19+
},
20+
"test -f packages/vite-plus-library/package.json && echo 'Created at packages/vite-plus-library' || echo 'NOT at packages/'",
21+
"test ! -f scripts/helper/packages/vite-plus-library/package.json && echo 'Not in scripts/helper/' || echo 'BUG: in scripts/helper/'",
22+
23+
{
24+
"command": "cd scripts/helper && vp create --no-interactive vite:application --directory apps/custom-app # --directory from non-workspace dir",
25+
"ignoreOutput": true
26+
},
27+
"test -f apps/custom-app/package.json && echo 'Created at apps/custom-app with --directory' || echo 'NOT at apps/custom-app'"
28+
]
29+
}
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+
}

0 commit comments

Comments
 (0)