From b9047e13e65050576d2bae5305ea9f846ebae4e7 Mon Sep 17 00:00:00 2001 From: Matt Johnson-Pint Date: Mon, 25 Mar 2024 08:39:12 -0700 Subject: [PATCH 1/2] Expose binaryen instance on transform --- cli/index.d.ts | 8 ++++++-- cli/index.js | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/cli/index.d.ts b/cli/index.d.ts index 16e070529e..58c7fb4ef6 100644 --- a/cli/index.d.ts +++ b/cli/index.d.ts @@ -240,7 +240,8 @@ export function createMemoryStream(fn?: (chunk: Uint8Array | string) => void): M /** Compatible TypeScript compiler options for syntax highlighting etc. */ export const tscOptions: Record; -import { Program, Parser, Module } from "../src"; +import binaryen from "../lib/binaryen"; +import { Program, Parser } from "../src"; /** Compiler transform base class. */ export abstract class Transform { @@ -248,6 +249,9 @@ export abstract class Transform { /** Program reference. */ readonly program: Program; + /** Binaryen reference. */ + readonly binaryen: typeof binaryen; + /** Base directory. */ readonly baseDir: string; @@ -276,5 +280,5 @@ export abstract class Transform { afterInitialize?(program: Program): void | Promise; /** Called when compilation is complete, before the module is being validated. */ - afterCompile?(module: Module): void | Promise; + afterCompile?(module: binaryen.Module): void | Promise; } diff --git a/cli/index.js b/cli/index.js index 91634a8c01..b7b4a836e5 100644 --- a/cli/index.js +++ b/cli/index.js @@ -450,6 +450,7 @@ export async function main(argv, options) { if (typeof transform === "function") { Object.assign(transform.prototype, { program, + binaryen, baseDir, stdout, stderr, From ae2ccdf0a59aefac4c9e29958a74ffbd92c884dc Mon Sep 17 00:00:00 2001 From: Matt Johnson-Pint Date: Mon, 25 Mar 2024 09:01:54 -0700 Subject: [PATCH 2/2] Fix invalid import in generated output --- scripts/build-dts.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/scripts/build-dts.js b/scripts/build-dts.js index 07215c9be9..0493075824 100644 --- a/scripts/build-dts.js +++ b/scripts/build-dts.js @@ -373,9 +373,13 @@ export function generateCli() { prefix, stdout, resolveModuleImport: ({ importedModuleId, currentModuleId }) => { - return currentModuleId == "cli/index" && importedModuleId == "../src" - ? prefix + "/src/index" - : null; + if (currentModuleId == "cli/index" && importedModuleId == "../src") + return prefix + "/src/index"; + + if (importedModuleId == "binaryen") + return "binaryen"; + + return null; }, });