vite-plugin-generoutes 0.2.6 → 0.2.8

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Ronnie Zhang(大脸怪)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/dist/index.d.ts CHANGED
@@ -34,6 +34,6 @@ interface Options {
34
34
  */
35
35
  nested: boolean;
36
36
  }
37
- declare function VitePluginGeneroutes(options?: Partial<Options>): Plugin<any>;
37
+ declare function VitePluginGeneroutes(options?: Partial<Options>): Plugin;
38
38
 
39
39
  export { VitePluginGeneroutes as default };
package/dist/index.js CHANGED
@@ -84,13 +84,13 @@ function VitePluginGeneroutes(options = {}) {
84
84
  return null;
85
85
  const pathSegments = filePath.replace(`${pagesFolder}`, "").replace(".vue", "").replace("index", "").split("/").filter((item) => !!item && !/^\(.*\)$/.test(item));
86
86
  const name = defineOptions.name || pathSegments.map((item) => toPascalCase(item)).join("_") || "Index";
87
- const component = `##/${filePath}##`;
87
+ const component = `##/${filePath}@@${name}##`;
88
88
  const routePath = `/${pathSegments.map((item) => item.replace(/\[(.*?)\]/g, (_, p1) => p1 === "...all" ? ":pathMatch(.*)*" : p1.split(",").map((i) => `:${i}`).join("/"))).join("/")}`;
89
89
  return {
90
90
  name,
91
91
  path: routePath,
92
92
  redirect: defineOptions.redirect,
93
- component,
93
+ component: defineOptions.redirect ? void 0 : component,
94
94
  meta,
95
95
  parent: defineOptions.parent
96
96
  };
@@ -112,7 +112,7 @@ function VitePluginGeneroutes(options = {}) {
112
112
 
113
113
  export const routes = ${JSON.stringify(routes, null, 2)}
114
114
  `;
115
- routesStr = routesStr.replace(/"##(.*)##"/g, (_, p1) => `() => import('${p1}')`);
115
+ routesStr = routesStr.replace(/"##(.*)##"/g, (_, p1) => `async () => ({...(await import('${p1.split("@@")[0]}')).default, name: '${p1.split("@@")[1]}'})`);
116
116
  routesStr = await prettier.format(routesStr, { parser: "babel", semi: false, singleQuote: true });
117
117
  const filePath = path.resolve(rootDir, routesPath);
118
118
  await fs.ensureDir(path.dirname(filePath));
@@ -139,7 +139,8 @@ function VitePluginGeneroutes(options = {}) {
139
139
  async configResolved(config) {
140
140
  rootDir = config.root;
141
141
  await writerRoutesFile();
142
- config.command !== "build" && createWatcher();
142
+ if (config.command !== "build")
143
+ createWatcher();
143
144
  },
144
145
  async handleHotUpdate({ file, read }) {
145
146
  if (file.includes(pagesFolder) && !ignoreFolders.some((folder) => file.includes(`/${folder}/`)) && file.endsWith(".vue")) {
@@ -151,7 +152,8 @@ function VitePluginGeneroutes(options = {}) {
151
152
  }
152
153
  },
153
154
  closeBundle() {
154
- watcher && watcher.close();
155
+ if (watcher)
156
+ watcher.close();
155
157
  }
156
158
  };
157
159
  }
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "vite-plugin-generoutes",
3
3
  "type": "module",
4
- "version": "0.2.6",
5
- "packageManager": "pnpm@9.1.1",
4
+ "version": "0.2.8",
5
+ "packageManager": "pnpm@9.9.0",
6
6
  "description": "A Vite plugin that generate routes based on the file structure, supports dynamic routes, and supports custom meta data for each route.",
7
7
  "author": "Ronnie Zhang <zclzone@outlook.com>",
8
8
  "license": "MIT",
@@ -42,35 +42,37 @@
42
42
  "release": "bumpp && npm publish",
43
43
  "test": "vitest",
44
44
  "typecheck": "tsc --noEmit",
45
- "prepare": "simple-git-hooks"
45
+ "prepare": "simple-git-hooks",
46
+ "up:deps": "taze major -I"
46
47
  },
47
48
  "peerDependencies": {
48
49
  "vite": "^5.2.11"
49
50
  },
50
51
  "dependencies": {
51
- "@antfu/utils": "^0.7.8",
52
- "@vue/compiler-sfc": "^3.4.27",
52
+ "@antfu/utils": "^0.7.10",
53
+ "@vue/compiler-sfc": "^3.4.38",
53
54
  "chokidar": "^3.6.0",
54
55
  "fs-extra": "^11.2.0",
55
- "glob": "^10.4.1",
56
- "prettier": "^3.3.2"
56
+ "glob": "^10.4.5",
57
+ "prettier": "^3.3.3"
57
58
  },
58
59
  "devDependencies": {
59
- "@antfu/eslint-config": "^2.18.1",
60
- "@antfu/ni": "^0.21.12",
60
+ "@antfu/eslint-config": "^3.0.0",
61
+ "@antfu/ni": "^0.23.0",
61
62
  "@types/fs-extra": "^11.0.4",
62
- "@types/node": "^20.12.12",
63
- "bumpp": "^9.4.1",
64
- "eslint": "^9.3.0",
63
+ "@types/node": "^20.16.2",
64
+ "bumpp": "^9.5.2",
65
+ "eslint": "^9.9.1",
65
66
  "esno": "^4.7.0",
66
- "lint-staged": "^15.2.2",
67
- "pnpm": "^9.1.1",
68
- "rimraf": "^5.0.7",
67
+ "lint-staged": "^15.2.9",
68
+ "pnpm": "^9.9.0",
69
+ "rimraf": "^5.0.10",
69
70
  "simple-git-hooks": "^2.11.1",
70
- "tsup": "^8.1.0",
71
- "typescript": "^5.4.5",
71
+ "taze": "^0.16.7",
72
+ "tsup": "^8.2.4",
73
+ "typescript": "^5.5.4",
72
74
  "unbuild": "^2.0.0",
73
- "vitest": "^1.6.0"
75
+ "vitest": "^2.0.5"
74
76
  },
75
77
  "simple-git-hooks": {
76
78
  "pre-commit": "pnpm lint-staged"