@lifo-sh/node-runner 0.1.19 → 0.1.21
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 +42 -19
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +42 -19
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
package/dist/index.cjs
CHANGED
|
@@ -248,11 +248,20 @@ 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 (
|
|
252
|
-
|
|
253
|
-
|
|
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
|
+
}
|
|
254
263
|
for (const key of Object.keys(cond)) {
|
|
255
|
-
if (key === "types") continue;
|
|
264
|
+
if (key === "types" || key === "require" || key === "default" || key === "import") continue;
|
|
256
265
|
const nested = resolveExportsCondition(cond[key]);
|
|
257
266
|
if (nested) return nested;
|
|
258
267
|
}
|
|
@@ -810,7 +819,7 @@ function transformEsmToCjs(source) {
|
|
|
810
819
|
}).filter((s) => s).join(", ");
|
|
811
820
|
return `
|
|
812
821
|
${indent}${cjsDecl(tmp)} ${tmp} = require(${mod});
|
|
813
|
-
${indent}${cjsDecl(defaultName)} ${defaultName} = ${tmp}.default
|
|
822
|
+
${indent}${cjsDecl(defaultName)} ${defaultName} = ${tmp} && ${tmp}.__esModule && 'default' in ${tmp} ? ${tmp}.default : ${tmp};
|
|
814
823
|
${indent}const { ${mapped} } = ${tmp};`;
|
|
815
824
|
}
|
|
816
825
|
);
|
|
@@ -819,7 +828,7 @@ ${indent}const { ${mapped} } = ${tmp};`;
|
|
|
819
828
|
(_match, indent, defaultName, nsName, mod) => {
|
|
820
829
|
return `
|
|
821
830
|
${indent}${cjsDecl(nsName)} ${nsName} = require(${mod});
|
|
822
|
-
${indent}${cjsDecl(defaultName)} ${defaultName} = ${nsName}.default
|
|
831
|
+
${indent}${cjsDecl(defaultName)} ${defaultName} = ${nsName} && ${nsName}.__esModule && 'default' in ${nsName} ? ${nsName}.default : ${nsName};`;
|
|
823
832
|
}
|
|
824
833
|
);
|
|
825
834
|
result = result.replace(
|
|
@@ -847,8 +856,12 @@ ${indent}${cjsDecl(name)} ${name} = require(${mod});`
|
|
|
847
856
|
);
|
|
848
857
|
result = result.replace(
|
|
849
858
|
/(?:^|\n)([ \t]*)import\s+([\w$]+)\s+from\s*(['"][^'"]+['"])[ \t]*;?/g,
|
|
850
|
-
(_match, indent, name, mod) =>
|
|
851
|
-
|
|
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
|
+
}
|
|
852
865
|
);
|
|
853
866
|
result = result.replace(
|
|
854
867
|
/(?:^|\n)([ \t]*)import\s*(['"][^'"]+['"])[ \t]*;?/g,
|
|
@@ -994,19 +1007,16 @@ ${indent}${decl}`;
|
|
|
994
1007
|
result += "\n" + trailingExports.join("\n");
|
|
995
1008
|
}
|
|
996
1009
|
result = unmaskStringLiterals(result, literals);
|
|
997
|
-
return result;
|
|
1010
|
+
return 'Object.defineProperty(exports, "__esModule", { value: true });\n' + result;
|
|
998
1011
|
}
|
|
999
1012
|
function transformToCjs(source, filename, vfs) {
|
|
1000
1013
|
if (shouldTreatAsEsm(source, filename, vfs)) {
|
|
1001
|
-
const code2 =
|
|
1014
|
+
const code2 = safetyNetImportMeta(transformEsmToCjs(source));
|
|
1002
1015
|
return { code: code2, wasEsm: true };
|
|
1003
1016
|
}
|
|
1004
|
-
const code =
|
|
1017
|
+
const code = safetyNetImportMeta(replaceImportMetaInCode(source));
|
|
1005
1018
|
return { code, wasEsm: false };
|
|
1006
1019
|
}
|
|
1007
|
-
function stripViteHmr(code) {
|
|
1008
|
-
return code.replace(/^[ \t]*__importMeta\.hot\b.*$/gm, "").replace(/^[ \t]*import\.meta\.hot\b.*$/gm, "");
|
|
1009
|
-
}
|
|
1010
1020
|
function safetyNetImportMeta(code) {
|
|
1011
1021
|
if (!code.includes("import.meta")) return code;
|
|
1012
1022
|
return code.replace(/\bimport\.meta\.url\b/g, "__importMetaUrl").replace(/\bimport\.meta\.dirname\b/g, "__dirname").replace(/\bimport\.meta\.filename\b/g, "__filename").replace(/\bimport\.meta\.require\b/g, "require").replace(/\bimport\.meta\.resolve\b/g, "__importMetaResolve").replace(/\bimport\.meta\b/g, "__importMeta");
|
|
@@ -1014,6 +1024,20 @@ function safetyNetImportMeta(code) {
|
|
|
1014
1024
|
|
|
1015
1025
|
// src/runner.ts
|
|
1016
1026
|
var textEncoder = new TextEncoder();
|
|
1027
|
+
function createHotStub() {
|
|
1028
|
+
const noop = () => {
|
|
1029
|
+
};
|
|
1030
|
+
return {
|
|
1031
|
+
accept: noop,
|
|
1032
|
+
prune: noop,
|
|
1033
|
+
dispose: noop,
|
|
1034
|
+
decline: noop,
|
|
1035
|
+
invalidate: noop,
|
|
1036
|
+
on: noop,
|
|
1037
|
+
send: noop,
|
|
1038
|
+
data: {}
|
|
1039
|
+
};
|
|
1040
|
+
}
|
|
1017
1041
|
var JS_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
1018
1042
|
".js",
|
|
1019
1043
|
".ts",
|
|
@@ -1238,9 +1262,8 @@ var NodeRunner = class {
|
|
|
1238
1262
|
}
|
|
1239
1263
|
const ext = resolved.path.slice(resolved.path.lastIndexOf("."));
|
|
1240
1264
|
if (ext && !JS_EXTENSIONS.has(ext)) {
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
return clean;
|
|
1265
|
+
self.moduleCache.set(resolved.path, resolved.source);
|
|
1266
|
+
return resolved.source;
|
|
1244
1267
|
}
|
|
1245
1268
|
const moduleExports2 = {};
|
|
1246
1269
|
const moduleObj2 = { exports: moduleExports2 };
|
|
@@ -1252,7 +1275,7 @@ var NodeRunner = class {
|
|
|
1252
1275
|
cleanSource = cjsSource;
|
|
1253
1276
|
const factory = compileModule(cleanSource, resolved.path, self.stderr);
|
|
1254
1277
|
const importMetaUrl = "file://" + resolved.path;
|
|
1255
|
-
const importMeta = { url: importMetaUrl, dirname: moduleDir, filename: resolved.path };
|
|
1278
|
+
const importMeta = { url: importMetaUrl, dirname: moduleDir, filename: resolved.path, hot: createHotStub() };
|
|
1256
1279
|
const importMetaResolve = (specifier) => {
|
|
1257
1280
|
throw new Error(`import.meta.resolve('${specifier}') is not supported`);
|
|
1258
1281
|
};
|
|
@@ -1355,7 +1378,7 @@ ${cleanMainSource}
|
|
|
1355
1378
|
const moduleObj = { exports: moduleExports };
|
|
1356
1379
|
const global = { process: processObj, Buffer: BufferClass, console: scriptConsole };
|
|
1357
1380
|
const mainImportMetaUrl = "file://" + absPath;
|
|
1358
|
-
const mainImportMeta = { url: mainImportMetaUrl, dirname: scriptDir, filename: absPath };
|
|
1381
|
+
const mainImportMeta = { url: mainImportMetaUrl, dirname: scriptDir, filename: absPath, hot: createHotStub() };
|
|
1359
1382
|
const mainImportMetaResolve = (specifier) => {
|
|
1360
1383
|
throw new Error(`import.meta.resolve('${specifier}') is not supported`);
|
|
1361
1384
|
};
|