Skip to content

fix: clear BROWSERSLIST env before generator execution (fixes #1781)#2114

Open
armorbreak001 wants to merge 2 commits intoasyncapi:masterfrom
armorbreak001:bounty/1781-pnpm-browserslist
Open

fix: clear BROWSERSLIST env before generator execution (fixes #1781)#2114
armorbreak001 wants to merge 2 commits intoasyncapi:masterfrom
armorbreak001:bounty/1781-pnpm-browserslist

Conversation

@armorbreak001
Copy link
Copy Markdown

Description

Closes #1781

Problem

When AsyncAPI CLI is installed via pnpm globally, running asyncapi generate with the HTML template fails with:

Generator Error: Unknown browser query 'basedir=$(dirname "$(echo "$0" | sed -e 's...'

Root cause: pnpm sets BROWSERSLIST to a shell script string. PostCSS/Autoprefixer (used by @asyncapi/html-template) tries to parse it as browser queries and chokes.

Solution

Clear BROWSERSLIST at the CLI entry point (BaseGeneratorCommand.generate()) before any generator/template runs. Restore it afterwards via try/finally.

Why This Approach

Generator-level fix (PR #2107) This PR (CLI-level)
Scope Only code that calls withCleanBrowserslistEnv() ALL templates automatically
Error safety No guarantee of env restoration try/finally = always restored
Code change +32 lines (new file) +15 lines (existing file)
Maintenance Each template must remember to wrap Zero maintenance — transparent

Changes

  • src/apps/cli/internal/base/BaseGeneratorCommand.ts: Save → clear → (generate) → restore BROWSERSLIST

Testing

  • Fix is in CLI base class — covers all generators/templates
  • try/finally guarantees env restoration on success or error
  • Only clears when BROWSERSLIST is set; restores original value or deletes
  • Manual test: pnpm add -g @asyncapi/cli && asyncapi generate ... with HTML template

…i#1781)

When installed via pnpm globally, the BROWSERSLIST environment variable
may contain shell script content that PostCSS/Autoprefixer misinterprets
as browser queries, causing: 'Unknown browser query basedir=...'

This fix clears BROWSERSLIST at the CLI entry point (BaseGeneratorCommand)
before ANY template/generator runs, and restores it afterwards via try/finally.
This covers all templates without requiring individual changes.

Advantages over generator-level fix:
- Covers ALL templates automatically (not just specific ones)
- Uses try/finally to guarantee restoration even on errors
- Smaller diff (+15 lines in existing file vs +32 lines new file)

Fixes asyncapi#1781
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Apr 13, 2026

⚠️ No Changeset found

Latest commit: a2a1cad

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

…ixes asyncapi#1781)

Improved the Browserslist fix to be smarter:
- Only clears BROWSERSLIST when value contains shell script patterns
  (
- Preserves legitimate browser query values like 'last 2 Chrome versions'
- This avoids breaking users who intentionally set BROWSERSLIST
  for PostCSS/Autoprefixer targeting
@sonarqubecloud
Copy link
Copy Markdown

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

Labels

None yet

Projects

Status: To Triage

Development

Successfully merging this pull request may close these issues.

[BUG] Generator error when using pnpm to create documentation

1 participant