mokup 2.2.0 → 2.2.3
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/bundle.cjs +11 -0
- package/dist/bundle.d.cts +27 -0
- package/dist/bundle.d.mts +27 -0
- package/dist/bundle.d.ts +27 -0
- package/dist/bundle.mjs +5 -0
- package/dist/index.d.cts +3 -2
- package/dist/index.d.mts +3 -2
- package/dist/index.d.ts +3 -2
- package/dist/shared/mokup.BXPIIxtS.cjs +47 -0
- package/dist/shared/{mokup.CYGG6ENd.cjs → mokup.Cn9uLpN8.cjs} +57 -350
- package/dist/shared/mokup.CsBTglhs.mjs +45 -0
- package/dist/shared/{mokup.ClsvLg8n.mjs → mokup.DJ2QlqTp.mjs} +29 -316
- package/dist/shared/{mokup.CWQ8woZc.d.cts → mokup.DeotZ0g8.d.cts} +69 -2
- package/dist/shared/{mokup.CWQ8woZc.d.mts → mokup.DeotZ0g8.d.mts} +69 -2
- package/dist/shared/{mokup.CWQ8woZc.d.ts → mokup.DeotZ0g8.d.ts} +69 -2
- package/dist/shared/mokup.Dy9VDphS.cjs +181 -0
- package/dist/shared/mokup.Iqw32OxC.mjs +174 -0
- package/dist/types/virtual.d.ts +2 -2
- package/dist/vite.cjs +15 -52
- package/dist/vite.d.cts +3 -2
- package/dist/vite.d.mts +3 -2
- package/dist/vite.d.ts +3 -2
- package/dist/vite.mjs +6 -43
- package/dist/webpack.cjs +10 -6
- package/dist/webpack.d.cts +3 -2
- package/dist/webpack.d.mts +3 -2
- package/dist/webpack.d.ts +3 -2
- package/dist/webpack.mjs +5 -1
- package/package.json +11 -6
|
@@ -3,43 +3,24 @@
|
|
|
3
3
|
const node_fs = require('node:fs');
|
|
4
4
|
const pathe = require('@mokup/shared/pathe');
|
|
5
5
|
const node_module = require('node:module');
|
|
6
|
-
const
|
|
6
|
+
const playgroundGrouping = require('@mokup/shared/playground-grouping');
|
|
7
|
+
const manifest = require('./mokup.Dy9VDphS.cjs');
|
|
7
8
|
const node_buffer = require('node:buffer');
|
|
8
9
|
const hono = require('@mokup/shared/hono');
|
|
10
|
+
const timing = require('@mokup/shared/timing');
|
|
11
|
+
const pathUtils = require('@mokup/shared/path-utils');
|
|
9
12
|
const node_url = require('node:url');
|
|
10
13
|
const esbuild = require('@mokup/shared/esbuild');
|
|
11
14
|
const jsoncParser = require('@mokup/shared/jsonc-parser');
|
|
12
15
|
const runtime = require('@mokup/runtime');
|
|
13
16
|
|
|
14
17
|
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
15
|
-
const methodSet = /* @__PURE__ */ new Set([
|
|
16
|
-
"GET",
|
|
17
|
-
"POST",
|
|
18
|
-
"PUT",
|
|
19
|
-
"PATCH",
|
|
20
|
-
"DELETE",
|
|
21
|
-
"OPTIONS",
|
|
22
|
-
"HEAD"
|
|
23
|
-
]);
|
|
24
|
-
const methodSuffixSet = new Set(
|
|
25
|
-
Array.from(methodSet, (method) => method.toLowerCase())
|
|
26
|
-
);
|
|
27
|
-
const supportedExtensions = /* @__PURE__ */ new Set([
|
|
28
|
-
".json",
|
|
29
|
-
".jsonc",
|
|
30
|
-
".ts",
|
|
31
|
-
".js",
|
|
32
|
-
".mjs",
|
|
33
|
-
".cjs"
|
|
34
|
-
]);
|
|
35
|
-
const configExtensions = [".ts", ".js", ".mjs", ".cjs"];
|
|
36
|
-
|
|
37
18
|
function normalizeMethod(method) {
|
|
38
19
|
if (!method) {
|
|
39
20
|
return void 0;
|
|
40
21
|
}
|
|
41
22
|
const normalized = method.toUpperCase();
|
|
42
|
-
if (methodSet.has(normalized)) {
|
|
23
|
+
if (manifest.methodSet.has(normalized)) {
|
|
43
24
|
return normalized;
|
|
44
25
|
}
|
|
45
26
|
return void 0;
|
|
@@ -59,194 +40,12 @@ function resolveDirs(dir, root) {
|
|
|
59
40
|
);
|
|
60
41
|
return Array.from(new Set(normalized));
|
|
61
42
|
}
|
|
62
|
-
function createDebouncer(delayMs, fn) {
|
|
63
|
-
let timer = null;
|
|
64
|
-
return () => {
|
|
65
|
-
if (timer) {
|
|
66
|
-
clearTimeout(timer);
|
|
67
|
-
}
|
|
68
|
-
timer = setTimeout(() => {
|
|
69
|
-
timer = null;
|
|
70
|
-
fn();
|
|
71
|
-
}, delayMs);
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
function toPosix(value) {
|
|
75
|
-
return value.replace(/\\/g, "/");
|
|
76
|
-
}
|
|
77
|
-
function isInDirs(file, dirs) {
|
|
78
|
-
const normalized = toPosix(file);
|
|
79
|
-
return dirs.some((dir) => {
|
|
80
|
-
const normalizedDir = toPosix(dir).replace(/\/$/, "");
|
|
81
|
-
return normalized === normalizedDir || normalized.startsWith(`${normalizedDir}/`);
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
43
|
function normalizeIgnorePrefix(value, fallback = ["."]) {
|
|
85
44
|
const list = typeof value === "undefined" ? fallback : Array.isArray(value) ? value : [value];
|
|
86
45
|
return list.filter((entry) => typeof entry === "string" && entry.length > 0);
|
|
87
46
|
}
|
|
88
|
-
function hasIgnoredPrefix(file, rootDir, prefixes) {
|
|
89
|
-
if (prefixes.length === 0) {
|
|
90
|
-
return false;
|
|
91
|
-
}
|
|
92
|
-
const relativePath = toPosix(pathe.relative(rootDir, file));
|
|
93
|
-
const segments = relativePath.split("/");
|
|
94
|
-
return segments.some(
|
|
95
|
-
(segment) => prefixes.some((prefix) => segment.startsWith(prefix))
|
|
96
|
-
);
|
|
97
|
-
}
|
|
98
|
-
function delay(ms) {
|
|
99
|
-
return new Promise((resolve2) => setTimeout(resolve2, ms));
|
|
100
|
-
}
|
|
101
47
|
|
|
102
|
-
|
|
103
|
-
const absolute = pathe.isAbsolute(file) ? file : pathe.resolve(root, file);
|
|
104
|
-
const rel = pathe.relative(root, absolute);
|
|
105
|
-
if (!rel.startsWith("..") && !pathe.isAbsolute(rel)) {
|
|
106
|
-
return `/${toPosix(rel)}`;
|
|
107
|
-
}
|
|
108
|
-
return `/@fs/${toPosix(absolute)}`;
|
|
109
|
-
}
|
|
110
|
-
function shouldModuleize(handler) {
|
|
111
|
-
if (typeof handler === "function") {
|
|
112
|
-
return true;
|
|
113
|
-
}
|
|
114
|
-
if (typeof Response !== "undefined" && handler instanceof Response) {
|
|
115
|
-
return true;
|
|
116
|
-
}
|
|
117
|
-
return false;
|
|
118
|
-
}
|
|
119
|
-
const BASE64_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
120
|
-
function getNodeBuffer() {
|
|
121
|
-
if (typeof globalThis === "undefined") {
|
|
122
|
-
return null;
|
|
123
|
-
}
|
|
124
|
-
const buffer = globalThis.Buffer;
|
|
125
|
-
return buffer ?? null;
|
|
126
|
-
}
|
|
127
|
-
function getBtoa() {
|
|
128
|
-
if (typeof globalThis === "undefined") {
|
|
129
|
-
return null;
|
|
130
|
-
}
|
|
131
|
-
const btoaFn = globalThis.btoa;
|
|
132
|
-
return typeof btoaFn === "function" ? btoaFn : null;
|
|
133
|
-
}
|
|
134
|
-
function encodeBase64(bytes) {
|
|
135
|
-
const buffer = getNodeBuffer();
|
|
136
|
-
if (buffer) {
|
|
137
|
-
return buffer.from(bytes).toString("base64");
|
|
138
|
-
}
|
|
139
|
-
const btoaFn = getBtoa();
|
|
140
|
-
if (btoaFn) {
|
|
141
|
-
let binary = "";
|
|
142
|
-
const chunkSize = 32768;
|
|
143
|
-
for (let i = 0; i < bytes.length; i += chunkSize) {
|
|
144
|
-
const chunk = bytes.subarray(i, i + chunkSize);
|
|
145
|
-
binary += String.fromCharCode(...chunk);
|
|
146
|
-
}
|
|
147
|
-
return btoaFn(binary);
|
|
148
|
-
}
|
|
149
|
-
let output = "";
|
|
150
|
-
for (let i = 0; i < bytes.length; i += 3) {
|
|
151
|
-
const a = bytes[i] ?? 0;
|
|
152
|
-
const b = i + 1 < bytes.length ? bytes[i + 1] ?? 0 : 0;
|
|
153
|
-
const c = i + 2 < bytes.length ? bytes[i + 2] ?? 0 : 0;
|
|
154
|
-
const triple = a << 16 | b << 8 | c;
|
|
155
|
-
output += BASE64_ALPHABET[triple >> 18 & 63];
|
|
156
|
-
output += BASE64_ALPHABET[triple >> 12 & 63];
|
|
157
|
-
output += i + 1 < bytes.length ? BASE64_ALPHABET[triple >> 6 & 63] : "=";
|
|
158
|
-
output += i + 2 < bytes.length ? BASE64_ALPHABET[triple & 63] : "=";
|
|
159
|
-
}
|
|
160
|
-
return output;
|
|
161
|
-
}
|
|
162
|
-
function toBinaryBody(handler) {
|
|
163
|
-
if (handler instanceof ArrayBuffer) {
|
|
164
|
-
return encodeBase64(new Uint8Array(handler));
|
|
165
|
-
}
|
|
166
|
-
if (handler instanceof Uint8Array) {
|
|
167
|
-
return encodeBase64(handler);
|
|
168
|
-
}
|
|
169
|
-
return null;
|
|
170
|
-
}
|
|
171
|
-
function buildManifestResponse(route, moduleId) {
|
|
172
|
-
if (moduleId) {
|
|
173
|
-
const response = {
|
|
174
|
-
type: "module",
|
|
175
|
-
module: moduleId
|
|
176
|
-
};
|
|
177
|
-
if (typeof route.ruleIndex === "number") {
|
|
178
|
-
response.ruleIndex = route.ruleIndex;
|
|
179
|
-
}
|
|
180
|
-
return response;
|
|
181
|
-
}
|
|
182
|
-
const handler = route.handler;
|
|
183
|
-
if (typeof handler === "string") {
|
|
184
|
-
return {
|
|
185
|
-
type: "text",
|
|
186
|
-
body: handler
|
|
187
|
-
};
|
|
188
|
-
}
|
|
189
|
-
const binary = toBinaryBody(handler);
|
|
190
|
-
if (binary) {
|
|
191
|
-
return {
|
|
192
|
-
type: "binary",
|
|
193
|
-
body: binary,
|
|
194
|
-
encoding: "base64"
|
|
195
|
-
};
|
|
196
|
-
}
|
|
197
|
-
return {
|
|
198
|
-
type: "json",
|
|
199
|
-
body: handler
|
|
200
|
-
};
|
|
201
|
-
}
|
|
202
|
-
function buildManifestData(params) {
|
|
203
|
-
const { routes, root } = params;
|
|
204
|
-
const resolveModulePath = params.resolveModulePath ?? toViteImportPath;
|
|
205
|
-
const ruleModules = /* @__PURE__ */ new Map();
|
|
206
|
-
const middlewareModules = /* @__PURE__ */ new Map();
|
|
207
|
-
const manifestRoutes = routes.map((route) => {
|
|
208
|
-
const moduleId = shouldModuleize(route.handler) ? resolveModulePath(route.file, root) : null;
|
|
209
|
-
if (moduleId && !ruleModules.has(moduleId)) {
|
|
210
|
-
ruleModules.set(moduleId, { id: moduleId, kind: "rule" });
|
|
211
|
-
}
|
|
212
|
-
const middleware = route.middlewares?.map((entry) => {
|
|
213
|
-
const modulePath = resolveModulePath(entry.source, root);
|
|
214
|
-
if (!middlewareModules.has(modulePath)) {
|
|
215
|
-
middlewareModules.set(modulePath, { id: modulePath, kind: "middleware" });
|
|
216
|
-
}
|
|
217
|
-
return {
|
|
218
|
-
module: modulePath,
|
|
219
|
-
ruleIndex: entry.index
|
|
220
|
-
};
|
|
221
|
-
});
|
|
222
|
-
const response = buildManifestResponse(route, moduleId);
|
|
223
|
-
const manifestRoute = {
|
|
224
|
-
method: route.method,
|
|
225
|
-
url: route.template,
|
|
226
|
-
...route.tokens ? { tokens: route.tokens } : {},
|
|
227
|
-
...route.score ? { score: route.score } : {},
|
|
228
|
-
...route.status ? { status: route.status } : {},
|
|
229
|
-
...route.headers ? { headers: route.headers } : {},
|
|
230
|
-
...route.delay ? { delay: route.delay } : {},
|
|
231
|
-
...middleware && middleware.length > 0 ? { middleware } : {},
|
|
232
|
-
response
|
|
233
|
-
};
|
|
234
|
-
return manifestRoute;
|
|
235
|
-
});
|
|
236
|
-
const manifest = {
|
|
237
|
-
version: 1,
|
|
238
|
-
routes: manifestRoutes
|
|
239
|
-
};
|
|
240
|
-
return {
|
|
241
|
-
manifest,
|
|
242
|
-
modules: [
|
|
243
|
-
...ruleModules.values(),
|
|
244
|
-
...middlewareModules.values()
|
|
245
|
-
]
|
|
246
|
-
};
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
const require$1 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('shared/mokup.CYGG6ENd.cjs', document.baseURI).href)));
|
|
48
|
+
const require$1 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('shared/mokup.Cn9uLpN8.cjs', document.baseURI).href)));
|
|
250
49
|
const mimeTypes = {
|
|
251
50
|
".html": "text/html; charset=utf-8",
|
|
252
51
|
".css": "text/css; charset=utf-8",
|
|
@@ -312,92 +111,6 @@ function resolvePlaygroundOptions(playground) {
|
|
|
312
111
|
return { enabled: true, path: "/__mokup", build: false };
|
|
313
112
|
}
|
|
314
113
|
|
|
315
|
-
function toPosixPath(value) {
|
|
316
|
-
return value.replace(/\\/g, "/");
|
|
317
|
-
}
|
|
318
|
-
function normalizePath(value) {
|
|
319
|
-
return toPosixPath(pathe.normalize(value));
|
|
320
|
-
}
|
|
321
|
-
function isAncestor(parent, child) {
|
|
322
|
-
const normalizedParent = normalizePath(parent).replace(/\/$/, "");
|
|
323
|
-
const normalizedChild = normalizePath(child);
|
|
324
|
-
return normalizedChild === normalizedParent || normalizedChild.startsWith(`${normalizedParent}/`);
|
|
325
|
-
}
|
|
326
|
-
function resolveGroupRoot(dirs, serverRoot) {
|
|
327
|
-
if (!dirs || dirs.length === 0) {
|
|
328
|
-
return serverRoot ?? process.cwd();
|
|
329
|
-
}
|
|
330
|
-
if (serverRoot) {
|
|
331
|
-
const normalizedRoot = normalizePath(serverRoot);
|
|
332
|
-
const canUseRoot = dirs.every((dir) => isAncestor(normalizedRoot, dir));
|
|
333
|
-
if (canUseRoot) {
|
|
334
|
-
return normalizedRoot;
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
if (dirs.length === 1) {
|
|
338
|
-
return normalizePath(pathe.dirname(dirs[0]));
|
|
339
|
-
}
|
|
340
|
-
let common = normalizePath(dirs[0]);
|
|
341
|
-
for (const dir of dirs.slice(1)) {
|
|
342
|
-
const normalizedDir = normalizePath(dir);
|
|
343
|
-
while (common && !isAncestor(common, normalizedDir)) {
|
|
344
|
-
const parent = normalizePath(pathe.dirname(common));
|
|
345
|
-
if (parent === common) {
|
|
346
|
-
break;
|
|
347
|
-
}
|
|
348
|
-
common = parent;
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
if (!common || common === "/") {
|
|
352
|
-
return serverRoot ?? process.cwd();
|
|
353
|
-
}
|
|
354
|
-
return common;
|
|
355
|
-
}
|
|
356
|
-
function resolveGroups(dirs, root) {
|
|
357
|
-
const groups = [];
|
|
358
|
-
const seen = /* @__PURE__ */ new Set();
|
|
359
|
-
for (const dir of dirs) {
|
|
360
|
-
const normalized = normalizePath(dir);
|
|
361
|
-
if (seen.has(normalized)) {
|
|
362
|
-
continue;
|
|
363
|
-
}
|
|
364
|
-
seen.add(normalized);
|
|
365
|
-
const rel = toPosixPath(pathe.relative(root, normalized));
|
|
366
|
-
const label = rel && !rel.startsWith("..") ? rel : normalized;
|
|
367
|
-
groups.push({
|
|
368
|
-
key: normalized,
|
|
369
|
-
label,
|
|
370
|
-
path: normalized
|
|
371
|
-
});
|
|
372
|
-
}
|
|
373
|
-
return groups;
|
|
374
|
-
}
|
|
375
|
-
function resolveRouteGroup(routeFile, groups) {
|
|
376
|
-
if (groups.length === 0) {
|
|
377
|
-
return void 0;
|
|
378
|
-
}
|
|
379
|
-
const normalizedFile = toPosixPath(pathe.normalize(routeFile));
|
|
380
|
-
let matched;
|
|
381
|
-
for (const group of groups) {
|
|
382
|
-
if (normalizedFile === group.path || normalizedFile.startsWith(`${group.path}/`)) {
|
|
383
|
-
if (!matched || group.path.length > matched.path.length) {
|
|
384
|
-
matched = group;
|
|
385
|
-
}
|
|
386
|
-
}
|
|
387
|
-
}
|
|
388
|
-
return matched;
|
|
389
|
-
}
|
|
390
|
-
function formatRouteFile(file, root) {
|
|
391
|
-
if (!root) {
|
|
392
|
-
return toPosixPath(file);
|
|
393
|
-
}
|
|
394
|
-
const rel = toPosixPath(pathe.relative(root, file));
|
|
395
|
-
if (!rel || rel.startsWith("..")) {
|
|
396
|
-
return toPosixPath(file);
|
|
397
|
-
}
|
|
398
|
-
return rel;
|
|
399
|
-
}
|
|
400
|
-
|
|
401
114
|
function injectPlaygroundHmr(html, base) {
|
|
402
115
|
if (html.includes("mokup-playground-hmr")) {
|
|
403
116
|
return html;
|
|
@@ -479,20 +192,20 @@ function normalizeIgnoredReason(reason) {
|
|
|
479
192
|
return "unknown";
|
|
480
193
|
}
|
|
481
194
|
function toPlaygroundRoute(route, root, groups) {
|
|
482
|
-
const matchedGroup = resolveRouteGroup(route.file, groups);
|
|
483
|
-
const preSources = route.middlewares?.filter((entry) => entry.position === "pre").map((entry) => formatRouteFile(entry.source, root)) ?? [];
|
|
484
|
-
const postSources = route.middlewares?.filter((entry) => entry.position === "post").map((entry) => formatRouteFile(entry.source, root)) ?? [];
|
|
485
|
-
const normalSources = route.middlewares?.filter((entry) => entry.position !== "pre" && entry.position !== "post").map((entry) => formatRouteFile(entry.source, root)) ?? [];
|
|
195
|
+
const matchedGroup = playgroundGrouping.resolveRouteGroup(route.file, groups);
|
|
196
|
+
const preSources = route.middlewares?.filter((entry) => entry.position === "pre").map((entry) => playgroundGrouping.formatRouteFile(entry.source, root)) ?? [];
|
|
197
|
+
const postSources = route.middlewares?.filter((entry) => entry.position === "post").map((entry) => playgroundGrouping.formatRouteFile(entry.source, root)) ?? [];
|
|
198
|
+
const normalSources = route.middlewares?.filter((entry) => entry.position !== "pre" && entry.position !== "post").map((entry) => playgroundGrouping.formatRouteFile(entry.source, root)) ?? [];
|
|
486
199
|
const combinedSources = [
|
|
487
200
|
...preSources,
|
|
488
201
|
...normalSources,
|
|
489
202
|
...postSources
|
|
490
203
|
];
|
|
491
|
-
const configChain = route.configChain?.map((entry) => formatRouteFile(entry, root)) ?? [];
|
|
204
|
+
const configChain = route.configChain?.map((entry) => playgroundGrouping.formatRouteFile(entry, root)) ?? [];
|
|
492
205
|
return {
|
|
493
206
|
method: route.method,
|
|
494
207
|
url: route.template,
|
|
495
|
-
file: formatRouteFile(route.file, root),
|
|
208
|
+
file: playgroundGrouping.formatRouteFile(route.file, root),
|
|
496
209
|
type: typeof route.handler === "function" ? "handler" : "static",
|
|
497
210
|
status: route.status,
|
|
498
211
|
delay: route.delay,
|
|
@@ -509,10 +222,26 @@ function toPlaygroundRoute(route, root, groups) {
|
|
|
509
222
|
group: matchedGroup?.label
|
|
510
223
|
};
|
|
511
224
|
}
|
|
225
|
+
function formatDecisionChain(chain, root) {
|
|
226
|
+
return chain.map((entry) => {
|
|
227
|
+
const formatted = {
|
|
228
|
+
step: entry.step,
|
|
229
|
+
result: entry.result
|
|
230
|
+
};
|
|
231
|
+
if (typeof entry.detail !== "undefined") {
|
|
232
|
+
formatted.detail = entry.detail;
|
|
233
|
+
}
|
|
234
|
+
if (typeof entry.source !== "undefined") {
|
|
235
|
+
const source = entry.source;
|
|
236
|
+
formatted.source = source && pathe.isAbsolute(source) ? playgroundGrouping.formatRouteFile(source, root) : source;
|
|
237
|
+
}
|
|
238
|
+
return formatted;
|
|
239
|
+
});
|
|
240
|
+
}
|
|
512
241
|
function toPlaygroundDisabledRoute(route, root, groups) {
|
|
513
|
-
const matchedGroup = resolveRouteGroup(route.file, groups);
|
|
242
|
+
const matchedGroup = playgroundGrouping.resolveRouteGroup(route.file, groups);
|
|
514
243
|
const disabled = {
|
|
515
|
-
file: formatRouteFile(route.file, root),
|
|
244
|
+
file: playgroundGrouping.formatRouteFile(route.file, root),
|
|
516
245
|
reason: normalizeDisabledReason(route.reason)
|
|
517
246
|
};
|
|
518
247
|
if (typeof route.method !== "undefined") {
|
|
@@ -522,7 +251,7 @@ function toPlaygroundDisabledRoute(route, root, groups) {
|
|
|
522
251
|
disabled.url = route.url;
|
|
523
252
|
}
|
|
524
253
|
if (route.configChain && route.configChain.length > 0) {
|
|
525
|
-
disabled.configChain = route.configChain.map((entry) => formatRouteFile(entry, root));
|
|
254
|
+
disabled.configChain = route.configChain.map((entry) => playgroundGrouping.formatRouteFile(entry, root));
|
|
526
255
|
}
|
|
527
256
|
if (route.decisionChain && route.decisionChain.length > 0) {
|
|
528
257
|
disabled.decisionChain = formatDecisionChain(route.decisionChain, root);
|
|
@@ -537,9 +266,9 @@ function toPlaygroundDisabledRoute(route, root, groups) {
|
|
|
537
266
|
return disabled;
|
|
538
267
|
}
|
|
539
268
|
function toPlaygroundIgnoredRoute(route, root, groups) {
|
|
540
|
-
const matchedGroup = resolveRouteGroup(route.file, groups);
|
|
269
|
+
const matchedGroup = playgroundGrouping.resolveRouteGroup(route.file, groups);
|
|
541
270
|
const ignored = {
|
|
542
|
-
file: formatRouteFile(route.file, root),
|
|
271
|
+
file: playgroundGrouping.formatRouteFile(route.file, root),
|
|
543
272
|
reason: normalizeIgnoredReason(route.reason)
|
|
544
273
|
};
|
|
545
274
|
if (matchedGroup) {
|
|
@@ -547,7 +276,7 @@ function toPlaygroundIgnoredRoute(route, root, groups) {
|
|
|
547
276
|
ignored.group = matchedGroup.label;
|
|
548
277
|
}
|
|
549
278
|
if (route.configChain && route.configChain.length > 0) {
|
|
550
|
-
ignored.configChain = route.configChain.map((entry) => formatRouteFile(entry, root));
|
|
279
|
+
ignored.configChain = route.configChain.map((entry) => playgroundGrouping.formatRouteFile(entry, root));
|
|
551
280
|
}
|
|
552
281
|
if (route.decisionChain && route.decisionChain.length > 0) {
|
|
553
282
|
ignored.decisionChain = formatDecisionChain(route.decisionChain, root);
|
|
@@ -558,9 +287,9 @@ function toPlaygroundIgnoredRoute(route, root, groups) {
|
|
|
558
287
|
return ignored;
|
|
559
288
|
}
|
|
560
289
|
function toPlaygroundConfigFile(entry, root, groups) {
|
|
561
|
-
const matchedGroup = resolveRouteGroup(entry.file, groups);
|
|
290
|
+
const matchedGroup = playgroundGrouping.resolveRouteGroup(entry.file, groups);
|
|
562
291
|
const configFile = {
|
|
563
|
-
file: formatRouteFile(entry.file, root)
|
|
292
|
+
file: playgroundGrouping.formatRouteFile(entry.file, root)
|
|
564
293
|
};
|
|
565
294
|
if (matchedGroup) {
|
|
566
295
|
configFile.groupKey = matchedGroup.key;
|
|
@@ -568,22 +297,6 @@ function toPlaygroundConfigFile(entry, root, groups) {
|
|
|
568
297
|
}
|
|
569
298
|
return configFile;
|
|
570
299
|
}
|
|
571
|
-
function formatDecisionChain(chain, root) {
|
|
572
|
-
return chain.map((entry) => {
|
|
573
|
-
const formatted = {
|
|
574
|
-
step: entry.step,
|
|
575
|
-
result: entry.result
|
|
576
|
-
};
|
|
577
|
-
if (typeof entry.detail !== "undefined") {
|
|
578
|
-
formatted.detail = entry.detail;
|
|
579
|
-
}
|
|
580
|
-
if (typeof entry.source !== "undefined") {
|
|
581
|
-
const source = entry.source;
|
|
582
|
-
formatted.source = source && pathe.isAbsolute(source) ? formatRouteFile(source, root) : source;
|
|
583
|
-
}
|
|
584
|
-
return formatted;
|
|
585
|
-
});
|
|
586
|
-
}
|
|
587
300
|
|
|
588
301
|
function createPlaygroundMiddleware(params) {
|
|
589
302
|
const distDir = resolvePlaygroundDist();
|
|
@@ -629,8 +342,8 @@ function createPlaygroundMiddleware(params) {
|
|
|
629
342
|
}
|
|
630
343
|
if (subPath === "/routes") {
|
|
631
344
|
const dirs = params.getDirs?.() ?? [];
|
|
632
|
-
const baseRoot = resolveGroupRoot(dirs, server?.config?.root);
|
|
633
|
-
const groups = resolveGroups(dirs, baseRoot);
|
|
345
|
+
const baseRoot = playgroundGrouping.resolveGroupRoot(dirs, server?.config?.root);
|
|
346
|
+
const groups = playgroundGrouping.resolveGroups(dirs, baseRoot);
|
|
634
347
|
const routes = params.getRoutes();
|
|
635
348
|
const disabledRoutes = params.getDisabledRoutes?.() ?? [];
|
|
636
349
|
const ignoredRoutes = params.getIgnoredRoutes?.() ?? [];
|
|
@@ -777,8 +490,8 @@ function buildSwScript(params) {
|
|
|
777
490
|
const runtimeImportPath = params.runtimeImportPath ?? "mokup/runtime";
|
|
778
491
|
const loggerImportPath = params.loggerImportPath ?? "@mokup/shared/logger";
|
|
779
492
|
const basePaths = params.basePaths ?? [];
|
|
780
|
-
const resolveModulePath = params.resolveModulePath ?? toViteImportPath;
|
|
781
|
-
const { manifest, modules } = buildManifestData({
|
|
493
|
+
const resolveModulePath = params.resolveModulePath ?? manifest.toViteImportPath;
|
|
494
|
+
const { manifest: manifest$1, modules } = manifest.buildManifestData({
|
|
782
495
|
routes,
|
|
783
496
|
root,
|
|
784
497
|
resolveModulePath
|
|
@@ -842,7 +555,7 @@ function buildSwScript(params) {
|
|
|
842
555
|
""
|
|
843
556
|
);
|
|
844
557
|
lines.push(
|
|
845
|
-
`const manifest = ${JSON.stringify(manifest, null, 2)}`,
|
|
558
|
+
`const manifest = ${JSON.stringify(manifest$1, null, 2)}`,
|
|
846
559
|
""
|
|
847
560
|
);
|
|
848
561
|
if (moduleEntries.length > 0) {
|
|
@@ -997,7 +710,7 @@ function createFinalizeMiddleware(route) {
|
|
|
997
710
|
const response = await next();
|
|
998
711
|
const resolved = resolveResponse(response, c.res);
|
|
999
712
|
if (route.delay && route.delay > 0) {
|
|
1000
|
-
await delay(route.delay);
|
|
713
|
+
await timing.delay(route.delay);
|
|
1001
714
|
}
|
|
1002
715
|
const overridden = applyRouteOverrides(resolved, route);
|
|
1003
716
|
c.res = overridden;
|
|
@@ -1161,7 +874,7 @@ function resolveTemplate(template, prefix) {
|
|
|
1161
874
|
function stripMethodSuffix(base) {
|
|
1162
875
|
const segments = base.split(".");
|
|
1163
876
|
const last = segments.at(-1);
|
|
1164
|
-
if (last && methodSuffixSet.has(last.toLowerCase())) {
|
|
877
|
+
if (last && manifest.methodSuffixSet.has(last.toLowerCase())) {
|
|
1165
878
|
segments.pop();
|
|
1166
879
|
return {
|
|
1167
880
|
name: segments.join("."),
|
|
@@ -1174,7 +887,7 @@ function stripMethodSuffix(base) {
|
|
|
1174
887
|
};
|
|
1175
888
|
}
|
|
1176
889
|
function deriveRouteFromFile(file, rootDir, logger) {
|
|
1177
|
-
const rel = toPosix(pathe.relative(rootDir, file));
|
|
890
|
+
const rel = pathUtils.toPosix(pathe.relative(rootDir, file));
|
|
1178
891
|
const ext = pathe.extname(rel);
|
|
1179
892
|
const withoutExt = rel.slice(0, rel.length - ext.length);
|
|
1180
893
|
const dir = pathe.dirname(withoutExt);
|
|
@@ -1190,7 +903,7 @@ function deriveRouteFromFile(file, rootDir, logger) {
|
|
|
1190
903
|
return null;
|
|
1191
904
|
}
|
|
1192
905
|
const joined = dir === "." ? name : pathe.join(dir, name);
|
|
1193
|
-
const segments = toPosix(joined).split("/");
|
|
906
|
+
const segments = pathUtils.toPosix(joined).split("/");
|
|
1194
907
|
if (segments.at(-1) === "index") {
|
|
1195
908
|
segments.pop();
|
|
1196
909
|
}
|
|
@@ -1295,29 +1008,29 @@ async function collectFiles(dirs) {
|
|
|
1295
1008
|
}
|
|
1296
1009
|
return files;
|
|
1297
1010
|
}
|
|
1298
|
-
function
|
|
1011
|
+
function isConfigFile(file) {
|
|
1299
1012
|
if (file.endsWith(".d.ts")) {
|
|
1300
1013
|
return false;
|
|
1301
1014
|
}
|
|
1302
|
-
|
|
1015
|
+
const base = pathe.basename(file);
|
|
1016
|
+
if (!base.startsWith("index.config.")) {
|
|
1303
1017
|
return false;
|
|
1304
1018
|
}
|
|
1305
1019
|
const ext = pathe.extname(file).toLowerCase();
|
|
1306
|
-
return
|
|
1020
|
+
return manifest.configExtensions.includes(ext);
|
|
1307
1021
|
}
|
|
1308
|
-
function
|
|
1022
|
+
function isSupportedFile(file) {
|
|
1309
1023
|
if (file.endsWith(".d.ts")) {
|
|
1310
1024
|
return false;
|
|
1311
1025
|
}
|
|
1312
|
-
|
|
1313
|
-
if (!base.startsWith("index.config.")) {
|
|
1026
|
+
if (isConfigFile(file)) {
|
|
1314
1027
|
return false;
|
|
1315
1028
|
}
|
|
1316
1029
|
const ext = pathe.extname(file).toLowerCase();
|
|
1317
|
-
return
|
|
1030
|
+
return manifest.supportedExtensions.has(ext);
|
|
1318
1031
|
}
|
|
1319
1032
|
|
|
1320
|
-
const sourceRoot = pathe.dirname(node_url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('shared/mokup.
|
|
1033
|
+
const sourceRoot = pathe.dirname(node_url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('shared/mokup.Cn9uLpN8.cjs', document.baseURI).href))));
|
|
1321
1034
|
const mokupSourceEntry = pathe.resolve(sourceRoot, "../index.ts");
|
|
1322
1035
|
const mokupViteSourceEntry = pathe.resolve(sourceRoot, "../vite.ts");
|
|
1323
1036
|
const hasMokupSourceEntry = node_fs.existsSync(mokupSourceEntry);
|
|
@@ -1342,7 +1055,7 @@ const workspaceResolvePlugin = createWorkspaceResolvePlugin();
|
|
|
1342
1055
|
async function loadModule(file) {
|
|
1343
1056
|
const ext = pathe.extname(file).toLowerCase();
|
|
1344
1057
|
if (ext === ".cjs") {
|
|
1345
|
-
const require$1 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('shared/mokup.
|
|
1058
|
+
const require$1 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('shared/mokup.Cn9uLpN8.cjs', document.baseURI).href)));
|
|
1346
1059
|
delete require$1.cache[file];
|
|
1347
1060
|
return require$1(file);
|
|
1348
1061
|
}
|
|
@@ -1383,7 +1096,7 @@ async function loadModuleWithVite(server, file) {
|
|
|
1383
1096
|
|
|
1384
1097
|
const middlewareSymbol = Symbol.for("mokup.config.middlewares");
|
|
1385
1098
|
function getConfigFileCandidates(dir) {
|
|
1386
|
-
return configExtensions.map((extension) => pathe.join(dir, `index.config${extension}`));
|
|
1099
|
+
return manifest.configExtensions.map((extension) => pathe.join(dir, `index.config${extension}`));
|
|
1387
1100
|
}
|
|
1388
1101
|
async function findConfigFile(dir, cache) {
|
|
1389
1102
|
const cached = cache.get(dir);
|
|
@@ -1771,7 +1484,7 @@ function runRoutePrechecks(params) {
|
|
|
1771
1484
|
return null;
|
|
1772
1485
|
}
|
|
1773
1486
|
if (effectiveIgnorePrefix.length > 0) {
|
|
1774
|
-
const ignoredByPrefix = hasIgnoredPrefix(fileInfo.file, fileInfo.rootDir, effectiveIgnorePrefix);
|
|
1487
|
+
const ignoredByPrefix = pathUtils.hasIgnoredPrefix(fileInfo.file, fileInfo.rootDir, effectiveIgnorePrefix);
|
|
1775
1488
|
pushDecisionStep(decisionChain, {
|
|
1776
1489
|
step: "ignore-prefix",
|
|
1777
1490
|
result: ignoredByPrefix ? "fail" : "pass",
|
|
@@ -1818,7 +1531,7 @@ function runRoutePrechecks(params) {
|
|
|
1818
1531
|
}
|
|
1819
1532
|
return null;
|
|
1820
1533
|
}
|
|
1821
|
-
const normalizedFile = toPosix(fileInfo.file);
|
|
1534
|
+
const normalizedFile = pathUtils.toPosix(fileInfo.file);
|
|
1822
1535
|
if (typeof effectiveExclude !== "undefined") {
|
|
1823
1536
|
const excluded = testPatterns(effectiveExclude, normalizedFile);
|
|
1824
1537
|
const patterns = toFilterStrings(effectiveExclude);
|
|
@@ -2058,18 +1771,13 @@ async function scanRoutes(params) {
|
|
|
2058
1771
|
return sortRoutes(routes);
|
|
2059
1772
|
}
|
|
2060
1773
|
|
|
2061
|
-
exports.buildManifestData = buildManifestData;
|
|
2062
1774
|
exports.buildSwScript = buildSwScript;
|
|
2063
|
-
exports.createDebouncer = createDebouncer;
|
|
2064
1775
|
exports.createHonoApp = createHonoApp;
|
|
2065
1776
|
exports.createMiddleware = createMiddleware;
|
|
2066
1777
|
exports.createPlaygroundMiddleware = createPlaygroundMiddleware;
|
|
2067
1778
|
exports.injectPlaygroundSw = injectPlaygroundSw;
|
|
2068
|
-
exports.isInDirs = isInDirs;
|
|
2069
1779
|
exports.normalizePlaygroundPath = normalizePlaygroundPath;
|
|
2070
1780
|
exports.resolveDirs = resolveDirs;
|
|
2071
|
-
exports.resolveGroupRoot = resolveGroupRoot;
|
|
2072
|
-
exports.resolveGroups = resolveGroups;
|
|
2073
1781
|
exports.resolvePlaygroundDist = resolvePlaygroundDist;
|
|
2074
1782
|
exports.resolvePlaygroundOptions = resolvePlaygroundOptions;
|
|
2075
1783
|
exports.resolvePlaygroundRequestPath = resolvePlaygroundRequestPath;
|
|
@@ -2081,4 +1789,3 @@ exports.toPlaygroundConfigFile = toPlaygroundConfigFile;
|
|
|
2081
1789
|
exports.toPlaygroundDisabledRoute = toPlaygroundDisabledRoute;
|
|
2082
1790
|
exports.toPlaygroundIgnoredRoute = toPlaygroundIgnoredRoute;
|
|
2083
1791
|
exports.toPlaygroundRoute = toPlaygroundRoute;
|
|
2084
|
-
exports.toPosix = toPosix;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { b as buildManifestData } from './mokup.Iqw32OxC.mjs';
|
|
2
|
+
|
|
3
|
+
function buildBundleModule(params) {
|
|
4
|
+
const { manifest, modules } = buildManifestData({
|
|
5
|
+
routes: params.routes,
|
|
6
|
+
root: params.root,
|
|
7
|
+
...params.resolveModulePath ? { resolveModulePath: params.resolveModulePath } : {}
|
|
8
|
+
});
|
|
9
|
+
const imports = [];
|
|
10
|
+
const moduleEntries = [];
|
|
11
|
+
let moduleIndex = 0;
|
|
12
|
+
for (const entry of modules) {
|
|
13
|
+
const name = `module${moduleIndex++}`;
|
|
14
|
+
imports.push(`import * as ${name} from '${entry.id}'`);
|
|
15
|
+
moduleEntries.push({ id: entry.id, name });
|
|
16
|
+
}
|
|
17
|
+
const lines = [];
|
|
18
|
+
if (imports.length > 0) {
|
|
19
|
+
lines.push(...imports, "");
|
|
20
|
+
}
|
|
21
|
+
lines.push(
|
|
22
|
+
`const manifest = ${JSON.stringify(manifest, null, 2)}`,
|
|
23
|
+
""
|
|
24
|
+
);
|
|
25
|
+
if (moduleEntries.length > 0) {
|
|
26
|
+
lines.push("const moduleMap = {");
|
|
27
|
+
for (const entry of moduleEntries) {
|
|
28
|
+
lines.push(
|
|
29
|
+
` ${JSON.stringify(entry.id)}: ${entry.name},`
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
lines.push("}", "");
|
|
33
|
+
}
|
|
34
|
+
const runtimeOptions = moduleEntries.length > 0 ? "{ manifest, moduleMap }" : "{ manifest }";
|
|
35
|
+
lines.push(
|
|
36
|
+
`const mokupBundle = ${runtimeOptions}`,
|
|
37
|
+
"",
|
|
38
|
+
"export default mokupBundle",
|
|
39
|
+
"export { mokupBundle }",
|
|
40
|
+
""
|
|
41
|
+
);
|
|
42
|
+
return lines.join("\n");
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export { buildBundleModule as b };
|