mokup 2.2.0 → 2.2.1
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 +9 -0
- package/dist/bundle.d.cts +24 -0
- package/dist/bundle.d.mts +24 -0
- package/dist/bundle.d.ts +24 -0
- package/dist/bundle.mjs +3 -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.C7-7PDF7.cjs +252 -0
- package/dist/shared/{mokup.ClsvLg8n.mjs → mokup.CtSctWaa.mjs} +3 -236
- package/dist/shared/{mokup.CYGG6ENd.cjs → mokup.DLUSS6KF.cjs} +21 -259
- 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.JBCzv4xR.mjs +237 -0
- package/dist/shared/mokup.vAap-D_L.mjs +45 -0
- package/dist/shared/mokup.zkaN1ADs.cjs +47 -0
- package/dist/types/virtual.d.ts +2 -2
- package/dist/vite.cjs +12 -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 +3 -43
- package/dist/webpack.cjs +9 -8
- 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 +2 -1
- package/package.json +9 -4
package/dist/bundle.cjs
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { R as RouteTable } from './shared/mokup.DeotZ0g8.cjs';
|
|
2
|
+
export { a as ResolvedRoute } from './shared/mokup.DeotZ0g8.cjs';
|
|
3
|
+
import '@mokup/runtime';
|
|
4
|
+
import '@mokup/shared';
|
|
5
|
+
import '@mokup/shared/hono';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Build the source for a virtual mokup bundle module.
|
|
9
|
+
*
|
|
10
|
+
* @param params - Bundle build parameters.
|
|
11
|
+
* @returns JavaScript source string.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* import { buildBundleModule } from 'mokup/bundle'
|
|
15
|
+
*
|
|
16
|
+
* const source = buildBundleModule({ routes: [], root: '/project' })
|
|
17
|
+
*/
|
|
18
|
+
declare function buildBundleModule(params: {
|
|
19
|
+
routes: RouteTable;
|
|
20
|
+
root: string;
|
|
21
|
+
resolveModulePath?: (file: string, root: string) => string;
|
|
22
|
+
}): string;
|
|
23
|
+
|
|
24
|
+
export { RouteTable, buildBundleModule };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { R as RouteTable } from './shared/mokup.DeotZ0g8.mjs';
|
|
2
|
+
export { a as ResolvedRoute } from './shared/mokup.DeotZ0g8.mjs';
|
|
3
|
+
import '@mokup/runtime';
|
|
4
|
+
import '@mokup/shared';
|
|
5
|
+
import '@mokup/shared/hono';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Build the source for a virtual mokup bundle module.
|
|
9
|
+
*
|
|
10
|
+
* @param params - Bundle build parameters.
|
|
11
|
+
* @returns JavaScript source string.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* import { buildBundleModule } from 'mokup/bundle'
|
|
15
|
+
*
|
|
16
|
+
* const source = buildBundleModule({ routes: [], root: '/project' })
|
|
17
|
+
*/
|
|
18
|
+
declare function buildBundleModule(params: {
|
|
19
|
+
routes: RouteTable;
|
|
20
|
+
root: string;
|
|
21
|
+
resolveModulePath?: (file: string, root: string) => string;
|
|
22
|
+
}): string;
|
|
23
|
+
|
|
24
|
+
export { RouteTable, buildBundleModule };
|
package/dist/bundle.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { R as RouteTable } from './shared/mokup.DeotZ0g8.js';
|
|
2
|
+
export { a as ResolvedRoute } from './shared/mokup.DeotZ0g8.js';
|
|
3
|
+
import '@mokup/runtime';
|
|
4
|
+
import '@mokup/shared';
|
|
5
|
+
import '@mokup/shared/hono';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Build the source for a virtual mokup bundle module.
|
|
9
|
+
*
|
|
10
|
+
* @param params - Bundle build parameters.
|
|
11
|
+
* @returns JavaScript source string.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* import { buildBundleModule } from 'mokup/bundle'
|
|
15
|
+
*
|
|
16
|
+
* const source = buildBundleModule({ routes: [], root: '/project' })
|
|
17
|
+
*/
|
|
18
|
+
declare function buildBundleModule(params: {
|
|
19
|
+
routes: RouteTable;
|
|
20
|
+
root: string;
|
|
21
|
+
resolveModulePath?: (file: string, root: string) => string;
|
|
22
|
+
}): string;
|
|
23
|
+
|
|
24
|
+
export { RouteTable, buildBundleModule };
|
package/dist/bundle.mjs
ADDED
package/dist/index.d.cts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { H as HttpMethod,
|
|
1
|
+
import { e as RouteDirectoryConfig, c as MiddlewareRegistry, d as RequestHandler, g as RouteRule } from './shared/mokup.DeotZ0g8.cjs';
|
|
2
|
+
export { H as HttpMethod, b as MiddlewarePosition, M as MokupPluginOptions, f as RouteResponse, h as RuntimeMode, S as ServiceWorkerOptions, V as VitePluginOptions, i as VitePluginOptionsInput } from './shared/mokup.DeotZ0g8.cjs';
|
|
3
3
|
export { Context, MiddlewareHandler } from '@mokup/shared/hono';
|
|
4
4
|
export { PlaygroundOptionsInput } from '@mokup/shared';
|
|
5
|
+
import '@mokup/runtime';
|
|
5
6
|
|
|
6
7
|
type DefineConfigFactory = (context: {
|
|
7
8
|
pre: MiddlewareRegistry;
|
package/dist/index.d.mts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { H as HttpMethod,
|
|
1
|
+
import { e as RouteDirectoryConfig, c as MiddlewareRegistry, d as RequestHandler, g as RouteRule } from './shared/mokup.DeotZ0g8.mjs';
|
|
2
|
+
export { H as HttpMethod, b as MiddlewarePosition, M as MokupPluginOptions, f as RouteResponse, h as RuntimeMode, S as ServiceWorkerOptions, V as VitePluginOptions, i as VitePluginOptionsInput } from './shared/mokup.DeotZ0g8.mjs';
|
|
3
3
|
export { Context, MiddlewareHandler } from '@mokup/shared/hono';
|
|
4
4
|
export { PlaygroundOptionsInput } from '@mokup/shared';
|
|
5
|
+
import '@mokup/runtime';
|
|
5
6
|
|
|
6
7
|
type DefineConfigFactory = (context: {
|
|
7
8
|
pre: MiddlewareRegistry;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
/// <reference path="./types/virtual.d.ts" />
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
export { H as HttpMethod,
|
|
3
|
+
import { e as RouteDirectoryConfig, c as MiddlewareRegistry, d as RequestHandler, g as RouteRule } from './shared/mokup.DeotZ0g8.js';
|
|
4
|
+
export { H as HttpMethod, b as MiddlewarePosition, M as MokupPluginOptions, f as RouteResponse, h as RuntimeMode, S as ServiceWorkerOptions, V as VitePluginOptions, i as VitePluginOptionsInput } from './shared/mokup.DeotZ0g8.js';
|
|
5
5
|
export { Context, MiddlewareHandler } from '@mokup/shared/hono';
|
|
6
6
|
export { PlaygroundOptionsInput } from '@mokup/shared';
|
|
7
|
+
import '@mokup/runtime';
|
|
7
8
|
|
|
8
9
|
type DefineConfigFactory = (context: {
|
|
9
10
|
pre: MiddlewareRegistry;
|
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const pathe = require('@mokup/shared/pathe');
|
|
4
|
+
|
|
5
|
+
const methodSet = /* @__PURE__ */ new Set([
|
|
6
|
+
"GET",
|
|
7
|
+
"POST",
|
|
8
|
+
"PUT",
|
|
9
|
+
"PATCH",
|
|
10
|
+
"DELETE",
|
|
11
|
+
"OPTIONS",
|
|
12
|
+
"HEAD"
|
|
13
|
+
]);
|
|
14
|
+
const methodSuffixSet = new Set(
|
|
15
|
+
Array.from(methodSet, (method) => method.toLowerCase())
|
|
16
|
+
);
|
|
17
|
+
const supportedExtensions = /* @__PURE__ */ new Set([
|
|
18
|
+
".json",
|
|
19
|
+
".jsonc",
|
|
20
|
+
".ts",
|
|
21
|
+
".js",
|
|
22
|
+
".mjs",
|
|
23
|
+
".cjs"
|
|
24
|
+
]);
|
|
25
|
+
const configExtensions = [".ts", ".js", ".mjs", ".cjs"];
|
|
26
|
+
|
|
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
|
+
function toViteImportPath(file, root) {
|
|
93
|
+
const absolute = pathe.isAbsolute(file) ? file : pathe.resolve(root, file);
|
|
94
|
+
const rel = pathe.relative(root, absolute);
|
|
95
|
+
if (!rel.startsWith("..") && !pathe.isAbsolute(rel)) {
|
|
96
|
+
return `/${toPosix(rel)}`;
|
|
97
|
+
}
|
|
98
|
+
return `/@fs/${toPosix(absolute)}`;
|
|
99
|
+
}
|
|
100
|
+
function shouldModuleize(handler) {
|
|
101
|
+
if (typeof handler === "function") {
|
|
102
|
+
return true;
|
|
103
|
+
}
|
|
104
|
+
if (typeof Response !== "undefined" && handler instanceof Response) {
|
|
105
|
+
return true;
|
|
106
|
+
}
|
|
107
|
+
return false;
|
|
108
|
+
}
|
|
109
|
+
const BASE64_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
110
|
+
function getNodeBuffer() {
|
|
111
|
+
if (typeof globalThis === "undefined") {
|
|
112
|
+
return null;
|
|
113
|
+
}
|
|
114
|
+
const buffer = globalThis.Buffer;
|
|
115
|
+
return buffer ?? null;
|
|
116
|
+
}
|
|
117
|
+
function getBtoa() {
|
|
118
|
+
if (typeof globalThis === "undefined") {
|
|
119
|
+
return null;
|
|
120
|
+
}
|
|
121
|
+
const btoaFn = globalThis.btoa;
|
|
122
|
+
return typeof btoaFn === "function" ? btoaFn : null;
|
|
123
|
+
}
|
|
124
|
+
function encodeBase64(bytes) {
|
|
125
|
+
const buffer = getNodeBuffer();
|
|
126
|
+
if (buffer) {
|
|
127
|
+
return buffer.from(bytes).toString("base64");
|
|
128
|
+
}
|
|
129
|
+
const btoaFn = getBtoa();
|
|
130
|
+
if (btoaFn) {
|
|
131
|
+
let binary = "";
|
|
132
|
+
const chunkSize = 32768;
|
|
133
|
+
for (let i = 0; i < bytes.length; i += chunkSize) {
|
|
134
|
+
const chunk = bytes.subarray(i, i + chunkSize);
|
|
135
|
+
binary += String.fromCharCode(...chunk);
|
|
136
|
+
}
|
|
137
|
+
return btoaFn(binary);
|
|
138
|
+
}
|
|
139
|
+
let output = "";
|
|
140
|
+
for (let i = 0; i < bytes.length; i += 3) {
|
|
141
|
+
const a = bytes[i] ?? 0;
|
|
142
|
+
const b = i + 1 < bytes.length ? bytes[i + 1] ?? 0 : 0;
|
|
143
|
+
const c = i + 2 < bytes.length ? bytes[i + 2] ?? 0 : 0;
|
|
144
|
+
const triple = a << 16 | b << 8 | c;
|
|
145
|
+
output += BASE64_ALPHABET[triple >> 18 & 63];
|
|
146
|
+
output += BASE64_ALPHABET[triple >> 12 & 63];
|
|
147
|
+
output += i + 1 < bytes.length ? BASE64_ALPHABET[triple >> 6 & 63] : "=";
|
|
148
|
+
output += i + 2 < bytes.length ? BASE64_ALPHABET[triple & 63] : "=";
|
|
149
|
+
}
|
|
150
|
+
return output;
|
|
151
|
+
}
|
|
152
|
+
function toBinaryBody(handler) {
|
|
153
|
+
if (handler instanceof ArrayBuffer) {
|
|
154
|
+
return encodeBase64(new Uint8Array(handler));
|
|
155
|
+
}
|
|
156
|
+
if (handler instanceof Uint8Array) {
|
|
157
|
+
return encodeBase64(handler);
|
|
158
|
+
}
|
|
159
|
+
return null;
|
|
160
|
+
}
|
|
161
|
+
function buildManifestResponse(route, moduleId) {
|
|
162
|
+
if (moduleId) {
|
|
163
|
+
const response = {
|
|
164
|
+
type: "module",
|
|
165
|
+
module: moduleId
|
|
166
|
+
};
|
|
167
|
+
if (typeof route.ruleIndex === "number") {
|
|
168
|
+
response.ruleIndex = route.ruleIndex;
|
|
169
|
+
}
|
|
170
|
+
return response;
|
|
171
|
+
}
|
|
172
|
+
const handler = route.handler;
|
|
173
|
+
if (typeof handler === "string") {
|
|
174
|
+
return {
|
|
175
|
+
type: "text",
|
|
176
|
+
body: handler
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
const binary = toBinaryBody(handler);
|
|
180
|
+
if (binary) {
|
|
181
|
+
return {
|
|
182
|
+
type: "binary",
|
|
183
|
+
body: binary,
|
|
184
|
+
encoding: "base64"
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
return {
|
|
188
|
+
type: "json",
|
|
189
|
+
body: handler
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
function buildManifestData(params) {
|
|
193
|
+
const { routes, root } = params;
|
|
194
|
+
const resolveModulePath = params.resolveModulePath ?? toViteImportPath;
|
|
195
|
+
const ruleModules = /* @__PURE__ */ new Map();
|
|
196
|
+
const middlewareModules = /* @__PURE__ */ new Map();
|
|
197
|
+
const manifestRoutes = routes.map((route) => {
|
|
198
|
+
const moduleId = shouldModuleize(route.handler) ? resolveModulePath(route.file, root) : null;
|
|
199
|
+
if (moduleId && !ruleModules.has(moduleId)) {
|
|
200
|
+
ruleModules.set(moduleId, { id: moduleId, kind: "rule" });
|
|
201
|
+
}
|
|
202
|
+
const middleware = route.middlewares?.map((entry) => {
|
|
203
|
+
const modulePath = resolveModulePath(entry.source, root);
|
|
204
|
+
if (!middlewareModules.has(modulePath)) {
|
|
205
|
+
middlewareModules.set(modulePath, { id: modulePath, kind: "middleware" });
|
|
206
|
+
}
|
|
207
|
+
return {
|
|
208
|
+
module: modulePath,
|
|
209
|
+
ruleIndex: entry.index
|
|
210
|
+
};
|
|
211
|
+
});
|
|
212
|
+
const response = buildManifestResponse(route, moduleId);
|
|
213
|
+
const manifestRoute = {
|
|
214
|
+
method: route.method,
|
|
215
|
+
url: route.template,
|
|
216
|
+
...route.tokens ? { tokens: route.tokens } : {},
|
|
217
|
+
...route.score ? { score: route.score } : {},
|
|
218
|
+
...route.status ? { status: route.status } : {},
|
|
219
|
+
...route.headers ? { headers: route.headers } : {},
|
|
220
|
+
...route.delay ? { delay: route.delay } : {},
|
|
221
|
+
...middleware && middleware.length > 0 ? { middleware } : {},
|
|
222
|
+
response
|
|
223
|
+
};
|
|
224
|
+
return manifestRoute;
|
|
225
|
+
});
|
|
226
|
+
const manifest = {
|
|
227
|
+
version: 1,
|
|
228
|
+
routes: manifestRoutes
|
|
229
|
+
};
|
|
230
|
+
return {
|
|
231
|
+
manifest,
|
|
232
|
+
modules: [
|
|
233
|
+
...ruleModules.values(),
|
|
234
|
+
...middlewareModules.values()
|
|
235
|
+
]
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
exports.buildManifestData = buildManifestData;
|
|
240
|
+
exports.configExtensions = configExtensions;
|
|
241
|
+
exports.createDebouncer = createDebouncer;
|
|
242
|
+
exports.delay = delay;
|
|
243
|
+
exports.hasIgnoredPrefix = hasIgnoredPrefix;
|
|
244
|
+
exports.isInDirs = isInDirs;
|
|
245
|
+
exports.methodSuffixSet = methodSuffixSet;
|
|
246
|
+
exports.normalizeIgnorePrefix = normalizeIgnorePrefix;
|
|
247
|
+
exports.normalizeMethod = normalizeMethod;
|
|
248
|
+
exports.normalizePrefix = normalizePrefix;
|
|
249
|
+
exports.resolveDirs = resolveDirs;
|
|
250
|
+
exports.supportedExtensions = supportedExtensions;
|
|
251
|
+
exports.toPosix = toPosix;
|
|
252
|
+
exports.toViteImportPath = toViteImportPath;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { promises, existsSync } from 'node:fs';
|
|
2
|
-
import {
|
|
2
|
+
import { join, dirname, relative, normalize, isAbsolute, extname, basename, resolve } from '@mokup/shared/pathe';
|
|
3
3
|
import { createRequire } from 'node:module';
|
|
4
4
|
import { cwd } from 'node:process';
|
|
5
|
+
import { a as toViteImportPath, b as buildManifestData, n as normalizePrefix, d as normalizeMethod, e as delay, t as toPosix, m as methodSuffixSet, f as configExtensions, s as supportedExtensions, g as normalizeIgnorePrefix, h as hasIgnoredPrefix } from './mokup.JBCzv4xR.mjs';
|
|
5
6
|
import { Buffer } from 'node:buffer';
|
|
6
7
|
import { Hono, PatternRouter } from '@mokup/shared/hono';
|
|
7
8
|
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
@@ -9,240 +10,6 @@ import { build } from '@mokup/shared/esbuild';
|
|
|
9
10
|
import { parse } from '@mokup/shared/jsonc-parser';
|
|
10
11
|
import { compareRouteScore, parseRouteTemplate } from '@mokup/runtime';
|
|
11
12
|
|
|
12
|
-
const methodSet = /* @__PURE__ */ new Set([
|
|
13
|
-
"GET",
|
|
14
|
-
"POST",
|
|
15
|
-
"PUT",
|
|
16
|
-
"PATCH",
|
|
17
|
-
"DELETE",
|
|
18
|
-
"OPTIONS",
|
|
19
|
-
"HEAD"
|
|
20
|
-
]);
|
|
21
|
-
const methodSuffixSet = new Set(
|
|
22
|
-
Array.from(methodSet, (method) => method.toLowerCase())
|
|
23
|
-
);
|
|
24
|
-
const supportedExtensions = /* @__PURE__ */ new Set([
|
|
25
|
-
".json",
|
|
26
|
-
".jsonc",
|
|
27
|
-
".ts",
|
|
28
|
-
".js",
|
|
29
|
-
".mjs",
|
|
30
|
-
".cjs"
|
|
31
|
-
]);
|
|
32
|
-
const configExtensions = [".ts", ".js", ".mjs", ".cjs"];
|
|
33
|
-
|
|
34
|
-
function normalizeMethod(method) {
|
|
35
|
-
if (!method) {
|
|
36
|
-
return void 0;
|
|
37
|
-
}
|
|
38
|
-
const normalized = method.toUpperCase();
|
|
39
|
-
if (methodSet.has(normalized)) {
|
|
40
|
-
return normalized;
|
|
41
|
-
}
|
|
42
|
-
return void 0;
|
|
43
|
-
}
|
|
44
|
-
function normalizePrefix(prefix) {
|
|
45
|
-
if (!prefix) {
|
|
46
|
-
return "";
|
|
47
|
-
}
|
|
48
|
-
const normalized = prefix.startsWith("/") ? prefix : `/${prefix}`;
|
|
49
|
-
return normalized.endsWith("/") ? normalized.slice(0, -1) : normalized;
|
|
50
|
-
}
|
|
51
|
-
function resolveDirs(dir, root) {
|
|
52
|
-
const raw = typeof dir === "function" ? dir(root) : dir;
|
|
53
|
-
const resolved = Array.isArray(raw) ? raw : raw ? [raw] : ["mock"];
|
|
54
|
-
const normalized = resolved.map(
|
|
55
|
-
(entry) => isAbsolute(entry) ? entry : resolve(root, entry)
|
|
56
|
-
);
|
|
57
|
-
return Array.from(new Set(normalized));
|
|
58
|
-
}
|
|
59
|
-
function createDebouncer(delayMs, fn) {
|
|
60
|
-
let timer = null;
|
|
61
|
-
return () => {
|
|
62
|
-
if (timer) {
|
|
63
|
-
clearTimeout(timer);
|
|
64
|
-
}
|
|
65
|
-
timer = setTimeout(() => {
|
|
66
|
-
timer = null;
|
|
67
|
-
fn();
|
|
68
|
-
}, delayMs);
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
function toPosix(value) {
|
|
72
|
-
return value.replace(/\\/g, "/");
|
|
73
|
-
}
|
|
74
|
-
function isInDirs(file, dirs) {
|
|
75
|
-
const normalized = toPosix(file);
|
|
76
|
-
return dirs.some((dir) => {
|
|
77
|
-
const normalizedDir = toPosix(dir).replace(/\/$/, "");
|
|
78
|
-
return normalized === normalizedDir || normalized.startsWith(`${normalizedDir}/`);
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
function normalizeIgnorePrefix(value, fallback = ["."]) {
|
|
82
|
-
const list = typeof value === "undefined" ? fallback : Array.isArray(value) ? value : [value];
|
|
83
|
-
return list.filter((entry) => typeof entry === "string" && entry.length > 0);
|
|
84
|
-
}
|
|
85
|
-
function hasIgnoredPrefix(file, rootDir, prefixes) {
|
|
86
|
-
if (prefixes.length === 0) {
|
|
87
|
-
return false;
|
|
88
|
-
}
|
|
89
|
-
const relativePath = toPosix(relative(rootDir, file));
|
|
90
|
-
const segments = relativePath.split("/");
|
|
91
|
-
return segments.some(
|
|
92
|
-
(segment) => prefixes.some((prefix) => segment.startsWith(prefix))
|
|
93
|
-
);
|
|
94
|
-
}
|
|
95
|
-
function delay(ms) {
|
|
96
|
-
return new Promise((resolve2) => setTimeout(resolve2, ms));
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
function toViteImportPath(file, root) {
|
|
100
|
-
const absolute = isAbsolute(file) ? file : resolve(root, file);
|
|
101
|
-
const rel = relative(root, absolute);
|
|
102
|
-
if (!rel.startsWith("..") && !isAbsolute(rel)) {
|
|
103
|
-
return `/${toPosix(rel)}`;
|
|
104
|
-
}
|
|
105
|
-
return `/@fs/${toPosix(absolute)}`;
|
|
106
|
-
}
|
|
107
|
-
function shouldModuleize(handler) {
|
|
108
|
-
if (typeof handler === "function") {
|
|
109
|
-
return true;
|
|
110
|
-
}
|
|
111
|
-
if (typeof Response !== "undefined" && handler instanceof Response) {
|
|
112
|
-
return true;
|
|
113
|
-
}
|
|
114
|
-
return false;
|
|
115
|
-
}
|
|
116
|
-
const BASE64_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
117
|
-
function getNodeBuffer() {
|
|
118
|
-
if (typeof globalThis === "undefined") {
|
|
119
|
-
return null;
|
|
120
|
-
}
|
|
121
|
-
const buffer = globalThis.Buffer;
|
|
122
|
-
return buffer ?? null;
|
|
123
|
-
}
|
|
124
|
-
function getBtoa() {
|
|
125
|
-
if (typeof globalThis === "undefined") {
|
|
126
|
-
return null;
|
|
127
|
-
}
|
|
128
|
-
const btoaFn = globalThis.btoa;
|
|
129
|
-
return typeof btoaFn === "function" ? btoaFn : null;
|
|
130
|
-
}
|
|
131
|
-
function encodeBase64(bytes) {
|
|
132
|
-
const buffer = getNodeBuffer();
|
|
133
|
-
if (buffer) {
|
|
134
|
-
return buffer.from(bytes).toString("base64");
|
|
135
|
-
}
|
|
136
|
-
const btoaFn = getBtoa();
|
|
137
|
-
if (btoaFn) {
|
|
138
|
-
let binary = "";
|
|
139
|
-
const chunkSize = 32768;
|
|
140
|
-
for (let i = 0; i < bytes.length; i += chunkSize) {
|
|
141
|
-
const chunk = bytes.subarray(i, i + chunkSize);
|
|
142
|
-
binary += String.fromCharCode(...chunk);
|
|
143
|
-
}
|
|
144
|
-
return btoaFn(binary);
|
|
145
|
-
}
|
|
146
|
-
let output = "";
|
|
147
|
-
for (let i = 0; i < bytes.length; i += 3) {
|
|
148
|
-
const a = bytes[i] ?? 0;
|
|
149
|
-
const b = i + 1 < bytes.length ? bytes[i + 1] ?? 0 : 0;
|
|
150
|
-
const c = i + 2 < bytes.length ? bytes[i + 2] ?? 0 : 0;
|
|
151
|
-
const triple = a << 16 | b << 8 | c;
|
|
152
|
-
output += BASE64_ALPHABET[triple >> 18 & 63];
|
|
153
|
-
output += BASE64_ALPHABET[triple >> 12 & 63];
|
|
154
|
-
output += i + 1 < bytes.length ? BASE64_ALPHABET[triple >> 6 & 63] : "=";
|
|
155
|
-
output += i + 2 < bytes.length ? BASE64_ALPHABET[triple & 63] : "=";
|
|
156
|
-
}
|
|
157
|
-
return output;
|
|
158
|
-
}
|
|
159
|
-
function toBinaryBody(handler) {
|
|
160
|
-
if (handler instanceof ArrayBuffer) {
|
|
161
|
-
return encodeBase64(new Uint8Array(handler));
|
|
162
|
-
}
|
|
163
|
-
if (handler instanceof Uint8Array) {
|
|
164
|
-
return encodeBase64(handler);
|
|
165
|
-
}
|
|
166
|
-
return null;
|
|
167
|
-
}
|
|
168
|
-
function buildManifestResponse(route, moduleId) {
|
|
169
|
-
if (moduleId) {
|
|
170
|
-
const response = {
|
|
171
|
-
type: "module",
|
|
172
|
-
module: moduleId
|
|
173
|
-
};
|
|
174
|
-
if (typeof route.ruleIndex === "number") {
|
|
175
|
-
response.ruleIndex = route.ruleIndex;
|
|
176
|
-
}
|
|
177
|
-
return response;
|
|
178
|
-
}
|
|
179
|
-
const handler = route.handler;
|
|
180
|
-
if (typeof handler === "string") {
|
|
181
|
-
return {
|
|
182
|
-
type: "text",
|
|
183
|
-
body: handler
|
|
184
|
-
};
|
|
185
|
-
}
|
|
186
|
-
const binary = toBinaryBody(handler);
|
|
187
|
-
if (binary) {
|
|
188
|
-
return {
|
|
189
|
-
type: "binary",
|
|
190
|
-
body: binary,
|
|
191
|
-
encoding: "base64"
|
|
192
|
-
};
|
|
193
|
-
}
|
|
194
|
-
return {
|
|
195
|
-
type: "json",
|
|
196
|
-
body: handler
|
|
197
|
-
};
|
|
198
|
-
}
|
|
199
|
-
function buildManifestData(params) {
|
|
200
|
-
const { routes, root } = params;
|
|
201
|
-
const resolveModulePath = params.resolveModulePath ?? toViteImportPath;
|
|
202
|
-
const ruleModules = /* @__PURE__ */ new Map();
|
|
203
|
-
const middlewareModules = /* @__PURE__ */ new Map();
|
|
204
|
-
const manifestRoutes = routes.map((route) => {
|
|
205
|
-
const moduleId = shouldModuleize(route.handler) ? resolveModulePath(route.file, root) : null;
|
|
206
|
-
if (moduleId && !ruleModules.has(moduleId)) {
|
|
207
|
-
ruleModules.set(moduleId, { id: moduleId, kind: "rule" });
|
|
208
|
-
}
|
|
209
|
-
const middleware = route.middlewares?.map((entry) => {
|
|
210
|
-
const modulePath = resolveModulePath(entry.source, root);
|
|
211
|
-
if (!middlewareModules.has(modulePath)) {
|
|
212
|
-
middlewareModules.set(modulePath, { id: modulePath, kind: "middleware" });
|
|
213
|
-
}
|
|
214
|
-
return {
|
|
215
|
-
module: modulePath,
|
|
216
|
-
ruleIndex: entry.index
|
|
217
|
-
};
|
|
218
|
-
});
|
|
219
|
-
const response = buildManifestResponse(route, moduleId);
|
|
220
|
-
const manifestRoute = {
|
|
221
|
-
method: route.method,
|
|
222
|
-
url: route.template,
|
|
223
|
-
...route.tokens ? { tokens: route.tokens } : {},
|
|
224
|
-
...route.score ? { score: route.score } : {},
|
|
225
|
-
...route.status ? { status: route.status } : {},
|
|
226
|
-
...route.headers ? { headers: route.headers } : {},
|
|
227
|
-
...route.delay ? { delay: route.delay } : {},
|
|
228
|
-
...middleware && middleware.length > 0 ? { middleware } : {},
|
|
229
|
-
response
|
|
230
|
-
};
|
|
231
|
-
return manifestRoute;
|
|
232
|
-
});
|
|
233
|
-
const manifest = {
|
|
234
|
-
version: 1,
|
|
235
|
-
routes: manifestRoutes
|
|
236
|
-
};
|
|
237
|
-
return {
|
|
238
|
-
manifest,
|
|
239
|
-
modules: [
|
|
240
|
-
...ruleModules.values(),
|
|
241
|
-
...middlewareModules.values()
|
|
242
|
-
]
|
|
243
|
-
};
|
|
244
|
-
}
|
|
245
|
-
|
|
246
13
|
const require$1 = createRequire(import.meta.url);
|
|
247
14
|
const mimeTypes = {
|
|
248
15
|
".html": "text/html; charset=utf-8",
|
|
@@ -2055,4 +1822,4 @@ async function scanRoutes(params) {
|
|
|
2055
1822
|
return sortRoutes(routes);
|
|
2056
1823
|
}
|
|
2057
1824
|
|
|
2058
|
-
export { sortRoutes as a, buildSwScript as b, createHonoApp as c,
|
|
1825
|
+
export { sortRoutes as a, buildSwScript as b, createHonoApp as c, resolveSwConfig as d, resolveSwUnregisterConfig as e, createPlaygroundMiddleware as f, createMiddleware as g, resolvePlaygroundDist as h, injectPlaygroundSw as i, resolveGroupRoot as j, resolveGroups as k, resolvePlaygroundRequestPath as l, toPlaygroundIgnoredRoute as m, normalizePlaygroundPath as n, toPlaygroundDisabledRoute as o, toPlaygroundRoute as p, resolvePlaygroundOptions as r, scanRoutes as s, toPlaygroundConfigFile as t };
|