* Applies the plugin by registering its hooks on the compiler. * @param {Compiler} compiler the compiler instance * @returns {void}
(compiler)
| 23 | * @returns {void} |
| 24 | */ |
| 25 | apply(compiler) { |
| 26 | compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => { |
| 27 | compilation.hooks.finishModules.tap(PLUGIN_NAME, (modules) => { |
| 28 | for (const module of modules) { |
| 29 | // 1. if a WebAssembly module |
| 30 | if (module.type.startsWith("webassembly") === true) { |
| 31 | const jsIncompatibleExports = |
| 32 | /** @type {SyncWasmModuleBuildMeta} */ |
| 33 | (module.buildMeta).jsIncompatibleExports; |
| 34 | |
| 35 | if (jsIncompatibleExports === undefined) { |
| 36 | continue; |
| 37 | } |
| 38 | |
| 39 | for (const connection of compilation.moduleGraph.getIncomingConnections( |
| 40 | module |
| 41 | )) { |
| 42 | // 2. is active and referenced by a non-WebAssembly module |
| 43 | if ( |
| 44 | connection.isTargetActive(undefined) && |
| 45 | /** @type {Module} */ |
| 46 | (connection.originModule).type.startsWith("webassembly") === |
| 47 | false |
| 48 | ) { |
| 49 | const referencedExports = |
| 50 | compilation.getDependencyReferencedExports( |
| 51 | /** @type {Dependency} */ (connection.dependency), |
| 52 | undefined |
| 53 | ); |
| 54 | |
| 55 | for (const info of referencedExports) { |
| 56 | const names = Array.isArray(info) ? info : info.name; |
| 57 | if (names.length === 0) continue; |
| 58 | const name = names[0]; |
| 59 | if (typeof name === "object") continue; |
| 60 | // 3. and uses a func with an incompatible JS signature |
| 61 | if ( |
| 62 | Object.prototype.hasOwnProperty.call( |
| 63 | jsIncompatibleExports, |
| 64 | name |
| 65 | ) |
| 66 | ) { |
| 67 | // 4. error |
| 68 | const error = new UnsupportedWebAssemblyFeatureError( |
| 69 | `Export "${name}" with ${jsIncompatibleExports[name]} can only be used for direct wasm to wasm dependencies\n` + |
| 70 | `It's used from ${ |
| 71 | /** @type {Module} */ |
| 72 | (connection.originModule).readableIdentifier( |
| 73 | compilation.requestShortener |
| 74 | ) |
| 75 | } at ${formatLocation( |
| 76 | /** @type {Dependency} */ (connection.dependency).loc |
| 77 | )}.` |
| 78 | ); |
| 79 | error.module = module; |
| 80 | compilation.errors.push(error); |
| 81 | } |
| 82 | } |
nothing calls this directly
no test coverage detected