Skip to content

Commit 1de1228

Browse files
committed
Revert "fix: cannot resolve path when build with EXTERNAL_PATH (#93)"
This reverts commit 8ea767a.
1 parent 6663bca commit 1de1228

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

build.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
const fs = require('fs');
22
const { buildSync } = require('esbuild');
3-
const path = require('path/posix')
43

54
const { EXTERNAL_PATH } = process.env;
65
const MINIFY = !EXTERNAL_PATH;
@@ -23,7 +22,7 @@ buildSync({
2322
},
2423
define: EXTERNAL_PATH ? {
2524
WASM_BINARY: 'undefined',
26-
EXTERNAL_PATH: `'${path.join(EXTERNAL_PATH, 'lib/lexer.wasm')}'`,
25+
EXTERNAL_PATH: `'${EXTERNAL_PATH}'`,
2726
} : {
2827
WASM_BINARY: `'${wasmBuffer.toString('base64')}'`,
2928
EXTERNAL_PATH: 'undefined'
@@ -37,7 +36,7 @@ if (EXTERNAL_PATH) {
3736
let lazy;
3837
async function init () {
3938
if (!lazy) {
40-
lazy = await import(require('node:url').pathToFileURL(require('node:module').createRequire('${path.join(EXTERNAL_PATH, 'dist/lexer.js')}').resolve('./lexer.mjs')));
39+
lazy = await import(require('node:url').pathToFileURL(require('node:module').createRequire('${EXTERNAL_PATH}/dist/lexer.js').resolve('./lexer.mjs')));
4140
}
4241
module.exports = lazy;
4342
return lazy.init();

src/lexer.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,11 @@ 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+
const { readFile } = await import('node:fs/promises');
95+
const { fileURLToPath } = await import('node:url');
96+
return readFile(fileURLToPath(
97+
import.meta.resolve("undefined/dist/lexer.wasm")
98+
));
9599
})) || (async () => {
96100
const binary = WASM_BINARY
97101
if (typeof window !== "undefined" && typeof atob === "function") {

0 commit comments

Comments
 (0)