Skip to content

Commit

Permalink
node: preserve modules
Browse files Browse the repository at this point in the history
  • Loading branch information
pulsejet committed Mar 8, 2025
1 parent e410336 commit 1ec4152
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/node/headless.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ async function loadGoEnvironment() {
globalThis.performance ??= performance;
globalThis.crypto ??= crypto as any;

// @ts-expect-error - go wasm module
await import('./wasm_exec.js');
const wasm_exec = './wasm_exec.js';
await import(wasm_exec);
console.log('Go environment loaded');
}

Expand Down
2 changes: 1 addition & 1 deletion src/services/ndn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ class NDNService {
// @ts-expect-error - node.js dynamic import
const fs = await import('fs');
// @ts-expect-error - relative path to wasm
const buffer = fs.readFileSync(import.meta.dirname + '/main.wasm');
const buffer = fs.readFileSync(import.meta.dirname + '/../../main.wasm');
result = await WebAssembly.instantiate(buffer, go.importObject);
}

Expand Down
5 changes: 4 additions & 1 deletion vite.config.headless.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@ export default defineConfig({
},
minify: false,
rollupOptions: {
output: {
preserveModules: true,
preserveModulesRoot: 'src/node',
},
external: [
'./wasm_exec.js',
/node:.*/,
'fs',
'fs/promises',
Expand Down

0 comments on commit 1ec4152

Please sign in to comment.