Skip to content

Conversation

@lightning-sagar
Copy link
Contributor

@lightning-sagar lightning-sagar commented Nov 28, 2025

Description

This PR fixes the long-standing Babel warning:

[BABEL] Note: The code generator has deoptimised the styling of asyncapi-ui.min.js as it exceeds the max of 500KB

The issue occurs because the React transpiler processes asyncapi-ui.min.js, which is a large minified dependency that should not be transpiled.

What was changed

  • Updated the React SDK transpiler to ignore asyncapi-ui.min.js before passing files to Rollup/Babel.

  • Implemented a simple filter:

    files = files.filter(f => !f.endsWith("asyncapi-ui.min.js"));

    (and equivalent logic where needed)

  • After applying the fix, the generator runs without any Babel deoptimisation warnings.

📌 Additional note

The old repo (asyncapi-archived-repos/generator-react-sdk) is archived, so this change was made in the active path:

apps/react-sdk/src/transpiler/transpiler.ts

Related issue(s)

Fixes:
#1771
#717

Summary by CodeRabbit

  • Bug Fixes
    • Reduced noisy build output by suppressing non-debug tool messages during normal runs.
    • Collected and surfaced build warnings only when running in debug mode for clearer diagnostics.
    • Ensured standard error output, warning handling, and build resources are reliably restored/closed after the transpile step.

✏️ Tip: You can customize this high-level summary in your review settings.

@changeset-bot
Copy link

changeset-bot bot commented Nov 28, 2025

⚠️ No Changeset found

Latest commit: e2fc5b8

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai
Copy link

coderabbitai bot commented Nov 28, 2025

Walkthrough

Suppresses non-debug Babel "[BABEL]" stderr output during transpilation by temporarily overriding process.stderr.write, collects Rollup warnings into an array via an onwarn handler, restores stderr.write with a try/finally, conditionally logs warnings when --debug is present, and calls bundles.close() after transpile.

Changes

Cohort / File(s) Summary
Transpiler runtime logging & warnings
apps/react-sdk/src/transpiler/transpiler.ts
Imported log from loglevel and RollupWarning typing; added warnings array and --debug detection; temporarily override process.stderr.write to filter [BABEL] messages when not debugging; wrapped transpile flow in try/finally to restore original stderr.write; replaced no-op onwarn with handler that collects warnings; conditionally logs collected warnings in debug mode; added explicit bundles.close() call.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Review focus:
    • Correctness and thread-safety of overriding/restoring process.stderr.write (async calls, nested invocations).
    • Coverage and accuracy of the [BABEL] filter (possible false positives/negatives).
    • Ensuring collected Rollup warnings are surfaced appropriately and bundles.close() always runs.

Pre-merge checks and finishing touches

❌ Failed checks (1 warning, 2 inconclusive)
Check name Status Explanation Resolution
Title check ⚠️ Warning The PR title mentions excluding asyncapi-ui.min.js but the actual changes focus on warning suppression and debug logging, not exclusion. The actual implementation suppresses Babel warnings via debug mode rather than filtering files. Update the title to reflect the actual approach, e.g., 'fix: suppress Babel deoptimisation warnings in debug mode' or implement file exclusion as originally stated.
Linked Issues check ❓ Inconclusive The PR partially addresses issue #1771 by suppressing warnings, but the approach diverges from the stated objective to exclude asyncapi-ui.min.js from transpilation. Clarify with maintainers whether suppressing warnings via --debug flag meets the issue requirements, or if excluding the file from transpilation is the intended solution per PR objectives.
Out of Scope Changes check ❓ Inconclusive The changes include debug logging infrastructure and warning collection that go beyond the stated objective of excluding asyncapi-ui.min.js. Review whether the debug mode and stderr interception are necessary scope additions or if a simpler file exclusion approach would be more appropriate.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@asyncapi-bot
Copy link
Contributor

What reviewer looks at during PR review

