Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JS SDK Beta #1

Merged
merged 45 commits into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
aa35788
feat: bring code over from extism/browser
mhmd-azeez Aug 20, 2023
67b1cd7
broken
mhmd-azeez Aug 20, 2023
e36bc5c
broken
mhmd-azeez Aug 20, 2023
978f6e0
nodejs is working
mhmd-azeez Aug 21, 2023
26960c2
browser works too
mhmd-azeez Aug 21, 2023
7fadb19
bring back PluginOptions, cleanup
mhmd-azeez Aug 22, 2023
4a1013a
more cleanup
mhmd-azeez Aug 22, 2023
f3d9c2f
make deno work too
mhmd-azeez Aug 22, 2023
9a9c6b6
add deno to build command
mhmd-azeez Aug 22, 2023
d7bda3a
moar cleanup
mhmd-azeez Aug 23, 2023
fe2c1cb
moar cleanup x2
mhmd-azeez Aug 23, 2023
182e537
remove old index.html
mhmd-azeez Aug 23, 2023
fa5f394
docs: add bun example
mhmd-azeez Aug 23, 2023
358e022
use iife pattern for browser
mhmd-azeez Aug 23, 2023
795b565
we don't bundle deno
mhmd-azeez Aug 23, 2023
ed7e555
moar cleanup
mhmd-azeez Aug 23, 2023
2ab5901
fix deno example
mhmd-azeez Aug 23, 2023
843a4e9
bring back browser esm and make the example html nicer
mhmd-azeez Aug 24, 2023
dde2f0f
implement http
mhmd-azeez Aug 27, 2023
450c6d3
check for allowed hosts in http
mhmd-azeez Aug 27, 2023
aa50eb2
test: add test suite for nodejs
mhmd-azeez Aug 28, 2023
e5a557b
add tests for deno
mhmd-azeez Aug 28, 2023
7ed8ec5
hashing
mhmd-azeez Aug 29, 2023
1ec7e56
fix build errors
mhmd-azeez Aug 29, 2023
3056173
cleanup
mhmd-azeez Aug 29, 2023
4130e8b
add more tests
mhmd-azeez Aug 29, 2023
abdfbf9
initialize guest runtime
mhmd-azeez Aug 29, 2023
36cc83d
call haskell plugin multiple times
mhmd-azeez Aug 29, 2023
857a03f
bring tests over to deno
mhmd-azeez Aug 30, 2023
18c41bc
make sure deno SDK can run Haskell plugins
mhmd-azeez Aug 31, 2023
f161f74
make sure file system access works
mhmd-azeez Aug 31, 2023
7ed6838
embed runtime
mhmd-azeez Sep 6, 2023
dc3dfd0
chore: restructure things a bit and add docs
mhmd-azeez Sep 7, 2023
07d839f
fix: return commandInit in wasiRuntime instead of haskellInit
mhmd-azeez Sep 10, 2023
3ea0980
feat: restructure the project to have one package.json for both brows…
mhmd-azeez Sep 10, 2023
39b4332
fix: address PR feedback
mhmd-azeez Sep 12, 2023
1cd02e7
ci: add an action to build & test on main and PRs
mhmd-azeez Sep 12, 2023
4ac0524
ci: run npm install before building
mhmd-azeez Sep 12, 2023
c93b39f
ci: fix dir separators
mhmd-azeez Sep 12, 2023
6a4b66b
ci: don't use npm cache
mhmd-azeez Sep 12, 2023
3a18e1a
chore: update extism kernel
zshipko Sep 19, 2023
50cb262
Merge pull request #2 from extism/update-kernel
zshipko Sep 19, 2023
4365ff0
chore: update wasm kernel
mhmd-azeez Sep 19, 2023
cab26c2
fix: make sure we copy the memory before setting it to var
mhmd-azeez Sep 20, 2023
4fd8864
fix: make sure getBytes copies the buffer
mhmd-azeez Sep 20, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: JS CI

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:

