mokup 2.2.1 → 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 +4 -2
- package/dist/bundle.d.cts +3 -0
- package/dist/bundle.d.mts +3 -0
- package/dist/bundle.d.ts +3 -0
- package/dist/bundle.mjs +4 -2
- package/dist/shared/{mokup.zkaN1ADs.cjs → mokup.BXPIIxtS.cjs} +1 -1
- package/dist/shared/{mokup.DLUSS6KF.cjs → mokup.Cn9uLpN8.cjs} +87 -142
- package/dist/shared/{mokup.vAap-D_L.mjs → mokup.CsBTglhs.mjs} +1 -1
- package/dist/shared/{mokup.CtSctWaa.mjs → mokup.DJ2QlqTp.mjs} +59 -113
- package/dist/shared/{mokup.C7-7PDF7.cjs → mokup.Dy9VDphS.cjs} +5 -76
- package/dist/shared/{mokup.JBCzv4xR.mjs → mokup.Iqw32OxC.mjs} +4 -67
- package/dist/vite.cjs +16 -13
- package/dist/vite.mjs +6 -3
- package/dist/webpack.cjs +12 -9
- package/dist/webpack.mjs +5 -2
- package/package.json +6 -6
package/dist/bundle.cjs
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const bundle = require('./shared/mokup.
|
|
4
|
-
require('./shared/mokup.
|
|
3
|
+
const bundle = require('./shared/mokup.BXPIIxtS.cjs');
|
|
4
|
+
require('./shared/mokup.Dy9VDphS.cjs');
|
|
5
5
|
require('@mokup/shared/pathe');
|
|
6
|
+
require('@mokup/shared/path-utils');
|
|
7
|
+
require('@mokup/shared/timing');
|
|
6
8
|
|
|
7
9
|
|
|
8
10
|
|
package/dist/bundle.d.cts
CHANGED
|
@@ -8,6 +8,9 @@ import '@mokup/shared/hono';
|
|
|
8
8
|
* Build the source for a virtual mokup bundle module.
|
|
9
9
|
*
|
|
10
10
|
* @param params - Bundle build parameters.
|
|
11
|
+
* @param params.routes - Resolved routes to serialize.
|
|
12
|
+
* @param params.root - Workspace root path.
|
|
13
|
+
* @param params.resolveModulePath - Optional module resolver.
|
|
11
14
|
* @returns JavaScript source string.
|
|
12
15
|
*
|
|
13
16
|
* @example
|
package/dist/bundle.d.mts
CHANGED
|
@@ -8,6 +8,9 @@ import '@mokup/shared/hono';
|
|
|
8
8
|
* Build the source for a virtual mokup bundle module.
|
|
9
9
|
*
|
|
10
10
|
* @param params - Bundle build parameters.
|
|
11
|
+
* @param params.routes - Resolved routes to serialize.
|
|
12
|
+
* @param params.root - Workspace root path.
|
|
13
|
+
* @param params.resolveModulePath - Optional module resolver.
|
|
11
14
|
* @returns JavaScript source string.
|
|
12
15
|
*
|
|
13
16
|
* @example
|
package/dist/bundle.d.ts
CHANGED
|
@@ -8,6 +8,9 @@ import '@mokup/shared/hono';
|
|
|
8
8
|
* Build the source for a virtual mokup bundle module.
|
|
9
9
|
*
|
|
10
10
|
* @param params - Bundle build parameters.
|
|
11
|
+
* @param params.routes - Resolved routes to serialize.
|
|
12
|
+
* @param params.root - Workspace root path.
|
|
13
|
+
* @param params.resolveModulePath - Optional module resolver.
|
|
11
14
|
* @returns JavaScript source string.
|
|
12
15
|
*
|
|
13
16
|
* @example
|
package/dist/bundle.mjs
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
-
export { b as buildBundleModule } from './shared/mokup.
|
|
2
|
-
import './shared/mokup.
|
|
1
|
+
export { b as buildBundleModule } from './shared/mokup.CsBTglhs.mjs';
|
|
2
|
+
import './shared/mokup.Iqw32OxC.mjs';
|
|
3
3
|
import '@mokup/shared/pathe';
|
|
4
|
+
import '@mokup/shared/path-utils';
|
|
5
|
+
import '@mokup/shared/timing';
|
|
@@ -3,17 +3,49 @@
|
|
|
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
|
|
7
|
-
const manifest = require('./mokup.
|
|
6
|
+
const playgroundGrouping = require('@mokup/shared/playground-grouping');
|
|
7
|
+
const manifest = require('./mokup.Dy9VDphS.cjs');
|
|
8
8
|
const node_buffer = require('node:buffer');
|
|
9
9
|
const hono = require('@mokup/shared/hono');
|
|
10
|
+
const timing = require('@mokup/shared/timing');
|
|
11
|
+
const pathUtils = require('@mokup/shared/path-utils');
|
|
10
12
|
const node_url = require('node:url');
|
|
11
13
|
const esbuild = require('@mokup/shared/esbuild');
|
|
12
14
|
const jsoncParser = require('@mokup/shared/jsonc-parser');
|
|
13
15
|
const runtime = require('@mokup/runtime');
|
|
14
16
|
|
|
15
17
|
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
16
|
-
|
|
18
|
+
function normalizeMethod(method) {
|
|
19
|
+
if (!method) {
|
|
20
|
+
return void 0;
|
|
21
|
+
}
|
|
22
|
+
const normalized = method.toUpperCase();
|
|
23
|
+
if (manifest.methodSet.has(normalized)) {
|
|
24
|
+
return normalized;
|
|
25
|
+
}
|
|
26
|
+
return void 0;
|
|
27
|
+
}
|
|
28
|
+
function normalizePrefix(prefix) {
|
|
29
|
+
if (!prefix) {
|
|
30
|
+
return "";
|
|
31
|
+
}
|
|
32
|
+
const normalized = prefix.startsWith("/") ? prefix : `/${prefix}`;
|
|
33
|
+
return normalized.endsWith("/") ? normalized.slice(0, -1) : normalized;
|
|
34
|
+
}
|
|
35
|
+
function resolveDirs(dir, root) {
|
|
36
|
+
const raw = typeof dir === "function" ? dir(root) : dir;
|
|
37
|
+
const resolved = Array.isArray(raw) ? raw : raw ? [raw] : ["mock"];
|
|
38
|
+
const normalized = resolved.map(
|
|
39
|
+
(entry) => pathe.isAbsolute(entry) ? entry : pathe.resolve(root, entry)
|
|
40
|
+
);
|
|
41
|
+
return Array.from(new Set(normalized));
|
|
42
|
+
}
|
|
43
|
+
function normalizeIgnorePrefix(value, fallback = ["."]) {
|
|
44
|
+
const list = typeof value === "undefined" ? fallback : Array.isArray(value) ? value : [value];
|
|
45
|
+
return list.filter((entry) => typeof entry === "string" && entry.length > 0);
|
|
46
|
+
}
|
|
47
|
+
|
|
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)));
|
|
17
49
|
const mimeTypes = {
|
|
18
50
|
".html": "text/html; charset=utf-8",
|
|
19
51
|
".css": "text/css; charset=utf-8",
|
|
@@ -79,92 +111,6 @@ function resolvePlaygroundOptions(playground) {
|
|
|
79
111
|
return { enabled: true, path: "/__mokup", build: false };
|
|
80
112
|
}
|
|
81
113
|
|
|
82
|
-
function toPosixPath(value) {
|
|
83
|
-
return value.replace(/\\/g, "/");
|
|
84
|
-
}
|
|
85
|
-
function normalizePath(value) {
|
|
86
|
-
return toPosixPath(pathe.normalize(value));
|
|
87
|
-
}
|
|
88
|
-
function isAncestor(parent, child) {
|
|
89
|
-
const normalizedParent = normalizePath(parent).replace(/\/$/, "");
|
|
90
|
-
const normalizedChild = normalizePath(child);
|
|
91
|
-
return normalizedChild === normalizedParent || normalizedChild.startsWith(`${normalizedParent}/`);
|
|
92
|
-
}
|
|
93
|
-
function resolveGroupRoot(dirs, serverRoot) {
|
|
94
|
-
if (!dirs || dirs.length === 0) {
|
|
95
|
-
return serverRoot ?? process.cwd();
|
|
96
|
-
}
|
|
97
|
-
if (serverRoot) {
|
|
98
|
-
const normalizedRoot = normalizePath(serverRoot);
|
|
99
|
-
const canUseRoot = dirs.every((dir) => isAncestor(normalizedRoot, dir));
|
|
100
|
-
if (canUseRoot) {
|
|
101
|
-
return normalizedRoot;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
if (dirs.length === 1) {
|
|
105
|
-
return normalizePath(pathe.dirname(dirs[0]));
|
|
106
|
-
}
|
|
107
|
-
let common = normalizePath(dirs[0]);
|
|
108
|
-
for (const dir of dirs.slice(1)) {
|
|
109
|
-
const normalizedDir = normalizePath(dir);
|
|
110
|
-
while (common && !isAncestor(common, normalizedDir)) {
|
|
111
|
-
const parent = normalizePath(pathe.dirname(common));
|
|
112
|
-
if (parent === common) {
|
|
113
|
-
break;
|
|
114
|
-
}
|
|
115
|
-
common = parent;
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
if (!common || common === "/") {
|
|
119
|
-
return serverRoot ?? process.cwd();
|
|
120
|
-
}
|
|
121
|
-
return common;
|
|
122
|
-
}
|
|
123
|
-
function resolveGroups(dirs, root) {
|
|
124
|
-
const groups = [];
|
|
125
|
-
const seen = /* @__PURE__ */ new Set();
|
|
126
|
-
for (const dir of dirs) {
|
|
127
|
-
const normalized = normalizePath(dir);
|
|
128
|
-
if (seen.has(normalized)) {
|
|
129
|
-
continue;
|
|
130
|
-
}
|
|
131
|
-
seen.add(normalized);
|
|
132
|
-
const rel = toPosixPath(pathe.relative(root, normalized));
|
|
133
|
-
const label = rel && !rel.startsWith("..") ? rel : normalized;
|
|
134
|
-
groups.push({
|
|
135
|
-
key: normalized,
|
|
136
|
-
label,
|
|
137
|
-
path: normalized
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
|
-
return groups;
|
|
141
|
-
}
|
|
142
|
-
function resolveRouteGroup(routeFile, groups) {
|
|
143
|
-
if (groups.length === 0) {
|
|
144
|
-
return void 0;
|
|
145
|
-
}
|
|
146
|
-
const normalizedFile = toPosixPath(pathe.normalize(routeFile));
|
|
147
|
-
let matched;
|
|
148
|
-
for (const group of groups) {
|
|
149
|
-
if (normalizedFile === group.path || normalizedFile.startsWith(`${group.path}/`)) {
|
|
150
|
-
if (!matched || group.path.length > matched.path.length) {
|
|
151
|
-
matched = group;
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
return matched;
|
|
156
|
-
}
|
|
157
|
-
function formatRouteFile(file, root) {
|
|
158
|
-
if (!root) {
|
|
159
|
-
return toPosixPath(file);
|
|
160
|
-
}
|
|
161
|
-
const rel = toPosixPath(pathe.relative(root, file));
|
|
162
|
-
if (!rel || rel.startsWith("..")) {
|
|
163
|
-
return toPosixPath(file);
|
|
164
|
-
}
|
|
165
|
-
return rel;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
114
|
function injectPlaygroundHmr(html, base) {
|
|
169
115
|
if (html.includes("mokup-playground-hmr")) {
|
|
170
116
|
return html;
|
|
@@ -246,20 +192,20 @@ function normalizeIgnoredReason(reason) {
|
|
|
246
192
|
return "unknown";
|
|
247
193
|
}
|
|
248
194
|
function toPlaygroundRoute(route, root, groups) {
|
|
249
|
-
const matchedGroup = resolveRouteGroup(route.file, groups);
|
|
250
|
-
const preSources = route.middlewares?.filter((entry) => entry.position === "pre").map((entry) => formatRouteFile(entry.source, root)) ?? [];
|
|
251
|
-
const postSources = route.middlewares?.filter((entry) => entry.position === "post").map((entry) => formatRouteFile(entry.source, root)) ?? [];
|
|
252
|
-
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)) ?? [];
|
|
253
199
|
const combinedSources = [
|
|
254
200
|
...preSources,
|
|
255
201
|
...normalSources,
|
|
256
202
|
...postSources
|
|
257
203
|
];
|
|
258
|
-
const configChain = route.configChain?.map((entry) => formatRouteFile(entry, root)) ?? [];
|
|
204
|
+
const configChain = route.configChain?.map((entry) => playgroundGrouping.formatRouteFile(entry, root)) ?? [];
|
|
259
205
|
return {
|
|
260
206
|
method: route.method,
|
|
261
207
|
url: route.template,
|
|
262
|
-
file: formatRouteFile(route.file, root),
|
|
208
|
+
file: playgroundGrouping.formatRouteFile(route.file, root),
|
|
263
209
|
type: typeof route.handler === "function" ? "handler" : "static",
|
|
264
210
|
status: route.status,
|
|
265
211
|
delay: route.delay,
|
|
@@ -276,10 +222,26 @@ function toPlaygroundRoute(route, root, groups) {
|
|
|
276
222
|
group: matchedGroup?.label
|
|
277
223
|
};
|
|
278
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
|
+
}
|
|
279
241
|
function toPlaygroundDisabledRoute(route, root, groups) {
|
|
280
|
-
const matchedGroup = resolveRouteGroup(route.file, groups);
|
|
242
|
+
const matchedGroup = playgroundGrouping.resolveRouteGroup(route.file, groups);
|
|
281
243
|
const disabled = {
|
|
282
|
-
file: formatRouteFile(route.file, root),
|
|
244
|
+
file: playgroundGrouping.formatRouteFile(route.file, root),
|
|
283
245
|
reason: normalizeDisabledReason(route.reason)
|
|
284
246
|
};
|
|
285
247
|
if (typeof route.method !== "undefined") {
|
|
@@ -289,7 +251,7 @@ function toPlaygroundDisabledRoute(route, root, groups) {
|
|
|
289
251
|
disabled.url = route.url;
|
|
290
252
|
}
|
|
291
253
|
if (route.configChain && route.configChain.length > 0) {
|
|
292
|
-
disabled.configChain = route.configChain.map((entry) => formatRouteFile(entry, root));
|
|
254
|
+
disabled.configChain = route.configChain.map((entry) => playgroundGrouping.formatRouteFile(entry, root));
|
|
293
255
|
}
|
|
294
256
|
if (route.decisionChain && route.decisionChain.length > 0) {
|
|
295
257
|
disabled.decisionChain = formatDecisionChain(route.decisionChain, root);
|
|
@@ -304,9 +266,9 @@ function toPlaygroundDisabledRoute(route, root, groups) {
|
|
|
304
266
|
return disabled;
|
|
305
267
|
}
|
|
306
268
|
function toPlaygroundIgnoredRoute(route, root, groups) {
|
|
307
|
-
const matchedGroup = resolveRouteGroup(route.file, groups);
|
|
269
|
+
const matchedGroup = playgroundGrouping.resolveRouteGroup(route.file, groups);
|
|
308
270
|
const ignored = {
|
|
309
|
-
file: formatRouteFile(route.file, root),
|
|
271
|
+
file: playgroundGrouping.formatRouteFile(route.file, root),
|
|
310
272
|
reason: normalizeIgnoredReason(route.reason)
|
|
311
273
|
};
|
|
312
274
|
if (matchedGroup) {
|
|
@@ -314,7 +276,7 @@ function toPlaygroundIgnoredRoute(route, root, groups) {
|
|
|
314
276
|
ignored.group = matchedGroup.label;
|
|
315
277
|
}
|
|
316
278
|
if (route.configChain && route.configChain.length > 0) {
|
|
317
|
-
ignored.configChain = route.configChain.map((entry) => formatRouteFile(entry, root));
|
|
279
|
+
ignored.configChain = route.configChain.map((entry) => playgroundGrouping.formatRouteFile(entry, root));
|
|
318
280
|
}
|
|
319
281
|
if (route.decisionChain && route.decisionChain.length > 0) {
|
|
320
282
|
ignored.decisionChain = formatDecisionChain(route.decisionChain, root);
|
|
@@ -325,9 +287,9 @@ function toPlaygroundIgnoredRoute(route, root, groups) {
|
|
|
325
287
|
return ignored;
|
|
326
288
|
}
|
|
327
289
|
function toPlaygroundConfigFile(entry, root, groups) {
|
|
328
|
-
const matchedGroup = resolveRouteGroup(entry.file, groups);
|
|
290
|
+
const matchedGroup = playgroundGrouping.resolveRouteGroup(entry.file, groups);
|
|
329
291
|
const configFile = {
|
|
330
|
-
file: formatRouteFile(entry.file, root)
|
|
292
|
+
file: playgroundGrouping.formatRouteFile(entry.file, root)
|
|
331
293
|
};
|
|
332
294
|
if (matchedGroup) {
|
|
333
295
|
configFile.groupKey = matchedGroup.key;
|
|
@@ -335,22 +297,6 @@ function toPlaygroundConfigFile(entry, root, groups) {
|
|
|
335
297
|
}
|
|
336
298
|
return configFile;
|
|
337
299
|
}
|
|
338
|
-
function formatDecisionChain(chain, root) {
|
|
339
|
-
return chain.map((entry) => {
|
|
340
|
-
const formatted = {
|
|
341
|
-
step: entry.step,
|
|
342
|
-
result: entry.result
|
|
343
|
-
};
|
|
344
|
-
if (typeof entry.detail !== "undefined") {
|
|
345
|
-
formatted.detail = entry.detail;
|
|
346
|
-
}
|
|
347
|
-
if (typeof entry.source !== "undefined") {
|
|
348
|
-
const source = entry.source;
|
|
349
|
-
formatted.source = source && pathe.isAbsolute(source) ? formatRouteFile(source, root) : source;
|
|
350
|
-
}
|
|
351
|
-
return formatted;
|
|
352
|
-
});
|
|
353
|
-
}
|
|
354
300
|
|
|
355
301
|
function createPlaygroundMiddleware(params) {
|
|
356
302
|
const distDir = resolvePlaygroundDist();
|
|
@@ -396,8 +342,8 @@ function createPlaygroundMiddleware(params) {
|
|
|
396
342
|
}
|
|
397
343
|
if (subPath === "/routes") {
|
|
398
344
|
const dirs = params.getDirs?.() ?? [];
|
|
399
|
-
const baseRoot = resolveGroupRoot(dirs, server?.config?.root);
|
|
400
|
-
const groups = resolveGroups(dirs, baseRoot);
|
|
345
|
+
const baseRoot = playgroundGrouping.resolveGroupRoot(dirs, server?.config?.root);
|
|
346
|
+
const groups = playgroundGrouping.resolveGroups(dirs, baseRoot);
|
|
401
347
|
const routes = params.getRoutes();
|
|
402
348
|
const disabledRoutes = params.getDisabledRoutes?.() ?? [];
|
|
403
349
|
const ignoredRoutes = params.getIgnoredRoutes?.() ?? [];
|
|
@@ -516,7 +462,7 @@ function resolveSwConfigFromEntries(entries, logger) {
|
|
|
516
462
|
}
|
|
517
463
|
continue;
|
|
518
464
|
}
|
|
519
|
-
const normalizedPrefix =
|
|
465
|
+
const normalizedPrefix = normalizePrefix(entry.prefix ?? "");
|
|
520
466
|
if (normalizedPrefix) {
|
|
521
467
|
basePaths.push(normalizedPrefix);
|
|
522
468
|
}
|
|
@@ -764,7 +710,7 @@ function createFinalizeMiddleware(route) {
|
|
|
764
710
|
const response = await next();
|
|
765
711
|
const resolved = resolveResponse(response, c.res);
|
|
766
712
|
if (route.delay && route.delay > 0) {
|
|
767
|
-
await
|
|
713
|
+
await timing.delay(route.delay);
|
|
768
714
|
}
|
|
769
715
|
const overridden = applyRouteOverrides(resolved, route);
|
|
770
716
|
c.res = overridden;
|
|
@@ -884,7 +830,7 @@ function createMiddleware(getApp, logger) {
|
|
|
884
830
|
const url = req.url ?? "/";
|
|
885
831
|
const parsedUrl = new URL(url, "http://mokup.local");
|
|
886
832
|
const pathname = parsedUrl.pathname;
|
|
887
|
-
const method =
|
|
833
|
+
const method = normalizeMethod(req.method) ?? "GET";
|
|
888
834
|
if (!hasMatch(app, method, pathname)) {
|
|
889
835
|
return next();
|
|
890
836
|
}
|
|
@@ -913,7 +859,7 @@ function resolveTemplate(template, prefix) {
|
|
|
913
859
|
if (!prefix) {
|
|
914
860
|
return normalized;
|
|
915
861
|
}
|
|
916
|
-
const normalizedPrefix =
|
|
862
|
+
const normalizedPrefix = normalizePrefix(prefix);
|
|
917
863
|
if (!normalizedPrefix) {
|
|
918
864
|
return normalized;
|
|
919
865
|
}
|
|
@@ -941,7 +887,7 @@ function stripMethodSuffix(base) {
|
|
|
941
887
|
};
|
|
942
888
|
}
|
|
943
889
|
function deriveRouteFromFile(file, rootDir, logger) {
|
|
944
|
-
const rel =
|
|
890
|
+
const rel = pathUtils.toPosix(pathe.relative(rootDir, file));
|
|
945
891
|
const ext = pathe.extname(rel);
|
|
946
892
|
const withoutExt = rel.slice(0, rel.length - ext.length);
|
|
947
893
|
const dir = pathe.dirname(withoutExt);
|
|
@@ -957,7 +903,7 @@ function deriveRouteFromFile(file, rootDir, logger) {
|
|
|
957
903
|
return null;
|
|
958
904
|
}
|
|
959
905
|
const joined = dir === "." ? name : pathe.join(dir, name);
|
|
960
|
-
const segments =
|
|
906
|
+
const segments = pathUtils.toPosix(joined).split("/");
|
|
961
907
|
if (segments.at(-1) === "index") {
|
|
962
908
|
segments.pop();
|
|
963
909
|
}
|
|
@@ -1062,29 +1008,29 @@ async function collectFiles(dirs) {
|
|
|
1062
1008
|
}
|
|
1063
1009
|
return files;
|
|
1064
1010
|
}
|
|
1065
|
-
function
|
|
1011
|
+
function isConfigFile(file) {
|
|
1066
1012
|
if (file.endsWith(".d.ts")) {
|
|
1067
1013
|
return false;
|
|
1068
1014
|
}
|
|
1069
|
-
|
|
1015
|
+
const base = pathe.basename(file);
|
|
1016
|
+
if (!base.startsWith("index.config.")) {
|
|
1070
1017
|
return false;
|
|
1071
1018
|
}
|
|
1072
1019
|
const ext = pathe.extname(file).toLowerCase();
|
|
1073
|
-
return manifest.
|
|
1020
|
+
return manifest.configExtensions.includes(ext);
|
|
1074
1021
|
}
|
|
1075
|
-
function
|
|
1022
|
+
function isSupportedFile(file) {
|
|
1076
1023
|
if (file.endsWith(".d.ts")) {
|
|
1077
1024
|
return false;
|
|
1078
1025
|
}
|
|
1079
|
-
|
|
1080
|
-
if (!base.startsWith("index.config.")) {
|
|
1026
|
+
if (isConfigFile(file)) {
|
|
1081
1027
|
return false;
|
|
1082
1028
|
}
|
|
1083
1029
|
const ext = pathe.extname(file).toLowerCase();
|
|
1084
|
-
return manifest.
|
|
1030
|
+
return manifest.supportedExtensions.has(ext);
|
|
1085
1031
|
}
|
|
1086
1032
|
|
|
1087
|
-
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))));
|
|
1088
1034
|
const mokupSourceEntry = pathe.resolve(sourceRoot, "../index.ts");
|
|
1089
1035
|
const mokupViteSourceEntry = pathe.resolve(sourceRoot, "../vite.ts");
|
|
1090
1036
|
const hasMokupSourceEntry = node_fs.existsSync(mokupSourceEntry);
|
|
@@ -1109,7 +1055,7 @@ const workspaceResolvePlugin = createWorkspaceResolvePlugin();
|
|
|
1109
1055
|
async function loadModule(file) {
|
|
1110
1056
|
const ext = pathe.extname(file).toLowerCase();
|
|
1111
1057
|
if (ext === ".cjs") {
|
|
1112
|
-
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)));
|
|
1113
1059
|
delete require$1.cache[file];
|
|
1114
1060
|
return require$1(file);
|
|
1115
1061
|
}
|
|
@@ -1504,7 +1450,7 @@ function runRoutePrechecks(params) {
|
|
|
1504
1450
|
source: configSources.enabled,
|
|
1505
1451
|
detail: config.enabled === false ? "enabled=false" : typeof config.enabled === "boolean" ? "enabled=true" : "enabled=true (default)"
|
|
1506
1452
|
});
|
|
1507
|
-
const effectiveIgnorePrefix = typeof config.ignorePrefix !== "undefined" ?
|
|
1453
|
+
const effectiveIgnorePrefix = typeof config.ignorePrefix !== "undefined" ? normalizeIgnorePrefix(config.ignorePrefix, []) : globalIgnorePrefix;
|
|
1508
1454
|
const effectiveInclude = typeof config.include !== "undefined" ? config.include : include;
|
|
1509
1455
|
const effectiveExclude = typeof config.exclude !== "undefined" ? config.exclude : exclude;
|
|
1510
1456
|
const effectiveConfigParams = {
|
|
@@ -1538,7 +1484,7 @@ function runRoutePrechecks(params) {
|
|
|
1538
1484
|
return null;
|
|
1539
1485
|
}
|
|
1540
1486
|
if (effectiveIgnorePrefix.length > 0) {
|
|
1541
|
-
const ignoredByPrefix =
|
|
1487
|
+
const ignoredByPrefix = pathUtils.hasIgnoredPrefix(fileInfo.file, fileInfo.rootDir, effectiveIgnorePrefix);
|
|
1542
1488
|
pushDecisionStep(decisionChain, {
|
|
1543
1489
|
step: "ignore-prefix",
|
|
1544
1490
|
result: ignoredByPrefix ? "fail" : "pass",
|
|
@@ -1585,7 +1531,7 @@ function runRoutePrechecks(params) {
|
|
|
1585
1531
|
}
|
|
1586
1532
|
return null;
|
|
1587
1533
|
}
|
|
1588
|
-
const normalizedFile =
|
|
1534
|
+
const normalizedFile = pathUtils.toPosix(fileInfo.file);
|
|
1589
1535
|
if (typeof effectiveExclude !== "undefined") {
|
|
1590
1536
|
const excluded = testPatterns(effectiveExclude, normalizedFile);
|
|
1591
1537
|
const patterns = toFilterStrings(effectiveExclude);
|
|
@@ -1653,7 +1599,7 @@ async function scanRoutes(params) {
|
|
|
1653
1599
|
const routes = [];
|
|
1654
1600
|
const seen = /* @__PURE__ */ new Set();
|
|
1655
1601
|
const files = await collectFiles(params.dirs);
|
|
1656
|
-
const globalIgnorePrefix =
|
|
1602
|
+
const globalIgnorePrefix = normalizeIgnorePrefix(params.ignorePrefix);
|
|
1657
1603
|
const configCache = /* @__PURE__ */ new Map();
|
|
1658
1604
|
const fileCache = /* @__PURE__ */ new Map();
|
|
1659
1605
|
const shouldCollectSkip = typeof params.onSkip === "function";
|
|
@@ -1831,8 +1777,7 @@ exports.createMiddleware = createMiddleware;
|
|
|
1831
1777
|
exports.createPlaygroundMiddleware = createPlaygroundMiddleware;
|
|
1832
1778
|
exports.injectPlaygroundSw = injectPlaygroundSw;
|
|
1833
1779
|
exports.normalizePlaygroundPath = normalizePlaygroundPath;
|
|
1834
|
-
exports.
|
|
1835
|
-
exports.resolveGroups = resolveGroups;
|
|
1780
|
+
exports.resolveDirs = resolveDirs;
|
|
1836
1781
|
exports.resolvePlaygroundDist = resolvePlaygroundDist;
|
|
1837
1782
|
exports.resolvePlaygroundOptions = resolvePlaygroundOptions;
|
|
1838
1783
|
exports.resolvePlaygroundRequestPath = resolvePlaygroundRequestPath;
|
|
@@ -1,15 +1,47 @@
|
|
|
1
1
|
import { promises, existsSync } from 'node:fs';
|
|
2
|
-
import {
|
|
2
|
+
import { resolve, isAbsolute, join, normalize, extname, relative, dirname, basename } from '@mokup/shared/pathe';
|
|
3
3
|
import { createRequire } from 'node:module';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import { resolveRouteGroup, formatRouteFile, resolveGroupRoot, resolveGroups } from '@mokup/shared/playground-grouping';
|
|
5
|
+
import { m as methodSet, t as toViteImportPath, b as buildManifestData, a as methodSuffixSet, c as configExtensions, s as supportedExtensions } from './mokup.Iqw32OxC.mjs';
|
|
6
6
|
import { Buffer } from 'node:buffer';
|
|
7
7
|
import { Hono, PatternRouter } from '@mokup/shared/hono';
|
|
8
|
+
import { delay } from '@mokup/shared/timing';
|
|
9
|
+
import { toPosix, hasIgnoredPrefix } from '@mokup/shared/path-utils';
|
|
8
10
|
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
9
11
|
import { build } from '@mokup/shared/esbuild';
|
|
10
12
|
import { parse } from '@mokup/shared/jsonc-parser';
|
|
11
13
|
import { compareRouteScore, parseRouteTemplate } from '@mokup/runtime';
|
|
12
14
|
|
|
15
|
+
function normalizeMethod(method) {
|
|
16
|
+
if (!method) {
|
|
17
|
+
return void 0;
|
|
18
|
+
}
|
|
19
|
+
const normalized = method.toUpperCase();
|
|
20
|
+
if (methodSet.has(normalized)) {
|
|
21
|
+
return normalized;
|
|
22
|
+
}
|
|
23
|
+
return void 0;
|
|
24
|
+
}
|
|
25
|
+
function normalizePrefix(prefix) {
|
|
26
|
+
if (!prefix) {
|
|
27
|
+
return "";
|
|
28
|
+
}
|
|
29
|
+
const normalized = prefix.startsWith("/") ? prefix : `/${prefix}`;
|
|
30
|
+
return normalized.endsWith("/") ? normalized.slice(0, -1) : normalized;
|
|
31
|
+
}
|
|
32
|
+
function resolveDirs(dir, root) {
|
|
33
|
+
const raw = typeof dir === "function" ? dir(root) : dir;
|
|
34
|
+
const resolved = Array.isArray(raw) ? raw : raw ? [raw] : ["mock"];
|
|
35
|
+
const normalized = resolved.map(
|
|
36
|
+
(entry) => isAbsolute(entry) ? entry : resolve(root, entry)
|
|
37
|
+
);
|
|
38
|
+
return Array.from(new Set(normalized));
|
|
39
|
+
}
|
|
40
|
+
function normalizeIgnorePrefix(value, fallback = ["."]) {
|
|
41
|
+
const list = typeof value === "undefined" ? fallback : Array.isArray(value) ? value : [value];
|
|
42
|
+
return list.filter((entry) => typeof entry === "string" && entry.length > 0);
|
|
43
|
+
}
|
|
44
|
+
|
|
13
45
|
const require$1 = createRequire(import.meta.url);
|
|
14
46
|
const mimeTypes = {
|
|
15
47
|
".html": "text/html; charset=utf-8",
|
|
@@ -76,92 +108,6 @@ function resolvePlaygroundOptions(playground) {
|
|
|
76
108
|
return { enabled: true, path: "/__mokup", build: false };
|
|
77
109
|
}
|
|
78
110
|
|
|
79
|
-
function toPosixPath(value) {
|
|
80
|
-
return value.replace(/\\/g, "/");
|
|
81
|
-
}
|
|
82
|
-
function normalizePath(value) {
|
|
83
|
-
return toPosixPath(normalize(value));
|
|
84
|
-
}
|
|
85
|
-
function isAncestor(parent, child) {
|
|
86
|
-
const normalizedParent = normalizePath(parent).replace(/\/$/, "");
|
|
87
|
-
const normalizedChild = normalizePath(child);
|
|
88
|
-
return normalizedChild === normalizedParent || normalizedChild.startsWith(`${normalizedParent}/`);
|
|
89
|
-
}
|
|
90
|
-
function resolveGroupRoot(dirs, serverRoot) {
|
|
91
|
-
if (!dirs || dirs.length === 0) {
|
|
92
|
-
return serverRoot ?? cwd();
|
|
93
|
-
}
|
|
94
|
-
if (serverRoot) {
|
|
95
|
-
const normalizedRoot = normalizePath(serverRoot);
|
|
96
|
-
const canUseRoot = dirs.every((dir) => isAncestor(normalizedRoot, dir));
|
|
97
|
-
if (canUseRoot) {
|
|
98
|
-
return normalizedRoot;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
if (dirs.length === 1) {
|
|
102
|
-
return normalizePath(dirname(dirs[0]));
|
|
103
|
-
}
|
|
104
|
-
let common = normalizePath(dirs[0]);
|
|
105
|
-
for (const dir of dirs.slice(1)) {
|
|
106
|
-
const normalizedDir = normalizePath(dir);
|
|
107
|
-
while (common && !isAncestor(common, normalizedDir)) {
|
|
108
|
-
const parent = normalizePath(dirname(common));
|
|
109
|
-
if (parent === common) {
|
|
110
|
-
break;
|
|
111
|
-
}
|
|
112
|
-
common = parent;
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
if (!common || common === "/") {
|
|
116
|
-
return serverRoot ?? cwd();
|
|
117
|
-
}
|
|
118
|
-
return common;
|
|
119
|
-
}
|
|
120
|
-
function resolveGroups(dirs, root) {
|
|
121
|
-
const groups = [];
|
|
122
|
-
const seen = /* @__PURE__ */ new Set();
|
|
123
|
-
for (const dir of dirs) {
|
|
124
|
-
const normalized = normalizePath(dir);
|
|
125
|
-
if (seen.has(normalized)) {
|
|
126
|
-
continue;
|
|
127
|
-
}
|
|
128
|
-
seen.add(normalized);
|
|
129
|
-
const rel = toPosixPath(relative(root, normalized));
|
|
130
|
-
const label = rel && !rel.startsWith("..") ? rel : normalized;
|
|
131
|
-
groups.push({
|
|
132
|
-
key: normalized,
|
|
133
|
-
label,
|
|
134
|
-
path: normalized
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
return groups;
|
|
138
|
-
}
|
|
139
|
-
function resolveRouteGroup(routeFile, groups) {
|
|
140
|
-
if (groups.length === 0) {
|
|
141
|
-
return void 0;
|
|
142
|
-
}
|
|
143
|
-
const normalizedFile = toPosixPath(normalize(routeFile));
|
|
144
|
-
let matched;
|
|
145
|
-
for (const group of groups) {
|
|
146
|
-
if (normalizedFile === group.path || normalizedFile.startsWith(`${group.path}/`)) {
|
|
147
|
-
if (!matched || group.path.length > matched.path.length) {
|
|
148
|
-
matched = group;
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
return matched;
|
|
153
|
-
}
|
|
154
|
-
function formatRouteFile(file, root) {
|
|
155
|
-
if (!root) {
|
|
156
|
-
return toPosixPath(file);
|
|
157
|
-
}
|
|
158
|
-
const rel = toPosixPath(relative(root, file));
|
|
159
|
-
if (!rel || rel.startsWith("..")) {
|
|
160
|
-
return toPosixPath(file);
|
|
161
|
-
}
|
|
162
|
-
return rel;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
111
|
function injectPlaygroundHmr(html, base) {
|
|
166
112
|
if (html.includes("mokup-playground-hmr")) {
|
|
167
113
|
return html;
|
|
@@ -273,6 +219,22 @@ function toPlaygroundRoute(route, root, groups) {
|
|
|
273
219
|
group: matchedGroup?.label
|
|
274
220
|
};
|
|
275
221
|
}
|
|
222
|
+
function formatDecisionChain(chain, root) {
|
|
223
|
+
return chain.map((entry) => {
|
|
224
|
+
const formatted = {
|
|
225
|
+
step: entry.step,
|
|
226
|
+
result: entry.result
|
|
227
|
+
};
|
|
228
|
+
if (typeof entry.detail !== "undefined") {
|
|
229
|
+
formatted.detail = entry.detail;
|
|
230
|
+
}
|
|
231
|
+
if (typeof entry.source !== "undefined") {
|
|
232
|
+
const source = entry.source;
|
|
233
|
+
formatted.source = source && isAbsolute(source) ? formatRouteFile(source, root) : source;
|
|
234
|
+
}
|
|
235
|
+
return formatted;
|
|
236
|
+
});
|
|
237
|
+
}
|
|
276
238
|
function toPlaygroundDisabledRoute(route, root, groups) {
|
|
277
239
|
const matchedGroup = resolveRouteGroup(route.file, groups);
|
|
278
240
|
const disabled = {
|
|
@@ -332,22 +294,6 @@ function toPlaygroundConfigFile(entry, root, groups) {
|
|
|
332
294
|
}
|
|
333
295
|
return configFile;
|
|
334
296
|
}
|
|
335
|
-
function formatDecisionChain(chain, root) {
|
|
336
|
-
return chain.map((entry) => {
|
|
337
|
-
const formatted = {
|
|
338
|
-
step: entry.step,
|
|
339
|
-
result: entry.result
|
|
340
|
-
};
|
|
341
|
-
if (typeof entry.detail !== "undefined") {
|
|
342
|
-
formatted.detail = entry.detail;
|
|
343
|
-
}
|
|
344
|
-
if (typeof entry.source !== "undefined") {
|
|
345
|
-
const source = entry.source;
|
|
346
|
-
formatted.source = source && isAbsolute(source) ? formatRouteFile(source, root) : source;
|
|
347
|
-
}
|
|
348
|
-
return formatted;
|
|
349
|
-
});
|
|
350
|
-
}
|
|
351
297
|
|
|
352
298
|
function createPlaygroundMiddleware(params) {
|
|
353
299
|
const distDir = resolvePlaygroundDist();
|
|
@@ -1059,26 +1005,26 @@ async function collectFiles(dirs) {
|
|
|
1059
1005
|
}
|
|
1060
1006
|
return files;
|
|
1061
1007
|
}
|
|
1062
|
-
function
|
|
1008
|
+
function isConfigFile(file) {
|
|
1063
1009
|
if (file.endsWith(".d.ts")) {
|
|
1064
1010
|
return false;
|
|
1065
1011
|
}
|
|
1066
|
-
|
|
1012
|
+
const base = basename(file);
|
|
1013
|
+
if (!base.startsWith("index.config.")) {
|
|
1067
1014
|
return false;
|
|
1068
1015
|
}
|
|
1069
1016
|
const ext = extname(file).toLowerCase();
|
|
1070
|
-
return
|
|
1017
|
+
return configExtensions.includes(ext);
|
|
1071
1018
|
}
|
|
1072
|
-
function
|
|
1019
|
+
function isSupportedFile(file) {
|
|
1073
1020
|
if (file.endsWith(".d.ts")) {
|
|
1074
1021
|
return false;
|
|
1075
1022
|
}
|
|
1076
|
-
|
|
1077
|
-
if (!base.startsWith("index.config.")) {
|
|
1023
|
+
if (isConfigFile(file)) {
|
|
1078
1024
|
return false;
|
|
1079
1025
|
}
|
|
1080
1026
|
const ext = extname(file).toLowerCase();
|
|
1081
|
-
return
|
|
1027
|
+
return supportedExtensions.has(ext);
|
|
1082
1028
|
}
|
|
1083
1029
|
|
|
1084
1030
|
const sourceRoot = dirname(fileURLToPath(import.meta.url));
|
|
@@ -1822,4 +1768,4 @@ async function scanRoutes(params) {
|
|
|
1822
1768
|
return sortRoutes(routes);
|
|
1823
1769
|
}
|
|
1824
1770
|
|
|
1825
|
-
export { sortRoutes as a, buildSwScript as b, createHonoApp as c,
|
|
1771
|
+
export { sortRoutes as a, buildSwScript as b, createHonoApp as c, resolvePlaygroundOptions as d, resolveSwConfig as e, resolveSwUnregisterConfig as f, createPlaygroundMiddleware as g, createMiddleware as h, resolvePlaygroundDist as i, injectPlaygroundSw as j, resolvePlaygroundRequestPath as k, toPlaygroundIgnoredRoute as l, toPlaygroundDisabledRoute as m, normalizePlaygroundPath as n, toPlaygroundRoute as o, resolveDirs as r, scanRoutes as s, toPlaygroundConfigFile as t };
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const pathe = require('@mokup/shared/pathe');
|
|
4
|
+
const pathUtils = require('@mokup/shared/path-utils');
|
|
5
|
+
require('@mokup/shared/timing');
|
|
4
6
|
|
|
5
7
|
const methodSet = /* @__PURE__ */ new Set([
|
|
6
8
|
"GET",
|
|
@@ -24,78 +26,13 @@ const supportedExtensions = /* @__PURE__ */ new Set([
|
|
|
24
26
|
]);
|
|
25
27
|
const configExtensions = [".ts", ".js", ".mjs", ".cjs"];
|
|
26
28
|
|
|
27
|
-
function normalizeMethod(method) {
|
|
28
|
-
if (!method) {
|
|
29
|
-
return void 0;
|
|
30
|
-
}
|
|
31
|
-
const normalized = method.toUpperCase();
|
|
32
|
-
if (methodSet.has(normalized)) {
|
|
33
|
-
return normalized;
|
|
34
|
-
}
|
|
35
|
-
return void 0;
|
|
36
|
-
}
|
|
37
|
-
function normalizePrefix(prefix) {
|
|
38
|
-
if (!prefix) {
|
|
39
|
-
return "";
|
|
40
|
-
}
|
|
41
|
-
const normalized = prefix.startsWith("/") ? prefix : `/${prefix}`;
|
|
42
|
-
return normalized.endsWith("/") ? normalized.slice(0, -1) : normalized;
|
|
43
|
-
}
|
|
44
|
-
function resolveDirs(dir, root) {
|
|
45
|
-
const raw = typeof dir === "function" ? dir(root) : dir;
|
|
46
|
-
const resolved = Array.isArray(raw) ? raw : raw ? [raw] : ["mock"];
|
|
47
|
-
const normalized = resolved.map(
|
|
48
|
-
(entry) => pathe.isAbsolute(entry) ? entry : pathe.resolve(root, entry)
|
|
49
|
-
);
|
|
50
|
-
return Array.from(new Set(normalized));
|
|
51
|
-
}
|
|
52
|
-
function createDebouncer(delayMs, fn) {
|
|
53
|
-
let timer = null;
|
|
54
|
-
return () => {
|
|
55
|
-
if (timer) {
|
|
56
|
-
clearTimeout(timer);
|
|
57
|
-
}
|
|
58
|
-
timer = setTimeout(() => {
|
|
59
|
-
timer = null;
|
|
60
|
-
fn();
|
|
61
|
-
}, delayMs);
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
function toPosix(value) {
|
|
65
|
-
return value.replace(/\\/g, "/");
|
|
66
|
-
}
|
|
67
|
-
function isInDirs(file, dirs) {
|
|
68
|
-
const normalized = toPosix(file);
|
|
69
|
-
return dirs.some((dir) => {
|
|
70
|
-
const normalizedDir = toPosix(dir).replace(/\/$/, "");
|
|
71
|
-
return normalized === normalizedDir || normalized.startsWith(`${normalizedDir}/`);
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
function normalizeIgnorePrefix(value, fallback = ["."]) {
|
|
75
|
-
const list = typeof value === "undefined" ? fallback : Array.isArray(value) ? value : [value];
|
|
76
|
-
return list.filter((entry) => typeof entry === "string" && entry.length > 0);
|
|
77
|
-
}
|
|
78
|
-
function hasIgnoredPrefix(file, rootDir, prefixes) {
|
|
79
|
-
if (prefixes.length === 0) {
|
|
80
|
-
return false;
|
|
81
|
-
}
|
|
82
|
-
const relativePath = toPosix(pathe.relative(rootDir, file));
|
|
83
|
-
const segments = relativePath.split("/");
|
|
84
|
-
return segments.some(
|
|
85
|
-
(segment) => prefixes.some((prefix) => segment.startsWith(prefix))
|
|
86
|
-
);
|
|
87
|
-
}
|
|
88
|
-
function delay(ms) {
|
|
89
|
-
return new Promise((resolve2) => setTimeout(resolve2, ms));
|
|
90
|
-
}
|
|
91
|
-
|
|
92
29
|
function toViteImportPath(file, root) {
|
|
93
30
|
const absolute = pathe.isAbsolute(file) ? file : pathe.resolve(root, file);
|
|
94
31
|
const rel = pathe.relative(root, absolute);
|
|
95
32
|
if (!rel.startsWith("..") && !pathe.isAbsolute(rel)) {
|
|
96
|
-
return `/${toPosix(rel)}`;
|
|
33
|
+
return `/${pathUtils.toPosix(rel)}`;
|
|
97
34
|
}
|
|
98
|
-
return `/@fs/${toPosix(absolute)}`;
|
|
35
|
+
return `/@fs/${pathUtils.toPosix(absolute)}`;
|
|
99
36
|
}
|
|
100
37
|
function shouldModuleize(handler) {
|
|
101
38
|
if (typeof handler === "function") {
|
|
@@ -238,15 +175,7 @@ function buildManifestData(params) {
|
|
|
238
175
|
|
|
239
176
|
exports.buildManifestData = buildManifestData;
|
|
240
177
|
exports.configExtensions = configExtensions;
|
|
241
|
-
exports.
|
|
242
|
-
exports.delay = delay;
|
|
243
|
-
exports.hasIgnoredPrefix = hasIgnoredPrefix;
|
|
244
|
-
exports.isInDirs = isInDirs;
|
|
178
|
+
exports.methodSet = methodSet;
|
|
245
179
|
exports.methodSuffixSet = methodSuffixSet;
|
|
246
|
-
exports.normalizeIgnorePrefix = normalizeIgnorePrefix;
|
|
247
|
-
exports.normalizeMethod = normalizeMethod;
|
|
248
|
-
exports.normalizePrefix = normalizePrefix;
|
|
249
|
-
exports.resolveDirs = resolveDirs;
|
|
250
180
|
exports.supportedExtensions = supportedExtensions;
|
|
251
|
-
exports.toPosix = toPosix;
|
|
252
181
|
exports.toViteImportPath = toViteImportPath;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isAbsolute, resolve, relative } from '@mokup/shared/pathe';
|
|
2
|
+
import { toPosix } from '@mokup/shared/path-utils';
|
|
3
|
+
import '@mokup/shared/timing';
|
|
2
4
|
|
|
3
5
|
const methodSet = /* @__PURE__ */ new Set([
|
|
4
6
|
"GET",
|
|
@@ -22,71 +24,6 @@ const supportedExtensions = /* @__PURE__ */ new Set([
|
|
|
22
24
|
]);
|
|
23
25
|
const configExtensions = [".ts", ".js", ".mjs", ".cjs"];
|
|
24
26
|
|
|
25
|
-
function normalizeMethod(method) {
|
|
26
|
-
if (!method) {
|
|
27
|
-
return void 0;
|
|
28
|
-
}
|
|
29
|
-
const normalized = method.toUpperCase();
|
|
30
|
-
if (methodSet.has(normalized)) {
|
|
31
|
-
return normalized;
|
|
32
|
-
}
|
|
33
|
-
return void 0;
|
|
34
|
-
}
|
|
35
|
-
function normalizePrefix(prefix) {
|
|
36
|
-
if (!prefix) {
|
|
37
|
-
return "";
|
|
38
|
-
}
|
|
39
|
-
const normalized = prefix.startsWith("/") ? prefix : `/${prefix}`;
|
|
40
|
-
return normalized.endsWith("/") ? normalized.slice(0, -1) : normalized;
|
|
41
|
-
}
|
|
42
|
-
function resolveDirs(dir, root) {
|
|
43
|
-
const raw = typeof dir === "function" ? dir(root) : dir;
|
|
44
|
-
const resolved = Array.isArray(raw) ? raw : raw ? [raw] : ["mock"];
|
|
45
|
-
const normalized = resolved.map(
|
|
46
|
-
(entry) => isAbsolute(entry) ? entry : resolve(root, entry)
|
|
47
|
-
);
|
|
48
|
-
return Array.from(new Set(normalized));
|
|
49
|
-
}
|
|
50
|
-
function createDebouncer(delayMs, fn) {
|
|
51
|
-
let timer = null;
|
|
52
|
-
return () => {
|
|
53
|
-
if (timer) {
|
|
54
|
-
clearTimeout(timer);
|
|
55
|
-
}
|
|
56
|
-
timer = setTimeout(() => {
|
|
57
|
-
timer = null;
|
|
58
|
-
fn();
|
|
59
|
-
}, delayMs);
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
function toPosix(value) {
|
|
63
|
-
return value.replace(/\\/g, "/");
|
|
64
|
-
}
|
|
65
|
-
function isInDirs(file, dirs) {
|
|
66
|
-
const normalized = toPosix(file);
|
|
67
|
-
return dirs.some((dir) => {
|
|
68
|
-
const normalizedDir = toPosix(dir).replace(/\/$/, "");
|
|
69
|
-
return normalized === normalizedDir || normalized.startsWith(`${normalizedDir}/`);
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
function normalizeIgnorePrefix(value, fallback = ["."]) {
|
|
73
|
-
const list = typeof value === "undefined" ? fallback : Array.isArray(value) ? value : [value];
|
|
74
|
-
return list.filter((entry) => typeof entry === "string" && entry.length > 0);
|
|
75
|
-
}
|
|
76
|
-
function hasIgnoredPrefix(file, rootDir, prefixes) {
|
|
77
|
-
if (prefixes.length === 0) {
|
|
78
|
-
return false;
|
|
79
|
-
}
|
|
80
|
-
const relativePath = toPosix(relative(rootDir, file));
|
|
81
|
-
const segments = relativePath.split("/");
|
|
82
|
-
return segments.some(
|
|
83
|
-
(segment) => prefixes.some((prefix) => segment.startsWith(prefix))
|
|
84
|
-
);
|
|
85
|
-
}
|
|
86
|
-
function delay(ms) {
|
|
87
|
-
return new Promise((resolve2) => setTimeout(resolve2, ms));
|
|
88
|
-
}
|
|
89
|
-
|
|
90
27
|
function toViteImportPath(file, root) {
|
|
91
28
|
const absolute = isAbsolute(file) ? file : resolve(root, file);
|
|
92
29
|
const rel = relative(root, absolute);
|
|
@@ -234,4 +171,4 @@ function buildManifestData(params) {
|
|
|
234
171
|
};
|
|
235
172
|
}
|
|
236
173
|
|
|
237
|
-
export {
|
|
174
|
+
export { methodSuffixSet as a, buildManifestData as b, configExtensions as c, methodSet as m, supportedExtensions as s, toViteImportPath as t };
|
package/dist/vite.cjs
CHANGED
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const process = require('node:process');
|
|
4
|
-
const bundle = require('./shared/mokup.
|
|
4
|
+
const bundle = require('./shared/mokup.BXPIIxtS.cjs');
|
|
5
5
|
const node_fs = require('node:fs');
|
|
6
6
|
const pathe = require('@mokup/shared/pathe');
|
|
7
|
-
const scanner = require('./shared/mokup.
|
|
7
|
+
const scanner = require('./shared/mokup.Cn9uLpN8.cjs');
|
|
8
|
+
const playgroundGrouping = require('@mokup/shared/playground-grouping');
|
|
8
9
|
const logger = require('@mokup/shared/logger');
|
|
9
|
-
const manifest = require('./shared/mokup.C7-7PDF7.cjs');
|
|
10
10
|
const pc = require('picocolors');
|
|
11
11
|
const node_path = require('node:path');
|
|
12
12
|
const chokidar = require('@mokup/shared/chokidar');
|
|
13
|
+
require('./shared/mokup.Dy9VDphS.cjs');
|
|
14
|
+
const pathUtils = require('@mokup/shared/path-utils');
|
|
15
|
+
const timing = require('@mokup/shared/timing');
|
|
13
16
|
const node_url = require('node:url');
|
|
14
17
|
require('node:module');
|
|
15
18
|
require('node:buffer');
|
|
@@ -36,8 +39,8 @@ function stripSwLifecycle(html) {
|
|
|
36
39
|
);
|
|
37
40
|
}
|
|
38
41
|
async function writeRoutesPayload(params, targetDir) {
|
|
39
|
-
const baseRoot =
|
|
40
|
-
const groups =
|
|
42
|
+
const baseRoot = playgroundGrouping.resolveGroupRoot(params.dirs, params.root);
|
|
43
|
+
const groups = playgroundGrouping.resolveGroups(params.dirs, baseRoot);
|
|
41
44
|
const basePath = scanner.resolvePlaygroundRequestPath(params.base, params.playgroundPath);
|
|
42
45
|
const payload = {
|
|
43
46
|
basePath,
|
|
@@ -237,7 +240,7 @@ function createRouteRefresher(params) {
|
|
|
237
240
|
const collectedIgnored = [];
|
|
238
241
|
const collectedConfigs = [];
|
|
239
242
|
for (const entry of optionList) {
|
|
240
|
-
const dirs =
|
|
243
|
+
const dirs = scanner.resolveDirs(entry.dir, root());
|
|
241
244
|
const scanParams = {
|
|
242
245
|
dirs,
|
|
243
246
|
prefix: entry.prefix ?? "",
|
|
@@ -304,7 +307,7 @@ function createDirResolver(optionList, root) {
|
|
|
304
307
|
const dirs = [];
|
|
305
308
|
const seen = /* @__PURE__ */ new Set();
|
|
306
309
|
for (const entry of optionList) {
|
|
307
|
-
for (const dir of
|
|
310
|
+
for (const dir of scanner.resolveDirs(entry.dir, root())) {
|
|
308
311
|
if (seen.has(dir)) {
|
|
309
312
|
continue;
|
|
310
313
|
}
|
|
@@ -461,12 +464,12 @@ function normalizeRawWatcherPath(rawPath) {
|
|
|
461
464
|
return "";
|
|
462
465
|
}
|
|
463
466
|
function setupViteWatchers(params) {
|
|
464
|
-
const scheduleRefresh =
|
|
467
|
+
const scheduleRefresh = timing.createDebouncer(80, () => {
|
|
465
468
|
void params.refresh();
|
|
466
469
|
});
|
|
467
470
|
const handleWatchedFile = (file) => {
|
|
468
471
|
const resolvedFile = normalizeWatcherFile(file, params.server.config.root ?? params.root);
|
|
469
|
-
if (
|
|
472
|
+
if (pathUtils.isInDirs(resolvedFile, params.dirs)) {
|
|
470
473
|
scheduleRefresh();
|
|
471
474
|
}
|
|
472
475
|
};
|
|
@@ -484,19 +487,19 @@ function setupViteWatchers(params) {
|
|
|
484
487
|
}
|
|
485
488
|
const baseDir = typeof details === "object" && details && "watchedPath" in details ? details.watchedPath ?? (params.server.config.root ?? params.root) : params.server.config.root ?? params.root;
|
|
486
489
|
const resolvedFile = normalizeWatcherFile(candidate, baseDir);
|
|
487
|
-
if (
|
|
490
|
+
if (pathUtils.isInDirs(resolvedFile, params.dirs)) {
|
|
488
491
|
scheduleRefresh();
|
|
489
492
|
}
|
|
490
493
|
});
|
|
491
494
|
}
|
|
492
495
|
function setupPreviewWatchers(params) {
|
|
493
496
|
const watcher = chokidar__default.watch(params.dirs, { ignoreInitial: true });
|
|
494
|
-
const scheduleRefresh =
|
|
497
|
+
const scheduleRefresh = timing.createDebouncer(80, () => {
|
|
495
498
|
void params.refresh();
|
|
496
499
|
});
|
|
497
500
|
const handleWatchedFile = (file) => {
|
|
498
501
|
const resolvedFile = normalizeWatcherFile(file, params.server.config.root ?? params.root);
|
|
499
|
-
if (
|
|
502
|
+
if (pathUtils.isInDirs(resolvedFile, params.dirs)) {
|
|
500
503
|
scheduleRefresh();
|
|
501
504
|
}
|
|
502
505
|
};
|
|
@@ -513,7 +516,7 @@ function setupPreviewWatchers(params) {
|
|
|
513
516
|
}
|
|
514
517
|
const baseDir = typeof details === "object" && details && "watchedPath" in details ? details.watchedPath ?? (params.server.config.root ?? params.root) : params.server.config.root ?? params.root;
|
|
515
518
|
const resolvedFile = normalizeWatcherFile(candidate, baseDir);
|
|
516
|
-
if (
|
|
519
|
+
if (pathUtils.isInDirs(resolvedFile, params.dirs)) {
|
|
517
520
|
scheduleRefresh();
|
|
518
521
|
}
|
|
519
522
|
});
|
package/dist/vite.mjs
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import { cwd } from 'node:process';
|
|
2
|
-
import { b as buildBundleModule } from './shared/mokup.
|
|
2
|
+
import { b as buildBundleModule } from './shared/mokup.CsBTglhs.mjs';
|
|
3
3
|
import { promises, existsSync } from 'node:fs';
|
|
4
4
|
import { join, normalize } from '@mokup/shared/pathe';
|
|
5
|
-
import {
|
|
5
|
+
import { i as resolvePlaygroundDist, n as normalizePlaygroundPath, j as injectPlaygroundSw, k as resolvePlaygroundRequestPath, t as toPlaygroundConfigFile, l as toPlaygroundIgnoredRoute, m as toPlaygroundDisabledRoute, o as toPlaygroundRoute, r as resolveDirs, s as scanRoutes, a as sortRoutes, c as createHonoApp, b as buildSwScript, h as createMiddleware, d as resolvePlaygroundOptions, e as resolveSwConfig, f as resolveSwUnregisterConfig, g as createPlaygroundMiddleware } from './shared/mokup.DJ2QlqTp.mjs';
|
|
6
|
+
import { resolveGroupRoot, resolveGroups } from '@mokup/shared/playground-grouping';
|
|
6
7
|
import { createLogger } from '@mokup/shared/logger';
|
|
7
|
-
import { r as resolveDirs, i as isInDirs, c as createDebouncer } from './shared/mokup.JBCzv4xR.mjs';
|
|
8
8
|
import pc from 'picocolors';
|
|
9
9
|
import { isAbsolute, resolve, dirname } from 'node:path';
|
|
10
10
|
import chokidar from '@mokup/shared/chokidar';
|
|
11
|
+
import './shared/mokup.Iqw32OxC.mjs';
|
|
12
|
+
import { isInDirs } from '@mokup/shared/path-utils';
|
|
13
|
+
import { createDebouncer } from '@mokup/shared/timing';
|
|
11
14
|
import { fileURLToPath } from 'node:url';
|
|
12
15
|
import 'node:module';
|
|
13
16
|
import 'node:buffer';
|
package/dist/webpack.cjs
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const process = require('node:process');
|
|
4
|
-
const scanner = require('./shared/mokup.
|
|
4
|
+
const scanner = require('./shared/mokup.Cn9uLpN8.cjs');
|
|
5
5
|
require('node:fs');
|
|
6
6
|
const pathe = require('@mokup/shared/pathe');
|
|
7
|
+
require('@mokup/shared/playground-grouping');
|
|
7
8
|
const logger = require('@mokup/shared/logger');
|
|
8
|
-
const manifest = require('./shared/mokup.C7-7PDF7.cjs');
|
|
9
9
|
const esbuild = require('@mokup/shared/esbuild');
|
|
10
10
|
const node_module = require('node:module');
|
|
11
|
+
require('./shared/mokup.Dy9VDphS.cjs');
|
|
12
|
+
const pathUtils = require('@mokup/shared/path-utils');
|
|
13
|
+
const timing = require('@mokup/shared/timing');
|
|
11
14
|
const chokidar = require('@mokup/shared/chokidar');
|
|
12
15
|
require('node:buffer');
|
|
13
16
|
require('@mokup/shared/hono');
|
|
@@ -256,7 +259,7 @@ function joinPublicPath(publicPath, fileName) {
|
|
|
256
259
|
}
|
|
257
260
|
function resolveModuleFilePath(file, root) {
|
|
258
261
|
const absolute = pathe.isAbsolute(file) ? file : pathe.resolve(root, file);
|
|
259
|
-
const normalized =
|
|
262
|
+
const normalized = pathUtils.toPosix(absolute);
|
|
260
263
|
if (/^[a-z]:\//i.test(normalized)) {
|
|
261
264
|
return `file:///${normalized}`;
|
|
262
265
|
}
|
|
@@ -274,7 +277,7 @@ function createRouteRefresher(params) {
|
|
|
274
277
|
const collectedConfigs = [];
|
|
275
278
|
for (const entry of optionList) {
|
|
276
279
|
const scanParams = {
|
|
277
|
-
dirs:
|
|
280
|
+
dirs: scanner.resolveDirs(entry.dir, root()),
|
|
278
281
|
prefix: entry.prefix ?? "",
|
|
279
282
|
logger,
|
|
280
283
|
onSkip: (info) => collectedDisabled.push(info),
|
|
@@ -319,21 +322,21 @@ function createWebpackWatcher(params) {
|
|
|
319
322
|
return null;
|
|
320
323
|
}
|
|
321
324
|
const watcher = chokidar__default.watch(params.dirs, { ignoreInitial: true });
|
|
322
|
-
const scheduleRefresh =
|
|
325
|
+
const scheduleRefresh = timing.createDebouncer(80, () => {
|
|
323
326
|
void params.onRefresh();
|
|
324
327
|
});
|
|
325
328
|
watcher.on("add", (file) => {
|
|
326
|
-
if (
|
|
329
|
+
if (pathUtils.isInDirs(file, params.dirs)) {
|
|
327
330
|
scheduleRefresh();
|
|
328
331
|
}
|
|
329
332
|
});
|
|
330
333
|
watcher.on("change", (file) => {
|
|
331
|
-
if (
|
|
334
|
+
if (pathUtils.isInDirs(file, params.dirs)) {
|
|
332
335
|
scheduleRefresh();
|
|
333
336
|
}
|
|
334
337
|
});
|
|
335
338
|
watcher.on("unlink", (file) => {
|
|
336
|
-
if (
|
|
339
|
+
if (pathUtils.isInDirs(file, params.dirs)) {
|
|
337
340
|
scheduleRefresh();
|
|
338
341
|
}
|
|
339
342
|
});
|
|
@@ -377,7 +380,7 @@ function createMokupWebpackPlugin(options = {}) {
|
|
|
377
380
|
const dirs = [];
|
|
378
381
|
const seen = /* @__PURE__ */ new Set();
|
|
379
382
|
for (const entry of optionList) {
|
|
380
|
-
for (const dir of
|
|
383
|
+
for (const dir of scanner.resolveDirs(entry.dir, root)) {
|
|
381
384
|
if (seen.has(dir)) {
|
|
382
385
|
continue;
|
|
383
386
|
}
|
package/dist/webpack.mjs
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import { cwd } from 'node:process';
|
|
2
|
-
import { b as buildSwScript, s as scanRoutes, a as sortRoutes, c as createHonoApp,
|
|
2
|
+
import { b as buildSwScript, r as resolveDirs, s as scanRoutes, a as sortRoutes, c as createHonoApp, d as resolvePlaygroundOptions, e as resolveSwConfig, f as resolveSwUnregisterConfig, g as createPlaygroundMiddleware, h as createMiddleware } from './shared/mokup.DJ2QlqTp.mjs';
|
|
3
3
|
import 'node:fs';
|
|
4
4
|
import { isAbsolute, resolve } from '@mokup/shared/pathe';
|
|
5
|
+
import '@mokup/shared/playground-grouping';
|
|
5
6
|
import { createLogger } from '@mokup/shared/logger';
|
|
6
|
-
import { t as toPosix, r as resolveDirs, i as isInDirs, c as createDebouncer } from './shared/mokup.JBCzv4xR.mjs';
|
|
7
7
|
import { build } from '@mokup/shared/esbuild';
|
|
8
8
|
import { createRequire } from 'node:module';
|
|
9
|
+
import './shared/mokup.Iqw32OxC.mjs';
|
|
10
|
+
import { toPosix, isInDirs } from '@mokup/shared/path-utils';
|
|
11
|
+
import { createDebouncer } from '@mokup/shared/timing';
|
|
9
12
|
import chokidar from '@mokup/shared/chokidar';
|
|
10
13
|
import 'node:buffer';
|
|
11
14
|
import '@mokup/shared/hono';
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mokup",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "2.2.
|
|
4
|
+
"version": "2.2.3",
|
|
5
5
|
"description": "Mock utilities and Vite plugin for mokup.",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"homepage": "https://mokup.icebreaker.top",
|
|
@@ -97,11 +97,11 @@
|
|
|
97
97
|
},
|
|
98
98
|
"dependencies": {
|
|
99
99
|
"picocolors": "^1.1.1",
|
|
100
|
-
"@mokup/cli": "1.0.
|
|
101
|
-
"@mokup/playground": "0.0.
|
|
102
|
-
"@mokup/runtime": "1.0.
|
|
103
|
-
"@mokup/server": "1.1.
|
|
104
|
-
"@mokup/shared": "1.1.
|
|
100
|
+
"@mokup/cli": "1.0.11",
|
|
101
|
+
"@mokup/playground": "0.0.15",
|
|
102
|
+
"@mokup/runtime": "1.0.6",
|
|
103
|
+
"@mokup/server": "1.1.8",
|
|
104
|
+
"@mokup/shared": "1.1.1"
|
|
105
105
|
},
|
|
106
106
|
"devDependencies": {
|
|
107
107
|
"@types/node": "^25.0.10",
|