resuxjs 0.3.7 → 0.3.9
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/README.md +251 -251
- package/dist/cli.js +308 -295
- package/dist/cli.js.map +1 -1
- package/dist/compiler/implementation.js +266 -162
- package/dist/compiler/index.js.map +1 -1
- package/dist/core/module-container.d.ts +4 -0
- package/dist/core/module-container.js +35 -8
- package/dist/core/module-container.js.map +1 -1
- package/dist/create.js +446 -446
- package/dist/deploy/framework-runtime.d.ts +1 -0
- package/dist/deploy/framework-runtime.js +56 -0
- package/dist/deploy/framework-runtime.js.map +1 -0
- package/dist/deploy/netlify.js +7 -0
- package/dist/deploy/netlify.js.map +1 -1
- package/dist/deploy/production-report.d.ts +1 -0
- package/dist/deploy/production-report.js +19 -0
- package/dist/deploy/production-report.js.map +1 -0
- package/dist/deploy/runtime-dependencies.d.ts +4 -0
- package/dist/deploy/runtime-dependencies.js +250 -0
- package/dist/deploy/runtime-dependencies.js.map +1 -0
- package/dist/deploy/vercel.js +7 -125
- package/dist/deploy/vercel.js.map +1 -1
- package/dist/halal-core/ai/classifyRuntimeContent.js +20 -20
- package/dist/halal-core/report/generateHalalReport.js +17 -17
- package/dist/i18n/index.js +45 -6
- package/dist/i18n/index.js.map +1 -1
- package/dist/i18n/shared.js +11 -1
- package/dist/i18n/shared.js.map +1 -1
- package/dist/icons/index.d.ts +4 -4
- package/dist/runtime/index.d.ts +2 -0
- package/dist/runtime/index.js +9307 -8941
- package/dist/runtime/index.js.map +1 -1
- package/dist/ui/index.d.ts +15 -15
- package/dist/ui/index.js +254 -250
- package/dist/ui/index.js.map +1 -1
- package/package.json +150 -150
- package/templates/default/README.md +18 -18
- package/templates/default/pages/index.vue +102 -102
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
1
2
|
import { mkdir, readFile, readdir, rm, stat, writeFile } from "node:fs/promises";
|
|
2
3
|
import { existsSync, statSync, writeFileSync, mkdirSync } from "node:fs";
|
|
3
4
|
import { createRequire } from "node:module";
|
|
@@ -355,6 +356,17 @@ export async function buildProject(appRoot, outDir = path.join(appRoot, ".resux"
|
|
|
355
356
|
]);
|
|
356
357
|
const packageDiagnostics = await analyzePackageUsage(absoluteRoot, packageSources, runtimeConfig);
|
|
357
358
|
const packageRegistry = createClientRuntimePackageRegistry(absoluteRoot, readConfiguredPackages(runtimeConfig), packageDiagnostics);
|
|
359
|
+
const buildCompatibilityId = createBuildCompatibilityId({
|
|
360
|
+
runtimeConfig,
|
|
361
|
+
routes,
|
|
362
|
+
components,
|
|
363
|
+
plugins,
|
|
364
|
+
middleware,
|
|
365
|
+
serverMiddleware,
|
|
366
|
+
serverHandlers,
|
|
367
|
+
packages: packageDiagnostics,
|
|
368
|
+
});
|
|
369
|
+
injectRuntimeBuildCompatibilityId(runtimeConfig, buildCompatibilityId);
|
|
358
370
|
if (buildOptions.vite === "dev") {
|
|
359
371
|
await writeViteClientRuntime(absoluteOut, packageRegistry);
|
|
360
372
|
await hooks.callHook("vite:compiled", { outDir: absoluteOut, dev: true });
|
|
@@ -423,6 +435,51 @@ export async function buildProject(appRoot, outDir = path.join(appRoot, ".resux"
|
|
|
423
435
|
throw error;
|
|
424
436
|
}
|
|
425
437
|
}
|
|
438
|
+
function createBuildCompatibilityId(input) {
|
|
439
|
+
const hash = createHash("sha256");
|
|
440
|
+
hash.update("resux-build-compatibility-v1\0");
|
|
441
|
+
hash.update(getClientRuntimeSource());
|
|
442
|
+
hash.update(JSON.stringify(input.runtimeConfig));
|
|
443
|
+
hash.update(JSON.stringify(input.routes.map(({ id, path: routePath, params, componentId, meta }) => ({ id, path: routePath, params, componentId, meta }))));
|
|
444
|
+
for (const component of input.components) {
|
|
445
|
+
hash.update(component.id);
|
|
446
|
+
hash.update(component.serverSource);
|
|
447
|
+
hash.update(component.clientSource);
|
|
448
|
+
}
|
|
449
|
+
for (const plugin of input.plugins) {
|
|
450
|
+
hash.update(plugin.id);
|
|
451
|
+
hash.update(plugin.serverSource);
|
|
452
|
+
hash.update(plugin.clientSource);
|
|
453
|
+
}
|
|
454
|
+
for (const entry of input.middleware) {
|
|
455
|
+
hash.update(entry.id);
|
|
456
|
+
hash.update(entry.serverSource);
|
|
457
|
+
hash.update(entry.clientSource);
|
|
458
|
+
}
|
|
459
|
+
for (const entry of input.serverMiddleware) {
|
|
460
|
+
hash.update(entry.id);
|
|
461
|
+
hash.update(entry.source);
|
|
462
|
+
}
|
|
463
|
+
for (const entry of input.serverHandlers) {
|
|
464
|
+
hash.update(entry.id);
|
|
465
|
+
hash.update(entry.source);
|
|
466
|
+
}
|
|
467
|
+
hash.update(JSON.stringify(input.packages));
|
|
468
|
+
return hash.digest("hex").slice(0, 24);
|
|
469
|
+
}
|
|
470
|
+
function injectRuntimeBuildCompatibilityId(runtimeConfig, buildId) {
|
|
471
|
+
const configuredRuntime = isPlainObject(runtimeConfig.runtimeConfig)
|
|
472
|
+
? runtimeConfig.runtimeConfig
|
|
473
|
+
: {};
|
|
474
|
+
const publicConfig = isPlainObject(configuredRuntime.public)
|
|
475
|
+
? configuredRuntime.public
|
|
476
|
+
: {};
|
|
477
|
+
configuredRuntime.public = {
|
|
478
|
+
...publicConfig,
|
|
479
|
+
__resuxBuildId: buildId,
|
|
480
|
+
};
|
|
481
|
+
runtimeConfig.runtimeConfig = configuredRuntime;
|
|
482
|
+
}
|
|
426
483
|
async function cleanGeneratedOutput(outDir) {
|
|
427
484
|
const directoryRmOptions = {
|
|
428
485
|
recursive: true,
|
|
@@ -1021,13 +1078,19 @@ function compileTemplateNode(node, state, options = {}) {
|
|
|
1021
1078
|
throw new ResuxCompileError("Events need an argument and expression.", locationFromVueNode(state.file, prop));
|
|
1022
1079
|
}
|
|
1023
1080
|
const isSimpleIdentifier = /^[A-Za-z_$][\w$]*$/.test(expression);
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1081
|
+
if (isSimpleIdentifier && state.activeLocals.includes(expression)) {
|
|
1082
|
+
throw new ResuxCompileError(`Direct template-local event handler "${expression}" cannot be resumed because template locals are serialized by value. Call a top-level handler with serializable local data instead.`, locationFromVueNode(state.file, prop));
|
|
1083
|
+
}
|
|
1084
|
+
const usesInlineHandler = !isSimpleIdentifier;
|
|
1085
|
+
const inlineHandler = usesInlineHandler
|
|
1086
|
+
? createInlineEventHandler(expression, state, prop)
|
|
1087
|
+
: null;
|
|
1088
|
+
const handler = inlineHandler?.name ?? expression;
|
|
1027
1089
|
const event = {
|
|
1028
1090
|
name: arg,
|
|
1029
1091
|
handler,
|
|
1030
|
-
modifiers
|
|
1092
|
+
modifiers,
|
|
1093
|
+
...(inlineHandler?.locals.length ? { locals: inlineHandler.locals } : {})
|
|
1031
1094
|
};
|
|
1032
1095
|
events.push(event);
|
|
1033
1096
|
state.handlers.push(event);
|
|
@@ -1107,7 +1170,11 @@ function compileTemplateNode(node, state, options = {}) {
|
|
|
1107
1170
|
if (!isAssignableExpression(expression)) {
|
|
1108
1171
|
throw new ResuxCompileError("v-model needs an assignable expression like \"message.value\".", locationFromVueNode(state.file, prop));
|
|
1109
1172
|
}
|
|
1110
|
-
const
|
|
1173
|
+
const assignmentRoot = assignableExpressionRoot(expression);
|
|
1174
|
+
if (assignmentRoot && state.activeLocals.includes(assignmentRoot)) {
|
|
1175
|
+
throw new ResuxCompileError(`v-model cannot assign through template-local binding "${assignmentRoot}" because resumed event locals are serialized by value. Bind v-model to resumable component state instead.`, locationFromVueNode(state.file, prop));
|
|
1176
|
+
}
|
|
1177
|
+
const model = createModelBinding(node.tag, node.props, expression, state, prop);
|
|
1111
1178
|
attrs.push({
|
|
1112
1179
|
kind: "dynamic",
|
|
1113
1180
|
name: model.attribute,
|
|
@@ -1117,7 +1184,8 @@ function compileTemplateNode(node, state, options = {}) {
|
|
|
1117
1184
|
const event = {
|
|
1118
1185
|
name: model.event,
|
|
1119
1186
|
handler: model.handler,
|
|
1120
|
-
modifiers: []
|
|
1187
|
+
modifiers: [],
|
|
1188
|
+
...(model.locals.length > 0 ? { locals: model.locals } : {})
|
|
1121
1189
|
};
|
|
1122
1190
|
events.push(event);
|
|
1123
1191
|
state.handlers.push(event);
|
|
@@ -1144,8 +1212,9 @@ function compileTemplateNode(node, state, options = {}) {
|
|
|
1144
1212
|
continue;
|
|
1145
1213
|
}
|
|
1146
1214
|
if (options.ifExpressionOverride) {
|
|
1215
|
+
const conditionalExpression = transformTemplateExpressionCode(options.ifExpressionOverride, state.templateRefBindings, state.file, node);
|
|
1147
1216
|
element.if = {
|
|
1148
|
-
expression: registerRawTemplateExpression(
|
|
1217
|
+
expression: registerRawTemplateExpression(conditionalExpression.transformed, options.ifExpressionOverride, conditionalExpression.identifiers, state),
|
|
1149
1218
|
blockId: nextBindingId(state),
|
|
1150
1219
|
};
|
|
1151
1220
|
}
|
|
@@ -1154,17 +1223,34 @@ function compileTemplateNode(node, state, options = {}) {
|
|
|
1154
1223
|
}
|
|
1155
1224
|
return element;
|
|
1156
1225
|
}
|
|
1226
|
+
function selectReferencedActiveLocals(activeLocals, identifiers) {
|
|
1227
|
+
const referenced = new Set(identifiers);
|
|
1228
|
+
const seen = new Set();
|
|
1229
|
+
const selected = [];
|
|
1230
|
+
for (let index = activeLocals.length - 1; index >= 0; index -= 1) {
|
|
1231
|
+
const local = activeLocals[index];
|
|
1232
|
+
if (!referenced.has(local) || seen.has(local))
|
|
1233
|
+
continue;
|
|
1234
|
+
seen.add(local);
|
|
1235
|
+
selected.unshift(local);
|
|
1236
|
+
}
|
|
1237
|
+
return selected;
|
|
1238
|
+
}
|
|
1157
1239
|
function createInlineEventHandler(expression, state, node) {
|
|
1158
1240
|
const name = nextInlineHandlerName(state);
|
|
1159
|
-
const transformed = transformTemplateExpressionCode(expression, state.templateRefBindings, state.file, node ?? {})
|
|
1241
|
+
const transformed = transformTemplateExpressionCode(expression, state.templateRefBindings, state.file, node ?? {});
|
|
1242
|
+
const capturedLocals = selectReferencedActiveLocals(state.activeLocals, transformed.identifiers);
|
|
1243
|
+
const localBindings = capturedLocals
|
|
1244
|
+
.map((local) => `const ${local} = __rx_event_locals[${JSON.stringify(local)}];`)
|
|
1245
|
+
.join("\n");
|
|
1160
1246
|
state.inlineHandlers.push({
|
|
1161
1247
|
name,
|
|
1162
|
-
source: `function ${name}($event) {\n${transformed}\n}`,
|
|
1163
|
-
locals:
|
|
1248
|
+
source: `function ${name}($event, __rx_event_locals = {}) {\n${localBindings}${localBindings ? "\n" : ""}${transformed.transformed}\n}`,
|
|
1249
|
+
locals: capturedLocals
|
|
1164
1250
|
});
|
|
1165
|
-
return name;
|
|
1251
|
+
return { name, locals: capturedLocals };
|
|
1166
1252
|
}
|
|
1167
|
-
function createModelBinding(tag, props, expression, state) {
|
|
1253
|
+
function createModelBinding(tag, props, expression, state, node) {
|
|
1168
1254
|
const normalizedTag = tag.toLowerCase();
|
|
1169
1255
|
const inputType = normalizedTag === "input" ? staticAttributeValue(props, "type")?.toLowerCase() : undefined;
|
|
1170
1256
|
const isCheckbox = inputType === "checkbox";
|
|
@@ -1174,16 +1260,22 @@ function createModelBinding(tag, props, expression, state) {
|
|
|
1174
1260
|
const assignment = isCheckbox
|
|
1175
1261
|
? `${assignmentExpression} = Boolean(${target} && ${target}.checked)`
|
|
1176
1262
|
: `${assignmentExpression} = ${target} ? ${target}.value : ""`;
|
|
1263
|
+
const identifiers = transformTemplateExpressionCode(expression, state.templateRefBindings, state.file, node ?? {}).identifiers;
|
|
1264
|
+
const capturedLocals = selectReferencedActiveLocals(state.activeLocals, identifiers);
|
|
1265
|
+
const localBindings = capturedLocals
|
|
1266
|
+
.map((local) => `const ${local} = __rx_event_locals[${JSON.stringify(local)}];`)
|
|
1267
|
+
.join("\n");
|
|
1177
1268
|
state.inlineHandlers.push({
|
|
1178
1269
|
name: handler,
|
|
1179
|
-
source: `function ${handler}($event) {\n${assignment}\n}`,
|
|
1180
|
-
locals:
|
|
1270
|
+
source: `function ${handler}($event, __rx_event_locals = {}) {\n${localBindings}${localBindings ? "\n" : ""}${assignment}\n}`,
|
|
1271
|
+
locals: capturedLocals
|
|
1181
1272
|
});
|
|
1182
1273
|
return {
|
|
1183
1274
|
attribute: isCheckbox ? "checked" : "value",
|
|
1184
1275
|
value: expression,
|
|
1185
1276
|
event: isCheckbox || normalizedTag === "select" ? "change" : "input",
|
|
1186
|
-
handler
|
|
1277
|
+
handler,
|
|
1278
|
+
locals: capturedLocals
|
|
1187
1279
|
};
|
|
1188
1280
|
}
|
|
1189
1281
|
function staticAttributeValue(props, name) {
|
|
@@ -1273,6 +1365,9 @@ function shouldAutoUnwrapTemplateIdentifier(node) {
|
|
|
1273
1365
|
function isAssignableExpression(expression) {
|
|
1274
1366
|
return /^[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*|\[[^\]]+\])*$/.test(expression.trim());
|
|
1275
1367
|
}
|
|
1368
|
+
function assignableExpressionRoot(expression) {
|
|
1369
|
+
return /^([A-Za-z_$][\w$]*)/.exec(expression.trim())?.[1];
|
|
1370
|
+
}
|
|
1276
1371
|
function normalizeEventModifiers(modifiers, file, node) {
|
|
1277
1372
|
const modifierNames = modifiers.map((modifier) => String(modifier.content));
|
|
1278
1373
|
const supported = new Set([
|
|
@@ -1815,7 +1910,7 @@ function inferTemplateRefBindings(script, file) {
|
|
|
1815
1910
|
const propertyName = element.propertyName && ts.isIdentifier(element.propertyName)
|
|
1816
1911
|
? element.propertyName.text
|
|
1817
1912
|
: element.name.text;
|
|
1818
|
-
if (calleeName
|
|
1913
|
+
if (isObjectTemplateRefBinding(calleeName, propertyName)) {
|
|
1819
1914
|
bindings.add(element.name.text);
|
|
1820
1915
|
}
|
|
1821
1916
|
}
|
|
@@ -1834,7 +1929,16 @@ function isAsyncDataFactory(name) {
|
|
|
1834
1929
|
return ["useAsyncData", "useFetch"].includes(name);
|
|
1835
1930
|
}
|
|
1836
1931
|
function isObjectTemplateRefFactory(name) {
|
|
1837
|
-
return isAsyncDataFactory(name) || name === "toRefs";
|
|
1932
|
+
return isAsyncDataFactory(name) || name === "toRefs" || name === "useI18n";
|
|
1933
|
+
}
|
|
1934
|
+
function isObjectTemplateRefBinding(factory, property) {
|
|
1935
|
+
if (factory === "toRefs") {
|
|
1936
|
+
return true;
|
|
1937
|
+
}
|
|
1938
|
+
if (factory === "useI18n") {
|
|
1939
|
+
return property === "locale" || property === "dir";
|
|
1940
|
+
}
|
|
1941
|
+
return ["data", "pending", "error", "value"].includes(property);
|
|
1838
1942
|
}
|
|
1839
1943
|
function isDefinePageMetaStatement(statement) {
|
|
1840
1944
|
return ts.isExpressionStatement(statement)
|
|
@@ -2035,33 +2139,33 @@ function createComponentModuleSource(options) {
|
|
|
2035
2139
|
const factory = options.client ? "createClientComponent" : "defineComponent";
|
|
2036
2140
|
const expressionClosures = (options.expressions ?? []).map((expr) => {
|
|
2037
2141
|
const destructure = expr.locals.length > 0
|
|
2038
|
-
? expr.locals.map(id => `let ${id} = (locals && "${id}" in locals) ? locals.${id} : (scope && "${id}" in scope) ? scope.${id} : (typeof globalThis !== "undefined" && "${id}" in globalThis) ? globalThis.${id} : undefined;
|
|
2039
|
-
if (typeof ${id} === "string" && ${id}.startsWith("__rx_callback:")) {
|
|
2040
|
-
const parts = ${id}.split(":");
|
|
2041
|
-
const cbScopeId = parts[2];
|
|
2042
|
-
const cbHandler = parts[3];
|
|
2043
|
-
${id} = async (...args) => {
|
|
2044
|
-
const payload = globalThis.__RESUX__;
|
|
2045
|
-
if (payload && payload.scopes[cbScopeId]) {
|
|
2046
|
-
const comp = await importComponent(payload.scopes[cbScopeId].moduleId, payload.modules, devImportRevision);
|
|
2047
|
-
let sRec = scopeCache.get(cbScopeId);
|
|
2048
|
-
if (!sRec) {
|
|
2049
|
-
sRec = await comp.createScope(payload.scopes[cbScopeId], payload.route);
|
|
2050
|
-
scopeCache.set(cbScopeId, sRec);
|
|
2051
|
-
}
|
|
2052
|
-
const patches = await comp.run(sRec, cbHandler, args[0]);
|
|
2053
|
-
const serialized = comp.serialize(sRec);
|
|
2054
|
-
payload.scopes[cbScopeId].props = serialized.props;
|
|
2055
|
-
payload.scopes[cbScopeId].state = serialized.state;
|
|
2056
|
-
payload.scopes[cbScopeId].asyncData = serialized.asyncData;
|
|
2057
|
-
applyPatches(cbScopeId, patches);
|
|
2058
|
-
}
|
|
2059
|
-
};
|
|
2142
|
+
? expr.locals.map(id => `let ${id} = (locals && "${id}" in locals) ? locals.${id} : (scope && "${id}" in scope) ? scope.${id} : (typeof globalThis !== "undefined" && "${id}" in globalThis) ? globalThis.${id} : undefined;
|
|
2143
|
+
if (typeof ${id} === "string" && ${id}.startsWith("__rx_callback:")) {
|
|
2144
|
+
const parts = ${id}.split(":");
|
|
2145
|
+
const cbScopeId = parts[2];
|
|
2146
|
+
const cbHandler = parts[3];
|
|
2147
|
+
${id} = async (...args) => {
|
|
2148
|
+
const payload = globalThis.__RESUX__;
|
|
2149
|
+
if (payload && payload.scopes[cbScopeId]) {
|
|
2150
|
+
const comp = await importComponent(payload.scopes[cbScopeId].moduleId, payload.modules, devImportRevision);
|
|
2151
|
+
let sRec = scopeCache.get(cbScopeId);
|
|
2152
|
+
if (!sRec) {
|
|
2153
|
+
sRec = await comp.createScope(payload.scopes[cbScopeId], payload.route);
|
|
2154
|
+
scopeCache.set(cbScopeId, sRec);
|
|
2155
|
+
}
|
|
2156
|
+
const patches = await comp.run(sRec, cbHandler, args[0]);
|
|
2157
|
+
const serialized = comp.serialize(sRec);
|
|
2158
|
+
payload.scopes[cbScopeId].props = serialized.props;
|
|
2159
|
+
payload.scopes[cbScopeId].state = serialized.state;
|
|
2160
|
+
payload.scopes[cbScopeId].asyncData = serialized.asyncData;
|
|
2161
|
+
applyPatches(cbScopeId, patches);
|
|
2162
|
+
}
|
|
2163
|
+
};
|
|
2060
2164
|
}`).join("\n ")
|
|
2061
2165
|
: "";
|
|
2062
|
-
return ` ${JSON.stringify(expr.id)}: function(scope, locals) {
|
|
2063
|
-
${destructure}
|
|
2064
|
-
return (${expr.transformed});
|
|
2166
|
+
return ` ${JSON.stringify(expr.id)}: function(scope, locals) {
|
|
2167
|
+
${destructure}
|
|
2168
|
+
return (${expr.transformed});
|
|
2065
2169
|
},`;
|
|
2066
2170
|
}).join("\n");
|
|
2067
2171
|
const importsText = (options.analysis.importDeclarations ?? []).map((decl) => {
|
|
@@ -2139,48 +2243,48 @@ function createServerManifestSource(routes, components, layouts, plugins, middle
|
|
|
2139
2243
|
.map((plugin) => plugin.id)
|
|
2140
2244
|
.join(",\n");
|
|
2141
2245
|
const clientPluginEntries = clientPlugins
|
|
2142
|
-
.map((plugin) => `{
|
|
2143
|
-
id: ${JSON.stringify(plugin.id)},
|
|
2144
|
-
file: ${JSON.stringify(normalizePath(plugin.file))},
|
|
2145
|
-
mode: ${JSON.stringify(plugin.mode)},
|
|
2146
|
-
src: ${JSON.stringify(`/__resux/plugins/${plugin.id}.mjs`)}
|
|
2246
|
+
.map((plugin) => `{
|
|
2247
|
+
id: ${JSON.stringify(plugin.id)},
|
|
2248
|
+
file: ${JSON.stringify(normalizePath(plugin.file))},
|
|
2249
|
+
mode: ${JSON.stringify(plugin.mode)},
|
|
2250
|
+
src: ${JSON.stringify(`/__resux/plugins/${plugin.id}.mjs`)}
|
|
2147
2251
|
}`)
|
|
2148
2252
|
.join(",\n");
|
|
2149
2253
|
const middlewareEntries = serverRouteMiddleware
|
|
2150
|
-
.map((entry) => `{
|
|
2151
|
-
id: ${JSON.stringify(entry.id)},
|
|
2152
|
-
name: ${JSON.stringify(entry.name)},
|
|
2153
|
-
file: ${JSON.stringify(normalizePath(entry.file))},
|
|
2154
|
-
global: ${JSON.stringify(entry.global)},
|
|
2155
|
-
mode: ${JSON.stringify(entry.mode)},
|
|
2156
|
-
handler: ${entry.id}
|
|
2254
|
+
.map((entry) => `{
|
|
2255
|
+
id: ${JSON.stringify(entry.id)},
|
|
2256
|
+
name: ${JSON.stringify(entry.name)},
|
|
2257
|
+
file: ${JSON.stringify(normalizePath(entry.file))},
|
|
2258
|
+
global: ${JSON.stringify(entry.global)},
|
|
2259
|
+
mode: ${JSON.stringify(entry.mode)},
|
|
2260
|
+
handler: ${entry.id}
|
|
2157
2261
|
}`)
|
|
2158
2262
|
.join(",\n");
|
|
2159
2263
|
const clientMiddlewareEntries = clientRouteMiddleware
|
|
2160
|
-
.map((entry) => `{
|
|
2161
|
-
id: ${JSON.stringify(entry.id)},
|
|
2162
|
-
name: ${JSON.stringify(entry.name)},
|
|
2163
|
-
file: ${JSON.stringify(normalizePath(entry.file))},
|
|
2164
|
-
global: ${JSON.stringify(entry.global)},
|
|
2165
|
-
mode: ${JSON.stringify(entry.mode)},
|
|
2166
|
-
src: ${JSON.stringify(`/__resux/middleware/${entry.id}.mjs`)}
|
|
2264
|
+
.map((entry) => `{
|
|
2265
|
+
id: ${JSON.stringify(entry.id)},
|
|
2266
|
+
name: ${JSON.stringify(entry.name)},
|
|
2267
|
+
file: ${JSON.stringify(normalizePath(entry.file))},
|
|
2268
|
+
global: ${JSON.stringify(entry.global)},
|
|
2269
|
+
mode: ${JSON.stringify(entry.mode)},
|
|
2270
|
+
src: ${JSON.stringify(`/__resux/middleware/${entry.id}.mjs`)}
|
|
2167
2271
|
}`)
|
|
2168
2272
|
.join(",\n");
|
|
2169
2273
|
const serverMiddlewareEntries = serverMiddleware
|
|
2170
|
-
.map((entry) => `{
|
|
2171
|
-
id: ${JSON.stringify(entry.id)},
|
|
2172
|
-
file: ${JSON.stringify(normalizePath(entry.file))},
|
|
2173
|
-
handler: ${entry.id}
|
|
2274
|
+
.map((entry) => `{
|
|
2275
|
+
id: ${JSON.stringify(entry.id)},
|
|
2276
|
+
file: ${JSON.stringify(normalizePath(entry.file))},
|
|
2277
|
+
handler: ${entry.id}
|
|
2174
2278
|
}`)
|
|
2175
2279
|
.join(",\n");
|
|
2176
2280
|
const serverHandlerEntries = serverHandlers
|
|
2177
|
-
.map((handler) => `{
|
|
2178
|
-
id: ${JSON.stringify(handler.id)},
|
|
2179
|
-
path: ${JSON.stringify(handler.path)},
|
|
2180
|
-
file: ${JSON.stringify(normalizePath(handler.file))},
|
|
2181
|
-
params: ${JSON.stringify(handler.params)},
|
|
2182
|
-
handler: ${handler.id},
|
|
2183
|
-
match: createMatcher(${JSON.stringify(handler.path)})
|
|
2281
|
+
.map((handler) => `{
|
|
2282
|
+
id: ${JSON.stringify(handler.id)},
|
|
2283
|
+
path: ${JSON.stringify(handler.path)},
|
|
2284
|
+
file: ${JSON.stringify(normalizePath(handler.file))},
|
|
2285
|
+
params: ${JSON.stringify(handler.params)},
|
|
2286
|
+
handler: ${handler.id},
|
|
2287
|
+
match: createMatcher(${JSON.stringify(handler.path)})
|
|
2184
2288
|
}`)
|
|
2185
2289
|
.join(",\n");
|
|
2186
2290
|
const routeEntries = routes
|
|
@@ -2189,102 +2293,102 @@ function createServerManifestSource(routes, components, layouts, plugins, middle
|
|
|
2189
2293
|
if (!component) {
|
|
2190
2294
|
throw new Error(`Missing compiled component for ${route.file}.`);
|
|
2191
2295
|
}
|
|
2192
|
-
return `{
|
|
2193
|
-
id: ${JSON.stringify(route.id)},
|
|
2194
|
-
path: ${JSON.stringify(route.path)},
|
|
2195
|
-
file: ${JSON.stringify(normalizePath(route.file))},
|
|
2196
|
-
params: ${JSON.stringify(route.params)},
|
|
2197
|
-
meta: ${JSON.stringify(route.meta ?? {})},
|
|
2198
|
-
component: ${route.componentId},
|
|
2199
|
-
match: createMatcher(${JSON.stringify(route.path)})
|
|
2296
|
+
return `{
|
|
2297
|
+
id: ${JSON.stringify(route.id)},
|
|
2298
|
+
path: ${JSON.stringify(route.path)},
|
|
2299
|
+
file: ${JSON.stringify(normalizePath(route.file))},
|
|
2300
|
+
params: ${JSON.stringify(route.params)},
|
|
2301
|
+
meta: ${JSON.stringify(route.meta ?? {})},
|
|
2302
|
+
component: ${route.componentId},
|
|
2303
|
+
match: createMatcher(${JSON.stringify(route.path)})
|
|
2200
2304
|
}`;
|
|
2201
2305
|
})
|
|
2202
2306
|
.join(",\n");
|
|
2203
2307
|
const appHead = createAppHead(runtimeConfig);
|
|
2204
2308
|
const appRuntimeConfig = createRuntimeConfig(runtimeConfig);
|
|
2205
2309
|
const routeRules = createRouteRules(runtimeConfig);
|
|
2206
|
-
return `${imports}
|
|
2207
|
-
${pluginImports}
|
|
2208
|
-
${middlewareImports}
|
|
2209
|
-
${serverMiddlewareImports}
|
|
2210
|
-
${handlerImports}
|
|
2211
|
-
export const app = ${app ? app.id : "undefined"};
|
|
2212
|
-
export const errorComponent = ${error ? error.id : "undefined"};
|
|
2213
|
-
export const components = {
|
|
2214
|
-
${componentEntries}
|
|
2215
|
-
};
|
|
2216
|
-
export const layouts = {
|
|
2217
|
-
${layoutEntries}
|
|
2218
|
-
};
|
|
2219
|
-
export const modules = {
|
|
2220
|
-
${moduleEntries}
|
|
2221
|
-
};
|
|
2222
|
-
export const vueIslands = {
|
|
2223
|
-
${vueIslandEntries}
|
|
2224
|
-
};
|
|
2225
|
-
export const resuxPlugins = [
|
|
2226
|
-
${pluginEntries}
|
|
2227
|
-
];
|
|
2228
|
-
export const clientPlugins = [
|
|
2229
|
-
${clientPluginEntries}
|
|
2230
|
-
];
|
|
2231
|
-
export const middleware = [
|
|
2232
|
-
${middlewareEntries}
|
|
2233
|
-
];
|
|
2234
|
-
export const clientMiddleware = [
|
|
2235
|
-
${clientMiddlewareEntries}
|
|
2236
|
-
];
|
|
2237
|
-
export const serverMiddleware = [
|
|
2238
|
-
${serverMiddlewareEntries}
|
|
2239
|
-
];
|
|
2240
|
-
export const serverHandlers = [
|
|
2241
|
-
${serverHandlerEntries}
|
|
2242
|
-
];
|
|
2243
|
-
export const runtimeConfig = ${JSON.stringify(appRuntimeConfig, null, 2)};
|
|
2244
|
-
export const appHead = ${JSON.stringify(appHead, null, 2)};
|
|
2245
|
-
export const routeRules = ${JSON.stringify(routeRules, null, 2)};
|
|
2246
|
-
export const routes = [
|
|
2247
|
-
${routeEntries}
|
|
2248
|
-
];
|
|
2249
|
-
export function matchRoute(pathname) {
|
|
2250
|
-
for (const route of routes) {
|
|
2251
|
-
const params = route.match(pathname);
|
|
2252
|
-
if (params) return { route, params };
|
|
2253
|
-
}
|
|
2254
|
-
return null;
|
|
2255
|
-
}
|
|
2256
|
-
export function matchServerHandler(pathname) {
|
|
2257
|
-
for (const route of serverHandlers) {
|
|
2258
|
-
const params = route.match(pathname);
|
|
2259
|
-
if (params) return { route, params };
|
|
2260
|
-
}
|
|
2261
|
-
return null;
|
|
2262
|
-
}
|
|
2263
|
-
function createMatcher(pattern) {
|
|
2264
|
-
const names = [];
|
|
2265
|
-
const source = pattern === "/" ? "^/$" : "^" + pattern.split("/").map((part) => {
|
|
2266
|
-
if (!part) return "";
|
|
2267
|
-
if (part.startsWith(":") && part.endsWith("*")) {
|
|
2268
|
-
names.push(part.slice(1, -1));
|
|
2269
|
-
return "(?:/(.*))?";
|
|
2270
|
-
}
|
|
2271
|
-
if (part.startsWith(":")) {
|
|
2272
|
-
names.push(part.slice(1));
|
|
2273
|
-
return "/([^/]+)";
|
|
2274
|
-
}
|
|
2275
|
-
return "/" + part.replace(/[.*+?^${"${"}}()|[\\]\\\\]/g, "\\\\$&");
|
|
2276
|
-
}).join("") + "$";
|
|
2277
|
-
const regex = new RegExp(source);
|
|
2278
|
-
return (pathname) => {
|
|
2279
|
-
const match = regex.exec(pathname);
|
|
2280
|
-
if (!match) return null;
|
|
2281
|
-
const params = {};
|
|
2282
|
-
names.forEach((name, index) => {
|
|
2283
|
-
params[name] = decodeURIComponent(match[index + 1] ?? "");
|
|
2284
|
-
});
|
|
2285
|
-
return params;
|
|
2286
|
-
};
|
|
2287
|
-
}
|
|
2310
|
+
return `${imports}
|
|
2311
|
+
${pluginImports}
|
|
2312
|
+
${middlewareImports}
|
|
2313
|
+
${serverMiddlewareImports}
|
|
2314
|
+
${handlerImports}
|
|
2315
|
+
export const app = ${app ? app.id : "undefined"};
|
|
2316
|
+
export const errorComponent = ${error ? error.id : "undefined"};
|
|
2317
|
+
export const components = {
|
|
2318
|
+
${componentEntries}
|
|
2319
|
+
};
|
|
2320
|
+
export const layouts = {
|
|
2321
|
+
${layoutEntries}
|
|
2322
|
+
};
|
|
2323
|
+
export const modules = {
|
|
2324
|
+
${moduleEntries}
|
|
2325
|
+
};
|
|
2326
|
+
export const vueIslands = {
|
|
2327
|
+
${vueIslandEntries}
|
|
2328
|
+
};
|
|
2329
|
+
export const resuxPlugins = [
|
|
2330
|
+
${pluginEntries}
|
|
2331
|
+
];
|
|
2332
|
+
export const clientPlugins = [
|
|
2333
|
+
${clientPluginEntries}
|
|
2334
|
+
];
|
|
2335
|
+
export const middleware = [
|
|
2336
|
+
${middlewareEntries}
|
|
2337
|
+
];
|
|
2338
|
+
export const clientMiddleware = [
|
|
2339
|
+
${clientMiddlewareEntries}
|
|
2340
|
+
];
|
|
2341
|
+
export const serverMiddleware = [
|
|
2342
|
+
${serverMiddlewareEntries}
|
|
2343
|
+
];
|
|
2344
|
+
export const serverHandlers = [
|
|
2345
|
+
${serverHandlerEntries}
|
|
2346
|
+
];
|
|
2347
|
+
export const runtimeConfig = ${JSON.stringify(appRuntimeConfig, null, 2)};
|
|
2348
|
+
export const appHead = ${JSON.stringify(appHead, null, 2)};
|
|
2349
|
+
export const routeRules = ${JSON.stringify(routeRules, null, 2)};
|
|
2350
|
+
export const routes = [
|
|
2351
|
+
${routeEntries}
|
|
2352
|
+
];
|
|
2353
|
+
export function matchRoute(pathname) {
|
|
2354
|
+
for (const route of routes) {
|
|
2355
|
+
const params = route.match(pathname);
|
|
2356
|
+
if (params) return { route, params };
|
|
2357
|
+
}
|
|
2358
|
+
return null;
|
|
2359
|
+
}
|
|
2360
|
+
export function matchServerHandler(pathname) {
|
|
2361
|
+
for (const route of serverHandlers) {
|
|
2362
|
+
const params = route.match(pathname);
|
|
2363
|
+
if (params) return { route, params };
|
|
2364
|
+
}
|
|
2365
|
+
return null;
|
|
2366
|
+
}
|
|
2367
|
+
function createMatcher(pattern) {
|
|
2368
|
+
const names = [];
|
|
2369
|
+
const source = pattern === "/" ? "^/$" : "^" + pattern.split("/").map((part) => {
|
|
2370
|
+
if (!part) return "";
|
|
2371
|
+
if (part.startsWith(":") && part.endsWith("*")) {
|
|
2372
|
+
names.push(part.slice(1, -1));
|
|
2373
|
+
return "(?:/(.*))?";
|
|
2374
|
+
}
|
|
2375
|
+
if (part.startsWith(":")) {
|
|
2376
|
+
names.push(part.slice(1));
|
|
2377
|
+
return "/([^/]+)";
|
|
2378
|
+
}
|
|
2379
|
+
return "/" + part.replace(/[.*+?^${"${"}}()|[\\]\\\\]/g, "\\\\$&");
|
|
2380
|
+
}).join("") + "$";
|
|
2381
|
+
const regex = new RegExp(source);
|
|
2382
|
+
return (pathname) => {
|
|
2383
|
+
const match = regex.exec(pathname);
|
|
2384
|
+
if (!match) return null;
|
|
2385
|
+
const params = {};
|
|
2386
|
+
names.forEach((name, index) => {
|
|
2387
|
+
params[name] = decodeURIComponent(match[index + 1] ?? "");
|
|
2388
|
+
});
|
|
2389
|
+
return params;
|
|
2390
|
+
};
|
|
2391
|
+
}
|
|
2288
2392
|
`;
|
|
2289
2393
|
}
|
|
2290
2394
|
function createAppHead(runtimeConfig) {
|