@hirarijs/loader-cjs-interop 1.0.13 → 1.0.15
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 +8 -1
- package/dist/index.js +10 -2
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -40,11 +40,11 @@ var import_meta = {};
|
|
|
40
40
|
var extensions = [".js", ".cjs"];
|
|
41
41
|
var isValidIdent = (name) => /^[A-Za-z_$][0-9A-Za-z_$]*$/.test(name);
|
|
42
42
|
var WRAP_MARK = "__HIRARI_CJS_INTEROP_WRAPPED__";
|
|
43
|
+
var BYPASS_KEY = import_loader.BYPASS_FLAG || "__hirari_loader_bypass__";
|
|
43
44
|
function runTransform(code, filename, ctx) {
|
|
44
45
|
if (code.includes(WRAP_MARK)) {
|
|
45
46
|
return { code, continue: true };
|
|
46
47
|
}
|
|
47
|
-
console.log("Transforming", filename);
|
|
48
48
|
const opts = ctx.loaderConfig.pluginOptions?.["@hirarijs/loader-cjs-interop"] || {};
|
|
49
49
|
const ignoreNm = opts.ignoreNodeModules !== false && opts.allowNodeModules !== true;
|
|
50
50
|
if (ignoreNm && filename.includes("node_modules")) {
|
|
@@ -60,6 +60,8 @@ function runTransform(code, filename, ctx) {
|
|
|
60
60
|
}
|
|
61
61
|
let exportKeys = [];
|
|
62
62
|
try {
|
|
63
|
+
;
|
|
64
|
+
globalThis[BYPASS_KEY] = true;
|
|
63
65
|
const req = (0, import_module.createRequire)(import_meta.url);
|
|
64
66
|
const mod = req(filename);
|
|
65
67
|
if (mod && typeof mod === "object") {
|
|
@@ -73,6 +75,11 @@ function runTransform(code, filename, ctx) {
|
|
|
73
75
|
console.log(`[loader-cjs-interop] imported ${filename}`);
|
|
74
76
|
}
|
|
75
77
|
return { code, continue: true };
|
|
78
|
+
} finally {
|
|
79
|
+
try {
|
|
80
|
+
delete globalThis[BYPASS_KEY];
|
|
81
|
+
} catch {
|
|
82
|
+
}
|
|
76
83
|
}
|
|
77
84
|
const lines = [];
|
|
78
85
|
lines.push(`// ${WRAP_MARK}`);
|
package/dist/index.js
CHANGED
|
@@ -2,16 +2,17 @@
|
|
|
2
2
|
import { createRequire } from "module";
|
|
3
3
|
import path from "path";
|
|
4
4
|
import {
|
|
5
|
-
IMPORT_META_URL_VARIABLE
|
|
5
|
+
IMPORT_META_URL_VARIABLE,
|
|
6
|
+
BYPASS_FLAG
|
|
6
7
|
} from "@hirarijs/loader";
|
|
7
8
|
var extensions = [".js", ".cjs"];
|
|
8
9
|
var isValidIdent = (name) => /^[A-Za-z_$][0-9A-Za-z_$]*$/.test(name);
|
|
9
10
|
var WRAP_MARK = "__HIRARI_CJS_INTEROP_WRAPPED__";
|
|
11
|
+
var BYPASS_KEY = BYPASS_FLAG || "__hirari_loader_bypass__";
|
|
10
12
|
function runTransform(code, filename, ctx) {
|
|
11
13
|
if (code.includes(WRAP_MARK)) {
|
|
12
14
|
return { code, continue: true };
|
|
13
15
|
}
|
|
14
|
-
console.log("Transforming", filename);
|
|
15
16
|
const opts = ctx.loaderConfig.pluginOptions?.["@hirarijs/loader-cjs-interop"] || {};
|
|
16
17
|
const ignoreNm = opts.ignoreNodeModules !== false && opts.allowNodeModules !== true;
|
|
17
18
|
if (ignoreNm && filename.includes("node_modules")) {
|
|
@@ -27,6 +28,8 @@ function runTransform(code, filename, ctx) {
|
|
|
27
28
|
}
|
|
28
29
|
let exportKeys = [];
|
|
29
30
|
try {
|
|
31
|
+
;
|
|
32
|
+
globalThis[BYPASS_KEY] = true;
|
|
30
33
|
const req = createRequire(import.meta.url);
|
|
31
34
|
const mod = req(filename);
|
|
32
35
|
if (mod && typeof mod === "object") {
|
|
@@ -40,6 +43,11 @@ function runTransform(code, filename, ctx) {
|
|
|
40
43
|
console.log(`[loader-cjs-interop] imported ${filename}`);
|
|
41
44
|
}
|
|
42
45
|
return { code, continue: true };
|
|
46
|
+
} finally {
|
|
47
|
+
try {
|
|
48
|
+
delete globalThis[BYPASS_KEY];
|
|
49
|
+
} catch {
|
|
50
|
+
}
|
|
43
51
|
}
|
|
44
52
|
const lines = [];
|
|
45
53
|
lines.push(`// ${WRAP_MARK}`);
|