mirror of
https://github.com/DustinBrett/daedalOS.git
synced 2026-01-15 12:15:02 +00:00
Switch to wasi-js
This commit is contained in:
@@ -1,27 +1,20 @@
|
||||
import { config } from "components/apps/Terminal/config";
|
||||
import type { LocalEcho } from "components/apps/Terminal/types";
|
||||
import type { WASI as IWASI } from "node_modules/@wasmer/wasi/dist/pkg/wasmer_wasi_js";
|
||||
import WASI from "wasi-js";
|
||||
import bindings from "wasi-js/dist/bindings/browser";
|
||||
|
||||
type WASIError = Error & {
|
||||
code: number;
|
||||
};
|
||||
|
||||
interface IWasmerWasi {
|
||||
WASI: typeof IWASI;
|
||||
init: () => Promise<WebAssembly.Exports>;
|
||||
}
|
||||
|
||||
const loadWapm = async (
|
||||
commandArgs: string[],
|
||||
localEcho: LocalEcho
|
||||
): Promise<void> => {
|
||||
const { fetchCommandFromWAPM } = await import("@wasmer/wasm-terminal");
|
||||
const { lowerI64Imports } = await import("@wasmer/wasm-transformer");
|
||||
const { init, WASI } = (await import("@wasmer/wasi")) as IWasmerWasi;
|
||||
|
||||
try {
|
||||
await init();
|
||||
|
||||
const wasmBinary = await fetchCommandFromWAPM({ args: commandArgs });
|
||||
|
||||
if (
|
||||
@@ -37,10 +30,13 @@ const loadWapm = async (
|
||||
const wasmModule = await WebAssembly.compile(moduleResponse);
|
||||
const wasi = new WASI({
|
||||
args: commandArgs,
|
||||
bindings,
|
||||
env: {
|
||||
COLUMNS: config.cols?.toString(),
|
||||
LINES: config.rows?.toString(),
|
||||
},
|
||||
sendStderr: (buffer: Uint8Array) => localEcho?.print(buffer.toString()),
|
||||
sendStdout: (buffer: Uint8Array) => localEcho?.print(buffer.toString()),
|
||||
});
|
||||
const instance = await WebAssembly.instantiate(
|
||||
wasmModule,
|
||||
@@ -48,7 +44,6 @@ const loadWapm = async (
|
||||
);
|
||||
|
||||
wasi.start(instance);
|
||||
localEcho?.print(wasi.getStdoutString());
|
||||
}
|
||||
} catch (error) {
|
||||
const { message } = error as WASIError;
|
||||
|
||||
@@ -33,7 +33,6 @@ const nextConfig = {
|
||||
reactStrictMode: true,
|
||||
swcMinify: !isProduction,
|
||||
webpack: (config) => {
|
||||
config.externals.push("wasmer_wasi_js_bg.wasm");
|
||||
config.plugins.push(
|
||||
new webpack.NormalModuleReplacementPlugin(/node:/, (resource) => {
|
||||
const mod = resource.request.replace(/^node:/, "");
|
||||
|
||||
@@ -46,10 +46,8 @@
|
||||
"@monaco-editor/react": "^4.4.6",
|
||||
"@panzoom/panzoom": "^4.5.1",
|
||||
"@prettier/plugin-xml": "^2.2.0",
|
||||
"@wasmer/wasi": "1.1.2",
|
||||
"@wasmer/wasm-terminal": "^0.12.0",
|
||||
"@wasmer/wasm-transformer": "^0.12.0",
|
||||
"@wasmer/wasmfs": "^0.12.0",
|
||||
"ani-cursor": "^0.0.5",
|
||||
"butterchurn-presets": "^3.0.0-beta.4",
|
||||
"fflate": "^0.7.4",
|
||||
@@ -71,7 +69,8 @@
|
||||
"react-rnd": "^10.3.7",
|
||||
"resedit": "^1.6.0",
|
||||
"styled-components": "^5.3.6",
|
||||
"utif": "https://github.com/photopea/UTIF.js"
|
||||
"utif": "https://github.com/photopea/UTIF.js",
|
||||
"wasi-js": "^1.7.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"7z-wasm": "^1.0.1",
|
||||
|
||||
44
yarn.lock
44
yarn.lock
@@ -331,6 +331,13 @@
|
||||
resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39"
|
||||
integrity sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==
|
||||
|
||||
"@cowasm/memfs@^3.5.1":
|
||||
version "3.5.1"
|
||||
resolved "https://registry.yarnpkg.com/@cowasm/memfs/-/memfs-3.5.1.tgz#8846077117ff300fe3edc41e8657184c01437c62"
|
||||
integrity sha512-TSz00K+BdLxAYFQvwHmKgM/eAK6h9OYSQhPTcv/9XSyOF0Q90EtMkJvtwirwAXunfTsZw8R9YMu1UU213ooVKw==
|
||||
dependencies:
|
||||
fs-monkey "^1.0.3"
|
||||
|
||||
"@csstools/selector-specificity@^2.0.2":
|
||||
version "2.0.2"
|
||||
resolved "https://registry.yarnpkg.com/@csstools/selector-specificity/-/selector-specificity-2.0.2.tgz#1bfafe4b7ed0f3e4105837e056e0a89b108ebe36"
|
||||
@@ -1249,16 +1256,18 @@
|
||||
"@typescript-eslint/types" "5.44.0"
|
||||
eslint-visitor-keys "^3.3.0"
|
||||
|
||||
"@wapython/unionfs@^4.5.7":
|
||||
version "4.5.7"
|
||||
resolved "https://registry.yarnpkg.com/@wapython/unionfs/-/unionfs-4.5.7.tgz#bdc35e34534709702cf125ac3e96d7a67a761af3"
|
||||
integrity sha512-7809nAVelP9TqXCq5c1yCwymPreTXrK4n4q/zxOlQOIIz4PNmoQmIKiLnwkKk39GDnLmP1MvP9ZkBDyXCCmTfg==
|
||||
dependencies:
|
||||
fs-monkey "^1.0.0"
|
||||
|
||||
"@wasmer/io-devices@^0.12.0":
|
||||
version "0.12.0"
|
||||
resolved "https://registry.yarnpkg.com/@wasmer/io-devices/-/io-devices-0.12.0.tgz#c9e10dba0b3eeff6aab8857d5b84a9bafde82fc8"
|
||||
integrity sha512-CiuhJPnNVZp2G1V5UHKSWMb2bIsiGn+78u9h3/3CNUNdzQ9W9ALGSXxzeieaSEUa3QL7HQC1DiE+IN2mXUv6Dw==
|
||||
|
||||
"@wasmer/wasi@1.1.2":
|
||||
version "1.1.2"
|
||||
resolved "https://registry.yarnpkg.com/@wasmer/wasi/-/wasi-1.1.2.tgz#c99faf45bfc7ff464dfd4bec661320c4073c268b"
|
||||
integrity sha512-c1h7L2qPviV6n+ny2fYboFPFL4RbvCqYckDPfpWMUOqX+QIt83EnMnYfeWNwWbUAIku087qj3cBJzcqY+HbHxw==
|
||||
|
||||
"@wasmer/wasi@^0.12.0":
|
||||
version "0.12.0"
|
||||
resolved "https://registry.yarnpkg.com/@wasmer/wasi/-/wasi-0.12.0.tgz#89c7c5e5ba58f7dfae4e323359346639c4ec382a"
|
||||
@@ -3034,7 +3043,7 @@ fb-watchman@^2.0.0:
|
||||
dependencies:
|
||||
bser "2.1.1"
|
||||
|
||||
fflate@^0.7.4:
|
||||
fflate@^0.7.3, fflate@^0.7.4:
|
||||
version "0.7.4"
|
||||
resolved "https://registry.yarnpkg.com/fflate/-/fflate-0.7.4.tgz#61587e5d958fdabb5a9368a302c25363f4f69f50"
|
||||
integrity sha512-5u2V/CDW15QM1XbbgS+0DfPxVB+jUKhWEKuuFuHncbk3tEEqzmoXL+2KyOFuKGqOnmdIy0/davWF1CkuwtibCw==
|
||||
@@ -3164,6 +3173,11 @@ fs-monkey@0.3.3:
|
||||
resolved "https://registry.yarnpkg.com/fs-monkey/-/fs-monkey-0.3.3.tgz#7960bb2b1fa2653731b9d0e2e84812a7e8b3664a"
|
||||
integrity sha512-FNUvuTAJ3CqCQb5ELn+qCbGR/Zllhf2HtwsdAtBi59s1WeCjKMT81fHcSu7dwIskqGVK+MmOrb7VOBlq3/SItw==
|
||||
|
||||
fs-monkey@^1.0.0, fs-monkey@^1.0.3:
|
||||
version "1.0.3"
|
||||
resolved "https://registry.yarnpkg.com/fs-monkey/-/fs-monkey-1.0.3.tgz#ae3ac92d53bb328efe0e9a1d9541f6ad8d48e2d3"
|
||||
integrity sha512-cybjIfiiE+pTWicSCLFHSrXZ6EilF30oh91FDP9S2B051prEa7QWfrVTQm10/dDpswBDXZugPa1Ogu8Yh+HV0Q==
|
||||
|
||||
fs.realpath@^1.0.0:
|
||||
version "1.0.0"
|
||||
resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f"
|
||||
@@ -6725,6 +6739,11 @@ typedarray-to-buffer@^3.1.5:
|
||||
dependencies:
|
||||
is-typedarray "^1.0.0"
|
||||
|
||||
typedarray-to-buffer@^4.0.0:
|
||||
version "4.0.0"
|
||||
resolved "https://registry.yarnpkg.com/typedarray-to-buffer/-/typedarray-to-buffer-4.0.0.tgz#cdd2933c61dd3f5f02eda5d012d441f95bfeb50a"
|
||||
integrity sha512-6dOYeZfS3O9RtRD1caom0sMxgK59b27+IwoNy8RDPsmslSGOyU+mpTamlaIW7aNKi90ZQZ9DFaZL3YRoiSCULQ==
|
||||
|
||||
typescript@^4.9.3:
|
||||
version "4.9.3"
|
||||
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.9.3.tgz#3aea307c1746b8c384435d8ac36b8a2e580d85db"
|
||||
@@ -6832,6 +6851,19 @@ walker@^1.0.8:
|
||||
dependencies:
|
||||
makeerror "1.0.12"
|
||||
|
||||
wasi-js@^1.7.2:
|
||||
version "1.7.2"
|
||||
resolved "https://registry.yarnpkg.com/wasi-js/-/wasi-js-1.7.2.tgz#9b3d647d51fd65d020fd696eac702f3b50d3368d"
|
||||
integrity sha512-UJHCQTng8sP/PMVZ4CCHtAZjTaMF1Xs3fT/nZYWDNmBgL9KA8z/s7cGrHKiKd1A0TOr0DU/8/2ylMYqIKrP9tA==
|
||||
dependencies:
|
||||
"@cowasm/memfs" "^3.5.1"
|
||||
"@wapython/unionfs" "^4.5.7"
|
||||
debug "^4.3.4"
|
||||
fflate "^0.7.3"
|
||||
path-browserify "^1.0.0"
|
||||
randomfill "^1.0.4"
|
||||
typedarray-to-buffer "^4.0.0"
|
||||
|
||||
wasm-feature-detect@^1.2.2:
|
||||
version "1.3.0"
|
||||
resolved "https://registry.yarnpkg.com/wasm-feature-detect/-/wasm-feature-detect-1.3.0.tgz#fb3fc5dd4a1ba950a429be843daad67fe048bc42"
|
||||
|
||||
Reference in New Issue
Block a user