| 154 | * @returns {HandlerFn} default handler |
| 155 | */ |
| 156 | const createDefaultHandler = (profile, logger, progressBar) => { |
| 157 | /** @type {{ value: string | undefined, time: number }[]} */ |
| 158 | const lastStateInfo = []; |
| 159 | |
| 160 | /** @type {HandlerFn} */ |
| 161 | const defaultHandler = (percentage, msg, ...args) => { |
| 162 | if (profile) { |
| 163 | reportProfile(logger, lastStateInfo, percentage, msg, args); |
| 164 | } |
| 165 | |
| 166 | if (progressBar) { |
| 167 | const reportBar = createReportBar(progressBar.name, progressBar.color); |
| 168 | const c = getColors(); |
| 169 | /** @type {string} */ |
| 170 | const currentBar = reportBar(percentage); |
| 171 | |
| 172 | if (percentage === 1) { |
| 173 | logger.status(); |
| 174 | } else if (msg) { |
| 175 | logger.status( |
| 176 | `${currentBar} (${Math.floor(percentage * 100)}%)`, |
| 177 | `\n${[msg, ...args].map(c.gray).join(" ")}` |
| 178 | ); |
| 179 | } else { |
| 180 | logger.status(`${currentBar} (${Math.floor(percentage * 100)}%)`); |
| 181 | } |
| 182 | return; |
| 183 | } |
| 184 | |
| 185 | logger.status(`${Math.floor(percentage * 100)}%`, msg, ...args); |
| 186 | if (percentage === 1 || (!msg && args.length === 0)) logger.status(); |
| 187 | }; |
| 188 | |
| 189 | return defaultHandler; |
| 190 | }; |
| 191 | |
| 192 | const SKIPPED_QUEUE_CONTEXTS = ["import-module", "load-module"]; |
| 193 | |