The following are ideal points maintainers look for during review. Reviewing these points yourself beforehand can help streamline the review process and reduce time to merge.

  1. PR Title: Use a concise title that follows our Conventional Commits guidelines and clearly summarizes the change using imperative mood (it means spoken or written as if giving a command or instruction, like "add new helper for listing operations")

    Note - In Generator, prepend feat: or fix: in PR title only when PATCH/MINOR release must be triggered.

  2. PR Description: Clearly explain the issue being solved, summarize the changes made, and mention the related issue.

    Note - In Generator, we use Maintainers Work board to track progress. Ensure the PR Description includes Resolves #<issue-number> or Fixes #<issue-number> this will automatically close the linked issue when the PR is merged and helps automate the maintainers workflow.

  3. Documentation: Update the relevant Generator documentation to accurately reflect the changes introduced in the PR, ensuring users and contributors have up-to-date guidance.

  4. Comments and JSDoc: Write clear and consistent JSDoc comments for functions, including parameter types, return values, and error conditions, so others can easily understand and use the code.

  5. DRY Code: Ensure the code follows the Don't Repeat Yourself principle. Look out for duplicate logic that can be reused.

  6. Test Coverage: Ensure the new code is well-tested with meaningful test cases that pass consistently and cover all relevant edge cases.

  7. Commit History: Contributors should avoid force-pushing as much as possible. It makes it harder to track incremental changes and review the latest updates.

  8. Template Design Principles Alignment: While reviewing template-related changes in the packages/ directory, ensure they align with the Assumptions and Principles. If any principle feels outdated or no longer applicable, start a discussion these principles are meant to evolve with the project.

  9. Reduce Scope When Needed: If an issue or PR feels too large or complex, consider splitting it and creating follow-up issues. Smaller, focused PRs are easier to review and merge.

  10. Bot Comments: As reviewers, check that contributors have appropriately addressed comments or suggestions made by automated bots. If there are bot comments the reviewer disagrees with, react to them or mark them as resolved, so the review history remains clear and accurate.

@lightning-sagar lightning-sagar force-pushed the fix/ignore-asyncapi-ui-min branch from 2578004 to 296272a Compare November 28, 2025 11:34
@lightning-sagar lightning-sagar changed the title fix: ignore asyncapi UI min fix: exclude asyncapi-ui.min.js from transpilation to prevent Babel deoptimisation warning Nov 28, 2025
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
apps/react-sdk/src/transpiler/transpiler.ts (2)

21-36: Improve type safety for warnings array.

The any[] type loses type information. Rollup exports RollupWarning which provides better type safety and IDE support.

+import { rollup, RollupWarning } from 'rollup';
-import { rollup } from 'rollup';
-    const warnings: any[] = [];
+    const warnings: RollupWarning[] = [];

Also, consider typing the onwarn parameter:

