@fluixi/start 0.1.0-alpha.73 → 0.1.0-alpha.74
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/adapter.cjs +748 -0
- package/dist/adapter.mjs +717 -0
- package/dist/adapters/entry.cjs +122 -0
- package/dist/adapters/entry.mjs +95 -0
- package/dist/adapters/platforms.cjs +311 -0
- package/dist/adapters/platforms.mjs +284 -0
- package/dist/api-RH6E5UTH.mjs +114 -0
- package/dist/api.cjs +145 -0
- package/dist/api.mjs +116 -0
- package/dist/commands/api-23MJFSYL.mjs +17 -0
- package/dist/commands/api-4IYNQRKG.mjs +16 -0
- package/dist/commands/api-RH6E5UTH.mjs +114 -0
- package/dist/commands/build.cjs +870 -0
- package/dist/commands/build.mjs +710 -0
- package/dist/commands/chunk-NS5GR2GX.mjs +115 -0
- package/dist/commands/chunk-OCPCK4ZJ.mjs +117 -0
- package/dist/commands/dev.cjs +663 -0
- package/dist/commands/dev.mjs +505 -0
- package/dist/commands/index.cjs +1138 -0
- package/dist/commands/index.mjs +975 -0
- package/dist/commands/prerender.cjs +402 -0
- package/dist/commands/prerender.mjs +375 -0
- package/dist/commands/start.cjs +461 -0
- package/dist/commands/start.mjs +426 -0
- package/dist/config.cjs +144 -0
- package/dist/config.mjs +108 -0
- package/dist/di.cjs +200 -0
- package/dist/di.mjs +169 -0
- package/dist/document.cjs +115 -0
- package/dist/document.mjs +86 -0
- package/dist/generated-api.cjs +43 -0
- package/dist/generated-api.mjs +18 -0
- package/dist/generated-server-fns.cjs +43 -0
- package/dist/generated-server-fns.mjs +18 -0
- package/dist/handler-core.cjs +211 -0
- package/dist/handler-core.mjs +185 -0
- package/dist/handler.cjs +181 -0
- package/dist/handler.mjs +150 -0
- package/dist/head.cjs +25 -0
- package/dist/head.mjs +4 -0
- package/dist/image.cjs +146 -0
- package/dist/image.mjs +120 -0
- package/dist/index.cjs +1036 -0
- package/dist/index.mjs +968 -0
- package/dist/interceptors.cjs +71 -0
- package/dist/interceptors.mjs +42 -0
- package/dist/internal.cjs +388 -0
- package/dist/internal.mjs +218 -0
- package/dist/middleware.cjs +58 -0
- package/dist/middleware.mjs +31 -0
- package/dist/preload.cjs +42 -0
- package/dist/preload.mjs +18 -0
- package/dist/router.cjs +25 -0
- package/dist/router.mjs +4 -0
- package/dist/server-fn-setup.cjs +46 -0
- package/dist/server-fn-setup.mjs +22 -0
- package/dist/server-fn.cjs +109 -0
- package/dist/server-fn.mjs +79 -0
- package/dist/tsconfig.lib.tsbuildinfo +1 -1
- package/dist/ui.cjs +123 -0
- package/dist/ui.mjs +93 -0
- package/package.json +45 -25
|
@@ -0,0 +1,71 @@
|
|
|
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/interceptors.ts
|
|
21
|
+
var interceptors_exports = {};
|
|
22
|
+
__export(interceptors_exports, {
|
|
23
|
+
addInterceptor: () => addInterceptor,
|
|
24
|
+
clearInterceptors: () => clearInterceptors,
|
|
25
|
+
fetchWithInterceptors: () => fetchWithInterceptors
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(interceptors_exports);
|
|
28
|
+
|
|
29
|
+
// src/server-fn.ts
|
|
30
|
+
var _fetch = (...a) => fetch(...a);
|
|
31
|
+
function setServerFnFetch(f) {
|
|
32
|
+
_fetch = f;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// src/interceptors.ts
|
|
36
|
+
var interceptors = [];
|
|
37
|
+
function addInterceptor(interceptor) {
|
|
38
|
+
if (interceptors.length === 0) setServerFnFetch(fetchWithInterceptors);
|
|
39
|
+
interceptors.push(interceptor);
|
|
40
|
+
return () => {
|
|
41
|
+
const i = interceptors.indexOf(interceptor);
|
|
42
|
+
if (i >= 0) interceptors.splice(i, 1);
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
function clearInterceptors() {
|
|
46
|
+
interceptors.length = 0;
|
|
47
|
+
setServerFnFetch(((...a) => fetch(...a)));
|
|
48
|
+
}
|
|
49
|
+
async function fetchWithInterceptors(input, init) {
|
|
50
|
+
let request = input instanceof Request && !init ? input : new Request(input, init);
|
|
51
|
+
for (const i of interceptors) if (i.request) request = await i.request(request);
|
|
52
|
+
let response;
|
|
53
|
+
try {
|
|
54
|
+
response = await fetch(request);
|
|
55
|
+
} catch (error) {
|
|
56
|
+
for (const i of interceptors) {
|
|
57
|
+
if (!i.error) continue;
|
|
58
|
+
const recovered = await i.error(error, request);
|
|
59
|
+
if (recovered) return recovered;
|
|
60
|
+
}
|
|
61
|
+
throw error;
|
|
62
|
+
}
|
|
63
|
+
for (const i of interceptors) if (i.response) response = await i.response(response, request);
|
|
64
|
+
return response;
|
|
65
|
+
}
|
|
66
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
67
|
+
0 && (module.exports = {
|
|
68
|
+
addInterceptor,
|
|
69
|
+
clearInterceptors,
|
|
70
|
+
fetchWithInterceptors
|
|
71
|
+
});
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// src/server-fn.ts
|
|
2
|
+
var _fetch = (...a) => fetch(...a);
|
|
3
|
+
function setServerFnFetch(f) {
|
|
4
|
+
_fetch = f;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
// src/interceptors.ts
|
|
8
|
+
var interceptors = [];
|
|
9
|
+
function addInterceptor(interceptor) {
|
|
10
|
+
if (interceptors.length === 0) setServerFnFetch(fetchWithInterceptors);
|
|
11
|
+
interceptors.push(interceptor);
|
|
12
|
+
return () => {
|
|
13
|
+
const i = interceptors.indexOf(interceptor);
|
|
14
|
+
if (i >= 0) interceptors.splice(i, 1);
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
function clearInterceptors() {
|
|
18
|
+
interceptors.length = 0;
|
|
19
|
+
setServerFnFetch(((...a) => fetch(...a)));
|
|
20
|
+
}
|
|
21
|
+
async function fetchWithInterceptors(input, init) {
|
|
22
|
+
let request = input instanceof Request && !init ? input : new Request(input, init);
|
|
23
|
+
for (const i of interceptors) if (i.request) request = await i.request(request);
|
|
24
|
+
let response;
|
|
25
|
+
try {
|
|
26
|
+
response = await fetch(request);
|
|
27
|
+
} catch (error) {
|
|
28
|
+
for (const i of interceptors) {
|
|
29
|
+
if (!i.error) continue;
|
|
30
|
+
const recovered = await i.error(error, request);
|
|
31
|
+
if (recovered) return recovered;
|
|
32
|
+
}
|
|
33
|
+
throw error;
|
|
34
|
+
}
|
|
35
|
+
for (const i of interceptors) if (i.response) response = await i.response(response, request);
|
|
36
|
+
return response;
|
|
37
|
+
}
|
|
38
|
+
export {
|
|
39
|
+
addInterceptor,
|
|
40
|
+
clearInterceptors,
|
|
41
|
+
fetchWithInterceptors
|
|
42
|
+
};
|
|
@@ -0,0 +1,388 @@
|
|
|
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 __esm = (fn, res) => function __init() {
|
|
9
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
10
|
+
};
|
|
11
|
+
var __export = (target, all) => {
|
|
12
|
+
for (var name in all)
|
|
13
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
14
|
+
};
|
|
15
|
+
var __copyProps = (to, from, except, desc) => {
|
|
16
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
17
|
+
for (let key of __getOwnPropNames(from))
|
|
18
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
19
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
20
|
+
}
|
|
21
|
+
return to;
|
|
22
|
+
};
|
|
23
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
24
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
25
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
26
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
27
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
28
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
29
|
+
mod
|
|
30
|
+
));
|
|
31
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
32
|
+
|
|
33
|
+
// src/api.ts
|
|
34
|
+
var api_exports = {};
|
|
35
|
+
__export(api_exports, {
|
|
36
|
+
API_VIRTUAL_MODULE: () => API_VIRTUAL_MODULE,
|
|
37
|
+
apiRoutesVitePlugin: () => apiRoutesVitePlugin,
|
|
38
|
+
derivePattern: () => derivePattern,
|
|
39
|
+
handleApi: () => handleApi,
|
|
40
|
+
isApiPath: () => isApiPath,
|
|
41
|
+
matchApiRoutes: () => matchApiRoutes
|
|
42
|
+
});
|
|
43
|
+
function derivePattern(rel, prefix = "/api") {
|
|
44
|
+
const segs = rel.split("/").filter(Boolean);
|
|
45
|
+
if (segs[segs.length - 1] === "index") segs.pop();
|
|
46
|
+
const keys = [];
|
|
47
|
+
let rank = 0;
|
|
48
|
+
const parts = segs.map((seg) => {
|
|
49
|
+
const catchAll = seg.match(/^\[\.\.\.(.+)\]$/);
|
|
50
|
+
if (catchAll) {
|
|
51
|
+
keys.push(catchAll[1]);
|
|
52
|
+
return "(.+)";
|
|
53
|
+
}
|
|
54
|
+
const param = seg.match(/^\[(.+)\]$/);
|
|
55
|
+
if (param) {
|
|
56
|
+
keys.push(param[1]);
|
|
57
|
+
rank += 1;
|
|
58
|
+
return "([^/]+)";
|
|
59
|
+
}
|
|
60
|
+
rank += 10;
|
|
61
|
+
return seg.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
62
|
+
});
|
|
63
|
+
return { source: `^${prefix}${parts.length ? "/" + parts.join("/") : ""}/?$`, keys, rank };
|
|
64
|
+
}
|
|
65
|
+
function isApiPath(pathname, prefix = "/api") {
|
|
66
|
+
return pathname === prefix || pathname.startsWith(prefix + "/");
|
|
67
|
+
}
|
|
68
|
+
function matchApiRoutes(routes, pathname) {
|
|
69
|
+
for (const r of [...routes].sort((a, b) => b.rank - a.rank)) {
|
|
70
|
+
const m = new RegExp(r.source).exec(pathname);
|
|
71
|
+
if (!m) continue;
|
|
72
|
+
const params = {};
|
|
73
|
+
r.keys.forEach((k, i) => params[k] = decodeURIComponent(m[i + 1] ?? ""));
|
|
74
|
+
return { mod: r.mod, params };
|
|
75
|
+
}
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
async function handleApi(routes, request, prefix = "/api") {
|
|
79
|
+
const pathname = new URL(request.url).pathname;
|
|
80
|
+
const match = matchApiRoutes(routes, pathname);
|
|
81
|
+
if (!match) return new Response("Not Found", { status: 404 });
|
|
82
|
+
const fn = match.mod[request.method];
|
|
83
|
+
if (typeof fn !== "function") {
|
|
84
|
+
const allow = METHODS.filter((m) => typeof match.mod[m] === "function").join(", ");
|
|
85
|
+
return new Response("Method Not Allowed", { status: 405, headers: allow ? { allow } : void 0 });
|
|
86
|
+
}
|
|
87
|
+
const out = await fn(request, { params: match.params });
|
|
88
|
+
if (out instanceof Response) return out;
|
|
89
|
+
return new Response(JSON.stringify(out ?? null), { headers: { "content-type": "application/json; charset=utf-8" } });
|
|
90
|
+
}
|
|
91
|
+
function scanFiles(dir, base = dir) {
|
|
92
|
+
let out = [];
|
|
93
|
+
let entries = [];
|
|
94
|
+
try {
|
|
95
|
+
entries = (0, import_node_fs.readdirSync)(dir);
|
|
96
|
+
} catch {
|
|
97
|
+
return out;
|
|
98
|
+
}
|
|
99
|
+
for (const name of entries) {
|
|
100
|
+
const full = (0, import_node_path.join)(dir, name);
|
|
101
|
+
if ((0, import_node_fs.statSync)(full).isDirectory()) out = out.concat(scanFiles(full, base));
|
|
102
|
+
else if (/\.(ts|tsx|js|mjs)$/.test(name) && !/\.(spec|test)\./.test(name)) out.push(full);
|
|
103
|
+
}
|
|
104
|
+
return out;
|
|
105
|
+
}
|
|
106
|
+
function apiRoutesVitePlugin(opts) {
|
|
107
|
+
let root = process.cwd();
|
|
108
|
+
const prefix = opts.prefix ?? "/api";
|
|
109
|
+
const id = "\0" + API_VMOD;
|
|
110
|
+
return {
|
|
111
|
+
name: "fluixi-api",
|
|
112
|
+
// Must beat node resolution: '@fluixi/start/api-routes' is a real file in this package,
|
|
113
|
+
// so without `pre` Vite resolves the typed stub and the generated table never loads —
|
|
114
|
+
// the app builds and every API route 404s.
|
|
115
|
+
enforce: "pre",
|
|
116
|
+
configResolved(config) {
|
|
117
|
+
root = config.root || root;
|
|
118
|
+
},
|
|
119
|
+
resolveId(source) {
|
|
120
|
+
return source === API_VMOD || source === "@fluixi/start/api-routes" ? id : null;
|
|
121
|
+
},
|
|
122
|
+
load(source) {
|
|
123
|
+
if (source !== id) return null;
|
|
124
|
+
const dir = (0, import_node_path.resolve)(root, opts.dir);
|
|
125
|
+
const files = scanFiles(dir);
|
|
126
|
+
const imports = [];
|
|
127
|
+
const entries = [];
|
|
128
|
+
files.forEach((file, i) => {
|
|
129
|
+
const rel = (0, import_node_path.relative)(dir, file).replace(/\.(ts|tsx|js|mjs)$/, "").split(/[\\/]/).join("/");
|
|
130
|
+
const { source: src, keys, rank } = derivePattern(rel, prefix);
|
|
131
|
+
imports.push(`import * as _${i} from ${JSON.stringify(file)};`);
|
|
132
|
+
entries.push(`{ source: ${JSON.stringify(src)}, keys: ${JSON.stringify(keys)}, rank: ${rank}, mod: _${i} }`);
|
|
133
|
+
});
|
|
134
|
+
return `import { isApiPath, handleApi } from '@fluixi/start/api';
|
|
135
|
+
${imports.join("\n")}
|
|
136
|
+
const routes = [${entries.join(",")}];
|
|
137
|
+
export const isApiRequest = (request) => isApiPath(new URL(request.url).pathname, ${JSON.stringify(prefix)});
|
|
138
|
+
export const handleApiRequest = (request) => handleApi(routes, request, ${JSON.stringify(prefix)});
|
|
139
|
+
`;
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
var import_node_fs, import_node_path, API_VMOD, METHODS, API_VIRTUAL_MODULE;
|
|
144
|
+
var init_api = __esm({
|
|
145
|
+
"src/api.ts"() {
|
|
146
|
+
"use strict";
|
|
147
|
+
import_node_fs = require("node:fs");
|
|
148
|
+
import_node_path = require("node:path");
|
|
149
|
+
API_VMOD = "virtual:fluixi-api";
|
|
150
|
+
METHODS = ["GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS", "HEAD"];
|
|
151
|
+
API_VIRTUAL_MODULE = API_VMOD;
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
// src/internal.ts
|
|
156
|
+
var internal_exports = {};
|
|
157
|
+
__export(internal_exports, {
|
|
158
|
+
I18N_VMOD: () => I18N_VMOD,
|
|
159
|
+
SERVER_FNS_VMOD: () => SERVER_FNS_VMOD,
|
|
160
|
+
fluixiPlugins: () => fluixiPlugins,
|
|
161
|
+
guardHandler: () => guardHandler,
|
|
162
|
+
i18nVitePlugin: () => i18nVitePlugin,
|
|
163
|
+
injectApp: () => injectApp,
|
|
164
|
+
injectAppAndHead: () => injectAppAndHead,
|
|
165
|
+
installCrashGuards: () => installCrashGuards,
|
|
166
|
+
loadServerEnv: () => loadServerEnv,
|
|
167
|
+
splitTemplate: () => splitTemplate,
|
|
168
|
+
startTypesPlugin: () => startTypesPlugin
|
|
169
|
+
});
|
|
170
|
+
module.exports = __toCommonJS(internal_exports);
|
|
171
|
+
var import_node_fs2 = require("node:fs");
|
|
172
|
+
var import_node_path2 = require("node:path");
|
|
173
|
+
|
|
174
|
+
// src/document.ts
|
|
175
|
+
var import_head = require("@fluixi/head");
|
|
176
|
+
function injectApp(template, appHtml, mountId = "root") {
|
|
177
|
+
const mount = new RegExp(`<div id=["']${mountId}["']\\s*>\\s*</div>`);
|
|
178
|
+
if (mount.test(template)) {
|
|
179
|
+
return template.replace(mount, `<div id="${mountId}">${appHtml}</div>`);
|
|
180
|
+
}
|
|
181
|
+
if (template.includes("<!--ssr-outlet-->")) {
|
|
182
|
+
return template.replace("<!--ssr-outlet-->", appHtml);
|
|
183
|
+
}
|
|
184
|
+
return template.replace("</body>", `<div id="${mountId}">${appHtml}</div></body>`);
|
|
185
|
+
}
|
|
186
|
+
function splitTemplate(template, mountId = "root") {
|
|
187
|
+
const mount = new RegExp(`<div id=["']${mountId}["']\\s*>\\s*</div>`);
|
|
188
|
+
const m = template.match(mount);
|
|
189
|
+
if (m && m.index !== void 0) {
|
|
190
|
+
return {
|
|
191
|
+
head: template.slice(0, m.index) + `<div id="${mountId}">`,
|
|
192
|
+
tail: `</div>` + template.slice(m.index + m[0].length)
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
const outlet = template.indexOf("<!--ssr-outlet-->");
|
|
196
|
+
if (outlet !== -1) {
|
|
197
|
+
return {
|
|
198
|
+
head: template.slice(0, outlet),
|
|
199
|
+
tail: template.slice(outlet + "<!--ssr-outlet-->".length)
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
const body = template.indexOf("</body>");
|
|
203
|
+
if (body !== -1) {
|
|
204
|
+
return {
|
|
205
|
+
head: template.slice(0, body) + `<div id="${mountId}">`,
|
|
206
|
+
tail: `</div>` + template.slice(body)
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
return { head: template, tail: "" };
|
|
210
|
+
}
|
|
211
|
+
function setHtmlAttr(html, name, value) {
|
|
212
|
+
const existing = new RegExp(`(<html\\b[^>]*?)\\s${name}="[^"]*"`, "i");
|
|
213
|
+
if (existing.test(html)) return html.replace(existing, `$1 ${name}="${value}"`);
|
|
214
|
+
return html.replace(/<html\b/i, `<html ${name}="${value}"`);
|
|
215
|
+
}
|
|
216
|
+
function injectAppAndHead(template, rendered, mountId = "root") {
|
|
217
|
+
const { head, body } = (0, import_head.extractHeadMarker)(rendered);
|
|
218
|
+
let html = injectApp(template, body, mountId);
|
|
219
|
+
if (head) {
|
|
220
|
+
if (head.headHtml) {
|
|
221
|
+
if (/<title[\s>]/i.test(head.headHtml)) html = html.replace(/<title>[\s\S]*?<\/title>/i, "");
|
|
222
|
+
html = html.replace("</head>", `${head.headHtml}</head>`);
|
|
223
|
+
}
|
|
224
|
+
for (const [k, v] of Object.entries(head.htmlAttrs)) html = setHtmlAttr(html, k, v);
|
|
225
|
+
}
|
|
226
|
+
return html;
|
|
227
|
+
}
|
|
228
|
+
function guardHandler(handler, onError) {
|
|
229
|
+
return async (request) => {
|
|
230
|
+
try {
|
|
231
|
+
return await handler(request);
|
|
232
|
+
} catch (e) {
|
|
233
|
+
onError?.(e);
|
|
234
|
+
return new Response(String(e?.stack || e), {
|
|
235
|
+
status: 500,
|
|
236
|
+
headers: { "content-type": "text/plain; charset=utf-8" }
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
// src/internal.ts
|
|
243
|
+
var SERVER_FNS_VMOD = "virtual:fluixi-server-fns";
|
|
244
|
+
var I18N_VMOD = "virtual:fluixi-i18n";
|
|
245
|
+
function i18nVitePlugin(opts) {
|
|
246
|
+
let root = process.cwd();
|
|
247
|
+
const id = "\0" + I18N_VMOD;
|
|
248
|
+
return {
|
|
249
|
+
name: "fluixi-i18n",
|
|
250
|
+
configResolved(config) {
|
|
251
|
+
root = config.root || root;
|
|
252
|
+
},
|
|
253
|
+
resolveId(source) {
|
|
254
|
+
return source === I18N_VMOD ? id : null;
|
|
255
|
+
},
|
|
256
|
+
load(source) {
|
|
257
|
+
if (source !== id) return null;
|
|
258
|
+
const dir = (0, import_node_path2.resolve)(root, opts.dir);
|
|
259
|
+
let files = [];
|
|
260
|
+
try {
|
|
261
|
+
files = (0, import_node_fs2.readdirSync)(dir).filter((f) => f.endsWith(".json"));
|
|
262
|
+
} catch {
|
|
263
|
+
}
|
|
264
|
+
const discovered = files.map((f) => f.replace(/\.json$/, "")).sort();
|
|
265
|
+
const locales = opts.locales?.length ? opts.locales : discovered;
|
|
266
|
+
const defaultLocale = opts.defaultLocale ?? locales[0] ?? "en";
|
|
267
|
+
const imports = locales.map((l, i) => `import _${i} from ${JSON.stringify((0, import_node_path2.resolve)(dir, l + ".json"))};`).join("\n");
|
|
268
|
+
const messages = `export const messages = {${locales.map((l, i) => `${JSON.stringify(l)}:_${i}`).join(",")}};`;
|
|
269
|
+
return `${imports}
|
|
270
|
+
export const locales = ${JSON.stringify(locales)};
|
|
271
|
+
export const defaultLocale = ${JSON.stringify(defaultLocale)};
|
|
272
|
+
${messages}
|
|
273
|
+
`;
|
|
274
|
+
}
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
async function loadServerEnv(root, mode) {
|
|
278
|
+
const { loadEnv } = await import("vite");
|
|
279
|
+
const env = loadEnv(mode, root, "");
|
|
280
|
+
for (const [k, v] of Object.entries(env)) {
|
|
281
|
+
if (process.env[k] === void 0) process.env[k] = v;
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
function i18nTypeBlock(root, i18n) {
|
|
285
|
+
const dir = (0, import_node_path2.resolve)(root, i18n.dir);
|
|
286
|
+
let discovered = [];
|
|
287
|
+
try {
|
|
288
|
+
discovered = (0, import_node_fs2.readdirSync)(dir).filter((f) => f.endsWith(".json")).map((f) => f.replace(/\.json$/, "")).sort();
|
|
289
|
+
} catch {
|
|
290
|
+
}
|
|
291
|
+
const locales = i18n.locales?.length ? i18n.locales : discovered;
|
|
292
|
+
const defaultLocale = i18n.defaultLocale ?? locales[0] ?? "en";
|
|
293
|
+
const typed = locales.length > 0 && locales.every((l) => discovered.includes(l));
|
|
294
|
+
if (!typed) {
|
|
295
|
+
return [
|
|
296
|
+
`declare module 'virtual:fluixi-i18n' {`,
|
|
297
|
+
` export const messages: Record<string, Record<string, unknown>>;`,
|
|
298
|
+
` export const locales: string[];`,
|
|
299
|
+
` export const defaultLocale: string;`,
|
|
300
|
+
`}`
|
|
301
|
+
];
|
|
302
|
+
}
|
|
303
|
+
const srcDir = (0, import_node_path2.resolve)(root, "src");
|
|
304
|
+
const toSpec = (l) => {
|
|
305
|
+
const rel = (0, import_node_path2.relative)(srcDir, (0, import_node_path2.resolve)(dir, l + ".json")).split(/[\\/]/).join("/");
|
|
306
|
+
return rel.startsWith(".") ? rel : "./" + rel;
|
|
307
|
+
};
|
|
308
|
+
const entries = locales.map((l) => ` ${JSON.stringify(l)}: (typeof import(${JSON.stringify(toSpec(l))}))['default'];`);
|
|
309
|
+
const tuple = locales.map((l) => JSON.stringify(l)).join(", ");
|
|
310
|
+
return [
|
|
311
|
+
`declare module 'virtual:fluixi-i18n' {`,
|
|
312
|
+
` export const messages: {`,
|
|
313
|
+
...entries,
|
|
314
|
+
` };`,
|
|
315
|
+
` export const locales: readonly [${tuple}];`,
|
|
316
|
+
` export const defaultLocale: ${JSON.stringify(defaultLocale)};`,
|
|
317
|
+
`}`
|
|
318
|
+
];
|
|
319
|
+
}
|
|
320
|
+
function startTypesPlugin(cfg) {
|
|
321
|
+
let root = process.cwd();
|
|
322
|
+
return {
|
|
323
|
+
name: "fluixi-start-types",
|
|
324
|
+
configResolved(config) {
|
|
325
|
+
root = config.root || root;
|
|
326
|
+
},
|
|
327
|
+
buildStart() {
|
|
328
|
+
const blocks = [];
|
|
329
|
+
if (cfg.i18n) blocks.push(...i18nTypeBlock(root, cfg.i18n));
|
|
330
|
+
if (blocks.length === 0) return;
|
|
331
|
+
const content = `// Auto-generated by @fluixi/start — do not edit.
|
|
332
|
+
${blocks.join("\n")}
|
|
333
|
+
`;
|
|
334
|
+
const file = (0, import_node_path2.resolve)(root, "src/fluixi-start-env.d.ts");
|
|
335
|
+
try {
|
|
336
|
+
if (!(0, import_node_fs2.existsSync)(file) || (0, import_node_fs2.readFileSync)(file, "utf8") !== content) (0, import_node_fs2.writeFileSync)(file, content);
|
|
337
|
+
} catch {
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
};
|
|
341
|
+
}
|
|
342
|
+
async function fluixiPlugins(cfg) {
|
|
343
|
+
const { fluixi, fluixiRoutesPlugin } = await import("@fluixi/core/plugins");
|
|
344
|
+
const { serverFunctionsVitePlugin } = await import("@fluixi/compiler/integrations");
|
|
345
|
+
const plugins = [
|
|
346
|
+
serverFunctionsVitePlugin(),
|
|
347
|
+
fluixiRoutesPlugin({ routesDir: cfg.routesDir, polyfills: false }),
|
|
348
|
+
// The app's component-resolution rules reach the compiler here; without this an SSR
|
|
349
|
+
// app has no way to say where an unimported tag comes from.
|
|
350
|
+
//
|
|
351
|
+
// `fluixi()` and not `createVitePlugin()`: the latter is the bare compiler integration,
|
|
352
|
+
// and the reactive graph — agent, source marks, /__fluixi/graph — is composed on top of
|
|
353
|
+
// it by the former. A start app got no graph at all until this changed.
|
|
354
|
+
fluixi({ resolve: cfg.resolve })
|
|
355
|
+
];
|
|
356
|
+
if (cfg.i18n) plugins.push(i18nVitePlugin(cfg.i18n));
|
|
357
|
+
const { apiRoutesVitePlugin: apiRoutesVitePlugin2 } = await Promise.resolve().then(() => (init_api(), api_exports));
|
|
358
|
+
plugins.push(apiRoutesVitePlugin2({ dir: cfg.apiDir }));
|
|
359
|
+
plugins.push(startTypesPlugin(cfg));
|
|
360
|
+
return plugins;
|
|
361
|
+
}
|
|
362
|
+
var _guardsInstalled = false;
|
|
363
|
+
function installCrashGuards() {
|
|
364
|
+
if (_guardsInstalled) return;
|
|
365
|
+
_guardsInstalled = true;
|
|
366
|
+
process.on(
|
|
367
|
+
"unhandledRejection",
|
|
368
|
+
(reason) => console.warn("[fluixi] unhandled rejection (backend likely down) —", reason?.message || reason)
|
|
369
|
+
);
|
|
370
|
+
process.on(
|
|
371
|
+
"uncaughtException",
|
|
372
|
+
(err) => console.warn("[fluixi] uncaught exception —", err?.message || err)
|
|
373
|
+
);
|
|
374
|
+
}
|
|
375
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
376
|
+
0 && (module.exports = {
|
|
377
|
+
I18N_VMOD,
|
|
378
|
+
SERVER_FNS_VMOD,
|
|
379
|
+
fluixiPlugins,
|
|
380
|
+
guardHandler,
|
|
381
|
+
i18nVitePlugin,
|
|
382
|
+
injectApp,
|
|
383
|
+
injectAppAndHead,
|
|
384
|
+
installCrashGuards,
|
|
385
|
+
loadServerEnv,
|
|
386
|
+
splitTemplate,
|
|
387
|
+
startTypesPlugin
|
|
388
|
+
});
|