Find the cost of adding an npm package to your app's bundle size teardown.kelinci.dev
14
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix: strip ANSI codes from rolldown errors

Mary 65de9757 28b42cbc

+16 -2
+13
src/lib/strings.ts
··· 1 1 export function normalizeWhitespace(input: string): string { 2 2 return input.replace(/\s+/g, ' ').trim(); 3 3 } 4 + 5 + // matches ANSI escape sequences (colors, cursor movement, etc.) 6 + const ANSI_REGEX = /\x1b\[[0-9;]*[a-zA-Z]/g; 7 + 8 + /** 9 + * strips ANSI escape codes from a string. 10 + * 11 + * @param input string potentially containing ANSI codes 12 + * @returns string with ANSI codes removed 13 + */ 14 + export function stripAnsi(input: string): string { 15 + return input.replace(ANSI_REGEX, ''); 16 + }
+3 -2
src/npm/worker.ts
··· 1 1 import { memfs } from '@rolldown/browser/experimental'; 2 2 import * as v from 'valibot'; 3 3 4 + import { stripAnsi } from '../lib/strings'; 4 5 import { bundlePackage, type BundleOptions } from './bundler'; 5 6 import { progress } from './events'; 6 7 import { fetchPackagesToVolume } from './fetch'; ··· 163 164 164 165 self.postMessage({ id, type: 'init', result: initResult } satisfies WorkerResponse); 165 166 } catch (error) { 166 - self.postMessage({ id, type: 'error', error: String(error) } satisfies WorkerResponse); 167 + self.postMessage({ id, type: 'error', error: stripAnsi(String(error)) } satisfies WorkerResponse); 167 168 } 168 169 } 169 170 ··· 211 212 const result = await bundlePackage(packageName!, subpath, selectedExports, options); 212 213 self.postMessage({ id, type: 'bundle', result } satisfies WorkerResponse); 213 214 } catch (error) { 214 - self.postMessage({ id, type: 'error', error: String(error) } satisfies WorkerResponse); 215 + self.postMessage({ id, type: 'error', error: stripAnsi(String(error)) } satisfies WorkerResponse); 215 216 } finally { 216 217 bundleInProgress = false; 217 218