@marko/run 0.2.6 → 0.2.8
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/default-entry.mjs +2 -2
- package/dist/adapter/dev-server.d.ts +11 -2
- package/dist/adapter/index.cjs +460 -28
- package/dist/adapter/index.d.ts +3 -1
- package/dist/adapter/index.js +454 -26
- package/dist/adapter/load-dev-worker.mjs +11 -9
- package/dist/adapter/middleware.cjs +49 -64
- package/dist/adapter/middleware.d.ts +1 -3
- package/dist/adapter/middleware.js +45 -64
- package/dist/adapter/runtime.cjs +22 -0
- package/dist/adapter/runtime.d.ts +1 -0
- package/dist/adapter/runtime.js +0 -0
- package/dist/adapter/utils.d.ts +10 -0
- package/dist/cli/index.mjs +231 -120
- package/dist/components/dev-error-page.marko +14 -0
- package/dist/runtime/index.d.ts +2 -0
- package/dist/vite/codegen/index.d.ts +2 -0
- package/dist/vite/constants.d.ts +0 -2
- package/dist/vite/index.cjs +229 -118
- package/dist/vite/index.js +225 -118
- package/dist/vite/types.d.ts +3 -2
- package/package.json +19 -13
- package/dist/vite/routes/routeTrie.d.ts +0 -2
package/dist/adapter/index.cjs
CHANGED
|
@@ -18,6 +18,10 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
return to;
|
|
19
19
|
};
|
|
20
20
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
21
25
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
26
|
mod
|
|
23
27
|
));
|
|
@@ -26,11 +30,11 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
26
30
|
// src/adapter/index.ts
|
|
27
31
|
var adapter_exports = {};
|
|
28
32
|
__export(adapter_exports, {
|
|
29
|
-
activeDevServers: () => activeDevServers,
|
|
30
33
|
createDevServer: () => createDevServer,
|
|
31
34
|
createViteDevMiddleware: () => createViteDevMiddleware,
|
|
32
35
|
createViteDevServer: () => createViteDevServer,
|
|
33
|
-
default: () => adapter
|
|
36
|
+
default: () => adapter,
|
|
37
|
+
getDevGlobal: () => getDevGlobal
|
|
34
38
|
});
|
|
35
39
|
module.exports = __toCommonJS(adapter_exports);
|
|
36
40
|
|
|
@@ -44,8 +48,228 @@ var import_url2 = require("url");
|
|
|
44
48
|
|
|
45
49
|
// src/adapter/dev-server.ts
|
|
46
50
|
var import_vite = require("vite");
|
|
51
|
+
|
|
52
|
+
// src/adapter/polyfill.ts
|
|
53
|
+
var webStream = __toESM(require("stream/web"), 1);
|
|
54
|
+
var import_crypto = require("crypto");
|
|
55
|
+
var undici = __toESM(require("undici"), 1);
|
|
56
|
+
globalThis.crypto ?? (globalThis.crypto = import_crypto.webcrypto);
|
|
57
|
+
globalThis.fetch ?? (globalThis.fetch = undici.fetch);
|
|
58
|
+
globalThis.Response ?? (globalThis.Response = undici.Response);
|
|
59
|
+
globalThis.Request ?? (globalThis.Request = undici.Request);
|
|
60
|
+
globalThis.Headers ?? (globalThis.Headers = undici.Headers);
|
|
61
|
+
globalThis.ReadableStream ?? (globalThis.ReadableStream = webStream.ReadableStream);
|
|
62
|
+
globalThis.TransformStream ?? (globalThis.TransformStream = webStream.TransformStream);
|
|
63
|
+
globalThis.WritableStream ?? (globalThis.WritableStream = webStream.WritableStream);
|
|
64
|
+
globalThis.FormData ?? (globalThis.FormData = undici.FormData);
|
|
65
|
+
globalThis.File ?? (globalThis.File = undici.File);
|
|
66
|
+
|
|
67
|
+
// src/adapter/middleware.ts
|
|
68
|
+
function getForwardedHeader(req, name) {
|
|
69
|
+
const value = req.headers["x-forwarded-" + name];
|
|
70
|
+
if (value) {
|
|
71
|
+
if (typeof value === "string") {
|
|
72
|
+
const index = value.indexOf(",");
|
|
73
|
+
return index < 0 ? value : value.slice(0, index);
|
|
74
|
+
}
|
|
75
|
+
return value[0];
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
function getOrigin(req, trustProxy) {
|
|
79
|
+
const protocol = req.protocol || trustProxy && getForwardedHeader(req, "proto") || (req.socket.encrypted ? "https" : "http");
|
|
80
|
+
let host = req.headers.host || trustProxy && getForwardedHeader(req, "host");
|
|
81
|
+
if (!host) {
|
|
82
|
+
if (process.env.NODE_ENV !== "production") {
|
|
83
|
+
host = "localhost";
|
|
84
|
+
console.warn(
|
|
85
|
+
`Could not automatically determine the origin host, using 'localhost'. Use the 'origin' option or the 'ORIGIN' environment variable to set the origin explicitly.`
|
|
86
|
+
);
|
|
87
|
+
} else {
|
|
88
|
+
throw new Error(
|
|
89
|
+
`Could not automatically determine the origin host. Use the 'origin' option or the 'ORIGIN' environment variable to set the origin explicitly.`
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return `${protocol}://${host}`;
|
|
94
|
+
}
|
|
95
|
+
var inExpiresDateRgs = /Expires\s*=\s*(?:Mon|Tue|Wed|Thu|Fri|Sat|Sun)\s*$/i;
|
|
96
|
+
function setResponseHeaders(response, res) {
|
|
97
|
+
for (const [key, value] of response.headers) {
|
|
98
|
+
if (key !== "set-cookie") {
|
|
99
|
+
res.setHeader(key, value);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
const setCookies = getSetCookie(response.headers);
|
|
103
|
+
if (setCookies == null ? void 0 : setCookies.length) {
|
|
104
|
+
res.setHeader("set-cookie", setCookies);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
var getSetCookie = Headers.prototype.getSetCookie ? getSetCookie_platform : getSetCookie_fallback;
|
|
108
|
+
function getSetCookie_platform(headers) {
|
|
109
|
+
return headers.getSetCookie();
|
|
110
|
+
}
|
|
111
|
+
function getSetCookie_fallback(headers) {
|
|
112
|
+
const value = headers.get("set-cookie");
|
|
113
|
+
if (!value)
|
|
114
|
+
return void 0;
|
|
115
|
+
let sepIndex = value.indexOf(",") + 1;
|
|
116
|
+
if (!sepIndex)
|
|
117
|
+
return value;
|
|
118
|
+
let index = 0;
|
|
119
|
+
let setCookie = void 0;
|
|
120
|
+
let setCookies = void 0;
|
|
121
|
+
do {
|
|
122
|
+
const valuePart = value.slice(index, sepIndex - 1);
|
|
123
|
+
if (!inExpiresDateRgs.test(valuePart)) {
|
|
124
|
+
if (setCookies) {
|
|
125
|
+
setCookies.push(valuePart);
|
|
126
|
+
} else if (setCookie) {
|
|
127
|
+
setCookies = [setCookie, valuePart];
|
|
128
|
+
} else {
|
|
129
|
+
setCookie = valuePart;
|
|
130
|
+
}
|
|
131
|
+
index = sepIndex;
|
|
132
|
+
while (value.charCodeAt(index) === 32)
|
|
133
|
+
index++;
|
|
134
|
+
}
|
|
135
|
+
sepIndex = value.indexOf(",", sepIndex) + 1;
|
|
136
|
+
} while (sepIndex);
|
|
137
|
+
if (index) {
|
|
138
|
+
const valuePart = value.slice(index);
|
|
139
|
+
if (setCookies) {
|
|
140
|
+
setCookies.push(valuePart);
|
|
141
|
+
return setCookies;
|
|
142
|
+
}
|
|
143
|
+
return [setCookie, valuePart];
|
|
144
|
+
}
|
|
145
|
+
return value;
|
|
146
|
+
}
|
|
147
|
+
function createMiddleware(fetch2, options = {}) {
|
|
148
|
+
const {
|
|
149
|
+
origin = process.env.ORIGIN,
|
|
150
|
+
trustProxy = process.env.TRUST_PROXY === "1"
|
|
151
|
+
} = options;
|
|
152
|
+
return async (req, res, next) => {
|
|
153
|
+
var _a;
|
|
154
|
+
const controller = new AbortController();
|
|
155
|
+
const { signal } = controller;
|
|
156
|
+
const url = new URL(req.url, origin || getOrigin(req, trustProxy));
|
|
157
|
+
const ip = req.ip || trustProxy && getForwardedHeader(req, "for") || req.socket.remoteAddress || "";
|
|
158
|
+
req.on("error", onErrorOrClose);
|
|
159
|
+
req.socket.on("error", onErrorOrClose);
|
|
160
|
+
res.on("error", onErrorOrClose);
|
|
161
|
+
res.on("close", onErrorOrClose);
|
|
162
|
+
signal.addEventListener("abort", onSignalAborted);
|
|
163
|
+
function onErrorOrClose(err) {
|
|
164
|
+
req.off("error", onErrorOrClose);
|
|
165
|
+
req.socket.off("error", onErrorOrClose);
|
|
166
|
+
res.off("error", onErrorOrClose);
|
|
167
|
+
res.off("close", onErrorOrClose);
|
|
168
|
+
if (err) {
|
|
169
|
+
signal.removeEventListener("abort", onSignalAborted);
|
|
170
|
+
controller.abort(err);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
function onSignalAborted() {
|
|
174
|
+
if (next) {
|
|
175
|
+
next(signal.reason);
|
|
176
|
+
} else {
|
|
177
|
+
if (!res.destroyed && res.socket) {
|
|
178
|
+
res.socket.destroySoon();
|
|
179
|
+
}
|
|
180
|
+
console.error(signal.reason);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
let setDevClientId;
|
|
184
|
+
if (process.env.NODE_ENV !== "production" && globalThis.__marko_run_dev__ && ((_a = req.headers.accept) == null ? void 0 : _a.includes("text/html"))) {
|
|
185
|
+
setDevClientId = globalThis.__marko_run_dev__.onClient((ws) => {
|
|
186
|
+
if (signal.aborted) {
|
|
187
|
+
sendError();
|
|
188
|
+
} else {
|
|
189
|
+
signal.addEventListener("abort", sendError);
|
|
190
|
+
}
|
|
191
|
+
function sendError() {
|
|
192
|
+
const { message, stack = "" } = signal.reason;
|
|
193
|
+
ws.send(
|
|
194
|
+
JSON.stringify({
|
|
195
|
+
type: "error",
|
|
196
|
+
err: { message, stack }
|
|
197
|
+
})
|
|
198
|
+
);
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
let body;
|
|
203
|
+
if (req.method !== "GET" && req.method !== "HEAD") {
|
|
204
|
+
if (req.readableDidRead) {
|
|
205
|
+
body = bodyConsumedErrorStream;
|
|
206
|
+
} else {
|
|
207
|
+
body = req;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
const request = new Request(url, {
|
|
211
|
+
method: req.method,
|
|
212
|
+
headers: req.headers,
|
|
213
|
+
body,
|
|
214
|
+
// @ts-expect-error: Node requires this for streams
|
|
215
|
+
duplex: "half",
|
|
216
|
+
signal
|
|
217
|
+
});
|
|
218
|
+
const response = await fetch2(request, {
|
|
219
|
+
ip,
|
|
220
|
+
request: req,
|
|
221
|
+
response: res
|
|
222
|
+
});
|
|
223
|
+
if (!response) {
|
|
224
|
+
if (next) {
|
|
225
|
+
next();
|
|
226
|
+
}
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
if (process.env.NODE_ENV !== "production" && setDevClientId) {
|
|
230
|
+
setDevClientId(response);
|
|
231
|
+
}
|
|
232
|
+
res.statusCode = response.status;
|
|
233
|
+
setResponseHeaders(response, res);
|
|
234
|
+
if (!response.body) {
|
|
235
|
+
if (!response.headers.has("content-length")) {
|
|
236
|
+
res.setHeader("content-length", "0");
|
|
237
|
+
}
|
|
238
|
+
res.end();
|
|
239
|
+
return;
|
|
240
|
+
} else if (res.destroyed) {
|
|
241
|
+
controller.abort(new Error("Response stream destroyed"));
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
writeResponse(response.body.getReader(), res, controller);
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
async function writeResponse(reader, res, controller) {
|
|
248
|
+
try {
|
|
249
|
+
while (!controller.signal.aborted) {
|
|
250
|
+
const { done, value } = await reader.read();
|
|
251
|
+
if (done) {
|
|
252
|
+
res.end();
|
|
253
|
+
return;
|
|
254
|
+
} else if (!res.write(value)) {
|
|
255
|
+
res.once("drain", () => writeResponse(reader, res, controller));
|
|
256
|
+
return;
|
|
257
|
+
} else if (res.flush) {
|
|
258
|
+
res.flush();
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
} catch (err) {
|
|
262
|
+
controller.abort(err);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
var bodyConsumedErrorStream = new ReadableStream({
|
|
266
|
+
start(controller) {
|
|
267
|
+
controller.error(new Error("The request body stream was already consumed by something before Marko Run."));
|
|
268
|
+
}
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
// src/adapter/dev-server.ts
|
|
47
272
|
var import_strip_ansi = __toESM(require("strip-ansi"), 1);
|
|
48
|
-
var activeDevServers = /* @__PURE__ */ new Set();
|
|
49
273
|
function createViteDevMiddleware(devServer, load, factory) {
|
|
50
274
|
let value;
|
|
51
275
|
let middleware;
|
|
@@ -74,34 +298,239 @@ async function createViteDevServer(config2) {
|
|
|
74
298
|
appType: "custom",
|
|
75
299
|
server: { ...config2 == null ? void 0 : config2.server, middlewareMode: true }
|
|
76
300
|
});
|
|
77
|
-
|
|
78
|
-
devServer.close = () => {
|
|
79
|
-
activeDevServers.delete(devServer);
|
|
80
|
-
return originalClose.call(devServer);
|
|
81
|
-
};
|
|
82
|
-
activeDevServers.add(devServer);
|
|
301
|
+
getDevGlobal().addDevServer(devServer);
|
|
83
302
|
return devServer;
|
|
84
303
|
}
|
|
85
304
|
async function createDevServer(config2) {
|
|
86
305
|
const devServer = await createViteDevServer(config2);
|
|
87
|
-
const
|
|
88
|
-
|
|
89
|
-
);
|
|
90
|
-
let fetch;
|
|
91
|
-
const nodeMiddleware = createMiddleware(
|
|
92
|
-
(request, platform) => fetch(request, platform),
|
|
93
|
-
{ devServer }
|
|
306
|
+
const routerMiddleware = createMiddleware(
|
|
307
|
+
(request, platform) => globalThis.__marko_run__.fetch(request, platform)
|
|
94
308
|
);
|
|
95
|
-
|
|
96
|
-
devServer
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
309
|
+
devServer.middlewares.use(async (req, res, next) => {
|
|
310
|
+
await devServer.ssrLoadModule("@marko/run/router");
|
|
311
|
+
routerMiddleware(req, res, (err) => {
|
|
312
|
+
if (err) {
|
|
313
|
+
res.statusCode = 500;
|
|
314
|
+
if (err instanceof Error) {
|
|
315
|
+
devServer.ssrFixStacktrace(err);
|
|
316
|
+
res.end(err.stack && (0, import_strip_ansi.default)(err.stack));
|
|
317
|
+
} else {
|
|
318
|
+
res.end();
|
|
319
|
+
}
|
|
320
|
+
} else {
|
|
321
|
+
next == null ? void 0 : next();
|
|
322
|
+
}
|
|
323
|
+
});
|
|
324
|
+
});
|
|
325
|
+
return devServer;
|
|
326
|
+
}
|
|
327
|
+
var ClientIdCookieName = "marko-run-client-id";
|
|
328
|
+
function getClientId(req) {
|
|
329
|
+
if (req.headers.cookie) {
|
|
330
|
+
const cookie = req.headers.cookie.split(/;\s+/).find((c) => c.startsWith(ClientIdCookieName));
|
|
331
|
+
if (cookie) {
|
|
332
|
+
return cookie.slice(ClientIdCookieName.length + 1);
|
|
101
333
|
}
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
var devGlobal;
|
|
337
|
+
function getDevGlobal() {
|
|
338
|
+
if (!devGlobal) {
|
|
339
|
+
let handleConnection2 = function(ws, req) {
|
|
340
|
+
if (callbacks == null ? void 0 : callbacks.length) {
|
|
341
|
+
const id = getClientId(req);
|
|
342
|
+
const now = Date.now();
|
|
343
|
+
const nextCallbacks = [];
|
|
344
|
+
for (const entry of callbacks) {
|
|
345
|
+
if (entry.id === id) {
|
|
346
|
+
entry.callback(ws);
|
|
347
|
+
} else if (entry.expires > now) {
|
|
348
|
+
nextCallbacks.push(entry);
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
callbacks = nextCallbacks;
|
|
352
|
+
}
|
|
353
|
+
};
|
|
354
|
+
var handleConnection = handleConnection2;
|
|
355
|
+
const devServers = /* @__PURE__ */ new Set();
|
|
356
|
+
let callbacks = [];
|
|
357
|
+
globalThis.__marko_run_dev__ = devGlobal = {
|
|
358
|
+
devServers,
|
|
359
|
+
addDevServer(devServer) {
|
|
360
|
+
const originalClose = devServer.close;
|
|
361
|
+
devServer.close = () => {
|
|
362
|
+
devServers.delete(devServer);
|
|
363
|
+
return originalClose.call(devServer);
|
|
364
|
+
};
|
|
365
|
+
devServers.add(devServer);
|
|
366
|
+
devServer.ws.on("connection", handleConnection2);
|
|
367
|
+
},
|
|
368
|
+
clear() {
|
|
369
|
+
callbacks = [];
|
|
370
|
+
for (const devServer of devServers) {
|
|
371
|
+
devServer.ws.off("connection", handleConnection2);
|
|
372
|
+
devServer.close();
|
|
373
|
+
}
|
|
374
|
+
},
|
|
375
|
+
onClient(callback) {
|
|
376
|
+
const expires = Date.now() + 1e3;
|
|
377
|
+
const id = Math.floor(Math.random() * expires).toString(36);
|
|
378
|
+
callbacks.push({
|
|
379
|
+
id,
|
|
380
|
+
expires,
|
|
381
|
+
callback
|
|
382
|
+
});
|
|
383
|
+
return (response) => {
|
|
384
|
+
response.headers.append(
|
|
385
|
+
"set-cookie",
|
|
386
|
+
`${ClientIdCookieName}=${id}; Path=/; Max-Age=100; HttpOnly`
|
|
387
|
+
);
|
|
388
|
+
};
|
|
389
|
+
}
|
|
390
|
+
};
|
|
391
|
+
}
|
|
392
|
+
return devGlobal;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
// src/adapter/utils.ts
|
|
396
|
+
var import_supports_color = __toESM(require("supports-color"), 1);
|
|
397
|
+
var import_kleur = __toESM(require("kleur"), 1);
|
|
398
|
+
function logInfoBox(address) {
|
|
399
|
+
const color = !!import_supports_color.default.stdout;
|
|
400
|
+
let message = import_kleur.default.bold("Marko Run");
|
|
401
|
+
if (true) {
|
|
402
|
+
message += ` v${"0.2.8"}`;
|
|
403
|
+
}
|
|
404
|
+
message += "\n\n";
|
|
405
|
+
message += import_kleur.default.dim("Server listening at");
|
|
406
|
+
message += "\n";
|
|
407
|
+
message += import_kleur.default.cyan(import_kleur.default.underline(address));
|
|
408
|
+
const lines = drawMarkoBox(message, { color, fill: color });
|
|
409
|
+
console.log(lines.join("\n"));
|
|
410
|
+
}
|
|
411
|
+
function drawMarkoBox(message, options) {
|
|
412
|
+
const textPaddingWidth = 3;
|
|
413
|
+
const logoPaddingWidth = 2;
|
|
414
|
+
const textPadding = " ".repeat(textPaddingWidth);
|
|
415
|
+
const logoPadding = " ".repeat(logoPaddingWidth);
|
|
416
|
+
const logo = drawMarkoLogo(options);
|
|
417
|
+
const textLines = message.split(/\n/);
|
|
418
|
+
const textWidths = textLines.map(
|
|
419
|
+
(line) => line.replace(/\x1b\[\d+m/g, "").length
|
|
102
420
|
);
|
|
103
|
-
|
|
104
|
-
|
|
421
|
+
const textWidth = Math.max(...textWidths);
|
|
422
|
+
const height = Math.max(textLines.length + 2, logo.lines.length);
|
|
423
|
+
const width = textPaddingWidth * 2 + logoPaddingWidth + textWidth + logo.width;
|
|
424
|
+
const hBorder = "\u2500".repeat(width);
|
|
425
|
+
const vBorder = "\u2502";
|
|
426
|
+
const lineDiff = logo.lines.length - textLines.length;
|
|
427
|
+
const textStartLine = lineDiff > 0 ? Math.floor(lineDiff / 2) : 1;
|
|
428
|
+
const textEndLine = height - (lineDiff > 0 ? Math.ceil(lineDiff / 2) : 1);
|
|
429
|
+
const logoEndLine = logo.lines.length;
|
|
430
|
+
const logoFill = " ".repeat(logo.width);
|
|
431
|
+
const textFill = " ".repeat(textWidth);
|
|
432
|
+
const lines = [`\u256D${hBorder}\u256E`];
|
|
433
|
+
for (let i = 0; i < height; i++) {
|
|
434
|
+
let line = vBorder;
|
|
435
|
+
line += logoPadding;
|
|
436
|
+
if (i < logoEndLine) {
|
|
437
|
+
line += logo.lines[i];
|
|
438
|
+
} else {
|
|
439
|
+
line += logoFill;
|
|
440
|
+
}
|
|
441
|
+
line += textPadding;
|
|
442
|
+
if (i >= textStartLine && i < textEndLine) {
|
|
443
|
+
let index = i - textStartLine;
|
|
444
|
+
line += textLines[index];
|
|
445
|
+
line += " ".repeat(textWidth - textWidths[index]);
|
|
446
|
+
} else {
|
|
447
|
+
line += textFill;
|
|
448
|
+
}
|
|
449
|
+
line += textPadding;
|
|
450
|
+
line += vBorder;
|
|
451
|
+
lines.push(line);
|
|
452
|
+
}
|
|
453
|
+
lines.push(`\u2570${hBorder}\u256F`);
|
|
454
|
+
return lines;
|
|
455
|
+
}
|
|
456
|
+
function drawMarkoLogo(options = {}) {
|
|
457
|
+
const { fill = true, color = true } = options;
|
|
458
|
+
const source = `
|
|
459
|
+
TT____ YY____ R____
|
|
460
|
+
C\u2571T\u2572 \u2572G\u2571Y\u2572 \u2572 R\u2572 \u2572
|
|
461
|
+
C\u2571 T\u2572 G\u2571 Y\u2572 \u2572 R\u2572 \u2572
|
|
462
|
+
C\u2571 \u2571T\u2572G\u2571 \u2571Y\u2572 \u2572 R\u2572 \u2572
|
|
463
|
+
B\u2572 \u2572 GG\u203E\u203E\u203E\u203E O\u2571 \u2571 P\u2571 \u2571
|
|
464
|
+
B\u2572 \u2572 OOO\u2571 \u2571 P\u2571 \u2571
|
|
465
|
+
B\u2572 \u2572 OOO\u2571 \u2571 P\u2571 \u2571
|
|
466
|
+
B\u203E\u203E\u203E\u203E OOO\u203E\u203E\u203E\u203E P\u203E\u203E\u203E\u203E
|
|
467
|
+
`;
|
|
468
|
+
const resetEscape = "\x1B[0m";
|
|
469
|
+
const colorEscapeCodes = Object.entries({
|
|
470
|
+
B: "#06cfe5",
|
|
471
|
+
C: "#05a5f0",
|
|
472
|
+
T: "#19d89c",
|
|
473
|
+
G: "#81dc09",
|
|
474
|
+
Y: "#ffd900",
|
|
475
|
+
O: "#ff9500",
|
|
476
|
+
R: "#f3154d",
|
|
477
|
+
P: "#ce176c"
|
|
478
|
+
}).reduce((acc, [key, hex]) => {
|
|
479
|
+
const r = parseInt(hex.slice(1, 3), 16);
|
|
480
|
+
const g = parseInt(hex.slice(3, 5), 16);
|
|
481
|
+
const b = parseInt(hex.slice(5, 7), 16);
|
|
482
|
+
acc[key] = `\x1B[38;2;${r};${g};${b}m`;
|
|
483
|
+
return acc;
|
|
484
|
+
}, {});
|
|
485
|
+
const lines = [];
|
|
486
|
+
const lineWidths = [];
|
|
487
|
+
let line = "";
|
|
488
|
+
let lineWidth = 0;
|
|
489
|
+
let width = 0;
|
|
490
|
+
for (let i = 0; i < source.length; i++) {
|
|
491
|
+
let char = source[i];
|
|
492
|
+
if (char === "\n") {
|
|
493
|
+
if (line) {
|
|
494
|
+
if (color) {
|
|
495
|
+
line += resetEscape;
|
|
496
|
+
}
|
|
497
|
+
width = Math.max(lineWidth, width);
|
|
498
|
+
lines.push(line);
|
|
499
|
+
lineWidths.push(lineWidth);
|
|
500
|
+
line = "";
|
|
501
|
+
lineWidth = 0;
|
|
502
|
+
}
|
|
503
|
+
} else if (/[A-Z]/.test(char)) {
|
|
504
|
+
while (source[i + 1] === char)
|
|
505
|
+
i++;
|
|
506
|
+
if (color) {
|
|
507
|
+
line += colorEscapeCodes[char];
|
|
508
|
+
}
|
|
509
|
+
if (fill) {
|
|
510
|
+
let fillChar = "";
|
|
511
|
+
for (; i < source.length; i++) {
|
|
512
|
+
char = source[i + 1];
|
|
513
|
+
if (fillChar && char !== " ") {
|
|
514
|
+
break;
|
|
515
|
+
} else if (!fillChar) {
|
|
516
|
+
fillChar = char;
|
|
517
|
+
}
|
|
518
|
+
line += fillChar;
|
|
519
|
+
lineWidth++;
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
} else {
|
|
523
|
+
line += char;
|
|
524
|
+
lineWidth++;
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
for (let i = 0; i < lines.length; i++) {
|
|
528
|
+
const padding = width - lineWidths[i];
|
|
529
|
+
if (padding > 0) {
|
|
530
|
+
lines[i] += " ".repeat(width - lineWidths[i]);
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
return { lines, width };
|
|
105
534
|
}
|
|
106
535
|
|
|
107
536
|
// src/vite/utils/server.ts
|
|
@@ -259,6 +688,7 @@ function adapter() {
|
|
|
259
688
|
},
|
|
260
689
|
async startDev(entry, config2, options) {
|
|
261
690
|
const { port = 3e3, envFile } = options;
|
|
691
|
+
globalThis.__marko_run_vite_config__ = config2;
|
|
262
692
|
if (entry) {
|
|
263
693
|
const { nodeArgs } = (0, import_parse_node_args.default)(options.args);
|
|
264
694
|
let worker;
|
|
@@ -302,7 +732,7 @@ function adapter() {
|
|
|
302
732
|
return new Promise((resolve) => {
|
|
303
733
|
const listener = devServer.middlewares.listen(port, () => {
|
|
304
734
|
const address = listener.address();
|
|
305
|
-
|
|
735
|
+
logInfoBox(`http://localhost:${address.port}`);
|
|
306
736
|
resolve({
|
|
307
737
|
port,
|
|
308
738
|
async close() {
|
|
@@ -317,15 +747,17 @@ function adapter() {
|
|
|
317
747
|
const { nodeArgs } = (0, import_parse_node_args.default)(options.args);
|
|
318
748
|
const args = [...nodeArgs, entry];
|
|
319
749
|
const server = await spawnServer("node", args, port, envFile);
|
|
320
|
-
|
|
750
|
+
if (!options.sourceEntry) {
|
|
751
|
+
logInfoBox(`http://localhost:${port}`);
|
|
752
|
+
}
|
|
321
753
|
return server;
|
|
322
754
|
}
|
|
323
755
|
};
|
|
324
756
|
}
|
|
325
757
|
// Annotate the CommonJS export names for ESM import in node:
|
|
326
758
|
0 && (module.exports = {
|
|
327
|
-
activeDevServers,
|
|
328
759
|
createDevServer,
|
|
329
760
|
createViteDevMiddleware,
|
|
330
|
-
createViteDevServer
|
|
761
|
+
createViteDevServer,
|
|
762
|
+
getDevGlobal
|
|
331
763
|
});
|
package/dist/adapter/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { Adapter } from "../vite";
|
|
2
|
+
import { type MarkoRunDev } from "./dev-server";
|
|
2
3
|
import { type SpawnedServer } from "../vite/utils/server";
|
|
3
|
-
export {
|
|
4
|
+
export { getDevGlobal, createDevServer, createViteDevServer, createViteDevMiddleware, type MarkoRunDev, } from "./dev-server";
|
|
4
5
|
export type { Adapter, SpawnedServer };
|
|
5
6
|
export type { NodePlatformInfo } from "./middleware";
|
|
7
|
+
export type MarkoRunDevAccessor = () => MarkoRunDev;
|
|
6
8
|
export default function adapter(): Adapter;
|