Skip to content

Commit

Permalink
Test fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderson1993 committed Feb 5, 2025
1 parent fabf448 commit b406a41
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 7 deletions.
3 changes: 2 additions & 1 deletion app/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { exitHandler, snapshot } from "@thorium/.server/init/exitHandler";
import { serveStatic } from "hono/bun";
import { Hono } from "hono";
import { createBunWebSocket } from "hono/bun";
import type { ServerWebSocket } from "bun";
import { readdir } from "node:fs/promises";
import { vanity } from "@thorium/utils/.server/vanity";
// @ts-expect-error
Expand All @@ -19,6 +18,8 @@ import httpsCert from "./.server/server.cert" with { type: "file" };
import httpsKey from "./.server/server.key" with { type: "file" };
import { getMimeType } from "hono/utils/mime";
import { getClientBundleFile } from "@thorium/utils/.server/getClientBundleFile";
import type { ServerWebSocket } from "bun";

const { upgradeWebSocket, websocket } = createBunWebSocket<ServerWebSocket>();

console.info(`Starting Thorium...`);
Expand Down
19 changes: 15 additions & 4 deletions patches/@thorium-sim%[email protected]
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
diff --git a/node_modules/@thorium-sim/rapier3d-node/.bun-tag-a46edb8bb6b58a91 b/.bun-tag-a46edb8bb6b58a91
new file mode 100644
index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
diff --git a/dist/rapier_wasm3d.js b/dist/rapier_wasm3d.js
index f506e35499d4d419a211ac6c82e1753198dca1b4..1a63573071b632114a7b490f53f2f383543b7ea8 100644
index f506e35499d4d419a211ac6c82e1753198dca1b4..967275b1e864dcfa2fb67f4794ced9b9e11642ff 100644
--- a/dist/rapier_wasm3d.js
+++ b/dist/rapier_wasm3d.js
@@ -5797,7 +5797,7 @@ module.exports.__wbindgen_memory = function() {
@@ -5797,8 +5797,14 @@ module.exports.__wbindgen_memory = function() {
return addHeapObject(ret);
};

-const path = require('path').join(__dirname, 'rapier_wasm3d_bg.wasm');
+import path from './rapier_wasm3d_bg.wasm' with { type: "file" }
const bytes = require('fs').readFileSync(path);
-const bytes = require('fs').readFileSync(path);
+let bytes = new ArrayBuffer();
+if (process.env.NODE_ENV === "production") {
+ const {embeddedFiles, peek} = require('bun')
+ bytes = (peek(embeddedFiles.find(f => f.name === "rapier_wasm3d_bg.wasm").arrayBuffer()))
+} else {
+ const path = require('path').join(__dirname, 'rapier_wasm3d_bg.wasm');
+ bytes = require('fs').readFileSync(path);
+}

const wasmModule = new WebAssembly.Module(bytes);
const wasmInstance = new WebAssembly.Instance(wasmModule, imports);
4 changes: 2 additions & 2 deletions scripts/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const arch = (process.env.BUILD_ARCH ||
`${targetArch}-${targetPlatform}`) as keyof typeof platformMap;

// We have to run this next command using a shell since the --compile flag doesn't work with the Bun API.
const command = `bun build --minify --define "process.env.NODE_ENV='production'" --target=TARGET --sourcemap --outfile ./src-tauri/binaries/thoriumNovaServer-ARCH --compile ./app/server.ts`;
const command = `bun build --minify --define "process.env.NODE_ENV='production'" --asset-naming="[name].[ext]" --target=TARGET --sourcemap --outfile ./src-tauri/binaries/thoriumNovaServer-ARCH --compile ./app/server.ts ./node_modules/@thorium-sim/rapier3d-node/dist/rapier_wasm3d_bg.wasm`;
const target = platformMap[arch];
if (!target) {
throw new Error(
Expand All @@ -78,4 +78,4 @@ await new Promise<void>((res, rej) =>
);

console.info("Cleaning up");
await rm(path.join("./build"), { force: true, recursive: true });
// await rm(path.join("./build"), { force: true, recursive: true });
5 changes: 5 additions & 0 deletions vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,10 @@ export default defineConfig({
alias: {
"../../../build/defaultPlugin.plug": "./stub.js",
},
server: {
deps: {
external: ["@thorium-sim/rapier3d-node"],
},
},
},
});

0 comments on commit b406a41

Please sign in to comment.