@lifo-sh/node-runner 0.1.22 → 0.1.24

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.cjs CHANGED
@@ -248,20 +248,11 @@ function resolveExportsCondition(value) {
248
248
  if (typeof value === "string") return value;
249
249
  if (value && typeof value === "object" && !Array.isArray(value)) {
250
250
  const cond = value;
251
- if (cond.require != null) {
252
- const r = resolveExportsCondition(cond.require);
253
- if (r) return r;
254
- }
255
- if (cond.default != null) {
256
- const r = resolveExportsCondition(cond.default);
257
- if (r) return r;
258
- }
259
- if (cond.import != null) {
260
- const r = resolveExportsCondition(cond.import);
261
- if (r) return r;
262
- }
251
+ if (typeof cond.require === "string") return cond.require;
252
+ if (typeof cond.default === "string") return cond.default;
253
+ if (typeof cond.import === "string") return cond.import;
263
254
  for (const key of Object.keys(cond)) {
264
- if (key === "types" || key === "require" || key === "default" || key === "import") continue;
255
+ if (key === "types") continue;
265
256
  const nested = resolveExportsCondition(cond[key]);
266
257
  if (nested) return nested;
267
258
  }
@@ -819,7 +810,7 @@ function transformEsmToCjs(source) {
819
810
  }).filter((s) => s).join(", ");
820
811
  return `
821
812
  ${indent}${cjsDecl(tmp)} ${tmp} = require(${mod});
822
- ${indent}${cjsDecl(defaultName)} ${defaultName} = ${tmp} && ${tmp}.__esModule && 'default' in ${tmp} ? ${tmp}.default : ${tmp};
813
+ ${indent}${cjsDecl(defaultName)} ${defaultName} = ${tmp}.default || ${tmp};
823
814
  ${indent}const { ${mapped} } = ${tmp};`;
824
815
  }
825
816
  );
@@ -828,7 +819,7 @@ ${indent}const { ${mapped} } = ${tmp};`;
828
819
  (_match, indent, defaultName, nsName, mod) => {
829
820
  return `
830
821
  ${indent}${cjsDecl(nsName)} ${nsName} = require(${mod});
831
- ${indent}${cjsDecl(defaultName)} ${defaultName} = ${nsName} && ${nsName}.__esModule && 'default' in ${nsName} ? ${nsName}.default : ${nsName};`;
822
+ ${indent}${cjsDecl(defaultName)} ${defaultName} = ${nsName}.default || ${nsName};`;
832
823
  }
833
824
  );
834
825
  result = result.replace(
@@ -856,12 +847,8 @@ ${indent}${cjsDecl(name)} ${name} = require(${mod});`
856
847
  );
857
848
  result = result.replace(
858
849
  /(?:^|\n)([ \t]*)import\s+([\w$]+)\s+from\s*(['"][^'"]+['"])[ \t]*;?/g,
859
- (_match, indent, name, mod) => {
860
- const tmp = "__imp_" + Math.random().toString(36).slice(2, 8);
861
- return `
862
- ${indent}const ${tmp} = require(${mod});
863
- ${indent}${cjsDecl(name)} ${name} = ${tmp} && ${tmp}.__esModule && 'default' in ${tmp} ? ${tmp}.default : ${tmp};`;
864
- }
850
+ (_match, indent, name, mod) => `
851
+ ${indent}${cjsDecl(name)} ${name} = require(${mod});`
865
852
  );
866
853
  result = result.replace(
867
854
  /(?:^|\n)([ \t]*)import\s*(['"][^'"]+['"])[ \t]*;?/g,
@@ -1007,7 +994,7 @@ ${indent}${decl}`;
1007
994
  result += "\n" + trailingExports.join("\n");
1008
995
  }
1009
996
  result = unmaskStringLiterals(result, literals);
1010
- return 'Object.defineProperty(exports, "__esModule", { value: true });\n' + result;
997
+ return result;
1011
998
  }
1012
999
  function transformToCjs(source, filename, vfs) {
1013
1000
  if (shouldTreatAsEsm(source, filename, vfs)) {
@@ -1400,6 +1387,7 @@ ${cleanMainSource}
1400
1387
  ga[k] = this.globalShims[k];
1401
1388
  }
1402
1389
  }
1390
+ let processExited = false;
1403
1391
  let pendingRejection = null;
1404
1392
  const rejectionHandler = (event) => {
1405
1393
  pendingRejection = event.reason;
@@ -1439,6 +1427,7 @@ ${cleanMainSource}
1439
1427
  if (pendingRejection) {
1440
1428
  if (pendingRejection instanceof ProcessExitError) {
1441
1429
  exitCode = pendingRejection.code;
1430
+ processExited = true;
1442
1431
  } else {
1443
1432
  exitCode = 1;
1444
1433
  }
@@ -1446,6 +1435,7 @@ ${cleanMainSource}
1446
1435
  } catch (e) {
1447
1436
  if (e instanceof ProcessExitError) {
1448
1437
  exitCode = e.code;
1438
+ processExited = true;
1449
1439
  } else {
1450
1440
  exitCode = 1;
1451
1441
  const msg = e instanceof Error ? e.stack || e.message : String(e);
@@ -1468,7 +1458,8 @@ ${cleanMainSource}
1468
1458
  globalThis.removeEventListener("unhandledrejection", rejectionHandler);
1469
1459
  }
1470
1460
  }
1471
- if (activeTimers.size > 0) {
1461
+ if (activeTimers.size > 0 && !processExited) {
1462
+ const DRAIN_TIMEOUT = 5e3;
1472
1463
  const drainPromise = new Promise((resolve) => {
1473
1464
  timerDrainResolve = resolve;
1474
1465
  });
@@ -1478,15 +1469,16 @@ ${cleanMainSource}
1478
1469
  return;
1479
1470
  }
1480
1471
  this.signal.addEventListener("abort", () => resolve(), { once: true });
1481
- }) : new Promise(() => {
1472
+ }) : new Promise((resolve) => {
1473
+ setTimeout(resolve, DRAIN_TIMEOUT);
1482
1474
  });
1483
1475
  await Promise.race([drainPromise, abortPromise]);
1484
- for (const id of activeTimers) {
1485
- globalThis.clearTimeout(id);
1486
- globalThis.clearInterval(id);
1487
- }
1488
- activeTimers.clear();
1489
1476
  }
1477
+ for (const id of activeTimers) {
1478
+ globalThis.clearTimeout(id);
1479
+ globalThis.clearInterval(id);
1480
+ }
1481
+ activeTimers.clear();
1490
1482
  return {
1491
1483
  exitCode,
1492
1484
  stdout: isStreaming ? "" : stdoutLines.join("\n"),