Skip to content

Commit

Permalink
change replace on read instead of write
Browse files Browse the repository at this point in the history
  • Loading branch information
d-roak committed Aug 19, 2024
1 parent 34f0258 commit 9152a82
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
6 changes: 6 additions & 0 deletions examples/chat/vite.config.mts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { defineConfig } from 'vite'
import { nodePolyfills } from 'vite-plugin-node-polyfills'
import path from 'path'

export default defineConfig({
build: {
Expand All @@ -12,6 +13,11 @@ export default defineConfig({
},
}),
],
resolve: {
alias: {
"@topology-foundation/crdt": path.join(__dirname, "../../", "node_modules/@topology-foundation/crdt")
}
},
optimizeDeps: {
esbuildOptions: {
target: 'esnext'
Expand Down
18 changes: 7 additions & 11 deletions packages/object/src/wasm/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,23 @@ import asc from "assemblyscript/asc";

export async function compileWasm(path: string) {
console.log("Compiling", path);
const { error } = await asc.main([
const { error, stderr } = await asc.main([
path,
"--bindings=esm",
"--outFile=/tmp/dist.wasm",
], {
readFile: (filename: string) =>
fs.existsSync(filename) ? fs.readFileSync(filename, "utf8") : null,
writeFile: (filename: string, contents: string | Uint8Array, baseDir: string) => {
if (typeof contents === "string") {
contents.replace('@topology-foundation/crdt', '@topology-foundation/crdt/src/index.asc')
} else {
contents = new TextDecoder().decode(contents)
contents.replace('@topology-foundation/crdt', '@topology-foundation/crdt/src/index.asc')
}
return fs.writeFileSync(filename, contents)
readFile: (filename: string) => {
if (!fs.existsSync(filename)) return null
return fs.readFileSync(filename, "utf8").replace('@topology-foundation/crdt', '@topology-foundation/crdt/src/index.asc')
},
writeFile: (filename: string, contents: string | Uint8Array, baseDir: string) =>
fs.writeFileSync(filename, contents),
listFiles: () => []
});

if (error) {
console.log("Compilation failed: " + error);
console.log(stderr.toString());
return new Uint8Array();
} else {
// read tmp file into uint8array
Expand Down

0 comments on commit 9152a82

Please sign in to comment.