nuxt-typed-router 0.2.25 → 0.2.26

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/lib/module.js CHANGED
@@ -14,29 +14,23 @@ function routeHook(filePath, routesObjectName, stripAtFromName) {
14
14
  let routesObjectString = '{';
15
15
  let routeObjectJs = {};
16
16
  const recursiveTypedRoutes = (route, level, routeObject, siblings, parentName, hadMatching) => {
17
- var _a, _b, _c;
18
- const matchingSiblings = (0, utils_1.extractMatchingSiblings)(route, level, siblings);
19
- const haveMatchingSiblings = !!(matchingSiblings === null || matchingSiblings === void 0 ? void 0 : matchingSiblings.length) &&
20
- route.path !== '/' &&
21
- ((_a = route.chunkName) === null || _a === void 0 ? void 0 : _a.split('/').length) !== level + 2;
22
- const chunkArray = (_c = (_b = route.chunkName) === null || _b === void 0 ? void 0 : _b.split('/')) !== null && _c !== void 0 ? _c : [];
23
- const isRootSibling = chunkArray[chunkArray.length - 1] === 'index';
17
+ var _a, _b;
18
+ const matchingSiblings = (0, utils_1.extractMatchingSiblings)(route, siblings);
19
+ const haveMatchingSiblings = !!(matchingSiblings === null || matchingSiblings === void 0 ? void 0 : matchingSiblings.length) && route.path !== '/';
20
+ const chunkArray = (_b = (_a = route.chunkName) === null || _a === void 0 ? void 0 : _a.split('/')) !== null && _b !== void 0 ? _b : [];
21
+ const isRootSibling = chunkArray[(chunkArray === null || chunkArray === void 0 ? void 0 : chunkArray.length) - 1] === 'index';
24
22
  if ((route.children && !haveMatchingSiblings) ||
25
23
  (!route.children && haveMatchingSiblings && isRootSibling)) {
26
24
  let childrenChunks = haveMatchingSiblings ? matchingSiblings : route.children;
27
- if (haveMatchingSiblings && isRootSibling) {
28
- childrenChunks === null || childrenChunks === void 0 ? void 0 : childrenChunks.push(route);
29
- }
30
25
  const splittedPaths = route.path.split('/');
31
26
  const parentPath = splittedPaths[splittedPaths.length - 1];
32
27
  const nameKey = (0, lodash_1.camelCase)(parentPath || 'index');
33
28
  routesObjectString += `${nameKey}:{`;
34
29
  routeObject[nameKey] = {};
35
- let unmatchedSiblings = (0, utils_1.extractUnMatchingSiblings)(route, siblings);
36
- childrenChunks === null || childrenChunks === void 0 ? void 0 : childrenChunks.map((r) => recursiveTypedRoutes(r, level + 1, routeObject[nameKey], unmatchedSiblings, nameKey, haveMatchingSiblings));
30
+ childrenChunks === null || childrenChunks === void 0 ? void 0 : childrenChunks.map((r) => recursiveTypedRoutes(r, level + 1, routeObject[nameKey], (0, utils_1.extractUnMatchingSiblings)(route, siblings), nameKey, haveMatchingSiblings));
37
31
  routesObjectString += '},';
38
32
  }
39
- else if (route.name && !haveMatchingSiblings) {
33
+ else {
40
34
  let splitted = [];
41
35
  if (route.name) {
42
36
  splitted = route.name.split('-');
@@ -52,7 +46,7 @@ function routeHook(filePath, routesObjectName, stripAtFromName) {
52
46
  };
53
47
  routes.map((r) => recursiveTypedRoutes(r, 0, routeObjectJs, routes === null || routes === void 0 ? void 0 : routes.filter((f) => f.path !== r.path)));
54
48
  routesObjectString += '}';
55
- const templateRoutes = `export const ${routesObjectName} = ${routesObjectString};`;
49
+ const templateRoutes = `export const ${routesObjectName} = ${routesObjectString} as const;`;
56
50
  await (0, save_1.saveRoutesFiles)(filePath, templateRoutes);
57
51
  });
58
52
  }
@@ -62,6 +56,7 @@ function routeHook(filePath, routesObjectName, stripAtFromName) {
62
56
  }
63
57
  const typedRouterModule = function (moduleOptions) {
64
58
  const { filePath = `${this.options.srcDir}/__routes.js`, routesObjectName = 'routerPagesNames', stripAtFromName = false, } = { ...this.options.typedRouter, ...moduleOptions };
59
+ this.nuxt.hook('build:before', () => routeHook.call(this, filePath, routesObjectName, stripAtFromName));
65
60
  this.nuxt.hook('build:extendRoutes', () => routeHook.call(this, filePath, routesObjectName, stripAtFromName));
66
61
  };
67
62
  module.exports = typedRouterModule;
package/lib/utils.js CHANGED
@@ -53,21 +53,17 @@ function extractChunkRouteName(chunkName) {
53
53
  return chunkName === null || chunkName === void 0 ? void 0 : chunkName.split('/')[chunkName.length - 1];
54
54
  }
55
55
  exports.extractChunkRouteName = extractChunkRouteName;
56
- function extractMatchingSiblings(mainRoute, level, siblingRoutes) {
57
- if (mainRoute.path !== '/') {
58
- return siblingRoutes === null || siblingRoutes === void 0 ? void 0 : siblingRoutes.filter((s) => {
59
- var _a;
60
- const chunkName = extractChunkMain(mainRoute.chunkName);
61
- if (chunkName && ((_a = s.chunkName) === null || _a === void 0 ? void 0 : _a.split('/').length) !== level + 2) {
62
- const siblingChunkName = extractChunkMain(s.chunkName);
63
- if (!siblingChunkName)
64
- return false;
65
- return chunkName === siblingChunkName;
66
- }
67
- return false;
68
- });
69
- }
70
- return [];
56
+ function extractMatchingSiblings(mainRoute, siblingRoutes) {
57
+ return siblingRoutes === null || siblingRoutes === void 0 ? void 0 : siblingRoutes.filter((s) => {
58
+ const chunkName = extractChunkMain(mainRoute.chunkName);
59
+ if (chunkName && s.name) {
60
+ const siblingChunkName = extractChunkMain(s.chunkName);
61
+ if (!siblingChunkName)
62
+ return false;
63
+ return chunkName === siblingChunkName;
64
+ }
65
+ return false;
66
+ });
71
67
  }
72
68
  exports.extractMatchingSiblings = extractMatchingSiblings;
73
69
  function extractUnMatchingSiblings(mainRoute, siblingRoutes) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nuxt-typed-router",
3
- "version": "0.2.25",
3
+ "version": "0.2.26",
4
4
  "description": "Provide autocompletion for pages route names generated by Nuxt router",
5
5
  "main": "lib/module.js",
6
6
  "keywords": [
@@ -43,6 +43,7 @@
43
43
  "typings": "types/index.d.ts",
44
44
  "dependencies": {
45
45
  "chalk": "^4.1.2",
46
+ "jest": "^27.2.4",
46
47
  "lodash": "^4.17.21",
47
48
  "log-symbols": "^5.0.0",
48
49
  "prettier": "^2.4.1"
@@ -52,11 +53,10 @@
52
53
  "@babel/preset-env": "^7.15.8",
53
54
  "@nuxt/test-utils": "^0.2.2",
54
55
  "@nuxt/types": "^2.15.8",
55
- "jest": "^27.2.4",
56
56
  "@types/jest": "^27.0.2",
57
- "@types/lodash": "^4.14.175",
58
- "@types/node": "^16.10.3",
59
- "@types/prettier": "^2.4.1",
57
+ "@types/lodash": "^4.14.173",
58
+ "@types/node": "^15.12.4",
59
+ "@types/prettier": "^2.3.2",
60
60
  "babel-jest": "^27.2.4",
61
61
  "copyfiles": "^2.4.0",
62
62
  "core-js": "^3.18.2",