Skip to content

Commit bcc6ce4

Browse files
authored
tests: fix loading wasm when targeting external deps (#94)
* tests: fix loading wasm when targeting external deps * Revert "fix: cannot resolve path when build with EXTERNAL_PATH (#93)" This reverts commit 8ea767a.
1 parent 5f974d8 commit bcc6ce4

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

build.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ if (EXTERNAL_PATH) {
3737
let lazy;
3838
async function init () {
3939
if (!lazy) {
40-
lazy = await import(require('node:url').pathToFileURL(require('node:module').createRequire('${path.join(EXTERNAL_PATH, 'dist/lexer.js')}').resolve('./lexer.mjs')));
40+
lazy = await import(require('node:url').pathToFileURL(require('node:module').createRequire('${EXTERNAL_PATH}/dist/lexer.js').resolve('./lexer.mjs')));
4141
}
4242
module.exports = lazy;
4343
return lazy.init();

src/lexer.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,12 @@ function copyLE (src, outBuf16) {
9191
}
9292

9393
const loadWasm = (typeof EXTERNAL_PATH === "string" && (async () => {
94-
return (await import('node:fs/promises')).readFile(EXTERNAL_PATH);
94+
return (await import("node:fs/promises"))
95+
.readFile(
96+
(await import("node:url")).fileURLToPath(
97+
import.meta.resolve("../lib/lexer.wasm")
98+
)
99+
);
95100
})) || (async () => {
96101
const binary = WASM_BINARY
97102
if (typeof window !== "undefined" && typeof atob === "function") {

0 commit comments

Comments
 (0)