@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 +21 -29
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +21 -29
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -217,20 +217,11 @@ function resolveExportsCondition(value) {
|
|
|
217
217
|
if (typeof value === "string") return value;
|
|
218
218
|
if (value && typeof value === "object" && !Array.isArray(value)) {
|
|
219
219
|
const cond = value;
|
|
220
|
-
if (cond.require
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
}
|
|
224
|
-
if (cond.default != null) {
|
|
225
|
-
const r = resolveExportsCondition(cond.default);
|
|
226
|
-
if (r) return r;
|
|
227
|
-
}
|
|
228
|
-
if (cond.import != null) {
|
|
229
|
-
const r = resolveExportsCondition(cond.import);
|
|
230
|
-
if (r) return r;
|
|
231
|
-
}
|
|
220
|
+
if (typeof cond.require === "string") return cond.require;
|
|
221
|
+
if (typeof cond.default === "string") return cond.default;
|
|
222
|
+
if (typeof cond.import === "string") return cond.import;
|
|
232
223
|
for (const key of Object.keys(cond)) {
|
|
233
|
-
if (key === "types"
|
|
224
|
+
if (key === "types") continue;
|
|
234
225
|
const nested = resolveExportsCondition(cond[key]);
|
|
235
226
|
if (nested) return nested;
|
|
236
227
|
}
|
|
@@ -788,7 +779,7 @@ function transformEsmToCjs(source) {
|
|
|
788
779
|
}).filter((s) => s).join(", ");
|
|
789
780
|
return `
|
|
790
781
|
${indent}${cjsDecl(tmp)} ${tmp} = require(${mod});
|
|
791
|
-
${indent}${cjsDecl(defaultName)} ${defaultName} = ${tmp}
|
|
782
|
+
${indent}${cjsDecl(defaultName)} ${defaultName} = ${tmp}.default || ${tmp};
|
|
792
783
|
${indent}const { ${mapped} } = ${tmp};`;
|
|
793
784
|
}
|
|
794
785
|
);
|
|
@@ -797,7 +788,7 @@ ${indent}const { ${mapped} } = ${tmp};`;
|
|
|
797
788
|
(_match, indent, defaultName, nsName, mod) => {
|
|
798
789
|
return `
|
|
799
790
|
${indent}${cjsDecl(nsName)} ${nsName} = require(${mod});
|
|
800
|
-
${indent}${cjsDecl(defaultName)} ${defaultName} = ${nsName}
|
|
791
|
+
${indent}${cjsDecl(defaultName)} ${defaultName} = ${nsName}.default || ${nsName};`;
|
|
801
792
|
}
|
|
802
793
|
);
|
|
803
794
|
result = result.replace(
|
|
@@ -825,12 +816,8 @@ ${indent}${cjsDecl(name)} ${name} = require(${mod});`
|
|
|
825
816
|
);
|
|
826
817
|
result = result.replace(
|
|
827
818
|
/(?:^|\n)([ \t]*)import\s+([\w$]+)\s+from\s*(['"][^'"]+['"])[ \t]*;?/g,
|
|
828
|
-
(_match, indent, name, mod) =>
|
|
829
|
-
|
|
830
|
-
return `
|
|
831
|
-
${indent}const ${tmp} = require(${mod});
|
|
832
|
-
${indent}${cjsDecl(name)} ${name} = ${tmp} && ${tmp}.__esModule && 'default' in ${tmp} ? ${tmp}.default : ${tmp};`;
|
|
833
|
-
}
|
|
819
|
+
(_match, indent, name, mod) => `
|
|
820
|
+
${indent}${cjsDecl(name)} ${name} = require(${mod});`
|
|
834
821
|
);
|
|
835
822
|
result = result.replace(
|
|
836
823
|
/(?:^|\n)([ \t]*)import\s*(['"][^'"]+['"])[ \t]*;?/g,
|
|
@@ -976,7 +963,7 @@ ${indent}${decl}`;
|
|
|
976
963
|
result += "\n" + trailingExports.join("\n");
|
|
977
964
|
}
|
|
978
965
|
result = unmaskStringLiterals(result, literals);
|
|
979
|
-
return
|
|
966
|
+
return result;
|
|
980
967
|
}
|
|
981
968
|
function transformToCjs(source, filename, vfs) {
|
|
982
969
|
if (shouldTreatAsEsm(source, filename, vfs)) {
|
|
@@ -1369,6 +1356,7 @@ ${cleanMainSource}
|
|
|
1369
1356
|
ga[k] = this.globalShims[k];
|
|
1370
1357
|
}
|
|
1371
1358
|
}
|
|
1359
|
+
let processExited = false;
|
|
1372
1360
|
let pendingRejection = null;
|
|
1373
1361
|
const rejectionHandler = (event) => {
|
|
1374
1362
|
pendingRejection = event.reason;
|
|
@@ -1408,6 +1396,7 @@ ${cleanMainSource}
|
|
|
1408
1396
|
if (pendingRejection) {
|
|
1409
1397
|
if (pendingRejection instanceof ProcessExitError) {
|
|
1410
1398
|
exitCode = pendingRejection.code;
|
|
1399
|
+
processExited = true;
|
|
1411
1400
|
} else {
|
|
1412
1401
|
exitCode = 1;
|
|
1413
1402
|
}
|
|
@@ -1415,6 +1404,7 @@ ${cleanMainSource}
|
|
|
1415
1404
|
} catch (e) {
|
|
1416
1405
|
if (e instanceof ProcessExitError) {
|
|
1417
1406
|
exitCode = e.code;
|
|
1407
|
+
processExited = true;
|
|
1418
1408
|
} else {
|
|
1419
1409
|
exitCode = 1;
|
|
1420
1410
|
const msg = e instanceof Error ? e.stack || e.message : String(e);
|
|
@@ -1437,7 +1427,8 @@ ${cleanMainSource}
|
|
|
1437
1427
|
globalThis.removeEventListener("unhandledrejection", rejectionHandler);
|
|
1438
1428
|
}
|
|
1439
1429
|
}
|
|
1440
|
-
if (activeTimers.size > 0) {
|
|
1430
|
+
if (activeTimers.size > 0 && !processExited) {
|
|
1431
|
+
const DRAIN_TIMEOUT = 5e3;
|
|
1441
1432
|
const drainPromise = new Promise((resolve) => {
|
|
1442
1433
|
timerDrainResolve = resolve;
|
|
1443
1434
|
});
|
|
@@ -1447,15 +1438,16 @@ ${cleanMainSource}
|
|
|
1447
1438
|
return;
|
|
1448
1439
|
}
|
|
1449
1440
|
this.signal.addEventListener("abort", () => resolve(), { once: true });
|
|
1450
|
-
}) : new Promise(() => {
|
|
1441
|
+
}) : new Promise((resolve) => {
|
|
1442
|
+
setTimeout(resolve, DRAIN_TIMEOUT);
|
|
1451
1443
|
});
|
|
1452
1444
|
await Promise.race([drainPromise, abortPromise]);
|
|
1453
|
-
for (const id of activeTimers) {
|
|
1454
|
-
globalThis.clearTimeout(id);
|
|
1455
|
-
globalThis.clearInterval(id);
|
|
1456
|
-
}
|
|
1457
|
-
activeTimers.clear();
|
|
1458
1445
|
}
|
|
1446
|
+
for (const id of activeTimers) {
|
|
1447
|
+
globalThis.clearTimeout(id);
|
|
1448
|
+
globalThis.clearInterval(id);
|
|
1449
|
+
}
|
|
1450
|
+
activeTimers.clear();
|
|
1459
1451
|
return {
|
|
1460
1452
|
exitCode,
|
|
1461
1453
|
stdout: isStreaming ? "" : stdoutLines.join("\n"),
|