Skip to content

Commit

Permalink
Bump package version to 1.0.6
Browse files Browse the repository at this point in the history
  • Loading branch information
ije committed Dec 15, 2024
1 parent 623689f commit cf37250
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 deletions.
12 changes: 8 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
# Changelog

## 1.0.6

- native: Fix reexport output

## 1.0.5

- lexer: Support reexport extends
```js
var foo = require("foo");
foo.bar = true;
module.exports = foo;
// outputed named exports: [ "bar", ...(foo.namedExports) ]
var lib = require("lib");
lib.bar = true;
module.exports = lib;
// output:
// { exports: [ "bar" ], reexports: [ "lib" ] }
```
- lexer: Support `var foo = exports; foo.bar = true` pattern
- lexer: Support `var foo = exports.foo = ...` pattern
Expand Down
19 changes: 10 additions & 9 deletions wasm/index.mjs
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
import { initSync, parse as __wbg_parse } from "./pkg/cjs-module-lexer.js";
const wasmPath = "./pkg/cjs-module-lexer_bg.wasm";

let wasm;
const wasmPath = "./pkg/cjs-module-lexer_bg.wasm";
const wasmUrl = new URL(wasmPath, import.meta.url);

if (globalThis.process || globalThis.Deno || globalThis.Bun) {
const { readFileSync } = await import("node:fs");
const url = new URL(wasmPath, import.meta.url);
const wasmData = readFileSync(url.pathname);
const wasmData = readFileSync(wasmUrl.pathname);
wasm = await WebAssembly.compile(wasmData);
} else {
const url = new URL(wasmPath, import.meta.url);
const pkgPrefix = "/@esm.sh/cjs-module-lexer@";
if (url.pathname.startsWith(pkgPrefix)) {
const version = url.pathname.slice(pkgPrefix.length).split("/", 1)[0];
url.pathname = pkgPrefix + version + wasmPath.slice(1);
if (wasmUrl.pathname.startsWith(pkgPrefix)) {
// fix the wasm url for esm.sh usage
const version = wasmUrl.pathname.slice(pkgPrefix.length).split("/", 1)[0];
wasmUrl.pathname = pkgPrefix + version + wasmPath.slice(1);
}
const res = await fetch(url);
const res = await fetch(wasmUrl);
if (!res.ok) {
throw new Error(`failed to fetch wasm: ${res.statusText}`);
}
Expand All @@ -24,7 +25,7 @@ if (globalThis.process || globalThis.Deno || globalThis.Bun) {
initSync({ module: wasm });

/**
* parse the given code and return the exports and reexports
* parse the given cjs module and return the name exports and reexports
* @param {string} filename
* @param {string} code
* @param {{ nodeEnv?: 'development' | 'production', callMode?: boolean }} options
Expand Down
2 changes: 1 addition & 1 deletion wasm/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@esm.sh/cjs-module-lexer",
"description": "A lexer for detecting the `module.exports` of a CJS module.",
"version": "1.0.5",
"version": "1.0.6",
"type": "module",
"main": "index.mjs",
"scripts": {
Expand Down

0 comments on commit cf37250

Please sign in to comment.