@react-router/remix-routes-option-adapter 7.15.1 → 8.0.0-pre.0
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/CHANGELOG.md +7 -0
- package/dist/index.d.ts +53 -45
- package/dist/index.js +80 -120
- package/package.json +10 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# `@react-router/remix-config-routes-adapter`
|
|
2
2
|
|
|
3
|
+
## v7.16.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies:
|
|
8
|
+
- [`@react-router/dev@7.16.0`](https://github.com/remix-run/react-router/releases/tag/@react-router/dev@7.16.0)
|
|
9
|
+
|
|
3
10
|
## v7.15.1
|
|
4
11
|
|
|
5
12
|
### Patch Changes
|
package/dist/index.d.ts
CHANGED
|
@@ -1,63 +1,71 @@
|
|
|
1
|
-
import { RouteConfigEntry } from '@react-router/dev/routes';
|
|
2
1
|
|
|
2
|
+
import { RouteConfigEntry } from "@react-router/dev/routes";
|
|
3
|
+
|
|
4
|
+
//#region manifest.d.ts
|
|
3
5
|
interface RouteManifestEntry {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
path?: string;
|
|
7
|
+
index?: boolean;
|
|
8
|
+
caseSensitive?: boolean;
|
|
9
|
+
id: string;
|
|
10
|
+
parentId?: string;
|
|
11
|
+
file: string;
|
|
10
12
|
}
|
|
11
13
|
interface RouteManifest {
|
|
12
|
-
|
|
14
|
+
[routeId: string]: RouteManifestEntry;
|
|
13
15
|
}
|
|
14
|
-
|
|
16
|
+
//#endregion
|
|
17
|
+
//#region defineRoutes.d.ts
|
|
15
18
|
type DefineRoutesFunction = (callback: (defineRoute: DefineRouteFunction) => void) => RouteManifest;
|
|
16
19
|
interface DefineRouteOptions {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
20
|
+
/**
|
|
21
|
+
* Should be `true` if the route `path` is case-sensitive. Defaults to
|
|
22
|
+
* `false`.
|
|
23
|
+
*/
|
|
24
|
+
caseSensitive?: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Should be `true` if this is an index route that does not allow child routes.
|
|
27
|
+
*/
|
|
28
|
+
index?: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* An optional unique id string for this route. Use this if you need to aggregate
|
|
31
|
+
* two or more routes with the same route file.
|
|
32
|
+
*/
|
|
33
|
+
id?: string;
|
|
31
34
|
}
|
|
32
35
|
interface DefineRouteChildren {
|
|
33
|
-
|
|
36
|
+
(): void;
|
|
34
37
|
}
|
|
35
38
|
interface DefineRouteFunction {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Options for defining routes, or a function for defining child routes.
|
|
48
|
-
*/
|
|
49
|
-
optionsOrChildren?: DefineRouteOptions | DefineRouteChildren,
|
|
50
|
-
/**
|
|
51
|
-
* A function for defining child routes.
|
|
52
|
-
*/
|
|
53
|
-
children?: DefineRouteChildren): void;
|
|
54
|
-
}
|
|
39
|
+
(
|
|
40
|
+
/**
|
|
41
|
+
* The path this route uses to match the URL pathname.
|
|
42
|
+
*/
|
|
43
|
+
|
|
44
|
+
path: string | undefined,
|
|
45
|
+
/**
|
|
46
|
+
* The path to the file that exports the React component rendered by this
|
|
47
|
+
* route as its default export, relative to the `app` directory.
|
|
48
|
+
*/
|
|
55
49
|
|
|
50
|
+
file: string,
|
|
51
|
+
/**
|
|
52
|
+
* Options for defining routes, or a function for defining child routes.
|
|
53
|
+
*/
|
|
54
|
+
|
|
55
|
+
optionsOrChildren?: DefineRouteOptions | DefineRouteChildren,
|
|
56
|
+
/**
|
|
57
|
+
* A function for defining child routes.
|
|
58
|
+
*/
|
|
59
|
+
|
|
60
|
+
children?: DefineRouteChildren): void;
|
|
61
|
+
}
|
|
62
|
+
//#endregion
|
|
63
|
+
//#region index.d.ts
|
|
56
64
|
/**
|
|
57
65
|
* Adapts routes defined using [Remix's `routes` config
|
|
58
66
|
* option](https://v2.remix.run/docs/file-conventions/vite-config#routes) to
|
|
59
67
|
* React Router's config format, for use within `routes.ts`.
|
|
60
68
|
*/
|
|
61
69
|
declare function remixRoutesOptionAdapter(routes: (defineRoutes: DefineRoutesFunction) => ReturnType<DefineRoutesFunction> | Promise<ReturnType<DefineRoutesFunction>>): Promise<RouteConfigEntry[]>;
|
|
62
|
-
|
|
63
|
-
export { type DefineRouteFunction, type DefineRoutesFunction, remixRoutesOptionAdapter };
|
|
70
|
+
//#endregion
|
|
71
|
+
export { type DefineRouteFunction, type DefineRoutesFunction, remixRoutesOptionAdapter };
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @react-router/remix-routes-option-adapter
|
|
2
|
+
* @react-router/remix-routes-option-adapter v8.0.0-pre.0
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -8,133 +8,93 @@
|
|
|
8
8
|
*
|
|
9
9
|
* @license MIT
|
|
10
10
|
*/
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
15
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
16
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
17
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
18
|
-
var __export = (target, all) => {
|
|
19
|
-
for (var name in all)
|
|
20
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
21
|
-
};
|
|
22
|
-
var __copyProps = (to, from, except, desc) => {
|
|
23
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
24
|
-
for (let key of __getOwnPropNames(from))
|
|
25
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
26
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
27
|
-
}
|
|
28
|
-
return to;
|
|
29
|
-
};
|
|
30
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
31
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
32
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
33
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
34
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
35
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
36
|
-
mod
|
|
37
|
-
));
|
|
38
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
39
|
-
|
|
40
|
-
// index.ts
|
|
41
|
-
var index_exports = {};
|
|
42
|
-
__export(index_exports, {
|
|
43
|
-
remixRoutesOptionAdapter: () => remixRoutesOptionAdapter
|
|
44
|
-
});
|
|
45
|
-
module.exports = __toCommonJS(index_exports);
|
|
46
|
-
|
|
47
|
-
// manifest.ts
|
|
11
|
+
import "@react-router/dev/routes";
|
|
12
|
+
import path from "node:path";
|
|
13
|
+
//#region manifest.ts
|
|
48
14
|
function routeManifestToRouteConfig(routeManifest, rootId = "root") {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
return routeConfig;
|
|
15
|
+
let routeConfigById = {};
|
|
16
|
+
for (let id in routeManifest) {
|
|
17
|
+
let route = routeManifest[id];
|
|
18
|
+
routeConfigById[id] = {
|
|
19
|
+
id: route.id,
|
|
20
|
+
file: route.file,
|
|
21
|
+
path: route.path,
|
|
22
|
+
index: route.index,
|
|
23
|
+
caseSensitive: route.caseSensitive
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
let routeConfig = [];
|
|
27
|
+
for (let id in routeConfigById) {
|
|
28
|
+
let route = routeConfigById[id];
|
|
29
|
+
let parentId = routeManifest[route.id].parentId;
|
|
30
|
+
if (parentId === rootId) routeConfig.push(route);
|
|
31
|
+
else {
|
|
32
|
+
let parentRoute = parentId && routeConfigById[parentId];
|
|
33
|
+
if (parentRoute) {
|
|
34
|
+
parentRoute.children = parentRoute.children || [];
|
|
35
|
+
parentRoute.children.push(route);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return routeConfig;
|
|
75
40
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
var import_node_path = __toESM(require("path"));
|
|
41
|
+
//#endregion
|
|
42
|
+
//#region normalizeSlashes.ts
|
|
79
43
|
function normalizeSlashes(file) {
|
|
80
|
-
|
|
44
|
+
return file.replaceAll(path.win32.sep, "/");
|
|
81
45
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
parentRoutes.pop();
|
|
119
|
-
}
|
|
120
|
-
};
|
|
121
|
-
callback(defineRoute);
|
|
122
|
-
alreadyReturned = true;
|
|
123
|
-
return routes;
|
|
46
|
+
//#endregion
|
|
47
|
+
//#region defineRoutes.ts
|
|
48
|
+
/**
|
|
49
|
+
* A function for defining routes programmatically, instead of using the
|
|
50
|
+
* filesystem convention.
|
|
51
|
+
*/
|
|
52
|
+
const defineRoutes = (callback) => {
|
|
53
|
+
let routes = Object.create(null);
|
|
54
|
+
let parentRoutes = [];
|
|
55
|
+
let alreadyReturned = false;
|
|
56
|
+
let defineRoute = (path, file, optionsOrChildren, children) => {
|
|
57
|
+
if (alreadyReturned) throw new Error("You tried to define routes asynchronously but started defining routes before the async work was done. Please await all async data before calling `defineRoutes()`");
|
|
58
|
+
let options;
|
|
59
|
+
if (typeof optionsOrChildren === "function") {
|
|
60
|
+
options = {};
|
|
61
|
+
children = optionsOrChildren;
|
|
62
|
+
} else options = optionsOrChildren || {};
|
|
63
|
+
let route = {
|
|
64
|
+
path: path ? path : void 0,
|
|
65
|
+
index: options.index ? true : void 0,
|
|
66
|
+
caseSensitive: options.caseSensitive ? true : void 0,
|
|
67
|
+
id: options.id || createRouteId(file),
|
|
68
|
+
parentId: parentRoutes.length > 0 ? parentRoutes[parentRoutes.length - 1].id : "root",
|
|
69
|
+
file
|
|
70
|
+
};
|
|
71
|
+
if (route.id in routes) throw new Error(`Unable to define routes with duplicate route id: "${route.id}"`);
|
|
72
|
+
routes[route.id] = route;
|
|
73
|
+
if (children) {
|
|
74
|
+
parentRoutes.push(route);
|
|
75
|
+
children();
|
|
76
|
+
parentRoutes.pop();
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
callback(defineRoute);
|
|
80
|
+
alreadyReturned = true;
|
|
81
|
+
return routes;
|
|
124
82
|
};
|
|
125
83
|
function createRouteId(file) {
|
|
126
|
-
|
|
84
|
+
return normalizeSlashes(stripFileExtension(file));
|
|
127
85
|
}
|
|
128
86
|
function stripFileExtension(file) {
|
|
129
|
-
|
|
87
|
+
return file.replace(/\.[a-z0-9]+$/i, "");
|
|
130
88
|
}
|
|
131
|
-
|
|
132
|
-
|
|
89
|
+
//#endregion
|
|
90
|
+
//#region index.ts
|
|
91
|
+
/**
|
|
92
|
+
* Adapts routes defined using [Remix's `routes` config
|
|
93
|
+
* option](https://v2.remix.run/docs/file-conventions/vite-config#routes) to
|
|
94
|
+
* React Router's config format, for use within `routes.ts`.
|
|
95
|
+
*/
|
|
133
96
|
async function remixRoutesOptionAdapter(routes) {
|
|
134
|
-
|
|
135
|
-
return routeManifestToRouteConfig(routeManifest);
|
|
97
|
+
return routeManifestToRouteConfig(await routes(defineRoutes));
|
|
136
98
|
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
remixRoutesOptionAdapter
|
|
140
|
-
});
|
|
99
|
+
//#endregion
|
|
100
|
+
export { remixRoutesOptionAdapter };
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-router/remix-routes-option-adapter",
|
|
3
|
-
"
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "8.0.0-pre.0",
|
|
4
5
|
"description": "Adapter for Remix's \"routes\" config option, for use within routes.ts",
|
|
5
6
|
"bugs": {
|
|
6
7
|
"url": "https://github.com/remix-run/react-router/issues"
|
|
@@ -22,7 +23,7 @@
|
|
|
22
23
|
},
|
|
23
24
|
"wireit": {
|
|
24
25
|
"build": {
|
|
25
|
-
"command": "
|
|
26
|
+
"command": "tsdown",
|
|
26
27
|
"files": [
|
|
27
28
|
"../../pnpm-workspace.yaml",
|
|
28
29
|
"*.ts",
|
|
@@ -35,14 +36,15 @@
|
|
|
35
36
|
}
|
|
36
37
|
},
|
|
37
38
|
"devDependencies": {
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"
|
|
39
|
+
"@types/node": "^22.19.19",
|
|
40
|
+
"tsdown": "^0.22.0",
|
|
41
|
+
"typescript": "^6.0.3",
|
|
42
|
+
"wireit": "0.14.12",
|
|
43
|
+
"@react-router/dev": "8.0.0-pre.0"
|
|
42
44
|
},
|
|
43
45
|
"peerDependencies": {
|
|
44
46
|
"typescript": "^5.1.0 || ^6.0.0",
|
|
45
|
-
"@react-router/dev": "^
|
|
47
|
+
"@react-router/dev": "^8.0.0-pre.0"
|
|
46
48
|
},
|
|
47
49
|
"peerDependenciesMeta": {
|
|
48
50
|
"typescript": {
|
|
@@ -50,7 +52,7 @@
|
|
|
50
52
|
}
|
|
51
53
|
},
|
|
52
54
|
"engines": {
|
|
53
|
-
"node": ">=
|
|
55
|
+
"node": ">=22.12.0"
|
|
54
56
|
},
|
|
55
57
|
"files": [
|
|
56
58
|
"dist/",
|