@uxf/router 11.114.0 → 11.119.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uxf/router",
3
- "version": "11.114.0",
3
+ "version": "11.119.2",
4
4
  "description": "UXF Router",
5
5
  "author": "UXFans <dev@uxf.cz>",
6
6
  "homepage": "https://gitlab.com/uxf-npm/router#readme",
@@ -3,6 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.routesCheck = routesCheck;
5
5
  const throw_error_1 = require("@uxf/core/utils/throw-error");
6
+ const fs_1 = require("fs");
6
7
  const path_1 = require("path");
7
8
  const process_1 = require("process");
8
9
  const true_case_path_1 = require("true-case-path");
@@ -19,6 +20,33 @@ function fileExists(path) {
19
20
  }
20
21
  }
21
22
  }
23
+ function findAppRoute(dir, parts) {
24
+ if (parts.length === 0) {
25
+ if (fileExists((0, path_1.join)(dir, "page.ts")) || fileExists((0, path_1.join)(dir, "route.ts"))) {
26
+ return true;
27
+ }
28
+ }
29
+ else {
30
+ if (findAppRoute((0, path_1.join)(dir, parts[0]), parts.slice(1))) {
31
+ return true;
32
+ }
33
+ }
34
+ let entries;
35
+ try {
36
+ entries = (0, fs_1.readdirSync)(dir);
37
+ }
38
+ catch {
39
+ return false;
40
+ }
41
+ for (const entry of entries) {
42
+ if (entry.startsWith("(") && entry.endsWith(")")) {
43
+ if (findAppRoute((0, path_1.join)(dir, entry), parts)) {
44
+ return true;
45
+ }
46
+ }
47
+ }
48
+ return false;
49
+ }
22
50
  let hasError = false;
23
51
  function routesCheck(routes, options) {
24
52
  Object.entries(routes).forEach(([routeName, routeDefinition]) => {
@@ -40,10 +68,7 @@ function routesCheck(routes, options) {
40
68
  if (fileExists(pagePath)) {
41
69
  return;
42
70
  }
43
- if (fileExists((0, path_1.join)(options.appDir, ...pathParts, "page.ts"))) {
44
- return;
45
- }
46
- if (fileExists((0, path_1.join)(options.appDir, ...pathParts, "route.ts"))) {
71
+ if (findAppRoute(options.appDir, pathParts)) {
47
72
  return;
48
73
  }
49
74
  throw new Error("Invalid");
@@ -13,6 +13,8 @@ describe("routesCheck", () => {
13
13
  app1: { path: "/app-directory" },
14
14
  app2: { path: "/app-directory/[param]" },
15
15
  app3: { path: "/api" },
16
+ app4: { path: "/grouped-route" }, // page lives inside a (group) folder
17
+ app5: { path: "/nested/deep" }, // page lives inside nested (group) folders
16
18
  }, {
17
19
  shouldProcessExit: false,
18
20
  appDir: (0, path_1.join)(__dirname, "__test__", "app"),