@farris/cli 2.3.12 → 2.3.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/lib/commands/add-project.js +3 -0
  2. package/lib/commands/add-project.js.map +1 -1
  3. package/lib/commands/create.js +8 -1
  4. package/lib/commands/create.js.map +1 -1
  5. package/lib/common/constant.js +4 -1
  6. package/lib/common/constant.js.map +1 -1
  7. package/lib/common/generate-app.js +5 -0
  8. package/lib/common/generate-app.js.map +1 -1
  9. package/lib/common/registry-notice.js +38 -0
  10. package/lib/common/registry-notice.js.map +1 -0
  11. package/lib/config/vite-app.js +5 -1
  12. package/lib/config/vite-app.js.map +1 -1
  13. package/lib/plugins/html-classic.js +24 -0
  14. package/lib/plugins/html-classic.js.map +1 -0
  15. package/lib/plugins/mock.js +12 -2
  16. package/lib/plugins/mock.js.map +1 -1
  17. package/package.json +93 -93
  18. package/templates/create/AGENTS.md +16 -1
  19. package/templates/create/README.md +4 -0
  20. package/templates/lib/package.json +1 -0
  21. package/templates/lib/tsconfig.json +4 -2
  22. package/templates/lib/vitest.config.ts +4 -1
  23. package/templates/lib/vitest.setup.ts +29 -0
  24. package/templates/micro/mock/README.md +7 -2
  25. package/templates/micro/mock/user.mock.ts +24 -0
  26. package/templates/micro/package.json +1 -1
  27. package/templates/micro/src/api/http-client.ts +38 -0
  28. package/templates/micro/src/api/index.ts +1 -0
  29. package/templates/micro/src/api/user.api.ts +21 -0
  30. package/templates/micro/src/views/HomeView.tsx +33 -1
  31. package/templates/micro/src/views/__tests__/HomeView.spec.tsx +2 -0
  32. package/templates/micro/tsconfig.json +3 -1
  33. package/templates/micro/vitest.config.ts +4 -1
  34. package/templates/micro/vitest.setup.ts +29 -0
  35. package/templates/mobile/mock/README.md +7 -2
  36. package/templates/mobile/tsconfig.json +3 -1
  37. package/templates/mobile/vitest.config.ts +4 -1
  38. package/templates/mobile/vitest.setup.ts +29 -0
  39. package/templates/web/mock/README.md +7 -2
  40. package/templates/web/mock/user.mock.ts +24 -0
  41. package/templates/web/package.json +1 -1
  42. package/templates/web/src/api/http-client.ts +38 -0
  43. package/templates/web/src/api/index.ts +1 -0
  44. package/templates/web/src/api/user.api.ts +21 -0
  45. package/templates/web/src/views/HomeView.tsx +33 -1
  46. package/templates/web/src/views/__tests__/HomeView.spec.tsx +2 -0
  47. package/templates/web/tsconfig.json +3 -1
  48. package/templates/web/vitest.config.ts +4 -1
  49. package/templates/web/vitest.setup.ts +29 -0
  50. package/templates/micro/mock/tsconfig.json +0 -10
  51. package/templates/mobile/mock/tsconfig.json +0 -10
  52. package/templates/web/mock/tsconfig.json +0 -10
@@ -3,7 +3,9 @@
3
3
  "include": [
4
4
  "env.d.ts",
5
5
  "src/**/*",
6
- "src/**/*.vue"
6
+ "src/**/*.vue",
7
+ "mock/**/*",
8
+ "vitest.setup.ts"
7
9
  ],
8
10
  "compilerOptions": {
9
11
  "composite": true,
@@ -1,10 +1,13 @@
1
1
  import vue from '@vitejs/plugin-vue';
2
+ import vueJsx from '@vitejs/plugin-vue-jsx';
2
3
  import { configDefaults, defineConfig } from 'vitest/config';
3
4
 
4
5
  export default defineConfig({
5
- plugins: [vue()],
6
+ plugins: [vue(), vueJsx()],
6
7
  test: {
7
8
  environment: 'jsdom',
9
+ // jsdom 缺失的浏览器 API(如 ResizeObserver)统一在这里补齐,用例里不要再各写一份
10
+ setupFiles: ['./vitest.setup.ts'],
8
11
  // 官方默认收集范围(**/*.{test,spec}.*),源码旁的测试才会被收集
9
12
  include: [...configDefaults.include],
10
13
  exclude: [...configDefaults.exclude, '**/__sandbox_*/**']
@@ -0,0 +1,29 @@
1
+ /**
2
+ * 测试运行前的环境兜底(由 `vitest.config.ts` 的 `setupFiles` 引入)。
3
+ *
4
+ * jsdom 没有实现全部浏览器 API,而组件在挂载时会直接读它们:例如依赖尺寸观测的组件,
5
+ * 缺 `ResizeObserver` 就报错。统一在这里补齐,不要在用例里各写一份。
6
+ * 需要更多 API(`IntersectionObserver`、`matchMedia` 等)时同样是往这里加。
7
+ */
8
+ class ResizeObserverStub implements ResizeObserver {
9
+ constructor(private readonly callback: ResizeObserverCallback) {}
10
+
11
+ /**
12
+ * 同步回调一次。只写空方法的话,靠回调算尺寸的组件在用例里永远不会被触发,
13
+ * 测试就变成"挂上去就完事"的假绿。
14
+ */
15
+ observe(target: Element): void {
16
+ const entry = [
17
+ { target, contentRect: (target as HTMLElement).getBoundingClientRect() }
18
+ ] as unknown as ResizeObserverEntry[];
19
+ this.callback(entry, this);
20
+ }
21
+
22
+ unobserve(): void {}
23
+
24
+ disconnect(): void {}
25
+ }
26
+
27
+ if (typeof globalThis.ResizeObserver === 'undefined') {
28
+ globalThis.ResizeObserver = ResizeObserverStub;
29
+ }
@@ -1,10 +0,0 @@
1
- {
2
- // mock 目录的独立 TS 工程:只服务于编辑器与按需类型检查(应用自身的 typecheck 不含本目录)。
3
- // msw 是应用的开发期依赖(见 package.json 的 devDependencies),按常规模块解析即可。
4
- "extends": "../tsconfig.json",
5
- "compilerOptions": {
6
- "composite": false,
7
- "noEmit": true
8
- },
9
- "include": ["**/*.ts", "**/*.d.ts"]
10
- }
@@ -1,10 +0,0 @@
1
- {
2
- // mock 目录的独立 TS 工程:只服务于编辑器与按需类型检查(应用自身的 typecheck 不含本目录)。
3
- // msw 是应用的开发期依赖(见 package.json 的 devDependencies),按常规模块解析即可。
4
- "extends": "../tsconfig.json",
5
- "compilerOptions": {
6
- "composite": false,
7
- "noEmit": true
8
- },
9
- "include": ["**/*.ts", "**/*.d.ts"]
10
- }
@@ -1,10 +0,0 @@
1
- {
2
- // mock 目录的独立 TS 工程:只服务于编辑器与按需类型检查(应用自身的 typecheck 不含本目录)。
3
- // msw 是应用的开发期依赖(见 package.json 的 devDependencies),按常规模块解析即可。
4
- "extends": "../tsconfig.json",
5
- "compilerOptions": {
6
- "composite": false,
7
- "noEmit": true
8
- },
9
- "include": ["**/*.ts", "**/*.d.ts"]
10
- }