From c44d5925a4787f8a6fff5e5f82bcaac1812c5d6b Mon Sep 17 00:00:00 2001 From: abearxiong Date: Sat, 19 Apr 2025 15:19:48 +0800 Subject: [PATCH] temp --- .gitignore | 4 +++- assembly/index.ts | 3 +++ deno-wasm/deno.json | 33 +++++++++++++++++++++++++++++++++ deno-wasm/src/index.ts | 5 +++++ deno.json | 3 +-- package.json | 4 +++- pnpm-lock.yaml | 24 ++++++++++++++++++++++++ 7 files changed, 72 insertions(+), 4 deletions(-) create mode 100644 assembly/index.ts create mode 100644 deno-wasm/deno.json create mode 100644 deno-wasm/src/index.ts diff --git a/.gitignore b/.gitignore index f1495cd..ba1ea26 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,6 @@ node_modules .env* -!.env*example \ No newline at end of file +!.env*example + +dist \ No newline at end of file diff --git a/assembly/index.ts b/assembly/index.ts new file mode 100644 index 0000000..7b003e5 --- /dev/null +++ b/assembly/index.ts @@ -0,0 +1,3 @@ +export function add(a: i32, b: i32): i32 { + return a + b; +} \ No newline at end of file diff --git a/deno-wasm/deno.json b/deno-wasm/deno.json new file mode 100644 index 0000000..5a29d5b --- /dev/null +++ b/deno-wasm/deno.json @@ -0,0 +1,33 @@ +{ + "compilerOptions": { + "lib": [ + "deno.window" + ] + }, + "tasks": { + "start": "deno run --allow-net deno-server/server.ts", + "build:wasm": "deno compile --target wasm -- --outfile dist/index.wasm src/index.ts" + }, + "imports": { + "http/": "https://deno.land/std@0.220.1/http/" + }, + "lint": { + "include": [ + "./src/**/*.ts", + "index.ts" + ], + "exclude": [ + "./types" + ], + "rules": { + "tags": [ + "recommended" + ], + "include": [], + "exclude": [ + "require-await", + "no-explicit-any" + ] + } + } +} \ No newline at end of file diff --git a/deno-wasm/src/index.ts b/deno-wasm/src/index.ts new file mode 100644 index 0000000..23a64bc --- /dev/null +++ b/deno-wasm/src/index.ts @@ -0,0 +1,5 @@ +// export const add = (a: number, b: number) => a + b; + +import { add } from "../../dist/index.wasm"; + +console.log(add(1, 2)); diff --git a/deno.json b/deno.json index 1ac4fa9..66e1274 100644 --- a/deno.json +++ b/deno.json @@ -25,8 +25,7 @@ "include": [], "exclude": [ "require-await", - "no-explicit-any", - "unused-vars" + "no-explicit-any" ] } } diff --git a/package.json b/package.json index 35f0ab2..45ad857 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,8 @@ "description": "", "main": "index.js", "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + "test": "echo \"Error: no test specified\" && exit 1", + "assembly:build": "asc assembly/index.ts --target release --outFile dist/index.wasm" }, "keywords": [], "author": "abearxiong (https://www.xiongxiao.me)", @@ -14,6 +15,7 @@ "devDependencies": { "@kevisual/router": "^0.0.13", "@kevisual/use-config": "^1.0.10", + "assemblyscript": "^0.27.36", "pino": "^9.6.0", "pino-pretty": "^13.0.0" } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 04d4939..9247acb 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -14,6 +14,9 @@ importers: '@kevisual/use-config': specifier: ^1.0.10 version: 1.0.10(dotenv@16.5.0) + assemblyscript: + specifier: ^0.27.36 + version: 0.27.36 pino: specifier: ^9.6.0 version: 9.6.0 @@ -40,10 +43,19 @@ packages: '@types/node@22.14.1': resolution: {integrity: sha512-u0HuPQwe/dHrItgHHpmw3N2fYCR6x4ivMNbPHRkBVP4CvN+kiRrKHWk3i8tXiO/joPwXLMYvF9TTF0eqgHIuOw==} + assemblyscript@0.27.36: + resolution: {integrity: sha512-1qX2zf6p7l/mNYv8r21jC/Yft7kX7XKR3xUHw41zvV4xad5lyC8w7jZiwZBGoy64VKZLc+bTDJDWi8Kb70YrHA==} + engines: {node: '>=18', npm: '>=10'} + hasBin: true + atomic-sleep@1.0.0: resolution: {integrity: sha512-kNOjDqAh7px0XWNI+4QbzoiR/nTkHAWNud2uvnJquD1/x5a7EQZMJT0AczqK0Qn67oY/TTQ1LbUKajZpp3I9tQ==} engines: {node: '>=8.0.0'} + binaryen@116.0.0-nightly.20240114: + resolution: {integrity: sha512-0GZrojJnuhoe+hiwji7QFaL3tBlJoA+KFUN7ouYSDGZLSo9CKM8swQX8n/UcbR0d1VuZKU+nhogNzv423JEu5A==} + hasBin: true + colorette@2.0.20: resolution: {integrity: sha512-IfEDxwoWIjkeXL1eXcDiow4UbKjhLdq6/EuSVR9GMN7KVH3r9gQ83e73hsz1Nd1T3ijd5xv1wcWRYO+D6kCI2w==} @@ -77,6 +89,9 @@ packages: resolution: {integrity: sha512-34wB/Y7MW7bzjKRjUKTa46I2Z7eV62Rkhva+KkopW7Qvv/OSWBqvkSY7vusOPrNuZcUG3tApvdVgNB8POj3SPw==} engines: {node: '>=10'} + long@5.3.2: + resolution: {integrity: sha512-mNAgZ1GmyNhD7AuqnTG3/VQ26o760+ZYBPKjPvugO8+nLbYfX6TVpJPseBvopbdY+qpZ/lKUnmEc1LeZYS3QAA==} + minimist@1.2.8: resolution: {integrity: sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==} @@ -177,8 +192,15 @@ snapshots: dependencies: undici-types: 6.21.0 + assemblyscript@0.27.36: + dependencies: + binaryen: 116.0.0-nightly.20240114 + long: 5.3.2 + atomic-sleep@1.0.0: {} + binaryen@116.0.0-nightly.20240114: {} + colorette@2.0.20: {} dateformat@4.6.3: {} @@ -201,6 +223,8 @@ snapshots: joycon@3.1.1: {} + long@5.3.2: {} + minimist@1.2.8: {} node-forge@1.3.1: {}