@yetanotheraryan/coldstart 1.0.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/LICENSE +21 -0
- package/dist/chunk-7HD2T2AD.mjs +261 -0
- package/dist/chunk-B5TADGOF.mjs +12 -0
- package/dist/chunk-IGYROJNQ.mjs +170 -0
- package/dist/cli.d.mts +1 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +285 -0
- package/dist/cli.mjs +123 -0
- package/dist/esm-loader.d.mts +30 -0
- package/dist/esm-loader.d.ts +30 -0
- package/dist/esm-loader.js +125 -0
- package/dist/esm-loader.mjs +100 -0
- package/dist/index.d.mts +67 -0
- package/dist/index.d.ts +67 -0
- package/dist/index.js +816 -0
- package/dist/index.mjs +368 -0
- package/dist/register.d.mts +2 -0
- package/dist/register.d.ts +2 -0
- package/dist/register.js +438 -0
- package/dist/register.mjs +181 -0
- package/package.json +63 -0
- package/readme.md +440 -0
package/dist/cli.js
ADDED
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
|
|
4
|
+
// src/cli.ts
|
|
5
|
+
var import_fs = require("fs");
|
|
6
|
+
var import_os = require("os");
|
|
7
|
+
var import_path = require("path");
|
|
8
|
+
var import_child_process = require("child_process");
|
|
9
|
+
|
|
10
|
+
// src/reporter/json.ts
|
|
11
|
+
function renderJsonReport(report, options2 = {}) {
|
|
12
|
+
return `${JSON.stringify(report, jsonReplacer, options2.pretty === false ? 0 : 2)}
|
|
13
|
+
`;
|
|
14
|
+
}
|
|
15
|
+
function jsonReplacer(_key, value) {
|
|
16
|
+
if (typeof value === "number" && !Number.isFinite(value)) {
|
|
17
|
+
return 0;
|
|
18
|
+
}
|
|
19
|
+
return value;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// src/reporter/text.ts
|
|
23
|
+
var BAR_WIDTH = 18;
|
|
24
|
+
var ANSI_RESET = "\x1B[0m";
|
|
25
|
+
var ANSI_RED = "\x1B[31m";
|
|
26
|
+
var ANSI_YELLOW = "\x1B[33m";
|
|
27
|
+
var ANSI_GREEN = "\x1B[32m";
|
|
28
|
+
var ANSI_DIM = "\x1B[2m";
|
|
29
|
+
function renderTextReport(report, options2 = {}) {
|
|
30
|
+
const color = options2.color ?? true;
|
|
31
|
+
const barWidth = options2.barWidth ?? BAR_WIDTH;
|
|
32
|
+
const showSummary = options2.showSummary ?? true;
|
|
33
|
+
const displayTree = collapseDisplayNoise(report.tree);
|
|
34
|
+
const maxInclusiveMs = Math.max(
|
|
35
|
+
1,
|
|
36
|
+
...report.flat.filter((node) => !node.cached).map((node) => node.inclusiveMs)
|
|
37
|
+
);
|
|
38
|
+
const lines = [
|
|
39
|
+
`coldstart - ${formatDuration(report.totalStartupMs)} total startup`,
|
|
40
|
+
""
|
|
41
|
+
];
|
|
42
|
+
for (let index = 0; index < displayTree.length; index += 1) {
|
|
43
|
+
const isLastRoot = index === displayTree.length - 1;
|
|
44
|
+
const root = displayTree[index];
|
|
45
|
+
lines.push(...renderNode(root, "", isLastRoot, maxInclusiveMs, barWidth, color));
|
|
46
|
+
}
|
|
47
|
+
if (showSummary) {
|
|
48
|
+
if (displayTree.length > 0) {
|
|
49
|
+
lines.push("");
|
|
50
|
+
}
|
|
51
|
+
lines.push(
|
|
52
|
+
`${dim("event loop")} max ${formatDuration(report.eventLoop.maxBlockMs)}, p99 ${formatDuration(report.eventLoop.p99BlockMs)}, mean ${formatDuration(report.eventLoop.meanBlockMs)}`,
|
|
53
|
+
`${dim("modules")} ${report.totalModulesLoaded} total, ${report.cachedModulesCount} cached`,
|
|
54
|
+
`${dim("time split")} ${formatDuration(report.firstPartyTime)} first-party, ${formatDuration(report.nodeModuleTime)} node_modules`
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
return lines.join("\n");
|
|
58
|
+
function dim(value) {
|
|
59
|
+
return colorize(value, ANSI_DIM, color);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
function collapseDisplayNoise(nodes) {
|
|
63
|
+
const result = [];
|
|
64
|
+
const seen = /* @__PURE__ */ new Set();
|
|
65
|
+
for (const node of nodes) {
|
|
66
|
+
const collapsedChildren = collapseDisplayNoise(node.children);
|
|
67
|
+
const collapsedNode = {
|
|
68
|
+
...node,
|
|
69
|
+
children: collapsedChildren
|
|
70
|
+
};
|
|
71
|
+
if (shouldCollapseBuiltinNode(collapsedNode)) {
|
|
72
|
+
const key = [
|
|
73
|
+
collapsedNode.request,
|
|
74
|
+
collapsedNode.depth
|
|
75
|
+
].join("|");
|
|
76
|
+
if (seen.has(key)) {
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
seen.add(key);
|
|
80
|
+
}
|
|
81
|
+
result.push(collapsedNode);
|
|
82
|
+
}
|
|
83
|
+
return result;
|
|
84
|
+
}
|
|
85
|
+
function shouldCollapseBuiltinNode(node) {
|
|
86
|
+
return node.isBuiltin && node.cached && node.inclusiveMs === 0 && node.children.length === 0;
|
|
87
|
+
}
|
|
88
|
+
function renderNode(node, prefix, isLast, maxInclusiveMs, barWidth, color) {
|
|
89
|
+
const branch = prefix.length === 0 ? isLast ? "\u2514\u2500 " : "\u250C\u2500 " : `${prefix}${isLast ? "\u2514\u2500 " : "\u251C\u2500 "}`;
|
|
90
|
+
const nextPrefix = prefix.length === 0 ? isLast ? " " : "\u2502 " : `${prefix}${isLast ? " " : "\u2502 "}`;
|
|
91
|
+
const label = formatLabel(node);
|
|
92
|
+
const duration = formatDuration(node.inclusiveMs).padStart(6);
|
|
93
|
+
const durationColor = getDurationColor(node.inclusiveMs);
|
|
94
|
+
const bar = renderBar(node.inclusiveMs, maxInclusiveMs, barWidth);
|
|
95
|
+
const suffix = node.inclusiveMs >= 100 ? ` ${colorize("! slow", ANSI_RED, color)}` : "";
|
|
96
|
+
const line = `${branch}${label.padEnd(18)} ${colorize(duration, durationColor, color)} ${colorize(bar, durationColor, color)}${suffix}`;
|
|
97
|
+
const lines = [line];
|
|
98
|
+
for (let index = 0; index < node.children.length; index += 1) {
|
|
99
|
+
const child = node.children[index];
|
|
100
|
+
const isLastChild = index === node.children.length - 1;
|
|
101
|
+
lines.push(...renderNode(child, nextPrefix, isLastChild, maxInclusiveMs, barWidth, color));
|
|
102
|
+
}
|
|
103
|
+
return lines;
|
|
104
|
+
}
|
|
105
|
+
function formatLabel(node) {
|
|
106
|
+
if (node.isBuiltin) {
|
|
107
|
+
return node.request.replace(/^node:/, "");
|
|
108
|
+
}
|
|
109
|
+
if (node.isNodeModule) {
|
|
110
|
+
return packageNameFromRequest(node.request);
|
|
111
|
+
}
|
|
112
|
+
const normalizedPath = normalizeModulePath(node);
|
|
113
|
+
const segments = normalizedPath.split("/");
|
|
114
|
+
const base = segments[segments.length - 1] ?? "";
|
|
115
|
+
return base.length > 0 ? base : node.request;
|
|
116
|
+
}
|
|
117
|
+
function normalizeModulePath(node) {
|
|
118
|
+
if (looksLikeRelativeRequest(node.request)) {
|
|
119
|
+
return node.request.replace(/\\/g, "/");
|
|
120
|
+
}
|
|
121
|
+
if (node.resolvedPath.startsWith("file://")) {
|
|
122
|
+
try {
|
|
123
|
+
return decodeURIComponent(new URL(node.resolvedPath).pathname).replace(/\\/g, "/");
|
|
124
|
+
} catch {
|
|
125
|
+
return node.resolvedPath.replace(/\\/g, "/");
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return node.resolvedPath.replace(/\\/g, "/");
|
|
129
|
+
}
|
|
130
|
+
function looksLikeRelativeRequest(request) {
|
|
131
|
+
return request.startsWith("./") || request.startsWith("../") || request.startsWith("/");
|
|
132
|
+
}
|
|
133
|
+
function packageNameFromRequest(request) {
|
|
134
|
+
if (request.startsWith("@")) {
|
|
135
|
+
const [scope, name2] = request.split("/");
|
|
136
|
+
return name2 ? `${scope}/${name2}` : request;
|
|
137
|
+
}
|
|
138
|
+
const [name] = request.split("/");
|
|
139
|
+
return name || request;
|
|
140
|
+
}
|
|
141
|
+
function renderBar(durationMs, maxInclusiveMs, barWidth) {
|
|
142
|
+
const filled = Math.max(1, Math.round(durationMs / maxInclusiveMs * barWidth));
|
|
143
|
+
return `${"\u2588".repeat(Math.min(barWidth, filled))}${"\u2591".repeat(Math.max(0, barWidth - filled))}`;
|
|
144
|
+
}
|
|
145
|
+
function formatDuration(valueMs) {
|
|
146
|
+
if (!Number.isFinite(valueMs)) {
|
|
147
|
+
return "0ms";
|
|
148
|
+
}
|
|
149
|
+
if (valueMs >= 1e3) {
|
|
150
|
+
return `${Math.round(valueMs)}ms`;
|
|
151
|
+
}
|
|
152
|
+
if (valueMs >= 100) {
|
|
153
|
+
return `${Math.round(valueMs)}ms`;
|
|
154
|
+
}
|
|
155
|
+
if (valueMs >= 10) {
|
|
156
|
+
return `${valueMs.toFixed(1).replace(/\.0$/, "")}ms`;
|
|
157
|
+
}
|
|
158
|
+
return `${valueMs.toFixed(2).replace(/0+$/, "").replace(/\.$/, "")}ms`;
|
|
159
|
+
}
|
|
160
|
+
function getDurationColor(durationMs) {
|
|
161
|
+
if (durationMs > 100) {
|
|
162
|
+
return ANSI_RED;
|
|
163
|
+
}
|
|
164
|
+
if (durationMs >= 20) {
|
|
165
|
+
return ANSI_YELLOW;
|
|
166
|
+
}
|
|
167
|
+
return ANSI_GREEN;
|
|
168
|
+
}
|
|
169
|
+
function colorize(value, code, enabled) {
|
|
170
|
+
if (!enabled) {
|
|
171
|
+
return value;
|
|
172
|
+
}
|
|
173
|
+
return `${code}${value}${ANSI_RESET}`;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// src/cli.ts
|
|
177
|
+
var options = parseArgs(process.argv.slice(2));
|
|
178
|
+
if (options.help || options.targetArgs.length === 0) {
|
|
179
|
+
printHelp(options.targetArgs.length === 0 ? 1 : 0);
|
|
180
|
+
} else {
|
|
181
|
+
run(options).catch((error) => {
|
|
182
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
183
|
+
process.stderr.write(`coldstart: ${message}
|
|
184
|
+
`);
|
|
185
|
+
process.exitCode = 1;
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
async function run(options2) {
|
|
189
|
+
const tempDir = (0, import_fs.mkdtempSync)((0, import_path.join)((0, import_os.tmpdir)(), "coldstart-"));
|
|
190
|
+
const reportPath = (0, import_path.join)(tempDir, "startup-report.json");
|
|
191
|
+
const childArgs = buildChildArgs(options2.targetArgs);
|
|
192
|
+
const child = (0, import_child_process.spawn)(process.execPath, childArgs, {
|
|
193
|
+
stdio: "inherit",
|
|
194
|
+
env: {
|
|
195
|
+
...process.env,
|
|
196
|
+
COLDSTART_REPORT_FILE: reportPath
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
const forwardSignal = (signal) => {
|
|
200
|
+
if (!child.killed) {
|
|
201
|
+
child.kill(signal);
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
process.once("SIGINT", () => forwardSignal("SIGINT"));
|
|
205
|
+
process.once("SIGTERM", () => forwardSignal("SIGTERM"));
|
|
206
|
+
const exitInfo = await new Promise((resolvePromise, reject) => {
|
|
207
|
+
child.once("error", reject);
|
|
208
|
+
child.once("exit", (code, signal) => resolvePromise({ code, signal }));
|
|
209
|
+
});
|
|
210
|
+
let report = null;
|
|
211
|
+
if ((0, import_fs.existsSync)(reportPath)) {
|
|
212
|
+
report = JSON.parse((0, import_fs.readFileSync)(reportPath, "utf8"));
|
|
213
|
+
}
|
|
214
|
+
(0, import_fs.rmSync)(tempDir, { recursive: true, force: true });
|
|
215
|
+
if (report) {
|
|
216
|
+
const output = options2.output === "json" ? renderJsonReport(report) : `${renderTextReport(report, { color: options2.color })}
|
|
217
|
+
`;
|
|
218
|
+
process.stdout.write(output);
|
|
219
|
+
} else {
|
|
220
|
+
process.stderr.write("coldstart: no startup report was captured\n");
|
|
221
|
+
}
|
|
222
|
+
if (exitInfo.signal) {
|
|
223
|
+
process.kill(process.pid, exitInfo.signal);
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
process.exitCode = exitInfo.code ?? 1;
|
|
227
|
+
}
|
|
228
|
+
function parseArgs(argv) {
|
|
229
|
+
const targetArgs = [];
|
|
230
|
+
let output = "text";
|
|
231
|
+
let color = process.stdout.isTTY;
|
|
232
|
+
let help = false;
|
|
233
|
+
let passthrough = false;
|
|
234
|
+
for (const arg of argv) {
|
|
235
|
+
if (passthrough) {
|
|
236
|
+
targetArgs.push(arg);
|
|
237
|
+
continue;
|
|
238
|
+
}
|
|
239
|
+
if (arg === "--") {
|
|
240
|
+
passthrough = true;
|
|
241
|
+
continue;
|
|
242
|
+
}
|
|
243
|
+
if (arg === "--json") {
|
|
244
|
+
output = "json";
|
|
245
|
+
continue;
|
|
246
|
+
}
|
|
247
|
+
if (arg === "--no-color") {
|
|
248
|
+
color = false;
|
|
249
|
+
continue;
|
|
250
|
+
}
|
|
251
|
+
if (arg === "--color") {
|
|
252
|
+
color = true;
|
|
253
|
+
continue;
|
|
254
|
+
}
|
|
255
|
+
if (arg === "--help" || arg === "-h") {
|
|
256
|
+
help = true;
|
|
257
|
+
continue;
|
|
258
|
+
}
|
|
259
|
+
targetArgs.push(arg);
|
|
260
|
+
}
|
|
261
|
+
return { output, color, help, targetArgs };
|
|
262
|
+
}
|
|
263
|
+
function buildChildArgs(targetArgs) {
|
|
264
|
+
const registerPath = (0, import_path.resolve)(__dirname, "register.mjs");
|
|
265
|
+
if (targetArgs[0] === "node") {
|
|
266
|
+
return ["--import", registerPath, ...targetArgs.slice(1)];
|
|
267
|
+
}
|
|
268
|
+
return ["--import", registerPath, ...targetArgs];
|
|
269
|
+
}
|
|
270
|
+
function printHelp(exitCode) {
|
|
271
|
+
const helpText = [
|
|
272
|
+
"Usage:",
|
|
273
|
+
" coldstart [--json] [--no-color] app.js [args...]",
|
|
274
|
+
" coldstart [--json] [--no-color] -- node [node-flags...] app.js [args...]",
|
|
275
|
+
"",
|
|
276
|
+
"Examples:",
|
|
277
|
+
" coldstart server.js",
|
|
278
|
+
" coldstart --json server.js",
|
|
279
|
+
" coldstart -- node --trace-warnings server.js"
|
|
280
|
+
].join("\n");
|
|
281
|
+
const stream = exitCode === 0 ? process.stdout : process.stderr;
|
|
282
|
+
stream.write(`${helpText}
|
|
283
|
+
`);
|
|
284
|
+
process.exit(exitCode);
|
|
285
|
+
}
|
package/dist/cli.mjs
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
renderJsonReport,
|
|
4
|
+
renderTextReport
|
|
5
|
+
} from "./chunk-IGYROJNQ.mjs";
|
|
6
|
+
import {
|
|
7
|
+
__dirname
|
|
8
|
+
} from "./chunk-B5TADGOF.mjs";
|
|
9
|
+
|
|
10
|
+
// src/cli.ts
|
|
11
|
+
import { existsSync, mkdtempSync, readFileSync, rmSync } from "fs";
|
|
12
|
+
import { tmpdir } from "os";
|
|
13
|
+
import { join, resolve } from "path";
|
|
14
|
+
import { spawn } from "child_process";
|
|
15
|
+
var options = parseArgs(process.argv.slice(2));
|
|
16
|
+
if (options.help || options.targetArgs.length === 0) {
|
|
17
|
+
printHelp(options.targetArgs.length === 0 ? 1 : 0);
|
|
18
|
+
} else {
|
|
19
|
+
run(options).catch((error) => {
|
|
20
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
21
|
+
process.stderr.write(`coldstart: ${message}
|
|
22
|
+
`);
|
|
23
|
+
process.exitCode = 1;
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
async function run(options2) {
|
|
27
|
+
const tempDir = mkdtempSync(join(tmpdir(), "coldstart-"));
|
|
28
|
+
const reportPath = join(tempDir, "startup-report.json");
|
|
29
|
+
const childArgs = buildChildArgs(options2.targetArgs);
|
|
30
|
+
const child = spawn(process.execPath, childArgs, {
|
|
31
|
+
stdio: "inherit",
|
|
32
|
+
env: {
|
|
33
|
+
...process.env,
|
|
34
|
+
COLDSTART_REPORT_FILE: reportPath
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
const forwardSignal = (signal) => {
|
|
38
|
+
if (!child.killed) {
|
|
39
|
+
child.kill(signal);
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
process.once("SIGINT", () => forwardSignal("SIGINT"));
|
|
43
|
+
process.once("SIGTERM", () => forwardSignal("SIGTERM"));
|
|
44
|
+
const exitInfo = await new Promise((resolvePromise, reject) => {
|
|
45
|
+
child.once("error", reject);
|
|
46
|
+
child.once("exit", (code, signal) => resolvePromise({ code, signal }));
|
|
47
|
+
});
|
|
48
|
+
let report = null;
|
|
49
|
+
if (existsSync(reportPath)) {
|
|
50
|
+
report = JSON.parse(readFileSync(reportPath, "utf8"));
|
|
51
|
+
}
|
|
52
|
+
rmSync(tempDir, { recursive: true, force: true });
|
|
53
|
+
if (report) {
|
|
54
|
+
const output = options2.output === "json" ? renderJsonReport(report) : `${renderTextReport(report, { color: options2.color })}
|
|
55
|
+
`;
|
|
56
|
+
process.stdout.write(output);
|
|
57
|
+
} else {
|
|
58
|
+
process.stderr.write("coldstart: no startup report was captured\n");
|
|
59
|
+
}
|
|
60
|
+
if (exitInfo.signal) {
|
|
61
|
+
process.kill(process.pid, exitInfo.signal);
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
process.exitCode = exitInfo.code ?? 1;
|
|
65
|
+
}
|
|
66
|
+
function parseArgs(argv) {
|
|
67
|
+
const targetArgs = [];
|
|
68
|
+
let output = "text";
|
|
69
|
+
let color = process.stdout.isTTY;
|
|
70
|
+
let help = false;
|
|
71
|
+
let passthrough = false;
|
|
72
|
+
for (const arg of argv) {
|
|
73
|
+
if (passthrough) {
|
|
74
|
+
targetArgs.push(arg);
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
if (arg === "--") {
|
|
78
|
+
passthrough = true;
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
if (arg === "--json") {
|
|
82
|
+
output = "json";
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
if (arg === "--no-color") {
|
|
86
|
+
color = false;
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
if (arg === "--color") {
|
|
90
|
+
color = true;
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
if (arg === "--help" || arg === "-h") {
|
|
94
|
+
help = true;
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
targetArgs.push(arg);
|
|
98
|
+
}
|
|
99
|
+
return { output, color, help, targetArgs };
|
|
100
|
+
}
|
|
101
|
+
function buildChildArgs(targetArgs) {
|
|
102
|
+
const registerPath = resolve(__dirname, "register.mjs");
|
|
103
|
+
if (targetArgs[0] === "node") {
|
|
104
|
+
return ["--import", registerPath, ...targetArgs.slice(1)];
|
|
105
|
+
}
|
|
106
|
+
return ["--import", registerPath, ...targetArgs];
|
|
107
|
+
}
|
|
108
|
+
function printHelp(exitCode) {
|
|
109
|
+
const helpText = [
|
|
110
|
+
"Usage:",
|
|
111
|
+
" coldstart [--json] [--no-color] app.js [args...]",
|
|
112
|
+
" coldstart [--json] [--no-color] -- node [node-flags...] app.js [args...]",
|
|
113
|
+
"",
|
|
114
|
+
"Examples:",
|
|
115
|
+
" coldstart server.js",
|
|
116
|
+
" coldstart --json server.js",
|
|
117
|
+
" coldstart -- node --trace-warnings server.js"
|
|
118
|
+
].join("\n");
|
|
119
|
+
const stream = exitCode === 0 ? process.stdout : process.stderr;
|
|
120
|
+
stream.write(`${helpText}
|
|
121
|
+
`);
|
|
122
|
+
process.exit(exitCode);
|
|
123
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
declare function initialize(data: {
|
|
2
|
+
port?: MessagePortLike;
|
|
3
|
+
}): Promise<void>;
|
|
4
|
+
declare function resolve(specifier: string, context: {
|
|
5
|
+
parentURL?: string;
|
|
6
|
+
}, nextResolve: (specifier: string, context: {
|
|
7
|
+
parentURL?: string;
|
|
8
|
+
}) => Promise<{
|
|
9
|
+
url: string;
|
|
10
|
+
format?: string | null;
|
|
11
|
+
}>): Promise<{
|
|
12
|
+
url: string;
|
|
13
|
+
format?: string | null;
|
|
14
|
+
}>;
|
|
15
|
+
declare function load(url: string, context: {
|
|
16
|
+
format?: string | null;
|
|
17
|
+
}, nextLoad: (url: string, context: {
|
|
18
|
+
format?: string | null;
|
|
19
|
+
}) => Promise<{
|
|
20
|
+
format: string;
|
|
21
|
+
source?: string | ArrayBuffer | Uint8Array;
|
|
22
|
+
}>): Promise<{
|
|
23
|
+
format: string;
|
|
24
|
+
source?: string | ArrayBuffer | Uint8Array;
|
|
25
|
+
}>;
|
|
26
|
+
interface MessagePortLike {
|
|
27
|
+
postMessage(message: unknown): void;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export { initialize, load, resolve };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
declare function initialize(data: {
|
|
2
|
+
port?: MessagePortLike;
|
|
3
|
+
}): Promise<void>;
|
|
4
|
+
declare function resolve(specifier: string, context: {
|
|
5
|
+
parentURL?: string;
|
|
6
|
+
}, nextResolve: (specifier: string, context: {
|
|
7
|
+
parentURL?: string;
|
|
8
|
+
}) => Promise<{
|
|
9
|
+
url: string;
|
|
10
|
+
format?: string | null;
|
|
11
|
+
}>): Promise<{
|
|
12
|
+
url: string;
|
|
13
|
+
format?: string | null;
|
|
14
|
+
}>;
|
|
15
|
+
declare function load(url: string, context: {
|
|
16
|
+
format?: string | null;
|
|
17
|
+
}, nextLoad: (url: string, context: {
|
|
18
|
+
format?: string | null;
|
|
19
|
+
}) => Promise<{
|
|
20
|
+
format: string;
|
|
21
|
+
source?: string | ArrayBuffer | Uint8Array;
|
|
22
|
+
}>): Promise<{
|
|
23
|
+
format: string;
|
|
24
|
+
source?: string | ArrayBuffer | Uint8Array;
|
|
25
|
+
}>;
|
|
26
|
+
interface MessagePortLike {
|
|
27
|
+
postMessage(message: unknown): void;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export { initialize, load, resolve };
|
|
@@ -0,0 +1,125 @@
|
|
|
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 __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/esm-loader.ts
|
|
21
|
+
var esm_loader_exports = {};
|
|
22
|
+
__export(esm_loader_exports, {
|
|
23
|
+
initialize: () => initialize,
|
|
24
|
+
load: () => load,
|
|
25
|
+
resolve: () => resolve
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(esm_loader_exports);
|
|
28
|
+
var import_node_module = require("module");
|
|
29
|
+
var import_node_perf_hooks = require("perf_hooks");
|
|
30
|
+
var port = null;
|
|
31
|
+
async function initialize(data) {
|
|
32
|
+
port = data.port ?? null;
|
|
33
|
+
}
|
|
34
|
+
async function resolve(specifier, context, nextResolve) {
|
|
35
|
+
const result = await nextResolve(specifier, context);
|
|
36
|
+
const isBuiltin = result.format === "builtin" || isBuiltinModule(specifier) || result.url.startsWith("node:");
|
|
37
|
+
port?.postMessage({
|
|
38
|
+
type: "resolve",
|
|
39
|
+
request: specifier,
|
|
40
|
+
resolvedPath: isBuiltin ? `builtin:${stripNodePrefix(specifier)}` : result.url,
|
|
41
|
+
parentPath: context.parentURL ?? "<entry>",
|
|
42
|
+
startTime: import_node_perf_hooks.performance.now(),
|
|
43
|
+
isBuiltin,
|
|
44
|
+
isNodeModule: !isBuiltin && result.url.includes("/node_modules/")
|
|
45
|
+
});
|
|
46
|
+
return result;
|
|
47
|
+
}
|
|
48
|
+
async function load(url, context, nextLoad) {
|
|
49
|
+
const result = await nextLoad(url, context);
|
|
50
|
+
if (result.format !== "module" || typeof result.source === "undefined" || shouldSkipInstrumentation(url)) {
|
|
51
|
+
return result;
|
|
52
|
+
}
|
|
53
|
+
const sourceText = typeof result.source === "string" ? result.source : arrayBufferLikeToString(result.source);
|
|
54
|
+
return {
|
|
55
|
+
...result,
|
|
56
|
+
source: `${sourceText}
|
|
57
|
+
;globalThis[Symbol.for('coldstart:esm:exit')]?.(${JSON.stringify(url)});
|
|
58
|
+
`
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
function shouldSkipInstrumentation(url) {
|
|
62
|
+
return url.startsWith("node:") || url.startsWith("data:");
|
|
63
|
+
}
|
|
64
|
+
function stripNodePrefix(value) {
|
|
65
|
+
return value.startsWith("node:") ? value.slice(5) : value;
|
|
66
|
+
}
|
|
67
|
+
function isBuiltinModule(name) {
|
|
68
|
+
return import_node_module.Module.isBuiltin?.(name) ?? fallbackBuiltinSet.has(stripNodePrefix(name));
|
|
69
|
+
}
|
|
70
|
+
function arrayBufferLikeToString(source) {
|
|
71
|
+
if (source instanceof Uint8Array) {
|
|
72
|
+
return Buffer.from(source).toString("utf8");
|
|
73
|
+
}
|
|
74
|
+
return Buffer.from(new Uint8Array(source)).toString("utf8");
|
|
75
|
+
}
|
|
76
|
+
var fallbackBuiltinSet = /* @__PURE__ */ new Set([
|
|
77
|
+
"assert",
|
|
78
|
+
"async_hooks",
|
|
79
|
+
"buffer",
|
|
80
|
+
"child_process",
|
|
81
|
+
"cluster",
|
|
82
|
+
"console",
|
|
83
|
+
"constants",
|
|
84
|
+
"crypto",
|
|
85
|
+
"dgram",
|
|
86
|
+
"diagnostics_channel",
|
|
87
|
+
"dns",
|
|
88
|
+
"domain",
|
|
89
|
+
"events",
|
|
90
|
+
"fs",
|
|
91
|
+
"http",
|
|
92
|
+
"http2",
|
|
93
|
+
"https",
|
|
94
|
+
"inspector",
|
|
95
|
+
"module",
|
|
96
|
+
"net",
|
|
97
|
+
"os",
|
|
98
|
+
"path",
|
|
99
|
+
"perf_hooks",
|
|
100
|
+
"process",
|
|
101
|
+
"punycode",
|
|
102
|
+
"querystring",
|
|
103
|
+
"readline",
|
|
104
|
+
"repl",
|
|
105
|
+
"stream",
|
|
106
|
+
"string_decoder",
|
|
107
|
+
"sys",
|
|
108
|
+
"timers",
|
|
109
|
+
"tls",
|
|
110
|
+
"trace_events",
|
|
111
|
+
"tty",
|
|
112
|
+
"url",
|
|
113
|
+
"util",
|
|
114
|
+
"v8",
|
|
115
|
+
"vm",
|
|
116
|
+
"wasi",
|
|
117
|
+
"worker_threads",
|
|
118
|
+
"zlib"
|
|
119
|
+
]);
|
|
120
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
121
|
+
0 && (module.exports = {
|
|
122
|
+
initialize,
|
|
123
|
+
load,
|
|
124
|
+
resolve
|
|
125
|
+
});
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import "./chunk-B5TADGOF.mjs";
|
|
2
|
+
|
|
3
|
+
// src/esm-loader.ts
|
|
4
|
+
import { Module } from "module";
|
|
5
|
+
import { performance } from "perf_hooks";
|
|
6
|
+
var port = null;
|
|
7
|
+
async function initialize(data) {
|
|
8
|
+
port = data.port ?? null;
|
|
9
|
+
}
|
|
10
|
+
async function resolve(specifier, context, nextResolve) {
|
|
11
|
+
const result = await nextResolve(specifier, context);
|
|
12
|
+
const isBuiltin = result.format === "builtin" || isBuiltinModule(specifier) || result.url.startsWith("node:");
|
|
13
|
+
port?.postMessage({
|
|
14
|
+
type: "resolve",
|
|
15
|
+
request: specifier,
|
|
16
|
+
resolvedPath: isBuiltin ? `builtin:${stripNodePrefix(specifier)}` : result.url,
|
|
17
|
+
parentPath: context.parentURL ?? "<entry>",
|
|
18
|
+
startTime: performance.now(),
|
|
19
|
+
isBuiltin,
|
|
20
|
+
isNodeModule: !isBuiltin && result.url.includes("/node_modules/")
|
|
21
|
+
});
|
|
22
|
+
return result;
|
|
23
|
+
}
|
|
24
|
+
async function load(url, context, nextLoad) {
|
|
25
|
+
const result = await nextLoad(url, context);
|
|
26
|
+
if (result.format !== "module" || typeof result.source === "undefined" || shouldSkipInstrumentation(url)) {
|
|
27
|
+
return result;
|
|
28
|
+
}
|
|
29
|
+
const sourceText = typeof result.source === "string" ? result.source : arrayBufferLikeToString(result.source);
|
|
30
|
+
return {
|
|
31
|
+
...result,
|
|
32
|
+
source: `${sourceText}
|
|
33
|
+
;globalThis[Symbol.for('coldstart:esm:exit')]?.(${JSON.stringify(url)});
|
|
34
|
+
`
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
function shouldSkipInstrumentation(url) {
|
|
38
|
+
return url.startsWith("node:") || url.startsWith("data:");
|
|
39
|
+
}
|
|
40
|
+
function stripNodePrefix(value) {
|
|
41
|
+
return value.startsWith("node:") ? value.slice(5) : value;
|
|
42
|
+
}
|
|
43
|
+
function isBuiltinModule(name) {
|
|
44
|
+
return Module.isBuiltin?.(name) ?? fallbackBuiltinSet.has(stripNodePrefix(name));
|
|
45
|
+
}
|
|
46
|
+
function arrayBufferLikeToString(source) {
|
|
47
|
+
if (source instanceof Uint8Array) {
|
|
48
|
+
return Buffer.from(source).toString("utf8");
|
|
49
|
+
}
|
|
50
|
+
return Buffer.from(new Uint8Array(source)).toString("utf8");
|
|
51
|
+
}
|
|
52
|
+
var fallbackBuiltinSet = /* @__PURE__ */ new Set([
|
|
53
|
+
"assert",
|
|
54
|
+
"async_hooks",
|
|
55
|
+
"buffer",
|
|
56
|
+
"child_process",
|
|
57
|
+
"cluster",
|
|
58
|
+
"console",
|
|
59
|
+
"constants",
|
|
60
|
+
"crypto",
|
|
61
|
+
"dgram",
|
|
62
|
+
"diagnostics_channel",
|
|
63
|
+
"dns",
|
|
64
|
+
"domain",
|
|
65
|
+
"events",
|
|
66
|
+
"fs",
|
|
67
|
+
"http",
|
|
68
|
+
"http2",
|
|
69
|
+
"https",
|
|
70
|
+
"inspector",
|
|
71
|
+
"module",
|
|
72
|
+
"net",
|
|
73
|
+
"os",
|
|
74
|
+
"path",
|
|
75
|
+
"perf_hooks",
|
|
76
|
+
"process",
|
|
77
|
+
"punycode",
|
|
78
|
+
"querystring",
|
|
79
|
+
"readline",
|
|
80
|
+
"repl",
|
|
81
|
+
"stream",
|
|
82
|
+
"string_decoder",
|
|
83
|
+
"sys",
|
|
84
|
+
"timers",
|
|
85
|
+
"tls",
|
|
86
|
+
"trace_events",
|
|
87
|
+
"tty",
|
|
88
|
+
"url",
|
|
89
|
+
"util",
|
|
90
|
+
"v8",
|
|
91
|
+
"vm",
|
|
92
|
+
"wasi",
|
|
93
|
+
"worker_threads",
|
|
94
|
+
"zlib"
|
|
95
|
+
]);
|
|
96
|
+
export {
|
|
97
|
+
initialize,
|
|
98
|
+
load,
|
|
99
|
+
resolve
|
|
100
|
+
};
|