diff --git a/host/javascript/src/common/index.ts b/host/javascript/src/common/index.ts index 8f3e6bdf..78a5c031 100644 --- a/host/javascript/src/common/index.ts +++ b/host/javascript/src/common/index.ts @@ -1,5 +1,6 @@ export { App, AsyncMutex } from './app.js'; -export type { TextCoder, FileSystem, Timers, Network, WasiContext, Persistence } from './interfaces.js'; +export * from './error.js'; export { HandleMap } from './handle_map.js'; +export type { FileSystem, Network, Persistence, TextCoder, Timers, WasiContext } from './interfaces.js'; export { SecurityValuesMap } from './security.js'; -export * from './error.js'; +export * from './wasm.js'; diff --git a/host/javascript/src/common/wasm.ts b/host/javascript/src/common/wasm.ts new file mode 100644 index 00000000..ce3ad1b7 --- /dev/null +++ b/host/javascript/src/common/wasm.ts @@ -0,0 +1,3 @@ +export function corePath(): string { + return process.env.CORE_PATH ?? new URL('../assets/core-async.wasm', import.meta.url).pathname; +} diff --git a/host/javascript/src/node/index.test.ts b/host/javascript/src/node/index.test.ts index 04479bbc..06ccbc36 100644 --- a/host/javascript/src/node/index.test.ts +++ b/host/javascript/src/node/index.test.ts @@ -1,5 +1,3 @@ -import { jest } from '@jest/globals'; - import { Server, createServer as httpCreateServer } from 'node:http'; import { fileURLToPath } from 'node:url'; import { resolve as resolvePath, dirname } from 'node:path'; diff --git a/host/javascript/src/node/index.ts b/host/javascript/src/node/index.ts index a2afa74d..cf8120e7 100644 --- a/host/javascript/src/node/index.ts +++ b/host/javascript/src/node/index.ts @@ -17,11 +17,10 @@ import { Persistence } from '../common/index.js'; import { fetchErrorToHostError, systemErrorToWasiError } from './error.js'; -import { loadCoreFile } from './wasm.js'; +import { corePath } from '../common/wasm.js'; export { PerformError, UnexpectedError, ValidationError } from '../common/index.js'; export { fetchErrorToHostError, systemErrorToWasiError } from './error.js'; -export { corePath, loadCoreFile } from './wasm.js'; const ASSETS_FOLDER = 'superface'; @@ -223,7 +222,7 @@ class InternalClient { } await this.app.loadCore( - await loadCoreFile() + await fs.readFile(corePath()) ); await this.app.init(new WASI({ env: process.env, version: 'preview1' } as any)); // TODO: node typings do not include version https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/node/wasi.d.ts#L68-L110 diff --git a/host/javascript/src/node/wasm.ts b/host/javascript/src/node/wasm.ts deleted file mode 100644 index a0474a1f..00000000 --- a/host/javascript/src/node/wasm.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { readFile } from 'node:fs/promises'; -import { createRequire } from 'node:module'; - -export function corePath(): string { - return process.env.CORE_PATH ?? createRequire(import.meta.url).resolve('../assets/core-async.wasm'); -} - -export async function loadCoreFile(): Promise { - return await readFile(corePath()); -}