From 296272a5cc7c52678696c0282cf024a4ff9568c3 Mon Sep 17 00:00:00 2001 From: Sagar Seth Date: Fri, 28 Nov 2025 16:32:16 +0530 Subject: [PATCH 1/4] fix(react-sdk): ignore asyncapi-ui.min.js during transpilation to prevent Babel deoptimisation warning --- apps/react-sdk/src/transpiler/transpiler.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/react-sdk/src/transpiler/transpiler.ts b/apps/react-sdk/src/transpiler/transpiler.ts index 29d2a8cf31..422bc4d5bc 100644 --- a/apps/react-sdk/src/transpiler/transpiler.ts +++ b/apps/react-sdk/src/transpiler/transpiler.ts @@ -16,7 +16,8 @@ const ROOT_DIR = Path.resolve(__dirname, '../..'); * @param options any extra options that should be passed. */ export async function transpileFiles(directory: string, outputDir: string, options?: TranspileFilesOptions) { - const { files, dirs } = await getStatsInDir(directory); + let { files, dirs } = await getStatsInDir(directory); + files = files.filter(f => !f.endsWith("asyncapi-ui.min.js")); if (files.length) { /** * WHEN ADDING PLUGINS to transform the input keep in mind that From 4fe6f9a8c706d0b61d05916bf11926972aef88a7 Mon Sep 17 00:00:00 2001 From: Sagar Seth Date: Sun, 7 Dec 2025 11:53:01 +0530 Subject: [PATCH 2/4] fix: suppress Babel deoptimisation warnings unless debug flag is enabled --- apps/react-sdk/src/transpiler/transpiler.ts | 96 +++++++++++++-------- 1 file changed, 61 insertions(+), 35 deletions(-) diff --git a/apps/react-sdk/src/transpiler/transpiler.ts b/apps/react-sdk/src/transpiler/transpiler.ts index 422bc4d5bc..7b38168f3f 100644 --- a/apps/react-sdk/src/transpiler/transpiler.ts +++ b/apps/react-sdk/src/transpiler/transpiler.ts @@ -1,4 +1,5 @@ import Path from 'path'; +import log from 'loglevel'; import { rollup } from 'rollup'; import babel from '@rollup/plugin-babel'; @@ -16,9 +17,26 @@ const ROOT_DIR = Path.resolve(__dirname, '../..'); * @param options any extra options that should be passed. */ export async function transpileFiles(directory: string, outputDir: string, options?: TranspileFilesOptions) { - let { files, dirs } = await getStatsInDir(directory); - files = files.filter(f => !f.endsWith("asyncapi-ui.min.js")); - if (files.length) { + const { files, dirs } = await getStatsInDir(directory); + const warnings: any[] = []; + const debug = process.argv.includes('--debug'); + const originalStderr = process.stderr.write; + + process.stderr.write = ((chunk: any, enc?: any, cb?: any): boolean => { + const msg = chunk.toString(); + + if (msg.includes('[BABEL]')) { + if (debug) { + return originalStderr.call(process.stderr, chunk, enc, cb); + } + if (typeof cb === 'function') cb(); + return true; + } + return originalStderr.call(process.stderr, chunk, enc, cb); + }) as any; + + try { + if (files.length) { /** * WHEN ADDING PLUGINS to transform the input keep in mind that * IF any of these changes the actual original content in some way @@ -26,40 +44,48 @@ export async function transpileFiles(directory: string, outputDir: string, optio * * An example of this is using the `sourceMaps: 'inline'` configuration for the babel plugin. */ - const bundles = await rollup({ - input: files, - onwarn: () => {}, - plugins: [ - babel({ - cwd: ROOT_DIR, - babelHelpers: "bundled", - plugins: [ - "source-map-support", - ], - presets: [ - ["@babel/preset-env", { - targets: { node: "12.16" }, - }], - ["@babel/preset-react", { - runtime: "automatic", - }], - ], - }) - ], - }) - await bundles.write({ - format: "commonjs", - sourcemap: true, - dir: outputDir, - exports: "auto", - paths: { - 'react/jsx-runtime': require.resolve('react/cjs/react-jsx-runtime.production.min').replace(/\\/g, '/'), - }, - sanitizeFileName: false, - }) + const bundles = await rollup({ + input: files, + onwarn: (warning) =>{ + warnings.push(warning); + }, + plugins: [ + babel({ + cwd: ROOT_DIR, + babelHelpers: "bundled", + plugins: [ + "source-map-support", + ], + presets: [ + ["@babel/preset-env", { + targets: { node: "12.16" }, + }], + ["@babel/preset-react", { + runtime: "automatic", + }], + ], + }) + ], + }) + await bundles.write({ + format: "commonjs", + sourcemap: true, + dir: outputDir, + exports: "auto", + paths: { + 'react/jsx-runtime': require.resolve('react/cjs/react-jsx-runtime.production.min').replace(/\\/g, '/'), + }, + sanitizeFileName: false, + }); + } + } finally { + process.stderr.write = originalStderr; + } + + if (debug && warnings.length > 0) { + warnings.forEach(w => log.debug(w.message)); } - // Check if we should transpile all subdirs if (options?.recursive === true && dirs.length > 0) { for (const subdir of dirs) { const subdirPath = Path.parse(subdir); From c3e4d74077e170e992f8b0b75b25ec1082544bd8 Mon Sep 17 00:00:00 2001 From: Sagar Seth Date: Tue, 9 Dec 2025 16:08:09 +0530 Subject: [PATCH 3/4] feat:improve and unify Babel/Rollup warning handling --- apps/react-sdk/src/transpiler/transpiler.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/apps/react-sdk/src/transpiler/transpiler.ts b/apps/react-sdk/src/transpiler/transpiler.ts index 7b38168f3f..97abaa6926 100644 --- a/apps/react-sdk/src/transpiler/transpiler.ts +++ b/apps/react-sdk/src/transpiler/transpiler.ts @@ -1,7 +1,7 @@ import Path from 'path'; import log from 'loglevel'; -import { rollup } from 'rollup'; +import { rollup, RollupWarning } from 'rollup'; import babel from '@rollup/plugin-babel'; import { getStatsInDir } from '../utils'; @@ -18,7 +18,7 @@ const ROOT_DIR = Path.resolve(__dirname, '../..'); */ export async function transpileFiles(directory: string, outputDir: string, options?: TranspileFilesOptions) { const { files, dirs } = await getStatsInDir(directory); - const warnings: any[] = []; + const warnings: RollupWarning[] = []; const debug = process.argv.includes('--debug'); const originalStderr = process.stderr.write; @@ -27,7 +27,7 @@ export async function transpileFiles(directory: string, outputDir: string, optio if (msg.includes('[BABEL]')) { if (debug) { - return originalStderr.call(process.stderr, chunk, enc, cb); + log.debug(msg.trim()); } if (typeof cb === 'function') cb(); return true; @@ -46,7 +46,7 @@ export async function transpileFiles(directory: string, outputDir: string, optio */ const bundles = await rollup({ input: files, - onwarn: (warning) =>{ + onwarn: (warning: RollupWarning) =>{ warnings.push(warning); }, plugins: [ From e2fc5b897de694f58c6c3fd9bfac1bca79ba4e4e Mon Sep 17 00:00:00 2001 From: Sagar Seth Date: Tue, 9 Dec 2025 16:28:55 +0530 Subject: [PATCH 4/4] fix: close rollup bundle to prevent resource leak --- apps/react-sdk/src/transpiler/transpiler.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/react-sdk/src/transpiler/transpiler.ts b/apps/react-sdk/src/transpiler/transpiler.ts index 97abaa6926..d6f66a60fb 100644 --- a/apps/react-sdk/src/transpiler/transpiler.ts +++ b/apps/react-sdk/src/transpiler/transpiler.ts @@ -77,6 +77,7 @@ export async function transpileFiles(directory: string, outputDir: string, optio }, sanitizeFileName: false, }); + await bundles.close(); } } finally { process.stderr.write = originalStderr;