@esm.sh/cjs-module-lexer 1.0.4 → 1.0.7
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/index.mjs +10 -9
- package/package.json +1 -1
- package/pkg/cjs-module-lexer_bg.wasm +0 -0
package/index.mjs
CHANGED
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
import { initSync, parse as __wbg_parse } from "./pkg/cjs-module-lexer.js";
|
|
2
|
-
const wasmPath = "./pkg/cjs-module-lexer_bg.wasm";
|
|
3
2
|
|
|
4
3
|
let wasm;
|
|
4
|
+
const wasmPath = "./pkg/cjs-module-lexer_bg.wasm";
|
|
5
|
+
const wasmUrl = new URL(wasmPath, import.meta.url);
|
|
6
|
+
|
|
5
7
|
if (globalThis.process || globalThis.Deno || globalThis.Bun) {
|
|
6
8
|
const { readFileSync } = await import("node:fs");
|
|
7
|
-
const
|
|
8
|
-
const wasmData = readFileSync(url.pathname);
|
|
9
|
+
const wasmData = readFileSync(wasmUrl.pathname);
|
|
9
10
|
wasm = await WebAssembly.compile(wasmData);
|
|
10
11
|
} else {
|
|
11
|
-
const url = new URL(wasmPath, import.meta.url);
|
|
12
12
|
const pkgPrefix = "/@esm.sh/cjs-module-lexer@";
|
|
13
|
-
if (
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
if (wasmUrl.pathname.startsWith(pkgPrefix)) {
|
|
14
|
+
// fix the wasm url for esm.sh usage
|
|
15
|
+
const version = wasmUrl.pathname.slice(pkgPrefix.length).split("/", 1)[0];
|
|
16
|
+
wasmUrl.pathname = pkgPrefix + version + wasmPath.slice(1);
|
|
16
17
|
}
|
|
17
|
-
const res = await fetch(
|
|
18
|
+
const res = await fetch(wasmUrl);
|
|
18
19
|
if (!res.ok) {
|
|
19
20
|
throw new Error(`failed to fetch wasm: ${res.statusText}`);
|
|
20
21
|
}
|
|
@@ -24,7 +25,7 @@ if (globalThis.process || globalThis.Deno || globalThis.Bun) {
|
|
|
24
25
|
initSync({ module: wasm });
|
|
25
26
|
|
|
26
27
|
/**
|
|
27
|
-
* parse the given
|
|
28
|
+
* parse the given cjs module and return the name exports and reexports
|
|
28
29
|
* @param {string} filename
|
|
29
30
|
* @param {string} code
|
|
30
31
|
* @param {{ nodeEnv?: 'development' | 'production', callMode?: boolean }} options
|
package/package.json
CHANGED
|
Binary file
|