Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 7b39ea1

Browse files
committed
Strip out typescript
1 parent 14c06e7 commit 7b39ea1

10 files changed

+34
-67
lines changed

bin/build.mjs renamed to bin/build.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import esbuild from "esbuild";
22
import url from "url";
3-
import wasmPlugin from "./wasmPlugin.mjs";
3+
import wasmPlugin from "./wasmPlugin.js";
44

5-
const entryPoint = url.fileURLToPath(new URL("../src/index.ts", import.meta.url));
5+
const entryPoint = url.fileURLToPath(new URL("../src/index", import.meta.url));
66
const outdir = url.fileURLToPath(new URL("../docs", import.meta.url));
77

88
const { metafile } = await esbuild.build({

bin/serve.mjs renamed to bin/serve.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import esbuild from "esbuild";
22
import url from "url";
3-
import wasmPlugin from "./wasmPlugin.mjs";
3+
import wasmPlugin from "./wasmPlugin.js";
44

5-
const entryPoint = url.fileURLToPath(new URL("../src/index.ts", import.meta.url));
5+
const entryPoint = url.fileURLToPath(new URL("../src/index", import.meta.url));
66
const outdir = url.fileURLToPath(new URL("../docs", import.meta.url));
77

88
const ctx = await esbuild.context({
File renamed without changes.

package.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
{
22
"license": "MIT",
3+
"type": "module",
34
"scripts": {
4-
"build": "node bin/build.mjs",
5-
"serve": "node bin/serve.mjs"
5+
"build": "node bin/build.js",
6+
"serve": "node bin/serve.js"
67
},
78
"dependencies": {
89
"@monaco-editor/loader": "^1.3.2",
@@ -13,8 +14,6 @@
1314
"ruby-head-wasm-wasi": "^0.6.0"
1415
},
1516
"devDependencies": {
16-
"@types/node": "^18.14.1",
17-
"@types/path-browserify": "^1.0.0",
1817
"esbuild": "^0.17.10",
1918
"monaco-editor": "^0.36.0"
2019
}
Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
1-
import { WASI } from "@wasmer/wasi";
2-
import { WasmFs } from "@wasmer/wasmfs";
3-
import path from "path-browserify";
4-
import { DefaultRubyVM } from "ruby-head-wasm-wasi/dist/browser.esm.js";
5-
6-
import load from "./app.wasm";
1+
import { DefaultRubyVM } from "ruby-head-wasm-wasi/dist/browser.esm";
2+
import app from "./app.wasm";
73

84
export default async function createRuby() {
9-
const { vm } = await DefaultRubyVM(await load())
5+
const { vm } = await DefaultRubyVM(await app());
106

117
// Once our virtual machine is booted, we're going to require the necessary
128
// files to make it work. I'm not sure why I need to explicitly require
@@ -23,38 +19,33 @@ export default async function createRuby() {
2319

2420
return {
2521
// A function that disassembles the YARV instructions for the given source.
26-
disasm(source: string) {
22+
disasm(source) {
2723
const jsonSource = JSON.stringify(JSON.stringify(source));
2824
const rubySource = `RubyVM::InstructionSequence.compile(JSON.parse(${jsonSource})).disasm`;
2925

3026
return vm.eval(rubySource).toString();
3127
},
32-
mermaid(source: string) {
28+
mermaid(source) {
3329
const jsonSource = JSON.stringify(JSON.stringify(source));
34-
const rubySource = `
35-
source = JSON.parse(${jsonSource})
36-
SyntaxTree.parse(source).to_mermaid
37-
`;
30+
const rubySource = `SyntaxTree.parse(JSON.parse(${jsonSource})).to_mermaid`;
3831

3932
return vm.eval(rubySource).toString();
4033
},
4134
// A function that calls through to the SyntaxTree.format function to get
4235
// the pretty-printed version of the source.
43-
format(source: string) {
36+
format(source) {
4437
const jsonSource = JSON.stringify(JSON.stringify(source));
4538
const rubySource = `SyntaxTree.format(JSON.parse(${jsonSource}))`;
4639

4740
return vm.eval(rubySource).toString();
4841
},
4942
// A function that calls through to PP to get the pretty-printed version of
5043
// the syntax tree.
51-
prettyPrint(source: string) {
44+
prettyPrint(source) {
5245
const jsonSource = JSON.stringify(JSON.stringify(source));
5346
const rubySource = `PP.pp(SyntaxTree.parse(JSON.parse(${jsonSource})), +"", 80)`;
5447

5548
return vm.eval(rubySource).toString();
5649
}
5750
};
5851
};
59-
60-
export type Ruby = Awaited<ReturnType<typeof createRuby>>;

src/index.ts renamed to src/index.js

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
import "./index.css";
22

3-
type SourceChangedEvent = { source: string };
4-
type DisplayChangedEvent = { kind: "prettyPrint" | "disasm" | "mermaid" };
5-
6-
Promise.all([
3+
await Promise.all([
74
// We're going to load the editor asynchronously so that we can get to
85
// first-paint faster. This works out nicely since we can use a textarea until
96
// this chunk is loaded.
107
import("./monacoLoader").then(async ({ default: loader }) => {
118
const monaco = await loader.init();
12-
const editor = document.getElementById("editor") as HTMLTextAreaElement;
9+
const editor = document.getElementById("editor");
1310
const newEditor = document.createElement("div");
1411
editor.replaceWith(newEditor);
1512

@@ -21,15 +18,15 @@ Promise.all([
2118
}
2219
});
2320
}),
24-
import("./mermaid-js"),
21+
import("./mermaid"),
2522
// We're going to load the Ruby VM chunk asynchronously because it is pretty
2623
// dang huge (> 40Mb). In the meantime the textarea that is holding the place
2724
// of the actual functional one is just going to display "Loading...".
2825
import("./createRuby").then(({ default: createRuby }) => createRuby())
29-
]).then(([editor, mermaidjs, ruby]) => {
26+
]).then(([editor, mermaid, ruby]) => {
3027
// First, grab a reference to the output element so that we can update it.
3128
// Then, set it initially to the output represented by the source.
32-
const output = document.getElementById("output") as HTMLTextAreaElement;
29+
const output = document.getElementById("output");
3330
output.value = ruby.prettyPrint(editor.getValue());
3431
output.disabled = false;
3532

@@ -38,14 +35,14 @@ Promise.all([
3835
let displayFunction = ruby.prettyPrint;
3936

4037
// Handle a custom event here for if the display option changed.
41-
output.addEventListener("display-changed", (event: CustomEvent<DisplayChangedEvent>) => {
38+
output.addEventListener("display-changed", (event) => {
4239
displayFunction = ruby[event.detail.kind];
4340

4441
try {
4542
let source = displayFunction(editor.getValue());
4643

4744
if (event.detail.kind === 'mermaid') {
48-
mermaidjs.render(() => {
45+
mermaid.render(() => {
4946
output.setAttribute("style", "display: none;");
5047

5148
return source;
@@ -54,7 +51,7 @@ Promise.all([
5451
output.value = source;
5552
output.setAttribute("style", "");
5653

57-
mermaidjs.reset();
54+
mermaid.reset();
5855
}
5956
} catch (error) {
6057
// For now, just ignoring the error. Eventually I'd like to make this mark
@@ -66,33 +63,33 @@ Promise.all([
6663
// event information.
6764
const toggles = document.getElementsByClassName("toggles")[0];
6865

69-
toggles.querySelector("select").addEventListener('change', (e) => {
70-
output.dispatchEvent(new CustomEvent<DisplayChangedEvent>("display-changed", {
71-
detail: { kind: e.target.value as DisplayChangedEvent["kind"] }
66+
toggles.querySelector("select").addEventListener('change', (event) => {
67+
output.dispatchEvent(new CustomEvent("display-changed", {
68+
detail: { kind: event.target.value }
7269
}));
7370
});
7471

7572
// We're going to handle updates to the source through a custom event. This
7673
// turns out to be faster than handling the change event directly on the
7774
// editor since it blocks updates to the UI until the event handled returns.
78-
output.addEventListener("source-changed", (event: CustomEvent<SourceChangedEvent>) => {
75+
output.addEventListener("source-changed", (event) => {
7976
// We may want to add some throttle here to avoid to much rerendering in our Graph
80-
output.dispatchEvent(new CustomEvent<DisplayChangedEvent>("display-changed", {
81-
detail: { kind: toggles.querySelector('select').value as DisplayChangedEvent["kind"] }
77+
output.dispatchEvent(new CustomEvent("display-changed", {
78+
detail: { kind: toggles.querySelector('select').value }
8279
}));
8380
});
8481

8582
// Attach to the editor and dispatch custom source-changed events whenever the
8683
// value is updated in the editor.
8784
editor.onDidChangeModelContent(() => {
88-
output.dispatchEvent(new CustomEvent<SourceChangedEvent>("source-changed", {
85+
output.dispatchEvent(new CustomEvent("source-changed", {
8986
detail: { source: editor.getValue() }
9087
}));
9188
});
9289

9390
// Attach to the format button to update the source whenever the button is
9491
// clicked.
95-
const format = document.getElementById("format") as HTMLButtonElement;
92+
const format = document.getElementById("format");
9693
format.disabled = false;
9794

9895
format.addEventListener("click", () => {

src/mermaid-js.ts renamed to src/mermaid.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@ import mermaidjs from "mermaid";
22

33
const getCleanContainer = () => {
44
const div = document.querySelector("#graph-container");
5-
6-
div.innerHTML = '';
7-
5+
div.innerHTML = "";
86
return div;
97
}
108

11-
const render = (fn: Function) => {
9+
const render = (fn) => {
1210
let container = getCleanContainer();
1311

1412
container.setAttribute("style", "display: block;");
File renamed without changes.

tsconfig.json

Lines changed: 0 additions & 13 deletions
This file was deleted.

yarn.lock

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -238,16 +238,11 @@
238238
resolved "https://registry.yarnpkg.com/@types/minimatch/-/minimatch-5.1.2.tgz#07508b45797cb81ec3f273011b054cd0755eddca"
239239
integrity sha512-K0VQKziLUWkVKiRVrx4a40iPaxTUefQmjtkQofBkYRcoaaL/8rhwDWww9qWbrgicNOgnpIsMxyNIUM4+n6dUIA==
240240

241-
"@types/node@*", "@types/node@^18.14.1":
241+
"@types/node@*":
242242
version "18.14.1"
243243
resolved "https://registry.yarnpkg.com/@types/node/-/node-18.14.1.tgz#90dad8476f1e42797c49d6f8b69aaf9f876fc69f"
244244
integrity sha512-QH+37Qds3E0eDlReeboBxfHbX9omAcBCXEzswCu6jySP642jiM3cYSIkU/REqwhCUqXdonHFuBfJDiAJxMNhaQ==
245245

246-
"@types/path-browserify@^1.0.0":
247-
version "1.0.0"
248-
resolved "https://registry.yarnpkg.com/@types/path-browserify/-/path-browserify-1.0.0.tgz#294ec6e88b6b0d340a3897b7120e5b393f16690e"
249-
integrity sha512-XMCcyhSvxcch8b7rZAtFAaierBYdeHXVvg2iYnxOV0MCQHmPuRRmGZPFDRzPayxcGiiSL1Te9UIO+f3cuj0tfw==
250-
251246
"@types/shelljs@^0.8.11":
252247
version "0.8.11"
253248
resolved "https://registry.yarnpkg.com/@types/shelljs/-/shelljs-0.8.11.tgz#17a5696c825974e96828e96e89585d685646fcb8"

0 commit comments

Comments
 (0)