unrun 0.2.10 → 0.2.11

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 CHANGED
@@ -1,3 +1,3 @@
1
- import { n as unrunCli, r as unrunSync, t as unrun } from "./src-Dsr1Mx3W.mjs";
1
+ import { n as unrunCli, r as unrunSync, t as unrun } from "./src-DyfW0b4_.mjs";
2
2
 
3
3
  export { unrun, unrunCli, unrunSync };
@@ -150,84 +150,124 @@ function findContainingNodeModules(filePath) {
150
150
 
151
151
  //#endregion
152
152
  //#region src/plugins/console-output-customizer.ts
153
- /**
154
- * Attach a util.inspect customizer to namespace-like module objects produced by rolldown helpers
155
- * so console.log prints concrete values instead of [Getter], while preserving live bindings.
156
- *
157
- * Cleaner strategy: inject a tiny helper at the top of the chunk and minimally augment
158
- * rolldown helpers (__export and __copyProps) right inside their definitions, before use.
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
- if (!/__unrun__setInspect\b/.test(chunk.code)) {
167
- const helper = [
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
@@ -1,4 +1,4 @@
1
- import { t as unrun } from "../src-Dsr1Mx3W.mjs";
1
+ import { t as unrun } from "../src-DyfW0b4_.mjs";
2
2
  import { runAsWorker } from "synckit";
3
3
 
4
4
  //#region src/sync/worker.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "unrun",
3
- "version": "0.2.10",
3
+ "version": "0.2.11",
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.97.0",
43
- "rolldown": "1.0.0-beta.50"
42
+ "@oxc-project/runtime": "^0.96.0",
43
+ "rolldown": "1.0.0-beta.51"
44
44
  },
45
45
  "devDependencies": {
46
- "@sxzz/eslint-config": "^7.2.10",
47
- "@sxzz/prettier-config": "^2.2.4",
46
+ "@sxzz/eslint-config": "^7.3.0",
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.27.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",
@@ -71,15 +71,16 @@
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.4",
76
+ "tsdown": "^0.16.5",
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.7",
83
+ "unplugin-vue": "^7.0.8",
83
84
  "vite": "^7.2.2",
84
85
  "vitepress": "2.0.0-alpha.12",
85
86
  "vitepress-plugin-group-icons": "^1.6.5",
@@ -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",