/
githubmirror
/
webpack
Обзор
Документация
Войти
/
githubmirror
/
webpack
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
lib/dependencies/RuntimeRequirementsDependency.js
88 строк
3 KB
Alexander Akait
refactor: annotate constructor fields with @type to improve type coverage (#21265)
24 июн 2026, 13:36
Не верифицирован
24 июн 2026, 13:36
e8f9334
Код
Авторство
О чём код?
/* MIT License http://www.opensource.org/licenses/mit-license.php Author Tobias Koppers @sokra */ "use strict"; const makeSerializable = require("../util/makeSerializable"); const NullDependency = require("./NullDependency"); /** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */ /** @typedef {import("./NullDependency").RawRuntimeRequirements} RawRuntimeRequirements */ /** @typedef {import("../Dependency")} Dependency */ /** @typedef {import("../Dependency").UpdateHashContext} UpdateHashContext */ /** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */ /** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext<[Set<string>]>} ObjectDeserializerContext */ /** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext<[Set<string>]>} ObjectSerializerContext */ /** @typedef {import("../util/Hash")} Hash */ class RuntimeRequirementsDependency extends NullDependency { /** * Creates an instance of RuntimeRequirementsDependency. * @param {RawRuntimeRequirements} runtimeRequirements runtime requirements */ constructor(runtimeRequirements) { super(); /** @type {Set<string>} */ this.runtimeRequirements = new Set(runtimeRequirements); /** @type {undefined | string} */ this._hashUpdate = undefined; } /** * Updates the hash with the data contributed by this instance. * @param {Hash} hash hash to be updated * @param {UpdateHashContext} context context * @returns {void} */ updateHash(hash, context) { if (this._hashUpdate === undefined) { this._hashUpdate = `${[...this.runtimeRequirements].join()}`; } hash.update(this._hashUpdate); } /** * Serializes this instance into the provided serializer context. * @param {ObjectSerializerContext} context context */ serialize(context) { context.write(this.runtimeRequirements); super.serialize(context); } /** * Restores this instance from the provided deserializer context. * @param {ObjectDeserializerContext} context context */ deserialize(context) { this.runtimeRequirements = context.read(); super.deserialize(context.rest); } } makeSerializable( RuntimeRequirementsDependency, "webpack/lib/dependencies/RuntimeRequirementsDependency" ); RuntimeRequirementsDependency.Template = class RuntimeRequirementsDependencyTemplate extends ( NullDependency.Template ) { /** * Applies the plugin by registering its hooks on the compiler. * @param {Dependency} dependency the dependency for which the template should be applied * @param {ReplaceSource} source the current replace source which can be modified * @param {DependencyTemplateContext} templateContext the context object * @returns {void} */ apply(dependency, source, { runtimeRequirements }) { const dep = /** @type {RuntimeRequirementsDependency} */ (dependency); for (const req of dep.runtimeRequirements) { runtimeRequirements.add(req); } } }; module.exports = RuntimeRequirementsDependency;