Skip to content

Commit

Permalink
Revert "fix: cannot resolve path when build with EXTERNAL_PATH (#93)"
Browse files Browse the repository at this point in the history
This reverts commit 8ea767a.
  • Loading branch information
guybedford committed Apr 28, 2024
1 parent 6663bca commit 1de1228
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
5 changes: 2 additions & 3 deletions build.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const fs = require('fs');
const { buildSync } = require('esbuild');
const path = require('path/posix')

const { EXTERNAL_PATH } = process.env;
const MINIFY = !EXTERNAL_PATH;
Expand All @@ -23,7 +22,7 @@ buildSync({
},
define: EXTERNAL_PATH ? {
WASM_BINARY: 'undefined',
EXTERNAL_PATH: `'${path.join(EXTERNAL_PATH, 'lib/lexer.wasm')}'`,
EXTERNAL_PATH: `'${EXTERNAL_PATH}'`,
} : {
WASM_BINARY: `'${wasmBuffer.toString('base64')}'`,
EXTERNAL_PATH: 'undefined'
Expand All @@ -37,7 +36,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
6 changes: 5 additions & 1 deletion src/lexer.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,11 @@ function copyLE (src, outBuf16) {
}

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

0 comments on commit 1de1228

Please sign in to comment.