MCPcopy
hub / github.com/rollup/rollup / batchWarnings

Function batchWarnings

cli/run/batchWarnings.ts:23–93  ·  view source on GitHub ↗
(command: Record<string, any>)

Source from the content-addressed store, hash-verified

21import type { BatchWarnings } from './loadConfigFileType';
22
23export default function batchWarnings(command: Record<string, any>): BatchWarnings {
24 const silent = !!command.silent;
25 const logFilter = generateLogFilter(command);
26 let count = 0;
27 const deferredWarnings = new Map<keyof typeof deferredHandlers, RollupLog[]>();
28 let warningOccurred = false;
29
30 const add = (warning: RollupLog) => {
31 count += 1;
32 warningOccurred = true;
33
34 if (silent) return;
35 if ((warning.code as string) in deferredHandlers) {
36 getOrCreate(deferredWarnings, warning.code, getNewArray).push(warning);
37 } else if ((warning.code as string) in immediateHandlers) {
38 immediateHandlers[warning.code!](warning);
39 } else {
40 title(warning.message);
41 defaultBody(warning);
42 }
43 };
44
45 return {
46 add,
47
48 get count() {
49 return count;
50 },
51
52 flush() {
53 if (count === 0 || silent) return;
54
55 const codes = [...deferredWarnings.keys()].sort(
56 (a, b) => deferredWarnings.get(b)!.length - deferredWarnings.get(a)!.length
57 );
58
59 for (const code of codes) {
60 deferredHandlers[code](deferredWarnings.get(code)!);
61 }
62
63 deferredWarnings.clear();
64 count = 0;
65 },
66
67 log(level, log) {
68 if (!logFilter(log)) return;
69 switch (level) {
70 case LOGLEVEL_WARN: {
71 return add(log);
72 }
73 case LOGLEVEL_DEBUG: {
74 if (!silent) {
75 stderr(bold(pc.blue(log.message)));
76 defaultBody(log);
77 }
78 return;
79 }
80 default: {

Callers 3

loadConfigFileFunction · 0.85
loadTranspiledConfigFileFunction · 0.85
loadConfigFromCommandFunction · 0.85

Calls 1

generateLogFilterFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…