@fluixi/core 1.0.0-alpha.83 → 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.
- package/dist/cdn/core.global.js +2 -1
- package/dist/cli/generate.cjs +4117 -292
- package/dist/cli/generate.mjs +4122 -292
- package/dist/cli/index.cjs +4117 -292
- package/dist/cli/index.mjs +4122 -292
- package/dist/cli/run.cjs +63 -1
- package/dist/cli/run.mjs +39 -1
- package/dist/src/cdn/chunk-VNLCQBFQ.mjs +747 -0
- package/dist/src/cdn/core.cjs +1279 -1
- package/dist/src/cdn/core.d.ts +3 -3
- package/dist/src/cdn/core.js +3 -3
- package/dist/src/cdn/core.mjs +642 -1
- package/dist/src/cdn/router-WMN2AA7E.mjs +66 -0
- package/dist/src/index.cjs +1201 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +1 -11
- package/dist/src/index.mjs +1313 -1
- package/dist/src/jsx-dev-runtime.cjs +26 -1
- package/dist/src/jsx-dev-runtime.mjs +24 -1
- package/dist/src/jsx-runtime.cjs +26 -1
- package/dist/src/jsx-runtime.js +0 -9
- package/dist/src/jsx-runtime.mjs +24 -1
- package/dist/src/lib/client/chunk-2C2KDDQV.mjs +133 -0
- package/dist/src/lib/client/index.cjs +870 -1
- package/dist/src/lib/client/index.d.ts +17 -6
- package/dist/src/lib/client/index.d.ts.map +1 -1
- package/dist/src/lib/client/index.js +26 -19
- package/dist/src/lib/client/index.mjs +222 -1
- package/dist/src/lib/client/router-X526HSWQ.mjs +548 -0
- package/dist/src/lib/context/context.cjs +118 -1
- package/dist/src/lib/context/context.d.ts +19 -37
- package/dist/src/lib/context/context.d.ts.map +1 -1
- package/dist/src/lib/context/context.js +8 -45
- package/dist/src/lib/context/context.mjs +99 -1
- package/dist/src/lib/context/index.cjs +120 -1
- package/dist/src/lib/context/index.mjs +99 -1
- package/dist/src/lib/control-flow.cjs +35 -1
- package/dist/src/lib/control-flow.mjs +25 -1
- package/dist/src/lib/core.cjs +1200 -1
- package/dist/src/lib/core.d.ts +0 -2
- package/dist/src/lib/core.d.ts.map +1 -1
- package/dist/src/lib/core.js +14 -48
- package/dist/src/lib/core.mjs +1313 -1
- package/dist/src/lib/env/index.cjs +60 -1
- package/dist/src/lib/env/index.d.ts +5 -5
- package/dist/src/lib/env/index.js +5 -5
- package/dist/src/lib/env/index.mjs +39 -1
- package/dist/src/lib/i18n/index.cjs +108 -1
- package/dist/src/lib/i18n/index.d.ts +31 -10
- package/dist/src/lib/i18n/index.d.ts.map +1 -1
- package/dist/src/lib/i18n/index.js +31 -10
- package/dist/src/lib/i18n/index.mjs +88 -1
- package/dist/src/lib/index.cjs +633 -1
- package/dist/src/lib/index.d.ts +0 -2
- package/dist/src/lib/index.d.ts.map +1 -1
- package/dist/src/lib/index.js +5 -11
- package/dist/src/lib/index.mjs +721 -1
- package/dist/src/lib/isomorphic.cjs +85 -1
- package/dist/src/lib/isomorphic.d.ts +41 -8
- package/dist/src/lib/isomorphic.d.ts.map +1 -1
- package/dist/src/lib/isomorphic.js +38 -5
- package/dist/src/lib/isomorphic.mjs +64 -1
- package/dist/src/lib/jsx-runtime/index.cjs +21 -1
- package/dist/src/lib/jsx-runtime/index.d.ts +1 -1
- package/dist/src/lib/jsx-runtime/index.js +1 -11
- package/dist/src/lib/jsx-runtime/index.mjs +4 -1
- package/dist/src/lib/jsx-runtime/jsx-dev-runtime.cjs +21 -1
- package/dist/src/lib/jsx-runtime/jsx-dev-runtime.mjs +4 -1
- package/dist/src/lib/plugins/fluixi-routes-plugin.cjs +302 -8
- package/dist/src/lib/plugins/fluixi-routes-plugin.d.ts +15 -1
- package/dist/src/lib/plugins/fluixi-routes-plugin.d.ts.map +1 -1
- package/dist/src/lib/plugins/fluixi-routes-plugin.js +19 -5
- package/dist/src/lib/plugins/fluixi-routes-plugin.mjs +271 -8
- package/dist/src/lib/plugins/index.cjs +311 -8
- package/dist/src/lib/plugins/index.mjs +279 -8
- package/dist/src/lib/plugins/route-codegen.cjs +73 -8
- package/dist/src/lib/plugins/route-codegen.d.ts +0 -1
- package/dist/src/lib/plugins/route-codegen.d.ts.map +1 -1
- package/dist/src/lib/plugins/route-codegen.js +4 -5
- package/dist/src/lib/plugins/route-codegen.mjs +52 -8
- package/dist/src/lib/plugins/route-scanner.cjs +189 -1
- package/dist/src/lib/plugins/route-scanner.d.ts +1 -2
- package/dist/src/lib/plugins/route-scanner.d.ts.map +1 -1
- package/dist/src/lib/plugins/route-scanner.js +7 -8
- package/dist/src/lib/plugins/route-scanner.mjs +158 -1
- package/dist/src/lib/plugins/vite.cjs +27 -1
- package/dist/src/lib/plugins/vite.mjs +6 -1
- package/dist/src/lib/render/await.cjs +38 -1
- package/dist/src/lib/render/await.d.ts +18 -0
- package/dist/src/lib/render/await.d.ts.map +1 -1
- package/dist/src/lib/render/await.js +20 -2
- package/dist/src/lib/render/await.mjs +17 -1
- package/dist/src/lib/render/component.cjs +221 -1
- package/dist/src/lib/render/component.d.ts +3 -44
- package/dist/src/lib/render/component.d.ts.map +1 -1
- package/dist/src/lib/render/component.js +23 -55
- package/dist/src/lib/render/component.mjs +214 -1
- package/dist/src/lib/render/deferred.cjs +175 -1
- package/dist/src/lib/render/deferred.js +5 -5
- package/dist/src/lib/render/deferred.mjs +158 -1
- package/dist/src/lib/render/index.cjs +573 -1
- package/dist/src/lib/render/index.d.ts +3 -17
- package/dist/src/lib/render/index.d.ts.map +1 -1
- package/dist/src/lib/render/index.js +8 -22
- package/dist/src/lib/render/index.mjs +590 -1
- package/dist/src/lib/render/lazy.cjs +67 -1
- package/dist/src/lib/render/lazy.d.ts +22 -1
- package/dist/src/lib/render/lazy.d.ts.map +1 -1
- package/dist/src/lib/render/lazy.js +26 -5
- package/dist/src/lib/render/lazy.mjs +50 -1
- package/dist/src/lib/render/suspense.cjs +141 -1
- package/dist/src/lib/render/suspense.d.ts +40 -0
- package/dist/src/lib/render/suspense.d.ts.map +1 -1
- package/dist/src/lib/render/suspense.js +46 -6
- package/dist/src/lib/render/suspense.mjs +136 -1
- package/dist/src/lib/render/versions.cjs +35 -1
- package/dist/src/lib/render/versions.js +6 -6
- package/dist/src/lib/render/versions.mjs +14 -1
- package/dist/src/lib/router/data.cjs +230 -1
- package/dist/src/lib/router/data.d.ts +1 -13
- package/dist/src/lib/router/data.d.ts.map +1 -1
- package/dist/src/lib/router/data.js +0 -12
- package/dist/src/lib/router/data.mjs +214 -1
- package/dist/src/lib/router/index.cjs +627 -1
- package/dist/src/lib/router/index.d.ts +62 -10
- package/dist/src/lib/router/index.d.ts.map +1 -1
- package/dist/src/lib/router/index.js +85 -33
- package/dist/src/lib/router/index.mjs +639 -1
- package/dist/src/lib/server/hydration.cjs +169 -1
- package/dist/src/lib/server/hydration.d.ts +15 -55
- package/dist/src/lib/server/hydration.d.ts.map +1 -1
- package/dist/src/lib/server/hydration.js +23 -62
- package/dist/src/lib/server/hydration.mjs +148 -1
- package/dist/src/lib/server/index.cjs +401 -11
- package/dist/src/lib/server/index.d.ts +30 -6
- package/dist/src/lib/server/index.d.ts.map +1 -1
- package/dist/src/lib/server/index.js +34 -11
- package/dist/src/lib/server/index.mjs +379 -11
- package/dist/src/lib/server/reactive.cjs +197 -1
- package/dist/src/lib/server/reactive.d.ts +18 -77
- package/dist/src/lib/server/reactive.d.ts.map +1 -1
- package/dist/src/lib/server/reactive.js +19 -78
- package/dist/src/lib/server/reactive.mjs +176 -1
- package/dist/src/lib/theme/index.cjs +110 -1
- package/dist/src/lib/theme/index.d.ts +19 -4
- package/dist/src/lib/theme/index.d.ts.map +1 -1
- package/dist/src/lib/theme/index.js +17 -2
- package/dist/src/lib/theme/index.mjs +89 -1
- package/dist/src/lib/utils/index.cjs +209 -1
- package/dist/src/lib/utils/index.d.ts +0 -93
- package/dist/src/lib/utils/index.d.ts.map +1 -1
- package/dist/src/lib/utils/index.js +0 -93
- package/dist/src/lib/utils/index.mjs +188 -1
- package/dist/src/routes.cjs +37 -1
- package/dist/src/routes.d.ts +1 -1
- package/dist/src/routes.js +2 -2
- package/dist/src/routes.mjs +17 -1
- package/dist/src/server.cjs +400 -11
- package/dist/src/server.d.ts +0 -1
- package/dist/src/server.d.ts.map +1 -1
- package/dist/src/server.js +0 -1
- package/dist/src/server.mjs +377 -11
- package/dist/src/utils.cjs +21 -1
- package/dist/src/utils.d.ts +1 -1
- package/dist/src/utils.js +1 -1
- package/dist/src/utils.mjs +4 -1
- package/dist/src/version.generated.cjs +26 -1
- package/dist/src/version.generated.d.ts +1 -1
- package/dist/src/version.generated.js +2 -2
- package/dist/src/version.generated.mjs +5 -1
- package/dist/tsconfig.lib.tsbuildinfo +1 -1
- package/package.json +17 -16
- package/src/index.ts +2 -14
- package/dist/src/cdn/chunk-55BT3H6E.mjs +0 -1
- package/dist/src/cdn/router-5JJZBK4E.mjs +0 -1
- package/dist/src/lib/client/chunk-SM4WHBOP.mjs +0 -1
- package/dist/src/lib/client/router-IBD4WPQT.mjs +0 -1
|
@@ -1,8 +1,279 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
/*! @fluixi/core v1.0.0-alpha.84 | (c) 2026 Ibrahima Touré and Fluixi contributors | MIT */
|
|
2
|
+
|
|
3
|
+
// src/lib/plugins/vite.ts
|
|
4
|
+
import { fluixi, createVitePlugin } from "@fluixi/vite-plugin";
|
|
5
|
+
|
|
6
|
+
// src/lib/plugins/fluixi-routes-plugin.ts
|
|
7
|
+
import * as path2 from "path";
|
|
8
|
+
import { nodePolyfills } from "vite-plugin-node-polyfills";
|
|
9
|
+
|
|
10
|
+
// src/lib/plugins/route-scanner.ts
|
|
11
|
+
import * as fs from "fs";
|
|
12
|
+
import * as path from "path";
|
|
13
|
+
var DEFAULT_EXTENSIONS = [".tsx", ".ts", ".jsx", ".js"];
|
|
14
|
+
function scanRoutes(routesDir, options = {}) {
|
|
15
|
+
const extensions = options.extensions ?? DEFAULT_EXTENSIONS;
|
|
16
|
+
const absDir = path.resolve(routesDir);
|
|
17
|
+
if (!fs.existsSync(absDir)) {
|
|
18
|
+
return [];
|
|
19
|
+
}
|
|
20
|
+
return scanDirectory(absDir, absDir, "", extensions);
|
|
21
|
+
}
|
|
22
|
+
function scanDirectory(dir, rootDir, parentUrlPath, extensions) {
|
|
23
|
+
const entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
24
|
+
const routes = [];
|
|
25
|
+
const layoutRoute = null;
|
|
26
|
+
const files = [];
|
|
27
|
+
const dirs = [];
|
|
28
|
+
for (const entry of entries) {
|
|
29
|
+
if (entry.isDirectory()) {
|
|
30
|
+
dirs.push(entry);
|
|
31
|
+
} else if (entry.isFile() && hasValidExtension(entry.name, extensions)) {
|
|
32
|
+
files.push(entry);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
let layout;
|
|
36
|
+
const nonLayoutFiles = [];
|
|
37
|
+
for (const file of files) {
|
|
38
|
+
const baseName = stripExtension(file.name);
|
|
39
|
+
if (baseName === "layout") {
|
|
40
|
+
layout = buildFileRoute(file.name, dir, rootDir, parentUrlPath, true);
|
|
41
|
+
} else {
|
|
42
|
+
nonLayoutFiles.push(file);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
const fileRoutes = [];
|
|
46
|
+
for (const file of nonLayoutFiles) {
|
|
47
|
+
fileRoutes.push(
|
|
48
|
+
buildFileRoute(file.name, dir, rootDir, parentUrlPath, false)
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
const dirRoutes = [];
|
|
52
|
+
for (const d of dirs) {
|
|
53
|
+
const dirName = d.name;
|
|
54
|
+
const isGroup = isRouteGroup(dirName);
|
|
55
|
+
const segment = isGroup ? "" : dirNameToSegment(dirName);
|
|
56
|
+
const childUrlPath = segment ? joinUrlPath(parentUrlPath, segment) : parentUrlPath;
|
|
57
|
+
const children = scanDirectory(
|
|
58
|
+
path.join(dir, dirName),
|
|
59
|
+
rootDir,
|
|
60
|
+
childUrlPath,
|
|
61
|
+
extensions
|
|
62
|
+
);
|
|
63
|
+
if (isGroup) {
|
|
64
|
+
dirRoutes.push(...children);
|
|
65
|
+
} else {
|
|
66
|
+
const childLayout = children.find((c) => c.isLayout && c.urlPath === childUrlPath);
|
|
67
|
+
const childNonLayout = children.filter((c) => !c.isLayout || c.urlPath !== childUrlPath);
|
|
68
|
+
if (childLayout) {
|
|
69
|
+
childLayout.children = [...childLayout.children, ...childNonLayout];
|
|
70
|
+
dirRoutes.push(childLayout);
|
|
71
|
+
} else if (childNonLayout.length > 0) {
|
|
72
|
+
dirRoutes.push(...childNonLayout);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
if (layout) {
|
|
77
|
+
layout.children = [...fileRoutes, ...dirRoutes];
|
|
78
|
+
routes.push(layout);
|
|
79
|
+
} else {
|
|
80
|
+
routes.push(...fileRoutes, ...dirRoutes);
|
|
81
|
+
}
|
|
82
|
+
return sortRoutes(routes);
|
|
83
|
+
}
|
|
84
|
+
function buildFileRoute(fileName, dir, rootDir, parentUrlPath, isLayout) {
|
|
85
|
+
const baseName = stripExtension(fileName);
|
|
86
|
+
const filePath = path.relative(rootDir, path.join(dir, fileName));
|
|
87
|
+
const isIndex = baseName === "index";
|
|
88
|
+
const isCatchAll = baseName.startsWith("[...");
|
|
89
|
+
const isDynamic = !isCatchAll && baseName.startsWith("[") && baseName.endsWith("]");
|
|
90
|
+
let urlSegment;
|
|
91
|
+
if (isLayout) {
|
|
92
|
+
urlSegment = "";
|
|
93
|
+
} else if (isIndex) {
|
|
94
|
+
urlSegment = "/";
|
|
95
|
+
} else if (isCatchAll) {
|
|
96
|
+
const paramName = baseName.slice(4, -1);
|
|
97
|
+
urlSegment = `*${paramName}`;
|
|
98
|
+
} else if (isDynamic) {
|
|
99
|
+
const paramName = baseName.slice(1, -1);
|
|
100
|
+
urlSegment = `:${paramName}`;
|
|
101
|
+
} else {
|
|
102
|
+
urlSegment = baseName;
|
|
103
|
+
}
|
|
104
|
+
const urlPath = isLayout ? parentUrlPath || "/" : isIndex ? parentUrlPath || "/" : joinUrlPath(parentUrlPath, urlSegment);
|
|
105
|
+
const absoluteFilePath = path.join(dir, fileName);
|
|
106
|
+
let hasRouteData = false;
|
|
107
|
+
try {
|
|
108
|
+
const content = fs.readFileSync(absoluteFilePath, "utf-8");
|
|
109
|
+
hasRouteData = /export\s+(const|function|async\s+function)\s+routeData\b/.test(content);
|
|
110
|
+
} catch {
|
|
111
|
+
}
|
|
112
|
+
return {
|
|
113
|
+
filePath: filePath.replace(/\\/g, "/"),
|
|
114
|
+
// normalize to forward slashes
|
|
115
|
+
urlSegment,
|
|
116
|
+
urlPath,
|
|
117
|
+
isLayout,
|
|
118
|
+
isIndex,
|
|
119
|
+
isDynamic,
|
|
120
|
+
isCatchAll,
|
|
121
|
+
isGroup: false,
|
|
122
|
+
children: [],
|
|
123
|
+
parentUrlPath,
|
|
124
|
+
hasRouteData,
|
|
125
|
+
rootDir,
|
|
126
|
+
dir
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
function hasValidExtension(fileName, extensions) {
|
|
130
|
+
return extensions.some((ext) => fileName.endsWith(ext));
|
|
131
|
+
}
|
|
132
|
+
function stripExtension(fileName) {
|
|
133
|
+
const lastDot = fileName.lastIndexOf(".");
|
|
134
|
+
return lastDot > 0 ? fileName.slice(0, lastDot) : fileName;
|
|
135
|
+
}
|
|
136
|
+
function isRouteGroup(dirName) {
|
|
137
|
+
return dirName.startsWith("(") && dirName.endsWith(")");
|
|
138
|
+
}
|
|
139
|
+
function dirNameToSegment(dirName) {
|
|
140
|
+
if (dirName.startsWith("[...") && dirName.endsWith("]")) {
|
|
141
|
+
return "*" + dirName.slice(4, -1);
|
|
142
|
+
}
|
|
143
|
+
if (dirName.startsWith("[") && dirName.endsWith("]")) {
|
|
144
|
+
return ":" + dirName.slice(1, -1);
|
|
145
|
+
}
|
|
146
|
+
return dirName;
|
|
147
|
+
}
|
|
148
|
+
function joinUrlPath(parent, segment) {
|
|
149
|
+
const base = parent.endsWith("/") ? parent : parent + "/";
|
|
150
|
+
return base + segment;
|
|
151
|
+
}
|
|
152
|
+
function sortRoutes(routes) {
|
|
153
|
+
return routes.sort((a, b) => {
|
|
154
|
+
if (a.isLayout && !b.isLayout) return -1;
|
|
155
|
+
if (!a.isLayout && b.isLayout) return 1;
|
|
156
|
+
if (a.isIndex && !b.isIndex) return -1;
|
|
157
|
+
if (!a.isIndex && b.isIndex) return 1;
|
|
158
|
+
if (!a.isDynamic && !a.isCatchAll && (b.isDynamic || b.isCatchAll)) return -1;
|
|
159
|
+
if ((a.isDynamic || a.isCatchAll) && !b.isDynamic && !b.isCatchAll) return 1;
|
|
160
|
+
if (a.isDynamic && b.isCatchAll) return -1;
|
|
161
|
+
if (a.isCatchAll && b.isDynamic) return 1;
|
|
162
|
+
return a.urlSegment.localeCompare(b.urlSegment);
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// src/lib/plugins/route-codegen.ts
|
|
167
|
+
function generateRouteModule(routes, routesDir) {
|
|
168
|
+
const lines = [];
|
|
169
|
+
lines.push(`// Auto-generated by fluixi route plugin`);
|
|
170
|
+
lines.push(`// Do not edit manually`);
|
|
171
|
+
lines.push(``);
|
|
172
|
+
lines.push(`import { lazy } from '@fluixi/core/router';`);
|
|
173
|
+
lines.push(``);
|
|
174
|
+
lines.push(`export const routes = ${generateRouteArray(routes, routesDir, 0)};`);
|
|
175
|
+
lines.push(``);
|
|
176
|
+
return lines.join("\n");
|
|
177
|
+
}
|
|
178
|
+
function generateRouteArray(routes, routesDir, depth) {
|
|
179
|
+
if (routes.length === 0) return "[]";
|
|
180
|
+
const indent = " ".repeat(depth);
|
|
181
|
+
const items = routes.map((route) => generateRouteObject(route, routesDir, depth + 1));
|
|
182
|
+
return `[
|
|
183
|
+
${items.join(",\n")}
|
|
184
|
+
${indent}]`;
|
|
185
|
+
}
|
|
186
|
+
function generateRouteObject(route, routesDir, depth) {
|
|
187
|
+
const indent = " ".repeat(depth);
|
|
188
|
+
const props = [];
|
|
189
|
+
const importPath = buildImportPath(route.filePath, routesDir);
|
|
190
|
+
const routePath = computeRoutePath(route);
|
|
191
|
+
props.push(`${indent} path: ${JSON.stringify(routePath)}`);
|
|
192
|
+
props.push(`${indent} component: lazy(() => import(${JSON.stringify(importPath)}))`);
|
|
193
|
+
if (route.hasRouteData) {
|
|
194
|
+
props.push(
|
|
195
|
+
`${indent} data: (args, __owner, __isCancelled) => import(${JSON.stringify(
|
|
196
|
+
importPath
|
|
197
|
+
)}).then(m => { if (typeof __isCancelled === 'function' && __isCancelled()) return undefined; if (!m.routeData) return undefined; return __owner ? m.routeData(args) : m.routeData(args); })`
|
|
198
|
+
);
|
|
199
|
+
}
|
|
200
|
+
if (route.children.length > 0) {
|
|
201
|
+
const childArray = generateRouteArray(route.children, routesDir, depth + 1);
|
|
202
|
+
props.push(`${indent} children: ${childArray}`);
|
|
203
|
+
}
|
|
204
|
+
return `${indent}{
|
|
205
|
+
${props.join(",\n")}
|
|
206
|
+
${indent}}`;
|
|
207
|
+
}
|
|
208
|
+
function computeRoutePath(route) {
|
|
209
|
+
return route.urlPath;
|
|
210
|
+
}
|
|
211
|
+
function buildImportPath(filePath, routesDir) {
|
|
212
|
+
const base = routesDir.replace(/\\/g, "/").replace(/\/$/, "");
|
|
213
|
+
return `${base}/${filePath}`;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
// src/lib/plugins/fluixi-routes-plugin.ts
|
|
217
|
+
var VIRTUAL_MODULE_ID = "virtual:fluixi-routes";
|
|
218
|
+
var RESOLVED_VIRTUAL_ID = "\0" + VIRTUAL_MODULE_ID;
|
|
219
|
+
var PUBLIC_MODULE_ID = "@fluixi/core/routes";
|
|
220
|
+
function fluixiRoutesPlugin(options = {}) {
|
|
221
|
+
const routesDir = options.routesDir ?? "src/routes";
|
|
222
|
+
const extensions = options.extensions ?? [".tsx", ".ts", ".jsx", ".js"];
|
|
223
|
+
let projectRoot = "";
|
|
224
|
+
let lastGenerated = null;
|
|
225
|
+
function generateModule(root) {
|
|
226
|
+
const absRoutesDir = path2.resolve(root, routesDir);
|
|
227
|
+
const scanOpts = { extensions };
|
|
228
|
+
const routes = scanRoutes(absRoutesDir, scanOpts);
|
|
229
|
+
return generateRouteModule(routes, "./" + routesDir);
|
|
230
|
+
}
|
|
231
|
+
const usePolyfills = options.polyfills !== false;
|
|
232
|
+
const polyfillsPlugin = usePolyfills ? Object.assign({}, nodePolyfills({ include: ["fs", "path"] }), { apply: "serve" }) : null;
|
|
233
|
+
const routesPlugin = {
|
|
234
|
+
name: "fluixi-routes",
|
|
235
|
+
enforce: "pre",
|
|
236
|
+
configResolved(config) {
|
|
237
|
+
projectRoot = config.root || process.cwd();
|
|
238
|
+
},
|
|
239
|
+
resolveId(id) {
|
|
240
|
+
if (id === VIRTUAL_MODULE_ID || id === PUBLIC_MODULE_ID) {
|
|
241
|
+
return RESOLVED_VIRTUAL_ID;
|
|
242
|
+
}
|
|
243
|
+
return null;
|
|
244
|
+
},
|
|
245
|
+
load(id) {
|
|
246
|
+
if (id !== RESOLVED_VIRTUAL_ID) return null;
|
|
247
|
+
lastGenerated = generateModule(projectRoot || process.cwd());
|
|
248
|
+
return lastGenerated;
|
|
249
|
+
},
|
|
250
|
+
// Vite dev server: watch routes directory for changes
|
|
251
|
+
configureServer(server) {
|
|
252
|
+
const root = projectRoot || process.cwd();
|
|
253
|
+
const absRoutesDir = path2.resolve(root, routesDir);
|
|
254
|
+
server.watcher.add(absRoutesDir);
|
|
255
|
+
server.watcher.on("all", (event, filePath) => {
|
|
256
|
+
if (!filePath.startsWith(absRoutesDir)) return;
|
|
257
|
+
if (!["add", "unlink", "addDir", "unlinkDir", "change"].includes(event)) return;
|
|
258
|
+
if (event !== "addDir" && event !== "unlinkDir" && !extensions.some((ext) => filePath.endsWith(ext))) {
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
const next = generateModule(root);
|
|
262
|
+
if (next === lastGenerated) return;
|
|
263
|
+
lastGenerated = next;
|
|
264
|
+
const mod = server.moduleGraph.getModuleById(RESOLVED_VIRTUAL_ID);
|
|
265
|
+
if (mod) {
|
|
266
|
+
server.moduleGraph.invalidateModule(mod);
|
|
267
|
+
server.ws.send({ type: "full-reload" });
|
|
268
|
+
}
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
};
|
|
272
|
+
return polyfillsPlugin ? [polyfillsPlugin, routesPlugin] : [routesPlugin];
|
|
273
|
+
}
|
|
274
|
+
export {
|
|
275
|
+
createVitePlugin,
|
|
276
|
+
fluixi,
|
|
277
|
+
fluixiRoutesPlugin,
|
|
278
|
+
scanRoutes
|
|
279
|
+
};
|
|
@@ -1,8 +1,73 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/lib/plugins/route-codegen.ts
|
|
21
|
+
var route_codegen_exports = {};
|
|
22
|
+
__export(route_codegen_exports, {
|
|
23
|
+
generateRouteModule: () => generateRouteModule
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(route_codegen_exports);
|
|
26
|
+
function generateRouteModule(routes, routesDir) {
|
|
27
|
+
const lines = [];
|
|
28
|
+
lines.push(`// Auto-generated by fluixi route plugin`);
|
|
29
|
+
lines.push(`// Do not edit manually`);
|
|
30
|
+
lines.push(``);
|
|
31
|
+
lines.push(`import { lazy } from '@fluixi/core/router';`);
|
|
32
|
+
lines.push(``);
|
|
33
|
+
lines.push(`export const routes = ${generateRouteArray(routes, routesDir, 0)};`);
|
|
34
|
+
lines.push(``);
|
|
35
|
+
return lines.join("\n");
|
|
36
|
+
}
|
|
37
|
+
function generateRouteArray(routes, routesDir, depth) {
|
|
38
|
+
if (routes.length === 0) return "[]";
|
|
39
|
+
const indent = " ".repeat(depth);
|
|
40
|
+
const items = routes.map((route) => generateRouteObject(route, routesDir, depth + 1));
|
|
41
|
+
return `[
|
|
42
|
+
${items.join(",\n")}
|
|
43
|
+
${indent}]`;
|
|
44
|
+
}
|
|
45
|
+
function generateRouteObject(route, routesDir, depth) {
|
|
46
|
+
const indent = " ".repeat(depth);
|
|
47
|
+
const props = [];
|
|
48
|
+
const importPath = buildImportPath(route.filePath, routesDir);
|
|
49
|
+
const routePath = computeRoutePath(route);
|
|
50
|
+
props.push(`${indent} path: ${JSON.stringify(routePath)}`);
|
|
51
|
+
props.push(`${indent} component: lazy(() => import(${JSON.stringify(importPath)}))`);
|
|
52
|
+
if (route.hasRouteData) {
|
|
53
|
+
props.push(
|
|
54
|
+
`${indent} data: (args, __owner, __isCancelled) => import(${JSON.stringify(
|
|
55
|
+
importPath
|
|
56
|
+
)}).then(m => { if (typeof __isCancelled === 'function' && __isCancelled()) return undefined; if (!m.routeData) return undefined; return __owner ? m.routeData(args) : m.routeData(args); })`
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
if (route.children.length > 0) {
|
|
60
|
+
const childArray = generateRouteArray(route.children, routesDir, depth + 1);
|
|
61
|
+
props.push(`${indent} children: ${childArray}`);
|
|
62
|
+
}
|
|
63
|
+
return `${indent}{
|
|
64
|
+
${props.join(",\n")}
|
|
65
|
+
${indent}}`;
|
|
66
|
+
}
|
|
67
|
+
function computeRoutePath(route) {
|
|
68
|
+
return route.urlPath;
|
|
69
|
+
}
|
|
70
|
+
function buildImportPath(filePath, routesDir) {
|
|
71
|
+
const base = routesDir.replace(/\\/g, "/").replace(/\/$/, "");
|
|
72
|
+
return `${base}/${filePath}`;
|
|
73
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"route-codegen.d.ts","sourceRoot":"","sources":["../../../../src/lib/plugins/route-codegen.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"route-codegen.d.ts","sourceRoot":"","sources":["../../../../src/lib/plugins/route-codegen.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAevD;;GAEG;AACH,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,YAAY,EAAE,EACtB,SAAS,EAAE,MAAM,GAChB,MAAM,CAeR"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @fileoverview Route code generator
|
|
3
2
|
* @module @fluixi/core/plugins/route-codegen
|
|
4
3
|
*
|
|
5
4
|
* Generates an ES module from a ScannedRoute tree.
|
|
@@ -27,7 +26,7 @@ export function generateRouteModule(routes, routesDir) {
|
|
|
27
26
|
lines.push(``);
|
|
28
27
|
// router is lit-free; the old './router' barrel imported @fluixi/lit (extends
|
|
29
28
|
// HTMLElement at module init) which crashed SSR/prod server bundles. (runWithOwner was
|
|
30
|
-
// imported here but never used in the generated output
|
|
29
|
+
// imported here but never used in the generated output: dropped.)
|
|
31
30
|
lines.push(`import { lazy } from '@fluixi/core/router';`);
|
|
32
31
|
lines.push(``);
|
|
33
32
|
lines.push(`export const routes = ${generateRouteArray(routes, routesDir, 0)};`);
|
|
@@ -48,9 +47,9 @@ function generateRouteObject(route, routesDir, depth) {
|
|
|
48
47
|
// Path
|
|
49
48
|
const routePath = computeRoutePath(route);
|
|
50
49
|
props.push(`${indent} path: ${JSON.stringify(routePath)}`);
|
|
51
|
-
// Component
|
|
50
|
+
// Component: lazy-loaded via dynamic import + Suspense
|
|
52
51
|
props.push(`${indent} component: lazy(() => import(${JSON.stringify(importPath)}))`);
|
|
53
|
-
// Data loader
|
|
52
|
+
// Data loader, only generated for routes that export `routeData`
|
|
54
53
|
// This prevents unnecessary async imports and avoids calling d.data() for
|
|
55
54
|
// levels that have no data, which kept the router's if (d.data) check clean.
|
|
56
55
|
if (route.hasRouteData) {
|
|
@@ -67,7 +66,7 @@ function generateRouteObject(route, routesDir, depth) {
|
|
|
67
66
|
/**
|
|
68
67
|
* Compute the route path for a RouteDefinition.
|
|
69
68
|
* The scanner already resolves groups, dynamic segments, and index paths
|
|
70
|
-
* into the correct urlPath
|
|
69
|
+
* into the correct urlPath, just use it directly.
|
|
71
70
|
*/
|
|
72
71
|
function computeRoutePath(route) {
|
|
73
72
|
return route.urlPath;
|
|
@@ -1,8 +1,52 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
`)
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
`)
|
|
8
|
-
|
|
1
|
+
// src/lib/plugins/route-codegen.ts
|
|
2
|
+
function generateRouteModule(routes, routesDir) {
|
|
3
|
+
const lines = [];
|
|
4
|
+
lines.push(`// Auto-generated by fluixi route plugin`);
|
|
5
|
+
lines.push(`// Do not edit manually`);
|
|
6
|
+
lines.push(``);
|
|
7
|
+
lines.push(`import { lazy } from '@fluixi/core/router';`);
|
|
8
|
+
lines.push(``);
|
|
9
|
+
lines.push(`export const routes = ${generateRouteArray(routes, routesDir, 0)};`);
|
|
10
|
+
lines.push(``);
|
|
11
|
+
return lines.join("\n");
|
|
12
|
+
}
|
|
13
|
+
function generateRouteArray(routes, routesDir, depth) {
|
|
14
|
+
if (routes.length === 0) return "[]";
|
|
15
|
+
const indent = " ".repeat(depth);
|
|
16
|
+
const items = routes.map((route) => generateRouteObject(route, routesDir, depth + 1));
|
|
17
|
+
return `[
|
|
18
|
+
${items.join(",\n")}
|
|
19
|
+
${indent}]`;
|
|
20
|
+
}
|
|
21
|
+
function generateRouteObject(route, routesDir, depth) {
|
|
22
|
+
const indent = " ".repeat(depth);
|
|
23
|
+
const props = [];
|
|
24
|
+
const importPath = buildImportPath(route.filePath, routesDir);
|
|
25
|
+
const routePath = computeRoutePath(route);
|
|
26
|
+
props.push(`${indent} path: ${JSON.stringify(routePath)}`);
|
|
27
|
+
props.push(`${indent} component: lazy(() => import(${JSON.stringify(importPath)}))`);
|
|
28
|
+
if (route.hasRouteData) {
|
|
29
|
+
props.push(
|
|
30
|
+
`${indent} data: (args, __owner, __isCancelled) => import(${JSON.stringify(
|
|
31
|
+
importPath
|
|
32
|
+
)}).then(m => { if (typeof __isCancelled === 'function' && __isCancelled()) return undefined; if (!m.routeData) return undefined; return __owner ? m.routeData(args) : m.routeData(args); })`
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
if (route.children.length > 0) {
|
|
36
|
+
const childArray = generateRouteArray(route.children, routesDir, depth + 1);
|
|
37
|
+
props.push(`${indent} children: ${childArray}`);
|
|
38
|
+
}
|
|
39
|
+
return `${indent}{
|
|
40
|
+
${props.join(",\n")}
|
|
41
|
+
${indent}}`;
|
|
42
|
+
}
|
|
43
|
+
function computeRoutePath(route) {
|
|
44
|
+
return route.urlPath;
|
|
45
|
+
}
|
|
46
|
+
function buildImportPath(filePath, routesDir) {
|
|
47
|
+
const base = routesDir.replace(/\\/g, "/").replace(/\/$/, "");
|
|
48
|
+
return `${base}/${filePath}`;
|
|
49
|
+
}
|
|
50
|
+
export {
|
|
51
|
+
generateRouteModule
|
|
52
|
+
};
|