Skip to content

Commit

Permalink
Refactor import statements, add support for binary files, and update …
Browse files Browse the repository at this point in the history
…dependencies
  • Loading branch information
geeknees committed May 1, 2024
1 parent f4f271f commit 4b54032
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 22 deletions.
10 changes: 10 additions & 0 deletions assets/assets.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// binary
declare module "*.wasm" {
const value: Uint8Array;
export default value;
}

declare module "*.png" {
const value: Uint8Array;
export default value;
}
Binary file added assets/ruby.wasm
Binary file not shown.
7 changes: 5 additions & 2 deletions esbuild.config.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import esbuild from "esbuild";
import process from "process";
import builtins from "builtin-modules";
import { wasmLoader } from "esbuild-plugin-wasm";

const banner = `/*
THIS IS A GENERATED/BUNDLED FILE BY ESBUILD
Expand All @@ -12,6 +11,10 @@ if you want to view the source, please visit the github repository of this plugi
const prod = process.argv[2] === "production";

const context = await esbuild.context({
loader: {
".wasm": "binary",
".png": "binary",
},
banner: {
js: banner,
},
Expand Down Expand Up @@ -39,7 +42,7 @@ const context = await esbuild.context({
sourcemap: prod ? false : "inline",
treeShaking: true,
outfile: "main.js",
plugins: [wasmLoader()],
plugins: [],
});

if (prod) {
Expand Down
7 changes: 2 additions & 5 deletions main.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { App, Editor, MarkdownView, Modal, Plugin } from "obsidian";

import { DefaultRubyVM } from "@ruby/wasm-wasi/dist/browser";
import rubyWASM from "./assets/ruby.wasm";

export default class RubyWasmPlugin extends Plugin {
// Function to check if inside code block
Expand All @@ -24,10 +24,7 @@ export default class RubyWasmPlugin extends Plugin {
};

async onload() {
const response = await fetch(
"https://cdn.jsdelivr.net/npm/@ruby/3.3-wasm-wasi@2.5.1/dist/ruby+stdlib.wasm"
);
const module = await WebAssembly.compileStreaming(response);
const module = await WebAssembly.compile(rubyWASM);
const { vm } = await DefaultRubyVM(module);

// This adds a simple command that can be triggered anywhere
Expand Down
14 changes: 0 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
"@typescript-eslint/parser": "5.29.0",
"builtin-modules": "3.3.0",
"esbuild": "0.17.3",
"esbuild-plugin-wasm": "^1.1.0",
"obsidian": "latest",
"tslib": "2.4.0",
"typescript": "4.7.4"
Expand Down

0 comments on commit 4b54032

Please sign in to comment.