warehouse-mock 1.1.1 → 1.1.3

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.
package/dist/index.d.ts CHANGED
@@ -23,6 +23,9 @@ declare class WarehouseMockPlugin {
23
23
  constructor(options?: MockPluginOptions);
24
24
  /**
25
25
  * 实时扫描 mock 目录,获取所有 mock 文件名列表
26
+ * 支持两种格式:
27
+ * 1. 旧格式:api.json
28
+ * 2. 新格式:api/.config.json
26
29
  */
27
30
  getMockFileList(): string[];
28
31
  /**
package/dist/index.js CHANGED
@@ -35,6 +35,9 @@ class WarehouseMockPlugin {
35
35
  }
36
36
  /**
37
37
  * 实时扫描 mock 目录,获取所有 mock 文件名列表
38
+ * 支持两种格式:
39
+ * 1. 旧格式:api.json
40
+ * 2. 新格式:api/.config.json
38
41
  */
39
42
  getMockFileList() {
40
43
  const mockPath = this.getResolvedMockPath();
@@ -42,7 +45,17 @@ class WarehouseMockPlugin {
42
45
  if (fs_1.default.existsSync(mockPath)) {
43
46
  const files = fs_1.default.readdirSync(mockPath);
44
47
  files.forEach((file) => {
45
- if (file.endsWith('.json')) {
48
+ const filePath = path_1.default.join(mockPath, file);
49
+ const stats = fs_1.default.statSync(filePath);
50
+ if (stats.isDirectory()) {
51
+ // 新格式:检查目录下是否有 .config.json
52
+ const configPath = path_1.default.join(filePath, '.config.json');
53
+ if (fs_1.default.existsSync(configPath)) {
54
+ fileList.push(file);
55
+ }
56
+ }
57
+ else if (file.endsWith('.json') && !file.startsWith('.')) {
58
+ // 旧格式:直接是 .json 文件(排除 .config.json 等隐藏文件)
46
59
  fileList.push(file.replace(/\.json$/, ''));
47
60
  }
48
61
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "warehouse-mock",
3
- "version": "1.1.1",
3
+ "version": "1.1.3",
4
4
  "description": "一个专为 Vue 2 项目设计的 Webpack 插件,支持 RPC 风格接口 mock,零业务代码侵入,实时更新",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -41,7 +41,7 @@
41
41
  "npm": "^11.7.0"
42
42
  },
43
43
  "optionalDependencies": {
44
- "warehouse-mock-admin": "^1.0.0"
44
+ "warehouse-mock-admin": "^1.0.1"
45
45
  },
46
46
  "devDependencies": {
47
47
  "@types/node": "^18.0.0",