@fluixi/core 1.0.0-alpha.82 → 1.0.0-alpha.84

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.
Files changed (179) hide show
  1. package/dist/cdn/core.global.js +2 -1
  2. package/dist/cli/generate.cjs +4117 -292
  3. package/dist/cli/generate.mjs +4122 -292
  4. package/dist/cli/index.cjs +4117 -292
  5. package/dist/cli/index.mjs +4122 -292
  6. package/dist/cli/run.cjs +63 -1
  7. package/dist/cli/run.mjs +39 -1
  8. package/dist/src/cdn/chunk-VNLCQBFQ.mjs +747 -0
  9. package/dist/src/cdn/core.cjs +1279 -1
  10. package/dist/src/cdn/core.d.ts +3 -3
  11. package/dist/src/cdn/core.js +3 -3
  12. package/dist/src/cdn/core.mjs +642 -1
  13. package/dist/src/cdn/router-WMN2AA7E.mjs +66 -0
  14. package/dist/src/index.cjs +1201 -1
  15. package/dist/src/index.d.ts.map +1 -1
  16. package/dist/src/index.js +1 -11
  17. package/dist/src/index.mjs +1313 -1
  18. package/dist/src/jsx-dev-runtime.cjs +26 -1
  19. package/dist/src/jsx-dev-runtime.mjs +24 -1
  20. package/dist/src/jsx-runtime.cjs +26 -1
  21. package/dist/src/jsx-runtime.js +0 -9
  22. package/dist/src/jsx-runtime.mjs +24 -1
  23. package/dist/src/lib/client/chunk-2C2KDDQV.mjs +133 -0
  24. package/dist/src/lib/client/index.cjs +870 -1
  25. package/dist/src/lib/client/index.d.ts +10 -14
  26. package/dist/src/lib/client/index.d.ts.map +1 -1
  27. package/dist/src/lib/client/index.js +36 -21
  28. package/dist/src/lib/client/index.mjs +222 -1
  29. package/dist/src/lib/client/router-X526HSWQ.mjs +548 -0
  30. package/dist/src/lib/context/context.cjs +118 -1
  31. package/dist/src/lib/context/context.d.ts +20 -38
  32. package/dist/src/lib/context/context.d.ts.map +1 -1
  33. package/dist/src/lib/context/context.js +10 -47
  34. package/dist/src/lib/context/context.mjs +99 -1
  35. package/dist/src/lib/context/index.cjs +120 -1
  36. package/dist/src/lib/context/index.mjs +99 -1
  37. package/dist/src/lib/control-flow.cjs +35 -1
  38. package/dist/src/lib/control-flow.mjs +25 -1
  39. package/dist/src/lib/core.cjs +1200 -1
  40. package/dist/src/lib/core.d.ts +0 -2
  41. package/dist/src/lib/core.d.ts.map +1 -1
  42. package/dist/src/lib/core.js +14 -48
  43. package/dist/src/lib/core.mjs +1313 -1
  44. package/dist/src/lib/env/index.cjs +60 -1
  45. package/dist/src/lib/env/index.d.ts +7 -8
  46. package/dist/src/lib/env/index.d.ts.map +1 -1
  47. package/dist/src/lib/env/index.js +14 -9
  48. package/dist/src/lib/env/index.mjs +39 -1
  49. package/dist/src/lib/i18n/index.cjs +108 -1
  50. package/dist/src/lib/i18n/index.d.ts +31 -10
  51. package/dist/src/lib/i18n/index.d.ts.map +1 -1
  52. package/dist/src/lib/i18n/index.js +31 -10
  53. package/dist/src/lib/i18n/index.mjs +88 -1
  54. package/dist/src/lib/index.cjs +633 -1
  55. package/dist/src/lib/index.d.ts +0 -2
  56. package/dist/src/lib/index.d.ts.map +1 -1
  57. package/dist/src/lib/index.js +5 -11
  58. package/dist/src/lib/index.mjs +721 -1
  59. package/dist/src/lib/isomorphic.cjs +85 -1
  60. package/dist/src/lib/isomorphic.d.ts +41 -8
  61. package/dist/src/lib/isomorphic.d.ts.map +1 -1
  62. package/dist/src/lib/isomorphic.js +38 -5
  63. package/dist/src/lib/isomorphic.mjs +64 -1
  64. package/dist/src/lib/jsx-runtime/index.cjs +21 -1
  65. package/dist/src/lib/jsx-runtime/index.d.ts +1 -1
  66. package/dist/src/lib/jsx-runtime/index.js +1 -11
  67. package/dist/src/lib/jsx-runtime/index.mjs +4 -1
  68. package/dist/src/lib/jsx-runtime/jsx-dev-runtime.cjs +21 -1
  69. package/dist/src/lib/jsx-runtime/jsx-dev-runtime.mjs +4 -1
  70. package/dist/src/lib/plugins/fluixi-routes-plugin.cjs +302 -8
  71. package/dist/src/lib/plugins/fluixi-routes-plugin.d.ts +15 -1
  72. package/dist/src/lib/plugins/fluixi-routes-plugin.d.ts.map +1 -1
  73. package/dist/src/lib/plugins/fluixi-routes-plugin.js +19 -5
  74. package/dist/src/lib/plugins/fluixi-routes-plugin.mjs +271 -8
  75. package/dist/src/lib/plugins/index.cjs +311 -8
  76. package/dist/src/lib/plugins/index.mjs +279 -8
  77. package/dist/src/lib/plugins/route-codegen.cjs +73 -8
  78. package/dist/src/lib/plugins/route-codegen.d.ts +0 -1
  79. package/dist/src/lib/plugins/route-codegen.d.ts.map +1 -1
  80. package/dist/src/lib/plugins/route-codegen.js +4 -5
  81. package/dist/src/lib/plugins/route-codegen.mjs +52 -8
  82. package/dist/src/lib/plugins/route-scanner.cjs +189 -1
  83. package/dist/src/lib/plugins/route-scanner.d.ts +1 -2
  84. package/dist/src/lib/plugins/route-scanner.d.ts.map +1 -1
  85. package/dist/src/lib/plugins/route-scanner.js +7 -8
  86. package/dist/src/lib/plugins/route-scanner.mjs +158 -1
  87. package/dist/src/lib/plugins/vite.cjs +27 -1
  88. package/dist/src/lib/plugins/vite.mjs +6 -1
  89. package/dist/src/lib/render/await.cjs +38 -1
  90. package/dist/src/lib/render/await.d.ts +18 -0
  91. package/dist/src/lib/render/await.d.ts.map +1 -1
  92. package/dist/src/lib/render/await.js +20 -2
  93. package/dist/src/lib/render/await.mjs +17 -1
  94. package/dist/src/lib/render/component.cjs +221 -1
  95. package/dist/src/lib/render/component.d.ts +3 -44
  96. package/dist/src/lib/render/component.d.ts.map +1 -1
  97. package/dist/src/lib/render/component.js +32 -59
  98. package/dist/src/lib/render/component.mjs +214 -1
  99. package/dist/src/lib/render/deferred.cjs +175 -1
  100. package/dist/src/lib/render/deferred.d.ts.map +1 -1
  101. package/dist/src/lib/render/deferred.js +8 -8
  102. package/dist/src/lib/render/deferred.mjs +158 -1
  103. package/dist/src/lib/render/index.cjs +573 -1
  104. package/dist/src/lib/render/index.d.ts +3 -17
  105. package/dist/src/lib/render/index.d.ts.map +1 -1
  106. package/dist/src/lib/render/index.js +12 -26
  107. package/dist/src/lib/render/index.mjs +590 -1
  108. package/dist/src/lib/render/lazy.cjs +67 -1
  109. package/dist/src/lib/render/lazy.d.ts +22 -1
  110. package/dist/src/lib/render/lazy.d.ts.map +1 -1
  111. package/dist/src/lib/render/lazy.js +47 -8
  112. package/dist/src/lib/render/lazy.mjs +50 -1
  113. package/dist/src/lib/render/suspense.cjs +141 -1
  114. package/dist/src/lib/render/suspense.d.ts +40 -0
  115. package/dist/src/lib/render/suspense.d.ts.map +1 -1
  116. package/dist/src/lib/render/suspense.js +47 -7
  117. package/dist/src/lib/render/suspense.mjs +136 -1
  118. package/dist/src/lib/render/versions.cjs +35 -1
  119. package/dist/src/lib/render/versions.js +6 -6
  120. package/dist/src/lib/render/versions.mjs +14 -1
  121. package/dist/src/lib/router/data.cjs +230 -1
  122. package/dist/src/lib/router/data.d.ts +1 -13
  123. package/dist/src/lib/router/data.d.ts.map +1 -1
  124. package/dist/src/lib/router/data.js +1 -13
  125. package/dist/src/lib/router/data.mjs +214 -1
  126. package/dist/src/lib/router/index.cjs +627 -1
  127. package/dist/src/lib/router/index.d.ts +62 -10
  128. package/dist/src/lib/router/index.d.ts.map +1 -1
  129. package/dist/src/lib/router/index.js +90 -39
  130. package/dist/src/lib/router/index.mjs +639 -1
  131. package/dist/src/lib/server/hydration.cjs +169 -1
  132. package/dist/src/lib/server/hydration.d.ts +15 -55
  133. package/dist/src/lib/server/hydration.d.ts.map +1 -1
  134. package/dist/src/lib/server/hydration.js +23 -62
  135. package/dist/src/lib/server/hydration.mjs +148 -1
  136. package/dist/src/lib/server/index.cjs +401 -11
  137. package/dist/src/lib/server/index.d.ts +30 -6
  138. package/dist/src/lib/server/index.d.ts.map +1 -1
  139. package/dist/src/lib/server/index.js +34 -11
  140. package/dist/src/lib/server/index.mjs +379 -11
  141. package/dist/src/lib/server/reactive.cjs +197 -1
  142. package/dist/src/lib/server/reactive.d.ts +18 -77
  143. package/dist/src/lib/server/reactive.d.ts.map +1 -1
  144. package/dist/src/lib/server/reactive.js +19 -78
  145. package/dist/src/lib/server/reactive.mjs +176 -1
  146. package/dist/src/lib/theme/index.cjs +110 -1
  147. package/dist/src/lib/theme/index.d.ts +19 -4
  148. package/dist/src/lib/theme/index.d.ts.map +1 -1
  149. package/dist/src/lib/theme/index.js +17 -2
  150. package/dist/src/lib/theme/index.mjs +89 -1
  151. package/dist/src/lib/utils/index.cjs +209 -1
  152. package/dist/src/lib/utils/index.d.ts +0 -93
  153. package/dist/src/lib/utils/index.d.ts.map +1 -1
  154. package/dist/src/lib/utils/index.js +0 -93
  155. package/dist/src/lib/utils/index.mjs +188 -1
  156. package/dist/src/routes.cjs +37 -1
  157. package/dist/src/routes.d.ts +1 -1
  158. package/dist/src/routes.js +2 -2
  159. package/dist/src/routes.mjs +17 -1
  160. package/dist/src/server.cjs +400 -11
  161. package/dist/src/server.d.ts +0 -1
  162. package/dist/src/server.d.ts.map +1 -1
  163. package/dist/src/server.js +0 -1
  164. package/dist/src/server.mjs +377 -11
  165. package/dist/src/utils.cjs +21 -1
  166. package/dist/src/utils.d.ts +1 -1
  167. package/dist/src/utils.js +1 -1
  168. package/dist/src/utils.mjs +4 -1
  169. package/dist/src/version.generated.cjs +26 -1
  170. package/dist/src/version.generated.d.ts +1 -1
  171. package/dist/src/version.generated.js +2 -2
  172. package/dist/src/version.generated.mjs +5 -1
  173. package/dist/tsconfig.lib.tsbuildinfo +1 -1
  174. package/package.json +17 -16
  175. package/src/index.ts +2 -14
  176. package/dist/src/cdn/chunk-RN7C7HNS.mjs +0 -1
  177. package/dist/src/cdn/router-QB3W43UQ.mjs +0 -1
  178. package/dist/src/lib/client/chunk-FT22BLCQ.mjs +0 -1
  179. package/dist/src/lib/client/router-IH7JYMRU.mjs +0 -1
