ProgressPlugin.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. "use strict";
  6. const Compiler = require("./Compiler");
  7. const MultiCompiler = require("./MultiCompiler");
  8. const NormalModule = require("./NormalModule");
  9. const { contextify } = require("./util/identifier");
  10. /** @typedef {import("tapable").Tap} Tap */
  11. /**
  12. * Defines the hook type used by this module.
  13. * @template T, R, AdditionalOptions
  14. * @typedef {import("tapable").Hook<T, R, AdditionalOptions>} Hook
  15. */
  16. /** @typedef {import("../declarations/plugins/ProgressPlugin").ProgressPluginArgument} ProgressPluginArgument */
  17. /** @typedef {import("../declarations/plugins/ProgressPlugin").ProgressPluginOptions} ProgressPluginOptions */
  18. /** @typedef {import("./Compilation").FactorizeModuleOptions} FactorizeModuleOptions */
  19. /** @typedef {import("./Dependency")} Dependency */
  20. /** @typedef {import("./Entrypoint").EntryOptions} EntryOptions */
  21. /** @typedef {import("./Module")} Module */
  22. /** @typedef {import("./ModuleFactory").ModuleFactoryResult} ModuleFactoryResult */
  23. /** @typedef {import("./logging/Logger").Logger} Logger */
  24. /**
  25. * Defines the async queue type used by this module.
  26. * @template T, K, R
  27. * @typedef {import("./util/AsyncQueue")<T, K, R>} AsyncQueue
  28. */
  29. /**
  30. * Defines the counts data type used by this module.
  31. * @typedef {object} CountsData
  32. * @property {number} modulesCount modules count
  33. * @property {number} dependenciesCount dependencies count
  34. */
  35. /**
  36. * Returns median.
  37. * @param {number} a a
  38. * @param {number} b b
  39. * @param {number} c c
  40. * @returns {number} median
  41. */
  42. const median3 = (a, b, c) => a + b + c - Math.max(a, b, c) - Math.min(a, b, c);
  43. /** @typedef {(percentage: number, msg: string, ...args: string[]) => void} HandlerFn */
  44. /**
  45. * Creates a default handler.
  46. * @param {boolean | null | undefined} profile need profile
  47. * @param {Logger} logger logger
  48. * @returns {HandlerFn} default handler
  49. */
  50. const createDefaultHandler = (profile, logger) => {
  51. /** @type {{ value: string | undefined, time: number }[]} */
  52. const lastStateInfo = [];
  53. /** @type {HandlerFn} */
  54. const defaultHandler = (percentage, msg, ...args) => {
  55. if (profile) {
  56. if (percentage === 0) {
  57. lastStateInfo.length = 0;
  58. }
  59. const fullState = [msg, ...args];
  60. const state = fullState.map((s) => s.replace(/\d+\/\d+ /g, ""));
  61. const now = Date.now();
  62. const len = Math.max(state.length, lastStateInfo.length);
  63. for (let i = len; i >= 0; i--) {
  64. const stateItem = i < state.length ? state[i] : undefined;
  65. const lastStateItem =
  66. i < lastStateInfo.length ? lastStateInfo[i] : undefined;
  67. if (lastStateItem) {
  68. if (stateItem !== lastStateItem.value) {
  69. const diff = now - lastStateItem.time;
  70. if (lastStateItem.value) {
  71. let reportState = lastStateItem.value;
  72. if (i > 0) {
  73. reportState = `${lastStateInfo[i - 1].value} > ${reportState}`;
  74. }
  75. const stateMsg = `${" | ".repeat(i)}${diff} ms ${reportState}`;
  76. const d = diff;
  77. // This depends on timing so we ignore it for coverage
  78. /* eslint-disable no-lone-blocks */
  79. /* istanbul ignore next */
  80. {
  81. if (d > 10000) {
  82. logger.error(stateMsg);
  83. } else if (d > 1000) {
  84. logger.warn(stateMsg);
  85. } else if (d > 10) {
  86. logger.info(stateMsg);
  87. } else if (d > 5) {
  88. logger.log(stateMsg);
  89. } else {
  90. logger.debug(stateMsg);
  91. }
  92. }
  93. /* eslint-enable no-lone-blocks */
  94. }
  95. if (stateItem === undefined) {
  96. lastStateInfo.length = i;
  97. } else {
  98. lastStateItem.value = stateItem;
  99. lastStateItem.time = now;
  100. lastStateInfo.length = i + 1;
  101. }
  102. }
  103. } else {
  104. lastStateInfo[i] = {
  105. value: stateItem,
  106. time: now
  107. };
  108. }
  109. }
  110. }
  111. logger.status(`${Math.floor(percentage * 100)}%`, msg, ...args);
  112. if (percentage === 1 || (!msg && args.length === 0)) logger.status();
  113. };
  114. return defaultHandler;
  115. };
  116. const SKIPPED_QUEUE_CONTEXTS = ["import-module", "load-module"];
  117. /**
  118. * Defines the report progress callback.
  119. * @callback ReportProgress
  120. * @param {number} p percentage
  121. * @param {...string} args additional arguments
  122. * @returns {void}
  123. */
  124. /** @type {WeakMap<Compiler, ReportProgress | undefined>} */
  125. const progressReporters = new WeakMap();
  126. const PLUGIN_NAME = "ProgressPlugin";
  127. /** @type {Required<Omit<ProgressPluginOptions, "handler">>} */
  128. const DEFAULT_OPTIONS = {
  129. profile: false,
  130. modulesCount: 5000,
  131. dependenciesCount: 10000,
  132. modules: true,
  133. dependencies: true,
  134. activeModules: false,
  135. entries: true,
  136. percentBy: null
  137. };
  138. class ProgressPlugin {
  139. /**
  140. * Returns a progress reporter, if any.
  141. * @param {Compiler} compiler the current compiler
  142. * @returns {ReportProgress | undefined} a progress reporter, if any
  143. */
  144. static getReporter(compiler) {
  145. return progressReporters.get(compiler);
  146. }
  147. /**
  148. * Creates an instance of ProgressPlugin.
  149. * @param {ProgressPluginArgument} options options
  150. */
  151. constructor(options = {}) {
  152. if (typeof options === "function") {
  153. options = {
  154. handler: options
  155. };
  156. }
  157. /** @type {ProgressPluginOptions} */
  158. this.options = options;
  159. const merged = { ...DEFAULT_OPTIONS, ...options };
  160. this.profile = merged.profile;
  161. this.handler = merged.handler;
  162. this.modulesCount = merged.modulesCount;
  163. this.dependenciesCount = merged.dependenciesCount;
  164. this.showEntries = merged.entries;
  165. this.showModules = merged.modules;
  166. this.showDependencies = merged.dependencies;
  167. this.showActiveModules = merged.activeModules;
  168. this.percentBy = merged.percentBy;
  169. }
  170. /**
  171. * Applies the plugin by registering its hooks on the compiler.
  172. * @param {Compiler | MultiCompiler} compiler webpack compiler
  173. * @returns {void}
  174. */
  175. apply(compiler) {
  176. const handler =
  177. this.handler ||
  178. createDefaultHandler(
  179. this.profile,
  180. compiler.getInfrastructureLogger("webpack.Progress")
  181. );
  182. if (compiler instanceof MultiCompiler) {
  183. this._applyOnMultiCompiler(compiler, handler);
  184. } else if (compiler instanceof Compiler) {
  185. this._applyOnCompiler(compiler, handler);
  186. }
  187. }
  188. /**
  189. * Apply on multi compiler.
  190. * @param {MultiCompiler} compiler webpack multi-compiler
  191. * @param {HandlerFn} handler function that executes for every progress step
  192. * @returns {void}
  193. */
  194. _applyOnMultiCompiler(compiler, handler) {
  195. const states = compiler.compilers.map(
  196. () => /** @type {[number, ...string[]]} */ ([0])
  197. );
  198. for (const [idx, item] of compiler.compilers.entries()) {
  199. new ProgressPlugin((p, msg, ...args) => {
  200. states[idx] = [p, msg, ...args];
  201. let sum = 0;
  202. for (const [p] of states) sum += p;
  203. handler(sum / states.length, `[${idx}] ${msg}`, ...args);
  204. }).apply(item);
  205. }
  206. }
  207. /**
  208. * Processes the provided compiler.
  209. * @param {Compiler} compiler webpack compiler
  210. * @param {HandlerFn} handler function that executes for every progress step
  211. * @returns {void}
  212. */
  213. _applyOnCompiler(compiler, handler) {
  214. compiler.hooks.validate.tap(PLUGIN_NAME, () => {
  215. compiler.validate(
  216. () => require("../schemas/plugins/ProgressPlugin.json"),
  217. this.options,
  218. {
  219. name: "Progress Plugin",
  220. baseDataPath: "options"
  221. },
  222. (options) => require("../schemas/plugins/ProgressPlugin.check")(options)
  223. );
  224. });
  225. const showEntries = this.showEntries;
  226. const showModules = this.showModules;
  227. const showDependencies = this.showDependencies;
  228. const showActiveModules = this.showActiveModules;
  229. let lastActiveModule = "";
  230. let currentLoader = "";
  231. let lastModulesCount = 0;
  232. let lastDependenciesCount = 0;
  233. let lastEntriesCount = 0;
  234. let modulesCount = 0;
  235. let skippedModulesCount = 0;
  236. let dependenciesCount = 0;
  237. let skippedDependenciesCount = 0;
  238. let entriesCount = 1;
  239. let doneModules = 0;
  240. let doneDependencies = 0;
  241. let doneEntries = 0;
  242. /** @type {Set<string>} */
  243. const activeModules = new Set();
  244. let lastUpdate = 0;
  245. const updateThrottled = () => {
  246. if (lastUpdate + 500 < Date.now()) update();
  247. };
  248. const update = () => {
  249. /** @type {string[]} */
  250. const items = [];
  251. const percentByModules =
  252. doneModules /
  253. Math.max(lastModulesCount || this.modulesCount || 1, modulesCount);
  254. const percentByEntries =
  255. doneEntries /
  256. Math.max(lastEntriesCount || this.dependenciesCount || 1, entriesCount);
  257. const percentByDependencies =
  258. doneDependencies /
  259. Math.max(lastDependenciesCount || 1, dependenciesCount);
  260. /** @type {number} */
  261. let percentageFactor;
  262. switch (this.percentBy) {
  263. case "entries":
  264. percentageFactor = percentByEntries;
  265. break;
  266. case "dependencies":
  267. percentageFactor = percentByDependencies;
  268. break;
  269. case "modules":
  270. percentageFactor = percentByModules;
  271. break;
  272. default:
  273. percentageFactor = median3(
  274. percentByModules,
  275. percentByEntries,
  276. percentByDependencies
  277. );
  278. }
  279. const percentage = 0.1 + percentageFactor * 0.55;
  280. if (currentLoader) {
  281. items.push(
  282. `import loader ${contextify(
  283. compiler.context,
  284. currentLoader,
  285. compiler.root
  286. )}`
  287. );
  288. } else {
  289. /** @type {string[]} */
  290. const statItems = [];
  291. if (showEntries) {
  292. statItems.push(`${doneEntries}/${entriesCount} entries`);
  293. }
  294. if (showDependencies) {
  295. statItems.push(
  296. `${doneDependencies}/${dependenciesCount} dependencies`
  297. );
  298. }
  299. if (showModules) {
  300. statItems.push(`${doneModules}/${modulesCount} modules`);
  301. }
  302. if (showActiveModules) {
  303. statItems.push(`${activeModules.size} active`);
  304. }
  305. if (statItems.length > 0) {
  306. items.push(statItems.join(" "));
  307. }
  308. if (showActiveModules) {
  309. items.push(lastActiveModule);
  310. }
  311. }
  312. handler(percentage, "building", ...items);
  313. lastUpdate = Date.now();
  314. };
  315. /**
  316. * Processes the provided factorize queue.
  317. * @template T
  318. * @param {AsyncQueue<FactorizeModuleOptions, string, Module | ModuleFactoryResult>} factorizeQueue async queue
  319. * @param {T} _item item
  320. */
  321. const factorizeAdd = (factorizeQueue, _item) => {
  322. if (SKIPPED_QUEUE_CONTEXTS.includes(factorizeQueue.getContext())) {
  323. skippedDependenciesCount++;
  324. }
  325. dependenciesCount++;
  326. if (dependenciesCount < 50 || dependenciesCount % 100 === 0) {
  327. updateThrottled();
  328. }
  329. };
  330. const factorizeDone = () => {
  331. doneDependencies++;
  332. if (doneDependencies < 50 || doneDependencies % 100 === 0) {
  333. updateThrottled();
  334. }
  335. };
  336. /**
  337. * Processes the provided add module queue.
  338. * @template T
  339. * @param {AsyncQueue<Module, string, Module>} addModuleQueue async queue
  340. * @param {T} _item item
  341. */
  342. const moduleAdd = (addModuleQueue, _item) => {
  343. if (SKIPPED_QUEUE_CONTEXTS.includes(addModuleQueue.getContext())) {
  344. skippedModulesCount++;
  345. }
  346. modulesCount++;
  347. if (modulesCount < 50 || modulesCount % 100 === 0) updateThrottled();
  348. };
  349. // only used when showActiveModules is set
  350. /**
  351. * Processes the provided module.
  352. * @param {Module} module the module
  353. */
  354. const moduleBuild = (module) => {
  355. const ident = module.identifier();
  356. if (ident) {
  357. activeModules.add(ident);
  358. lastActiveModule = ident;
  359. update();
  360. }
  361. };
  362. /**
  363. * Processes the provided entry.
  364. * @param {Dependency} entry entry dependency
  365. * @param {EntryOptions} options options object
  366. */
  367. const entryAdd = (entry, options) => {
  368. entriesCount++;
  369. if (entriesCount < 5 || entriesCount % 10 === 0) updateThrottled();
  370. };
  371. /**
  372. * Processes the provided module.
  373. * @param {Module} module the module
  374. */
  375. const moduleDone = (module) => {
  376. doneModules++;
  377. if (showActiveModules) {
  378. const ident = module.identifier();
  379. if (ident) {
  380. activeModules.delete(ident);
  381. if (lastActiveModule === ident) {
  382. lastActiveModule = "";
  383. for (const m of activeModules) {
  384. lastActiveModule = m;
  385. }
  386. update();
  387. return;
  388. }
  389. }
  390. }
  391. if (doneModules < 50 || doneModules % 100 === 0) updateThrottled();
  392. };
  393. /**
  394. * Processes the provided entry.
  395. * @param {Dependency} entry entry dependency
  396. * @param {EntryOptions} options options object
  397. */
  398. const entryDone = (entry, options) => {
  399. doneEntries++;
  400. update();
  401. };
  402. const cache = compiler.getCache(PLUGIN_NAME).getItemCache("counts", null);
  403. /** @type {Promise<CountsData> | undefined} */
  404. let cacheGetPromise;
  405. compiler.hooks.beforeCompile.tap(PLUGIN_NAME, () => {
  406. if (!cacheGetPromise) {
  407. cacheGetPromise = cache.getPromise().then(
  408. (data) => {
  409. if (data) {
  410. lastModulesCount = lastModulesCount || data.modulesCount;
  411. lastDependenciesCount =
  412. lastDependenciesCount || data.dependenciesCount;
  413. }
  414. return data;
  415. },
  416. (_err) => {
  417. // Ignore error
  418. }
  419. );
  420. }
  421. });
  422. compiler.hooks.afterCompile.tapPromise(PLUGIN_NAME, (compilation) => {
  423. if (compilation.compiler.isChild()) return Promise.resolve();
  424. return /** @type {Promise<CountsData>} */ (cacheGetPromise).then(
  425. async (oldData) => {
  426. const realModulesCount = modulesCount - skippedModulesCount;
  427. const realDependenciesCount =
  428. dependenciesCount - skippedDependenciesCount;
  429. if (
  430. !oldData ||
  431. oldData.modulesCount !== realModulesCount ||
  432. oldData.dependenciesCount !== realDependenciesCount
  433. ) {
  434. await cache.storePromise({
  435. modulesCount: realModulesCount,
  436. dependenciesCount: realDependenciesCount
  437. });
  438. }
  439. }
  440. );
  441. });
  442. compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => {
  443. if (compilation.compiler.isChild()) return;
  444. lastModulesCount = modulesCount;
  445. lastEntriesCount = entriesCount;
  446. lastDependenciesCount = dependenciesCount;
  447. modulesCount =
  448. skippedModulesCount =
  449. dependenciesCount =
  450. skippedDependenciesCount =
  451. entriesCount =
  452. 0;
  453. doneModules = doneDependencies = doneEntries = 0;
  454. compilation.factorizeQueue.hooks.added.tap(PLUGIN_NAME, (item) =>
  455. factorizeAdd(compilation.factorizeQueue, item)
  456. );
  457. compilation.factorizeQueue.hooks.result.tap(PLUGIN_NAME, factorizeDone);
  458. compilation.addModuleQueue.hooks.added.tap(PLUGIN_NAME, (item) =>
  459. moduleAdd(compilation.addModuleQueue, item)
  460. );
  461. compilation.processDependenciesQueue.hooks.result.tap(
  462. PLUGIN_NAME,
  463. moduleDone
  464. );
  465. if (showActiveModules) {
  466. compilation.hooks.buildModule.tap(PLUGIN_NAME, moduleBuild);
  467. }
  468. compilation.hooks.addEntry.tap(PLUGIN_NAME, entryAdd);
  469. compilation.hooks.failedEntry.tap(PLUGIN_NAME, entryDone);
  470. compilation.hooks.succeedEntry.tap(PLUGIN_NAME, entryDone);
  471. // @ts-expect-error avoid dynamic require if bundled with webpack
  472. if (typeof __webpack_require__ !== "function") {
  473. /** @type {Set<string>} */
  474. const requiredLoaders = new Set();
  475. NormalModule.getCompilationHooks(compilation).beforeLoaders.tap(
  476. PLUGIN_NAME,
  477. (loaders) => {
  478. for (const loader of loaders) {
  479. if (
  480. loader.type !== "module" &&
  481. !requiredLoaders.has(loader.loader)
  482. ) {
  483. requiredLoaders.add(loader.loader);
  484. currentLoader = loader.loader;
  485. update();
  486. require(loader.loader);
  487. }
  488. }
  489. if (currentLoader) {
  490. currentLoader = "";
  491. update();
  492. }
  493. }
  494. );
  495. }
  496. const hooks = {
  497. finishModules: "finish module graph",
  498. seal: "plugins",
  499. optimizeDependencies: "dependencies optimization",
  500. afterOptimizeDependencies: "after dependencies optimization",
  501. beforeChunks: "chunk graph",
  502. afterChunks: "after chunk graph",
  503. optimize: "optimizing",
  504. optimizeModules: "module optimization",
  505. afterOptimizeModules: "after module optimization",
  506. optimizeChunks: "chunk optimization",
  507. afterOptimizeChunks: "after chunk optimization",
  508. optimizeTree: "module and chunk tree optimization",
  509. afterOptimizeTree: "after module and chunk tree optimization",
  510. optimizeChunkModules: "chunk modules optimization",
  511. afterOptimizeChunkModules: "after chunk modules optimization",
  512. reviveModules: "module reviving",
  513. beforeModuleIds: "before module ids",
  514. moduleIds: "module ids",
  515. optimizeModuleIds: "module id optimization",
  516. afterOptimizeModuleIds: "module id optimization",
  517. reviveChunks: "chunk reviving",
  518. beforeChunkIds: "before chunk ids",
  519. chunkIds: "chunk ids",
  520. optimizeChunkIds: "chunk id optimization",
  521. afterOptimizeChunkIds: "after chunk id optimization",
  522. recordModules: "record modules",
  523. recordChunks: "record chunks",
  524. beforeModuleHash: "module hashing",
  525. beforeCodeGeneration: "code generation",
  526. beforeRuntimeRequirements: "runtime requirements",
  527. beforeHash: "hashing",
  528. afterHash: "after hashing",
  529. recordHash: "record hash",
  530. beforeModuleAssets: "module assets processing",
  531. beforeChunkAssets: "chunk assets processing",
  532. processAssets: "asset processing",
  533. afterProcessAssets: "after asset optimization",
  534. record: "recording",
  535. afterSeal: "after seal"
  536. };
  537. const numberOfHooks = Object.keys(hooks).length;
  538. for (const [idx, name] of Object.keys(hooks).entries()) {
  539. const title = hooks[/** @type {keyof typeof hooks} */ (name)];
  540. const percentage = (idx / numberOfHooks) * 0.25 + 0.7;
  541. compilation.hooks[/** @type {keyof typeof hooks} */ (name)].intercept({
  542. name: PLUGIN_NAME,
  543. call() {
  544. handler(percentage, "sealing", title);
  545. },
  546. done() {
  547. progressReporters.set(compiler, undefined);
  548. handler(percentage, "sealing", title);
  549. },
  550. result() {
  551. handler(percentage, "sealing", title);
  552. },
  553. error() {
  554. handler(percentage, "sealing", title);
  555. },
  556. tap(tap) {
  557. // p is percentage from 0 to 1
  558. // args is any number of messages in a hierarchical matter
  559. progressReporters.set(compilation.compiler, (p, ...args) => {
  560. handler(percentage, "sealing", title, tap.name, ...args);
  561. });
  562. handler(percentage, "sealing", title, tap.name);
  563. }
  564. });
  565. }
  566. });
  567. compiler.hooks.make.intercept({
  568. name: PLUGIN_NAME,
  569. call() {
  570. handler(0.1, "building");
  571. },
  572. done() {
  573. handler(0.65, "building");
  574. }
  575. });
  576. /**
  577. * Processes the provided hook.
  578. * @template {Hook<EXPECTED_ANY, EXPECTED_ANY, EXPECTED_ANY>} T
  579. * @param {T} hook hook
  580. * @param {number} progress progress from 0 to 1
  581. * @param {string} category category
  582. * @param {string} name name
  583. */
  584. const interceptHook = (hook, progress, category, name) => {
  585. hook.intercept({
  586. name: PLUGIN_NAME,
  587. call() {
  588. handler(progress, category, name);
  589. },
  590. done() {
  591. progressReporters.set(compiler, undefined);
  592. handler(progress, category, name);
  593. },
  594. result() {
  595. handler(progress, category, name);
  596. },
  597. error() {
  598. handler(progress, category, name);
  599. },
  600. /**
  601. * Processes the provided tap.
  602. * @param {Tap} tap tap
  603. */
  604. tap(tap) {
  605. progressReporters.set(compiler, (p, ...args) => {
  606. handler(progress, category, name, tap.name, ...args);
  607. });
  608. handler(progress, category, name, tap.name);
  609. }
  610. });
  611. };
  612. compiler.cache.hooks.endIdle.intercept({
  613. name: PLUGIN_NAME,
  614. call() {
  615. handler(0, "");
  616. }
  617. });
  618. interceptHook(compiler.cache.hooks.endIdle, 0.01, "cache", "end idle");
  619. compiler.hooks.beforeRun.intercept({
  620. name: PLUGIN_NAME,
  621. call() {
  622. handler(0, "");
  623. }
  624. });
  625. interceptHook(compiler.hooks.beforeRun, 0.01, "setup", "before run");
  626. interceptHook(compiler.hooks.run, 0.02, "setup", "run");
  627. interceptHook(compiler.hooks.watchRun, 0.03, "setup", "watch run");
  628. interceptHook(
  629. compiler.hooks.normalModuleFactory,
  630. 0.04,
  631. "setup",
  632. "normal module factory"
  633. );
  634. interceptHook(
  635. compiler.hooks.contextModuleFactory,
  636. 0.05,
  637. "setup",
  638. "context module factory"
  639. );
  640. interceptHook(
  641. compiler.hooks.beforeCompile,
  642. 0.06,
  643. "setup",
  644. "before compile"
  645. );
  646. interceptHook(compiler.hooks.compile, 0.07, "setup", "compile");
  647. interceptHook(compiler.hooks.thisCompilation, 0.08, "setup", "compilation");
  648. interceptHook(compiler.hooks.compilation, 0.09, "setup", "compilation");
  649. interceptHook(compiler.hooks.finishMake, 0.69, "building", "finish");
  650. interceptHook(compiler.hooks.emit, 0.95, "emitting", "emit");
  651. interceptHook(compiler.hooks.afterEmit, 0.98, "emitting", "after emit");
  652. interceptHook(compiler.hooks.done, 0.99, "done", "plugins");
  653. compiler.hooks.done.intercept({
  654. name: PLUGIN_NAME,
  655. done() {
  656. handler(0.99, "");
  657. }
  658. });
  659. interceptHook(
  660. compiler.cache.hooks.storeBuildDependencies,
  661. 0.99,
  662. "cache",
  663. "store build dependencies"
  664. );
  665. interceptHook(compiler.cache.hooks.shutdown, 0.99, "cache", "shutdown");
  666. interceptHook(compiler.cache.hooks.beginIdle, 0.99, "cache", "begin idle");
  667. interceptHook(
  668. compiler.hooks.watchClose,
  669. 0.99,
  670. "end",
  671. "closing watch compilation"
  672. );
  673. compiler.cache.hooks.beginIdle.intercept({
  674. name: PLUGIN_NAME,
  675. done() {
  676. handler(1, "");
  677. }
  678. });
  679. compiler.cache.hooks.shutdown.intercept({
  680. name: PLUGIN_NAME,
  681. done() {
  682. handler(1, "");
  683. }
  684. });
  685. }
  686. }
  687. ProgressPlugin.defaultOptions = DEFAULT_OPTIONS;
  688. ProgressPlugin.createDefaultHandler = createDefaultHandler;
  689. module.exports = ProgressPlugin;