Skip to content

Commit

Permalink
Merge pull request #104 from superfaceai/feat/use_url_to_wasm
Browse files Browse the repository at this point in the history
Use URL to get path to wasm asset
  • Loading branch information
freaz authored Sep 7, 2023
2 parents e1dafbc + 8428a54 commit 1201f66
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 17 deletions.
5 changes: 3 additions & 2 deletions host/javascript/src/common/index.ts
Original file line number Diff line number Diff line change
@@ -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';
3 changes: 3 additions & 0 deletions host/javascript/src/common/wasm.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function corePath(): string {
return process.env.CORE_PATH ?? new URL('../assets/core-async.wasm', import.meta.url).pathname;
}
2 changes: 0 additions & 2 deletions host/javascript/src/node/index.test.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
5 changes: 2 additions & 3 deletions host/javascript/src/node/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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

Expand Down
10 changes: 0 additions & 10 deletions host/javascript/src/node/wasm.ts

This file was deleted.

0 comments on commit 1201f66

Please sign in to comment.