@@ -1,8 +1,302 @@
1
- "use strict";var T=Object.create;var D=Object.defineProperty;var v=Object.getOwnPropertyDescriptor;var N=Object.getOwnPropertyNames;var V=Object.getPrototypeOf,k=Object.prototype.hasOwnProperty;var J=(n,t)=>{for(var e in t)D(n,e,{get:t[e],enumerable:!0})},j=(n,t,e,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of N(t))!k.call(n,i)&&i!==e&&D(n,i,{get:()=>t[i],enumerable:!(s=v(t,i))||s.enumerable});return n};var O=(n,t,e)=>(e=n!=null?T(V(n)):{},j(t||!n||!n.__esModule?D(e,"default",{value:n,enumerable:!0}):e,n)),U=n=>j(D({},"__esModule",{value:!0}),n);var tn={};J(tn,{fluixiRoutesPlugin:()=>nn});module.exports=U(tn);var _=O(require("path"),1),G=require("vite-plugin-node-polyfills");var g=O(require("fs"),1),p=O(require("path"),1),z=[".tsx",".ts",".jsx",".js"];function A(n,t={}){let e=t.extensions??z,s=p.resolve(n);return g.existsSync(s)?C(s,s,"",e):[]}function C(n,t,e,s){let i=g.readdirSync(n,{withFileTypes:!0}),r=[],m=null,l=[],h=[];for(let u of i)u.isDirectory()?h.push(u):u.isFile()&&B(u.name,s)&&l.push(u);let o,a=[];for(let u of l)W(u.name)==="layout"?o=L(u.name,n,t,e,!0):a.push(u);let d=[];for(let u of a)d.push(L(u.name,n,t,e,!1));let c=[];for(let u of h){let f=u.name,y=X(f),S=y?"":q(f),b=S?w(e,S):e,P=C(p.join(n,f),t,b,s);if(y)c.push(...P);else{let x=P.find(R=>R.isLayout&&R.urlPath===b),$=P.filter(R=>!R.isLayout||R.urlPath!==b);x?(x.children=[...x.children,...$],c.push(x)):$.length>0&&c.push(...$)}}return o?(o.children=[...d,...c],r.push(o)):r.push(...d,...c),H(r)}function L(n,t,e,s,i){let r=W(n),m=p.relative(e,p.join(t,n)),l=r==="index",h=r.startsWith("[..."),o=!h&&r.startsWith("[")&&r.endsWith("]"),a;i?a="":l?a="/":h?a=`*${r.slice(4,-1)}`:o?a=`:${r.slice(1,-1)}`:a=r;let d=i||l?s||"/":w(s,a),c=p.join(t,n),u=!1;try{let f=g.readFileSync(c,"utf-8");u=/export\s+(const|function|async\s+function)\s+routeData\b/.test(f)}catch{}return{filePath:m.replace(/\\/g,"/"),urlSegment:a,urlPath:d,isLayout:i,isIndex:l,isDynamic:o,isCatchAll:h,isGroup:!1,children:[],parentUrlPath:s,hasRouteData:u,rootDir:e,dir:t}}function B(n,t){return t.some(e=>n.endsWith(e))}function W(n){let t=n.lastIndexOf(".");return t>0?n.slice(0,t):n}function X(n){return n.startsWith("(")&&n.endsWith(")")}function q(n){return n.startsWith("[...")&&n.endsWith("]")?"*"+n.slice(4,-1):n.startsWith("[")&&n.endsWith("]")?":"+n.slice(1,-1):n}function w(n,t){return(n.endsWith("/")?n:n+"/")+t}function H(n){return n.sort((t,e)=>t.isLayout&&!e.isLayout?-1:!t.isLayout&&e.isLayout?1:t.isIndex&&!e.isIndex?-1:!t.isIndex&&e.isIndex?1:!t.isDynamic&&!t.isCatchAll&&(e.isDynamic||e.isCatchAll)?-1:(t.isDynamic||t.isCatchAll)&&!e.isDynamic&&!e.isCatchAll?1:t.isDynamic&&e.isCatchAll?-1:t.isCatchAll&&e.isDynamic?1:t.urlSegment.localeCompare(e.urlSegment))}function E(n,t){let e=[];return e.push("// Auto-generated by fluixi route plugin"),e.push("// Do not edit manually"),e.push(""),e.push("import { lazy } from '@fluixi/core/router';"),e.push(""),e.push(`export const routes = ${F(n,t,0)};`),e.push(""),e.join(`
2
- `)}function F(n,t,e){if(n.length===0)return"[]";let s=" ".repeat(e);return`[
3
- ${n.map(r=>K(r,t,e+1)).join(`,
4
- `)}
5
- ${s}]`}function K(n,t,e){let s=" ".repeat(e),i=[],r=Y(n.filePath,t),m=Q(n);if(i.push(`${s} path: ${JSON.stringify(m)}`),i.push(`${s} component: lazy(() => import(${JSON.stringify(r)}))`),n.hasRouteData&&i.push(`${s} data: (args, __owner, __isCancelled) => import(${JSON.stringify(r)}).then(m => { if (typeof __isCancelled === 'function' && __isCancelled()) return undefined; if (!m.routeData) return undefined; return __owner ? m.routeData(args) : m.routeData(args); })`),n.children.length>0){let l=F(n.children,t,e+1);i.push(`${s} children: ${l}`)}return`${s}{
6
- ${i.join(`,
7
- `)}
8
- ${s}}`}function Q(n){return n.urlPath}function Y(n,t){return`${t.replace(/\\/g,"/").replace(/\/$/,"")}/${n}`}var M="virtual:fluixi-routes",I="\0"+M,Z="@fluixi/core/routes";function nn(n={}){let t=n.routesDir??"src/routes",e=n.extensions??[".tsx",".ts",".jsx",".js"],s="",i=null;function r(o){let a=_.resolve(o,t),c=A(a,{extensions:e});return E(c,"./"+t)}let l=n.polyfills!==!1?Object.assign({},(0,G.nodePolyfills)({include:["fs","path"]}),{apply:"serve"}):null,h={name:"fluixi-routes",enforce:"pre",configResolved(o){s=o.root||process.cwd()},resolveId(o){return o===M||o===Z?I:null},load(o){return o!==I?null:(i=r(s||process.cwd()),i)},configureServer(o){let a=s||process.cwd(),d=_.resolve(a,t);o.watcher.add(d),o.watcher.on("all",(c,u)=>{if(!u.startsWith(d)||!["add","unlink","addDir","unlinkDir","change"].includes(c)||c!=="addDir"&&c!=="unlinkDir"&&!e.some(S=>u.endsWith(S)))return;let f=r(a);if(f===i)return;i=f;let y=o.moduleGraph.getModuleById(I);y&&(o.moduleGraph.invalidateModule(y),o.ws.send({type:"full-reload"}))})}};return l?[l,h]:[h]}
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/lib/plugins/fluixi-routes-plugin.ts
31
+ var fluixi_routes_plugin_exports = {};
32
+ __export(fluixi_routes_plugin_exports, {
33
+ fluixiRoutesPlugin: () => fluixiRoutesPlugin
34
+ });
35
+ module.exports = __toCommonJS(fluixi_routes_plugin_exports);
36
+ var path2 = __toESM(require("path"), 1);
37
+ var import_vite_plugin_node_polyfills = require("vite-plugin-node-polyfills");
38
+
39
+ // src/lib/plugins/route-scanner.ts
40
+ var fs = __toESM(require("fs"), 1);
41
+ var path = __toESM(require("path"), 1);
42
+ var DEFAULT_EXTENSIONS = [".tsx", ".ts", ".jsx", ".js"];
43
+ function scanRoutes(routesDir, options = {}) {
44
+ const extensions = options.extensions ?? DEFAULT_EXTENSIONS;
45
+ const absDir = path.resolve(routesDir);
46
+ if (!fs.existsSync(absDir)) {
47
+ return [];
48
+ }
49
+ return scanDirectory(absDir, absDir, "", extensions);
50
+ }
51
+ function scanDirectory(dir, rootDir, parentUrlPath, extensions) {
52
+ const entries = fs.readdirSync(dir, { withFileTypes: true });
53
+ const routes = [];
54
+ const layoutRoute = null;
55
+ const files = [];
56
+ const dirs = [];
57
+ for (const entry of entries) {
58
+ if (entry.isDirectory()) {
59
+ dirs.push(entry);
60
+ } else if (entry.isFile() && hasValidExtension(entry.name, extensions)) {
61
+ files.push(entry);
62
+ }
63
+ }
64
+ let layout;
65
+ const nonLayoutFiles = [];
66
+ for (const file of files) {
67
+ const baseName = stripExtension(file.name);
68
+ if (baseName === "layout") {
69
+ layout = buildFileRoute(file.name, dir, rootDir, parentUrlPath, true);
70
+ } else {
71
+ nonLayoutFiles.push(file);
72
+ }
73
+ }
74
+ const fileRoutes = [];
75
+ for (const file of nonLayoutFiles) {
76
+ fileRoutes.push(
77
+ buildFileRoute(file.name, dir, rootDir, parentUrlPath, false)
78
+ );
79
+ }
80
+ const dirRoutes = [];
81
+ for (const d of dirs) {
82
+ const dirName = d.name;
83
+ const isGroup = isRouteGroup(dirName);
84
+ const segment = isGroup ? "" : dirNameToSegment(dirName);
85
+ const childUrlPath = segment ? joinUrlPath(parentUrlPath, segment) : parentUrlPath;
86
+ const children = scanDirectory(
87
+ path.join(dir, dirName),
88
+ rootDir,
89
+ childUrlPath,
90
+ extensions
91
+ );
92
+ if (isGroup) {
93
+ dirRoutes.push(...children);
94
+ } else {
95
+ const childLayout = children.find((c) => c.isLayout && c.urlPath === childUrlPath);
96
+ const childNonLayout = children.filter((c) => !c.isLayout || c.urlPath !== childUrlPath);
97
+ if (childLayout) {
98
+ childLayout.children = [...childLayout.children, ...childNonLayout];
99
+ dirRoutes.push(childLayout);
100
+ } else if (childNonLayout.length > 0) {
101
+ dirRoutes.push(...childNonLayout);
102
+ }
103
+ }
104
+ }
105
+ if (layout) {
106
+ layout.children = [...fileRoutes, ...dirRoutes];
107
+ routes.push(layout);
108
+ } else {
109
+ routes.push(...fileRoutes, ...dirRoutes);
110
+ }
111
+ return sortRoutes(routes);
112
+ }
113
+ function buildFileRoute(fileName, dir, rootDir, parentUrlPath, isLayout) {
114
+ const baseName = stripExtension(fileName);
115
+ const filePath = path.relative(rootDir, path.join(dir, fileName));
116
+ const isIndex = baseName === "index";
117
+ const isCatchAll = baseName.startsWith("[...");
118
+ const isDynamic = !isCatchAll && baseName.startsWith("[") && baseName.endsWith("]");
119
+ let urlSegment;
120
+ if (isLayout) {
121
+ urlSegment = "";
122
+ } else if (isIndex) {
123
+ urlSegment = "/";
124
+ } else if (isCatchAll) {
125
+ const paramName = baseName.slice(4, -1);
126
+ urlSegment = `*${paramName}`;
127
+ } else if (isDynamic) {
128
+ const paramName = baseName.slice(1, -1);
129
+ urlSegment = `:${paramName}`;
130
+ } else {
131
+ urlSegment = baseName;
132
+ }
133
+ const urlPath = isLayout ? parentUrlPath || "/" : isIndex ? parentUrlPath || "/" : joinUrlPath(parentUrlPath, urlSegment);
134
+ const absoluteFilePath = path.join(dir, fileName);
135
+ let hasRouteData = false;
136
+ try {
137
+ const content = fs.readFileSync(absoluteFilePath, "utf-8");
138
+ hasRouteData = /export\s+(const|function|async\s+function)\s+routeData\b/.test(content);
139
+ } catch {
140
+ }
141
+ return {
142
+ filePath: filePath.replace(/\\/g, "/"),
143
+ // normalize to forward slashes
144
+ urlSegment,
145
+ urlPath,
146
+ isLayout,
147
+ isIndex,
148
+ isDynamic,
149
+ isCatchAll,
150
+ isGroup: false,
151
+ children: [],
152
+ parentUrlPath,
153
+ hasRouteData,
154
+ rootDir,
155
+ dir
156
+ };
157
+ }
158
+ function hasValidExtension(fileName, extensions) {
159
+ return extensions.some((ext) => fileName.endsWith(ext));
160
+ }
161
+ function stripExtension(fileName) {
162
+ const lastDot = fileName.lastIndexOf(".");
163
+ return lastDot > 0 ? fileName.slice(0, lastDot) : fileName;
164
+ }
165
+ function isRouteGroup(dirName) {
166
+ return dirName.startsWith("(") && dirName.endsWith(")");
167
+ }
168
+ function dirNameToSegment(dirName) {
169
+ if (dirName.startsWith("[...") && dirName.endsWith("]")) {
170
+ return "*" + dirName.slice(4, -1);
171
+ }
172
+ if (dirName.startsWith("[") && dirName.endsWith("]")) {
173
+ return ":" + dirName.slice(1, -1);
174
+ }
175
+ return dirName;
176
+ }
177
+ function joinUrlPath(parent, segment) {
178
+ const base = parent.endsWith("/") ? parent : parent + "/";
179
+ return base + segment;
180
+ }
181
+ function sortRoutes(routes) {
182
+ return routes.sort((a, b) => {
183
+ if (a.isLayout && !b.isLayout) return -1;
184
+ if (!a.isLayout && b.isLayout) return 1;
185
+ if (a.isIndex && !b.isIndex) return -1;
186
+ if (!a.isIndex && b.isIndex) return 1;
187
+ if (!a.isDynamic && !a.isCatchAll && (b.isDynamic || b.isCatchAll)) return -1;
188
+ if ((a.isDynamic || a.isCatchAll) && !b.isDynamic && !b.isCatchAll) return 1;
189
+ if (a.isDynamic && b.isCatchAll) return -1;
190
+ if (a.isCatchAll && b.isDynamic) return 1;
191
+ return a.urlSegment.localeCompare(b.urlSegment);
192
+ });
193
+ }
194
+
195
+ // src/lib/plugins/route-codegen.ts
196
+ function generateRouteModule(routes, routesDir) {
197
+ const lines = [];
198
+ lines.push(`// Auto-generated by fluixi route plugin`);
199
+ lines.push(`// Do not edit manually`);
200
+ lines.push(``);
201
+ lines.push(`import { lazy } from '@fluixi/core/router';`);
202
+ lines.push(``);
203
+ lines.push(`export const routes = ${generateRouteArray(routes, routesDir, 0)};`);
204
+ lines.push(``);
205
+ return lines.join("\n");
206
+ }
207
+ function generateRouteArray(routes, routesDir, depth) {
208
+ if (routes.length === 0) return "[]";
209
+ const indent = " ".repeat(depth);
210
+ const items = routes.map((route) => generateRouteObject(route, routesDir, depth + 1));
211
+ return `[
212
+ ${items.join(",\n")}
213
+ ${indent}]`;
214
+ }
215
+ function generateRouteObject(route, routesDir, depth) {
216
+ const indent = " ".repeat(depth);
217
+ const props = [];
218
+ const importPath = buildImportPath(route.filePath, routesDir);
219
+ const routePath = computeRoutePath(route);
220
+ props.push(`${indent} path: ${JSON.stringify(routePath)}`);
221
+ props.push(`${indent} component: lazy(() => import(${JSON.stringify(importPath)}))`);
222
+ if (route.hasRouteData) {
223
+ props.push(
224
+ `${indent} data: (args, __owner, __isCancelled) => import(${JSON.stringify(
225
+ importPath
226
+ )}).then(m => { if (typeof __isCancelled === 'function' && __isCancelled()) return undefined; if (!m.routeData) return undefined; return __owner ? m.routeData(args) : m.routeData(args); })`
227
+ );
228
+ }
229
+ if (route.children.length > 0) {
230
+ const childArray = generateRouteArray(route.children, routesDir, depth + 1);
231
+ props.push(`${indent} children: ${childArray}`);
232
+ }
233
+ return `${indent}{
234
+ ${props.join(",\n")}
235
+ ${indent}}`;
236
+ }
237
+ function computeRoutePath(route) {
238
+ return route.urlPath;
239
+ }
240
+ function buildImportPath(filePath, routesDir) {
241
+ const base = routesDir.replace(/\\/g, "/").replace(/\/$/, "");
242
+ return `${base}/${filePath}`;
243
+ }
244
+
245
+ // src/lib/plugins/fluixi-routes-plugin.ts
246
+ var VIRTUAL_MODULE_ID = "virtual:fluixi-routes";
247
+ var RESOLVED_VIRTUAL_ID = "\0" + VIRTUAL_MODULE_ID;
248
+ var PUBLIC_MODULE_ID = "@fluixi/core/routes";
249
+ function fluixiRoutesPlugin(options = {}) {
250
+ const routesDir = options.routesDir ?? "src/routes";
251
+ const extensions = options.extensions ?? [".tsx", ".ts", ".jsx", ".js"];
252
+ let projectRoot = "";
253
+ let lastGenerated = null;
254
+ function generateModule(root) {
255
+ const absRoutesDir = path2.resolve(root, routesDir);
256
+ const scanOpts = { extensions };
257
+ const routes = scanRoutes(absRoutesDir, scanOpts);
258
+ return generateRouteModule(routes, "./" + routesDir);
259
+ }
260
+ const usePolyfills = options.polyfills !== false;
261
+ const polyfillsPlugin = usePolyfills ? Object.assign({}, (0, import_vite_plugin_node_polyfills.nodePolyfills)({ include: ["fs", "path"] }), { apply: "serve" }) : null;
262
+ const routesPlugin = {
263
+ name: "fluixi-routes",
264
+ enforce: "pre",
265
+ configResolved(config) {
266
+ projectRoot = config.root || process.cwd();
267
+ },
268
+ resolveId(id) {
269
+ if (id === VIRTUAL_MODULE_ID || id === PUBLIC_MODULE_ID) {
270
+ return RESOLVED_VIRTUAL_ID;
271
+ }
272
+ return null;
273
+ },
274
+ load(id) {
275
+ if (id !== RESOLVED_VIRTUAL_ID) return null;
276
+ lastGenerated = generateModule(projectRoot || process.cwd());
277
+ return lastGenerated;
278
+ },
279
+ // Vite dev server: watch routes directory for changes
280
+ configureServer(server) {
281
+ const root = projectRoot || process.cwd();
282
+ const absRoutesDir = path2.resolve(root, routesDir);
283
+ server.watcher.add(absRoutesDir);
284
+ server.watcher.on("all", (event, filePath) => {
285
+ if (!filePath.startsWith(absRoutesDir)) return;
286
+ if (!["add", "unlink", "addDir", "unlinkDir", "change"].includes(event)) return;
287
+ if (event !== "addDir" && event !== "unlinkDir" && !extensions.some((ext) => filePath.endsWith(ext))) {
288
+ return;
289
+ }
290
+ const next = generateModule(root);
291
+ if (next === lastGenerated) return;
292
+ lastGenerated = next;
293
+ const mod = server.moduleGraph.getModuleById(RESOLVED_VIRTUAL_ID);
294
+ if (mod) {
295
+ server.moduleGraph.invalidateModule(mod);
296
+ server.ws.send({ type: "full-reload" });
297
+ }
298
+ });
299
+ }
300
+ };
301
+ return polyfillsPlugin ? [polyfillsPlugin, routesPlugin] : [routesPlugin];
302
+ }
@@ -1,5 +1,4 @@
1
1
  /**
2
- * @fileoverview Vite/Rollup plugin for file-system routing
3
2
  * @module @fluixi/core/plugins/fluixi-routes-plugin
4
3
  *
5
4
  * Scans a routes directory at build time and generates a virtual module
@@ -17,5 +16,20 @@ export interface FluixiRoutesPluginOptions {
17
16
  */
