* Applies the plugin by registering its hooks on the compiler. * @param {Compiler} compiler the compiler instance * @returns {void}
(compiler)
| 29 | * @returns {void} |
| 30 | */ |
| 31 | apply(compiler) { |
| 32 | compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => { |
| 33 | const moduleGraph = compilation.moduleGraph; |
| 34 | const cache = compilation.getCache(PLUGIN_NAME); |
| 35 | compilation.hooks.finishModules.tapAsync( |
| 36 | PLUGIN_NAME, |
| 37 | (modules, callback) => { |
| 38 | const logger = compilation.getLogger(PLUGIN_LOGGER_NAME); |
| 39 | let statRestoredFromMemCache = 0; |
| 40 | let statRestoredFromCache = 0; |
| 41 | let statNoExports = 0; |
| 42 | let statFlaggedUncached = 0; |
| 43 | let statNotCached = 0; |
| 44 | let statQueueItemsProcessed = 0; |
| 45 | |
| 46 | const { moduleMemCaches } = compilation; |
| 47 | |
| 48 | /** @type {Queue<Module>} */ |
| 49 | const queue = new Queue(); |
| 50 | |
| 51 | // Step 1: Try to restore cached provided export info from cache |
| 52 | logger.time("restore cached provided exports"); |
| 53 | asyncLib.each( |
| 54 | /** @type {import("neo-async").IterableCollection<Module>} */ ( |
| 55 | /** @type {unknown} */ (modules) |
| 56 | ), |
| 57 | (module, callback) => { |
| 58 | const exportsInfo = moduleGraph.getExportsInfo(module); |
| 59 | // If the module doesn't have an exportsType, it's a module |
| 60 | // without declared exports. |
| 61 | if ( |
| 62 | (!module.buildMeta || !module.buildMeta.exportsType) && |
| 63 | exportsInfo.otherExportsInfo.provided !== null |
| 64 | ) { |
| 65 | // It's a module without declared exports |
| 66 | statNoExports++; |
| 67 | exportsInfo.setHasProvideInfo(); |
| 68 | exportsInfo.setUnknownExportsProvided(); |
| 69 | return callback(); |
| 70 | } |
| 71 | // If the module has no hash, it's uncacheable |
| 72 | if ( |
| 73 | typeof (/** @type {BuildInfo} */ (module.buildInfo).hash) !== |
| 74 | "string" |
| 75 | ) { |
| 76 | statFlaggedUncached++; |
| 77 | // Enqueue uncacheable module for determining the exports |
| 78 | queue.enqueue(module); |
| 79 | exportsInfo.setHasProvideInfo(); |
| 80 | return callback(); |
| 81 | } |
| 82 | const memCache = moduleMemCaches && moduleMemCaches.get(module); |
| 83 | const memCacheValue = memCache && memCache.get(this); |
| 84 | if (memCacheValue !== undefined) { |
| 85 | statRestoredFromMemCache++; |
| 86 | exportsInfo.restoreProvided(memCacheValue); |
| 87 | return callback(); |
| 88 | } |
nothing calls this directly
no test coverage detected