Skip to content

Commit

Permalink
feat: backport bundling improvements
Browse files Browse the repository at this point in the history
* pod and now also nodejs_comlink use a slightly different way to import the WASM asset, so backport that in here as well as it seems more portable
* ensure all imports and reexports in javascript_common have a file extension so that they corrently work with bundlers
  • Loading branch information
TheEdward162 committed Jan 30, 2024
1 parent 1baaafb commit 811808c
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 12 deletions.
2 changes: 1 addition & 1 deletion packages/javascript_common/src/error.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export * from './lib/error';
export * from './lib/error.js';

export abstract class BaseError extends Error {
constructor(name: string, message: string) {
Expand Down
1 change: 0 additions & 1 deletion packages/javascript_common/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@ export * from './error.js';
export type { FileSystem, Network, Persistence, TextCoder, Timers, WasiContext } from './interfaces.js';
export type { SecurityValuesMap } from './security.js';
export { HandleMap, AsyncMutex } from './lib/index.js';
export { corePathURL } from './wasm.js';
2 changes: 1 addition & 1 deletion packages/javascript_common/src/interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export * from './lib/interfaces';
export * from './lib/interfaces.js';
export interface FileSystem {
/** Return true if the file exists (can be `stat`ed). */
exists(path: string): Promise<boolean>;
Expand Down
5 changes: 0 additions & 5 deletions packages/javascript_common/src/wasm.ts

This file was deleted.

9 changes: 5 additions & 4 deletions packages/nodejs_host/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import fs, { FileHandle } from 'node:fs/promises';
import { createRequire } from 'node:module';
import { resolve as resolvePath } from 'node:path';
import process from 'node:process';
import { fileURLToPath } from 'node:url';
import { WASI } from 'node:wasi';

import { AsyncMutex } from './common/lib/index.js';
Expand All @@ -17,12 +16,14 @@ import {
Timers,
UnexpectedError,
WasiErrno,
WasiError,
corePathURL
WasiError
} from './common/index.js';
import { fetchErrorToHostError, systemErrorToWasiError } from './error.js';

const pkg = createRequire(import.meta.url)('../package.json');
function corePathURL(): URL {
return new URL('../assets/core-async.wasm', import.meta.url);
}

export { PerformError, UnexpectedError, ValidationError } from './common/index.js';
export { fetchErrorToHostError, systemErrorToWasiError } from './error.js';
Expand Down Expand Up @@ -264,7 +265,7 @@ class InternalClient {
}

await this.app.loadCore(
await fs.readFile(process.env.CORE_PATH ?? fileURLToPath(corePathURL()))
await fs.readFile(process.env.CORE_PATH ?? corePathURL().pathname)
);
await this.app.init(new WASI({
env: {
Expand Down

0 comments on commit 811808c

Please sign in to comment.