18
17
  polyfills?: boolean;
19
18
  }
19
+ /**
20
+ * The Vite plugin that turns a routes directory into a route tree.
21
+ *
22
+ * Scans `routesDir` and serves the result as `@fluixi/core/routes`, so an app imports a
23
+ * real module from this package and needs no generated `declare module` of its own. The
24
+ * shipped file is a typed empty array, which is what the plugin replaces.
25
+ *
26
+ * Without it that import resolves to the empty array and an app has no routes, which is
27
+ * the error `routes.ts` raises rather than rendering a blank page.
28
+ *
29
+ * @example
30
+ * ```ts
31
+ * export default defineConfig({ plugins: [fluixiRoutesPlugin({ routesDir: 'src/routes' })] });
32
+ * ```
33
+ */
20
34
  export declare function fluixiRoutesPlugin(options?: FluixiRoutesPluginOptions): any[];
21
35
  //# sourceMappingURL=fluixi-routes-plugin.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"fluixi-routes-plugin.d.ts","sourceRoot":"","sources":["../../../../src/lib/plugins/fluixi-routes-plugin.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAQH,MAAM,WAAW,yBAAyB;IACxC,gFAAgF;IAChF,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,uEAAuE;IACvE,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB;;;;OAIG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAcD,wBAAgB,kBAAkB,CAChC,OAAO,GAAE,yBAA8B,GACtC,GAAG,EAAE,CA+FP"}
