[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 Dependency = require("../Dependency");
|
---|
| 9 | const makeSerializable = require("../util/makeSerializable");
|
---|
| 10 |
|
---|
| 11 | /** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
---|
| 12 | /** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
---|
| 13 |
|
---|
| 14 | class ProvideSharedDependency extends Dependency {
|
---|
| 15 | /**
|
---|
| 16 | * @param {string} shareScope share scope
|
---|
| 17 | * @param {string} name module name
|
---|
| 18 | * @param {string | false} version version
|
---|
| 19 | * @param {string} request request
|
---|
| 20 | * @param {boolean} eager true, if this is an eager dependency
|
---|
| 21 | */
|
---|
| 22 | constructor(shareScope, name, version, request, eager) {
|
---|
| 23 | super();
|
---|
| 24 | this.shareScope = shareScope;
|
---|
| 25 | this.name = name;
|
---|
| 26 | this.version = version;
|
---|
| 27 | this.request = request;
|
---|
| 28 | this.eager = eager;
|
---|
| 29 | }
|
---|
| 30 |
|
---|
| 31 | get type() {
|
---|
| 32 | return "provide shared module";
|
---|
| 33 | }
|
---|
| 34 |
|
---|
| 35 | /**
|
---|
| 36 | * @returns {string | null} an identifier to merge equal requests
|
---|
| 37 | */
|
---|
| 38 | getResourceIdentifier() {
|
---|
| 39 | return `provide module (${this.shareScope}) ${this.request} as ${
|
---|
| 40 | this.name
|
---|
| 41 | } @ ${this.version}${this.eager ? " (eager)" : ""}`;
|
---|
| 42 | }
|
---|
| 43 |
|
---|
| 44 | /**
|
---|
| 45 | * @param {ObjectSerializerContext} context context
|
---|
| 46 | */
|
---|
| 47 | serialize(context) {
|
---|
| 48 | context.write(this.shareScope);
|
---|
| 49 | context.write(this.name);
|
---|
| 50 | context.write(this.request);
|
---|
| 51 | context.write(this.version);
|
---|
| 52 | context.write(this.eager);
|
---|
| 53 | super.serialize(context);
|
---|
| 54 | }
|
---|
| 55 |
|
---|
| 56 | /**
|
---|
| 57 | * @param {ObjectDeserializerContext} context context
|
---|
| 58 | * @returns {ProvideSharedDependency} deserialize fallback dependency
|
---|
| 59 | */
|
---|
| 60 | static deserialize(context) {
|
---|
| 61 | const { read } = context;
|
---|
| 62 | const obj = new ProvideSharedDependency(
|
---|
| 63 | read(),
|
---|
| 64 | read(),
|
---|
| 65 | read(),
|
---|
| 66 | read(),
|
---|
| 67 | read()
|
---|
| 68 | );
|
---|
| 69 | this.shareScope = context.read();
|
---|
| 70 | obj.deserialize(context);
|
---|
| 71 | return obj;
|
---|
| 72 | }
|
---|
| 73 | }
|
---|
| 74 |
|
---|
| 75 | makeSerializable(
|
---|
| 76 | ProvideSharedDependency,
|
---|
| 77 | "webpack/lib/sharing/ProvideSharedDependency"
|
---|
| 78 | );
|
---|
| 79 |
|
---|
| 80 | module.exports = ProvideSharedDependency;
|
---|