next-vite-router 1.2.1 → 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/dist/cli.cjs +7 -3
- package/dist/index.d.ts +2 -0
- package/dist/index.js +97 -112
- package/dist/plugin.js +83 -63
- package/dist/tree-HwBRWJNI.js +64 -0
- package/package.json +1 -1
- package/dist/path-BodMUTCM.js +0 -14
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,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 = r.split(
|
|
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 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 $(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
|
+
}
|
|
27
29
|
}
|
|
28
30
|
}
|
|
29
31
|
}
|
|
30
|
-
return
|
|
32
|
+
return h.existsSync(r) && s(r), [...n.values()].sort((a, t) => a.path.localeCompare(t.path));
|
|
31
33
|
}
|
|
32
|
-
function
|
|
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) {
|
|
33
45
|
const e = r.match(/^\/(?:\[\.\.\.|:)([^/\]]+)\]?$/);
|
|
34
46
|
return e == null ? void 0 : e[1];
|
|
35
47
|
}
|
|
36
|
-
function
|
|
37
|
-
const e = r.map(({ path:
|
|
38
|
-
`),
|
|
39
|
-
const
|
|
40
|
-
...
|
|
41
|
-
...
|
|
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;`)
|
|
42
54
|
].join(`
|
|
43
55
|
`) : " [key: string]: never;";
|
|
44
|
-
return ` "${
|
|
45
|
-
${
|
|
56
|
+
return ` "${s}": {
|
|
57
|
+
${c}
|
|
46
58
|
};`;
|
|
47
59
|
}).join(`
|
|
48
60
|
`);
|
|
@@ -58,7 +70,7 @@ ${e || ' | "/"'};
|
|
|
58
70
|
: never;
|
|
59
71
|
|
|
60
72
|
export interface RoutePathParams {
|
|
61
|
-
${
|
|
73
|
+
${n}
|
|
62
74
|
}
|
|
63
75
|
|
|
64
76
|
export const generateRoutes: () => RouteObject[];
|
|
@@ -68,46 +80,54 @@ ${i}
|
|
|
68
80
|
}
|
|
69
81
|
`;
|
|
70
82
|
}
|
|
71
|
-
function
|
|
83
|
+
function S(r = {}) {
|
|
72
84
|
const {
|
|
73
85
|
pagesDir: e = "src/app",
|
|
74
|
-
pageFile:
|
|
75
|
-
layoutFile:
|
|
76
|
-
notFoundFile:
|
|
77
|
-
} = r,
|
|
78
|
-
let
|
|
79
|
-
function
|
|
80
|
-
const
|
|
81
|
-
|
|
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");
|
|
82
94
|
}
|
|
83
95
|
return {
|
|
84
96
|
name: "next-vite-router",
|
|
85
|
-
configResolved(
|
|
86
|
-
|
|
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();
|
|
87
99
|
},
|
|
88
|
-
configureServer(
|
|
89
|
-
const
|
|
90
|
-
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
|
+
);
|
|
91
110
|
return;
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
111
|
+
}
|
|
112
|
+
f();
|
|
113
|
+
const d = o.moduleGraph.getModuleById(i);
|
|
114
|
+
d && (o.moduleGraph.invalidateModule(d), o.ws.send({ type: "full-reload", path: "*" }));
|
|
95
115
|
};
|
|
96
|
-
|
|
116
|
+
o.watcher.on("add", g), o.watcher.on("unlink", g);
|
|
97
117
|
},
|
|
98
|
-
resolveId(
|
|
99
|
-
if (
|
|
100
|
-
return
|
|
118
|
+
resolveId(o) {
|
|
119
|
+
if (o === c)
|
|
120
|
+
return i;
|
|
101
121
|
},
|
|
102
|
-
load(
|
|
103
|
-
if (
|
|
122
|
+
load(o) {
|
|
123
|
+
if (o === i)
|
|
104
124
|
return `
|
|
105
125
|
import { buildRouteTree, treeToRoutes, normalizeSegment, createLazyElement, useParams } from 'next-vite-router';
|
|
106
126
|
import { Link, useRoutes } from 'react-router-dom';
|
|
107
127
|
|
|
108
|
-
const pagesGlob = import.meta.glob('/${e}/**/${
|
|
109
|
-
const layoutsGlob = import.meta.glob('/${e}/**/${
|
|
110
|
-
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}');
|
|
111
131
|
|
|
112
132
|
const transformPath = (path) => path.replace('/${e}/', '');
|
|
113
133
|
|
|
@@ -122,7 +142,7 @@ const notFounds = Object.fromEntries(
|
|
|
122
142
|
);
|
|
123
143
|
|
|
124
144
|
export function generateRoutes() {
|
|
125
|
-
const tree = buildRouteTree(pages, layouts, notFounds, ${JSON.stringify(
|
|
145
|
+
const tree = buildRouteTree(pages, layouts, notFounds, ${JSON.stringify(t)});
|
|
126
146
|
const routes = treeToRoutes(tree, true);
|
|
127
147
|
return routes;
|
|
128
148
|
}
|
|
@@ -141,5 +161,5 @@ export { useParams };
|
|
|
141
161
|
};
|
|
142
162
|
}
|
|
143
163
|
export {
|
|
144
|
-
|
|
164
|
+
S as nextViteRouter
|
|
145
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
|
-
};
|