unrun 0.2.10 → 0.2.12
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/index.mjs +1 -1
- package/dist/{src-Dsr1Mx3W.mjs → src-BMOFH46e.mjs} +139 -96
- package/dist/sync/worker.mjs +1 -1
- package/package.json +16 -13
package/dist/index.mjs
CHANGED
|
@@ -150,84 +150,124 @@ function findContainingNodeModules(filePath) {
|
|
|
150
150
|
|
|
151
151
|
//#endregion
|
|
152
152
|
//#region src/plugins/console-output-customizer.ts
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
153
|
+
const INSPECT_HELPER_SNIPPET = `(function(){
|
|
154
|
+
function __unrun__fmt(names, getter, np){
|
|
155
|
+
var onlyDefault = names.length === 1 && names[0] === "default";
|
|
156
|
+
var o = np ? Object.create(null) : {};
|
|
157
|
+
for (var i = 0; i < names.length; i++) {
|
|
158
|
+
var n = names[i];
|
|
159
|
+
try { o[n] = getter(n) } catch {}
|
|
160
|
+
}
|
|
161
|
+
if (onlyDefault) {
|
|
162
|
+
try {
|
|
163
|
+
var s = JSON.stringify(o.default);
|
|
164
|
+
if (s !== undefined) {
|
|
165
|
+
s = s.replace(/"([^"]+)":/g, "$1: ").replace(/,/g, ", ").replace(/{/g, "{ ").replace(/}/g, " }");
|
|
166
|
+
return "[Module: null prototype] { default: " + s + " }";
|
|
167
|
+
}
|
|
168
|
+
} catch {}
|
|
169
|
+
return "[Module: null prototype] { default: " + String(o.default) + " }";
|
|
170
|
+
}
|
|
171
|
+
return o;
|
|
172
|
+
}
|
|
173
|
+
function __unrun__setInspect(obj, names, getter, np){
|
|
174
|
+
try {
|
|
175
|
+
var __insp = Symbol.for('nodejs.util.inspect.custom');
|
|
176
|
+
Object.defineProperty(obj, __insp, {
|
|
177
|
+
value: function(){ return __unrun__fmt(names, getter, np) },
|
|
178
|
+
enumerable: false, configurable: true
|
|
179
|
+
});
|
|
180
|
+
} catch {}
|
|
181
|
+
return obj;
|
|
182
|
+
}
|
|
183
|
+
try {
|
|
184
|
+
Object.defineProperty(globalThis, "__unrun__setInspect", {
|
|
185
|
+
value: __unrun__setInspect,
|
|
186
|
+
enumerable: false,
|
|
187
|
+
});
|
|
188
|
+
} catch {}
|
|
189
|
+
})();`;
|
|
190
|
+
const WRAPPER_SNIPPET = `(function __unrun__wrapRolldownHelpers(){
|
|
191
|
+
if (typeof __unrun__setInspect !== "function") return;
|
|
192
|
+
if (typeof __export === "function" && !__export.__unrunPatched) {
|
|
193
|
+
var __unrun__origExport = __export;
|
|
194
|
+
var __unrun__patchedExport = (...__unrun__args) => {
|
|
195
|
+
var __unrun__target = __unrun__origExport(...__unrun__args);
|
|
196
|
+
if (__unrun__target && typeof __unrun__target === "object") {
|
|
197
|
+
try {
|
|
198
|
+
var __unrun__map = (__unrun__args[0] && typeof __unrun__args[0] === "object") ? __unrun__args[0] : {};
|
|
199
|
+
var __unrun__names = Object.keys(__unrun__map).filter(function(n){ return n !== "__esModule" });
|
|
200
|
+
__unrun__setInspect(
|
|
201
|
+
__unrun__target,
|
|
202
|
+
__unrun__names,
|
|
203
|
+
function(n){
|
|
204
|
+
var getter = __unrun__map[n];
|
|
205
|
+
return typeof getter === "function" ? getter() : getter;
|
|
206
|
+
},
|
|
207
|
+
false,
|
|
208
|
+
);
|
|
209
|
+
} catch {}
|
|
210
|
+
}
|
|
211
|
+
return __unrun__target;
|
|
212
|
+
};
|
|
213
|
+
__unrun__patchedExport.__unrunPatched = true;
|
|
214
|
+
__export = __unrun__patchedExport;
|
|
215
|
+
}
|
|
216
|
+
if (typeof __copyProps === "function" && !__copyProps.__unrunPatched) {
|
|
217
|
+
var __unrun__origCopyProps = __copyProps;
|
|
218
|
+
var __unrun__patchedCopyProps = (...__unrun__args) => {
|
|
219
|
+
var __unrun__result = __unrun__origCopyProps(...__unrun__args);
|
|
220
|
+
if (__unrun__result && typeof __unrun__result === "object") {
|
|
221
|
+
try {
|
|
222
|
+
var __unrun__names = Object.keys(__unrun__result).filter(function(n){ return n !== "__esModule" });
|
|
223
|
+
__unrun__setInspect(__unrun__result, __unrun__names, function(n){ return __unrun__result[n] }, true);
|
|
224
|
+
} catch {}
|
|
225
|
+
}
|
|
226
|
+
return __unrun__result;
|
|
227
|
+
};
|
|
228
|
+
__unrun__patchedCopyProps.__unrunPatched = true;
|
|
229
|
+
__copyProps = __unrun__patchedCopyProps;
|
|
230
|
+
}
|
|
231
|
+
})();`;
|
|
232
|
+
const HELPER_DECLARATION_PATTERN = /__unrun__setInspect\b/;
|
|
233
|
+
const WRAPPER_MARKER = "__unrun__wrapRolldownHelpers";
|
|
160
234
|
function createConsoleOutputCustomizer() {
|
|
161
235
|
return {
|
|
162
236
|
name: "unrun-console-output-customizer",
|
|
163
237
|
generateBundle: { handler(_, bundle$1) {
|
|
164
238
|
for (const chunk of Object.values(bundle$1)) {
|
|
165
239
|
if (chunk.type !== "chunk") continue;
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
"(function(){",
|
|
169
|
-
" function __unrun__fmt(names, getter, np){",
|
|
170
|
-
" var onlyDefault = names.length === 1 && names[0] === \"default\";",
|
|
171
|
-
" var o = np ? Object.create(null) : {};",
|
|
172
|
-
" for (var i = 0; i < names.length; i++) {",
|
|
173
|
-
" var n = names[i];",
|
|
174
|
-
" try { o[n] = getter(n) } catch {}",
|
|
175
|
-
" }",
|
|
176
|
-
" if (onlyDefault) {",
|
|
177
|
-
" try {",
|
|
178
|
-
" var s = JSON.stringify(o.default);",
|
|
179
|
-
" if (s !== undefined) {",
|
|
180
|
-
" s = s.replace(/\"([^\"]+)\":/g, \"$1: \").replace(/,/g, \", \").replace(/{/g, \"{ \").replace(/}/g, \" }\");",
|
|
181
|
-
" return \"[Module: null prototype] { default: \" + s + \" }\";",
|
|
182
|
-
" }",
|
|
183
|
-
" } catch {}",
|
|
184
|
-
" return \"[Module: null prototype] { default: \" + String(o.default) + \" }\";",
|
|
185
|
-
" }",
|
|
186
|
-
" return o;",
|
|
187
|
-
" }",
|
|
188
|
-
" function __unrun__setInspect(obj, names, getter, np){",
|
|
189
|
-
" try {",
|
|
190
|
-
" var __insp = Symbol.for('nodejs.util.inspect.custom')",
|
|
191
|
-
" Object.defineProperty(obj, __insp, {",
|
|
192
|
-
" value: function(){ return __unrun__fmt(names, getter, np) },",
|
|
193
|
-
" enumerable: false, configurable: true",
|
|
194
|
-
" })",
|
|
195
|
-
" } catch {}",
|
|
196
|
-
" return obj;",
|
|
197
|
-
" }",
|
|
198
|
-
" try { Object.defineProperty(globalThis, \"__unrun__setInspect\", { value: __unrun__setInspect, enumerable: false }) } catch {}",
|
|
199
|
-
"})();"
|
|
200
|
-
].join("\n");
|
|
201
|
-
if (chunk.code.startsWith("#!")) {
|
|
202
|
-
const nl = chunk.code.indexOf("\n");
|
|
203
|
-
if (nl !== -1) chunk.code = `${chunk.code.slice(0, nl + 1)}${helper}\n${chunk.code.slice(nl + 1)}`;
|
|
204
|
-
else chunk.code = `${helper}\n${chunk.code}`;
|
|
205
|
-
} else chunk.code = `${helper}\n${chunk.code}`;
|
|
206
|
-
}
|
|
207
|
-
chunk.code = chunk.code.replace(/var\s+__export\s*=\s*\(all\)\s*=>\s*\{([\s\S]*?)return\s+target;\s*\}/, (_m, body) => {
|
|
208
|
-
return `var __export = (all) => {\n${[
|
|
209
|
-
body,
|
|
210
|
-
" try {",
|
|
211
|
-
" var __names = Object.keys(all).filter(function(n){ return n !== \"__esModule\" })",
|
|
212
|
-
" __unrun__setInspect(target, __names, function(n){ return all[n]() }, false)",
|
|
213
|
-
" } catch {}",
|
|
214
|
-
" return target;"
|
|
215
|
-
].join("\n")}\n}`;
|
|
216
|
-
});
|
|
217
|
-
chunk.code = chunk.code.replace(/var\s+__copyProps\s*=\s*\(to,\s*from,\s*except,\s*desc\)\s*=>\s*\{([\s\S]*?)return\s+to;\s*\};/, (_m, body) => {
|
|
218
|
-
return `var __copyProps = (to, from, except, desc) => {\n${[
|
|
219
|
-
body,
|
|
220
|
-
" try {",
|
|
221
|
-
" var __names = Object.keys(to).filter(function(n){ return n !== \"__esModule\" })",
|
|
222
|
-
" __unrun__setInspect(to, __names, function(n){ return to[n] }, true)",
|
|
223
|
-
" } catch {}",
|
|
224
|
-
" return to;"
|
|
225
|
-
].join("\n")}\n};`;
|
|
226
|
-
});
|
|
240
|
+
injectInspectHelper(chunk);
|
|
241
|
+
injectHelperWrappers(chunk);
|
|
227
242
|
}
|
|
228
243
|
} }
|
|
229
244
|
};
|
|
230
245
|
}
|
|
246
|
+
function injectInspectHelper(chunk) {
|
|
247
|
+
if (HELPER_DECLARATION_PATTERN.test(chunk.code)) return;
|
|
248
|
+
chunk.code = chunk.code.startsWith("#!") ? insertAfterShebang(chunk.code, `${INSPECT_HELPER_SNIPPET}\n`) : `${INSPECT_HELPER_SNIPPET}\n${chunk.code}`;
|
|
249
|
+
}
|
|
250
|
+
function injectHelperWrappers(chunk) {
|
|
251
|
+
if (chunk.code.includes(WRAPPER_MARKER)) return;
|
|
252
|
+
const insertIndex = findRuntimeBoundary(chunk.code);
|
|
253
|
+
const snippet = `${WRAPPER_SNIPPET}\n`;
|
|
254
|
+
if (insertIndex === -1) {
|
|
255
|
+
chunk.code = `${chunk.code}\n${snippet}`;
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
chunk.code = `${chunk.code.slice(0, insertIndex)}${snippet}${chunk.code.slice(insertIndex)}`;
|
|
259
|
+
}
|
|
260
|
+
function findRuntimeBoundary(code) {
|
|
261
|
+
const markerIndex = code.indexOf("//#endregion");
|
|
262
|
+
if (markerIndex === -1) return -1;
|
|
263
|
+
const newlineIndex = code.indexOf("\n", markerIndex);
|
|
264
|
+
return newlineIndex === -1 ? code.length : newlineIndex + 1;
|
|
265
|
+
}
|
|
266
|
+
function insertAfterShebang(code, insertion) {
|
|
267
|
+
const nl = code.indexOf("\n");
|
|
268
|
+
if (nl === -1) return `${code}\n${insertion}`;
|
|
269
|
+
return `${code.slice(0, nl + 1)}${insertion}${code.slice(nl + 1)}`;
|
|
270
|
+
}
|
|
231
271
|
|
|
232
272
|
//#endregion
|
|
233
273
|
//#region src/plugins/json-loader.ts
|
|
@@ -297,37 +337,40 @@ function createMakeCjsWrapperAsyncFriendlyPlugin() {
|
|
|
297
337
|
for (const chunk of Object.values(bundle$1)) {
|
|
298
338
|
if (chunk.type !== "chunk") continue;
|
|
299
339
|
let code = chunk.code;
|
|
300
|
-
const
|
|
301
|
-
if (!code.includes(marker))
|
|
302
|
-
let pos = 0;
|
|
340
|
+
const wrapperMarkers = ["__commonJS({", "__commonJSMin("];
|
|
341
|
+
if (!wrapperMarkers.some((marker) => code.includes(marker))) continue;
|
|
303
342
|
const arrowToken = "(() => {";
|
|
304
343
|
const asyncArrowToken = "(async () => {";
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
344
|
+
const patchMarker = (marker) => {
|
|
345
|
+
let pos = 0;
|
|
346
|
+
while (true) {
|
|
347
|
+
const markerIdx = code.indexOf(marker, pos);
|
|
348
|
+
if (markerIdx === -1) break;
|
|
349
|
+
const fnStart = code.indexOf(arrowToken, markerIdx);
|
|
350
|
+
if (fnStart === -1) {
|
|
351
|
+
pos = markerIdx + marker.length;
|
|
352
|
+
continue;
|
|
353
|
+
}
|
|
354
|
+
const bodyStart = fnStart + 8;
|
|
355
|
+
let i = bodyStart;
|
|
356
|
+
let depth = 1;
|
|
357
|
+
while (i < code.length && depth > 0) {
|
|
358
|
+
const ch = code[i++];
|
|
359
|
+
if (ch === "{") depth++;
|
|
360
|
+
else if (ch === "}") depth--;
|
|
361
|
+
}
|
|
362
|
+
if (depth !== 0) break;
|
|
363
|
+
const bodyEnd = i - 1;
|
|
364
|
+
const body = code.slice(bodyStart, bodyEnd);
|
|
365
|
+
if (/\bawait\b/.test(body) && code.slice(fnStart, fnStart + 14) !== asyncArrowToken) {
|
|
366
|
+
code = `${code.slice(0, fnStart + 1)}async ${code.slice(fnStart + 1)}`;
|
|
367
|
+
pos = fnStart + 1 + 6;
|
|
368
|
+
continue;
|
|
369
|
+
}
|
|
370
|
+
pos = bodyEnd;
|
|
312
371
|
}
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
let depth = 1;
|
|
316
|
-
while (i < code.length && depth > 0) {
|
|
317
|
-
const ch = code[i++];
|
|
318
|
-
if (ch === "{") depth++;
|
|
319
|
-
else if (ch === "}") depth--;
|
|
320
|
-
}
|
|
321
|
-
if (depth !== 0) break;
|
|
322
|
-
const bodyEnd = i - 1;
|
|
323
|
-
const body = code.slice(bodyStart, bodyEnd);
|
|
324
|
-
if (/\bawait\b/.test(body) && code.slice(fnStart, fnStart + 14) !== asyncArrowToken) {
|
|
325
|
-
code = `${code.slice(0, fnStart + 1)}async ${code.slice(fnStart + 1)}`;
|
|
326
|
-
pos = fnStart + 1 + 6;
|
|
327
|
-
continue;
|
|
328
|
-
}
|
|
329
|
-
pos = bodyEnd;
|
|
330
|
-
}
|
|
372
|
+
};
|
|
373
|
+
for (const marker of wrapperMarkers) patchMarker(marker);
|
|
331
374
|
if (code !== chunk.code) chunk.code = code;
|
|
332
375
|
}
|
|
333
376
|
} }
|
package/dist/sync/worker.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "unrun",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.12",
|
|
4
4
|
"description": "A tool to load and execute any JavaScript or TypeScript code at runtime.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -39,12 +39,12 @@
|
|
|
39
39
|
}
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@oxc-project/runtime": "^0.
|
|
43
|
-
"rolldown": "1.0.0-beta.
|
|
42
|
+
"@oxc-project/runtime": "^0.99.0",
|
|
43
|
+
"rolldown": "1.0.0-beta.52"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@sxzz/eslint-config": "^7.2
|
|
47
|
-
"@sxzz/prettier-config": "^2.2.
|
|
46
|
+
"@sxzz/eslint-config": "^7.3.2",
|
|
47
|
+
"@sxzz/prettier-config": "^2.2.5",
|
|
48
48
|
"@types/node": "^24.10.1",
|
|
49
49
|
"acorn": "^8.15.0",
|
|
50
50
|
"bumpp": "^10.3.1",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"consola": "^3.4.2",
|
|
54
54
|
"defu": "^6.1.4",
|
|
55
55
|
"destr": "^2.0.5",
|
|
56
|
-
"esbuild": "^0.
|
|
56
|
+
"esbuild": "^0.25.12",
|
|
57
57
|
"eslint": "^9.39.1",
|
|
58
58
|
"estree-walker": "^3.0.3",
|
|
59
59
|
"etag": "^1.8.1",
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
"jiti": "^2.6.1",
|
|
64
64
|
"mime": "^4.1.0",
|
|
65
65
|
"moment-timezone": "^0.6.0",
|
|
66
|
-
"nano-jsx": "^0.2.
|
|
66
|
+
"nano-jsx": "^0.2.1",
|
|
67
67
|
"preact": "^10.27.2",
|
|
68
68
|
"preact-render-to-string": "^6.6.3",
|
|
69
69
|
"prettier": "^3.6.2",
|
|
@@ -71,22 +71,23 @@
|
|
|
71
71
|
"react-dom": "^19.2.0",
|
|
72
72
|
"reflect-metadata": "^0.2.2",
|
|
73
73
|
"synckit": "^0.11.11",
|
|
74
|
+
"test-ecosystem-ci": "^0.0.1",
|
|
74
75
|
"tinyexec": "^1.0.2",
|
|
75
|
-
"tsdown": "^0.16.
|
|
76
|
+
"tsdown": "^0.16.7",
|
|
76
77
|
"tsx": "^4.20.6",
|
|
77
78
|
"typedoc": "^0.28.14",
|
|
78
79
|
"typedoc-plugin-markdown": "^4.9.0",
|
|
79
80
|
"typedoc-vitepress-theme": "^1.1.2",
|
|
80
81
|
"typescript": "^5.9.3",
|
|
81
82
|
"unconfig": "^7.4.1",
|
|
82
|
-
"unplugin-vue": "^7.0.
|
|
83
|
-
"vite": "^7.2.
|
|
83
|
+
"unplugin-vue": "^7.0.8",
|
|
84
|
+
"vite": "^7.2.4",
|
|
84
85
|
"vitepress": "2.0.0-alpha.12",
|
|
85
86
|
"vitepress-plugin-group-icons": "^1.6.5",
|
|
86
87
|
"vitest": "4.0.8",
|
|
87
|
-
"vue": "^3.5.
|
|
88
|
-
"vue-tsc": "^3.1.
|
|
89
|
-
"zod": "^4.1.
|
|
88
|
+
"vue": "^3.5.25",
|
|
89
|
+
"vue-tsc": "^3.1.5",
|
|
90
|
+
"zod": "^4.1.13"
|
|
90
91
|
},
|
|
91
92
|
"engines": {
|
|
92
93
|
"node": ">=20.19.0"
|
|
@@ -103,6 +104,8 @@
|
|
|
103
104
|
"pretest:run": "node ./scripts/manage-pnpm-override.mjs add",
|
|
104
105
|
"test:run": "vitest run",
|
|
105
106
|
"posttest:run": "node ./scripts/manage-pnpm-override.mjs remove",
|
|
107
|
+
"ecosystem-ci": "ecosystem-ci",
|
|
108
|
+
"ecosystem-ci:force": "ecosystem-ci --force",
|
|
106
109
|
"test:update-fixtures": "node ./dist/cli.mjs ./scripts/update-fixtures.ts",
|
|
107
110
|
"benchmark": "tsdown -c benchmark/tsdown.config.ts && node ./benchmark/dist/benchmark.mjs",
|
|
108
111
|
"typecheck": "tsc --noEmit",
|