From e5a3712d76f0daf758dce59f95ec464ce5522049 Mon Sep 17 00:00:00 2001 From: armorbreak001 Date: Mon, 13 Apr 2026 16:32:30 +0800 Subject: [PATCH 1/2] fix: clear BROWSERSLIST env before generator execution (fixes #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 #1781 --- .../cli/internal/base/BaseGeneratorCommand.ts | 43 +++++++++++++------ 1 file changed, 31 insertions(+), 12 deletions(-) diff --git a/src/apps/cli/internal/base/BaseGeneratorCommand.ts b/src/apps/cli/internal/base/BaseGeneratorCommand.ts index 1fa8674c3..b803668be 100644 --- a/src/apps/cli/internal/base/BaseGeneratorCommand.ts +++ b/src/apps/cli/internal/base/BaseGeneratorCommand.ts @@ -94,18 +94,37 @@ export abstract class BaseGeneratorCommand extends Command { interactive = true ): Promise { const specification = await this.loadSpecificationSafely(asyncapi); - - const result = await this.generatorService.generate( - specification, - template, - output, - options as any, // GeneratorService expects different options interface - genOption, - interactive, - ); - - if (!result.success) { - throw new GeneratorError(new Error(result.error)); + + // When installed via pnpm, the BROWSERSLIST env variable may contain + // shell script content (e.g., "basedir=$(dirname ...)") that gets + // misinterpreted by PostCSS/Autoprefixer inside HTML templates. + // Clear it before generator execution and restore afterwards. + // See: https://github.com/asyncapi/cli/issues/1781 + const originalBrowserslist = process.env.BROWSERSLIST; + if (originalBrowserslist !== undefined) { + delete process.env.BROWSERSLIST; + } + + try { + const result = await this.generatorService.generate( + specification, + template, + output, + options as any, // GeneratorService expects different options interface + genOption, + interactive, + ); + + if (!result.success) { + throw new GeneratorError(new Error(result.error)); + } + } finally { + // Restore original BROWSERSLIST value + if (originalBrowserslist !== undefined) { + process.env.BROWSERSLIST = originalBrowserslist; + } else { + delete process.env.BROWSERSLIST; + } } } From ba4ab9a06fa36ae32ae3a8f0373ee9e80c4ad12a Mon Sep 17 00:00:00 2001 From: armorbreak001 Date: Mon, 13 Apr 2026 22:19:18 +0800 Subject: [PATCH 2/2] 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 --- .../cli/internal/base/BaseGeneratorCommand.ts | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/apps/cli/internal/base/BaseGeneratorCommand.ts b/src/apps/cli/internal/base/BaseGeneratorCommand.ts index b803668be..27e7feb88 100644 --- a/src/apps/cli/internal/base/BaseGeneratorCommand.ts +++ b/src/apps/cli/internal/base/BaseGeneratorCommand.ts @@ -95,13 +95,19 @@ export abstract class BaseGeneratorCommand extends Command { ): Promise { const specification = await this.loadSpecificationSafely(asyncapi); - // When installed via pnpm, the BROWSERSLIST env variable may contain + // When installed via pnpm globally, the BROWSERSLIST env variable may contain // shell script content (e.g., "basedir=$(dirname ...)") that gets // misinterpreted by PostCSS/Autoprefixer inside HTML templates. - // Clear it before generator execution and restore afterwards. + // Only clear when the value looks like shell script garbage, not legitimate + // browser queries like "last 2 Chrome versions" or "> 1%". // See: https://github.com/asyncapi/cli/issues/1781 const originalBrowserslist = process.env.BROWSERSLIST; - if (originalBrowserslist !== undefined) { + const looksLikeShellScript = originalBrowserslist !== undefined && ( + originalBrowserslist.includes('$(') || + originalBrowserslist.includes('`') || + /^\w+=/.test(originalBrowserslist) + ); + if (looksLikeShellScript) { delete process.env.BROWSERSLIST; } @@ -119,11 +125,9 @@ export abstract class BaseGeneratorCommand extends Command { throw new GeneratorError(new Error(result.error)); } } finally { - // Restore original BROWSERSLIST value - if (originalBrowserslist !== undefined) { + // Restore original BROWSERSLIST value only if we cleared it + if (looksLikeShellScript) { process.env.BROWSERSLIST = originalBrowserslist; - } else { - delete process.env.BROWSERSLIST; } } }