Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fix-pnpm-browserslist-env-var-leak.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@asyncapi/cli": patch
---

fix: clear BROWSERSLIST env var during generator execution to prevent pnpm shell context interference
32 changes: 32 additions & 0 deletions src/utils/environment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* Executes a given function with the BROWSERSLIST environment variable temporarily cleared.
* This prevents the AsyncAPI generator and its dependencies (like the HTML template,
* which may use PostCSS/Autoprefixer and Browserslist) from encountering
* malformed browser queries due to an incorrectly set BROWSERSLIST environment variable.
*
* The original BROWSERSLIST value (if any) is restored after the function completes.
*
* @param fn The function to execute within the controlled environment.
* @returns The result of the executed function.
*/
export function withCleanBrowserslistEnv<T>(fn: () => T): T {
const originalBrowserslistEnv = process.env.BROWSERSLIST;
try {
// Clear the BROWSERSLIST environment variable to prevent it from interfering
// with internal template dependencies that might use browserslist,
// especially when an invalid value (like a shell command string) is present.
delete process.env.BROWSERSLIST;

// Optionally, if a specific default browserslist is always desired, one could set it here:
// process.env.BROWSERSLIST = 'last 2 versions, not dead, > 0.2%';

return fn();
} finally {
// Restore the original BROWSERSLIST environment variable or ensure it remains deleted
if (originalBrowserslistEnv !== undefined) {

Check warning on line 26 in src/utils/environment.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unexpected negated condition.

See more on https://sonarcloud.io/project/issues?id=asyncapi_cli&issues=AZ1qe_hlxaCleYMjx1-5&open=AZ1qe_hlxaCleYMjx1-5&pullRequest=2107
process.env.BROWSERSLIST = originalBrowserslistEnv;
} else {
delete process.env.BROWSERSLIST;
}
}
}
Loading