next-vite-router 1.2.1 → 1.2.3
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/README.md +14 -22
- package/dist/cli.cjs +7 -3
- package/dist/index.d.ts +2 -0
- package/dist/index.js +97 -112
- package/dist/plugin.js +95 -60
- package/dist/tree-HwBRWJNI.js +64 -0
- package/package.json +1 -1
- package/dist/path-BodMUTCM.js +0 -14
package/README.md
CHANGED
|
@@ -6,33 +6,19 @@ Define routes with folders and let the package generate the
|
|
|
6
6
|
[React Router](https://reactrouter.com/) `RouteObject[]`. It does not replace
|
|
7
7
|
React Router, navigation, history, loaders, or application state.
|
|
8
8
|
|
|
9
|
-
## Release notes
|
|
10
|
-
|
|
11
|
-
### Plugin import
|
|
12
|
-
|
|
13
|
-
The Vite plugin is no longer exported from the main
|
|
14
|
-
`next-vite-router` entry point. Existing imports must be migrated:
|
|
15
|
-
|
|
16
|
-
```ts
|
|
17
|
-
// Previous import
|
|
18
|
-
import { nextViteRouter } from "next-vite-router";
|
|
19
|
-
|
|
20
|
-
// Current import
|
|
21
|
-
import { nextViteRouter } from "next-vite-router/plugin";
|
|
22
|
-
```
|
|
23
|
-
|
|
24
|
-
The plugin remains available through `next-vite-router/plugin`. This separation
|
|
25
|
-
prevents the plugin's Node dependencies from being included in the application's
|
|
26
|
-
browser dependency graph.
|
|
27
|
-
|
|
28
9
|
## Start here
|
|
29
10
|
|
|
30
11
|
```bash
|
|
31
12
|
npm create vite@latest my-app -- --template react-ts
|
|
32
13
|
cd my-app
|
|
33
|
-
npm install next-vite-router
|
|
14
|
+
npm install next-vite-router
|
|
34
15
|
```
|
|
35
16
|
|
|
17
|
+
`next-vite-router` declares `react-router-dom` as a peer dependency. Recent
|
|
18
|
+
versions of npm install this dependency automatically; if your package manager
|
|
19
|
+
does not resolve peer dependencies automatically, install
|
|
20
|
+
`react-router-dom` explicitly.
|
|
21
|
+
|
|
36
22
|
Add the plugin to `vite.config.ts`:
|
|
37
23
|
|
|
38
24
|
```ts
|
|
@@ -203,8 +189,14 @@ No manual declaration for the virtual module is required.
|
|
|
203
189
|
|
|
204
190
|
Pages and `not-found.tsx` files use Vite's non-eager `import.meta.glob`, so
|
|
205
191
|
Vite can emit separate chunks for pages. Layouts are eager because they wrap
|
|
206
|
-
the generated route tree
|
|
207
|
-
|
|
192
|
+
the generated route tree. Vite handles ordinary content changes to pages,
|
|
193
|
+
layouts, and `not-found.tsx` through its normal HMR mechanism. Creating,
|
|
194
|
+
deleting, or renaming a route-related file also refreshes the generated route
|
|
195
|
+
module and route declarations. Because Vite cannot reliably preserve a cached
|
|
196
|
+
route tree when an `import.meta.glob` entry is added or removed, these
|
|
197
|
+
structural changes trigger a full-page reload as a fallback. Lazy-loaded route
|
|
198
|
+
components remain lazy-loaded during normal navigation. Lazy loading is
|
|
199
|
+
enabled by default:
|
|
208
200
|
|
|
209
201
|
```tsx
|
|
210
202
|
import { configureRouter } from "next-vite-router";
|
package/dist/cli.cjs
CHANGED
|
@@ -408,6 +408,10 @@ function startViteConfig(projectDir, src) {
|
|
|
408
408
|
if (!viteConfigContent) throw new Error("Vite config empty");
|
|
409
409
|
if (!viteConfigContent.includes("import { resolve }")) {
|
|
410
410
|
viteConfigContent = `import { resolve } from "path";
|
|
411
|
+
` + viteConfigContent;
|
|
412
|
+
}
|
|
413
|
+
if (!viteConfigContent.includes("import { fileURLToPath }")) {
|
|
414
|
+
viteConfigContent = `import { fileURLToPath } from "node:url";
|
|
411
415
|
` + viteConfigContent;
|
|
412
416
|
}
|
|
413
417
|
if (!viteConfigContent.includes("import { nextViteRouter }")) {
|
|
@@ -416,7 +420,7 @@ function startViteConfig(projectDir, src) {
|
|
|
416
420
|
}
|
|
417
421
|
const resolveConfig = ` resolve: {
|
|
418
422
|
alias: {
|
|
419
|
-
"@": resolve(
|
|
423
|
+
"@": resolve(fileURLToPath(new URL("./${src ? "src" : "."}", import.meta.url))),
|
|
420
424
|
},
|
|
421
425
|
},`;
|
|
422
426
|
const defineConfigRegex = /defineConfig\(\s*{/;
|
|
@@ -430,7 +434,7 @@ ${resolveConfig}
|
|
|
430
434
|
}
|
|
431
435
|
const pluginsRegex = /plugins\s*:\s*\[(.*?)\]/s;
|
|
432
436
|
const match = viteConfigContent.match(pluginsRegex);
|
|
433
|
-
const pluginString =
|
|
437
|
+
const pluginString = "nextViteRouter()";
|
|
434
438
|
if (match) {
|
|
435
439
|
const existing = match[1].trim();
|
|
436
440
|
const newPlugins = existing ? `${existing}, ${pluginString}` : pluginString;
|
|
@@ -544,7 +548,7 @@ const init = new commander.Command().name("init").description(
|
|
|
544
548
|
Project "${projectName}" is ready!
|
|
545
549
|
`);
|
|
546
550
|
});
|
|
547
|
-
const version = "1.2.
|
|
551
|
+
const version = "1.2.3";
|
|
548
552
|
const pkg = {
|
|
549
553
|
version
|
|
550
554
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -3,6 +3,8 @@ import { default as default_2 } from 'react';
|
|
|
3
3
|
import { ReactElement } from 'react';
|
|
4
4
|
import { RouteObject } from 'react-router-dom';
|
|
5
5
|
|
|
6
|
+
export declare function assertNoDuplicateRoutes(filePaths: string[], fileOptions?: RouteFileOptions): void;
|
|
7
|
+
|
|
6
8
|
export declare function buildRouteTree(pages: Record<string, () => Promise<any>>, layouts: Record<string, any>, notFounds: Record<string, () => Promise<any>>, fileOptions?: RouteFileOptions): RouteNode;
|
|
7
9
|
|
|
8
10
|
export declare function CatchAllParamProvider({ name, children, }: {
|
package/dist/index.js
CHANGED
|
@@ -1,93 +1,69 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
1
|
+
import { n as p, b as z } from "./tree-HwBRWJNI.js";
|
|
2
|
+
import { a as V, e as W } from "./tree-HwBRWJNI.js";
|
|
3
|
+
import c, { Suspense as d, lazy as b, createContext as v, useContext as L } from "react";
|
|
3
4
|
import { useParams as A } from "react-router-dom";
|
|
4
|
-
const
|
|
5
|
+
const M = {
|
|
5
6
|
enableLazyLoading: !0
|
|
6
7
|
};
|
|
7
|
-
let
|
|
8
|
-
function
|
|
9
|
-
|
|
8
|
+
let m = { ...M };
|
|
9
|
+
function j(e) {
|
|
10
|
+
m = { ...m, ...e };
|
|
10
11
|
}
|
|
11
|
-
function
|
|
12
|
-
return
|
|
12
|
+
function k() {
|
|
13
|
+
return m;
|
|
13
14
|
}
|
|
14
|
-
let
|
|
15
|
-
function
|
|
16
|
-
|
|
15
|
+
let g = [];
|
|
16
|
+
function q(e, t) {
|
|
17
|
+
g.push({ pattern: e, middleware: t });
|
|
17
18
|
}
|
|
18
|
-
function
|
|
19
|
-
|
|
19
|
+
function B() {
|
|
20
|
+
g = [];
|
|
20
21
|
}
|
|
21
|
-
function
|
|
22
|
+
function h(e, t) {
|
|
22
23
|
let n = t;
|
|
23
|
-
for (const r of
|
|
24
|
+
for (const r of g)
|
|
24
25
|
r.pattern.lastIndex = 0, r.pattern.test(e) && (n = r.middleware(n)), r.pattern.lastIndex = 0;
|
|
25
26
|
return n;
|
|
26
27
|
}
|
|
27
|
-
const
|
|
28
|
+
const S = () => c.createElement("div"), C = /* @__PURE__ */ new Map();
|
|
28
29
|
function R(e, t, n) {
|
|
29
|
-
const r =
|
|
30
|
+
const r = k();
|
|
30
31
|
if (r.enableLazyLoading === !1) {
|
|
31
|
-
const
|
|
32
|
-
|
|
32
|
+
const s = c.lazy(e), i = c.createElement(
|
|
33
|
+
d,
|
|
33
34
|
{ fallback: null },
|
|
34
35
|
// No loading fallback when disabled
|
|
35
|
-
|
|
36
|
+
c.createElement(s)
|
|
36
37
|
);
|
|
37
|
-
return n ?
|
|
38
|
+
return n ? h(n, i) : i;
|
|
38
39
|
}
|
|
39
|
-
let a =
|
|
40
|
-
a || (a =
|
|
41
|
-
const l = r.loadingFallback ||
|
|
42
|
-
|
|
43
|
-
{ fallback:
|
|
44
|
-
|
|
40
|
+
let a = C.get(t);
|
|
41
|
+
a || (a = b(e), C.set(t, a));
|
|
42
|
+
const l = r.loadingFallback || S, o = c.createElement(
|
|
43
|
+
d,
|
|
44
|
+
{ fallback: c.createElement(l) },
|
|
45
|
+
c.createElement(a)
|
|
45
46
|
);
|
|
46
|
-
return n ?
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
let u = e, s = "";
|
|
51
|
-
o.forEach((c, h) => {
|
|
52
|
-
s = s ? `${s}/${c}` : c, u.children.has(c) || u.children.set(c, {
|
|
53
|
-
segment: c,
|
|
54
|
-
fullPath: s,
|
|
55
|
-
children: /* @__PURE__ */ new Map()
|
|
56
|
-
}), u = u.children.get(c), h === o.length - 1 && (u[r] = n);
|
|
57
|
-
}), o.length === 0 && (e[r] = n);
|
|
58
|
-
}
|
|
59
|
-
function j(e, t, n, r) {
|
|
60
|
-
const a = {
|
|
61
|
-
segment: "",
|
|
62
|
-
fullPath: "",
|
|
63
|
-
children: /* @__PURE__ */ new Map()
|
|
64
|
-
};
|
|
65
|
-
return Object.entries(t).forEach(([l, o]) => {
|
|
66
|
-
m(a, l, o.default, "layout", r);
|
|
67
|
-
}), Object.entries(e).forEach(([l, o]) => {
|
|
68
|
-
m(a, l, o, "page", r);
|
|
69
|
-
}), Object.entries(n).forEach(([l, o]) => {
|
|
70
|
-
m(a, l, o, "notFound", r);
|
|
71
|
-
}), a;
|
|
72
|
-
}
|
|
73
|
-
const F = L(void 0);
|
|
74
|
-
function N({
|
|
47
|
+
return n ? h(n, o) : o;
|
|
48
|
+
}
|
|
49
|
+
const w = v(void 0);
|
|
50
|
+
function D({
|
|
75
51
|
name: e,
|
|
76
52
|
children: t
|
|
77
53
|
}) {
|
|
78
|
-
return
|
|
79
|
-
|
|
54
|
+
return c.createElement(
|
|
55
|
+
w.Provider,
|
|
80
56
|
{ value: e },
|
|
81
57
|
t
|
|
82
58
|
);
|
|
83
59
|
}
|
|
84
|
-
function
|
|
85
|
-
return
|
|
60
|
+
function N() {
|
|
61
|
+
return L(w);
|
|
86
62
|
}
|
|
87
|
-
function
|
|
88
|
-
return
|
|
63
|
+
function y(e, t) {
|
|
64
|
+
return h(e, c.createElement(t));
|
|
89
65
|
}
|
|
90
|
-
function
|
|
66
|
+
function T(e) {
|
|
91
67
|
return /^\[\[\.\.\..+\]\]$/.test(e);
|
|
92
68
|
}
|
|
93
69
|
function f(e, t, n = !1) {
|
|
@@ -98,13 +74,13 @@ function f(e, t, n = !1) {
|
|
|
98
74
|
async () => ({ default: (await r()).default }),
|
|
99
75
|
`page:${e.fullPath || t}`,
|
|
100
76
|
t
|
|
101
|
-
), l = e.segment.match(/^\[\[?\.\.\.(.+?)\]\]?$/), o = l ?
|
|
77
|
+
), l = e.segment.match(/^\[\[?\.\.\.(.+?)\]\]?$/), o = l ? c.createElement(D, {
|
|
102
78
|
name: l[1],
|
|
103
79
|
children: a
|
|
104
80
|
}) : a;
|
|
105
|
-
return n ? { index: !0, element: o } : { path:
|
|
81
|
+
return n ? { index: !0, element: o } : { path: p(e.segment), element: o };
|
|
106
82
|
}
|
|
107
|
-
function
|
|
83
|
+
function P(e) {
|
|
108
84
|
const t = e.notFound;
|
|
109
85
|
if (!t)
|
|
110
86
|
throw new Error(`Route node "${e.fullPath}" has no not-found loader`);
|
|
@@ -118,91 +94,100 @@ function $(e) {
|
|
|
118
94
|
)
|
|
119
95
|
};
|
|
120
96
|
}
|
|
121
|
-
function
|
|
97
|
+
function F(e, t) {
|
|
122
98
|
const n = [];
|
|
123
99
|
return [...e.children.entries()].sort(([r], [a]) => r.localeCompare(a)).forEach(([r, a]) => {
|
|
124
|
-
const l =
|
|
125
|
-
n.push(
|
|
100
|
+
const l = p(r), o = l ? t ? `${t}/${l}` : `/${l}` : t;
|
|
101
|
+
n.push(...$(a, !1, o));
|
|
126
102
|
}), n;
|
|
127
103
|
}
|
|
128
|
-
function
|
|
104
|
+
function E(e, t) {
|
|
129
105
|
const n = [];
|
|
130
|
-
return e.page && n.push(f(e, t || "/", !0)), n.push(...
|
|
106
|
+
return e.page && n.push(f(e, t || "/", !0)), n.push(...F(e, t)), e.notFound && n.push(P(e)), n;
|
|
131
107
|
}
|
|
132
|
-
function
|
|
108
|
+
function $(e, t = !1, n = "") {
|
|
133
109
|
const r = [];
|
|
134
110
|
if (t) {
|
|
135
|
-
const
|
|
111
|
+
const u = E(e, "");
|
|
136
112
|
return e.layout ? (r.push({
|
|
137
113
|
path: "/",
|
|
138
|
-
element:
|
|
139
|
-
children:
|
|
140
|
-
}), r) : e.page ?
|
|
114
|
+
element: y("/", e.layout),
|
|
115
|
+
children: u
|
|
116
|
+
}), r) : e.page ? u.length > 1 ? [{
|
|
117
|
+
path: "/",
|
|
118
|
+
children: u
|
|
119
|
+
}] : [{
|
|
141
120
|
path: "/",
|
|
142
|
-
element: f(e, "/", !1).element
|
|
143
|
-
|
|
144
|
-
}), r) : e.notFound ? (r.push({
|
|
121
|
+
element: f(e, "/", !1).element
|
|
122
|
+
}] : e.notFound ? (r.push({
|
|
145
123
|
path: "/",
|
|
146
|
-
children:
|
|
147
|
-
}), r) :
|
|
124
|
+
children: u
|
|
125
|
+
}), r) : u;
|
|
148
126
|
}
|
|
149
|
-
const a =
|
|
127
|
+
const a = p(e.segment), l = !a, o = l ? n : n + "/" + a, s = F(e, o), i = e.notFound ? [P(e)] : [];
|
|
150
128
|
if (e.layout) {
|
|
151
|
-
const
|
|
129
|
+
const u = E(e, o);
|
|
152
130
|
return [{
|
|
153
131
|
...l ? {} : { path: a },
|
|
154
|
-
element:
|
|
155
|
-
children:
|
|
132
|
+
element: y(o, e.layout),
|
|
133
|
+
children: u.length > 0 ? u : void 0
|
|
156
134
|
}];
|
|
157
135
|
}
|
|
158
136
|
if (e.page && !l) {
|
|
159
|
-
if (
|
|
160
|
-
const
|
|
137
|
+
if (T(e.segment)) {
|
|
138
|
+
const u = f(e, n, !0), x = {
|
|
161
139
|
path: a,
|
|
162
140
|
element: f(e, o).element,
|
|
163
|
-
children: [...
|
|
141
|
+
children: [...s, ...i].length > 0 ? [...s, ...i] : void 0
|
|
164
142
|
};
|
|
165
|
-
return [
|
|
143
|
+
return [u, x];
|
|
166
144
|
}
|
|
167
|
-
return [{
|
|
145
|
+
return s.length > 0 || i.length > 0 ? [{
|
|
146
|
+
path: a,
|
|
147
|
+
children: [
|
|
148
|
+
f(e, o, !0),
|
|
149
|
+
...s,
|
|
150
|
+
...i
|
|
151
|
+
]
|
|
152
|
+
}] : [{
|
|
168
153
|
path: a,
|
|
169
|
-
element: f(e, o).element
|
|
170
|
-
children: [...u, ...s].length > 0 ? [...u, ...s] : void 0
|
|
154
|
+
element: f(e, o).element
|
|
171
155
|
}];
|
|
172
156
|
}
|
|
173
157
|
if (e.page || e.notFound || !l) {
|
|
174
|
-
const
|
|
158
|
+
const u = [
|
|
175
159
|
...e.page ? [f(e, o, !0)] : [],
|
|
176
|
-
...
|
|
177
|
-
...
|
|
160
|
+
...s,
|
|
161
|
+
...i
|
|
178
162
|
];
|
|
179
163
|
return [{
|
|
180
164
|
...l ? {} : { path: a },
|
|
181
|
-
children:
|
|
165
|
+
children: u.length > 0 ? u : void 0
|
|
182
166
|
}];
|
|
183
167
|
}
|
|
184
|
-
return
|
|
168
|
+
return s;
|
|
185
169
|
}
|
|
186
|
-
function
|
|
170
|
+
function H(e, t, n, r) {
|
|
187
171
|
return () => {
|
|
188
|
-
const a =
|
|
189
|
-
return
|
|
172
|
+
const a = z(e, t, n, r);
|
|
173
|
+
return $(a, !0);
|
|
190
174
|
};
|
|
191
175
|
}
|
|
192
|
-
function
|
|
193
|
-
const e = A(), t =
|
|
176
|
+
function J() {
|
|
177
|
+
const e = A(), t = N();
|
|
194
178
|
return typeof t == "string" && e["*"] !== void 0 ? { ...e, [t]: e["*"] } : e;
|
|
195
179
|
}
|
|
196
180
|
export {
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
B as
|
|
181
|
+
D as CatchAllParamProvider,
|
|
182
|
+
V as assertNoDuplicateRoutes,
|
|
183
|
+
z as buildRouteTree,
|
|
184
|
+
B as clearMiddlewares,
|
|
185
|
+
j as configureRouter,
|
|
201
186
|
R as createLazyElement,
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
187
|
+
H as createRouteGenerator,
|
|
188
|
+
W as extractRoutePath,
|
|
189
|
+
p as normalizeSegment,
|
|
190
|
+
q as registerMiddleware,
|
|
191
|
+
$ as treeToRoutes,
|
|
192
|
+
J as useParams
|
|
208
193
|
};
|
package/dist/plugin.js
CHANGED
|
@@ -1,48 +1,60 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import { n as
|
|
4
|
-
function
|
|
5
|
-
const e =
|
|
1
|
+
import h from "node:fs";
|
|
2
|
+
import l from "node:path";
|
|
3
|
+
import { a as b, n as j } from "./tree-HwBRWJNI.js";
|
|
4
|
+
function $(n) {
|
|
5
|
+
const e = n.split(l.sep).filter(Boolean).map(j).filter(Boolean);
|
|
6
6
|
return e.length > 0 ? `/${e.join("/")}` : "/";
|
|
7
7
|
}
|
|
8
|
-
function
|
|
9
|
-
const
|
|
10
|
-
function a
|
|
11
|
-
for (const
|
|
12
|
-
const
|
|
13
|
-
if (
|
|
14
|
-
|
|
15
|
-
else if (
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
if (
|
|
19
|
-
return { name:
|
|
20
|
-
const
|
|
21
|
-
return
|
|
22
|
-
}).filter((
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
8
|
+
function T(n, e) {
|
|
9
|
+
const r = /* @__PURE__ */ new Map();
|
|
10
|
+
function i(a) {
|
|
11
|
+
for (const o of h.readdirSync(a, { withFileTypes: !0 })) {
|
|
12
|
+
const p = l.join(a, o.name);
|
|
13
|
+
if (o.isDirectory())
|
|
14
|
+
i(p);
|
|
15
|
+
else if (o.isFile() && o.name === e) {
|
|
16
|
+
const s = l.relative(n, a), u = s.split(l.sep).filter(Boolean), y = u.map((t) => {
|
|
17
|
+
const c = t.match(/^\[\[\.\.\.(.+)\]\]$/);
|
|
18
|
+
if (c)
|
|
19
|
+
return { name: c[1], optional: !0 };
|
|
20
|
+
const m = t.match(/^\[\.\.\.(.+)\]$/);
|
|
21
|
+
return m ? { name: m[1], optional: !1 } : void 0;
|
|
22
|
+
}).filter((t) => !!t), d = $(s);
|
|
23
|
+
r.set(d, { path: d, params: y });
|
|
24
|
+
const f = u[u.length - 1];
|
|
25
|
+
if (f == null ? void 0 : f.match(/^\[\[\.\.\.(.+)\]\]$/)) {
|
|
26
|
+
const t = u.slice(0, -1).join(l.sep), c = $(t);
|
|
27
|
+
r.has(c) || r.set(c, { path: c, params: [] });
|
|
28
|
+
}
|
|
27
29
|
}
|
|
28
30
|
}
|
|
29
31
|
}
|
|
30
|
-
return
|
|
32
|
+
return h.existsSync(n) && i(n), [...r.values()].sort((a, o) => a.path.localeCompare(o.path));
|
|
31
33
|
}
|
|
32
|
-
function
|
|
33
|
-
const
|
|
34
|
+
function F(n, e) {
|
|
35
|
+
const r = [];
|
|
36
|
+
function i(a) {
|
|
37
|
+
for (const o of h.readdirSync(a, { withFileTypes: !0 })) {
|
|
38
|
+
const p = l.join(a, o.name);
|
|
39
|
+
o.isDirectory() ? i(p) : o.isFile() && o.name === e && r.push(l.relative(n, p));
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return h.existsSync(n) && i(n), r;
|
|
43
|
+
}
|
|
44
|
+
function k(n) {
|
|
45
|
+
const e = n.match(/^\/(?:\[\.\.\.|:)([^/\]]+)\]?$/);
|
|
34
46
|
return e == null ? void 0 : e[1];
|
|
35
47
|
}
|
|
36
|
-
function
|
|
37
|
-
const e =
|
|
38
|
-
`),
|
|
39
|
-
const
|
|
40
|
-
...
|
|
41
|
-
...
|
|
48
|
+
function w(n) {
|
|
49
|
+
const e = n.map(({ path: i }) => ` | "${i}"`).join(`
|
|
50
|
+
`), r = n.map(({ path: i, params: a }) => {
|
|
51
|
+
const o = i.split("/").map((s) => k(`/${s}`)).filter((s) => !!s), p = o.length > 0 || a.length > 0 ? [
|
|
52
|
+
...o.map((s) => ` ${s}: string;`),
|
|
53
|
+
...a.map(({ name: s, optional: u }) => ` ${s}${u ? "?" : ""}: string;`)
|
|
42
54
|
].join(`
|
|
43
55
|
`) : " [key: string]: never;";
|
|
44
|
-
return ` "${
|
|
45
|
-
${
|
|
56
|
+
return ` "${i}": {
|
|
57
|
+
${p}
|
|
46
58
|
};`;
|
|
47
59
|
}).join(`
|
|
48
60
|
`);
|
|
@@ -58,7 +70,7 @@ ${e || ' | "/"'};
|
|
|
58
70
|
: never;
|
|
59
71
|
|
|
60
72
|
export interface RoutePathParams {
|
|
61
|
-
${
|
|
73
|
+
${r}
|
|
62
74
|
}
|
|
63
75
|
|
|
64
76
|
export const generateRoutes: () => RouteObject[];
|
|
@@ -68,46 +80,63 @@ ${i}
|
|
|
68
80
|
}
|
|
69
81
|
`;
|
|
70
82
|
}
|
|
71
|
-
function
|
|
83
|
+
function D(n = {}) {
|
|
72
84
|
const {
|
|
73
85
|
pagesDir: e = "src/app",
|
|
74
|
-
pageFile:
|
|
75
|
-
layoutFile:
|
|
76
|
-
notFoundFile:
|
|
77
|
-
} =
|
|
78
|
-
let
|
|
79
|
-
function
|
|
80
|
-
const t =
|
|
81
|
-
|
|
86
|
+
pageFile: r = "page.tsx",
|
|
87
|
+
layoutFile: i = "layout.tsx",
|
|
88
|
+
notFoundFile: a = "not-found.tsx"
|
|
89
|
+
} = n, o = { pagesDir: e, pageFile: r, layoutFile: i, notFoundFile: a }, p = "virtual:next-vite-router", s = "\0" + p;
|
|
90
|
+
let u = "", y = "", d, f;
|
|
91
|
+
function g() {
|
|
92
|
+
const t = w(T(u, r));
|
|
93
|
+
h.writeFileSync(y, t, "utf-8");
|
|
82
94
|
}
|
|
83
95
|
return {
|
|
84
96
|
name: "next-vite-router",
|
|
85
97
|
configResolved(t) {
|
|
86
|
-
|
|
98
|
+
u = l.resolve(t.root, e), y = l.join(l.dirname(u), "virtual-next-vite-router.d.ts"), b(F(u, r), o), g();
|
|
87
99
|
},
|
|
88
100
|
configureServer(t) {
|
|
89
|
-
|
|
90
|
-
|
|
101
|
+
if (d === t)
|
|
102
|
+
return;
|
|
103
|
+
f == null || f(), d = t;
|
|
104
|
+
const c = (P) => {
|
|
105
|
+
if (l.relative(u, P).startsWith("..") || ![r, i, a].includes(l.basename(P)))
|
|
106
|
+
return;
|
|
107
|
+
try {
|
|
108
|
+
b(F(u, r), o);
|
|
109
|
+
} catch (x) {
|
|
110
|
+
t.config.logger.error(
|
|
111
|
+
x instanceof Error ? x.message : String(x)
|
|
112
|
+
);
|
|
91
113
|
return;
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
114
|
+
}
|
|
115
|
+
g();
|
|
116
|
+
const v = t.moduleGraph.getModuleById(s);
|
|
117
|
+
v && (t.moduleGraph.invalidateModule(v), m && clearTimeout(m), m = setTimeout(() => {
|
|
118
|
+
m = void 0, t.ws.send({ type: "full-reload", path: "*" });
|
|
119
|
+
}, 0));
|
|
95
120
|
};
|
|
96
|
-
|
|
121
|
+
let m;
|
|
122
|
+
const R = () => {
|
|
123
|
+
m && (clearTimeout(m), m = void 0), t.watcher.off("add", c), t.watcher.off("unlink", c), t.watcher.off("close", R), d === t && (d = void 0, f = void 0);
|
|
124
|
+
};
|
|
125
|
+
t.watcher.on("add", c), t.watcher.on("unlink", c), t.watcher.once("close", R), f = R;
|
|
97
126
|
},
|
|
98
127
|
resolveId(t) {
|
|
99
|
-
if (t ===
|
|
100
|
-
return
|
|
128
|
+
if (t === p)
|
|
129
|
+
return s;
|
|
101
130
|
},
|
|
102
131
|
load(t) {
|
|
103
|
-
if (t ===
|
|
132
|
+
if (t === s)
|
|
104
133
|
return `
|
|
105
134
|
import { buildRouteTree, treeToRoutes, normalizeSegment, createLazyElement, useParams } from 'next-vite-router';
|
|
106
135
|
import { Link, useRoutes } from 'react-router-dom';
|
|
107
136
|
|
|
108
|
-
const pagesGlob = import.meta.glob('/${e}/**/${
|
|
109
|
-
const layoutsGlob = import.meta.glob('/${e}/**/${
|
|
110
|
-
const notFoundsGlob = import.meta.glob('/${e}/**/${
|
|
137
|
+
const pagesGlob = import.meta.glob('/${e}/**/${r}');
|
|
138
|
+
const layoutsGlob = import.meta.glob('/${e}/**/${i}', { eager: true });
|
|
139
|
+
const notFoundsGlob = import.meta.glob('/${e}/**/${a}');
|
|
111
140
|
|
|
112
141
|
const transformPath = (path) => path.replace('/${e}/', '');
|
|
113
142
|
|
|
@@ -122,7 +151,7 @@ const notFounds = Object.fromEntries(
|
|
|
122
151
|
);
|
|
123
152
|
|
|
124
153
|
export function generateRoutes() {
|
|
125
|
-
const tree = buildRouteTree(pages, layouts, notFounds, ${JSON.stringify(
|
|
154
|
+
const tree = buildRouteTree(pages, layouts, notFounds, ${JSON.stringify(o)});
|
|
126
155
|
const routes = treeToRoutes(tree, true);
|
|
127
156
|
return routes;
|
|
128
157
|
}
|
|
@@ -134,6 +163,12 @@ export function Router() {
|
|
|
134
163
|
|
|
135
164
|
let routes;
|
|
136
165
|
|
|
166
|
+
if (import.meta.hot) {
|
|
167
|
+
import.meta.hot.accept(() => {
|
|
168
|
+
routes = undefined;
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
|
|
137
172
|
export { Link, useRoutes };
|
|
138
173
|
export { useParams };
|
|
139
174
|
`;
|
|
@@ -141,5 +176,5 @@ export { useParams };
|
|
|
141
176
|
};
|
|
142
177
|
}
|
|
143
178
|
export {
|
|
144
|
-
|
|
179
|
+
D as nextViteRouter
|
|
145
180
|
};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
function p(t) {
|
|
2
|
+
return /^\([^)]+\)$/.test(t) ? "" : /^\[\[\.\.\.(.+)\]\]$/.test(t) || /^\[\.\.\.(.+)\]$/.test(t) ? "*" : /^\[([^\]]+)\]$/.test(t) ? t.replace(/^\[([^\]]+)\]$/, ":$1") : t;
|
|
3
|
+
}
|
|
4
|
+
function h(t, { pagesDir: c, pageFile: a = "page.tsx", layoutFile: o = "layout.tsx", notFoundFile: r = "not-found.tsx" } = {}) {
|
|
5
|
+
const n = t.replace(/\\/g, "/"), e = c == null ? void 0 : c.replace(/\\/g, "/").replace(/^\/|\/$/g, ""), l = [a, o, r].map((u) => u.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("|");
|
|
6
|
+
return n.replace(
|
|
7
|
+
e ? new RegExp(`^.*(?:^|/)${e}/`) : /^.*(?:^|\/)(?:app|pages)\//,
|
|
8
|
+
""
|
|
9
|
+
).replace(/\\/g, "/").replace(new RegExp(`/?(?:${l})$`), "");
|
|
10
|
+
}
|
|
11
|
+
function $(t, c) {
|
|
12
|
+
const a = h(t, c), o = a ? a.split("/").map(p).filter(Boolean) : [];
|
|
13
|
+
return o.length > 0 ? `/${o.join("/")}` : "/";
|
|
14
|
+
}
|
|
15
|
+
function d(t, c) {
|
|
16
|
+
const a = /* @__PURE__ */ new Map();
|
|
17
|
+
for (const r of t) {
|
|
18
|
+
const n = $(r, c), e = a.get(n) ?? [];
|
|
19
|
+
e.push(r), a.set(n, e);
|
|
20
|
+
}
|
|
21
|
+
const o = [...a.entries()].filter(([, r]) => r.length > 1).sort(([r], [n]) => r.localeCompare(n));
|
|
22
|
+
if (o.length > 0)
|
|
23
|
+
throw new Error(
|
|
24
|
+
o.map(
|
|
25
|
+
([r, n]) => `Duplicate route "${r}" detected:
|
|
26
|
+
${n.sort((e, l) => e.localeCompare(l)).map((e) => ` ${e}`).join(`
|
|
27
|
+
`)}`
|
|
28
|
+
).join(`
|
|
29
|
+
|
|
30
|
+
`)
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
function i(t, c, a, o, r) {
|
|
34
|
+
const n = h(c, r), e = n ? n.split("/") : [];
|
|
35
|
+
let l = t, u = "";
|
|
36
|
+
e.forEach((s, f) => {
|
|
37
|
+
u = u ? `${u}/${s}` : s, l.children.has(s) || l.children.set(s, {
|
|
38
|
+
segment: s,
|
|
39
|
+
fullPath: u,
|
|
40
|
+
children: /* @__PURE__ */ new Map()
|
|
41
|
+
}), l = l.children.get(s), f === e.length - 1 && (l[o] = a);
|
|
42
|
+
}), e.length === 0 && (t[o] = a);
|
|
43
|
+
}
|
|
44
|
+
function P(t, c, a, o) {
|
|
45
|
+
d(Object.keys(t), o);
|
|
46
|
+
const r = {
|
|
47
|
+
segment: "",
|
|
48
|
+
fullPath: "",
|
|
49
|
+
children: /* @__PURE__ */ new Map()
|
|
50
|
+
};
|
|
51
|
+
return Object.entries(c).forEach(([n, e]) => {
|
|
52
|
+
i(r, n, e.default, "layout", o);
|
|
53
|
+
}), Object.entries(t).forEach(([n, e]) => {
|
|
54
|
+
i(r, n, e, "page", o);
|
|
55
|
+
}), Object.entries(a).forEach(([n, e]) => {
|
|
56
|
+
i(r, n, e, "notFound", o);
|
|
57
|
+
}), r;
|
|
58
|
+
}
|
|
59
|
+
export {
|
|
60
|
+
d as a,
|
|
61
|
+
P as b,
|
|
62
|
+
h as e,
|
|
63
|
+
p as n
|
|
64
|
+
};
|
package/package.json
CHANGED
package/dist/path-BodMUTCM.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
function $(e) {
|
|
2
|
-
return /^\([^)]+\)$/.test(e) ? "" : /^\[\[\.\.\.(.+)\]\]$/.test(e) || /^\[\.\.\.(.+)\]$/.test(e) ? "*" : /^\[([^\]]+)\]$/.test(e) ? e.replace(/^\[([^\]]+)\]$/, ":$1") : e;
|
|
3
|
-
}
|
|
4
|
-
function u(e, { pagesDir: t, pageFile: a = "page.tsx", layoutFile: n = "layout.tsx", notFoundFile: c = "not-found.tsx" } = {}) {
|
|
5
|
-
const o = e.replace(/\\/g, "/"), r = t == null ? void 0 : t.replace(/\\/g, "/").replace(/^\/|\/$/g, ""), l = [a, n, c].map((p) => p.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("|");
|
|
6
|
-
return o.replace(
|
|
7
|
-
r ? new RegExp(`^.*(?:^|/)${r}/`) : /^.*(?:^|\/)(?:app|pages)\//,
|
|
8
|
-
""
|
|
9
|
-
).replace(/\\/g, "/").replace(new RegExp(`/?(?:${l})$`), "");
|
|
10
|
-
}
|
|
11
|
-
export {
|
|
12
|
-
u as e,
|
|
13
|
-
$ as n
|
|
14
|
-
};
|