@react-router/dev 0.0.0-experimental-f7761f1cd → 0.0.0-experimental-63fd291ad
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/bin.js +15 -0
- package/dist/cli/index.d.ts +1 -2
- package/dist/cli/index.js +2649 -378
- package/dist/config.d.ts +280 -2
- package/dist/config.js +19 -2
- package/dist/{routes-Kx8VZRs3.d.ts → routes-CZR-bKRt.d.ts} +62 -63
- package/dist/routes.d.ts +2 -3
- package/dist/routes.js +190 -3
- package/dist/vite/cloudflare.d.ts +24 -0
- package/dist/vite/cloudflare.js +949 -0
- package/dist/vite.d.ts +6 -7
- package/dist/vite.js +6588 -3187
- package/module-sync-enabled/index.mjs +2 -2
- package/package.json +59 -53
- package/bin.cjs +0 -20
- package/dist/build-_VgN3Fs2.js +0 -41
- package/dist/config-DvmRcD4Z.d.ts +0 -279
- package/dist/dev-Cx78re5_.js +0 -53
- package/dist/routes-Craztzkd.js +0 -194
- package/dist/typegen-DrKkP7mg.js +0 -857
package/dist/routes-Craztzkd.js
DELETED
|
@@ -1,194 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @react-router/dev v0.0.0-experimental-f7761f1cd
|
|
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
|
-
import * as Path from "pathe";
|
|
12
|
-
import pick from "lodash/pick.js";
|
|
13
|
-
import * as v from "valibot";
|
|
14
|
-
//#region invariant.ts
|
|
15
|
-
function invariant(value, message) {
|
|
16
|
-
if (value === false || value === null || typeof value === "undefined") {
|
|
17
|
-
console.error("The following error is a bug in React Router; please open an issue! https://github.com/remix-run/react-router/issues/new/choose");
|
|
18
|
-
throw new Error(message);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
//#endregion
|
|
22
|
-
//#region config/routes.ts
|
|
23
|
-
function setAppDirectory(directory) {
|
|
24
|
-
globalThis.__reactRouterAppDirectory = directory;
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Provides the absolute path to the app directory, for use within `routes.ts`.
|
|
28
|
-
* This is designed to support resolving file system routes.
|
|
29
|
-
*/
|
|
30
|
-
function getAppDirectory() {
|
|
31
|
-
invariant(globalThis.__reactRouterAppDirectory);
|
|
32
|
-
return globalThis.__reactRouterAppDirectory;
|
|
33
|
-
}
|
|
34
|
-
const routeConfigEntrySchema = v.pipe(v.custom((value) => {
|
|
35
|
-
return !(typeof value === "object" && value !== null && "then" in value && "catch" in value);
|
|
36
|
-
}, "Invalid type: Expected object but received a promise. Did you forget to await?"), v.object({
|
|
37
|
-
id: v.optional(v.pipe(v.string(), v.notValue("root", "A route cannot use the reserved id 'root'."))),
|
|
38
|
-
path: v.optional(v.string()),
|
|
39
|
-
index: v.optional(v.boolean()),
|
|
40
|
-
caseSensitive: v.optional(v.boolean()),
|
|
41
|
-
file: v.string(),
|
|
42
|
-
children: v.optional(v.array(v.lazy(() => routeConfigEntrySchema)))
|
|
43
|
-
}));
|
|
44
|
-
const resolvedRouteConfigSchema = v.array(routeConfigEntrySchema);
|
|
45
|
-
function validateRouteConfig({ routeConfigFile, routeConfig }) {
|
|
46
|
-
if (!routeConfig) return {
|
|
47
|
-
valid: false,
|
|
48
|
-
message: `Route config must be the default export in "${routeConfigFile}".`
|
|
49
|
-
};
|
|
50
|
-
if (!Array.isArray(routeConfig)) return {
|
|
51
|
-
valid: false,
|
|
52
|
-
message: `Route config in "${routeConfigFile}" must be an array.`
|
|
53
|
-
};
|
|
54
|
-
let { issues } = v.safeParse(resolvedRouteConfigSchema, routeConfig);
|
|
55
|
-
if (issues?.length) {
|
|
56
|
-
let { root, nested } = v.flatten(issues);
|
|
57
|
-
return {
|
|
58
|
-
valid: false,
|
|
59
|
-
message: [
|
|
60
|
-
`Route config in "${routeConfigFile}" is invalid.`,
|
|
61
|
-
root ? `${root}` : [],
|
|
62
|
-
nested ? Object.entries(nested).map(([path, message]) => `Path: routes.${path}\n${message}`) : []
|
|
63
|
-
].flat().join("\n\n")
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
return {
|
|
67
|
-
valid: true,
|
|
68
|
-
routeConfig
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
const createConfigRouteOptionKeys = [
|
|
72
|
-
"id",
|
|
73
|
-
"index",
|
|
74
|
-
"caseSensitive"
|
|
75
|
-
];
|
|
76
|
-
function route(path, file, optionsOrChildren, children) {
|
|
77
|
-
let options = {};
|
|
78
|
-
if (Array.isArray(optionsOrChildren) || !optionsOrChildren) children = optionsOrChildren;
|
|
79
|
-
else options = optionsOrChildren;
|
|
80
|
-
return {
|
|
81
|
-
file,
|
|
82
|
-
children,
|
|
83
|
-
path: path ?? void 0,
|
|
84
|
-
...pick(options, createConfigRouteOptionKeys)
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
const createIndexOptionKeys = ["id"];
|
|
88
|
-
/**
|
|
89
|
-
* Helper function for creating a route config entry for an index route, for use
|
|
90
|
-
* within `routes.ts`.
|
|
91
|
-
*/
|
|
92
|
-
function index(file, options) {
|
|
93
|
-
return {
|
|
94
|
-
file,
|
|
95
|
-
index: true,
|
|
96
|
-
...pick(options, createIndexOptionKeys)
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
const createLayoutOptionKeys = ["id"];
|
|
100
|
-
function layout(file, optionsOrChildren, children) {
|
|
101
|
-
let options = {};
|
|
102
|
-
if (Array.isArray(optionsOrChildren) || !optionsOrChildren) children = optionsOrChildren;
|
|
103
|
-
else options = optionsOrChildren;
|
|
104
|
-
return {
|
|
105
|
-
file,
|
|
106
|
-
children,
|
|
107
|
-
...pick(options, createLayoutOptionKeys)
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* Helper function for adding a path prefix to a set of routes without needing
|
|
112
|
-
* to introduce a parent route file, for use within `routes.ts`.
|
|
113
|
-
*/
|
|
114
|
-
function prefix(prefixPath, routes) {
|
|
115
|
-
return routes.map((route) => {
|
|
116
|
-
if (route.index || typeof route.path === "string") return {
|
|
117
|
-
...route,
|
|
118
|
-
path: route.path ? joinRoutePaths(prefixPath, route.path) : prefixPath,
|
|
119
|
-
children: route.children
|
|
120
|
-
};
|
|
121
|
-
else if (route.children) return {
|
|
122
|
-
...route,
|
|
123
|
-
children: prefix(prefixPath, route.children)
|
|
124
|
-
};
|
|
125
|
-
return route;
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
/**
|
|
129
|
-
* Creates a set of route config helpers that resolve file paths relative to the
|
|
130
|
-
* given directory, for use within `routes.ts`. This is designed to support
|
|
131
|
-
* splitting route config into multiple files within different directories.
|
|
132
|
-
*/
|
|
133
|
-
function relative(directory) {
|
|
134
|
-
return {
|
|
135
|
-
/**
|
|
136
|
-
* Helper function for creating a route config entry, for use within
|
|
137
|
-
* `routes.ts`. Note that this helper has been scoped, meaning that file
|
|
138
|
-
* path will be resolved relative to the directory provided to the
|
|
139
|
-
* `relative` call that created this helper.
|
|
140
|
-
*/
|
|
141
|
-
route: (path, file, ...rest) => {
|
|
142
|
-
return route(path, Path.resolve(directory, file), ...rest);
|
|
143
|
-
},
|
|
144
|
-
/**
|
|
145
|
-
* Helper function for creating a route config entry for an index route, for
|
|
146
|
-
* use within `routes.ts`. Note that this helper has been scoped, meaning
|
|
147
|
-
* that file path will be resolved relative to the directory provided to the
|
|
148
|
-
* `relative` call that created this helper.
|
|
149
|
-
*/
|
|
150
|
-
index: (file, ...rest) => {
|
|
151
|
-
return index(Path.resolve(directory, file), ...rest);
|
|
152
|
-
},
|
|
153
|
-
/**
|
|
154
|
-
* Helper function for creating a route config entry for a layout route, for
|
|
155
|
-
* use within `routes.ts`. Note that this helper has been scoped, meaning
|
|
156
|
-
* that file path will be resolved relative to the directory provided to the
|
|
157
|
-
* `relative` call that created this helper.
|
|
158
|
-
*/
|
|
159
|
-
layout: (file, ...rest) => {
|
|
160
|
-
return layout(Path.resolve(directory, file), ...rest);
|
|
161
|
-
},
|
|
162
|
-
prefix
|
|
163
|
-
};
|
|
164
|
-
}
|
|
165
|
-
function configRoutesToRouteManifest(appDirectory, routes) {
|
|
166
|
-
let routeManifest = {};
|
|
167
|
-
function walk(route, parentId) {
|
|
168
|
-
let id = route.id || createRouteId(route.file);
|
|
169
|
-
let manifestItem = {
|
|
170
|
-
id,
|
|
171
|
-
parentId,
|
|
172
|
-
file: Path.isAbsolute(route.file) ? Path.relative(appDirectory, route.file) : route.file,
|
|
173
|
-
path: route.path,
|
|
174
|
-
index: route.index,
|
|
175
|
-
caseSensitive: route.caseSensitive
|
|
176
|
-
};
|
|
177
|
-
if (routeManifest.hasOwnProperty(id)) throw new Error(`Unable to define routes with duplicate route id: "${id}"`);
|
|
178
|
-
routeManifest[id] = manifestItem;
|
|
179
|
-
if (route.children) for (let child of route.children) walk(child, id);
|
|
180
|
-
}
|
|
181
|
-
for (let route of routes) walk(route);
|
|
182
|
-
return routeManifest;
|
|
183
|
-
}
|
|
184
|
-
function createRouteId(file) {
|
|
185
|
-
return Path.normalize(stripFileExtension(file));
|
|
186
|
-
}
|
|
187
|
-
function stripFileExtension(file) {
|
|
188
|
-
return file.replace(/\.[a-z0-9]+$/i, "");
|
|
189
|
-
}
|
|
190
|
-
function joinRoutePaths(path1, path2) {
|
|
191
|
-
return [path1.replace(/\/+$/, ""), path2.replace(/^\/+/, "")].join("/");
|
|
192
|
-
}
|
|
193
|
-
//#endregion
|
|
194
|
-
export { prefix as a, setAppDirectory as c, layout as i, validateRouteConfig as l, getAppDirectory as n, relative as o, index as r, route as s, configRoutesToRouteManifest as t, invariant as u };
|