From bcc6ce486de987d18092609c45d66d0dc163a18c Mon Sep 17 00:00:00 2001 From: Zephyr Lykos Date: Mon, 29 Apr 2024 01:32:07 +0800 Subject: [PATCH] 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 8ea767a6f4b7ce2a757586e0a5d8351bf1ef690b. --- build.js | 2 +- src/lexer.js | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/build.js b/build.js index c641d46..8db7738 100755 --- a/build.js +++ b/build.js @@ -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(); diff --git a/src/lexer.js b/src/lexer.js index c774d43..f3dc575 100755 --- a/src/lexer.js +++ b/src/lexer.js @@ -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") {