@react-router/remix-routes-option-adapter 0.0.0-nightly-f0cd1c5cc-20241029
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.md +23 -0
- package/README.md +7 -0
- package/dist/index.d.ts +63 -0
- package/dist/index.js +140 -0
- package/package.json +63 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) React Training LLC 2015-2019
|
|
4
|
+
Copyright (c) Remix Software Inc. 2020-2021
|
|
5
|
+
Copyright (c) Shopify Inc. 2022-2023
|
|
6
|
+
|
|
7
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
in the Software without restriction, including without limitation the rights
|
|
10
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
furnished to do so, subject to the following conditions:
|
|
13
|
+
|
|
14
|
+
The above copyright notice and this permission notice shall be included in all
|
|
15
|
+
copies or substantial portions of the Software.
|
|
16
|
+
|
|
17
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
+
SOFTWARE.
|
package/README.md
ADDED
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { RouteConfigEntry } from '@react-router/dev/routes';
|
|
2
|
+
|
|
3
|
+
interface RouteManifestEntry {
|
|
4
|
+
path?: string;
|
|
5
|
+
index?: boolean;
|
|
6
|
+
caseSensitive?: boolean;
|
|
7
|
+
id: string;
|
|
8
|
+
parentId?: string;
|
|
9
|
+
file: string;
|
|
10
|
+
}
|
|
11
|
+
interface RouteManifest {
|
|
12
|
+
[routeId: string]: RouteManifestEntry;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
type DefineRoutesFunction = (callback: (defineRoute: DefineRouteFunction) => void) => RouteManifest;
|
|
16
|
+
interface DefineRouteOptions {
|
|
17
|
+
/**
|
|
18
|
+
* Should be `true` if the route `path` is case-sensitive. Defaults to
|
|
19
|
+
* `false`.
|
|
20
|
+
*/
|
|
21
|
+
caseSensitive?: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Should be `true` if this is an index route that does not allow child routes.
|
|
24
|
+
*/
|
|
25
|
+
index?: boolean;
|
|
26
|
+
/**
|
|
27
|
+
* An optional unique id string for this route. Use this if you need to aggregate
|
|
28
|
+
* two or more routes with the same route file.
|
|
29
|
+
*/
|
|
30
|
+
id?: string;
|
|
31
|
+
}
|
|
32
|
+
interface DefineRouteChildren {
|
|
33
|
+
(): void;
|
|
34
|
+
}
|
|
35
|
+
interface DefineRouteFunction {
|
|
36
|
+
(
|
|
37
|
+
/**
|
|
38
|
+
* The path this route uses to match the URL pathname.
|
|
39
|
+
*/
|
|
40
|
+
path: string | undefined,
|
|
41
|
+
/**
|
|
42
|
+
* The path to the file that exports the React component rendered by this
|
|
43
|
+
* route as its default export, relative to the `app` directory.
|
|
44
|
+
*/
|
|
45
|
+
file: string,
|
|
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
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Adapts routes defined using [Remix's `routes` config
|
|
58
|
+
* option](https://remix.run/docs/en/v2/file-conventions/vite-config#routes) to
|
|
59
|
+
* React Router's config format, for use within `routes.ts`.
|
|
60
|
+
*/
|
|
61
|
+
declare function remixRoutesOptionAdapter(routes: (defineRoutes: DefineRoutesFunction) => ReturnType<DefineRoutesFunction> | Promise<ReturnType<DefineRoutesFunction>>): Promise<RouteConfigEntry[]>;
|
|
62
|
+
|
|
63
|
+
export { type DefineRoutesFunction, remixRoutesOptionAdapter };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @react-router/remix-routes-option-adapter v0.0.0-nightly-f0cd1c5cc-20241029
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) Remix Software Inc.
|
|
5
|
+
*
|
|
6
|
+
* This source code is licensed under the MIT license found in the
|
|
7
|
+
* LICENSE.md file in the root directory of this source tree.
|
|
8
|
+
*
|
|
9
|
+
* @license MIT
|
|
10
|
+
*/
|
|
11
|
+
"use strict";
|
|
12
|
+
var __create = Object.create;
|
|
13
|
+
var __defProp = Object.defineProperty;
|
|
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 react_router_remix_routes_option_adapter_exports = {};
|
|
42
|
+
__export(react_router_remix_routes_option_adapter_exports, {
|
|
43
|
+
remixRoutesOptionAdapter: () => remixRoutesOptionAdapter
|
|
44
|
+
});
|
|
45
|
+
module.exports = __toCommonJS(react_router_remix_routes_option_adapter_exports);
|
|
46
|
+
|
|
47
|
+
// manifest.ts
|
|
48
|
+
function routeManifestToRouteConfig(routeManifest, rootId = "root") {
|
|
49
|
+
let routeConfigById = {};
|
|
50
|
+
for (let id in routeManifest) {
|
|
51
|
+
let route = routeManifest[id];
|
|
52
|
+
routeConfigById[id] = {
|
|
53
|
+
id: route.id,
|
|
54
|
+
file: route.file,
|
|
55
|
+
path: route.path,
|
|
56
|
+
index: route.index,
|
|
57
|
+
caseSensitive: route.caseSensitive
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
let routeConfig = [];
|
|
61
|
+
for (let id in routeConfigById) {
|
|
62
|
+
let route = routeConfigById[id];
|
|
63
|
+
let parentId = routeManifest[route.id].parentId;
|
|
64
|
+
if (parentId === rootId) {
|
|
65
|
+
routeConfig.push(route);
|
|
66
|
+
} else {
|
|
67
|
+
let parentRoute = parentId && routeConfigById[parentId];
|
|
68
|
+
if (parentRoute) {
|
|
69
|
+
parentRoute.children = parentRoute.children || [];
|
|
70
|
+
parentRoute.children.push(route);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return routeConfig;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// normalizeSlashes.ts
|
|
78
|
+
var import_node_path = __toESM(require("path"));
|
|
79
|
+
function normalizeSlashes(file) {
|
|
80
|
+
return file.split(import_node_path.default.win32.sep).join("/");
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// defineRoutes.ts
|
|
84
|
+
var defineRoutes = (callback) => {
|
|
85
|
+
let routes = /* @__PURE__ */ Object.create(null);
|
|
86
|
+
let parentRoutes = [];
|
|
87
|
+
let alreadyReturned = false;
|
|
88
|
+
let defineRoute = (path2, file, optionsOrChildren, children) => {
|
|
89
|
+
if (alreadyReturned) {
|
|
90
|
+
throw new Error(
|
|
91
|
+
"You tried to define routes asynchronously but started defining routes before the async work was done. Please await all async data before calling `defineRoutes()`"
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
let options;
|
|
95
|
+
if (typeof optionsOrChildren === "function") {
|
|
96
|
+
options = {};
|
|
97
|
+
children = optionsOrChildren;
|
|
98
|
+
} else {
|
|
99
|
+
options = optionsOrChildren || {};
|
|
100
|
+
}
|
|
101
|
+
let route = {
|
|
102
|
+
path: path2 ? path2 : void 0,
|
|
103
|
+
index: options.index ? true : void 0,
|
|
104
|
+
caseSensitive: options.caseSensitive ? true : void 0,
|
|
105
|
+
id: options.id || createRouteId(file),
|
|
106
|
+
parentId: parentRoutes.length > 0 ? parentRoutes[parentRoutes.length - 1].id : "root",
|
|
107
|
+
file
|
|
108
|
+
};
|
|
109
|
+
if (route.id in routes) {
|
|
110
|
+
throw new Error(
|
|
111
|
+
`Unable to define routes with duplicate route id: "${route.id}"`
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
routes[route.id] = route;
|
|
115
|
+
if (children) {
|
|
116
|
+
parentRoutes.push(route);
|
|
117
|
+
children();
|
|
118
|
+
parentRoutes.pop();
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
callback(defineRoute);
|
|
122
|
+
alreadyReturned = true;
|
|
123
|
+
return routes;
|
|
124
|
+
};
|
|
125
|
+
function createRouteId(file) {
|
|
126
|
+
return normalizeSlashes(stripFileExtension(file));
|
|
127
|
+
}
|
|
128
|
+
function stripFileExtension(file) {
|
|
129
|
+
return file.replace(/\.[a-z0-9]+$/i, "");
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// index.ts
|
|
133
|
+
async function remixRoutesOptionAdapter(routes) {
|
|
134
|
+
let routeManifest = await routes(defineRoutes);
|
|
135
|
+
return routeManifestToRouteConfig(routeManifest);
|
|
136
|
+
}
|
|
137
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
138
|
+
0 && (module.exports = {
|
|
139
|
+
remixRoutesOptionAdapter
|
|
140
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@react-router/remix-routes-option-adapter",
|
|
3
|
+
"version": "0.0.0-nightly-f0cd1c5cc-20241029",
|
|
4
|
+
"description": "Adapter for Remix's \"routes\" config option, for use within routes.ts",
|
|
5
|
+
"bugs": {
|
|
6
|
+
"url": "https://github.com/remix-run/react-router/issues"
|
|
7
|
+
},
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "https://github.com/remix-run/react-router",
|
|
11
|
+
"directory": "packages/react-router-remix-routes-option-adapter"
|
|
12
|
+
},
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"main": "dist/index.js",
|
|
15
|
+
"typings": "dist/index.d.ts",
|
|
16
|
+
"exports": {
|
|
17
|
+
".": {
|
|
18
|
+
"types": "./dist/index.d.ts",
|
|
19
|
+
"default": "./dist/index.js"
|
|
20
|
+
},
|
|
21
|
+
"./package.json": "./package.json"
|
|
22
|
+
},
|
|
23
|
+
"wireit": {
|
|
24
|
+
"build": {
|
|
25
|
+
"command": "tsup",
|
|
26
|
+
"files": [
|
|
27
|
+
"*.ts",
|
|
28
|
+
"tsconfig.json",
|
|
29
|
+
"package.json"
|
|
30
|
+
],
|
|
31
|
+
"output": [
|
|
32
|
+
"dist/**"
|
|
33
|
+
]
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"tsup": "^8.3.0",
|
|
38
|
+
"typescript": "^5.1.6",
|
|
39
|
+
"wireit": "0.14.9",
|
|
40
|
+
"@react-router/dev": "0.0.0-nightly-f0cd1c5cc-20241029"
|
|
41
|
+
},
|
|
42
|
+
"peerDependencies": {
|
|
43
|
+
"typescript": "^5.1.0",
|
|
44
|
+
"@react-router/dev": "^0.0.0-nightly-f0cd1c5cc-20241029"
|
|
45
|
+
},
|
|
46
|
+
"peerDependenciesMeta": {
|
|
47
|
+
"typescript": {
|
|
48
|
+
"optional": true
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
"engines": {
|
|
52
|
+
"node": ">=20.0.0"
|
|
53
|
+
},
|
|
54
|
+
"files": [
|
|
55
|
+
"dist/",
|
|
56
|
+
"CHANGELOG.md",
|
|
57
|
+
"LICENSE.md",
|
|
58
|
+
"README.md"
|
|
59
|
+
],
|
|
60
|
+
"scripts": {
|
|
61
|
+
"build": "wireit"
|
|
62
|
+
}
|
|
63
|
+
}
|