Skip to content

Commit

Permalink
Merge pull request #36 from Phala-Network/feat-run-phatjs
Browse files Browse the repository at this point in the history
Using phatjs wasm in async runtime
  • Loading branch information
Leechael committed Feb 28, 2024
2 parents 99d6407 + f795fe5 commit 1c4c89e
Show file tree
Hide file tree
Showing 9 changed files with 691 additions and 467 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@
/tmp
node_modules
oclif.manifest.json
.npmrc
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
}
},
"scripts": {
"build": "shx rm -rf dist && tsc -b",
"build": "shx rm -rf dist && tsc -b && shx cp src/lib/phatjs/phatjs_bg.*.wasm dist/lib/phatjs/",
"lint": "tsc --noEmit",
"test": "mocha --forbid-only \"test/**/*.test.ts\""
},
Expand Down
6 changes: 2 additions & 4 deletions src/commands/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default class Run extends Command {
}),
}

public async run(): Promise<{ output: string }> {
public async run() {
const {
flags: { scriptArgs = [], experimentalAsync },
args: { script },
Expand All @@ -39,8 +39,6 @@ export default class Run extends Command {
isAsync: experimentalAsync,
})
this.log(JSON.stringify({ output }))
return {
output,
}
process.exit(0)
}
}
36 changes: 36 additions & 0 deletions src/lib/phatjs/phatjs.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/* tslint:disable */
/* eslint-disable */
/**
*/
export function start(): void;
/**
* Get the version of the runtime.
* @returns {Promise<string>}
*/
export function version(): Promise<string>;
/**
* Run a script.
*
* # Arguments
* - `args` - a list of arguments to pass to the runtime, including the script name and arguments.
*
* # Example
*
* ```js
* const result = await run(["phatjs", "-c", "console.log(scriptArgs)", "--", "Hello, world!"]);
* console.log(result);
* ```
* @param {(string)[]} args
* @returns {Promise<any>}
*/
export function run(args: (string)[]): Promise<any>;
/**
* Set a hook for the runtime.
*
* # Available hooks
* - `fetch` - a function that takes a `Request` object and returns a `Response` object.
* @param {string} hook_name
* @param {any} hook_value
*/
export function setHook(hook_name: string, hook_value: any): void;
export function init(): void;
Loading

0 comments on commit 1c4c89e

Please sign in to comment.