@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
|
@@ -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
|
));
|
|
@@ -132,95 +136,74 @@ function getSetCookie_fallback(headers) {
|
|
|
132
136
|
}
|
|
133
137
|
return value;
|
|
134
138
|
}
|
|
135
|
-
var HRMClientIdCookieName = "hmr-client-id";
|
|
136
|
-
function getHMRClientId(req) {
|
|
137
|
-
if (req.headers.cookie) {
|
|
138
|
-
const cookie = req.headers.cookie.split(/;\s+/).find((c) => c.startsWith(HRMClientIdCookieName));
|
|
139
|
-
if (cookie) {
|
|
140
|
-
return cookie.slice(HRMClientIdCookieName.length + 1);
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
139
|
function createMiddleware(fetch2, options = {}) {
|
|
145
140
|
const {
|
|
146
141
|
origin = process.env.ORIGIN,
|
|
147
|
-
trustProxy = process.env.TRUST_PROXY === "1"
|
|
148
|
-
devServer
|
|
142
|
+
trustProxy = process.env.TRUST_PROXY === "1"
|
|
149
143
|
} = options;
|
|
150
|
-
let hmrCallbacks;
|
|
151
|
-
if (process.env.NODE_ENV !== "production" && devServer) {
|
|
152
|
-
hmrCallbacks = [];
|
|
153
|
-
devServer.ws.on("connection", (ws, req) => {
|
|
154
|
-
if (hmrCallbacks == null ? void 0 : hmrCallbacks.length) {
|
|
155
|
-
const id = getHMRClientId(req);
|
|
156
|
-
const now = Date.now();
|
|
157
|
-
const nextHMRCallbacks = [];
|
|
158
|
-
for (const entry of hmrCallbacks) {
|
|
159
|
-
if (entry.id === id) {
|
|
160
|
-
entry.callback(ws);
|
|
161
|
-
} else if (entry.expires > now) {
|
|
162
|
-
nextHMRCallbacks.push(entry);
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
hmrCallbacks = nextHMRCallbacks;
|
|
166
|
-
}
|
|
167
|
-
});
|
|
168
|
-
}
|
|
169
144
|
return async (req, res, next) => {
|
|
170
145
|
var _a;
|
|
171
146
|
const controller = new AbortController();
|
|
172
147
|
const { signal } = controller;
|
|
173
148
|
const url = new URL(req.url, origin || getOrigin(req, trustProxy));
|
|
174
149
|
const ip = req.ip || trustProxy && getForwardedHeader(req, "for") || req.socket.remoteAddress || "";
|
|
175
|
-
const headers = req.headers;
|
|
176
150
|
req.on("error", onErrorOrClose);
|
|
177
151
|
req.socket.on("error", onErrorOrClose);
|
|
178
152
|
res.on("error", onErrorOrClose);
|
|
179
153
|
res.on("close", onErrorOrClose);
|
|
154
|
+
signal.addEventListener("abort", onSignalAborted);
|
|
180
155
|
function onErrorOrClose(err) {
|
|
181
156
|
req.off("error", onErrorOrClose);
|
|
182
157
|
req.socket.off("error", onErrorOrClose);
|
|
183
158
|
res.off("error", onErrorOrClose);
|
|
184
159
|
res.off("close", onErrorOrClose);
|
|
185
160
|
if (err) {
|
|
161
|
+
signal.removeEventListener("abort", onSignalAborted);
|
|
186
162
|
controller.abort(err);
|
|
187
163
|
}
|
|
188
164
|
}
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
hmrCallbacks.push({
|
|
194
|
-
id: hmrId,
|
|
195
|
-
expires,
|
|
196
|
-
callback(ws) {
|
|
197
|
-
if (signal.aborted) {
|
|
198
|
-
sendError();
|
|
199
|
-
} else {
|
|
200
|
-
signal.addEventListener("abort", sendError);
|
|
201
|
-
}
|
|
202
|
-
function sendError() {
|
|
203
|
-
const { message, stack = "" } = signal.reason;
|
|
204
|
-
ws.send(
|
|
205
|
-
JSON.stringify({
|
|
206
|
-
type: "error",
|
|
207
|
-
err: { message, stack }
|
|
208
|
-
})
|
|
209
|
-
);
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
});
|
|
213
|
-
} else {
|
|
214
|
-
signal.addEventListener("abort", () => {
|
|
165
|
+
function onSignalAborted() {
|
|
166
|
+
if (next) {
|
|
167
|
+
next(signal.reason);
|
|
168
|
+
} else {
|
|
215
169
|
if (!res.destroyed && res.socket) {
|
|
216
170
|
res.socket.destroySoon();
|
|
217
171
|
}
|
|
172
|
+
console.error(signal.reason);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
let setDevClientId;
|
|
176
|
+
if (process.env.NODE_ENV !== "production" && globalThis.__marko_run_dev__ && ((_a = req.headers.accept) == null ? void 0 : _a.includes("text/html"))) {
|
|
177
|
+
setDevClientId = globalThis.__marko_run_dev__.onClient((ws) => {
|
|
178
|
+
if (signal.aborted) {
|
|
179
|
+
sendError();
|
|
180
|
+
} else {
|
|
181
|
+
signal.addEventListener("abort", sendError);
|
|
182
|
+
}
|
|
183
|
+
function sendError() {
|
|
184
|
+
const { message, stack = "" } = signal.reason;
|
|
185
|
+
ws.send(
|
|
186
|
+
JSON.stringify({
|
|
187
|
+
type: "error",
|
|
188
|
+
err: { message, stack }
|
|
189
|
+
})
|
|
190
|
+
);
|
|
191
|
+
}
|
|
218
192
|
});
|
|
219
193
|
}
|
|
194
|
+
let body;
|
|
195
|
+
if (req.method !== "GET" && req.method !== "HEAD") {
|
|
196
|
+
if (req.readableDidRead) {
|
|
197
|
+
body = bodyConsumedErrorStream;
|
|
198
|
+
} else {
|
|
199
|
+
body = req;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
220
202
|
const request = new Request(url, {
|
|
221
203
|
method: req.method,
|
|
222
|
-
headers,
|
|
223
|
-
body
|
|
204
|
+
headers: req.headers,
|
|
205
|
+
body,
|
|
206
|
+
// @ts-expect-error: Node requires this for streams
|
|
224
207
|
duplex: "half",
|
|
225
208
|
signal
|
|
226
209
|
});
|
|
@@ -235,11 +218,8 @@ function createMiddleware(fetch2, options = {}) {
|
|
|
235
218
|
}
|
|
236
219
|
return;
|
|
237
220
|
}
|
|
238
|
-
if (process.env.NODE_ENV !== "production" &&
|
|
239
|
-
response
|
|
240
|
-
"set-cookie",
|
|
241
|
-
`${HRMClientIdCookieName}=${hmrId}; Path=/; Max-Age=100; HttpOnly`
|
|
242
|
-
);
|
|
221
|
+
if (process.env.NODE_ENV !== "production" && setDevClientId) {
|
|
222
|
+
setDevClientId(response);
|
|
243
223
|
}
|
|
244
224
|
res.statusCode = response.status;
|
|
245
225
|
setResponseHeaders(response, res);
|
|
@@ -274,6 +254,11 @@ async function writeResponse(reader, res, controller) {
|
|
|
274
254
|
controller.abort(err);
|
|
275
255
|
}
|
|
276
256
|
}
|
|
257
|
+
var bodyConsumedErrorStream = new ReadableStream({
|
|
258
|
+
start(controller) {
|
|
259
|
+
controller.error(new Error("The request body stream was already consumed by something before Marko Run."));
|
|
260
|
+
}
|
|
261
|
+
});
|
|
277
262
|
// Annotate the CommonJS export names for ESM import in node:
|
|
278
263
|
0 && (module.exports = {
|
|
279
264
|
createMiddleware,
|
|
@@ -2,14 +2,13 @@
|
|
|
2
2
|
import "./polyfill";
|
|
3
3
|
import type { Fetch } from "../runtime";
|
|
4
4
|
import type { IncomingMessage, ServerResponse, OutgoingMessage } from "http";
|
|
5
|
-
import type { ViteDevServer } from "vite";
|
|
6
5
|
export interface NodePlatformInfo {
|
|
7
6
|
ip: string;
|
|
8
7
|
request: IncomingMessage;
|
|
9
8
|
response: ServerResponse;
|
|
10
9
|
}
|
|
11
10
|
/** Connect/Express style request listener/middleware */
|
|
12
|
-
export type NodeMiddleware = (req: IncomingMessage, res: ServerResponse, next?: () => void) => void;
|
|
11
|
+
export type NodeMiddleware = (req: IncomingMessage, res: ServerResponse, next?: (error?: Error) => void) => void;
|
|
13
12
|
/** Adapter options */
|
|
14
13
|
export interface NodeAdapterOptions {
|
|
15
14
|
/**
|
|
@@ -32,7 +31,6 @@ export interface NodeAdapterOptions {
|
|
|
32
31
|
* is set to `1`, otherwise false.
|
|
33
32
|
*/
|
|
34
33
|
trustProxy?: boolean;
|
|
35
|
-
devServer?: ViteDevServer;
|
|
36
34
|
}
|
|
37
35
|
export declare function getOrigin(req: IncomingMessage, trustProxy?: boolean): string;
|
|
38
36
|
export declare function setResponseHeaders(response: Response, res: OutgoingMessage): void;
|
|
@@ -93,95 +93,74 @@ function getSetCookie_fallback(headers) {
|
|
|
93
93
|
}
|
|
94
94
|
return value;
|
|
95
95
|
}
|
|
96
|
-
var HRMClientIdCookieName = "hmr-client-id";
|
|
97
|
-
function getHMRClientId(req) {
|
|
98
|
-
if (req.headers.cookie) {
|
|
99
|
-
const cookie = req.headers.cookie.split(/;\s+/).find((c) => c.startsWith(HRMClientIdCookieName));
|
|
100
|
-
if (cookie) {
|
|
101
|
-
return cookie.slice(HRMClientIdCookieName.length + 1);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
96
|
function createMiddleware(fetch2, options = {}) {
|
|
106
97
|
const {
|
|
107
98
|
origin = process.env.ORIGIN,
|
|
108
|
-
trustProxy = process.env.TRUST_PROXY === "1"
|
|
109
|
-
devServer
|
|
99
|
+
trustProxy = process.env.TRUST_PROXY === "1"
|
|
110
100
|
} = options;
|
|
111
|
-
let hmrCallbacks;
|
|
112
|
-
if (process.env.NODE_ENV !== "production" && devServer) {
|
|
113
|
-
hmrCallbacks = [];
|
|
114
|
-
devServer.ws.on("connection", (ws, req) => {
|
|
115
|
-
if (hmrCallbacks == null ? void 0 : hmrCallbacks.length) {
|
|
116
|
-
const id = getHMRClientId(req);
|
|
117
|
-
const now = Date.now();
|
|
118
|
-
const nextHMRCallbacks = [];
|
|
119
|
-
for (const entry of hmrCallbacks) {
|
|
120
|
-
if (entry.id === id) {
|
|
121
|
-
entry.callback(ws);
|
|
122
|
-
} else if (entry.expires > now) {
|
|
123
|
-
nextHMRCallbacks.push(entry);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
hmrCallbacks = nextHMRCallbacks;
|
|
127
|
-
}
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
101
|
return async (req, res, next) => {
|
|
131
102
|
var _a;
|
|
132
103
|
const controller = new AbortController();
|
|
133
104
|
const { signal } = controller;
|
|
134
105
|
const url = new URL(req.url, origin || getOrigin(req, trustProxy));
|
|
135
106
|
const ip = req.ip || trustProxy && getForwardedHeader(req, "for") || req.socket.remoteAddress || "";
|
|
136
|
-
const headers = req.headers;
|
|
137
107
|
req.on("error", onErrorOrClose);
|
|
138
108
|
req.socket.on("error", onErrorOrClose);
|
|
139
109
|
res.on("error", onErrorOrClose);
|
|
140
110
|
res.on("close", onErrorOrClose);
|
|
111
|
+
signal.addEventListener("abort", onSignalAborted);
|
|
141
112
|
function onErrorOrClose(err) {
|
|
142
113
|
req.off("error", onErrorOrClose);
|
|
143
114
|
req.socket.off("error", onErrorOrClose);
|
|
144
115
|
res.off("error", onErrorOrClose);
|
|
145
116
|
res.off("close", onErrorOrClose);
|
|
146
117
|
if (err) {
|
|
118
|
+
signal.removeEventListener("abort", onSignalAborted);
|
|
147
119
|
controller.abort(err);
|
|
148
120
|
}
|
|
149
121
|
}
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
hmrCallbacks.push({
|
|
155
|
-
id: hmrId,
|
|
156
|
-
expires,
|
|
157
|
-
callback(ws) {
|
|
158
|
-
if (signal.aborted) {
|
|
159
|
-
sendError();
|
|
160
|
-
} else {
|
|
161
|
-
signal.addEventListener("abort", sendError);
|
|
162
|
-
}
|
|
163
|
-
function sendError() {
|
|
164
|
-
const { message, stack = "" } = signal.reason;
|
|
165
|
-
ws.send(
|
|
166
|
-
JSON.stringify({
|
|
167
|
-
type: "error",
|
|
168
|
-
err: { message, stack }
|
|
169
|
-
})
|
|
170
|
-
);
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
});
|
|
174
|
-
} else {
|
|
175
|
-
signal.addEventListener("abort", () => {
|
|
122
|
+
function onSignalAborted() {
|
|
123
|
+
if (next) {
|
|
124
|
+
next(signal.reason);
|
|
125
|
+
} else {
|
|
176
126
|
if (!res.destroyed && res.socket) {
|
|
177
127
|
res.socket.destroySoon();
|
|
178
128
|
}
|
|
129
|
+
console.error(signal.reason);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
let setDevClientId;
|
|
133
|
+
if (process.env.NODE_ENV !== "production" && globalThis.__marko_run_dev__ && ((_a = req.headers.accept) == null ? void 0 : _a.includes("text/html"))) {
|
|
134
|
+
setDevClientId = globalThis.__marko_run_dev__.onClient((ws) => {
|
|
135
|
+
if (signal.aborted) {
|
|
136
|
+
sendError();
|
|
137
|
+
} else {
|
|
138
|
+
signal.addEventListener("abort", sendError);
|
|
139
|
+
}
|
|
140
|
+
function sendError() {
|
|
141
|
+
const { message, stack = "" } = signal.reason;
|
|
142
|
+
ws.send(
|
|
143
|
+
JSON.stringify({
|
|
144
|
+
type: "error",
|
|
145
|
+
err: { message, stack }
|
|
146
|
+
})
|
|
147
|
+
);
|
|
148
|
+
}
|
|
179
149
|
});
|
|
180
150
|
}
|
|
151
|
+
let body;
|
|
152
|
+
if (req.method !== "GET" && req.method !== "HEAD") {
|
|
153
|
+
if (req.readableDidRead) {
|
|
154
|
+
body = bodyConsumedErrorStream;
|
|
155
|
+
} else {
|
|
156
|
+
body = req;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
181
159
|
const request = new Request(url, {
|
|
182
160
|
method: req.method,
|
|
183
|
-
headers,
|
|
184
|
-
body
|
|
161
|
+
headers: req.headers,
|
|
162
|
+
body,
|
|
163
|
+
// @ts-expect-error: Node requires this for streams
|
|
185
164
|
duplex: "half",
|
|
186
165
|
signal
|
|
187
166
|
});
|
|
@@ -196,11 +175,8 @@ function createMiddleware(fetch2, options = {}) {
|
|
|
196
175
|
}
|
|
197
176
|
return;
|
|
198
177
|
}
|
|
199
|
-
if (process.env.NODE_ENV !== "production" &&
|
|
200
|
-
response
|
|
201
|
-
"set-cookie",
|
|
202
|
-
`${HRMClientIdCookieName}=${hmrId}; Path=/; Max-Age=100; HttpOnly`
|
|
203
|
-
);
|
|
178
|
+
if (process.env.NODE_ENV !== "production" && setDevClientId) {
|
|
179
|
+
setDevClientId(response);
|
|
204
180
|
}
|
|
205
181
|
res.statusCode = response.status;
|
|
206
182
|
setResponseHeaders(response, res);
|
|
@@ -235,6 +211,11 @@ async function writeResponse(reader, res, controller) {
|
|
|
235
211
|
controller.abort(err);
|
|
236
212
|
}
|
|
237
213
|
}
|
|
214
|
+
var bodyConsumedErrorStream = new ReadableStream({
|
|
215
|
+
start(controller) {
|
|
216
|
+
controller.error(new Error("The request body stream was already consumed by something before Marko Run."));
|
|
217
|
+
}
|
|
218
|
+
});
|
|
238
219
|
export {
|
|
239
220
|
createMiddleware,
|
|
240
221
|
getOrigin,
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
|
|
16
|
+
// src/adapter/runtime.ts
|
|
17
|
+
var runtime_exports = {};
|
|
18
|
+
module.exports = __toCommonJS(runtime_exports);
|
|
19
|
+
|
|
20
|
+
// scripts/importMetaURL.js
|
|
21
|
+
var import_url = require("url");
|
|
22
|
+
var __importMetaURL = (0, import_url.pathToFileURL)(__filename);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
File without changes
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare function logInfoBox(address: string): void;
|
|
2
|
+
export declare function drawMarkoBox(message: string, options?: LogoOptions): string[];
|
|
3
|
+
export interface LogoOptions {
|
|
4
|
+
fill?: boolean;
|
|
5
|
+
color?: boolean;
|
|
6
|
+
}
|
|
7
|
+
export declare function drawMarkoLogo(options?: LogoOptions): {
|
|
8
|
+
lines: string[];
|
|
9
|
+
width: number;
|
|
10
|
+
};
|