diff --git a/README.md b/README.md index 6659b85b..392d2d78 100644 --- a/README.md +++ b/README.md @@ -182,6 +182,7 @@ export function componentize(jsSource: string, opts: { engine?: string, preview2Adapter?: string, disableFeatures?: ('stdio' | 'random' | 'clocks' | 'http')[], + runtimeArgs?: string, }): { component: Uint8Array, imports: string[] diff --git a/src/componentize.js b/src/componentize.js index 17b4acb6..bc29860d 100644 --- a/src/componentize.js +++ b/src/componentize.js @@ -39,13 +39,14 @@ export async function componentize(jsSource, witWorld, opts) { witWorld = opts?.witWorld; } opts = opts || {}; - const { + let { sourceName = 'source.js', preview2Adapter = preview1AdapterReactorPath(), witPath, worldName, disableFeatures = [], enableFeatures = [], + runtimeArgs, aotCache = fileURLToPath( new URL(`../lib/starlingmonkey_ics.wevalcache`, import.meta.url) ), @@ -222,6 +223,10 @@ export async function componentize(jsSource, witWorld, opts) { console.log('--- Wizer Env ---'); console.log(env); } + + let sourcePath = maybeWindowsPath(join(sourceDir, sourceName.slice(0, -3) + '.bindings.js')); + runtimeArgs = runtimeArgs ? `${runtimeArgs} ${sourcePath}` : sourcePath; + if (opts.enableAot) { // Determine the weval bin path, possibly using a pre-downloaded version let wevalBin; @@ -247,9 +252,7 @@ export async function componentize(jsSource, witWorld, opts) { { stdio: [null, stdout, stderr], env, - input: maybeWindowsPath( - join(sourceDir, sourceName.slice(0, -3) + '.bindings.js') - ), + input: runtimeArgs, shell: true, encoding: 'utf-8', } @@ -284,9 +287,7 @@ export async function componentize(jsSource, witWorld, opts) { { stdio: [null, stdout, stderr], env, - input: maybeWindowsPath( - join(sourceDir, sourceName.slice(0, -3) + '.bindings.js') - ), + input: runtimeArgs, shell: true, encoding: 'utf-8', } diff --git a/types.d.ts b/types.d.ts index cb391a75..2d2d9201 100644 --- a/types.d.ts +++ b/types.d.ts @@ -53,6 +53,11 @@ interface ComponentizeOptions { * To pass only a subset, provide an object with the desired variables */ env?: boolean | Record, + /** + * Runtime arguments to provide to the StarlingMonkey engine initialization + * (see https://github.com/bytecodealliance/StarlingMonkey/blob/main/include/config-parser.h) + */ + runtimeArgs?: string, } /**