@marko/run 0.7.2 → 0.7.4
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/.tsbuildinfo +1 -1
- package/dist/adapter/index.cjs +391 -220
- package/dist/adapter/index.d.ts +2 -0
- package/dist/adapter/index.js +391 -218
- package/dist/adapter/load-dev-worker.mjs +26 -2
- package/dist/cli/index.mjs +114 -63
- package/dist/vite/index.cjs +2 -0
- package/dist/vite/index.d.ts +1 -1
- package/dist/vite/index.js +1 -0
- package/package.json +1 -1
package/dist/adapter/index.cjs
CHANGED
|
@@ -34,7 +34,8 @@ __export(adapter_exports, {
|
|
|
34
34
|
createErrorMiddleware: () => createErrorMiddleware,
|
|
35
35
|
createViteDevServer: () => createViteDevServer,
|
|
36
36
|
default: () => adapter,
|
|
37
|
-
getDevGlobal: () => getDevGlobal
|
|
37
|
+
getDevGlobal: () => getDevGlobal,
|
|
38
|
+
resolveAdapter: () => resolveAdapter2
|
|
38
39
|
});
|
|
39
40
|
module.exports = __toCommonJS(adapter_exports);
|
|
40
41
|
|
|
@@ -43,20 +44,361 @@ var import_url = require("url");
|
|
|
43
44
|
var __importMetaURL = (0, import_url.pathToFileURL)(__filename);
|
|
44
45
|
|
|
45
46
|
// src/adapter/index.ts
|
|
46
|
-
var
|
|
47
|
+
var import_fs7 = __toESM(require("fs"), 1);
|
|
47
48
|
var import_inspector2 = __toESM(require("inspector"), 1);
|
|
48
|
-
var
|
|
49
|
+
var import_path8 = __toESM(require("path"), 1);
|
|
50
|
+
var import_url3 = require("url");
|
|
51
|
+
|
|
52
|
+
// src/vite/plugin.ts
|
|
53
|
+
var import_vite = __toESM(require("@marko/vite"), 1);
|
|
54
|
+
var import_browserslist = __toESM(require("browserslist"), 1);
|
|
55
|
+
var import_debug = __toESM(require("debug"), 1);
|
|
56
|
+
var import_esbuild_plugin_browserslist = require("esbuild-plugin-browserslist");
|
|
57
|
+
var import_fs4 = __toESM(require("fs"), 1);
|
|
58
|
+
var import_glob = require("glob");
|
|
59
|
+
var import_path6 = __toESM(require("path"), 1);
|
|
49
60
|
var import_url2 = require("url");
|
|
61
|
+
var import_vite2 = require("vite");
|
|
62
|
+
|
|
63
|
+
// src/adapter/utils.ts
|
|
64
|
+
var import_kleur = __toESM(require("kleur"), 1);
|
|
65
|
+
var import_supports_color = __toESM(require("supports-color"), 1);
|
|
66
|
+
function stripAnsi(string) {
|
|
67
|
+
return string.replace(
|
|
68
|
+
/([\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><])/g,
|
|
69
|
+
""
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
function cleanStack(stack) {
|
|
73
|
+
return stack.split(/\n/).filter((l) => /^\s*at/.test(l)).join("\n");
|
|
74
|
+
}
|
|
75
|
+
function prepareError(err) {
|
|
76
|
+
var _a;
|
|
77
|
+
return {
|
|
78
|
+
message: stripAnsi(err.message),
|
|
79
|
+
stack: stripAnsi(cleanStack(err.stack || "")),
|
|
80
|
+
id: err.id,
|
|
81
|
+
frame: stripAnsi(err.frame || ""),
|
|
82
|
+
plugin: err.plugin,
|
|
83
|
+
pluginCode: (_a = err.pluginCode) == null ? void 0 : _a.toString(),
|
|
84
|
+
loc: err.loc
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
function logInfoBox(address, explorer) {
|
|
88
|
+
const color = !!import_supports_color.default.stdout;
|
|
89
|
+
let message = import_kleur.default.bold("Marko Run");
|
|
90
|
+
if (true) {
|
|
91
|
+
message += ` v${"0.7.4"}`;
|
|
92
|
+
}
|
|
93
|
+
message += "\n\n";
|
|
94
|
+
message += import_kleur.default.dim("Server listening at");
|
|
95
|
+
message += "\n";
|
|
96
|
+
message += import_kleur.default.cyan(import_kleur.default.underline(address));
|
|
97
|
+
if (explorer) {
|
|
98
|
+
message += "\n\n";
|
|
99
|
+
message += import_kleur.default.dim("Explore your routes");
|
|
100
|
+
message += "\n";
|
|
101
|
+
message += import_kleur.default.dim(import_kleur.default.green(import_kleur.default.underline(explorer)));
|
|
102
|
+
}
|
|
103
|
+
const lines = drawMarkoBox(message, { color, fill: color });
|
|
104
|
+
console.log(lines.join("\n") + "\n");
|
|
105
|
+
}
|
|
106
|
+
function drawMarkoBox(message, options) {
|
|
107
|
+
const textPaddingWidth = 3;
|
|
108
|
+
const logoPaddingWidth = 2;
|
|
109
|
+
const textPadding = " ".repeat(textPaddingWidth);
|
|
110
|
+
const logoPadding = " ".repeat(logoPaddingWidth);
|
|
111
|
+
const logo = drawMarkoLogo(options);
|
|
112
|
+
const textLines = message.split(/\n/);
|
|
113
|
+
const textWidths = textLines.map(
|
|
114
|
+
(line) => line.replace(/\x1b\[\d+m/g, "").length
|
|
115
|
+
);
|
|
116
|
+
const textWidth = Math.max(...textWidths);
|
|
117
|
+
const height = Math.max(textLines.length + 2, logo.lines.length);
|
|
118
|
+
const width = textPaddingWidth * 2 + logoPaddingWidth + textWidth + logo.width;
|
|
119
|
+
const hBorder = "\u2500".repeat(width);
|
|
120
|
+
const vBorder = "\u2502";
|
|
121
|
+
const lineDiff = logo.lines.length - textLines.length;
|
|
122
|
+
const textStartLine = lineDiff > 0 ? Math.max(Math.floor(lineDiff / 2), 1) : 1;
|
|
123
|
+
const textEndLine = height - (lineDiff > 0 ? Math.ceil(lineDiff / 2) : 1);
|
|
124
|
+
const logoEndLine = logo.lines.length;
|
|
125
|
+
const logoFill = " ".repeat(logo.width);
|
|
126
|
+
const textFill = " ".repeat(textWidth);
|
|
127
|
+
const lines = [`\u256D${hBorder}\u256E`];
|
|
128
|
+
for (let i = 0; i < height; i++) {
|
|
129
|
+
let line = vBorder;
|
|
130
|
+
line += logoPadding;
|
|
131
|
+
if (i < logoEndLine) {
|
|
132
|
+
line += logo.lines[i];
|
|
133
|
+
} else {
|
|
134
|
+
line += logoFill;
|
|
135
|
+
}
|
|
136
|
+
line += textPadding;
|
|
137
|
+
if (i >= textStartLine && i < textEndLine) {
|
|
138
|
+
const index = i - textStartLine;
|
|
139
|
+
line += textLines[index];
|
|
140
|
+
line += " ".repeat(textWidth - textWidths[index]);
|
|
141
|
+
} else {
|
|
142
|
+
line += textFill;
|
|
143
|
+
}
|
|
144
|
+
line += textPadding;
|
|
145
|
+
line += vBorder;
|
|
146
|
+
lines.push(line);
|
|
147
|
+
}
|
|
148
|
+
lines.push(`\u2570${hBorder}\u256F`);
|
|
149
|
+
return lines;
|
|
150
|
+
}
|
|
151
|
+
function drawMarkoLogo(options = {}) {
|
|
152
|
+
const { fill = true, color = true } = options;
|
|
153
|
+
const source = `
|
|
154
|
+
TT____ YY____ R____
|
|
155
|
+
C\u2571T\u2572 \u2572G\u2571Y\u2572 \u2572 R\u2572 \u2572
|
|
156
|
+
C\u2571 T\u2572 G\u2571 Y\u2572 \u2572 R\u2572 \u2572
|
|
157
|
+
C\u2571 \u2571T\u2572G\u2571 \u2571Y\u2572 \u2572 R\u2572 \u2572
|
|
158
|
+
B\u2572 \u2572 GG\u203E\u203E\u203E\u203E O\u2571 \u2571 P\u2571 \u2571
|
|
159
|
+
B\u2572 \u2572 OOO\u2571 \u2571 P\u2571 \u2571
|
|
160
|
+
B\u2572 \u2572 OOO\u2571 \u2571 P\u2571 \u2571
|
|
161
|
+
B\u203E\u203E\u203E\u203E OOO\u203E\u203E\u203E\u203E P\u203E\u203E\u203E\u203E
|
|
162
|
+
`;
|
|
163
|
+
const resetEscape = "\x1B[0m";
|
|
164
|
+
const colorEscapeCodes = Object.entries({
|
|
165
|
+
B: "#06cfe5",
|
|
166
|
+
C: "#05a5f0",
|
|
167
|
+
T: "#19d89c",
|
|
168
|
+
G: "#81dc09",
|
|
169
|
+
Y: "#ffd900",
|
|
170
|
+
O: "#ff9500",
|
|
171
|
+
R: "#f3154d",
|
|
172
|
+
P: "#ce176c"
|
|
173
|
+
}).reduce(
|
|
174
|
+
(acc, [key, hex]) => {
|
|
175
|
+
const r = parseInt(hex.slice(1, 3), 16);
|
|
176
|
+
const g = parseInt(hex.slice(3, 5), 16);
|
|
177
|
+
const b = parseInt(hex.slice(5, 7), 16);
|
|
178
|
+
acc[key] = `\x1B[38;2;${r};${g};${b}m`;
|
|
179
|
+
return acc;
|
|
180
|
+
},
|
|
181
|
+
{}
|
|
182
|
+
);
|
|
183
|
+
const lines = [];
|
|
184
|
+
const lineWidths = [];
|
|
185
|
+
let line = "";
|
|
186
|
+
let lineWidth = 0;
|
|
187
|
+
let width = 0;
|
|
188
|
+
for (let i = 0; i < source.length; i++) {
|
|
189
|
+
let char = source[i];
|
|
190
|
+
if (char === "\n") {
|
|
191
|
+
if (line) {
|
|
192
|
+
if (color) {
|
|
193
|
+
line += resetEscape;
|
|
194
|
+
}
|
|
195
|
+
width = Math.max(lineWidth, width);
|
|
196
|
+
lines.push(line);
|
|
197
|
+
lineWidths.push(lineWidth);
|
|
198
|
+
line = "";
|
|
199
|
+
lineWidth = 0;
|
|
200
|
+
}
|
|
201
|
+
} else if (/[A-Z]/.test(char)) {
|
|
202
|
+
while (source[i + 1] === char) i++;
|
|
203
|
+
if (color) {
|
|
204
|
+
line += colorEscapeCodes[char];
|
|
205
|
+
}
|
|
206
|
+
if (fill) {
|
|
207
|
+
let fillChar = "";
|
|
208
|
+
for (; i < source.length; i++) {
|
|
209
|
+
char = source[i + 1];
|
|
210
|
+
if (fillChar && char !== " ") {
|
|
211
|
+
break;
|
|
212
|
+
} else if (!fillChar) {
|
|
213
|
+
fillChar = char;
|
|
214
|
+
}
|
|
215
|
+
line += fillChar;
|
|
216
|
+
lineWidth++;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
} else {
|
|
220
|
+
line += char;
|
|
221
|
+
lineWidth++;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
for (let i = 0; i < lines.length; i++) {
|
|
225
|
+
const padding = width - lineWidths[i];
|
|
226
|
+
if (padding > 0) {
|
|
227
|
+
lines[i] += " ".repeat(width - lineWidths[i]);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
return { lines, width };
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
// src/vite/codegen/index.ts
|
|
234
|
+
var import_path2 = __toESM(require("path"), 1);
|
|
235
|
+
|
|
236
|
+
// src/vite/constants.ts
|
|
237
|
+
var markoRunFilePrefix = "__marko-run__";
|
|
238
|
+
var virtualFilePrefix = "virtual:marko-run";
|
|
239
|
+
var httpVerbs = [
|
|
240
|
+
"get",
|
|
241
|
+
"head",
|
|
242
|
+
"post",
|
|
243
|
+
"put",
|
|
244
|
+
"delete",
|
|
245
|
+
"patch",
|
|
246
|
+
"options"
|
|
247
|
+
];
|
|
248
|
+
var RoutableFileTypes = {
|
|
249
|
+
Page: "page",
|
|
250
|
+
Layout: "layout",
|
|
251
|
+
Handler: "handler",
|
|
252
|
+
Middleware: "middleware",
|
|
253
|
+
Meta: "meta",
|
|
254
|
+
NotFound: "404",
|
|
255
|
+
Error: "500"
|
|
256
|
+
};
|
|
257
|
+
|
|
258
|
+
// src/vite/utils/fs.ts
|
|
259
|
+
var import_path = __toESM(require("path"), 1);
|
|
260
|
+
var POSIX_SEP = "/";
|
|
261
|
+
var WINDOWS_SEP = "\\";
|
|
262
|
+
var normalizePath = import_path.default.sep === WINDOWS_SEP ? (id) => id.replace(/\\/g, POSIX_SEP) : (id) => id;
|
|
263
|
+
|
|
264
|
+
// src/vite/utils/route.ts
|
|
265
|
+
var httpVerbOrder = httpVerbs.reduce(
|
|
266
|
+
(order, verb, index) => {
|
|
267
|
+
order[verb] = index;
|
|
268
|
+
return order;
|
|
269
|
+
},
|
|
270
|
+
{}
|
|
271
|
+
);
|
|
272
|
+
|
|
273
|
+
// src/vite/routes/builder.ts
|
|
274
|
+
var import_path3 = __toESM(require("path"), 1);
|
|
275
|
+
var markoFiles = `(${RoutableFileTypes.Layout}|${RoutableFileTypes.Page}|${RoutableFileTypes.NotFound}|${RoutableFileTypes.Error})\\.(?:.*\\.)?(marko)`;
|
|
276
|
+
var nonMarkoFiles = `(${RoutableFileTypes.Middleware}|${RoutableFileTypes.Handler}|${RoutableFileTypes.Meta})\\.(?:.*\\.)?(.+)`;
|
|
277
|
+
var routeableFileRegex = new RegExp(
|
|
278
|
+
`[+](?:${markoFiles}|${nonMarkoFiles})$`,
|
|
279
|
+
"i"
|
|
280
|
+
);
|
|
281
|
+
|
|
282
|
+
// src/vite/routes/walk.ts
|
|
283
|
+
var import_fs2 = __toESM(require("fs"), 1);
|
|
284
|
+
var import_path4 = __toESM(require("path"), 1);
|
|
285
|
+
|
|
286
|
+
// src/vite/utils/ast.ts
|
|
287
|
+
var t = __toESM(require("@babel/types"), 1);
|
|
288
|
+
|
|
289
|
+
// src/vite/utils/config.ts
|
|
290
|
+
var PluginConfigKey = "__MARKO_RUN_PLUGIN_CONFIG__";
|
|
291
|
+
function getConfig(obj, key) {
|
|
292
|
+
return obj[key];
|
|
293
|
+
}
|
|
294
|
+
var getExternalPluginOptions = (viteConfig) => getConfig(viteConfig, PluginConfigKey);
|
|
295
|
+
|
|
296
|
+
// src/vite/utils/log.ts
|
|
297
|
+
var import_node_zlib = __toESM(require("node:zlib"), 1);
|
|
298
|
+
var import_buffer = require("buffer");
|
|
299
|
+
var import_cli_table3 = __toESM(require("cli-table3"), 1);
|
|
300
|
+
var import_human_format = __toESM(require("human-format"), 1);
|
|
301
|
+
var import_kleur2 = __toESM(require("kleur"), 1);
|
|
302
|
+
var HttpVerbColors = {
|
|
303
|
+
get: import_kleur2.default.green,
|
|
304
|
+
head: import_kleur2.default.dim().green,
|
|
305
|
+
post: import_kleur2.default.magenta,
|
|
306
|
+
put: import_kleur2.default.cyan,
|
|
307
|
+
delete: import_kleur2.default.red,
|
|
308
|
+
patch: import_kleur2.default.yellow,
|
|
309
|
+
options: import_kleur2.default.grey
|
|
310
|
+
};
|
|
311
|
+
|
|
312
|
+
// src/vite/utils/read-once-persisted-store.ts
|
|
313
|
+
var import_fs3 = require("fs");
|
|
314
|
+
var import_os = __toESM(require("os"), 1);
|
|
315
|
+
var import_path5 = __toESM(require("path"), 1);
|
|
316
|
+
var noop = () => {
|
|
317
|
+
};
|
|
318
|
+
var tmpFile = import_path5.default.join(import_os.default.tmpdir(), "marko-run-storage.json");
|
|
319
|
+
var values = /* @__PURE__ */ new Map();
|
|
320
|
+
process.once("beforeExit", (code) => {
|
|
321
|
+
if (code === 0 && values.size) {
|
|
322
|
+
import_fs3.promises.writeFile(tmpFile, JSON.stringify([...values])).catch(noop);
|
|
323
|
+
}
|
|
324
|
+
});
|
|
325
|
+
|
|
326
|
+
// src/vite/plugin.ts
|
|
327
|
+
var debug = (0, import_debug.default)("@marko/run");
|
|
328
|
+
var __dirname = import_path6.default.dirname((0, import_url2.fileURLToPath)(__importMetaURL));
|
|
329
|
+
var PLUGIN_NAME_PREFIX = "marko-run-vite";
|
|
330
|
+
var MIDDLEWARE_FILENAME = `${markoRunFilePrefix}middleware.js`;
|
|
331
|
+
var ROUTER_FILENAME = `${markoRunFilePrefix}router.js`;
|
|
332
|
+
var defaultPort = Number(process.env.PORT || 3e3);
|
|
333
|
+
async function getPackageData(dir) {
|
|
334
|
+
do {
|
|
335
|
+
const pkgPath = import_path6.default.join(dir, "package.json");
|
|
336
|
+
if (import_fs4.default.existsSync(pkgPath)) {
|
|
337
|
+
return JSON.parse(await import_fs4.default.promises.readFile(pkgPath, "utf-8"));
|
|
338
|
+
}
|
|
339
|
+
} while (dir !== (dir = import_path6.default.dirname(dir)));
|
|
340
|
+
return null;
|
|
341
|
+
}
|
|
342
|
+
async function resolveAdapter(root, options, log) {
|
|
343
|
+
if (options && options.adapter !== void 0) {
|
|
344
|
+
return options.adapter;
|
|
345
|
+
}
|
|
346
|
+
const pkg = await getPackageData(root);
|
|
347
|
+
if (pkg) {
|
|
348
|
+
let dependecies = pkg.dependencies ? Object.keys(pkg.dependencies) : [];
|
|
349
|
+
if (pkg.devDependencies) {
|
|
350
|
+
dependecies = dependecies.concat(Object.keys(pkg.devDependencies));
|
|
351
|
+
}
|
|
352
|
+
for (const name of dependecies) {
|
|
353
|
+
if (name.startsWith("@marko/run-adapter") || name.indexOf("marko-run-adapter") !== -1) {
|
|
354
|
+
try {
|
|
355
|
+
const module3 = await import(
|
|
356
|
+
/* @vite-ignore */
|
|
357
|
+
name
|
|
358
|
+
);
|
|
359
|
+
log && debug(
|
|
360
|
+
`Using adapter ${name} listed in your package.json dependecies`
|
|
361
|
+
);
|
|
362
|
+
return module3.default();
|
|
363
|
+
} catch (err) {
|
|
364
|
+
log && debug(`Attempt to use package '${name}' failed %O`, err);
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
const defaultAdapter = "@marko/run/adapter";
|
|
370
|
+
const module2 = await import(
|
|
371
|
+
/* @vite-ignore */
|
|
372
|
+
defaultAdapter
|
|
373
|
+
);
|
|
374
|
+
log && debug("Using default adapter");
|
|
375
|
+
return module2.default();
|
|
376
|
+
}
|
|
377
|
+
var defaultConfigPlugin = {
|
|
378
|
+
name: `${PLUGIN_NAME_PREFIX}:defaults`,
|
|
379
|
+
enforce: "pre",
|
|
380
|
+
config(config2) {
|
|
381
|
+
var _a, _b;
|
|
382
|
+
return {
|
|
383
|
+
server: {
|
|
384
|
+
port: ((_a = config2.server) == null ? void 0 : _a.port) ?? defaultPort
|
|
385
|
+
},
|
|
386
|
+
preview: {
|
|
387
|
+
port: ((_b = config2.preview) == null ? void 0 : _b.port) ?? defaultPort
|
|
388
|
+
}
|
|
389
|
+
};
|
|
390
|
+
}
|
|
391
|
+
};
|
|
50
392
|
|
|
51
393
|
// src/vite/utils/server.ts
|
|
52
394
|
var import_child_process = __toESM(require("child_process"), 1);
|
|
53
395
|
var import_cluster = __toESM(require("cluster"), 1);
|
|
54
396
|
var import_dotenv = require("dotenv");
|
|
55
|
-
var
|
|
397
|
+
var import_fs6 = __toESM(require("fs"), 1);
|
|
56
398
|
var import_net = __toESM(require("net"), 1);
|
|
57
399
|
async function parseEnv(envFile) {
|
|
58
|
-
if (
|
|
59
|
-
const content = await
|
|
400
|
+
if (import_fs6.default.existsSync(envFile)) {
|
|
401
|
+
const content = await import_fs6.default.promises.readFile(envFile, "utf8");
|
|
60
402
|
return (0, import_dotenv.parse)(content);
|
|
61
403
|
}
|
|
62
404
|
}
|
|
@@ -212,14 +554,14 @@ function getInspectOptions(args) {
|
|
|
212
554
|
}
|
|
213
555
|
|
|
214
556
|
// src/adapter/dev-server.ts
|
|
215
|
-
var
|
|
216
|
-
var
|
|
557
|
+
var import_path7 = __toESM(require("path"), 1);
|
|
558
|
+
var import_vite3 = require("vite");
|
|
217
559
|
|
|
218
560
|
// src/adapter/logger.ts
|
|
219
561
|
var import_draftlog = __toESM(require("draftlog"), 1);
|
|
220
|
-
var
|
|
562
|
+
var import_human_format2 = __toESM(require("human-format"), 1);
|
|
221
563
|
var import_inspector = __toESM(require("inspector"), 1);
|
|
222
|
-
var
|
|
564
|
+
var import_kleur3 = __toESM(require("kleur"), 1);
|
|
223
565
|
if (!import_inspector.default.url()) {
|
|
224
566
|
import_draftlog.default.into(console);
|
|
225
567
|
import_draftlog.default.defaults.canReWrite = false;
|
|
@@ -240,16 +582,16 @@ var HttpStatusColors = [
|
|
|
240
582
|
];
|
|
241
583
|
var IdChars = [
|
|
242
584
|
"",
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
585
|
+
import_kleur3.default.cyan("\xB9"),
|
|
586
|
+
import_kleur3.default.magenta("\xB2"),
|
|
587
|
+
import_kleur3.default.green("\xB3"),
|
|
588
|
+
import_kleur3.default.red("\u2074"),
|
|
589
|
+
import_kleur3.default.cyan("\u2075"),
|
|
590
|
+
import_kleur3.default.magenta("\u2076"),
|
|
591
|
+
import_kleur3.default.green("\u2077"),
|
|
592
|
+
import_kleur3.default.red("\u2078"),
|
|
593
|
+
import_kleur3.default.cyan("\u2079"),
|
|
594
|
+
import_kleur3.default.red("\u207A")
|
|
253
595
|
];
|
|
254
596
|
var ArrowSteps = [" ", " \u25C0", " \u25C0\u2501", "\u25C0\u2501\u2501", "\u2501\u2501 ", "\u2501 ", " "];
|
|
255
597
|
function logger_default(_options = {}) {
|
|
@@ -317,13 +659,13 @@ function logger_default(_options = {}) {
|
|
|
317
659
|
}
|
|
318
660
|
var spinners;
|
|
319
661
|
function logRequest(id, req) {
|
|
320
|
-
const info = id + " " +
|
|
321
|
-
const final =
|
|
662
|
+
const info = id + " " + import_kleur3.default.bold(req.method) + " " + import_kleur3.default.dim(req.url);
|
|
663
|
+
const final = import_kleur3.default.dim(requestArrow(id)) + info;
|
|
322
664
|
if (console.draft) {
|
|
323
665
|
spinners ?? (spinners = createAnimationManager({ steps: ArrowSteps.length }));
|
|
324
666
|
const update = console.draft();
|
|
325
667
|
const stop = spinners.add((step) => {
|
|
326
|
-
update(
|
|
668
|
+
update(import_kleur3.default.cyan(requestArrow(id, step)) + info);
|
|
327
669
|
});
|
|
328
670
|
return () => {
|
|
329
671
|
stop();
|
|
@@ -341,18 +683,18 @@ function logResponse(id, req, res, startTime, contentLength, success) {
|
|
|
341
683
|
if (req.method === "HEAD" || [204, 205, 304].includes(status)) {
|
|
342
684
|
length = "";
|
|
343
685
|
} else if (!contentLength) {
|
|
344
|
-
length =
|
|
686
|
+
length = import_kleur3.default.dim("-");
|
|
345
687
|
} else {
|
|
346
688
|
length = formatMeasurement(bytes(contentLength));
|
|
347
689
|
}
|
|
348
690
|
let arrow = id ? "\u2501" : "\u2501\u2501";
|
|
349
691
|
if (success) {
|
|
350
|
-
arrow =
|
|
692
|
+
arrow = import_kleur3.default.dim(arrow + "\u25B6");
|
|
351
693
|
} else {
|
|
352
|
-
arrow =
|
|
694
|
+
arrow = import_kleur3.default.red(import_kleur3.default.dim(arrow) + import_kleur3.default.bold("x"));
|
|
353
695
|
}
|
|
354
696
|
console.log(
|
|
355
|
-
arrow + id + " " +
|
|
697
|
+
arrow + id + " " + import_kleur3.default.bold(req.method) + " " + import_kleur3.default.dim(req.url) + " " + import_kleur3.default[color](status) + " " + formatMeasurement(time(startTime)) + " " + length
|
|
356
698
|
);
|
|
357
699
|
}
|
|
358
700
|
function requestArrow(id, step = 3) {
|
|
@@ -364,11 +706,11 @@ function time(start) {
|
|
|
364
706
|
return delta < 5e3 ? [delta, "ms"] : [(delta / 1e3).toFixed(1), "s"];
|
|
365
707
|
}
|
|
366
708
|
function bytes(size) {
|
|
367
|
-
const { value, prefix } =
|
|
709
|
+
const { value, prefix } = import_human_format2.default.raw(size, { maxDecimals: 2, unit: "b" });
|
|
368
710
|
return [value.toFixed(2), (prefix + "b").toLowerCase()];
|
|
369
711
|
}
|
|
370
712
|
function formatMeasurement([value, unit]) {
|
|
371
|
-
return
|
|
713
|
+
return import_kleur3.default.dim(value + import_kleur3.default.yellow(import_kleur3.default.bold(unit)));
|
|
372
714
|
}
|
|
373
715
|
function createAnimationManager(options = {}) {
|
|
374
716
|
const { steps = 1e4, ms = 100 } = options;
|
|
@@ -541,176 +883,6 @@ var bodyConsumedErrorStream = new ReadableStream({
|
|
|
541
883
|
}
|
|
542
884
|
});
|
|
543
885
|
|
|
544
|
-
// src/adapter/utils.ts
|
|
545
|
-
var import_kleur2 = __toESM(require("kleur"), 1);
|
|
546
|
-
var import_supports_color = __toESM(require("supports-color"), 1);
|
|
547
|
-
function stripAnsi(string) {
|
|
548
|
-
return string.replace(
|
|
549
|
-
/([\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><])/g,
|
|
550
|
-
""
|
|
551
|
-
);
|
|
552
|
-
}
|
|
553
|
-
function cleanStack(stack) {
|
|
554
|
-
return stack.split(/\n/).filter((l) => /^\s*at/.test(l)).join("\n");
|
|
555
|
-
}
|
|
556
|
-
function prepareError(err) {
|
|
557
|
-
var _a;
|
|
558
|
-
return {
|
|
559
|
-
message: stripAnsi(err.message),
|
|
560
|
-
stack: stripAnsi(cleanStack(err.stack || "")),
|
|
561
|
-
id: err.id,
|
|
562
|
-
frame: stripAnsi(err.frame || ""),
|
|
563
|
-
plugin: err.plugin,
|
|
564
|
-
pluginCode: (_a = err.pluginCode) == null ? void 0 : _a.toString(),
|
|
565
|
-
loc: err.loc
|
|
566
|
-
};
|
|
567
|
-
}
|
|
568
|
-
function logInfoBox(address, explorer) {
|
|
569
|
-
const color = !!import_supports_color.default.stdout;
|
|
570
|
-
let message = import_kleur2.default.bold("Marko Run");
|
|
571
|
-
if (true) {
|
|
572
|
-
message += ` v${"0.7.2"}`;
|
|
573
|
-
}
|
|
574
|
-
message += "\n\n";
|
|
575
|
-
message += import_kleur2.default.dim("Server listening at");
|
|
576
|
-
message += "\n";
|
|
577
|
-
message += import_kleur2.default.cyan(import_kleur2.default.underline(address));
|
|
578
|
-
if (explorer) {
|
|
579
|
-
message += "\n\n";
|
|
580
|
-
message += import_kleur2.default.dim("Explore your routes");
|
|
581
|
-
message += "\n";
|
|
582
|
-
message += import_kleur2.default.dim(import_kleur2.default.green(import_kleur2.default.underline(explorer)));
|
|
583
|
-
}
|
|
584
|
-
const lines = drawMarkoBox(message, { color, fill: color });
|
|
585
|
-
console.log(lines.join("\n") + "\n");
|
|
586
|
-
}
|
|
587
|
-
function drawMarkoBox(message, options) {
|
|
588
|
-
const textPaddingWidth = 3;
|
|
589
|
-
const logoPaddingWidth = 2;
|
|
590
|
-
const textPadding = " ".repeat(textPaddingWidth);
|
|
591
|
-
const logoPadding = " ".repeat(logoPaddingWidth);
|
|
592
|
-
const logo = drawMarkoLogo(options);
|
|
593
|
-
const textLines = message.split(/\n/);
|
|
594
|
-
const textWidths = textLines.map(
|
|
595
|
-
(line) => line.replace(/\x1b\[\d+m/g, "").length
|
|
596
|
-
);
|
|
597
|
-
const textWidth = Math.max(...textWidths);
|
|
598
|
-
const height = Math.max(textLines.length + 2, logo.lines.length);
|
|
599
|
-
const width = textPaddingWidth * 2 + logoPaddingWidth + textWidth + logo.width;
|
|
600
|
-
const hBorder = "\u2500".repeat(width);
|
|
601
|
-
const vBorder = "\u2502";
|
|
602
|
-
const lineDiff = logo.lines.length - textLines.length;
|
|
603
|
-
const textStartLine = lineDiff > 0 ? Math.max(Math.floor(lineDiff / 2), 1) : 1;
|
|
604
|
-
const textEndLine = height - (lineDiff > 0 ? Math.ceil(lineDiff / 2) : 1);
|
|
605
|
-
const logoEndLine = logo.lines.length;
|
|
606
|
-
const logoFill = " ".repeat(logo.width);
|
|
607
|
-
const textFill = " ".repeat(textWidth);
|
|
608
|
-
const lines = [`\u256D${hBorder}\u256E`];
|
|
609
|
-
for (let i = 0; i < height; i++) {
|
|
610
|
-
let line = vBorder;
|
|
611
|
-
line += logoPadding;
|
|
612
|
-
if (i < logoEndLine) {
|
|
613
|
-
line += logo.lines[i];
|
|
614
|
-
} else {
|
|
615
|
-
line += logoFill;
|
|
616
|
-
}
|
|
617
|
-
line += textPadding;
|
|
618
|
-
if (i >= textStartLine && i < textEndLine) {
|
|
619
|
-
const index = i - textStartLine;
|
|
620
|
-
line += textLines[index];
|
|
621
|
-
line += " ".repeat(textWidth - textWidths[index]);
|
|
622
|
-
} else {
|
|
623
|
-
line += textFill;
|
|
624
|
-
}
|
|
625
|
-
line += textPadding;
|
|
626
|
-
line += vBorder;
|
|
627
|
-
lines.push(line);
|
|
628
|
-
}
|
|
629
|
-
lines.push(`\u2570${hBorder}\u256F`);
|
|
630
|
-
return lines;
|
|
631
|
-
}
|
|
632
|
-
function drawMarkoLogo(options = {}) {
|
|
633
|
-
const { fill = true, color = true } = options;
|
|
634
|
-
const source = `
|
|
635
|
-
TT____ YY____ R____
|
|
636
|
-
C\u2571T\u2572 \u2572G\u2571Y\u2572 \u2572 R\u2572 \u2572
|
|
637
|
-
C\u2571 T\u2572 G\u2571 Y\u2572 \u2572 R\u2572 \u2572
|
|
638
|
-
C\u2571 \u2571T\u2572G\u2571 \u2571Y\u2572 \u2572 R\u2572 \u2572
|
|
639
|
-
B\u2572 \u2572 GG\u203E\u203E\u203E\u203E O\u2571 \u2571 P\u2571 \u2571
|
|
640
|
-
B\u2572 \u2572 OOO\u2571 \u2571 P\u2571 \u2571
|
|
641
|
-
B\u2572 \u2572 OOO\u2571 \u2571 P\u2571 \u2571
|
|
642
|
-
B\u203E\u203E\u203E\u203E OOO\u203E\u203E\u203E\u203E P\u203E\u203E\u203E\u203E
|
|
643
|
-
`;
|
|
644
|
-
const resetEscape = "\x1B[0m";
|
|
645
|
-
const colorEscapeCodes = Object.entries({
|
|
646
|
-
B: "#06cfe5",
|
|
647
|
-
C: "#05a5f0",
|
|
648
|
-
T: "#19d89c",
|
|
649
|
-
G: "#81dc09",
|
|
650
|
-
Y: "#ffd900",
|
|
651
|
-
O: "#ff9500",
|
|
652
|
-
R: "#f3154d",
|
|
653
|
-
P: "#ce176c"
|
|
654
|
-
}).reduce(
|
|
655
|
-
(acc, [key, hex]) => {
|
|
656
|
-
const r = parseInt(hex.slice(1, 3), 16);
|
|
657
|
-
const g = parseInt(hex.slice(3, 5), 16);
|
|
658
|
-
const b = parseInt(hex.slice(5, 7), 16);
|
|
659
|
-
acc[key] = `\x1B[38;2;${r};${g};${b}m`;
|
|
660
|
-
return acc;
|
|
661
|
-
},
|
|
662
|
-
{}
|
|
663
|
-
);
|
|
664
|
-
const lines = [];
|
|
665
|
-
const lineWidths = [];
|
|
666
|
-
let line = "";
|
|
667
|
-
let lineWidth = 0;
|
|
668
|
-
let width = 0;
|
|
669
|
-
for (let i = 0; i < source.length; i++) {
|
|
670
|
-
let char = source[i];
|
|
671
|
-
if (char === "\n") {
|
|
672
|
-
if (line) {
|
|
673
|
-
if (color) {
|
|
674
|
-
line += resetEscape;
|
|
675
|
-
}
|
|
676
|
-
width = Math.max(lineWidth, width);
|
|
677
|
-
lines.push(line);
|
|
678
|
-
lineWidths.push(lineWidth);
|
|
679
|
-
line = "";
|
|
680
|
-
lineWidth = 0;
|
|
681
|
-
}
|
|
682
|
-
} else if (/[A-Z]/.test(char)) {
|
|
683
|
-
while (source[i + 1] === char) i++;
|
|
684
|
-
if (color) {
|
|
685
|
-
line += colorEscapeCodes[char];
|
|
686
|
-
}
|
|
687
|
-
if (fill) {
|
|
688
|
-
let fillChar = "";
|
|
689
|
-
for (; i < source.length; i++) {
|
|
690
|
-
char = source[i + 1];
|
|
691
|
-
if (fillChar && char !== " ") {
|
|
692
|
-
break;
|
|
693
|
-
} else if (!fillChar) {
|
|
694
|
-
fillChar = char;
|
|
695
|
-
}
|
|
696
|
-
line += fillChar;
|
|
697
|
-
lineWidth++;
|
|
698
|
-
}
|
|
699
|
-
}
|
|
700
|
-
} else {
|
|
701
|
-
line += char;
|
|
702
|
-
lineWidth++;
|
|
703
|
-
}
|
|
704
|
-
}
|
|
705
|
-
for (let i = 0; i < lines.length; i++) {
|
|
706
|
-
const padding = width - lineWidths[i];
|
|
707
|
-
if (padding > 0) {
|
|
708
|
-
lines[i] += " ".repeat(width - lineWidths[i]);
|
|
709
|
-
}
|
|
710
|
-
}
|
|
711
|
-
return { lines, width };
|
|
712
|
-
}
|
|
713
|
-
|
|
714
886
|
// src/adapter/dev-server.ts
|
|
715
887
|
async function createViteDevServer(config2) {
|
|
716
888
|
const finalConfig = {
|
|
@@ -724,7 +896,7 @@ async function createViteDevServer(config2) {
|
|
|
724
896
|
} else if (typeof cors === "object") {
|
|
725
897
|
cors.preflightContinue ?? (cors.preflightContinue = true);
|
|
726
898
|
}
|
|
727
|
-
const devServer = await (0,
|
|
899
|
+
const devServer = await (0, import_vite3.createServer)(finalConfig);
|
|
728
900
|
getDevGlobal().addDevServer(devServer);
|
|
729
901
|
devServer.middlewares.use(logger_default());
|
|
730
902
|
return devServer;
|
|
@@ -813,7 +985,7 @@ function createErrorMiddleware(devServer) {
|
|
|
813
985
|
return function errorMiddleware(error, _req, res, _next) {
|
|
814
986
|
if (!error.id) {
|
|
815
987
|
devServer.config.logger.error(
|
|
816
|
-
(0,
|
|
988
|
+
(0, import_vite3.buildErrorMessage)(error, [
|
|
817
989
|
`\x1B[31;1mRequest failed with error: ${error.message}\x1B[0m`
|
|
818
990
|
])
|
|
819
991
|
);
|
|
@@ -829,7 +1001,7 @@ function createErrorMiddleware(devServer) {
|
|
|
829
1001
|
<script type="module">
|
|
830
1002
|
const error = ${stripHtml(JSON.stringify(preparedError))}
|
|
831
1003
|
try {
|
|
832
|
-
const { ErrorOverlay } = await import(${JSON.stringify(
|
|
1004
|
+
const { ErrorOverlay } = await import(${JSON.stringify(import_path7.default.posix.join(devServer.config.base, "/@vite/client"))})
|
|
833
1005
|
document.body.appendChild(new ErrorOverlay(error))
|
|
834
1006
|
} catch {
|
|
835
1007
|
const p = document.createElement('p')
|
|
@@ -853,15 +1025,13 @@ function stripHtml(string) {
|
|
|
853
1025
|
|
|
854
1026
|
// src/adapter/index.ts
|
|
855
1027
|
var import_parse_node_args = __toESM(require("parse-node-args"), 1);
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
var
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
var defaultEntry = import_path2.default.join(__dirname, "default-entry");
|
|
864
|
-
var loadDevWorker = import_path2.default.join(__dirname, "load-dev-worker.mjs");
|
|
1028
|
+
var __dirname2 = import_path8.default.dirname((0, import_url3.fileURLToPath)(__importMetaURL));
|
|
1029
|
+
var defaultEntry = import_path8.default.join(__dirname2, "default-entry");
|
|
1030
|
+
var loadDevWorker = import_path8.default.join(__dirname2, "load-dev-worker.mjs");
|
|
1031
|
+
async function resolveAdapter2(config2) {
|
|
1032
|
+
const options = getExternalPluginOptions(config2);
|
|
1033
|
+
return resolveAdapter(config2.root, options);
|
|
1034
|
+
}
|
|
865
1035
|
function adapter() {
|
|
866
1036
|
return {
|
|
867
1037
|
name: "base-adapter",
|
|
@@ -966,12 +1136,12 @@ function adapter() {
|
|
|
966
1136
|
return;
|
|
967
1137
|
}
|
|
968
1138
|
const promises = [];
|
|
969
|
-
const cacheDir =
|
|
970
|
-
const codeDir =
|
|
971
|
-
if (
|
|
972
|
-
await
|
|
1139
|
+
const cacheDir = import_path8.default.resolve(__dirname2, "../../.cache/explorer");
|
|
1140
|
+
const codeDir = import_path8.default.join(cacheDir, "code");
|
|
1141
|
+
if (import_fs7.default.existsSync(codeDir)) {
|
|
1142
|
+
await import_fs7.default.promises.rm(codeDir, { recursive: true });
|
|
973
1143
|
}
|
|
974
|
-
await
|
|
1144
|
+
await import_fs7.default.promises.mkdir(codeDir, { recursive: true });
|
|
975
1145
|
const data = {
|
|
976
1146
|
meta,
|
|
977
1147
|
routes: {},
|
|
@@ -989,7 +1159,7 @@ function adapter() {
|
|
|
989
1159
|
}
|
|
990
1160
|
if (fileName) {
|
|
991
1161
|
promises.push(
|
|
992
|
-
|
|
1162
|
+
import_fs7.default.promises.writeFile(import_path8.default.join(codeDir, fileName), code, {})
|
|
993
1163
|
);
|
|
994
1164
|
}
|
|
995
1165
|
}
|
|
@@ -1000,8 +1170,8 @@ function adapter() {
|
|
|
1000
1170
|
data.routes["s" + id] = route;
|
|
1001
1171
|
}
|
|
1002
1172
|
promises.push(
|
|
1003
|
-
|
|
1004
|
-
|
|
1173
|
+
import_fs7.default.promises.writeFile(
|
|
1174
|
+
import_path8.default.join(cacheDir, "data.json"),
|
|
1005
1175
|
JSON.stringify(data),
|
|
1006
1176
|
{}
|
|
1007
1177
|
)
|
|
@@ -1022,5 +1192,6 @@ async function startExplorer() {
|
|
|
1022
1192
|
createDevServer,
|
|
1023
1193
|
createErrorMiddleware,
|
|
1024
1194
|
createViteDevServer,
|
|
1025
|
-
getDevGlobal
|
|
1195
|
+
getDevGlobal,
|
|
1196
|
+
resolveAdapter
|
|
1026
1197
|
});
|