diff --git a/lib/cache/PackFileCacheStrategy.js b/lib/cache/PackFileCacheStrategy.js index a5047321e95..75191854af8 100644 --- a/lib/cache/PackFileCacheStrategy.js +++ b/lib/cache/PackFileCacheStrategy.js @@ -8,6 +8,7 @@ const FileSystemInfo = require("../FileSystemInfo"); const ProgressPlugin = require("../ProgressPlugin"); const { formatSize } = require("../SizeFormatHelpers"); +const SerializerMiddleware = require("../serialization/SerializerMiddleware"); const LazySet = require("../util/LazySet"); const makeSerializable = require("../util/makeSerializable"); const memoize = require("../util/memoize"); @@ -715,6 +716,7 @@ class PackContent { this.logger.timeEnd(timeMessage); } this.content = map; + this.lazy = SerializerMiddleware.unMemoizeLazy(this.lazy); return map.get(identifier); }); } else { @@ -723,6 +725,7 @@ class PackContent { this.logger.timeEnd(timeMessage); } this.content = map; + this.lazy = SerializerMiddleware.unMemoizeLazy(this.lazy); return map.get(identifier); } } diff --git a/lib/serialization/SerializerMiddleware.js b/lib/serialization/SerializerMiddleware.js index f9d79ed833f..3b8e2d0dd36 100644 --- a/lib/serialization/SerializerMiddleware.js +++ b/lib/serialization/SerializerMiddleware.js @@ -126,6 +126,25 @@ class SerializerMiddleware { fn[LAZY_SERIALIZED_VALUE] = lazy; return fn; } + + /** + * @param {function(): Promise | any} lazy lazy function + * @returns {function(): Promise | any} new lazy + */ + static unMemoizeLazy(lazy) { + if (!SerializerMiddleware.isLazy(lazy)) return lazy; + const fn = () => { + throw new Error( + "A lazy value that has been unmemorized can't be called again" + ); + }; + fn[LAZY_SERIALIZED_VALUE] = SerializerMiddleware.unMemoizeLazy( + lazy[LAZY_SERIALIZED_VALUE] + ); + fn[LAZY_TARGET] = lazy[LAZY_TARGET]; + fn.options = /** @type {any} */ (lazy).options; + return fn; + } } module.exports = SerializerMiddleware;