1
+ {"version":3,"file":"fluixi-routes-plugin.d.ts","sourceRoot":"","sources":["../../../../src/lib/plugins/fluixi-routes-plugin.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAQH,MAAM,WAAW,yBAAyB;IACxC,gFAAgF;IAChF,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,uEAAuE;IACvE,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB;;;;OAIG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAcD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,GAAE,yBAA8B,GACtC,GAAG,EAAE,CA+FP"}
@@ -1,5 +1,4 @@
1
1
  /**
2
- * @fileoverview Vite/Rollup plugin for file-system routing
3
2
  * @module @fluixi/core/plugins/fluixi-routes-plugin
4
3
  *
5
4
  * Scans a routes directory at build time and generates a virtual module
@@ -19,6 +18,21 @@ const RESOLVED_VIRTUAL_ID = '\0' + VIRTUAL_MODULE_ID;
19
18
  * `virtual:fluixi-routes` stays resolvable so existing apps keep working.
20
19
  */
21
20
  const PUBLIC_MODULE_ID = '@fluixi/core/routes';
21
+ /**
22
+ * The Vite plugin that turns a routes directory into a route tree.
23
+ *
24
+ * Scans `routesDir` and serves the result as `@fluixi/core/routes`, so an app imports a
25
+ * real module from this package and needs no generated `declare module` of its own. The
26
+ * shipped file is a typed empty array, which is what the plugin replaces.
27
+ *
28
+ * Without it that import resolves to the empty array and an app has no routes, which is
29
+ * the error `routes.ts` raises rather than rendering a blank page.
30
+ *
31
+ * @example
32
+ * ```ts
33
+ * export default defineConfig({ plugins: [fluixiRoutesPlugin({ routesDir: 'src/routes' })] });
34
+ * ```
35
+ */
22
36
  export function fluixiRoutesPlugin(options = {}) {
23
37
  const routesDir = options.routesDir ?? 'src/routes';
24
38
  const extensions = options.extensions ?? ['.tsx', '.ts', '.jsx', '.js'];
@@ -34,7 +48,7 @@ export function fluixiRoutesPlugin(options = {}) {
34
48
  }
35
49
  // nodePolyfills injects `vite-plugin-node-polyfills/shims/*` (browser polyfills for
36
50
  // Buffer/process/global/fs/path) into transformed modules. It's needed by some apps
37
- // for the BROWSER, but it BREAKS SSR Node already has those globals, and the
51
+ // for the BROWSER, but it BREAKS SSR. Node already has those globals, and the
38
52
  // injected CJS shim can't be ESM-evaluated (and often can't be resolved at all:
39
53
  // "Cannot find module .../shims/buffer"). So it's opt-out: on by default for
40
54
  // back-compat, but SSR-first setups (e.g. @fluixi/start) pass `polyfills: false`.
@@ -71,7 +85,7 @@ export function fluixiRoutesPlugin(options = {}) {
71
85
  return;
72
86
  // `change` matters as much as add/unlink. The route tree is not only a list of
73
87
  // files: `routeData` is detected by reading each file at scan time, so EDITING a
74
- // route adding a `routeData` export, or changing one changes the generated
88
+ // route, adding a `routeData` export, or changing one, changes the generated
75
89
  // module even though no file appeared or vanished. Leaving `change` out meant
76
90
  // those edits needed a dev-server restart to take effect.
77
91
  if (!['add', 'unlink', 'addDir', 'unlinkDir', 'change'].includes(event))
@@ -83,7 +97,7 @@ export function fluixiRoutesPlugin(options = {}) {
83
97
  return;
84
98
  }
85
99
  // Regenerate and compare before invalidating. Every save of a route component now
86
- // reaches this handler, and most change nothing about the tree reloading the
100
+ // reaches this handler, and most change nothing about the tree: reloading the
87
101
  // page on each of them would undo the point of HMR. A full reload is only correct
88
102
  // when the generated module actually differs.
89
103
  const next = generateModule(root);
@@ -98,7 +112,7 @@ export function fluixiRoutesPlugin(options = {}) {
98
112
  });
99
113
  },
100
114
  };
101
- // Vite flattens plugin arrays automatically consumers just use:
115
+ // Vite flattens plugin arrays automatically: consumers just use:
102
116
  // plugins: [fluixiRoutesPlugin({ routesDir: 'src/routes' })]
103
117
  return polyfillsPlugin ? [polyfillsPlugin, routesPlugin] : [routesPlugin];
104
118
  }