(compiler)
| 11 | * @param {import("../../../../").Compiler} compiler the compiler |
| 12 | */ |
| 13 | const testPlugin = (compiler) => { |
| 14 | compiler.hooks.compilation.tap("TestPlugin", (compilation) => { |
| 15 | let shouldReplace = false; |
| 16 | NormalModule.getCompilationHooks(compilation).loader.tap( |
| 17 | "TestPlugin", |
| 18 | (loaderContext) => { |
| 19 | /** @type {EXPECTED_ANY} */ |
| 20 | (loaderContext).shouldReplace = shouldReplace; |
| 21 | } |
| 22 | ); |
| 23 | compilation.hooks.finishModules.tapAsync( |
| 24 | "TestPlugin", |
| 25 | (modules, callback) => { |
| 26 | const src = resolve(join(__dirname, "other-file.js")); |
| 27 | |
| 28 | /** |
| 29 | * @param {Module} m test |
| 30 | * @returns {boolean | string} test |
| 31 | */ |
| 32 | function matcher(m) { |
| 33 | return ( |
| 34 | /** @type {NormalModule} */ (m).resource && |
| 35 | /** @type {NormalModule} */ (m).resource === src |
| 36 | ); |
| 37 | } |
| 38 | |
| 39 | const module = [...modules].find(matcher); |
| 40 | |
| 41 | if (!module) { |
| 42 | throw new Error("something went wrong"); |
| 43 | } |
| 44 | |
| 45 | // Check if already build the updated version |
| 46 | // this will happen when using caching |
| 47 | if ( |
| 48 | /** @type {NonNullable<Module["buildInfo"]>} */ |
| 49 | (module.buildInfo)._isReplaced |
| 50 | ) { |
| 51 | return callback(); |
| 52 | } |
| 53 | |
| 54 | shouldReplace = true; |
| 55 | compilation.rebuildModule(module, (err) => { |
| 56 | shouldReplace = false; |
| 57 | callback(err); |
| 58 | }); |
| 59 | } |
| 60 | ); |
| 61 | }); |
| 62 | }; |
| 63 | |
| 64 | /** @type {import("../../../../").Configuration} */ |
| 65 | module.exports = { |
nothing calls this directly
no test coverage detected