Files
klz-cables.com/.pnpm-store/v10/files/ee/31315514f5c6e475c515d06bda6b93c5d720f28b110d1edf069775d311dd353fca1d4c41a1c97742638881f9b56ad4253cb103d9f6bb948732eee5fb7cebac
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

76 lines
2.0 KiB
Plaintext

/*
MIT License http://www.opensource.org/licenses/mit-license.php
Author Tobias Koppers @sokra
*/
"use strict";
const { dirname, join } = require("./util/fs");
/** @typedef {import("./Compiler")} Compiler */
/** @typedef {import("./NormalModuleFactory").ResolveData} ResolveData */
/** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */
/** @typedef {(resolveData: ResolveData) => void} ModuleReplacer */
const PLUGIN_NAME = "NormalModuleReplacementPlugin";
class NormalModuleReplacementPlugin {
/**
* Create an instance of the plugin
* @param {RegExp} resourceRegExp the resource matcher
* @param {string | ModuleReplacer} newResource the resource replacement
*/
constructor(resourceRegExp, newResource) {
this.resourceRegExp = resourceRegExp;
this.newResource = newResource;
}
/**
* Apply the plugin
* @param {Compiler} compiler the compiler instance
* @returns {void}
*/
apply(compiler) {
const resourceRegExp = this.resourceRegExp;
const newResource = this.newResource;
compiler.hooks.normalModuleFactory.tap(PLUGIN_NAME, (nmf) => {
nmf.hooks.beforeResolve.tap(PLUGIN_NAME, (result) => {
if (resourceRegExp.test(result.request)) {
if (typeof newResource === "function") {
newResource(result);
} else {
result.request = newResource;
}
}
});
nmf.hooks.afterResolve.tap(PLUGIN_NAME, (result) => {
const createData = result.createData;
if (resourceRegExp.test(/** @type {string} */ (createData.resource))) {
if (typeof newResource === "function") {
newResource(result);
} else {
const fs =
/** @type {InputFileSystem} */
(compiler.inputFileSystem);
if (
newResource.startsWith("/") ||
(newResource.length > 1 && newResource[1] === ":")
) {
createData.resource = newResource;
} else {
createData.resource = join(
fs,
dirname(fs, /** @type {string} */ (createData.resource)),
newResource
);
}
}
}
});
});
}
}
module.exports = NormalModuleReplacementPlugin;