Skip to content

Commit 4d4d4d9

Browse files
authored
chore(cli): use 'vite test' replace 'vitest' command (#206)
### TL;DR Improved monorepo template scripts and added silent flag to npm install tests. ### What changed? - Updated monorepo template scripts in `package.json` to use more descriptive names: - Changed `prepublishOnly` to `build:all` - Changed `test` to `test:all` - Updated the `ready` script to use the new script names - Added `--silent` flag to npm install commands in snap tests to reduce output verbosity - Enhanced the `fixPackageJsonForVitePlus` function to properly update test scripts - Simplified the monorepo template's `vite.config.ts` by replacing the test projects configuration with commented placeholders - Updated snap tests to display package.json contents for better verification - Changed vitest config import to use `@voidzero-dev/vite-plus` ### How to test? 1. Create a new monorepo project: `vp new my-monorepo --template monorepo` 2. Verify the root package.json has the updated script names 3. Add a new library: `vp new --lib packages/my-lib --template react` 4. Check that the library's package.json has the correct test script 5. Run the CLI snap tests: `vite test packages/cli/snap-tests/npm-install-with-options` ### Why make this change? The script naming improvements make the monorepo template more intuitive and consistent. The `build:all` and `test:all` names better reflect their purpose of running these commands across all packages. Adding the silent flag to npm install tests reduces noise in test output, making it easier to focus on relevant information. The package.json display in snap tests provides better verification of template generation.
1 parent 4eaf174 commit 4d4d4d9

8 files changed

Lines changed: 118 additions & 32 deletions

File tree

packages/cli/snap-tests/npm-install-with-options/snap.txt

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,13 @@ aliases: add, i, in, ins, inst, insta, instal, isnt, isnta, isntal, isntall
2121
Run "npm help install" for more info
2222

2323

24-
> vite install --production # https://docs.npmjs.com/cli/v10/commands/npm-install
24+
> vite install --production --silent # https://docs.npmjs.com/cli/v10/commands/npm-install
2525

26-
added 1 package, and audited 2 packages in <variable>ms
27-
28-
found 0 vulnerabilities
29-
30-
31-
npm warn config production Use `--omit=dev` instead.
3226

3327
> ls node_modules
3428
@oxlint
3529
tslib
3630

37-
> vite install --production # install again hit cache
31+
> vite install --production --silent # install again hit cache
3832
✓ cache hit, replaying
3933

40-
added 1 package, and audited 2 packages in <variable>ms
41-
42-
found 0 vulnerabilities
43-
44-
45-
npm warn config production Use `--omit=dev` instead.

packages/cli/snap-tests/npm-install-with-options/steps.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
},
55
"commands": [
66
"vite install --help # print help message",
7-
"vite install --production # https://docs.npmjs.com/cli/v10/commands/npm-install",
7+
"vite install --production --silent # https://docs.npmjs.com/cli/v10/commands/npm-install",
88
"ls node_modules",
9-
"vite install --production # install again hit cache"
9+
"vite install --production --silent # install again hit cache"
1010
]
1111
}

packages/global/snap-tests/new-monorepo/snap.txt

