Skip to content

Commit

Permalink
tests: fix loading wasm when targeting external deps (#94)
Browse files Browse the repository at this point in the history
* tests: fix loading wasm when targeting external deps

* Revert "fix: cannot resolve path when build with EXTERNAL_PATH (#93)"

This reverts commit 8ea767a.
  • Loading branch information
mochaaP authored Apr 28, 2024
1 parent 5f974d8 commit bcc6ce4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion build.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ if (EXTERNAL_PATH) {
let lazy;
async function init () {
if (!lazy) {
lazy = await import(require('node:url').pathToFileURL(require('node:module').createRequire('${path.join(EXTERNAL_PATH, 'dist/lexer.js')}').resolve('./lexer.mjs')));
lazy = await import(require('node:url').pathToFileURL(require('node:module').createRequire('${EXTERNAL_PATH}/dist/lexer.js').resolve('./lexer.mjs')));
}
module.exports = lazy;
return lazy.init();
Expand Down
7 changes: 6 additions & 1 deletion src/lexer.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,12 @@ function copyLE (src, outBuf16) {
}

const loadWasm = (typeof EXTERNAL_PATH === "string" && (async () => {
return (await import('node:fs/promises')).readFile(EXTERNAL_PATH);
return (await import("node:fs/promises"))
.readFile(
(await import("node:url")).fileURLToPath(
import.meta.resolve("../lib/lexer.wasm")
)
);
})) || (async () => {
const binary = WASM_BINARY
if (typeof window !== "undefined" && typeof atob === "function") {
Expand Down

0 comments on commit bcc6ce4

Please sign in to comment.