next-vite-router 1.2.0 → 1.2.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/README.md +3 -2
- package/dist/cli.cjs +7 -3
- package/dist/index.d.ts +2 -0
- package/dist/index.js +108 -111
- package/dist/plugin.js +86 -49
- package/dist/tree-HwBRWJNI.js +64 -0
- package/package.json +1 -1
- package/dist/path-BodMUTCM.js +0 -14
package/README.md
CHANGED
|
@@ -238,12 +238,13 @@ replace React Router.
|
|
|
238
238
|
For an interactive setup:
|
|
239
239
|
|
|
240
240
|
```bash
|
|
241
|
-
npx
|
|
241
|
+
npx next-vite-router init
|
|
242
242
|
```
|
|
243
243
|
|
|
244
244
|
The CLI creates a Vite React project, installs the package and
|
|
245
245
|
`react-router-dom@^7.0.0`, configures the plugin, and adds an example route
|
|
246
|
-
tree.
|
|
246
|
+
tree. The CLI is published as part of `next-vite-router`; `create-next-vite-router`
|
|
247
|
+
is its executable name, not a separate npm package.
|
|
247
248
|
|
|
248
249
|
## Compatibility
|
|
249
250
|
|
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.2";
|
|
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,196 +1,193 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
|
|
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";
|
|
4
|
+
import { useParams as A } from "react-router-dom";
|
|
5
|
+
const M = {
|
|
5
6
|
enableLazyLoading: !0
|
|
6
7
|
};
|
|
7
|
-
let m = { ...
|
|
8
|
-
function
|
|
8
|
+
let m = { ...M };
|
|
9
|
+
function j(e) {
|
|
9
10
|
m = { ...m, ...e };
|
|
10
11
|
}
|
|
11
|
-
function
|
|
12
|
+
function k() {
|
|
12
13
|
return m;
|
|
13
14
|
}
|
|
14
15
|
let g = [];
|
|
15
|
-
function
|
|
16
|
+
function q(e, t) {
|
|
16
17
|
g.push({ pattern: e, middleware: t });
|
|
17
18
|
}
|
|
18
|
-
function
|
|
19
|
+
function B() {
|
|
19
20
|
g = [];
|
|
20
21
|
}
|
|
21
|
-
function
|
|
22
|
+
function h(e, t) {
|
|
22
23
|
let n = t;
|
|
23
24
|
for (const r of g)
|
|
24
|
-
r.pattern.test(e) && (n = r.middleware(n));
|
|
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
|
-
function
|
|
29
|
-
const r =
|
|
28
|
+
const S = () => c.createElement("div"), C = /* @__PURE__ */ new Map();
|
|
29
|
+
function R(e, t, n) {
|
|
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
40
|
let a = C.get(t);
|
|
40
|
-
a || (a =
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
{ fallback:
|
|
44
|
-
|
|
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
|
-
l.forEach((c, v) => {
|
|
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), v === l.length - 1 && (u[r] = n);
|
|
57
|
-
}), l.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(([o, l]) => {
|
|
66
|
-
h(a, o, l.default, "layout", r);
|
|
67
|
-
}), Object.entries(e).forEach(([o, l]) => {
|
|
68
|
-
h(a, o, l, "page", r);
|
|
69
|
-
}), Object.entries(n).forEach(([o, l]) => {
|
|
70
|
-
h(a, o, l, "notFound", r);
|
|
71
|
-
}), a;
|
|
72
|
-
}
|
|
73
|
-
const F = M(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));
|
|
65
|
+
}
|
|
66
|
+
function T(e) {
|
|
67
|
+
return /^\[\[\.\.\..+\]\]$/.test(e);
|
|
89
68
|
}
|
|
90
69
|
function f(e, t, n = !1) {
|
|
91
70
|
const r = e.page;
|
|
92
71
|
if (!r)
|
|
93
72
|
throw new Error(`Route node "${e.fullPath}" has no page loader`);
|
|
94
|
-
const a =
|
|
73
|
+
const a = R(
|
|
95
74
|
async () => ({ default: (await r()).default }),
|
|
96
75
|
`page:${e.fullPath || t}`,
|
|
97
76
|
t
|
|
98
|
-
),
|
|
99
|
-
name:
|
|
77
|
+
), l = e.segment.match(/^\[\[?\.\.\.(.+?)\]\]?$/), o = l ? c.createElement(D, {
|
|
78
|
+
name: l[1],
|
|
100
79
|
children: a
|
|
101
80
|
}) : a;
|
|
102
|
-
return n ? { index: !0, element:
|
|
81
|
+
return n ? { index: !0, element: o } : { path: p(e.segment), element: o };
|
|
103
82
|
}
|
|
104
|
-
function
|
|
83
|
+
function P(e) {
|
|
105
84
|
const t = e.notFound;
|
|
106
85
|
if (!t)
|
|
107
86
|
throw new Error(`Route node "${e.fullPath}" has no not-found loader`);
|
|
108
87
|
const n = e.fullPath ? `/${e.fullPath}` : "/";
|
|
109
88
|
return {
|
|
110
89
|
path: "*",
|
|
111
|
-
element:
|
|
90
|
+
element: R(
|
|
112
91
|
async () => ({ default: (await t()).default }),
|
|
113
92
|
`notfound:${e.fullPath}`,
|
|
114
93
|
n
|
|
115
94
|
)
|
|
116
95
|
};
|
|
117
96
|
}
|
|
118
|
-
function
|
|
97
|
+
function F(e, t) {
|
|
119
98
|
const n = [];
|
|
120
99
|
return [...e.children.entries()].sort(([r], [a]) => r.localeCompare(a)).forEach(([r, a]) => {
|
|
121
|
-
const
|
|
122
|
-
n.push(
|
|
100
|
+
const l = p(r), o = l ? t ? `${t}/${l}` : `/${l}` : t;
|
|
101
|
+
n.push(...$(a, !1, o));
|
|
123
102
|
}), n;
|
|
124
103
|
}
|
|
125
|
-
function
|
|
104
|
+
function E(e, t) {
|
|
126
105
|
const n = [];
|
|
127
|
-
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;
|
|
128
107
|
}
|
|
129
|
-
function
|
|
108
|
+
function $(e, t = !1, n = "") {
|
|
130
109
|
const r = [];
|
|
131
110
|
if (t) {
|
|
132
|
-
const
|
|
111
|
+
const u = E(e, "");
|
|
133
112
|
return e.layout ? (r.push({
|
|
134
113
|
path: "/",
|
|
135
|
-
element:
|
|
136
|
-
children:
|
|
137
|
-
}), r) : e.page ?
|
|
114
|
+
element: y("/", e.layout),
|
|
115
|
+
children: u
|
|
116
|
+
}), r) : e.page ? u.length > 1 ? [{
|
|
138
117
|
path: "/",
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
}), r) : e.notFound ? (r.push({
|
|
118
|
+
children: u
|
|
119
|
+
}] : [{
|
|
142
120
|
path: "/",
|
|
143
|
-
|
|
144
|
-
}
|
|
121
|
+
element: f(e, "/", !1).element
|
|
122
|
+
}] : e.notFound ? (r.push({
|
|
123
|
+
path: "/",
|
|
124
|
+
children: u
|
|
125
|
+
}), r) : u;
|
|
145
126
|
}
|
|
146
|
-
const a = p(e.segment),
|
|
127
|
+
const a = p(e.segment), l = !a, o = l ? n : n + "/" + a, s = F(e, o), i = e.notFound ? [P(e)] : [];
|
|
147
128
|
if (e.layout) {
|
|
148
|
-
const
|
|
129
|
+
const u = E(e, o);
|
|
149
130
|
return [{
|
|
150
|
-
...
|
|
151
|
-
element:
|
|
152
|
-
children:
|
|
131
|
+
...l ? {} : { path: a },
|
|
132
|
+
element: y(o, e.layout),
|
|
133
|
+
children: u.length > 0 ? u : void 0
|
|
153
134
|
}];
|
|
154
135
|
}
|
|
155
|
-
if (e.page && !
|
|
156
|
-
|
|
136
|
+
if (e.page && !l) {
|
|
137
|
+
if (T(e.segment)) {
|
|
138
|
+
const u = f(e, n, !0), x = {
|
|
139
|
+
path: a,
|
|
140
|
+
element: f(e, o).element,
|
|
141
|
+
children: [...s, ...i].length > 0 ? [...s, ...i] : void 0
|
|
142
|
+
};
|
|
143
|
+
return [u, x];
|
|
144
|
+
}
|
|
145
|
+
return s.length > 0 || i.length > 0 ? [{
|
|
157
146
|
path: a,
|
|
158
|
-
|
|
159
|
-
|
|
147
|
+
children: [
|
|
148
|
+
f(e, o, !0),
|
|
149
|
+
...s,
|
|
150
|
+
...i
|
|
151
|
+
]
|
|
152
|
+
}] : [{
|
|
153
|
+
path: a,
|
|
154
|
+
element: f(e, o).element
|
|
160
155
|
}];
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
...
|
|
165
|
-
...s
|
|
156
|
+
}
|
|
157
|
+
if (e.page || e.notFound || !l) {
|
|
158
|
+
const u = [
|
|
159
|
+
...e.page ? [f(e, o, !0)] : [],
|
|
160
|
+
...s,
|
|
161
|
+
...i
|
|
166
162
|
];
|
|
167
163
|
return [{
|
|
168
|
-
...
|
|
169
|
-
children:
|
|
164
|
+
...l ? {} : { path: a },
|
|
165
|
+
children: u.length > 0 ? u : void 0
|
|
170
166
|
}];
|
|
171
167
|
}
|
|
172
|
-
return
|
|
168
|
+
return s;
|
|
173
169
|
}
|
|
174
|
-
function
|
|
170
|
+
function H(e, t, n, r) {
|
|
175
171
|
return () => {
|
|
176
|
-
const a =
|
|
177
|
-
return
|
|
172
|
+
const a = z(e, t, n, r);
|
|
173
|
+
return $(a, !0);
|
|
178
174
|
};
|
|
179
175
|
}
|
|
180
|
-
function
|
|
181
|
-
const e =
|
|
176
|
+
function J() {
|
|
177
|
+
const e = A(), t = N();
|
|
182
178
|
return typeof t == "string" && e["*"] !== void 0 ? { ...e, [t]: e["*"] } : e;
|
|
183
179
|
}
|
|
184
180
|
export {
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
B as
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
181
|
+
D as CatchAllParamProvider,
|
|
182
|
+
V as assertNoDuplicateRoutes,
|
|
183
|
+
z as buildRouteTree,
|
|
184
|
+
B as clearMiddlewares,
|
|
185
|
+
j as configureRouter,
|
|
186
|
+
R as createLazyElement,
|
|
187
|
+
H as createRouteGenerator,
|
|
188
|
+
W as extractRoutePath,
|
|
192
189
|
p as normalizeSegment,
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
190
|
+
q as registerMiddleware,
|
|
191
|
+
$ as treeToRoutes,
|
|
192
|
+
J as useParams
|
|
196
193
|
};
|
package/dist/plugin.js
CHANGED
|
@@ -1,31 +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 v, n as b } from "./tree-HwBRWJNI.js";
|
|
4
|
+
function x(r) {
|
|
5
|
+
const e = r.split(l.sep).filter(Boolean).map(b).filter(Boolean);
|
|
6
6
|
return e.length > 0 ? `/${e.join("/")}` : "/";
|
|
7
7
|
}
|
|
8
|
-
function
|
|
9
|
-
const
|
|
10
|
-
function
|
|
11
|
-
for (const
|
|
12
|
-
const
|
|
13
|
-
|
|
8
|
+
function $(r, e) {
|
|
9
|
+
const n = /* @__PURE__ */ new Map();
|
|
10
|
+
function s(a) {
|
|
11
|
+
for (const t of h.readdirSync(a, { withFileTypes: !0 })) {
|
|
12
|
+
const c = l.join(a, t.name);
|
|
13
|
+
if (t.isDirectory())
|
|
14
|
+
s(c);
|
|
15
|
+
else if (t.isFile() && t.name === e) {
|
|
16
|
+
const i = l.relative(r, a), u = i.split(l.sep).filter(Boolean), y = u.map((p) => {
|
|
17
|
+
const m = p.match(/^\[\[\.\.\.(.+)\]\]$/);
|
|
18
|
+
if (m)
|
|
19
|
+
return { name: m[1], optional: !0 };
|
|
20
|
+
const d = p.match(/^\[\.\.\.(.+)\]$/);
|
|
21
|
+
return d ? { name: d[1], optional: !1 } : void 0;
|
|
22
|
+
}).filter((p) => !!p), f = x(i);
|
|
23
|
+
n.set(f, { path: f, params: y });
|
|
24
|
+
const o = u[u.length - 1];
|
|
25
|
+
if (o == null ? void 0 : o.match(/^\[\[\.\.\.(.+)\]\]$/)) {
|
|
26
|
+
const p = u.slice(0, -1).join(l.sep), m = x(p);
|
|
27
|
+
n.has(m) || n.set(m, { path: m, params: [] });
|
|
28
|
+
}
|
|
29
|
+
}
|
|
14
30
|
}
|
|
15
31
|
}
|
|
16
|
-
return
|
|
32
|
+
return h.existsSync(r) && s(r), [...n.values()].sort((a, t) => a.path.localeCompare(t.path));
|
|
17
33
|
}
|
|
18
|
-
function
|
|
19
|
-
const
|
|
34
|
+
function P(r, e) {
|
|
35
|
+
const n = [];
|
|
36
|
+
function s(a) {
|
|
37
|
+
for (const t of h.readdirSync(a, { withFileTypes: !0 })) {
|
|
38
|
+
const c = l.join(a, t.name);
|
|
39
|
+
t.isDirectory() ? s(c) : t.isFile() && t.name === e && n.push(l.relative(r, c));
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return h.existsSync(r) && s(r), n;
|
|
43
|
+
}
|
|
44
|
+
function F(r) {
|
|
45
|
+
const e = r.match(/^\/(?:\[\.\.\.|:)([^/\]]+)\]?$/);
|
|
20
46
|
return e == null ? void 0 : e[1];
|
|
21
47
|
}
|
|
22
|
-
function
|
|
23
|
-
const e =
|
|
24
|
-
`),
|
|
25
|
-
const
|
|
48
|
+
function j(r) {
|
|
49
|
+
const e = r.map(({ path: s }) => ` | "${s}"`).join(`
|
|
50
|
+
`), n = r.map(({ path: s, params: a }) => {
|
|
51
|
+
const t = s.split("/").map((i) => F(`/${i}`)).filter((i) => !!i), c = t.length > 0 || a.length > 0 ? [
|
|
52
|
+
...t.map((i) => ` ${i}: string;`),
|
|
53
|
+
...a.map(({ name: i, optional: u }) => ` ${i}${u ? "?" : ""}: string;`)
|
|
54
|
+
].join(`
|
|
26
55
|
`) : " [key: string]: never;";
|
|
27
|
-
return ` "${
|
|
28
|
-
${
|
|
56
|
+
return ` "${s}": {
|
|
57
|
+
${c}
|
|
29
58
|
};`;
|
|
30
59
|
}).join(`
|
|
31
60
|
`);
|
|
@@ -41,7 +70,7 @@ ${e || ' | "/"'};
|
|
|
41
70
|
: never;
|
|
42
71
|
|
|
43
72
|
export interface RoutePathParams {
|
|
44
|
-
${
|
|
73
|
+
${n}
|
|
45
74
|
}
|
|
46
75
|
|
|
47
76
|
export const generateRoutes: () => RouteObject[];
|
|
@@ -51,46 +80,54 @@ ${s}
|
|
|
51
80
|
}
|
|
52
81
|
`;
|
|
53
82
|
}
|
|
54
|
-
function
|
|
83
|
+
function S(r = {}) {
|
|
55
84
|
const {
|
|
56
85
|
pagesDir: e = "src/app",
|
|
57
|
-
pageFile:
|
|
58
|
-
layoutFile:
|
|
59
|
-
notFoundFile:
|
|
60
|
-
} =
|
|
61
|
-
let
|
|
62
|
-
function
|
|
63
|
-
const
|
|
64
|
-
|
|
86
|
+
pageFile: n = "page.tsx",
|
|
87
|
+
layoutFile: s = "layout.tsx",
|
|
88
|
+
notFoundFile: a = "not-found.tsx"
|
|
89
|
+
} = r, t = { pagesDir: e, pageFile: n, layoutFile: s, notFoundFile: a }, c = "virtual:next-vite-router", i = "\0" + c;
|
|
90
|
+
let u = "", y = "";
|
|
91
|
+
function f() {
|
|
92
|
+
const o = j($(u, n));
|
|
93
|
+
h.writeFileSync(y, o, "utf-8");
|
|
65
94
|
}
|
|
66
95
|
return {
|
|
67
96
|
name: "next-vite-router",
|
|
68
|
-
configResolved(
|
|
69
|
-
|
|
97
|
+
configResolved(o) {
|
|
98
|
+
u = l.resolve(o.root, e), y = l.join(l.dirname(u), "virtual-next-vite-router.d.ts"), v(P(u, n), t), f();
|
|
70
99
|
},
|
|
71
|
-
configureServer(
|
|
72
|
-
const
|
|
73
|
-
if (
|
|
100
|
+
configureServer(o) {
|
|
101
|
+
const g = (p) => {
|
|
102
|
+
if (l.relative(u, p).startsWith("..") || ![n, s, a].includes(l.basename(p)))
|
|
103
|
+
return;
|
|
104
|
+
try {
|
|
105
|
+
v(P(u, n), t);
|
|
106
|
+
} catch (R) {
|
|
107
|
+
o.config.logger.error(
|
|
108
|
+
R instanceof Error ? R.message : String(R)
|
|
109
|
+
);
|
|
74
110
|
return;
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
111
|
+
}
|
|
112
|
+
f();
|
|
113
|
+
const d = o.moduleGraph.getModuleById(i);
|
|
114
|
+
d && (o.moduleGraph.invalidateModule(d), o.ws.send({ type: "full-reload", path: "*" }));
|
|
78
115
|
};
|
|
79
|
-
|
|
116
|
+
o.watcher.on("add", g), o.watcher.on("unlink", g);
|
|
80
117
|
},
|
|
81
|
-
resolveId(
|
|
82
|
-
if (
|
|
83
|
-
return
|
|
118
|
+
resolveId(o) {
|
|
119
|
+
if (o === c)
|
|
120
|
+
return i;
|
|
84
121
|
},
|
|
85
|
-
load(
|
|
86
|
-
if (
|
|
122
|
+
load(o) {
|
|
123
|
+
if (o === i)
|
|
87
124
|
return `
|
|
88
125
|
import { buildRouteTree, treeToRoutes, normalizeSegment, createLazyElement, useParams } from 'next-vite-router';
|
|
89
126
|
import { Link, useRoutes } from 'react-router-dom';
|
|
90
127
|
|
|
91
|
-
const pagesGlob = import.meta.glob('/${e}/**/${
|
|
92
|
-
const layoutsGlob = import.meta.glob('/${e}/**/${
|
|
93
|
-
const notFoundsGlob = import.meta.glob('/${e}/**/${
|
|
128
|
+
const pagesGlob = import.meta.glob('/${e}/**/${n}');
|
|
129
|
+
const layoutsGlob = import.meta.glob('/${e}/**/${s}', { eager: true });
|
|
130
|
+
const notFoundsGlob = import.meta.glob('/${e}/**/${a}');
|
|
94
131
|
|
|
95
132
|
const transformPath = (path) => path.replace('/${e}/', '');
|
|
96
133
|
|
|
@@ -105,7 +142,7 @@ const notFounds = Object.fromEntries(
|
|
|
105
142
|
);
|
|
106
143
|
|
|
107
144
|
export function generateRoutes() {
|
|
108
|
-
const tree = buildRouteTree(pages, layouts, notFounds, ${JSON.stringify(
|
|
145
|
+
const tree = buildRouteTree(pages, layouts, notFounds, ${JSON.stringify(t)});
|
|
109
146
|
const routes = treeToRoutes(tree, true);
|
|
110
147
|
return routes;
|
|
111
148
|
}
|
|
@@ -124,5 +161,5 @@ export { useParams };
|
|
|
124
161
|
};
|
|
125
162
|
}
|
|
126
163
|
export {
|
|
127
|
-
|
|
164
|
+
S as nextViteRouter
|
|
128
165
|
};
|
|
@@ -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
|
-
};
|