Skip to content

Commit

Permalink
enable jsr build
Browse files Browse the repository at this point in the history
Thanks to @sigmaSd for getting this off the ground!

I vendored the last version of deno-snapshot_preview1 available (v0.206.0),
added very basic type definitions for `Deno`, and sprinkled in some `as <type>`
annotations into the codebase.

I've also merged the "jsr publish" into the release workflow.
  • Loading branch information
sigmaSd authored and chrisdickinson committed Apr 26, 2024
1 parent fa50f98 commit b7786e3
Show file tree
Hide file tree
Showing 8 changed files with 1,866 additions and 20 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ jobs:
build:
runs-on: ubuntu-latest

permissions:
contents: read
id-token: write

steps:
- uses: actions/checkout@v3

Expand All @@ -31,12 +35,18 @@ jobs:
tag="${{ github.ref }}"
tag="${tag/refs\/tags\/v/}"
npm version $tag --no-git-tag-version --no-commit-hooks
jsr="$(<jsr.json jq '. |.version = $version' --arg version "$tag")"
echo "$jsr" >jsr.json
- name: npm publish @extism/extism
uses: JS-DevTools/[email protected]
with:
token: ${{ secrets.NPM_TOKEN }}

- name: jsr publish @extism/extism
run: |
npx jsr publish
- name: Update package name
run: |
pkg="$(<package.json jq '.name = "extism"')"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const createPlugin = require("@extism/extism")
import createPlugin from '@extism/extism';

// Deno
import createPlugin from 'https://raw.githubusercontent.com/extism/js-sdk/main/src/mod.ts';
import createPlugin from "jsr:@extism/extism";
```

## Creating A Plug-in
Expand Down
7 changes: 7 additions & 0 deletions jsr.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "@extism/extism",
"version": "0.0.0-replaced-by-ci",
"exports": "./src/mod.ts",
"include": ["./src/**/*.ts", "LICENSE", "README.md", "types", "tsconfig.json"],
"exclude": ["./src/mod.test.ts"]
}
22 changes: 13 additions & 9 deletions src/call-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class Block {
view: DataView;
local: boolean;

get byteLength() {
get byteLength(): number {
return this.buffer.byteLength;
}

Expand Down Expand Up @@ -199,12 +199,12 @@ export class CallContext {
block?.view.setBigUint64(Number(offset), n, true);
},

input_offset: () => {
input_offset: (): bigint => {
const blockIdx = this.#stack[this.#stack.length - 1][0];
return Block.indexToAddress(blockIdx || 0);
},

input_length: () => {
input_length: (): bigint => {
return BigInt(this.#input?.byteLength ?? 0);
},

Expand Down Expand Up @@ -269,7 +269,7 @@ export class CallContext {
return this.#vars.has(key) ? Block.indexToAddress(this.#vars.get(key) as number) : 0n;
},

var_set: (addr: bigint, valueaddr: bigint) => {
var_set: (addr: bigint, valueaddr: bigint): 0n | undefined => {
const item = this.read(addr);

if (item === null) {
Expand Down Expand Up @@ -307,9 +307,10 @@ export class CallContext {
const blockIdx = Block.addressToIndex(addr);
const block = this.#blocks[blockIdx];
if (!block) {
return this.#logger.error(
this.#logger.error(
`failed to log(warn): bad block reference in addr 0x${addr.toString(16).padStart(64, '0')}`,
);
return;
}
const text = this.#decoder.decode(block.buffer);
this.#logger.warn(text);
Expand All @@ -319,9 +320,10 @@ export class CallContext {
const blockIdx = Block.addressToIndex(addr);
const block = this.#blocks[blockIdx];
if (!block) {
return this.#logger.error(
this.#logger.error(
`failed to log(info): bad block reference in addr 0x${addr.toString(16).padStart(64, '0')}`,
);
return;
}
const text = this.#decoder.decode(block.buffer);
this.#logger.info(text);
Expand All @@ -331,9 +333,10 @@ export class CallContext {
const blockIdx = Block.addressToIndex(addr);
const block = this.#blocks[blockIdx];
if (!block) {
return this.#logger.error(
this.#logger.error(
`failed to log(debug): bad block reference in addr 0x${addr.toString(16).padStart(64, '0')}`,
);
return;
}
const text = this.#decoder.decode(block.buffer);
this.#logger.debug(text);
Expand All @@ -343,9 +346,10 @@ export class CallContext {
const blockIdx = Block.addressToIndex(addr);
const block = this.#blocks[blockIdx];
if (!block) {
return this.#logger.error(
this.#logger.error(
`failed to log(error): bad block reference in addr 0x${addr.toString(16).padStart(64, '0')}`,
);
return;
}
const text = this.#decoder.decode(block.buffer);
this.#logger.error(text);
Expand Down Expand Up @@ -414,7 +418,7 @@ export class CallContext {
}

/** @hidden */
[STORE](input?: string | Uint8Array) {
[STORE](input?: string | Uint8Array): number | null {
if (!input) {
return null;
}
Expand Down
2 changes: 1 addition & 1 deletion src/polyfills/deno-minimatch.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import minimatch from 'https://deno.land/x/minimatch@v3.0.4/index.js';
import { minimatch } from "npm:minimatch@9.0.4";

export function matches(text: string, pattern: string): boolean {
return minimatch(text, pattern);
Expand Down
Loading

0 comments on commit b7786e3

Please sign in to comment.