Lines changed: 104 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,11 @@ vite.config.ts
6767
"version": "0.0.0",
6868
"type": "module",
6969
"scripts": {
70-
"ready": "vite fmt && vite run lint && vite run test && vite run prepublishOnly",
70+
"ready": "vite fmt && vite run lint && vite run test:all && vite run build:all",
7171
"dev": "vite run website#dev",
7272
"lint": "vite lint --type-aware",
73-
"test": "vite test --passWithNoTests",
74-
"prepublishOnly": "vite run -r build"
73+
"test:all": "vite run -r test",
74+
"build:all": "vite run -r build"
7575
},
7676
"devDependencies": {
7777
"vite": "catalog:"
@@ -139,10 +139,65 @@ website
139139
vite run dev
140140

141141

142-
> cd hello-vite-plus && ls -a packages
142+
> cd hello-vite-plus && ls -a packages && cat packages/my-lib/package.json # check package.json
143143
.
144144
..
145145
my-lib
146+
{
147+
"name": "my-lib",
148+
"version": "0.0.0",
149+
"description": "A starter for creating a React component library.",
150+
"type": "module",
151+
"license": "MIT",
152+
"homepage": "https://github.com/author/library#readme",
153+
"bugs": {
154+
"url": "https://github.com/author/library/issues"
155+
},
156+
"repository": {
157+
"type": "git",
158+
"url": "git+https://github.com/author/library.git"
159+
},
160+
"author": "Author Name <author.name@mail.com>",
161+
"files": [
162+
"dist"
163+
],
164+
"main": "./dist/index.js",
165+
"module": "./dist/index.js",
166+
"types": "./dist/index.d.ts",
167+
"exports": {
168+
".": "./dist/index.js",
169+
"./package.json": "./package.json"
170+
},
171+
"publishConfig": {
172+
"access": "public"
173+
},
174+
"scripts": {
175+
"build": "vite lib",
176+
"dev": "vite lib --watch",
177+
"playground": "vite --config playground/vite.config.ts",
178+
"test": "vite test",
179+
"typecheck": "tsc --noEmit",
180+
"release": "bumpp && pnpm publish",
181+
"prepublishOnly": "pnpm run build",
182+
"ready": "vite fmt && vite lint --type-aware && vite run build && vite test --passWithNoTests"
183+
},
184+
"devDependencies": {
185+
"@testing-library/jest-dom": "^6.6.3",
186+
"@testing-library/react": "^16.3.0",
187+
"@types/node": "catalog:",
188+
"@types/react": "^19.1.3",
189+
"@types/react-dom": "^19.1.4",
190+
"@vitejs/plugin-react": "^4.4.1",
191+
"bumpp": "catalog:",
192+
"happy-dom": "catalog:",
193+
"react": "^19.1.0",
194+
"react-dom": "^19.1.0",
195+
"tsdown": "catalog:",
196+
"typescript": "catalog:",
197+
"vite": "catalog:",
198+
"vitest": "catalog:"
199+
}
200+
}
146201

147202
> cd hello-vite-plus && vp new --lib tools/my-tool --template default # add lib new not exists tools directory
148203

@@ -167,7 +222,51 @@ my-lib
167222
vite run dev
168223

169224

170-
> cd hello-vite-plus && ls -a tools
225+
> cd hello-vite-plus && ls -a tools && cat tools/my-tool/package.json # check package.json
171226
.
172227
..
173228
my-tool
229+
{
230+
"name": "my-tool",
231+
"version": "0.0.0",
232+
"description": "A starter for creating a TypeScript package.",
233+
"type": "module",
234+
"license": "MIT",
235+
"homepage": "https://github.com/author/library#readme",
236+
"bugs": {
237+
"url": "https://github.com/author/library/issues"
238+
},
239+
"repository": {
240+
"type": "git",
241+
"url": "git+https://github.com/author/library.git"
242+
},
243+
"author": "Author Name <author.name@mail.com>",
244+
"files": [
245+
"dist"
246+
],
247+
"main": "./dist/index.js",
248+
"module": "./dist/index.js",
249+
"types": "./dist/index.d.ts",
250+
"exports": {
251+
".": "./dist/index.js",
252+
"./package.json": "./package.json"
253+
},
254+
"publishConfig": {
255+
"access": "public"
256+
},
257+
"scripts": {
258+
"build": "vite lib",
259+
"dev": "vite lib --watch",
260+
"test": "vite test",
261+
"typecheck": "tsc --noEmit",
262+
"release": "bumpp && npm publish",
263+
"ready": "vite fmt && vite lint --type-aware && vite run build && vite test --passWithNoTests"
264+
},
265+
"devDependencies": {
266+
"@types/node": "catalog:",
267+
"bumpp": "catalog:",
268+
"tsdown": "catalog:",
269+
"typescript": "catalog:",
270+
"vitest": "catalog:"
271+
}
272+
}

packages/global/snap-tests/new-monorepo/steps.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
"cd hello-vite-plus && vp new --app --template vanilla-ts apps/my-app # add app",
88
"cd hello-vite-plus && ls -a apps",
99
"cd hello-vite-plus && vp new --lib packages/my-lib --template react # add lib",
10-
"cd hello-vite-plus && ls -a packages",
10+
"cd hello-vite-plus && ls -a packages && cat packages/my-lib/package.json # check package.json",
1111
"cd hello-vite-plus && vp new --lib tools/my-tool --template default # add lib new not exists tools directory",
12-
"cd hello-vite-plus && ls -a tools"
12+
"cd hello-vite-plus && ls -a tools && cat tools/my-tool/package.json # check package.json"
1313
]
1414
}

packages/global/src/new.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -869,6 +869,9 @@ async function fixPackageJsonForVitePlus(projectDir: string, selectedPackageMana
869869
if (pkg.scripts?.dev === 'tsdown --watch') {
870870
pkg.scripts.dev = 'vite lib --watch';
871871
}
872+
if (pkg.scripts?.test === 'vitest' || pkg.scripts?.test === 'vitest run') {
873+
pkg.scripts.test = 'vite test';
874+
}
872875
// try to add ready script
873876
if (!pkg.scripts?.ready) {
874877
pkg.scripts.ready = 'vite fmt && vite lint --type-aware && vite run build && vite test --passWithNoTests';

packages/global/templates/monorepo/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
"tools/*"
99
],
1010
"scripts": {
11-
"ready": "vite fmt && vite run lint && vite run test && vite run prepublishOnly",
11+
"ready": "vite fmt && vite run lint && vite run test:all && vite run build:all",
1212
"dev": "vite run website#dev",
1313
"lint": "vite lint --type-aware",
14-
"test": "vite test --passWithNoTests",
15-
"prepublishOnly": "vite run -r build"
14+
"test:all": "vite run -r test",
15+
"build:all": "vite run -r build"
1616
},
1717
"devDependencies": {
1818
"vite": "catalog:"
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
11
import { defineConfig } from 'vite';
22

3-
export default defineConfig({
4-
test: {
5-
projects: ['apps/*', 'packages/*', 'tools/*'],
6-
},
7-
});
3+
export default defineConfig({});

vitest.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { defineConfig } from 'vitest/config';
1+
import { defineConfig } from '@voidzero-dev/vite-plus';
22

33
export default defineConfig({
44
test: {

0 commit comments

Comments
 (0)