Skip to content

Commit 07f4131

Browse files
committed
wasm-lib: refresh assets script and switch tests to consolidated testcases.json (#10)
- add refresh_assets.sh to rebuild/copy only config-referenced .ocd2 files and testcases.json - convert wasm-lib tests to consume the new `{cases:[...]}` JSON format - update bundled .ocd2 dictionaries and testcases.json fixtures ---- * wasm-lib: refresh assets script and switch tests to consolidated testcases.json - add refresh_assets.sh to rebuild/copy only config-referenced .ocd2 files and testcases.json - convert wasm-lib tests to consume the new `{cases:[...]}` JSON format - update bundled .ocd2 dictionaries and testcases.json fixtures * Rebuild the wasm-lib and update the documentations
1 parent 09d22ff commit 07f4131

15 files changed

Lines changed: 473 additions & 288 deletions

wasm-lib/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,3 +119,8 @@ wasm-lib/
119119
- Dictionaries are written under `/data/dict/` in the virtual FS; configs under `/data/config/`. Paths inside configs are rewritten automatically.
120120
- Memory grows on demand (`ALLOW_MEMORY_GROWTH=1`); no native dependencies needed.
121121
- Performance note: opencc-wasm focuses on fidelity and compatibility (uses official configs and `.ocd2`, matches Node OpenCC output 1:1). Raw throughput can be slower than pure JS implementations like `opencc-js`, but the WASM version guarantees full OpenCC behavior and config coverage.
122+
123+
## 0.2.0 changes
124+
- Conversion rules and bundled dictionaries are rebuilt from OpenCC commit [`36c7cbbc`](https://github.com/frankslin/OpenCC/commit/36c7cbbc9702d2a46a89ea7a55ff8ba5656455df). This aligns the WASM build with the upstream configs in that revision (including updated `.ocd2` data).
125+
- Output layout now mirrors the new `dist/` structure: ESM glue under `dist/esm/`, CJS glue under `dist/cjs/`, shared `opencc-wasm.wasm` at `dist/opencc-wasm.wasm`, and configs/dicts in `dist/data/`. Adjust your bundler/static hosting paths accordingly.
126+
- Tests are rewritten to use `node:test` with data-driven cases (`test/testcases.json`) instead of ad-hoc assertions, keeping coverage aligned with upstream OpenCC fixtures.

wasm-lib/data/dict/STPhrases.ocd2

17 Bytes
Binary file not shown.

wasm-lib/data/dict/TWPhrases.ocd2

33 Bytes
Binary file not shown.
49 Bytes
Binary file not shown.

wasm-lib/dist/cjs/index.cjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ let api = null;
2424

2525
async function getModule() {
2626
if (!modulePromise) {
27-
const wasmUrl = new URL("../opencc-wasm.cjs", BASE_URL);
27+
const wasmUrl = new URL("./opencc-wasm.cjs", import.meta.url || "file://" + __filename);
2828
const create = require(wasmUrl);
2929
modulePromise = create();
3030
}
17 Bytes
Binary file not shown.
33 Bytes
Binary file not shown.
49 Bytes
Binary file not shown.

wasm-lib/dist/esm/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,18 @@ async function getModule() {
4747
if (modulePromise) return modulePromise;
4848

4949
// 1) 先确定包根目录(一定要以 / 结尾)
50-
const pkgBase = new URL("../", import.meta.url);
50+
const pkgBase = new URL("./", import.meta.url);
5151
// 如果这段代码在 HTML inline script 里,没有 import.meta.url,那就用绝对路径:
5252
// const pkgBase = new URL("/vendor/opencc-wasm/", window.location.origin);
5353

54-
// 2) import glue
55-
const glueUrl = new URL("opencc-wasm.js", pkgBase);
54+
// 2) import glue (from build/ for testing/development)
55+
const glueUrl = new URL("./opencc-wasm.js", import.meta.url);
5656

5757
const { default: create } = await import(glueUrl.href);
5858

5959
// 3) locateFile 必须相对 pkgBase,而不是 glueUrl
6060
modulePromise = create({
61-
locateFile: (p) => new URL(p, pkgBase).href
61+
locateFile: (p) => new URL(`../${p}`, import.meta.url).href
6262
});
6363

6464
return modulePromise;

wasm-lib/dist/esm/opencc-wasm.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)