[79a0317] | 1 | /*
|
---|
| 2 | MIT License http://www.opensource.org/licenses/mit-license.php
|
---|
| 3 | Author Tobias Koppers @sokra
|
---|
| 4 | */
|
---|
| 5 |
|
---|
| 6 | "use strict";
|
---|
| 7 |
|
---|
| 8 | const makeSerializable = require("../util/makeSerializable");
|
---|
| 9 | const NullDependency = require("./NullDependency");
|
---|
| 10 |
|
---|
| 11 | /** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
|
---|
| 12 | /** @typedef {import("../ChunkGraph")} ChunkGraph */
|
---|
| 13 | /** @typedef {import("../Dependency")} Dependency */
|
---|
| 14 | /** @typedef {import("../Dependency").UpdateHashContext} UpdateHashContext */
|
---|
| 15 | /** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
|
---|
| 16 | /** @typedef {import("../ModuleGraph")} ModuleGraph */
|
---|
| 17 | /** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
---|
| 18 | /** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
---|
| 19 | /** @typedef {import("../util/Hash")} Hash */
|
---|
| 20 |
|
---|
| 21 | class RuntimeRequirementsDependency extends NullDependency {
|
---|
| 22 | /**
|
---|
| 23 | * @param {string[]} runtimeRequirements runtime requirements
|
---|
| 24 | */
|
---|
| 25 | constructor(runtimeRequirements) {
|
---|
| 26 | super();
|
---|
| 27 | this.runtimeRequirements = new Set(runtimeRequirements);
|
---|
| 28 | this._hashUpdate = undefined;
|
---|
| 29 | }
|
---|
| 30 |
|
---|
| 31 | /**
|
---|
| 32 | * Update the hash
|
---|
| 33 | * @param {Hash} hash hash to be updated
|
---|
| 34 | * @param {UpdateHashContext} context context
|
---|
| 35 | * @returns {void}
|
---|
| 36 | */
|
---|
| 37 | updateHash(hash, context) {
|
---|
| 38 | if (this._hashUpdate === undefined) {
|
---|
| 39 | this._hashUpdate = `${Array.from(this.runtimeRequirements).join()}`;
|
---|
| 40 | }
|
---|
| 41 | hash.update(this._hashUpdate);
|
---|
| 42 | }
|
---|
| 43 |
|
---|
| 44 | /**
|
---|
| 45 | * @param {ObjectSerializerContext} context context
|
---|
| 46 | */
|
---|
| 47 | serialize(context) {
|
---|
| 48 | const { write } = context;
|
---|
| 49 | write(this.runtimeRequirements);
|
---|
| 50 | super.serialize(context);
|
---|
| 51 | }
|
---|
| 52 |
|
---|
| 53 | /**
|
---|
| 54 | * @param {ObjectDeserializerContext} context context
|
---|
| 55 | */
|
---|
| 56 | deserialize(context) {
|
---|
| 57 | const { read } = context;
|
---|
| 58 | this.runtimeRequirements = read();
|
---|
| 59 | super.deserialize(context);
|
---|
| 60 | }
|
---|
| 61 | }
|
---|
| 62 |
|
---|
| 63 | makeSerializable(
|
---|
| 64 | RuntimeRequirementsDependency,
|
---|
| 65 | "webpack/lib/dependencies/RuntimeRequirementsDependency"
|
---|
| 66 | );
|
---|
| 67 |
|
---|
| 68 | RuntimeRequirementsDependency.Template = class RuntimeRequirementsDependencyTemplate extends (
|
---|
| 69 | NullDependency.Template
|
---|
| 70 | ) {
|
---|
| 71 | /**
|
---|
| 72 | * @param {Dependency} dependency the dependency for which the template should be applied
|
---|
| 73 | * @param {ReplaceSource} source the current replace source which can be modified
|
---|
| 74 | * @param {DependencyTemplateContext} templateContext the context object
|
---|
| 75 | * @returns {void}
|
---|
| 76 | */
|
---|
| 77 | apply(dependency, source, { runtimeRequirements }) {
|
---|
| 78 | const dep = /** @type {RuntimeRequirementsDependency} */ (dependency);
|
---|
| 79 | for (const req of dep.runtimeRequirements) {
|
---|
| 80 | runtimeRequirements.add(req);
|
---|
| 81 | }
|
---|
| 82 | }
|
---|
| 83 | };
|
---|
| 84 |
|
---|
| 85 | module.exports = RuntimeRequirementsDependency;
|
---|