Skip to content

Commit 1c5a507

Browse files
committed
fix: relative imports for wasm module
1 parent 6928c03 commit 1c5a507

File tree

5 files changed

+16
-21
lines changed

5 files changed

+16
-21
lines changed

deno.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@inspatial/cloud",
3-
"version": "0.2.0",
3+
"version": "0.2.1",
44
"license": "Apache-2.0",
55
"exports": {
66
".": "./mod.ts",
@@ -10,6 +10,8 @@
1010
"publish": {
1111
"include": [
1212
"src/",
13+
"src/**/*.wasm",
14+
"src/**/*.data",
1315
"examples/",
1416
"extensions/",
1517
"types.ts",

src/orm/db/postgres/in-pg/in-pg-client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export class InPGClient extends PostgresClient {
1616
const pgDataRoot = normalizePath(`${inRoot}/pgdata`);
1717
this.wasmPath = `${thisDir}/src/inpg.wasm`;
1818

19-
this.#inPg = new InPG(this.wasmPath, {
19+
this.#inPg = new InPG({
2020
env: {
2121
PGDATA: pgDataRoot,
2222
MODE: "REACT",

src/orm/db/postgres/in-pg/in-pg.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import { ExitStatus } from "./src/utils.ts";
66
import { WasmLoader } from "./src/wasmLoader.ts";
77
import type { InPgOptions } from "./types.ts";
88

9+
const fileData = Deno.readFileSync(import.meta.dirname + `/src/inpg.data`);
10+
const wasmData = Deno.readFileSync(import.meta.dirname + `/src/inpg.wasm`);
911
export class InPG implements Deno.Conn {
1012
pgMem: PGMem;
1113
wasmLoader;
@@ -77,7 +79,6 @@ export class InPG implements Deno.Conn {
7779
return envs;
7880
}
7981
constructor(
80-
wasmPath: string,
8182
options: InPgOptions,
8283
) {
8384
this.#onStdErr = options.onStderr || ((m) => console.error(m));
@@ -88,11 +89,11 @@ export class InPG implements Deno.Conn {
8889
this.#bufferData = new Uint8Array(0);
8990
this.runtimeInitialized = false;
9091
this.pgMem = new PGMem(this);
91-
this.wasmLoader = new WasmLoader(this, wasmPath);
92+
this.wasmLoader = new WasmLoader(this, wasmData);
9293
this.readEmAsmArgsArray = [];
9394
this.fileManager = new FileManager(this, {
9495
debug: options?.debug,
95-
pgFilesDir: options.pgFilesDir,
96+
fileData,
9697
});
9798
this.sysCalls = new SysCalls(this);
9899

src/orm/db/postgres/in-pg/src/fileManager/in-pg-files.ts

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { type InPG, ni } from "../../in-pg.ts";
22
import type { DevType, PGFile, PGFileMem } from "../../types.ts";
33
import { ERRNO_CODES } from "../constants.ts";
44
import { normalizePath } from "../convert.ts";
5-
65
import type { PGMem } from "../pgMem.ts";
76
import { MemFile, PostgresFile } from "./pg-file.ts";
87

@@ -19,18 +18,16 @@ export class FileManager {
1918
tmpMap: Map<string, string>;
2019
lastDebugMessage: string;
2120
messageCount: number = 0;
22-
pgFilesDir: string;
2321
isWindows: boolean = Deno.build.os === "windows";
2422
tmDir!: string;
2523
postgresFiles: Map<string, PostgresFile>;
2624
constructor(inPg: InPG, options: {
2725
debug?: boolean;
28-
pgFilesDir: string;
26+
fileData: Uint8Array;
2927
}) {
3028
this.lastDebugMessage = "";
3129
this.dirReadOffsets = new Map();
3230
this.debug = options?.debug;
33-
this.pgFilesDir = options.pgFilesDir;
3431
this.#currFD = 100;
3532
this.inPg = inPg;
3633
this.mem = inPg.pgMem;
@@ -47,11 +44,7 @@ export class FileManager {
4744
truncate: true,
4845
});
4946
}
50-
this.init();
51-
}
52-
53-
init() {
54-
this.loadPostgresFiles();
47+
this.loadPostgresFiles(options.fileData);
5548
this.setupStdStreams();
5649
}
5750
clearTmp() {
@@ -419,8 +412,7 @@ export class FileManager {
419412
}
420413
return null;
421414
}
422-
loadPostgresFiles() {
423-
const data = Deno.readFileSync(`${this.pgFilesDir}/src/inpg.data`);
415+
loadPostgresFiles(data: Uint8Array) {
424416
let offset = 0;
425417
const view = new DataView(data.buffer, data.byteOffset, data.byteLength);
426418

src/orm/db/postgres/in-pg/src/wasmLoader.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ class LDSO {
2727
}
2828
}
2929
export class WasmLoader {
30-
wasmPath: string;
3130
wasmImports: WasmImports;
3231
wasmTable;
3332
GOT: Record<string, any>;
@@ -38,14 +37,14 @@ export class WasmLoader {
3837
wasmExports: WebAssembly.Exports;
3938
freeTableIndexes: Array<number>;
4039
inPg: InPG;
40+
wasmData: Uint8Array;
4141

4242
get pgMem(): PGMem {
4343
return this.inPg.pgMem;
4444
}
45-
constructor(inPg: InPG, wasmPath: string) {
45+
constructor(inPg: InPG, wasmData: Uint8Array) {
4646
this.GOT = {};
4747
this.inPg = inPg;
48-
this.wasmPath = wasmPath;
4948
this.wasmExports = {};
5049
this.wasmImports = {};
5150
this.LDSO = new LDSO();
@@ -55,6 +54,7 @@ export class WasmLoader {
5554
initial: this.inPg.tableSize,
5655
element: "anyfunc",
5756
});
57+
this.wasmData = wasmData;
5858

5959
const GOT = this.GOT;
6060
const currentModuleWeakSymbols = this.currentModuleWeakSymbols;
@@ -92,8 +92,8 @@ export class WasmLoader {
9292
GOTHandler,
9393
) as WebAssembly.ModuleImports,
9494
};
95-
const buffer = await Deno.readFile(this.wasmPath);
96-
const result = await WebAssembly.instantiate(buffer, info);
95+
96+
const result = await WebAssembly.instantiate(this.wasmData, info);
9797
this.wasmExports = result.instance.exports;
9898

9999
for (var [sym, exp] of Object.entries(result.instance.exports)) {

0 commit comments

Comments
 (0)