-                onwarn: (warning) =>{
+                onwarn: (warning: RollupWarning) => {

81-87: Consider consistent warning output in debug mode.

There's an inconsistency in how warnings are emitted in debug mode:

  • BABEL messages are forwarded directly to stderr (line 30)
  • Rollup warnings are logged via log.debug() (line 86)

This could result in different output destinations depending on loglevel configuration. Consider using log.debug() for both, or forwarding both to stderr for consistency.

Additionally, if transpilation throws an error, collected warnings won't be logged. Consider moving the warning logging into the finally block or a catch block if warnings should be visible even on failure.

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 296272a and 2e40188.

📒 Files selected for processing (1)
  • apps/react-sdk/src/transpiler/transpiler.ts (2 hunks)
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2025-05-12T14:57:35.024Z
Learnt from: Adi-204
Repo: asyncapi/generator PR: 1557
File: packages/templates/clients/websocket/javascript/components/SendOperation.js:21-21
Timestamp: 2025-05-12T14:57:35.024Z
Learning: In the AsyncAPI generator templates, particularly in the JavaScript WebSocket client, single quotes are used for string literals inside template-generated code (which is itself inside backticks) to preserve template placeholders like ${variable} as literal text in the generated code output.

Applied to files:

  • apps/react-sdk/src/transpiler/transpiler.ts
📚 Learning: 2025-05-12T17:29:03.886Z
Learnt from: derberg
Repo: asyncapi/generator PR: 1557
File: packages/templates/clients/websocket/javascript/components/SendOperation.js:7-7
Timestamp: 2025-05-12T17:29:03.886Z
Learning: Do not suggest adding key props to mapped React elements in the asyncapi/generator repository, even when linters like Biome flag them as missing.

Applied to files:

  • apps/react-sdk/src/transpiler/transpiler.ts
🧬 Code graph analysis (1)
apps/react-sdk/src/transpiler/transpiler.ts (1)
apps/generator/lib/generator.js (1)
  • ROOT_DIR (44-44)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
  • GitHub Check: Acceptance tests for generated templates
  • GitHub Check: Test generator as dependency with Node 20
  • GitHub Check: Test generator as dependency with Node 18
  • GitHub Check: Test NodeJS PR - macos-latest
  • GitHub Check: Test NodeJS PR - ubuntu-latest
  • GitHub Check: Test NodeJS PR - windows-latest
🔇 Additional comments (2)
apps/react-sdk/src/transpiler/transpiler.ts (2)

2-2: LGTM!

The loglevel import is appropriate for consistent debug logging with the rest of the codebase.


47-79: LGTM!

The rollup configuration with onwarn handler correctly collects warnings for deferred logging. This approach addresses the PR objective by suppressing noisy warnings by default while preserving them for debug mode.

@lightning-sagar
Copy link
Contributor Author

@derberg ,
i noticed Babel prints warnings directly to stderr, so Rollup doesnot catch them, to follow your suggestion, i modified the transpiler so:

  • babel warning are suppressed by default and
  • they only appear when the generator is run with --debug flag

is this the right approach or would you prefer a different way of handling these warnings??

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
apps/react-sdk/src/transpiler/transpiler.ts (1)

21-36: Consider passing debug as an option parameter and hoisting stderr interception.

Two concerns:

  1. Reading --debug from process.argv couples this SDK function directly to CLI behavior. For better reusability, pass debug via the options parameter.

  2. Each recursive call (line 92) re-intercepts stderr and creates a new warnings array, leading to nested interceptions. Hoist the interception to occur once at the top-level call.

Suggested approach:

-export async function transpileFiles(directory: string, outputDir: string, options?: TranspileFilesOptions) {
+export async function transpileFiles(directory: string, outputDir: string, options?: TranspileFilesOptions & { debug?: boolean }) {
     const { files, dirs } = await getStatsInDir(directory);
     const warnings: RollupWarning[] = [];
-    const debug = process.argv.includes('--debug');
+    const debug = options?.debug ?? false;
+    const isTopLevel = options?._isTopLevel !== false;

Then only intercept stderr for top-level calls and pass { ...options, _isTopLevel: false } to recursive calls.

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2e40188 and c3e4d74.

📒 Files selected for processing (1)
  • apps/react-sdk/src/transpiler/transpiler.ts (2 hunks)
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2025-05-12T14:57:35.024Z
Learnt from: Adi-204
Repo: asyncapi/generator PR: 1557
File: packages/templates/clients/websocket/javascript/components/SendOperation.js:21-21
Timestamp: 2025-05-12T14:57:35.024Z
Learning: In the AsyncAPI generator templates, particularly in the JavaScript WebSocket client, single quotes are used for string literals inside template-generated code (which is itself inside backticks) to preserve template placeholders like ${variable} as literal text in the generated code output.

Applied to files:

  • apps/react-sdk/src/transpiler/transpiler.ts
📚 Learning: 2025-05-12T17:29:03.886Z
Learnt from: derberg
Repo: asyncapi/generator PR: 1557
File: packages/templates/clients/websocket/javascript/components/SendOperation.js:7-7
Timestamp: 2025-05-12T17:29:03.886Z
Learning: Do not suggest adding key props to mapped React elements in the asyncapi/generator repository, even when linters like Biome flag them as missing.

Applied to files:

  • apps/react-sdk/src/transpiler/transpiler.ts
🧬 Code graph analysis (1)
apps/react-sdk/src/transpiler/transpiler.ts (2)
apps/generator/lib/generator.js (1)
  • ROOT_DIR (44-44)
apps/react-sdk/src/transpiler/__tests__/testfiles/ES6/simple.js (1)
  • require (4-4)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
  • GitHub Check: Acceptance tests for generated templates
  • GitHub Check: Test generator as dependency with Node 20
  • GitHub Check: Test generator as dependency with Node 18
  • GitHub Check: Test NodeJS PR - windows-latest
  • GitHub Check: Test NodeJS PR - ubuntu-latest
  • GitHub Check: Test NodeJS PR - macos-latest
🔇 Additional comments (2)
apps/react-sdk/src/transpiler/transpiler.ts (2)

2-4: LGTM on imports.

The additions of loglevel and RollupWarning type are appropriate for the new warning handling functionality.


85-87: Warnings from recursive calls are handled separately.

Each recursive invocation creates its own warnings array and logs independently. This works but results in interleaved debug output. If consolidated reporting is desired later, consider aggregating warnings across recursive calls.

@sonarqubecloud
Copy link

sonarqubecloud bot commented Dec 9, 2025

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
apps/react-sdk/src/transpiler/transpiler.ts (2)

25-37: Babel stderr filtering behavior: confirm that hiding all [BABEL] output is desired

The interception correctly forwards non‑Babel writes to the original stderr and only swallows chunks containing [BABEL], optionally re‑emitting them via log.debug when --debug is passed. This matches the maintainer request to suppress Babel warnings by default.

Two small points to validate:

  • This will hide all Babel [BABEL] messages (not just the deoptimisation note) in non‑debug runs. If there are other useful Babel diagnostics that also start with [BABEL], they will only be visible under --debug.
  • The callback handling (if (typeof cb === 'function') cb();) ensures upstream callers aren’t left hanging, which is good; just be aware that if Babel (or another tool) relies on stderr backpressure instead of callbacks, this short‑circuiting assumes the writes are small enough not to matter.

If that behavior is acceptable, the implementation looks fine as‑is.

If you later find this too broad, you could tighten the filter to specific message substrings (e.g. the deoptimisation note) or add a small allowlist of Babel warning codes while still routing them through log.debug.


47-52: Rollup warning collection and bundle cleanup look good; consider more robust close() on failures

Nice improvements here:

  • onwarn now collects RollupWarnings into an array and only logs them at debug level, which keeps normal output clean and aligns with the --debug behavior.
  • await bundles.close() after bundles.write() ensures plugins get their closeBundle hook and resources are released on the success path.
  • Debug logging of warnings via log.debug(w.message) is straightforward and low‑noise.

One potential hardening you may want to consider: if bundles.write(...) throws, bundles.close() is never called. Per Rollup 2.60.1's JavaScript API documentation, the closeBundle hook accepts an optional error parameter—indicating that plugins expect to receive cleanup notifications even when failures occur. Wrapping the write/close pair in try/finally ensures plugins always get the opportunity to clean up resources:

-            const bundles = await rollup({
+            const bundles = await rollup({
               /* config */
-            })
-            await bundles.write({ /* options */ });
-            await bundles.close();
+            });
+            try {
+              await bundles.write({ /* options */ });
+            } finally {
+              await bundles.close();
+            }

Also applies to: 70-80, 86-87

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c3e4d74 and e2fc5b8.

📒 Files selected for processing (1)
  • apps/react-sdk/src/transpiler/transpiler.ts (2 hunks)
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2025-05-12T14:57:35.024Z
Learnt from: Adi-204
Repo: asyncapi/generator PR: 1557
File: packages/templates/clients/websocket/javascript/components/SendOperation.js:21-21
Timestamp: 2025-05-12T14:57:35.024Z
Learning: In the AsyncAPI generator templates, particularly in the JavaScript WebSocket client, single quotes are used for string literals inside template-generated code (which is itself inside backticks) to preserve template placeholders like ${variable} as literal text in the generated code output.

Applied to files:

  • apps/react-sdk/src/transpiler/transpiler.ts
📚 Learning: 2025-05-12T17:29:03.886Z
Learnt from: derberg
Repo: asyncapi/generator PR: 1557
File: packages/templates/clients/websocket/javascript/components/SendOperation.js:7-7
Timestamp: 2025-05-12T17:29:03.886Z
Learning: Do not suggest adding key props to mapped React elements in the asyncapi/generator repository, even when linters like Biome flag them as missing.

Applied to files:

  • apps/react-sdk/src/transpiler/transpiler.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
  • GitHub Check: Test generator as dependency with Node 18
  • GitHub Check: Acceptance tests for generated templates
  • GitHub Check: Test generator as dependency with Node 20
  • GitHub Check: Test NodeJS PR - macos-latest
  • GitHub Check: Test NodeJS PR - windows-latest
  • GitHub Check: Test NodeJS PR - ubuntu-latest
🔇 Additional comments (1)
apps/react-sdk/src/transpiler/transpiler.ts (1)

21-24: Global process.stderr.write override is scoped but has concurrency implications

The pattern of capturing originalStderr, overriding process.stderr.write, and restoring it in a finally block properly contains the override to this function's execution. However, it still affects the entire process globally while transpileFiles is running. If this function is invoked in parallel from different parts of a long‑lived process, the overrides could interfere with each other or with other code hooking stderr.

Not urgent for current CLI‑style usage, but consider in the future:

  • Passing a debug/suppressBabel option into this function instead of reading process.argv directly.
  • Centralizing stderr interception at a higher CLI layer to keep this helper side‑effect free.

Verify that transpileFiles call patterns across the repository confirm it cannot be invoked concurrently before treating this as a non-issue.

Also applies to: 38-39, 82-84

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants