@esm.sh/cjs-module-lexer 1.0.5 → 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.
Files changed (2) hide show
  1. package/index.mjs +10 -9
  2. package/package.json +1 -1
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 url = new URL(wasmPath, import.meta.url);
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 (url.pathname.startsWith(pkgPrefix)) {
14
- const version = url.pathname.slice(pkgPrefix.length).split("/", 1)[0];
15
- url.pathname = pkgPrefix + version + wasmPath.slice(1);
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(url);
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 code and return the exports and reexports
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
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@esm.sh/cjs-module-lexer",
3
3
  "description": "A lexer for detecting the `module.exports` of a CJS module.",
4
- "version": "1.0.5",
4
+ "version": "1.0.7",
5
5
  "type": "module",
6
6
  "main": "index.mjs",
7
7
  "scripts": {