[6a3a178] | 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("../Dependency")} Dependency */
|
---|
| 13 | /** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
|
---|
| 14 |
|
---|
| 15 | class RequireResolveHeaderDependency extends NullDependency {
|
---|
| 16 | constructor(range) {
|
---|
| 17 | super();
|
---|
| 18 |
|
---|
| 19 | if (!Array.isArray(range)) throw new Error("range must be valid");
|
---|
| 20 |
|
---|
| 21 | this.range = range;
|
---|
| 22 | }
|
---|
| 23 |
|
---|
| 24 | serialize(context) {
|
---|
| 25 | const { write } = context;
|
---|
| 26 |
|
---|
| 27 | write(this.range);
|
---|
| 28 |
|
---|
| 29 | super.serialize(context);
|
---|
| 30 | }
|
---|
| 31 |
|
---|
| 32 | static deserialize(context) {
|
---|
| 33 | const obj = new RequireResolveHeaderDependency(context.read());
|
---|
| 34 | obj.deserialize(context);
|
---|
| 35 | return obj;
|
---|
| 36 | }
|
---|
| 37 | }
|
---|
| 38 |
|
---|
| 39 | makeSerializable(
|
---|
| 40 | RequireResolveHeaderDependency,
|
---|
| 41 | "webpack/lib/dependencies/RequireResolveHeaderDependency"
|
---|
| 42 | );
|
---|
| 43 |
|
---|
| 44 | RequireResolveHeaderDependency.Template = class RequireResolveHeaderDependencyTemplate extends (
|
---|
| 45 | NullDependency.Template
|
---|
| 46 | ) {
|
---|
| 47 | /**
|
---|
| 48 | * @param {Dependency} dependency the dependency for which the template should be applied
|
---|
| 49 | * @param {ReplaceSource} source the current replace source which can be modified
|
---|
| 50 | * @param {DependencyTemplateContext} templateContext the context object
|
---|
| 51 | * @returns {void}
|
---|
| 52 | */
|
---|
| 53 | apply(dependency, source, templateContext) {
|
---|
| 54 | const dep = /** @type {RequireResolveHeaderDependency} */ (dependency);
|
---|
| 55 | source.replace(dep.range[0], dep.range[1] - 1, "/*require.resolve*/");
|
---|
| 56 | }
|
---|
| 57 |
|
---|
| 58 | applyAsTemplateArgument(name, dep, source) {
|
---|
| 59 | source.replace(dep.range[0], dep.range[1] - 1, "/*require.resolve*/");
|
---|
| 60 | }
|
---|
| 61 | };
|
---|
| 62 |
|
---|
| 63 | module.exports = RequireResolveHeaderDependency;
|
---|