@uxf/router 11.111.2 → 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.
|
|
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",
|
|
@@ -26,12 +26,12 @@
|
|
|
26
26
|
"true-case-path": "2.2.1"
|
|
27
27
|
},
|
|
28
28
|
"peerDependencies": {
|
|
29
|
-
"@uxf/core": "11.
|
|
29
|
+
"@uxf/core": "11.114.0",
|
|
30
30
|
"next": ">= 12",
|
|
31
31
|
"superstruct": "^2.0.2"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"@uxf/core": "11.
|
|
34
|
+
"@uxf/core": "11.114.0",
|
|
35
35
|
"next": "16.1.6",
|
|
36
36
|
"superstruct": "^2.0.2"
|
|
37
37
|
}
|
package/router.js
CHANGED
|
@@ -39,7 +39,6 @@ function createRouter(routes, routerOptions) {
|
|
|
39
39
|
throw new Error(`Route '${String(route)}' not found.`);
|
|
40
40
|
}
|
|
41
41
|
const restParams = {};
|
|
42
|
-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
43
42
|
Object.keys(params !== null && params !== void 0 ? params : empty_object_1.EMPTY_OBJECT).forEach((key) => {
|
|
44
43
|
const value = params[key];
|
|
45
44
|
const segment = `[${key}]`;
|
|
@@ -132,7 +131,6 @@ function createRouter(routes, routerOptions) {
|
|
|
132
131
|
pathname: typeof routes[route].path === "string"
|
|
133
132
|
? routes[route].path
|
|
134
133
|
: routes[route].path[(_a = options === null || options === void 0 ? void 0 : options.locale) !== null && _a !== void 0 ? _a : (0, throw_error_1.throwError)("Locale is required")],
|
|
135
|
-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
136
134
|
query: params !== null && params !== void 0 ? params : null,
|
|
137
135
|
};
|
|
138
136
|
},
|
|
@@ -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 (
|
|
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"),
|