Files
klz-cables.com/.pnpm-store/v10/files/51/eb602d4a1e0981a763a9347afa85ffeaecf8e784e69e47556c013e48a825bcec85600f5ce5ad3b55a8318fff2beeb1840ff3bd3d6ca76d71db4a11af9ddba8
Marc Mintel 5397309103
Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
fix(products): fix breadcrumbs and product filtering (backport from main)
2026-02-24 16:04:21 +01:00

92 lines
2.8 KiB
Plaintext

/*
MIT License http://www.opensource.org/licenses/mit-license.php
Author Tobias Koppers @sokra
*/
"use strict";
const formatLocation = require("../formatLocation");
const UnsupportedWebAssemblyFeatureError = require("./UnsupportedWebAssemblyFeatureError");
/** @typedef {import("../Compiler")} Compiler */
/** @typedef {import("../Dependency")} Dependency */
/** @typedef {import("../Module")} Module */
/** @typedef {import("../Module").BuildMeta} BuildMeta */
const PLUGIN_NAME = "WasmFinalizeExportsPlugin";
class WasmFinalizeExportsPlugin {
/**
* Apply the plugin
* @param {Compiler} compiler the compiler instance
* @returns {void}
*/
apply(compiler) {
compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => {
compilation.hooks.finishModules.tap(PLUGIN_NAME, (modules) => {
for (const module of modules) {
// 1. if a WebAssembly module
if (module.type.startsWith("webassembly") === true) {
const jsIncompatibleExports =
/** @type {BuildMeta} */
(module.buildMeta).jsIncompatibleExports;
if (jsIncompatibleExports === undefined) {
continue;
}
for (const connection of compilation.moduleGraph.getIncomingConnections(
module
)) {
// 2. is active and referenced by a non-WebAssembly module
if (
connection.isTargetActive(undefined) &&
/** @type {Module} */
(connection.originModule).type.startsWith("webassembly") ===
false
) {
const referencedExports =
compilation.getDependencyReferencedExports(
/** @type {Dependency} */ (connection.dependency),
undefined
);
for (const info of referencedExports) {
const names = Array.isArray(info) ? info : info.name;
if (names.length === 0) continue;
const name = names[0];
if (typeof name === "object") continue;
// 3. and uses a func with an incompatible JS signature
if (
Object.prototype.hasOwnProperty.call(
jsIncompatibleExports,
name
)
) {
// 4. error
const error = new UnsupportedWebAssemblyFeatureError(
`Export "${name}" with ${jsIncompatibleExports[name]} can only be used for direct wasm to wasm dependencies\n` +
`It's used from ${
/** @type {Module} */
(connection.originModule).readableIdentifier(
compilation.requestShortener
)
} at ${formatLocation(
/** @type {Dependency} */ (connection.dependency).loc
)}.`
);
error.module = module;
compilation.errors.push(error);
}
}
}
}
}
}
});
});
}
}
module.exports = WasmFinalizeExportsPlugin;