Skip to content

Commit a2a1cad

Browse files
author
armorbreak001
committed
fix: only clear BROWSERSLIST when it looks like shell script garbage (fixes #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
1 parent e5e3cc0 commit a2a1cad

1 file changed

Lines changed: 11 additions & 7 deletions

File tree

src/apps/cli/internal/base/BaseGeneratorCommand.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,19 @@ export abstract class BaseGeneratorCommand extends Command {
9595
): Promise<void> {
9696
const specification = await this.loadSpecificationSafely(asyncapi);
9797

98-
// When installed via pnpm, the BROWSERSLIST env variable may contain
98+
// When installed via pnpm globally, the BROWSERSLIST env variable may contain
9999
// shell script content (e.g., "basedir=$(dirname ...)") that gets
100100
// misinterpreted by PostCSS/Autoprefixer inside HTML templates.
101-
// Clear it before generator execution and restore afterwards.
101+
// Only clear when the value looks like shell script garbage, not legitimate
102+
// browser queries like "last 2 Chrome versions" or "> 1%".
102103
// See: https://github.com/asyncapi/cli/issues/1781
103104
const originalBrowserslist = process.env.BROWSERSLIST;
104-
if (originalBrowserslist !== undefined) {
105+
const looksLikeShellScript = originalBrowserslist !== undefined && (
106+
originalBrowserslist.includes('$(') ||
107+
originalBrowserslist.includes('`') ||
108+
/^\w+=/.test(originalBrowserslist)
109+
);
110+
if (looksLikeShellScript) {
105111
delete process.env.BROWSERSLIST;
106112
}
107113

@@ -119,11 +125,9 @@ export abstract class BaseGeneratorCommand extends Command {
119125
throw new GeneratorError(new Error(result.error));
120126
}
121127
} finally {
122-
// Restore original BROWSERSLIST value
123-
if (originalBrowserslist !== undefined) {
128+
// Restore original BROWSERSLIST value only if we cleared it
129+
if (looksLikeShellScript) {
124130
process.env.BROWSERSLIST = originalBrowserslist;
125-
} else {
126-
delete process.env.BROWSERSLIST;
127131
}
128132
}
129133
}

0 commit comments

Comments
 (0)