@zuplo/cli 6.13.2 → 6.14.0
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/common/errors/stacktracy.d.ts +31 -0
- package/dist/common/errors/stacktracy.d.ts.map +1 -0
- package/dist/common/errors/stacktracy.js +252 -0
- package/dist/common/errors/stacktracy.js.map +1 -0
- package/dist/common/errors/youch-terminal.d.ts +3 -0
- package/dist/common/errors/youch-terminal.d.ts.map +1 -0
- package/dist/common/errors/youch-terminal.js +156 -0
- package/dist/common/errors/youch-terminal.js.map +1 -0
- package/dist/common/errors/youch.d.ts +20 -0
- package/dist/common/errors/youch.d.ts.map +1 -0
- package/dist/common/errors/youch.js +123 -0
- package/dist/common/errors/youch.js.map +1 -0
- package/dist/common/worker-output.d.ts +23 -0
- package/dist/common/worker-output.d.ts.map +1 -0
- package/dist/common/worker-output.js +180 -0
- package/dist/common/worker-output.js.map +1 -0
- package/dist/common/worker-output.spec.d.ts +2 -0
- package/dist/common/worker-output.spec.d.ts.map +1 -0
- package/dist/common/worker-output.spec.js +64 -0
- package/dist/common/worker-output.spec.js.map +1 -0
- package/dist/compile/handler.d.ts.map +1 -1
- package/dist/compile/handler.js +2 -0
- package/dist/compile/handler.js.map +1 -1
- package/dist/dev/handler.d.ts.map +1 -1
- package/dist/dev/handler.js +13 -2
- package/dist/dev/handler.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +8 -3
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { readFile } from "node:fs";
|
|
2
|
+
import { fileURLToPath } from "node:url";
|
|
3
|
+
class Youch {
|
|
4
|
+
constructor(error, request, options = {}) {
|
|
5
|
+
this.options = options;
|
|
6
|
+
this.options.postLines = options.postLines || 5;
|
|
7
|
+
this.options.preLines = options.preLines || 5;
|
|
8
|
+
this._filterHeaders = ["cookie", "connection"];
|
|
9
|
+
this.error = error;
|
|
10
|
+
this.request = request;
|
|
11
|
+
this.links = [];
|
|
12
|
+
this.showAllFrames = false;
|
|
13
|
+
}
|
|
14
|
+
_getFrameSource(frame) {
|
|
15
|
+
let path = frame.file
|
|
16
|
+
.replace(/dist\/webpack:\//g, "")
|
|
17
|
+
.replace(/dist\\webpack:\\/g, "");
|
|
18
|
+
try {
|
|
19
|
+
path = path.startsWith("file:") ? fileURLToPath(path) : path;
|
|
20
|
+
}
|
|
21
|
+
catch { }
|
|
22
|
+
return new Promise((resolve) => {
|
|
23
|
+
readFile(path, "utf-8", (error, contents) => {
|
|
24
|
+
if (error) {
|
|
25
|
+
resolve(null);
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
const lines = contents.split(/\r?\n/);
|
|
29
|
+
const lineNumber = frame.line;
|
|
30
|
+
resolve({
|
|
31
|
+
pre: lines.slice(Math.max(0, lineNumber - (this.options.preLines + 1)), lineNumber - 1),
|
|
32
|
+
line: lines[lineNumber - 1],
|
|
33
|
+
post: lines.slice(lineNumber, lineNumber + this.options.postLines),
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
_parseError() {
|
|
39
|
+
return new Promise((resolve, reject) => {
|
|
40
|
+
const stack = this.error;
|
|
41
|
+
Promise.all(stack.items.map(async (frame) => {
|
|
42
|
+
if (this._isNode(frame)) {
|
|
43
|
+
return Promise.resolve(frame);
|
|
44
|
+
}
|
|
45
|
+
return this._getFrameSource(frame).then((context) => {
|
|
46
|
+
frame.context = context;
|
|
47
|
+
return frame;
|
|
48
|
+
});
|
|
49
|
+
}))
|
|
50
|
+
.then(resolve)
|
|
51
|
+
.catch(reject);
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
_getContext(frame) {
|
|
55
|
+
if (!frame.context) {
|
|
56
|
+
return {};
|
|
57
|
+
}
|
|
58
|
+
return {
|
|
59
|
+
start: frame.line - (frame.context.pre || []).length,
|
|
60
|
+
pre: frame.context.pre.join("\n"),
|
|
61
|
+
line: frame.context.line,
|
|
62
|
+
post: frame.context.post.join("\n"),
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
_serializeFrame(frame) {
|
|
66
|
+
return {
|
|
67
|
+
file: frame.fileRelative,
|
|
68
|
+
filePath: frame.file.startsWith("file:")
|
|
69
|
+
? fileURLToPath(frame.file).replaceAll("\\", "/")
|
|
70
|
+
: frame.file,
|
|
71
|
+
line: frame.line,
|
|
72
|
+
callee: frame.callee,
|
|
73
|
+
calleeShort: frame.calleeShort,
|
|
74
|
+
column: frame.column,
|
|
75
|
+
context: this._getContext(frame),
|
|
76
|
+
isModule: frame.thirdParty,
|
|
77
|
+
isNative: frame.native,
|
|
78
|
+
isApp: this._isApp(frame),
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
_isNode(frame) {
|
|
82
|
+
if (frame.native) {
|
|
83
|
+
return true;
|
|
84
|
+
}
|
|
85
|
+
const filename = frame.file || "";
|
|
86
|
+
if (filename.startsWith("node:")) {
|
|
87
|
+
return true;
|
|
88
|
+
}
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
_isApp(frame) {
|
|
92
|
+
return !this._isNode(frame) && !this._isNodeModule(frame);
|
|
93
|
+
}
|
|
94
|
+
_isNodeModule(frame) {
|
|
95
|
+
return (frame.file || "").indexOf("node_modules/") > -1;
|
|
96
|
+
}
|
|
97
|
+
_serializeData(stack, callback) {
|
|
98
|
+
callback = callback || this._serializeFrame.bind(this);
|
|
99
|
+
return {
|
|
100
|
+
message: this.error.message,
|
|
101
|
+
help: this.error.help,
|
|
102
|
+
cause: this.error.cause,
|
|
103
|
+
name: this.error.name,
|
|
104
|
+
status: this.error.status,
|
|
105
|
+
frames: stack instanceof Array === true
|
|
106
|
+
? stack.filter((frame) => frame.file).map(callback)
|
|
107
|
+
: [],
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
toJSON() {
|
|
111
|
+
return new Promise((resolve, reject) => {
|
|
112
|
+
this._parseError()
|
|
113
|
+
.then((stack) => {
|
|
114
|
+
resolve({
|
|
115
|
+
error: this._serializeData(stack),
|
|
116
|
+
});
|
|
117
|
+
})
|
|
118
|
+
.catch(reject);
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
export default Youch;
|
|
123
|
+
//# sourceMappingURL=youch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"youch.js","sourceRoot":"","sources":["../../../src/common/errors/youch.js"],"names":[],"mappings":"AAaA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,MAAM,KAAK;IACT,YAAY,KAAK,EAAE,OAAO,EAAE,OAAO,GAAG,EAAE;QACtC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,OAAO,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,IAAI,CAAC,CAAC;QAChD,IAAI,CAAC,OAAO,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,IAAI,CAAC,CAAC;QAE9C,IAAI,CAAC,cAAc,GAAG,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC;QAC/C,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC;QAChB,IAAI,CAAC,aAAa,GAAG,KAAK,CAAC;IAC7B,CAAC;IASD,eAAe,CAAC,KAAK;QACnB,IAAI,IAAI,GAAG,KAAK,CAAC,IAAI;aAClB,OAAO,CAAC,mBAAmB,EAAE,EAAE,CAAC;aAChC,OAAO,CAAC,mBAAmB,EAAE,EAAE,CAAC,CAAC;QAOpC,IAAI,CAAC;YACH,IAAI,GAAG,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;QAC/D,CAA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,CAAC,EAAE;SACT,CAAC;IACJ,CAAC;IAOD,MAAM;QACJ,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACrC,IAAI,CAAC,WAAW,EAAE;iBACf,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE;gBACd,OAAO,CAAC;oBACN,KAAK,EAAE,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC;iBAClC,CAAC,CAAC;YACL,CAAC,CAAC;iBACD,KAAK,CAAC,MAAM,CAAC,CAAC;QACnB,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAED,eAAe,KAAK,CAAC","sourcesContent":["/* eslint-disable */\n/*\n * youch\n *\n * (c) Harminder Virk <virk@adonisjs.com>\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n *\n *\n * Source: https://github.com/poppinss/youch/tree/develop\n */\n\nimport { readFile } from \"node:fs\";\nimport { fileURLToPath } from \"node:url\";\n\nclass Youch {\n constructor(error, request, options = {}) {\n this.options = options;\n this.options.postLines = options.postLines || 5;\n this.options.preLines = options.preLines || 5;\n\n this._filterHeaders = [\"cookie\", \"connection\"];\n this.error = error;\n this.request = request;\n this.links = [];\n this.showAllFrames = false;\n }\n\n /**\n * Returns the source code for a given file. It unable to\n * read file it resolves the promise with a null.\n *\n * @param {Object} frame\n * @return {Promise}\n */\n _getFrameSource(frame) {\n let path = frame.file\n .replace(/dist\\/webpack:\\//g, \"\") // unix\n .replace(/dist\\\\webpack:\\\\/g, \"\"); // windows\n\n /**\n * We ignore the error when \"fileURLToPath\" is unable to parse\n * the path, since returning the frame source is an optional\n * thing\n */\n try {\n path = path.startsWith(\"file:\") ? fileURLToPath(path) : path;\n } catch {}\n\n return new Promise((resolve) => {\n readFile(path, \"utf-8\", (error, contents) => {\n if (error) {\n resolve(null);\n return;\n }\n\n const lines = contents.split(/\\r?\\n/);\n const lineNumber = frame.line;\n\n resolve({\n pre: lines.slice(\n Math.max(0, lineNumber - (this.options.preLines + 1)),\n lineNumber - 1\n ),\n line: lines[lineNumber - 1],\n post: lines.slice(lineNumber, lineNumber + this.options.postLines),\n });\n });\n });\n }\n\n /**\n * Parses the error stack and returns serialized\n * frames out of it.\n *\n * @return {Object}\n */\n _parseError() {\n return new Promise((resolve, reject) => {\n // const stack = new StackTracey(this.error);\n const stack = this.error;\n Promise.all(\n stack.items.map(async (frame) => {\n if (this._isNode(frame)) {\n return Promise.resolve(frame);\n }\n return this._getFrameSource(frame).then((context) => {\n frame.context = context;\n return frame;\n });\n })\n )\n .then(resolve)\n .catch(reject);\n });\n }\n\n /**\n * Returns the context with code for a given\n * frame.\n *\n * @param {Object}\n * @return {Object}\n */\n _getContext(frame) {\n if (!frame.context) {\n return {};\n }\n\n return {\n start: frame.line - (frame.context.pre || []).length,\n pre: frame.context.pre.join(\"\\n\"),\n line: frame.context.line,\n post: frame.context.post.join(\"\\n\"),\n };\n }\n\n /**\n * Serializes frame to a usable error object.\n *\n * @param {Object}\n *\n * @return {Object}\n */\n _serializeFrame(frame) {\n return {\n file: frame.fileRelative,\n filePath: frame.file.startsWith(\"file:\")\n ? fileURLToPath(frame.file).replaceAll(\"\\\\\", \"/\")\n : frame.file,\n line: frame.line,\n callee: frame.callee,\n calleeShort: frame.calleeShort,\n column: frame.column,\n context: this._getContext(frame),\n isModule: frame.thirdParty,\n isNative: frame.native,\n isApp: this._isApp(frame),\n };\n }\n\n /**\n * Returns whether frame belongs to nodejs\n * or not.\n *\n * @return {Boolean} [description]\n */\n _isNode(frame) {\n if (frame.native) {\n return true;\n }\n\n const filename = frame.file || \"\";\n if (filename.startsWith(\"node:\")) {\n return true;\n }\n return false;\n\n // return !path.isAbsolute(filename) && filename[0] !== '.'\n }\n\n /**\n * Returns whether code belongs to the app\n * or not.\n *\n * @return {Boolean} [description]\n */\n _isApp(frame) {\n return !this._isNode(frame) && !this._isNodeModule(frame);\n }\n\n /**\n * Returns whether frame belongs to a node_module or\n * not\n *\n * @method _isNodeModule\n *\n * @param {Object} frame\n *\n * @return {Boolean}\n *\n * @private\n */\n _isNodeModule(frame) {\n return (frame.file || \"\").indexOf(\"node_modules/\") > -1;\n }\n\n /**\n * Serializes stack to Mustache friendly object to\n * be used within the view. Optionally can pass\n * a callback to customize the frames output.\n *\n * @param {Object}\n * @param {Function} [callback]\n *\n * @return {Object}\n */\n _serializeData(stack, callback) {\n callback = callback || this._serializeFrame.bind(this);\n return {\n message: this.error.message,\n help: this.error.help,\n cause: this.error.cause,\n name: this.error.name,\n status: this.error.status,\n frames:\n stack instanceof Array === true\n ? stack.filter((frame) => frame.file).map(callback)\n : [],\n };\n }\n\n /**\n * Returns error stack as JSON.\n *\n * @return {Promise}\n */\n toJSON() {\n return new Promise((resolve, reject) => {\n this._parseError()\n .then((stack) => {\n resolve({\n error: this._serializeData(stack),\n });\n })\n .catch(reject);\n });\n }\n}\n\nexport default Youch;\n"]}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Readable } from "node:stream";
|
|
2
|
+
type LogLevel = "error" | "warn" | "info" | "debug";
|
|
3
|
+
export interface ConsoleLogEntry {
|
|
4
|
+
logId: string;
|
|
5
|
+
logOwner: string;
|
|
6
|
+
logSource: string;
|
|
7
|
+
level: LogLevel;
|
|
8
|
+
timestamp: string;
|
|
9
|
+
loggingId: string;
|
|
10
|
+
buildId: string;
|
|
11
|
+
rayId: string | null;
|
|
12
|
+
messages: unknown[];
|
|
13
|
+
requestId: string;
|
|
14
|
+
vectorClock: number;
|
|
15
|
+
url: string;
|
|
16
|
+
route: string;
|
|
17
|
+
method: string;
|
|
18
|
+
}
|
|
19
|
+
export declare function handleRuntimeStdio(stdout: Readable, stderr: Readable): void;
|
|
20
|
+
export declare function logConsole(level: LogLevel, data: unknown): void;
|
|
21
|
+
export declare function logStructured(logEntry: ConsoleLogEntry, message: unknown): Promise<void>;
|
|
22
|
+
export {};
|
|
23
|
+
//# sourceMappingURL=worker-output.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker-output.d.ts","sourceRoot":"","sources":["../../src/common/worker-output.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAKvC,KAAK,QAAQ,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;AAKpD,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,QAAQ,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,QAAQ,EAAE,OAAO,EAAE,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAChB;AAqBD,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,QAoIpE;AAKD,wBAAgB,UAAU,CAAC,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,OAAO,QA2CxD;AAGD,wBAAsB,aAAa,CACjC,QAAQ,EAAE,eAAe,EACzB,OAAO,EAAE,OAAO,iBAqBjB"}
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import chalk from "chalk";
|
|
2
|
+
import StackTracey from "./errors/stacktracy.js";
|
|
3
|
+
import forTerminal from "./errors/youch-terminal.js";
|
|
4
|
+
import Youch from "./errors/youch.js";
|
|
5
|
+
export function handleRuntimeStdio(stdout, stderr) {
|
|
6
|
+
const classifiers = {
|
|
7
|
+
isBarf(chunk) {
|
|
8
|
+
const containsLlvmSymbolizerWarning = chunk.includes("Not symbolizing stack traces because $LLVM_SYMBOLIZER is not set");
|
|
9
|
+
const containsRecursiveIsolateLockWarning = chunk.includes("took recursive isolate lock");
|
|
10
|
+
const containsHexStack = /stack:( (0|[a-f\d]{4,})){3,}/.test(chunk);
|
|
11
|
+
return (containsLlvmSymbolizerWarning ||
|
|
12
|
+
containsRecursiveIsolateLockWarning ||
|
|
13
|
+
containsHexStack);
|
|
14
|
+
},
|
|
15
|
+
isAddressInUse(chunk) {
|
|
16
|
+
return chunk.includes("Address already in use; toString() = ");
|
|
17
|
+
},
|
|
18
|
+
isWarning(chunk) {
|
|
19
|
+
return /\.c\+\+:\d+: warning:/.test(chunk);
|
|
20
|
+
},
|
|
21
|
+
isCodeMovedWarning(chunk) {
|
|
22
|
+
return /CODE_MOVED for unknown code block/.test(chunk);
|
|
23
|
+
},
|
|
24
|
+
isAccessViolation(chunk) {
|
|
25
|
+
return chunk.includes("access violation;");
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
stdout.on("data", (chunk) => {
|
|
29
|
+
chunk = chunk.toString().trim();
|
|
30
|
+
if (classifiers.isBarf(chunk)) {
|
|
31
|
+
logConsole("debug", chunk);
|
|
32
|
+
}
|
|
33
|
+
else if (classifiers.isWarning(chunk)) {
|
|
34
|
+
logConsole("warn", chunk);
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
logConsole("error", chunk);
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
stderr.on("data", (chunk) => {
|
|
41
|
+
chunk = chunk.toString().trim();
|
|
42
|
+
if (classifiers.isBarf(chunk)) {
|
|
43
|
+
if (classifiers.isAddressInUse(chunk)) {
|
|
44
|
+
const address = chunk.match(/Address already in use; toString\(\) = (.+)\n/)?.[1];
|
|
45
|
+
logConsole("error", `Address already in use (${address}). Please check that you are not already running a server on this address or specify a different port with --port.`);
|
|
46
|
+
logConsole("debug", chunk);
|
|
47
|
+
}
|
|
48
|
+
else if (classifiers.isAccessViolation(chunk)) {
|
|
49
|
+
let error = "There was an access violation in the runtime.";
|
|
50
|
+
if (process.platform === "win32") {
|
|
51
|
+
error +=
|
|
52
|
+
"\nOn Windows, this may be caused by an outdated Microsoft Visual C++ Redistributable library.\n" +
|
|
53
|
+
"Check that you have the latest version installed.\n" +
|
|
54
|
+
"See https://learn.microsoft.com/en-us/cpp/windows/latest-supported-vc-redist.";
|
|
55
|
+
}
|
|
56
|
+
logConsole("error", error);
|
|
57
|
+
logConsole("debug", chunk);
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
logConsole("debug", chunk);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
else if (classifiers.isWarning(chunk)) {
|
|
64
|
+
logConsole("warn", chunk);
|
|
65
|
+
}
|
|
66
|
+
else if (classifiers.isCodeMovedWarning(chunk)) {
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
logConsole("error", chunk);
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
export function logConsole(level, data) {
|
|
74
|
+
void (async () => {
|
|
75
|
+
try {
|
|
76
|
+
if (!data) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
if (typeof data !== "string") {
|
|
80
|
+
console[level](data);
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
let message = data?.trim();
|
|
84
|
+
if (!message || message?.length === 0) {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
if (message.startsWith(`{"logId":"`)) {
|
|
88
|
+
let logEntry;
|
|
89
|
+
try {
|
|
90
|
+
logEntry = JSON.parse(message);
|
|
91
|
+
}
|
|
92
|
+
catch (e) {
|
|
93
|
+
const lines = message.split("\n");
|
|
94
|
+
lines.forEach((line) => void logConsole(level, line));
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
const messages = logEntry.messages;
|
|
98
|
+
messages.forEach((msg) => void logStructured(logEntry, msg));
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
message = await formatMessage(message);
|
|
102
|
+
const line = `${getTimestamp()} ${levelFormats[level]} ${message}`;
|
|
103
|
+
console[level](line);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
catch (err) {
|
|
107
|
+
console.log(err);
|
|
108
|
+
console[level](data);
|
|
109
|
+
}
|
|
110
|
+
})();
|
|
111
|
+
}
|
|
112
|
+
export async function logStructured(logEntry, message) {
|
|
113
|
+
if (typeof message === "object" &&
|
|
114
|
+
message &&
|
|
115
|
+
Object.keys(message).length === 0) {
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
const { level, route, method, timestamp } = logEntry;
|
|
119
|
+
const routeStr = route.endsWith("{/}?") ? route.slice(0, -4) : route;
|
|
120
|
+
const msg = await formatMessage(message);
|
|
121
|
+
const line = `${getTimestamp(timestamp)} ${levelFormats[level]} [${methodFormats[method.toUpperCase()]} ${chalk.blue(routeStr)}] ${msg}`;
|
|
122
|
+
console[level](line);
|
|
123
|
+
}
|
|
124
|
+
const methodFormats = {
|
|
125
|
+
GET: chalk.green(chalk.bold("GET")),
|
|
126
|
+
POST: chalk.blue(chalk.bold("POST")),
|
|
127
|
+
PUT: chalk.yellow(chalk.bold("PUT")),
|
|
128
|
+
DELETE: chalk.red(chalk.bold("DELETE")),
|
|
129
|
+
PATCH: chalk.magenta(chalk.bold("PATCH")),
|
|
130
|
+
HEAD: chalk.cyan(chalk.bold("HEAD")),
|
|
131
|
+
OPTIONS: chalk.gray(chalk.bold("OPTIONS")),
|
|
132
|
+
};
|
|
133
|
+
const levelFormats = {
|
|
134
|
+
error: chalk.red(chalk.bold("ERROR".padEnd(5))),
|
|
135
|
+
warn: chalk.yellow(chalk.bold("WARN".padEnd(5))),
|
|
136
|
+
info: chalk.blue(chalk.bold("INFO".padEnd(5))),
|
|
137
|
+
debug: chalk.gray(chalk.bold("DEBUG".padEnd(5))),
|
|
138
|
+
};
|
|
139
|
+
let timeFormatter;
|
|
140
|
+
function getTimeFormatter() {
|
|
141
|
+
timeFormatter ??= new Intl.DateTimeFormat(undefined, {
|
|
142
|
+
hour: "2-digit",
|
|
143
|
+
minute: "2-digit",
|
|
144
|
+
second: "2-digit",
|
|
145
|
+
hour12: false,
|
|
146
|
+
fractionalSecondDigits: 3,
|
|
147
|
+
});
|
|
148
|
+
return timeFormatter;
|
|
149
|
+
}
|
|
150
|
+
function getTimestamp(timestamp) {
|
|
151
|
+
return chalk.white(chalk.dim(`[${getTimeFormatter().format(timestamp ? new Date(timestamp) : new Date())}]`));
|
|
152
|
+
}
|
|
153
|
+
async function formatMessage(message) {
|
|
154
|
+
if (typeof message === "string" && isJavaScriptStackTrace(message)) {
|
|
155
|
+
const lines = message.split("\n");
|
|
156
|
+
const title = lines.shift();
|
|
157
|
+
return title + "\n" + (await formatError(lines.join("\n")));
|
|
158
|
+
}
|
|
159
|
+
return typeof message === "object"
|
|
160
|
+
? JSON.stringify(message)
|
|
161
|
+
: String(message);
|
|
162
|
+
}
|
|
163
|
+
async function formatError(error) {
|
|
164
|
+
const stack = new StackTracey(error);
|
|
165
|
+
const jsonResponse = await new Youch(stack, {}).toJSON();
|
|
166
|
+
const options = {
|
|
167
|
+
displayShortPath: false,
|
|
168
|
+
prefix: " ",
|
|
169
|
+
hideErrorTitle: false,
|
|
170
|
+
hideMessage: true,
|
|
171
|
+
displayMainFrameOnly: true,
|
|
172
|
+
framesMaxLimit: 3,
|
|
173
|
+
};
|
|
174
|
+
return forTerminal(jsonResponse, options);
|
|
175
|
+
}
|
|
176
|
+
function isJavaScriptStackTrace(str) {
|
|
177
|
+
const stackTraceRegex = /at\s+(.*?)\s+\((.*?):(\d+):(\d+)\)|at\s+(.*?):(\d+):(\d+)/;
|
|
178
|
+
return stackTraceRegex.test(str);
|
|
179
|
+
}
|
|
180
|
+
//# sourceMappingURL=worker-output.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker-output.js","sourceRoot":"","sources":["../../src/common/worker-output.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,O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IAAI;QAG1B,cAAc,EAAE,CAAC;KAClB,CAAC;IAEF,OAAO,WAAW,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;AAC5C,CAAC;AAED,SAAS,sBAAsB,CAAC,GAAW;IACzC,MAAM,eAAe,GACnB,2DAA2D,CAAC;IAC9D,OAAO,eAAe,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACnC,CAAC","sourcesContent":["/* eslint-disable no-console */\nimport chalk from \"chalk\";\nimport { Readable } from \"node:stream\";\nimport StackTracey from \"./errors/stacktracy.js\";\nimport forTerminal from \"./errors/youch-terminal.js\";\nimport Youch from \"./errors/youch.js\";\n\ntype LogLevel = \"error\" | \"warn\" | \"info\" | \"debug\";\n\n/**\n * This is the structure of the runtime console log transport log entry\n */\nexport interface ConsoleLogEntry {\n logId: string;\n logOwner: string;\n logSource: string;\n level: LogLevel;\n timestamp: string;\n loggingId: string;\n buildId: string;\n rayId: string | null;\n messages: unknown[];\n requestId: string;\n vectorClock: number;\n url: string;\n route: string;\n method: string;\n}\n\n// /**\n// * Handler worker stdout and stderr streams.\n// */\n// export const handleRuntimeStdio = (stdout: Readable, stderr: Readable) => {\n// rl.createInterface(stdout).on(\"line\", (data) => {\n// try {\n// const logEntry: ConsoleLogEntry = JSON.parse(data);\n// const messages = logEntry.messages;\n\n// messages.forEach((msg) => void logStructured(logEntry, msg));\n// } catch (e) {\n// void logConsole(\"info\", data);\n// }\n// });\n// rl.createInterface(stderr).on(\"line\", (data) => {\n// void logConsole(\"error\", data);\n// });\n// };\n\nexport function handleRuntimeStdio(stdout: Readable, stderr: Readable) {\n // ASSUMPTION: each chunk is a whole message from workerd\n // This may not hold across OSes/architectures, but it seems to work on macOS M-line\n // I'm going with this simple approach to avoid complicating this too early\n // We can iterate on this heuristic in the future if it causes issues\n const classifiers = {\n // Is this chunk a big chonky barf from workerd that we want to hijack to cleanup/ignore?\n isBarf(chunk: string) {\n const containsLlvmSymbolizerWarning = chunk.includes(\n \"Not symbolizing stack traces because $LLVM_SYMBOLIZER is not set\"\n );\n const containsRecursiveIsolateLockWarning = chunk.includes(\n \"took recursive isolate lock\"\n );\n // Matches stack traces from workerd\n // - on unix: groups of 9 hex digits separated by spaces\n // - on windows: groups of 12 hex digits, or a single digit 0, separated by spaces\n const containsHexStack = /stack:( (0|[a-f\\d]{4,})){3,}/.test(chunk);\n\n return (\n containsLlvmSymbolizerWarning ||\n containsRecursiveIsolateLockWarning ||\n containsHexStack\n );\n },\n // Is this chunk an Address In Use error?\n isAddressInUse(chunk: string) {\n return chunk.includes(\"Address already in use; toString() = \");\n },\n isWarning(chunk: string) {\n return /\\.c\\+\\+:\\d+: warning:/.test(chunk);\n },\n isCodeMovedWarning(chunk: string) {\n return /CODE_MOVED for unknown code block/.test(chunk);\n },\n isAccessViolation(chunk: string) {\n return chunk.includes(\"access violation;\");\n },\n };\n\n stdout.on(\"data\", (chunk: Buffer | string) => {\n chunk = chunk.toString().trim();\n\n if (classifiers.isBarf(chunk)) {\n // this is a big chonky barf from workerd that we want to hijack to cleanup/ignore\n\n // CLEANABLE:\n // there are no known cases to cleanup yet\n // but, as they are identified, we will do that here\n\n // IGNORABLE:\n // anything else not handled above is considered ignorable\n // so send it to the debug logs which are discarded unless\n // the user explicitly sets a logLevel indicating they care\n logConsole(\"debug\", chunk);\n }\n\n // known case: warnings are not info, log them as such\n else if (classifiers.isWarning(chunk)) {\n logConsole(\"warn\", chunk);\n }\n\n // anything not explicitly handled above should be logged as info (via stdout)\n else {\n //logger.info(getSourceMappedString(chunk));\n logConsole(\"error\", chunk);\n }\n });\n\n stderr.on(\"data\", (chunk: Buffer | string) => {\n chunk = chunk.toString().trim();\n\n if (classifiers.isBarf(chunk)) {\n // this is a big chonky barf from workerd that we want to hijack to cleanup/ignore\n\n // CLEANABLE:\n // known case to cleanup: Address in use errors\n if (classifiers.isAddressInUse(chunk)) {\n const address = chunk.match(\n /Address already in use; toString\\(\\) = (.+)\\n/\n )?.[1];\n\n logConsole(\n \"error\",\n `Address already in use (${address}). Please check that you are not already running a server on this address or specify a different port with --port.`\n );\n\n // Log the original error to the debug logs.\n logConsole(\"debug\", chunk);\n }\n // In the past we have seen Access Violation errors on Windows, which may be caused by an outdated\n // version of the Windows OS or the Microsoft Visual C++ Redistributable.\n // See https://github.com/cloudflare/workers-sdk/issues/6170#issuecomment-2245209918\n else if (classifiers.isAccessViolation(chunk)) {\n let error = \"There was an access violation in the runtime.\";\n if (process.platform === \"win32\") {\n error +=\n \"\\nOn Windows, this may be caused by an outdated Microsoft Visual C++ Redistributable library.\\n\" +\n \"Check that you have the latest version installed.\\n\" +\n \"See https://learn.microsoft.com/en-us/cpp/windows/latest-supported-vc-redist.\";\n }\n logConsole(\"error\", error);\n\n // Log the original error to the debug logs.\n logConsole(\"debug\", chunk);\n }\n\n // IGNORABLE:\n // anything else not handled above is considered ignorable\n // so send it to the debug logs which are discarded unless\n // the user explicitly sets a logLevel indicating they care\n else {\n logConsole(\"debug\", chunk);\n }\n }\n\n // known case: warnings are not errors, log them as such\n else if (classifiers.isWarning(chunk)) {\n logConsole(\"warn\", chunk);\n }\n\n // known case: \"error: CODE_MOVED for unknown code block?\", warning for workerd devs, not application devs\n else if (classifiers.isCodeMovedWarning(chunk)) {\n // ignore entirely, don't even send it to the debug log file\n }\n\n // anything not explicitly handled above should be logged as an error (via stderr)\n else {\n //logConsole(\"error\", getSourceMappedString(chunk));\n logConsole(\"error\", chunk);\n }\n });\n}\n\n/**\n * This is what is logged when the runtime calls console.log, etc.\n */\nexport function logConsole(level: LogLevel, data: unknown) {\n void (async () => {\n try {\n if (!data) {\n return;\n }\n\n // This shouldn't happen, but just in case\n if (typeof data !== \"string\") {\n console[level](data);\n return;\n }\n\n let message = data?.trim();\n if (!message || message?.length === 0) {\n return;\n }\n\n if (message.startsWith(`{\"logId\":\"`)) {\n let logEntry: ConsoleLogEntry;\n try {\n logEntry = JSON.parse(message);\n } catch (e) {\n // We might have multiple log entries in a single chunk\n // so split them and log each one\n const lines = message.split(\"\\n\");\n lines.forEach((line) => void logConsole(level, line));\n return;\n }\n const messages = logEntry.messages;\n messages.forEach((msg) => void logStructured(logEntry, msg));\n } else {\n message = await formatMessage(message);\n\n const line = `${getTimestamp()} ${levelFormats[level]} ${message}`;\n\n console[level](line);\n }\n } catch (err) {\n console.log(err);\n console[level](data);\n }\n })();\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport async function logStructured(\n logEntry: ConsoleLogEntry,\n message: unknown\n) {\n if (\n typeof message === \"object\" &&\n message &&\n Object.keys(message).length === 0\n ) {\n return;\n }\n\n // Get the log properties we care about\n const { level, route, method, timestamp } = logEntry;\n\n const routeStr = route.endsWith(\"{/}?\") ? route.slice(0, -4) : route;\n\n const msg = await formatMessage(message);\n\n const line = `${getTimestamp(timestamp)} ${levelFormats[level]} [${methodFormats[method.toUpperCase() as HttpMethod]} ${chalk.blue(routeStr)}] ${msg}`;\n\n // Log the line\n console[level](line);\n}\n\ntype HttpMethod =\n | \"GET\"\n | \"POST\"\n | \"PUT\"\n | \"DELETE\"\n | \"PATCH\"\n | \"HEAD\"\n | \"OPTIONS\";\nconst methodFormats: Record<HttpMethod, string> = {\n GET: chalk.green(chalk.bold(\"GET\")),\n POST: chalk.blue(chalk.bold(\"POST\")),\n PUT: chalk.yellow(chalk.bold(\"PUT\")),\n DELETE: chalk.red(chalk.bold(\"DELETE\")),\n PATCH: chalk.magenta(chalk.bold(\"PATCH\")),\n HEAD: chalk.cyan(chalk.bold(\"HEAD\")),\n OPTIONS: chalk.gray(chalk.bold(\"OPTIONS\")),\n};\n\nconst levelFormats: Record<LogLevel, string> = {\n error: chalk.red(chalk.bold(\"ERROR\".padEnd(5))),\n warn: chalk.yellow(chalk.bold(\"WARN\".padEnd(5))),\n info: chalk.blue(chalk.bold(\"INFO\".padEnd(5))),\n debug: chalk.gray(chalk.bold(\"DEBUG\".padEnd(5))),\n};\n\n// Only initialize the timeFormatter when the timestamp option is used, and\n// reuse it across all loggers\nlet timeFormatter: Intl.DateTimeFormat;\nfunction getTimeFormatter() {\n timeFormatter ??= new Intl.DateTimeFormat(undefined, {\n hour: \"2-digit\",\n minute: \"2-digit\",\n second: \"2-digit\",\n hour12: false,\n fractionalSecondDigits: 3,\n });\n return timeFormatter;\n}\n\nfunction getTimestamp(timestamp?: string) {\n return chalk.white(\n chalk.dim(\n `[${getTimeFormatter().format(timestamp ? new Date(timestamp) : new Date())}]`\n )\n );\n}\n\nasync function formatMessage(message: unknown): Promise<string> {\n if (typeof message === \"string\" && isJavaScriptStackTrace(message)) {\n const lines = message.split(\"\\n\");\n const title = lines.shift();\n return title + \"\\n\" + (await formatError(lines.join(\"\\n\")));\n }\n\n return typeof message === \"object\"\n ? JSON.stringify(message)\n : String(message);\n}\n\nasync function formatError(error: string) {\n const stack = new StackTracey(error);\n\n const jsonResponse = await new Youch(stack, {}).toJSON();\n\n const options = {\n // Defaults to false\n displayShortPath: false,\n\n // Defaults to single whitspace\n prefix: \" \",\n\n // Defaults to false\n hideErrorTitle: false,\n\n // Defaults to false\n hideMessage: true,\n\n // Defaults to false\n displayMainFrameOnly: true,\n\n // Defaults to 3\n framesMaxLimit: 3,\n };\n\n return forTerminal(jsonResponse, options);\n}\n\nfunction isJavaScriptStackTrace(str: string): boolean {\n const stackTraceRegex =\n /at\\s+(.*?)\\s+\\((.*?):(\\d+):(\\d+)\\)|at\\s+(.*?):(\\d+):(\\d+)/;\n return stackTraceRegex.test(str);\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker-output.spec.d.ts","sourceRoot":"","sources":["../../src/common/worker-output.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { logConsole, logStructured } from "./worker-output.js";
|
|
2
|
+
const lines = [
|
|
3
|
+
{
|
|
4
|
+
type: "structured",
|
|
5
|
+
line: `{"logId":"d5a57adb-4cb8-414b-95ba-7d5490823bde","requestId":"b674109a-8519-4c23-a405-916fbcd470d5","rayId":null,"level":"debug","logSource":"request","messages":["Request received '/hello'",{"method":"GET","url":"/hello","hostname":"localhost","route":"/hello"}],"timestamp":"2024-10-30T21:48:29.945Z","logOwner":"user","loggingId":"local","buildId":"475a3d75-1873-42dc-9215-46de28f9661b","vectorClock":0,"url":"http://localhost:9000/hello","method":"GET","route":"/hello{/}?"}`,
|
|
6
|
+
},
|
|
7
|
+
{
|
|
8
|
+
type: "structured",
|
|
9
|
+
line: `{"logId":"0bef78e0-0665-4439-9f01-5c698d30c08a","requestId":"b674109a-8519-4c23-a405-916fbcd470d5","rayId":null,"level":"info","logSource":"request","messages":["Hello"],"timestamp":"2024-10-30T21:48:29.982Z","logOwner":"user","loggingId":"local","buildId":"475a3d75-1873-42dc-9215-46de28f9661b","vectorClock":1,"url":"http://localhost:9000/hello","method":"GET","route":"/hello{/}?"}`,
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
type: "structured",
|
|
13
|
+
line: `{"logId":"0af9543a-892d-4e48-b58b-5ac73eec7232","requestId":"2f07c260-f2d9-45d5-9908-dc54e6bf6ead","rayId":null,"level":"debug","logSource":"request","messages":["Request received '/echo'",{"method":"GET","url":"/echo","hostname":"localhost","route":"/echo"}],"timestamp":"2024-10-30T21:48:30.054Z","logOwner":"user","loggingId":"local","buildId":"475a3d75-1873-42dc-9215-46de28f9661b","vectorClock":2,"url":"http://localhost:9000/echo","method":"GET","route":"/echo{/}?"}`,
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
type: "structured",
|
|
17
|
+
line: `{"logId":"7047f560-0bcd-4314-bd42-350372055556","requestId":"2f07c260-f2d9-45d5-9908-dc54e6bf6ead","rayId":null,"level":"debug","logSource":"request","messages":["URL Forwarding to 'https://echo.zuplo.io/echo'"],"timestamp":"2024-10-30T21:48:30.087Z","logOwner":"user","loggingId":"local","buildId":"475a3d75-1873-42dc-9215-46de28f9661b","vectorClock":3,"url":"http://localhost:9000/echo","method":"GET","route":"/echo{/}?"}`,
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
type: "structured",
|
|
21
|
+
line: `{"logId":"7047f560-0bcd-4314-bd42-350372055556","requestId":"2f07c260-f2d9-45d5-9908-dc54e6bf6ead","rayId":null,"level":"debug","logSource":"request","messages":["URL Forwarding to 'https://echo.zuplo.io/echo'"],"timestamp":"2024-10-30T21:48:30.087Z","logOwner":"user","loggingId":"local","buildId":"475a3d75-1873-42dc-9215-46de28f9661b","vectorClock":3,"url":"http://localhost:9000/echo","method":"POST","route":"/echo{/}?"}`,
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
type: "structured",
|
|
25
|
+
line: `{"logId":"7047f560-0bcd-4314-bd42-350372055556","requestId":"2f07c260-f2d9-45d5-9908-dc54e6bf6ead","rayId":null,"level":"debug","logSource":"request","messages":["URL Forwarding to 'https://echo.zuplo.io/echo'"],"timestamp":"2024-10-30T21:48:30.087Z","logOwner":"user","loggingId":"local","buildId":"475a3d75-1873-42dc-9215-46de28f9661b","vectorClock":3,"url":"http://localhost:9000/echo","method":"PUT","route":"/echo{/}?"}`,
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
type: "structured",
|
|
29
|
+
line: `{"logId":"7047f560-0bcd-4314-bd42-350372055556","requestId":"2f07c260-f2d9-45d5-9908-dc54e6bf6ead","rayId":null,"level":"debug","logSource":"request","messages":["URL Forwarding to 'https://echo.zuplo.io/echo'"],"timestamp":"2024-10-30T21:48:30.087Z","logOwner":"user","loggingId":"local","buildId":"475a3d75-1873-42dc-9215-46de28f9661b","vectorClock":3,"url":"http://localhost:9000/echo","method":"DELETE","route":"/echo{/}?"}`,
|
|
30
|
+
},
|
|
31
|
+
{ type: "raw", line: `Error exporting traces 404 page not found` },
|
|
32
|
+
{ type: "raw", line: `` },
|
|
33
|
+
{
|
|
34
|
+
type: "structured",
|
|
35
|
+
line: `{"logId":"43d05a54-1a53-4e3a-8284-de73cde5c1cf","requestId":"2f07c260-f2d9-45d5-9908-dc54e6bf6ead","rayId":null,"level":"debug","logSource":"request","messages":["URL Forward received response 200 - OK in 66ms"],"timestamp":"2024-10-30T21:48:30.153Z","logOwner":"user","loggingId":"local","buildId":"475a3d75-1873-42dc-9215-46de28f9661b","vectorClock":4,"url":"http://localhost:9000/echo","method":"GET","route":"/echo{/}?"}`,
|
|
36
|
+
},
|
|
37
|
+
{ type: "raw", line: `Error exporting traces 404 page not found` },
|
|
38
|
+
{ type: "raw", line: `` },
|
|
39
|
+
{
|
|
40
|
+
type: "raw",
|
|
41
|
+
line: `Error: this is an unhandled error
|
|
42
|
+
at buildRouteHandler (file:///Users/ntotten/zuplo/core/test-fixtures/otel/dist/chunk-UK2CLRIC.js:5112:13)
|
|
43
|
+
at file:///Users/ntotten/zuplo/core/test-fixtures/otel/dist/chunk-UK2CLRIC.js:3819:39
|
|
44
|
+
at file:///Users/ntotten/zuplo/core/test-fixtures/otel/dist/chunk-UK2CLRIC.js:3799:34
|
|
45
|
+
at AsyncLocalStorageContextManager.with (file:///Users/ntotten/zuplo/core/test-fixtures/otel/dist/worker.js:5122:36)
|
|
46
|
+
at _ContextAPI.with (file:///Users/ntotten/zuplo/core/test-fixtures/otel/dist/worker.js:797:46)
|
|
47
|
+
at WorkerTracer.startActiveSpan (file:///Users/ntotten/zuplo/core/test-fixtures/otel/dist/worker.js:4365:37)
|
|
48
|
+
at file:///Users/ntotten/zuplo/core/test-fixtures/otel/dist/chunk-UK2CLRIC.js:3797:21
|
|
49
|
+
at nextPipe (file:///Users/ntotten/zuplo/core/test-fixtures/otel/dist/chunk-UK2CLRIC.js:3822:35)
|
|
50
|
+
at metricsProcessor (file:///Users/ntotten/zuplo/core/test-fixtures/otel/dist/chunk-UK2CLRIC.js:5029:21)
|
|
51
|
+
at nextPipe (file:///Users/ntotten/zuplo/core/test-fixtures/otel/dist/chunk-UK2CLRIC.js:3825:16)`,
|
|
52
|
+
},
|
|
53
|
+
];
|
|
54
|
+
lines.forEach((line) => {
|
|
55
|
+
if (line.type === "structured") {
|
|
56
|
+
const logEntry = JSON.parse(line.line);
|
|
57
|
+
const messages = logEntry.messages;
|
|
58
|
+
messages.forEach((msg) => logStructured(logEntry, msg));
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
logConsole("error", line.line);
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
//# sourceMappingURL=worker-output.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker-output.spec.js","sourceRoot":"","sources":["../../src/common/worker-output.spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAE/D,MAAM,KAAK,GAAG;IACZ;QACE,IAAI,EAAE,YAAY;QAClB,IAAI,EAAE,+dAA+d;KACte;IACD;QACE,IAAI,EAAE,YAAY;QAClB,IAAI,EAAE,kYAAkY;KACzY;IACD;QACE,IAAI,EAAE,YAAY;QAClB,IAAI,EAAE,0dAA0d;KACje;IACD;QACE,IAAI,EAAE,YAAY;QAClB,IAAI,EAAE,0aAA0a;KACjb;IACD;QACE,IAAI,EAAE,YAAY;QAClB,IAAI,EAAE,2aAA2a;KAClb;IACD;QACE,IAAI,EAAE,YAAY;QAClB,IAAI,EAAE,0aAA0a;KACjb;IACD;QACE,IAAI,EAAE,YAAY;QAClB,IAAI,EAAE,6aAA6a;KACpb;IACD,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,2CAA2C,EAAE;IAClE,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,EAAE;IACzB;QACE,IAAI,EAAE,YAAY;QAClB,IAAI,EAAE,0aAA0a;KACjb;IACD,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,2CAA2C,EAAE;IAClE,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,EAAE;IACzB;QACE,IAAI,EAAE,KAAK;QACX,IAAI,EAAE;;;;;;;;;;iGAUuF;KAC9F;CACF,CAAC;AAEF,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;IACrB,IAAI,IAAI,CAAC,IAAI,KAAK,YAAY,EAAE,CAAC;QAC/B,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACvC,MAAM,QAAQ,GAAG,QAAQ,CAAC,QAAQ,CAAC;QACnC,QAAQ,CAAC,OAAO,CAAC,CAAC,GAAQ,EAAE,EAAE,CAAC,aAAa,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC,CAAC;IAC/D,CAAC;SAAM,CAAC;QACN,UAAU,CAAC,OAAO,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;IACjC,CAAC;AACH,CAAC,CAAC,CAAC","sourcesContent":["import { logConsole, logStructured } from \"./worker-output.js\";\n\nconst lines = [\n {\n type: \"structured\",\n line: `{\"logId\":\"d5a57adb-4cb8-414b-95ba-7d5490823bde\",\"requestId\":\"b674109a-8519-4c23-a405-916fbcd470d5\",\"rayId\":null,\"level\":\"debug\",\"logSource\":\"request\",\"messages\":[\"Request received '/hello'\",{\"method\":\"GET\",\"url\":\"/hello\",\"hostname\":\"localhost\",\"route\":\"/hello\"}],\"timestamp\":\"2024-10-30T21:48:29.945Z\",\"logOwner\":\"user\",\"loggingId\":\"local\",\"buildId\":\"475a3d75-1873-42dc-9215-46de28f9661b\",\"vectorClock\":0,\"url\":\"http://localhost:9000/hello\",\"method\":\"GET\",\"route\":\"/hello{/}?\"}`,\n },\n {\n type: \"structured\",\n line: `{\"logId\":\"0bef78e0-0665-4439-9f01-5c698d30c08a\",\"requestId\":\"b674109a-8519-4c23-a405-916fbcd470d5\",\"rayId\":null,\"level\":\"info\",\"logSource\":\"request\",\"messages\":[\"Hello\"],\"timestamp\":\"2024-10-30T21:48:29.982Z\",\"logOwner\":\"user\",\"loggingId\":\"local\",\"buildId\":\"475a3d75-1873-42dc-9215-46de28f9661b\",\"vectorClock\":1,\"url\":\"http://localhost:9000/hello\",\"method\":\"GET\",\"route\":\"/hello{/}?\"}`,\n },\n {\n type: \"structured\",\n line: `{\"logId\":\"0af9543a-892d-4e48-b58b-5ac73eec7232\",\"requestId\":\"2f07c260-f2d9-45d5-9908-dc54e6bf6ead\",\"rayId\":null,\"level\":\"debug\",\"logSource\":\"request\",\"messages\":[\"Request received '/echo'\",{\"method\":\"GET\",\"url\":\"/echo\",\"hostname\":\"localhost\",\"route\":\"/echo\"}],\"timestamp\":\"2024-10-30T21:48:30.054Z\",\"logOwner\":\"user\",\"loggingId\":\"local\",\"buildId\":\"475a3d75-1873-42dc-9215-46de28f9661b\",\"vectorClock\":2,\"url\":\"http://localhost:9000/echo\",\"method\":\"GET\",\"route\":\"/echo{/}?\"}`,\n },\n {\n type: \"structured\",\n line: `{\"logId\":\"7047f560-0bcd-4314-bd42-350372055556\",\"requestId\":\"2f07c260-f2d9-45d5-9908-dc54e6bf6ead\",\"rayId\":null,\"level\":\"debug\",\"logSource\":\"request\",\"messages\":[\"URL Forwarding to 'https://echo.zuplo.io/echo'\"],\"timestamp\":\"2024-10-30T21:48:30.087Z\",\"logOwner\":\"user\",\"loggingId\":\"local\",\"buildId\":\"475a3d75-1873-42dc-9215-46de28f9661b\",\"vectorClock\":3,\"url\":\"http://localhost:9000/echo\",\"method\":\"GET\",\"route\":\"/echo{/}?\"}`,\n },\n {\n type: \"structured\",\n line: `{\"logId\":\"7047f560-0bcd-4314-bd42-350372055556\",\"requestId\":\"2f07c260-f2d9-45d5-9908-dc54e6bf6ead\",\"rayId\":null,\"level\":\"debug\",\"logSource\":\"request\",\"messages\":[\"URL Forwarding to 'https://echo.zuplo.io/echo'\"],\"timestamp\":\"2024-10-30T21:48:30.087Z\",\"logOwner\":\"user\",\"loggingId\":\"local\",\"buildId\":\"475a3d75-1873-42dc-9215-46de28f9661b\",\"vectorClock\":3,\"url\":\"http://localhost:9000/echo\",\"method\":\"POST\",\"route\":\"/echo{/}?\"}`,\n },\n {\n type: \"structured\",\n line: `{\"logId\":\"7047f560-0bcd-4314-bd42-350372055556\",\"requestId\":\"2f07c260-f2d9-45d5-9908-dc54e6bf6ead\",\"rayId\":null,\"level\":\"debug\",\"logSource\":\"request\",\"messages\":[\"URL Forwarding to 'https://echo.zuplo.io/echo'\"],\"timestamp\":\"2024-10-30T21:48:30.087Z\",\"logOwner\":\"user\",\"loggingId\":\"local\",\"buildId\":\"475a3d75-1873-42dc-9215-46de28f9661b\",\"vectorClock\":3,\"url\":\"http://localhost:9000/echo\",\"method\":\"PUT\",\"route\":\"/echo{/}?\"}`,\n },\n {\n type: \"structured\",\n line: `{\"logId\":\"7047f560-0bcd-4314-bd42-350372055556\",\"requestId\":\"2f07c260-f2d9-45d5-9908-dc54e6bf6ead\",\"rayId\":null,\"level\":\"debug\",\"logSource\":\"request\",\"messages\":[\"URL Forwarding to 'https://echo.zuplo.io/echo'\"],\"timestamp\":\"2024-10-30T21:48:30.087Z\",\"logOwner\":\"user\",\"loggingId\":\"local\",\"buildId\":\"475a3d75-1873-42dc-9215-46de28f9661b\",\"vectorClock\":3,\"url\":\"http://localhost:9000/echo\",\"method\":\"DELETE\",\"route\":\"/echo{/}?\"}`,\n },\n { type: \"raw\", line: `Error exporting traces 404 page not found` },\n { type: \"raw\", line: `` },\n {\n type: \"structured\",\n line: `{\"logId\":\"43d05a54-1a53-4e3a-8284-de73cde5c1cf\",\"requestId\":\"2f07c260-f2d9-45d5-9908-dc54e6bf6ead\",\"rayId\":null,\"level\":\"debug\",\"logSource\":\"request\",\"messages\":[\"URL Forward received response 200 - OK in 66ms\"],\"timestamp\":\"2024-10-30T21:48:30.153Z\",\"logOwner\":\"user\",\"loggingId\":\"local\",\"buildId\":\"475a3d75-1873-42dc-9215-46de28f9661b\",\"vectorClock\":4,\"url\":\"http://localhost:9000/echo\",\"method\":\"GET\",\"route\":\"/echo{/}?\"}`,\n },\n { type: \"raw\", line: `Error exporting traces 404 page not found` },\n { type: \"raw\", line: `` },\n {\n type: \"raw\",\n line: `Error: this is an unhandled error\nat buildRouteHandler (file:///Users/ntotten/zuplo/core/test-fixtures/otel/dist/chunk-UK2CLRIC.js:5112:13)\nat file:///Users/ntotten/zuplo/core/test-fixtures/otel/dist/chunk-UK2CLRIC.js:3819:39\nat file:///Users/ntotten/zuplo/core/test-fixtures/otel/dist/chunk-UK2CLRIC.js:3799:34\nat AsyncLocalStorageContextManager.with (file:///Users/ntotten/zuplo/core/test-fixtures/otel/dist/worker.js:5122:36)\nat _ContextAPI.with (file:///Users/ntotten/zuplo/core/test-fixtures/otel/dist/worker.js:797:46)\nat WorkerTracer.startActiveSpan (file:///Users/ntotten/zuplo/core/test-fixtures/otel/dist/worker.js:4365:37)\nat file:///Users/ntotten/zuplo/core/test-fixtures/otel/dist/chunk-UK2CLRIC.js:3797:21\nat nextPipe (file:///Users/ntotten/zuplo/core/test-fixtures/otel/dist/chunk-UK2CLRIC.js:3822:35)\nat metricsProcessor (file:///Users/ntotten/zuplo/core/test-fixtures/otel/dist/chunk-UK2CLRIC.js:5029:21)\nat nextPipe (file:///Users/ntotten/zuplo/core/test-fixtures/otel/dist/chunk-UK2CLRIC.js:3825:16)`,\n },\n];\n\nlines.forEach((line) => {\n if (line.type === \"structured\") {\n const logEntry = JSON.parse(line.line);\n const messages = logEntry.messages;\n messages.forEach((msg: any) => logStructured(logEntry, msg));\n } else {\n logConsole(\"error\", line.line);\n }\n});\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handler.d.ts","sourceRoot":"","sources":["../../src/compile/handler.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"handler.d.ts","sourceRoot":"","sources":["../../src/compile/handler.ts"],"names":[],"mappings":"AAaA,MAAM,WAAW,SAAS;IACxB,GAAG,EAAE,MAAM,CAAC;IACZ,aAAa,EAAE,MAAM,CAAC;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,aAAa,EAAE,MAAM,CAAC;CACvB;AAED,wBAAsB,OAAO,CAAC,IAAI,EAAE,SAAS,iBA0E5C"}
|
package/dist/compile/handler.js
CHANGED
|
@@ -4,6 +4,7 @@ import { join, relative, resolve } from "node:path";
|
|
|
4
4
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
5
5
|
import { logger } from "../common/logger.js";
|
|
6
6
|
import { printCriticalFailureToConsoleAndExit, printDiagnosticsToConsole, printResultToConsoleAndExitGracefully, } from "../common/output.js";
|
|
7
|
+
import { handleRuntimeStdio } from "../common/worker-output.js";
|
|
7
8
|
export async function compile(argv) {
|
|
8
9
|
const sourceDirectory = resolve(join(relative(process.cwd(), argv.dir)));
|
|
9
10
|
const zuploRuntimePath = new URL("../../node_modules/@zuplo/runtime", import.meta.url);
|
|
@@ -41,6 +42,7 @@ export async function compile(argv) {
|
|
|
41
42
|
:
|
|
42
43
|
undefined,
|
|
43
44
|
logger,
|
|
45
|
+
handleRuntimeStdio,
|
|
44
46
|
});
|
|
45
47
|
printDiagnosticsToConsole("📦 Compiled a self-contained zup binary");
|
|
46
48
|
await printResultToConsoleAndExitGracefully(`The binary is available at ${sourceDirectory}/dist/${argv["binary-name"]}`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handler.js","sourceRoot":"","sources":["../../src/compile/handler.ts"],"names":[],"mappings":"AACA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC3D,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACxD,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EACL,oCAAoC,EACpC,yBAAyB,EACzB,qCAAqC,GACtC,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"handler.js","sourceRoot":"","sources":["../../src/compile/handler.ts"],"names":[],"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AQ,GAAG,YAAY,CAAC,YAAY,CAAC,CAAC;QAC5C,QAAQ,GAAG,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IACpC,CAAC;IAGD,MAAM,MAAM,GAAG;QACb,gBAAgB,EAAE,aAAa,CAAC,eAAe,CAAC;KACjD,CAAC;IACF,OAAO,CAAC,GAAG,CAAC,cAAc,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC;IAG1D,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,iBAAiB,CAAC,CAAC;IAE7C,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC;IAE1B,IAAI,CAAC;QACH,MAAM,IAAI,CAAC,oBAAoB,CAAC;YAC9B,eAAe;YACf,UAAU,EAAE,IAAI,CAAC,aAAa,CAAC;YAC/B,IAAI,EAAE,OAAO;YACb,UAAU,EAAE,IAAI,CAAC,aAAa,CAAC;YAC/B,+BAA+B,EAAE,QAAQ;gBACvC,CAAC,CAAC;oBACE,kBAAkB,EAAE,QAAQ,CAAC,kBAAkB;oBAC/C,kBAAkB,EAAE,QAAQ,CAAC,kBAAkB;oBAC/C,sBAAsB,EAAE,QAAQ,CAAC,sBAAsB;iBACxD;gBACH,CAAC;oBACC,SAAS;YACb,MAAM;YACN,kBAAkB;SACnB,CAAC,CAAC;QAEH,yBAAyB,CAAC,yCAAyC,CAAC,CAAC;QACrE,MAAM,qCAAqC,CACzC,8BAA8B,eAAe,SAAS,IAAI,CAAC,aAAa,CAAC,EAAE,CAC5E,CAAC;IACJ,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,yBAAyB,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QACvC,MAAM,oCAAoC,CACxC,kCAAkC,CACnC,CAAC;IACJ,CAAC;AACH,CAAC","sourcesContent":["/* eslint-disable node/no-process-env */\nimport dotenv from \"dotenv\";\nimport { cpSync, existsSync, readFileSync } from \"node:fs\";\nimport { join, relative, resolve } from \"node:path\";\nimport { fileURLToPath, pathToFileURL } from \"node:url\";\nimport { logger } from \"../common/logger.js\";\nimport {\n printCriticalFailureToConsoleAndExit,\n printDiagnosticsToConsole,\n printResultToConsoleAndExitGracefully,\n} from \"../common/output.js\";\nimport { handleRuntimeStdio } from \"../common/worker-output.js\";\n\nexport interface Arguments {\n dir: string;\n \"bundled-dir\": string;\n port: number;\n \"binary-name\": string;\n}\n\nexport async function compile(argv: Arguments) {\n const sourceDirectory = resolve(join(relative(process.cwd(), argv.dir)));\n\n // When we build, we MIGHT need to use the @zuplo/runtime from the node_modules if the user\n // has installed our packages using https://www.npmjs.com/package/zuplo in a global directory\n\n // Try to copy the @zuplo/runtime locally\n const zuploRuntimePath = new URL(\n \"../../node_modules/@zuplo/runtime\",\n import.meta.url\n );\n if (existsSync(zuploRuntimePath)) {\n cpSync(\n zuploRuntimePath,\n join(sourceDirectory, \"node_modules/@zuplo/runtime\"),\n {\n recursive: true,\n dereference: true,\n }\n );\n }\n\n // Set GLOBAL_MODULE_LOCATION to the location of the CLIs node_modules\n process.env.GLOBAL_MODULE_LOCATION = fileURLToPath(\n new URL(\"../../node_modules\", import.meta.url)\n );\n\n // Check if the user has a .env.zuplo file\n let envZuplo: dotenv.DotenvParseOutput = {};\n const envZuploFile = join(sourceDirectory, \".env.zuplo\");\n if (existsSync(envZuploFile)) {\n const contents = readFileSync(envZuploFile);\n envZuplo = dotenv.parse(contents);\n }\n\n // Set other variables using __ZUPLO_CONFIG\n const config = {\n build_assets_url: pathToFileURL(sourceDirectory),\n };\n process.env.__ZUPLO_CONFIG = btoa(JSON.stringify(config));\n\n // Use a dynamic import so that setting process.env has effect\n const core = await import(\"@zuplo/core/cli\");\n\n const zupPort = argv.port;\n\n try {\n await core.compileWorkerdServer({\n sourceDirectory,\n bundledDir: argv[\"bundled-dir\"],\n port: zupPort,\n binaryName: argv[\"binary-name\"],\n publicZuploEnvironmentVariables: envZuplo\n ? {\n ZUPLO_ACCOUNT_NAME: envZuplo.ZUPLO_ACCOUNT_NAME,\n ZUPLO_PROJECT_NAME: envZuplo.ZUPLO_PROJECT_NAME,\n ZUPLO_ENVIRONMENT_TYPE: envZuplo.ZUPLO_ENVIRONMENT_TYPE,\n }\n : // Leave this as undefined to simulate the old behavior\n undefined,\n logger,\n handleRuntimeStdio,\n });\n\n printDiagnosticsToConsole(\"📦 Compiled a self-contained zup binary\");\n await printResultToConsoleAndExitGracefully(\n `The binary is available at ${sourceDirectory}/dist/${argv[\"binary-name\"]}`\n );\n } catch (err) {\n printDiagnosticsToConsole(err.message);\n await printCriticalFailureToConsoleAndExit(\n \"Failed to compile the zup binary\"\n );\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handler.d.ts","sourceRoot":"","sources":["../../src/dev/handler.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"handler.d.ts","sourceRoot":"","sources":["../../src/dev/handler.ts"],"names":[],"mappings":"AAcA,MAAM,WAAW,SAAS;IACxB,GAAG,EAAE,MAAM,CAAC;IACZ,cAAc,EAAE,OAAO,CAAC;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,wBAAsB,GAAG,CAAC,IAAI,EAAE,SAAS,iBA6JxC"}
|
package/dist/dev/handler.js
CHANGED
|
@@ -5,6 +5,7 @@ import { fileURLToPath, pathToFileURL } from "node:url";
|
|
|
5
5
|
import { logger } from "../common/logger.js";
|
|
6
6
|
import { printCriticalFailureToConsoleAndExit, printDiagnosticsToConsole, } from "../common/output.js";
|
|
7
7
|
import { isPortAvailable } from "../common/utils/ports.js";
|
|
8
|
+
import { handleRuntimeStdio } from "../common/worker-output.js";
|
|
8
9
|
import { ApiServer } from "../editor/server/server.js";
|
|
9
10
|
export async function dev(argv) {
|
|
10
11
|
const sourceDirectory = resolve(join(relative(process.cwd(), argv.dir)));
|
|
@@ -51,6 +52,7 @@ export async function dev(argv) {
|
|
|
51
52
|
await printCriticalFailureToConsoleAndExit(`Port ${zupDebugPort} is already in use. Please specify a different port using --debug-port.`);
|
|
52
53
|
}
|
|
53
54
|
}
|
|
55
|
+
let firstLoad = true;
|
|
54
56
|
await core.startDevServer({
|
|
55
57
|
sourceDirectory,
|
|
56
58
|
port: zupPort,
|
|
@@ -64,6 +66,15 @@ export async function dev(argv) {
|
|
|
64
66
|
:
|
|
65
67
|
undefined,
|
|
66
68
|
logger,
|
|
69
|
+
handleRuntimeStdio,
|
|
70
|
+
onReload: () => {
|
|
71
|
+
if (firstLoad) {
|
|
72
|
+
firstLoad = false;
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
printDiagnosticsToConsole("Code changed. Server reloaded...");
|
|
76
|
+
}
|
|
77
|
+
},
|
|
67
78
|
});
|
|
68
79
|
let editor;
|
|
69
80
|
if (argv["start-editor"]) {
|
|
@@ -89,9 +100,9 @@ export async function dev(argv) {
|
|
|
89
100
|
printDiagnosticsToConsole("");
|
|
90
101
|
return new Promise((resolve) => {
|
|
91
102
|
async function exit() {
|
|
92
|
-
printDiagnosticsToConsole("
|
|
103
|
+
printDiagnosticsToConsole("");
|
|
104
|
+
printDiagnosticsToConsole("Stopping local development server...");
|
|
93
105
|
if (argv["start-editor"]) {
|
|
94
|
-
printDiagnosticsToConsole("Closing local route designer");
|
|
95
106
|
await editor.close();
|
|
96
107
|
}
|
|
97
108
|
resolve();
|