build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
rust:
- stable

steps:
- uses: actions/checkout@v3

- name: Setup Node.js environment
uses: actions/[email protected]

- name: Setup Deno
uses: denoland/[email protected]

- name: NPM install with caching
run: npm install

- name: Build
run: npm run build

- name: Node Test
run: npm run test

- name: Deno Test
run: deno test -A ./tests/mod.test.ts
130 changes: 130 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Snowpack dependency directory (https://snowpack.dev/)
web_modules/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional stylelint cache
.stylelintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variable files
.env
.env.development.local
.env.test.local
.env.production.local
.env.local

# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache

# Next.js build output
.next
out

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# vuepress v2.x temp and cache directory
.temp
.cache

# Docusaurus cache and generated files
.docusaurus

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port

# Stores VSCode versions used for testing VSCode extensions
.vscode-test

# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*
5 changes: 5 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"printWidth": 120,
"trailingComma": "all",
"singleQuote": true
}
10 changes: 10 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"deno.enable": true,
"deno.lint": true,
"deno.unstable": true,
"deno.enablePaths": [
"./src/deno/mod.ts",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This path may need to change with the latest update to directory structure

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry, can you elaborate on this? I think the path is correct

"./examples/deno.ts",
"./tests/mod.test.ts"
]
}
28 changes: 0 additions & 28 deletions LICENSE

This file was deleted.

32 changes: 32 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
.PHONY: test

prepare:
npm install

build:
npm run build

test: prepare
npm run test
deno test -A .\tests\mod.test.ts

clean:
echo "No clean implemented"

publish: clean prepare build
npm publish

format:
npx prettier --write src

lint:
npx prettier --check src

docs:
npx typedoc --out doc src

show-docs: docs
open doc/index.html

update-kernel:
node update-kernel.js
20 changes: 19 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,19 @@
# Extism JavaScript SDK
# Extism JS SDK

## Run Examples:

```
npm run build

node --experimental-wasi-unstable-preview1 ./examples/node.js wasm/config.wasm

deno run -A ./examples/deno.js ./wasm/config.wasm

bun run ./examples/node.js wasm/config.wasm
```

## Update `extism-kernel.wasm`:
We are shipping an embedded kernel in base64 form in plugin.ts. To update it, you can run these commands:
```
make update-kernel
```
29 changes: 29 additions & 0 deletions build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const { build } = require("esbuild");
const { peerDependencies } = require('./package.json')
const fs = require('fs')

const sharedConfig = {
bundle: true,
minify: true,
drop: [], // preseve debugger statements
external: Object.keys(peerDependencies || {}),
};

// NodeJS CSJ
build({
...sharedConfig,
entryPoints: ["src/node/index.ts"],
platform: 'node', // for CJS
outfile: "dist/node/index.js",
external: [ './src/mod.ts', "sync-fetch", "child_process" ]
});

// Browser ESM
build({
...sharedConfig,
entryPoints: ["src/browser/index.ts"],
outfile: "dist/browser/index.mjs",
platform: 'neutral',
external: [ './src/mod.ts', "sync-fetch", "child_process" ],
format: "esm",
});
12 changes: 0 additions & 12 deletions example.deno.js

This file was deleted.

18 changes: 0 additions & 18 deletions example.node.js

This file was deleted.

22 changes: 22 additions & 0 deletions examples/deno.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { ExtismPlugin, ExtismPluginOptions } from '../src/deno/mod.ts'

async function main() {
const filename = Deno.args[0] || "wasm/hello.wasm";
const funcname = Deno.args[1] || "run_test";
const input = Deno.args[2] || "this is a test";
const wasm = {
path: filename
}

const options = new ExtismPluginOptions()
.withConfig("thing", "testing")
.withWasi();

const plugin = await ExtismPlugin.new(wasm, options);

const res = await plugin.call(funcname, new TextEncoder().encode(input));
const s = new TextDecoder().decode(res.buffer);
console.log(s)
}

main();
Loading