/
githubmirror
/
webpack
Обзор
Документация
Войти
/
githubmirror
/
webpack
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
lib/cache/MemoryCachePlugin.js
66 строк
2 KB
Alexander Akait
fix(css): terminate a string or url() the tokenizer closed at EOF (#21624)
07 авг 2026, 16:56
Не верифицирован
07 авг 2026, 16:56
21af4f5
Код
Авторство
О чём код?
/* MIT License http://www.opensource.org/licenses/mit-license.php Author Tobias Koppers @sokra */ "use strict"; const Cache = require("../Cache"); /** @typedef {import("../Cache").Data} Data */ /** @typedef {import("../Cache").Etag} Etag */ /** @typedef {import("../Compiler")} Compiler */ class MemoryCachePlugin { /** * Applies the plugin by registering its hooks on the compiler. * @param {Compiler} compiler the compiler instance * @returns {void} */ apply(compiler) { /** @type {Map<string, { etag: Etag | null, data: Data } | null>} */ const cache = new Map(); compiler.cache.hooks.store.tap( { name: "MemoryCachePlugin", stage: Cache.STAGE_MEMORY }, (identifier, etag, data) => { cache.set(identifier, { etag, data }); } ); compiler.cache.hooks.get.tap( { name: "MemoryCachePlugin", stage: Cache.STAGE_MEMORY }, (identifier, etag, gotHandlers) => { const cacheEntry = cache.get(identifier); // A recorded miss: the whole chain was asked for this identifier already. if (cacheEntry === null) return null; // Etags are compared by identity — a lazy one is interned per source // object, so equal content reached through a second object is a // different etag. Hashing to tell those apart would cost every hit what // laziness saves, so a mismatch falls through to the next stage instead: // the file cache compares etags by value and can still answer. Returning // `null` here would bail the hook and lose that (`Cache.get` maps it to // `undefined` regardless, so it buys the caller nothing). if (cacheEntry !== undefined && cacheEntry.etag === etag) { return cacheEntry.data; } gotHandlers.push((result, callback) => { if (result !== undefined) { cache.set(identifier, { etag, data: result }); } else if (cacheEntry === undefined) { // Record the miss only for an identifier nothing was known about: // an entry reached with a different etag still answers its own. cache.set(identifier, null); } return callback(); }); } ); compiler.cache.hooks.shutdown.tap( { name: "MemoryCachePlugin", stage: Cache.STAGE_MEMORY }, () => { cache.clear(); } ); } } module.exports = MemoryCachePlugin;