@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.
- 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 +10 -14
- package/dist/src/lib/client/index.d.ts.map +1 -1
- package/dist/src/lib/client/index.js +36 -21
- 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 +20 -38
- package/dist/src/lib/context/context.d.ts.map +1 -1
- package/dist/src/lib/context/context.js +10 -47
- 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 +7 -8
- package/dist/src/lib/env/index.d.ts.map +1 -1
- package/dist/src/lib/env/index.js +14 -9
- 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 +32 -59
- package/dist/src/lib/render/component.mjs +214 -1
- package/dist/src/lib/render/deferred.cjs +175 -1
- package/dist/src/lib/render/deferred.d.ts.map +1 -1
- package/dist/src/lib/render/deferred.js +8 -8
- 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 +12 -26
- 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 +47 -8
- 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 +47 -7
- 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 +1 -13
- 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 +90 -39
- 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-RN7C7HNS.mjs +0 -1
- package/dist/src/cdn/router-QB3W43UQ.mjs +0 -1
- package/dist/src/lib/client/chunk-FT22BLCQ.mjs +0 -1
- package/dist/src/lib/client/router-IH7JYMRU.mjs +0 -1
|
@@ -1,8 +1,302 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
}
|