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 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(__dirname, "./${src ? "src" : "."}"),
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 = `nextViteRouter({ pagesDir: "${src ? "src/app" : "app"}", pageFile: "page.tsx", layoutFile: "layout.tsx", notFoundFile: "not-found.tsx" })`;
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.1";
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 { e as z, n as g } from "./path-BodMUTCM.js";
2
- import i, { Suspense as C, lazy as x, createContext as L, useContext as M } from "react";
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 k = {
5
+ const M = {
5
6
  enableLazyLoading: !0
6
7
  };
7
- let d = { ...k };
8
- function B(e) {
9
- d = { ...d, ...e };
8
+ let m = { ...M };
9
+ function j(e) {
10
+ m = { ...m, ...e };
10
11
  }
11
- function S() {
12
- return d;
12
+ function k() {
13
+ return m;
13
14
  }
14
- let E = [];
15
- function H(e, t) {
16
- E.push({ pattern: e, middleware: t });
15
+ let g = [];
16
+ function q(e, t) {
17
+ g.push({ pattern: e, middleware: t });
17
18
  }
18
- function J() {
19
- E = [];
19
+ function B() {
20
+ g = [];
20
21
  }
21
- function p(e, t) {
22
+ function h(e, t) {
22
23
  let n = t;
23
- for (const r of E)
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 T = () => i.createElement("div"), y = /* @__PURE__ */ new Map();
28
+ const S = () => c.createElement("div"), C = /* @__PURE__ */ new Map();
28
29
  function R(e, t, n) {
29
- const r = S();
30
+ const r = k();
30
31
  if (r.enableLazyLoading === !1) {
31
- const u = i.lazy(e), s = i.createElement(
32
- C,
32
+ const s = c.lazy(e), i = c.createElement(
33
+ d,
33
34
  { fallback: null },
34
35
  // No loading fallback when disabled
35
- i.createElement(u)
36
+ c.createElement(s)
36
37
  );
37
- return n ? p(n, s) : s;
38
+ return n ? h(n, i) : i;
38
39
  }
39
- let a = y.get(t);
40
- a || (a = x(e), y.set(t, a));
41
- const l = r.loadingFallback || T, o = i.createElement(
42
- C,
43
- { fallback: i.createElement(l) },
44
- i.createElement(a)
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 ? p(n, o) : o;
47
- }
48
- function m(e, t, n, r, a) {
49
- const l = z(t, a), o = l ? l.split("/") : [];
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 i.createElement(
79
- F.Provider,
54
+ return c.createElement(
55
+ w.Provider,
80
56
  { value: e },
81
57
  t
82
58
  );
83
59
  }
84
- function D() {
85
- return M(F);
60
+ function N() {
61
+ return L(w);
86
62
  }
87
- function P(e, t) {
88
- return p(e, i.createElement(t));
63
+ function y(e, t) {
64
+ return h(e, c.createElement(t));
89
65
  }
90
- function I(e) {
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 ? i.createElement(N, {
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: g(e.segment), element: o };
81
+ return n ? { index: !0, element: o } : { path: p(e.segment), element: o };
106
82
  }
107
- function $(e) {
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 b(e, t) {
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 = g(r), o = l ? t ? `${t}/${l}` : `/${l}` : t;
125
- n.push(...v(a, !1, o));
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 w(e, t) {
104
+ function E(e, t) {
129
105
  const n = [];
130
- return e.page && n.push(f(e, t || "/", !0)), n.push(...b(e, t)), e.notFound && n.push($(e)), n;
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 v(e, t = !1, n = "") {
108
+ function $(e, t = !1, n = "") {
133
109
  const r = [];
134
110
  if (t) {
135
- const c = w(e, "");
111
+ const u = E(e, "");
136
112
  return e.layout ? (r.push({
137
113
  path: "/",
138
- element: P("/", e.layout),
139
- children: c
140
- }), r) : e.page ? (r.push({
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
- children: c.slice(1).length > 0 ? c.slice(1) : void 0
144
- }), r) : e.notFound ? (r.push({
121
+ element: f(e, "/", !1).element
122
+ }] : e.notFound ? (r.push({
145
123
  path: "/",
146
- children: c
147
- }), r) : c;
124
+ children: u
125
+ }), r) : u;
148
126
  }
149
- const a = g(e.segment), l = !a, o = l ? n : n + "/" + a, u = b(e, o), s = e.notFound ? [$(e)] : [];
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 c = w(e, o);
129
+ const u = E(e, o);
152
130
  return [{
153
131
  ...l ? {} : { path: a },
154
- element: P(o, e.layout),
155
- children: c.length > 0 ? c : void 0
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 (I(e.segment)) {
160
- const c = f(e, n, !0), h = {
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: [...u, ...s].length > 0 ? [...u, ...s] : void 0
141
+ children: [...s, ...i].length > 0 ? [...s, ...i] : void 0
164
142
  };
165
- return [c, h];
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 c = [
158
+ const u = [
175
159
  ...e.page ? [f(e, o, !0)] : [],
176
- ...u,
177
- ...s
160
+ ...s,
161
+ ...i
178
162
  ];
179
163
  return [{
180
164
  ...l ? {} : { path: a },
181
- children: c.length > 0 ? c : void 0
165
+ children: u.length > 0 ? u : void 0
182
166
  }];
183
167
  }
184
- return u;
168
+ return s;
185
169
  }
186
- function Q(e, t, n, r) {
170
+ function H(e, t, n, r) {
187
171
  return () => {
188
- const a = j(e, t, n, r);
189
- return v(a, !0);
172
+ const a = z(e, t, n, r);
173
+ return $(a, !0);
190
174
  };
191
175
  }
192
- function U() {
193
- const e = A(), t = D();
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
- N as CatchAllParamProvider,
198
- j as buildRouteTree,
199
- J as clearMiddlewares,
200
- B as configureRouter,
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
- Q as createRouteGenerator,
203
- z as extractRoutePath,
204
- g as normalizeSegment,
205
- H as registerMiddleware,
206
- v as treeToRoutes,
207
- U as useParams
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 d from "node:fs";
2
- import u from "node:path";
3
- import { n as R } from "./path-BodMUTCM.js";
4
- function g(r) {
5
- const e = r.split(u.sep).filter(Boolean).map(R).filter(Boolean);
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 v(r, e) {
9
- const i = /* @__PURE__ */ new Map();
10
- function a(n) {
11
- for (const s of d.readdirSync(n, { withFileTypes: !0 })) {
12
- const m = u.join(n, s.name);
13
- if (s.isDirectory())
14
- a(m);
15
- else if (s.isFile() && s.name === e) {
16
- const o = u.relative(r, n), f = o.split(u.sep).filter(Boolean).map((c) => {
17
- const t = c.match(/^\[\[\.\.\.(.+)\]\]$/);
18
- if (t)
19
- return { name: t[1], optional: !0 };
20
- const p = c.match(/^\[\.\.\.(.+)\]$/);
21
- return p ? { name: p[1], optional: !1 } : void 0;
22
- }).filter((c) => !!c);
23
- i.set(g(o), {
24
- path: g(o),
25
- params: f
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 d.existsSync(r) && a(r), [...i.values()].sort((n, s) => n.path.localeCompare(s.path));
32
+ return h.existsSync(r) && s(r), [...n.values()].sort((a, t) => a.path.localeCompare(t.path));
31
33
  }
32
- function x(r) {
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 P(r) {
37
- const e = r.map(({ path: a }) => ` | "${a}"`).join(`
38
- `), i = r.map(({ path: a, params: n }) => {
39
- const s = a.split("/").map((o) => x(`/${o}`)).filter((o) => !!o), m = s.length > 0 || n.length > 0 ? [
40
- ...s.map((o) => ` ${o}: string;`),
41
- ...n.map(({ name: o, optional: l }) => ` ${o}${l ? "?" : ""}: string;`)
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 ` "${a}": {
45
- ${m}
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
- ${i}
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 k(r = {}) {
83
+ function S(r = {}) {
72
84
  const {
73
85
  pagesDir: e = "src/app",
74
- pageFile: i = "page.tsx",
75
- layoutFile: a = "layout.tsx",
76
- notFoundFile: n = "not-found.tsx"
77
- } = r, s = { pagesDir: e, pageFile: i, layoutFile: a, notFoundFile: n }, m = "virtual:next-vite-router", o = "\0" + m;
78
- let l = "", f = "";
79
- function c() {
80
- const t = P(v(l, i));
81
- d.writeFileSync(f, t, "utf-8");
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(t) {
86
- l = u.resolve(t.root, e), f = u.join(u.dirname(l), "virtual-next-vite-router.d.ts"), c();
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(t) {
89
- const p = (h) => {
90
- if (u.relative(l, h).startsWith("..") || ![i, a, n].includes(u.basename(h)))
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
- c();
93
- const y = t.moduleGraph.getModuleById(o);
94
- y && (t.moduleGraph.invalidateModule(y), t.ws.send({ type: "full-reload", path: "*" }));
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
- t.watcher.on("add", p), t.watcher.on("unlink", p);
116
+ o.watcher.on("add", g), o.watcher.on("unlink", g);
97
117
  },
98
- resolveId(t) {
99
- if (t === m)
100
- return o;
118
+ resolveId(o) {
119
+ if (o === c)
120
+ return i;
101
121
  },
102
- load(t) {
103
- if (t === o)
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}/**/${i}');
109
- const layoutsGlob = import.meta.glob('/${e}/**/${a}', { eager: true });
110
- const notFoundsGlob = import.meta.glob('/${e}/**/${n}');
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(s)});
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
- k as nextViteRouter
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-vite-router",
3
- "version": "1.2.1",
3
+ "version": "1.2.2",
4
4
  "description": "Next.js-like file-based routing for React + Vite",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -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
- };