$
This commit is contained in:
253
node_modules/webpack/lib/APIPlugin.js
generated
vendored
Normal file
253
node_modules/webpack/lib/APIPlugin.js
generated
vendored
Normal file
@@ -0,0 +1,253 @@
|
||||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
const RuntimeGlobals = require("./RuntimeGlobals");
|
||||
const WebpackError = require("./WebpackError");
|
||||
const ConstDependency = require("./dependencies/ConstDependency");
|
||||
const BasicEvaluatedExpression = require("./javascript/BasicEvaluatedExpression");
|
||||
const {
|
||||
toConstantDependency,
|
||||
evaluateToString
|
||||
} = require("./javascript/JavascriptParserHelpers");
|
||||
const ChunkNameRuntimeModule = require("./runtime/ChunkNameRuntimeModule");
|
||||
const GetFullHashRuntimeModule = require("./runtime/GetFullHashRuntimeModule");
|
||||
|
||||
/** @typedef {import("./Compiler")} Compiler */
|
||||
/** @typedef {import("./javascript/JavascriptParser")} JavascriptParser */
|
||||
|
||||
/* eslint-disable camelcase */
|
||||
const REPLACEMENTS = {
|
||||
__webpack_require__: {
|
||||
expr: RuntimeGlobals.require,
|
||||
req: [RuntimeGlobals.require],
|
||||
type: "function",
|
||||
assign: false
|
||||
},
|
||||
__webpack_public_path__: {
|
||||
expr: RuntimeGlobals.publicPath,
|
||||
req: [RuntimeGlobals.publicPath],
|
||||
type: "string",
|
||||
assign: true
|
||||
},
|
||||
__webpack_base_uri__: {
|
||||
expr: RuntimeGlobals.baseURI,
|
||||
req: [RuntimeGlobals.baseURI],
|
||||
type: "string",
|
||||
assign: true
|
||||
},
|
||||
__webpack_modules__: {
|
||||
expr: RuntimeGlobals.moduleFactories,
|
||||
req: [RuntimeGlobals.moduleFactories],
|
||||
type: "object",
|
||||
assign: false
|
||||
},
|
||||
__webpack_chunk_load__: {
|
||||
expr: RuntimeGlobals.ensureChunk,
|
||||
req: [RuntimeGlobals.ensureChunk],
|
||||
type: "function",
|
||||
assign: true
|
||||
},
|
||||
__non_webpack_require__: {
|
||||
expr: "require",
|
||||
req: null,
|
||||
type: undefined, // type is not known, depends on environment
|
||||
assign: true
|
||||
},
|
||||
__webpack_nonce__: {
|
||||
expr: RuntimeGlobals.scriptNonce,
|
||||
req: [RuntimeGlobals.scriptNonce],
|
||||
type: "string",
|
||||
assign: true
|
||||
},
|
||||
__webpack_hash__: {
|
||||
expr: `${RuntimeGlobals.getFullHash}()`,
|
||||
req: [RuntimeGlobals.getFullHash],
|
||||
type: "string",
|
||||
assign: false
|
||||
},
|
||||
__webpack_chunkname__: {
|
||||
expr: RuntimeGlobals.chunkName,
|
||||
req: [RuntimeGlobals.chunkName],
|
||||
type: "string",
|
||||
assign: false
|
||||
},
|
||||
__webpack_get_script_filename__: {
|
||||
expr: RuntimeGlobals.getChunkScriptFilename,
|
||||
req: [RuntimeGlobals.getChunkScriptFilename],
|
||||
type: "function",
|
||||
assign: true
|
||||
},
|
||||
__webpack_runtime_id__: {
|
||||
expr: RuntimeGlobals.runtimeId,
|
||||
req: [RuntimeGlobals.runtimeId],
|
||||
assign: false
|
||||
},
|
||||
"require.onError": {
|
||||
expr: RuntimeGlobals.uncaughtErrorHandler,
|
||||
req: [RuntimeGlobals.uncaughtErrorHandler],
|
||||
type: undefined, // type is not known, could be function or undefined
|
||||
assign: true // is never a pattern
|
||||
},
|
||||
__system_context__: {
|
||||
expr: RuntimeGlobals.systemContext,
|
||||
req: [RuntimeGlobals.systemContext],
|
||||
type: "object",
|
||||
assign: false
|
||||
},
|
||||
__webpack_share_scopes__: {
|
||||
expr: RuntimeGlobals.shareScopeMap,
|
||||
req: [RuntimeGlobals.shareScopeMap],
|
||||
type: "object",
|
||||
assign: false
|
||||
},
|
||||
__webpack_init_sharing__: {
|
||||
expr: RuntimeGlobals.initializeSharing,
|
||||
req: [RuntimeGlobals.initializeSharing],
|
||||
type: "function",
|
||||
assign: true
|
||||
}
|
||||
};
|
||||
/* eslint-enable camelcase */
|
||||
|
||||
class APIPlugin {
|
||||
/**
|
||||
* Apply the plugin
|
||||
* @param {Compiler} compiler the compiler instance
|
||||
* @returns {void}
|
||||
*/
|
||||
apply(compiler) {
|
||||
compiler.hooks.compilation.tap(
|
||||
"APIPlugin",
|
||||
(compilation, { normalModuleFactory }) => {
|
||||
compilation.dependencyTemplates.set(
|
||||
ConstDependency,
|
||||
new ConstDependency.Template()
|
||||
);
|
||||
|
||||
compilation.hooks.runtimeRequirementInTree
|
||||
.for(RuntimeGlobals.chunkName)
|
||||
.tap("APIPlugin", chunk => {
|
||||
compilation.addRuntimeModule(
|
||||
chunk,
|
||||
new ChunkNameRuntimeModule(chunk.name)
|
||||
);
|
||||
return true;
|
||||
});
|
||||
|
||||
compilation.hooks.runtimeRequirementInTree
|
||||
.for(RuntimeGlobals.getFullHash)
|
||||
.tap("APIPlugin", (chunk, set) => {
|
||||
compilation.addRuntimeModule(chunk, new GetFullHashRuntimeModule());
|
||||
return true;
|
||||
});
|
||||
|
||||
/**
|
||||
* @param {JavascriptParser} parser the parser
|
||||
*/
|
||||
const handler = parser => {
|
||||
Object.keys(REPLACEMENTS).forEach(key => {
|
||||
const info = REPLACEMENTS[key];
|
||||
parser.hooks.expression
|
||||
.for(key)
|
||||
.tap(
|
||||
"APIPlugin",
|
||||
toConstantDependency(parser, info.expr, info.req)
|
||||
);
|
||||
if (info.assign === false) {
|
||||
parser.hooks.assign.for(key).tap("APIPlugin", expr => {
|
||||
const err = new WebpackError(`${key} must not be assigned`);
|
||||
err.loc = expr.loc;
|
||||
throw err;
|
||||
});
|
||||
}
|
||||
if (info.type) {
|
||||
parser.hooks.evaluateTypeof
|
||||
.for(key)
|
||||
.tap("APIPlugin", evaluateToString(info.type));
|
||||
}
|
||||
});
|
||||
|
||||
parser.hooks.expression
|
||||
.for("__webpack_layer__")
|
||||
.tap("APIPlugin", expr => {
|
||||
const dep = new ConstDependency(
|
||||
JSON.stringify(parser.state.module.layer),
|
||||
expr.range
|
||||
);
|
||||
dep.loc = expr.loc;
|
||||
parser.state.module.addPresentationalDependency(dep);
|
||||
return true;
|
||||
});
|
||||
parser.hooks.evaluateIdentifier
|
||||
.for("__webpack_layer__")
|
||||
.tap("APIPlugin", expr =>
|
||||
(parser.state.module.layer === null
|
||||
? new BasicEvaluatedExpression().setNull()
|
||||
: new BasicEvaluatedExpression().setString(
|
||||
parser.state.module.layer
|
||||
)
|
||||
).setRange(expr.range)
|
||||
);
|
||||
parser.hooks.evaluateTypeof
|
||||
.for("__webpack_layer__")
|
||||
.tap("APIPlugin", expr =>
|
||||
new BasicEvaluatedExpression()
|
||||
.setString(
|
||||
parser.state.module.layer === null ? "object" : "string"
|
||||
)
|
||||
.setRange(expr.range)
|
||||
);
|
||||
|
||||
parser.hooks.expression
|
||||
.for("__webpack_module__.id")
|
||||
.tap("APIPlugin", expr => {
|
||||
parser.state.module.buildInfo.moduleConcatenationBailout =
|
||||
"__webpack_module__.id";
|
||||
const dep = new ConstDependency(
|
||||
parser.state.module.moduleArgument + ".id",
|
||||
expr.range,
|
||||
[RuntimeGlobals.moduleId]
|
||||
);
|
||||
dep.loc = expr.loc;
|
||||
parser.state.module.addPresentationalDependency(dep);
|
||||
return true;
|
||||
});
|
||||
|
||||
parser.hooks.expression
|
||||
.for("__webpack_module__")
|
||||
.tap("APIPlugin", expr => {
|
||||
parser.state.module.buildInfo.moduleConcatenationBailout =
|
||||
"__webpack_module__";
|
||||
const dep = new ConstDependency(
|
||||
parser.state.module.moduleArgument,
|
||||
expr.range,
|
||||
[RuntimeGlobals.module]
|
||||
);
|
||||
dep.loc = expr.loc;
|
||||
parser.state.module.addPresentationalDependency(dep);
|
||||
return true;
|
||||
});
|
||||
parser.hooks.evaluateTypeof
|
||||
.for("__webpack_module__")
|
||||
.tap("APIPlugin", evaluateToString("object"));
|
||||
};
|
||||
|
||||
normalModuleFactory.hooks.parser
|
||||
.for("javascript/auto")
|
||||
.tap("APIPlugin", handler);
|
||||
normalModuleFactory.hooks.parser
|
||||
.for("javascript/dynamic")
|
||||
.tap("APIPlugin", handler);
|
||||
normalModuleFactory.hooks.parser
|
||||
.for("javascript/esm")
|
||||
.tap("APIPlugin", handler);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = APIPlugin;
|
49
node_modules/webpack/lib/AbstractMethodError.js
generated
vendored
Normal file
49
node_modules/webpack/lib/AbstractMethodError.js
generated
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Ivan Kopeykin @vankop
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
const WebpackError = require("./WebpackError");
|
||||
const CURRENT_METHOD_REGEXP = /at ([a-zA-Z0-9_.]*)/;
|
||||
|
||||
/**
|
||||
* @param {string=} method method name
|
||||
* @returns {string} message
|
||||
*/
|
||||
function createMessage(method) {
|
||||
return `Abstract method${method ? " " + method : ""}. Must be overridden.`;
|
||||
}
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
*/
|
||||
function Message() {
|
||||
/** @type {string} */
|
||||
this.stack = undefined;
|
||||
Error.captureStackTrace(this);
|
||||
/** @type {RegExpMatchArray} */
|
||||
const match = this.stack.split("\n")[3].match(CURRENT_METHOD_REGEXP);
|
||||
|
||||
this.message = match && match[1] ? createMessage(match[1]) : createMessage();
|
||||
}
|
||||
|
||||
/**
|
||||
* Error for abstract method
|
||||
* @example
|
||||
* class FooClass {
|
||||
* abstractMethod() {
|
||||
* throw new AbstractMethodError(); // error message: Abstract method FooClass.abstractMethod. Must be overridden.
|
||||
* }
|
||||
* }
|
||||
*
|
||||
*/
|
||||
class AbstractMethodError extends WebpackError {
|
||||
constructor() {
|
||||
super(new Message().message);
|
||||
this.name = "AbstractMethodError";
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = AbstractMethodError;
|
106
node_modules/webpack/lib/AsyncDependenciesBlock.js
generated
vendored
Normal file
106
node_modules/webpack/lib/AsyncDependenciesBlock.js
generated
vendored
Normal file
@@ -0,0 +1,106 @@
|
||||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
const DependenciesBlock = require("./DependenciesBlock");
|
||||
const makeSerializable = require("./util/makeSerializable");
|
||||
|
||||
/** @typedef {import("./ChunkGraph")} ChunkGraph */
|
||||
/** @typedef {import("./ChunkGroup")} ChunkGroup */
|
||||
/** @typedef {import("./ChunkGroup").ChunkGroupOptions} ChunkGroupOptions */
|
||||
/** @typedef {import("./Dependency").DependencyLocation} DependencyLocation */
|
||||
/** @typedef {import("./Dependency").UpdateHashContext} UpdateHashContext */
|
||||
/** @typedef {import("./Entrypoint").EntryOptions} EntryOptions */
|
||||
/** @typedef {import("./Module")} Module */
|
||||
/** @typedef {import("./util/Hash")} Hash */
|
||||
|
||||
class AsyncDependenciesBlock extends DependenciesBlock {
|
||||
/**
|
||||
* @param {ChunkGroupOptions & { entryOptions?: EntryOptions }} groupOptions options for the group
|
||||
* @param {DependencyLocation=} loc the line of code
|
||||
* @param {string=} request the request
|
||||
*/
|
||||
constructor(groupOptions, loc, request) {
|
||||
super();
|
||||
if (typeof groupOptions === "string") {
|
||||
groupOptions = { name: groupOptions };
|
||||
} else if (!groupOptions) {
|
||||
groupOptions = { name: undefined };
|
||||
}
|
||||
this.groupOptions = groupOptions;
|
||||
this.loc = loc;
|
||||
this.request = request;
|
||||
this._stringifiedGroupOptions = undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {string} The name of the chunk
|
||||
*/
|
||||
get chunkName() {
|
||||
return this.groupOptions.name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} value The new chunk name
|
||||
* @returns {void}
|
||||
*/
|
||||
set chunkName(value) {
|
||||
if (this.groupOptions.name !== value) {
|
||||
this.groupOptions.name = value;
|
||||
this._stringifiedGroupOptions = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Hash} hash the hash used to track dependencies
|
||||
* @param {UpdateHashContext} context context
|
||||
* @returns {void}
|
||||
*/
|
||||
updateHash(hash, context) {
|
||||
const { chunkGraph } = context;
|
||||
if (this._stringifiedGroupOptions === undefined) {
|
||||
this._stringifiedGroupOptions = JSON.stringify(this.groupOptions);
|
||||
}
|
||||
const chunkGroup = chunkGraph.getBlockChunkGroup(this);
|
||||
hash.update(
|
||||
`${this._stringifiedGroupOptions}${chunkGroup ? chunkGroup.id : ""}`
|
||||
);
|
||||
super.updateHash(hash, context);
|
||||
}
|
||||
|
||||
serialize(context) {
|
||||
const { write } = context;
|
||||
write(this.groupOptions);
|
||||
write(this.loc);
|
||||
write(this.request);
|
||||
super.serialize(context);
|
||||
}
|
||||
|
||||
deserialize(context) {
|
||||
const { read } = context;
|
||||
this.groupOptions = read();
|
||||
this.loc = read();
|
||||
this.request = read();
|
||||
super.deserialize(context);
|
||||
}
|
||||
}
|
||||
|
||||
makeSerializable(AsyncDependenciesBlock, "webpack/lib/AsyncDependenciesBlock");
|
||||
|
||||
Object.defineProperty(AsyncDependenciesBlock.prototype, "module", {
|
||||
get() {
|
||||
throw new Error(
|
||||
"module property was removed from AsyncDependenciesBlock (it's not needed)"
|
||||
);
|
||||
},
|
||||
set() {
|
||||
throw new Error(
|
||||
"module property was removed from AsyncDependenciesBlock (it's not needed)"
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = AsyncDependenciesBlock;
|
31
node_modules/webpack/lib/AsyncDependencyToInitialChunkError.js
generated
vendored
Normal file
31
node_modules/webpack/lib/AsyncDependencyToInitialChunkError.js
generated
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Sean Larkin @thelarkinn
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
const WebpackError = require("./WebpackError");
|
||||
|
||||
/** @typedef {import("./Dependency").DependencyLocation} DependencyLocation */
|
||||
/** @typedef {import("./Module")} Module */
|
||||
|
||||
class AsyncDependencyToInitialChunkError extends WebpackError {
|
||||
/**
|
||||
* Creates an instance of AsyncDependencyToInitialChunkError.
|
||||
* @param {string} chunkName Name of Chunk
|
||||
* @param {Module} module module tied to dependency
|
||||
* @param {DependencyLocation} loc location of dependency
|
||||
*/
|
||||
constructor(chunkName, module, loc) {
|
||||
super(
|
||||
`It's not allowed to load an initial chunk on demand. The chunk name "${chunkName}" is already used by an entrypoint.`
|
||||
);
|
||||
|
||||
this.name = "AsyncDependencyToInitialChunkError";
|
||||
this.module = module;
|
||||
this.loc = loc;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = AsyncDependencyToInitialChunkError;
|
65
node_modules/webpack/lib/AutomaticPrefetchPlugin.js
generated
vendored
Normal file
65
node_modules/webpack/lib/AutomaticPrefetchPlugin.js
generated
vendored
Normal file
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
const asyncLib = require("neo-async");
|
||||
const NormalModule = require("./NormalModule");
|
||||
const PrefetchDependency = require("./dependencies/PrefetchDependency");
|
||||
|
||||
/** @typedef {import("./Compiler")} Compiler */
|
||||
|
||||
class AutomaticPrefetchPlugin {
|
||||
/**
|
||||
* Apply the plugin
|
||||
* @param {Compiler} compiler the compiler instance
|
||||
* @returns {void}
|
||||
*/
|
||||
apply(compiler) {
|
||||
compiler.hooks.compilation.tap(
|
||||
"AutomaticPrefetchPlugin",
|
||||
(compilation, { normalModuleFactory }) => {
|
||||
compilation.dependencyFactories.set(
|
||||
PrefetchDependency,
|
||||
normalModuleFactory
|
||||
);
|
||||
}
|
||||
);
|
||||
let lastModules = null;
|
||||
compiler.hooks.afterCompile.tap("AutomaticPrefetchPlugin", compilation => {
|
||||
lastModules = [];
|
||||
|
||||
for (const m of compilation.modules) {
|
||||
if (m instanceof NormalModule) {
|
||||
lastModules.push({
|
||||
context: m.context,
|
||||
request: m.request
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
compiler.hooks.make.tapAsync(
|
||||
"AutomaticPrefetchPlugin",
|
||||
(compilation, callback) => {
|
||||
if (!lastModules) return callback();
|
||||
asyncLib.forEach(
|
||||
lastModules,
|
||||
(m, callback) => {
|
||||
compilation.addModuleChain(
|
||||
m.context || compiler.context,
|
||||
new PrefetchDependency(`!!${m.request}`),
|
||||
callback
|
||||
);
|
||||
},
|
||||
err => {
|
||||
lastModules = null;
|
||||
callback(err);
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
module.exports = AutomaticPrefetchPlugin;
|
125
node_modules/webpack/lib/BannerPlugin.js
generated
vendored
Normal file
125
node_modules/webpack/lib/BannerPlugin.js
generated
vendored
Normal file
@@ -0,0 +1,125 @@
|
||||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
const { ConcatSource } = require("webpack-sources");
|
||||
const Compilation = require("./Compilation");
|
||||
const ModuleFilenameHelpers = require("./ModuleFilenameHelpers");
|
||||
const Template = require("./Template");
|
||||
const createSchemaValidation = require("./util/create-schema-validation");
|
||||
|
||||
/** @typedef {import("../declarations/plugins/BannerPlugin").BannerPluginArgument} BannerPluginArgument */
|
||||
/** @typedef {import("../declarations/plugins/BannerPlugin").BannerPluginOptions} BannerPluginOptions */
|
||||
/** @typedef {import("./Compiler")} Compiler */
|
||||
|
||||
const validate = createSchemaValidation(
|
||||
require("../schemas/plugins/BannerPlugin.check.js"),
|
||||
() => require("../schemas/plugins/BannerPlugin.json"),
|
||||
{
|
||||
name: "Banner Plugin",
|
||||
baseDataPath: "options"
|
||||
}
|
||||
);
|
||||
|
||||
const wrapComment = str => {
|
||||
if (!str.includes("\n")) {
|
||||
return Template.toComment(str);
|
||||
}
|
||||
return `/*!\n * ${str
|
||||
.replace(/\*\//g, "* /")
|
||||
.split("\n")
|
||||
.join("\n * ")
|
||||
.replace(/\s+\n/g, "\n")
|
||||
.trimEnd()}\n */`;
|
||||
};
|
||||
|
||||
class BannerPlugin {
|
||||
/**
|
||||
* @param {BannerPluginArgument} options options object
|
||||
*/
|
||||
constructor(options) {
|
||||
if (typeof options === "string" || typeof options === "function") {
|
||||
options = {
|
||||
banner: options
|
||||
};
|
||||
}
|
||||
|
||||
validate(options);
|
||||
|
||||
this.options = options;
|
||||
|
||||
const bannerOption = options.banner;
|
||||
if (typeof bannerOption === "function") {
|
||||
const getBanner = bannerOption;
|
||||
this.banner = this.options.raw
|
||||
? getBanner
|
||||
: data => wrapComment(getBanner(data));
|
||||
} else {
|
||||
const banner = this.options.raw
|
||||
? bannerOption
|
||||
: wrapComment(bannerOption);
|
||||
this.banner = () => banner;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply the plugin
|
||||
* @param {Compiler} compiler the compiler instance
|
||||
* @returns {void}
|
||||
*/
|
||||
apply(compiler) {
|
||||
const options = this.options;
|
||||
const banner = this.banner;
|
||||
const matchObject = ModuleFilenameHelpers.matchObject.bind(
|
||||
undefined,
|
||||
options
|
||||
);
|
||||
const cache = new WeakMap();
|
||||
|
||||
compiler.hooks.compilation.tap("BannerPlugin", compilation => {
|
||||
compilation.hooks.processAssets.tap(
|
||||
{
|
||||
name: "BannerPlugin",
|
||||
stage: Compilation.PROCESS_ASSETS_STAGE_ADDITIONS
|
||||
},
|
||||
() => {
|
||||
for (const chunk of compilation.chunks) {
|
||||
if (options.entryOnly && !chunk.canBeInitial()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (const file of chunk.files) {
|
||||
if (!matchObject(file)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const data = {
|
||||
chunk,
|
||||
filename: file
|
||||
};
|
||||
|
||||
const comment = compilation.getPath(banner, data);
|
||||
|
||||
compilation.updateAsset(file, old => {
|
||||
let cached = cache.get(old);
|
||||
if (!cached || cached.comment !== comment) {
|
||||
const source = options.footer
|
||||
? new ConcatSource(old, "\n", comment)
|
||||
: new ConcatSource(comment, "\n", old);
|
||||
cache.set(old, { source, comment });
|
||||
return source;
|
||||
}
|
||||
return cached.source;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = BannerPlugin;
|
161
node_modules/webpack/lib/Cache.js
generated
vendored
Normal file
161
node_modules/webpack/lib/Cache.js
generated
vendored
Normal file
@@ -0,0 +1,161 @@
|
||||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
const { AsyncParallelHook, AsyncSeriesBailHook, SyncHook } = require("tapable");
|
||||
const {
|
||||
makeWebpackError,
|
||||
makeWebpackErrorCallback
|
||||
} = require("./HookWebpackError");
|
||||
|
||||
/** @typedef {import("./WebpackError")} WebpackError */
|
||||
|
||||
/**
|
||||
* @typedef {Object} Etag
|
||||
* @property {function(): string} toString
|
||||
*/
|
||||
|
||||
/**
|
||||
* @template T
|
||||
* @callback CallbackCache
|
||||
* @param {(WebpackError | null)=} err
|
||||
* @param {T=} result
|
||||
* @returns {void}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @callback GotHandler
|
||||
* @param {any} result
|
||||
* @param {function(Error=): void} callback
|
||||
* @returns {void}
|
||||
*/
|
||||
|
||||
const needCalls = (times, callback) => {
|
||||
return err => {
|
||||
if (--times === 0) {
|
||||
return callback(err);
|
||||
}
|
||||
if (err && times > 0) {
|
||||
times = 0;
|
||||
return callback(err);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
class Cache {
|
||||
constructor() {
|
||||
this.hooks = {
|
||||
/** @type {AsyncSeriesBailHook<[string, Etag | null, GotHandler[]], any>} */
|
||||
get: new AsyncSeriesBailHook(["identifier", "etag", "gotHandlers"]),
|
||||
/** @type {AsyncParallelHook<[string, Etag | null, any]>} */
|
||||
store: new AsyncParallelHook(["identifier", "etag", "data"]),
|
||||
/** @type {AsyncParallelHook<[Iterable<string>]>} */
|
||||
storeBuildDependencies: new AsyncParallelHook(["dependencies"]),
|
||||
/** @type {SyncHook<[]>} */
|
||||
beginIdle: new SyncHook([]),
|
||||
/** @type {AsyncParallelHook<[]>} */
|
||||
endIdle: new AsyncParallelHook([]),
|
||||
/** @type {AsyncParallelHook<[]>} */
|
||||
shutdown: new AsyncParallelHook([])
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @template T
|
||||
* @param {string} identifier the cache identifier
|
||||
* @param {Etag | null} etag the etag
|
||||
* @param {CallbackCache<T>} callback signals when the value is retrieved
|
||||
* @returns {void}
|
||||
*/
|
||||
get(identifier, etag, callback) {
|
||||
const gotHandlers = [];
|
||||
this.hooks.get.callAsync(identifier, etag, gotHandlers, (err, result) => {
|
||||
if (err) {
|
||||
callback(makeWebpackError(err, "Cache.hooks.get"));
|
||||
return;
|
||||
}
|
||||
if (result === null) {
|
||||
result = undefined;
|
||||
}
|
||||
if (gotHandlers.length > 1) {
|
||||
const innerCallback = needCalls(gotHandlers.length, () =>
|
||||
callback(null, result)
|
||||
);
|
||||
for (const gotHandler of gotHandlers) {
|
||||
gotHandler(result, innerCallback);
|
||||
}
|
||||
} else if (gotHandlers.length === 1) {
|
||||
gotHandlers[0](result, () => callback(null, result));
|
||||
} else {
|
||||
callback(null, result);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @template T
|
||||
* @param {string} identifier the cache identifier
|
||||
* @param {Etag | null} etag the etag
|
||||
* @param {T} data the value to store
|
||||
* @param {CallbackCache<void>} callback signals when the value is stored
|
||||
* @returns {void}
|
||||
*/
|
||||
store(identifier, etag, data, callback) {
|
||||
this.hooks.store.callAsync(
|
||||
identifier,
|
||||
etag,
|
||||
data,
|
||||
makeWebpackErrorCallback(callback, "Cache.hooks.store")
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* After this method has succeeded the cache can only be restored when build dependencies are
|
||||
* @param {Iterable<string>} dependencies list of all build dependencies
|
||||
* @param {CallbackCache<void>} callback signals when the dependencies are stored
|
||||
* @returns {void}
|
||||
*/
|
||||
storeBuildDependencies(dependencies, callback) {
|
||||
this.hooks.storeBuildDependencies.callAsync(
|
||||
dependencies,
|
||||
makeWebpackErrorCallback(callback, "Cache.hooks.storeBuildDependencies")
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {void}
|
||||
*/
|
||||
beginIdle() {
|
||||
this.hooks.beginIdle.call();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {CallbackCache<void>} callback signals when the call finishes
|
||||
* @returns {void}
|
||||
*/
|
||||
endIdle(callback) {
|
||||
this.hooks.endIdle.callAsync(
|
||||
makeWebpackErrorCallback(callback, "Cache.hooks.endIdle")
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {CallbackCache<void>} callback signals when the call finishes
|
||||
* @returns {void}
|
||||
*/
|
||||
shutdown(callback) {
|
||||
this.hooks.shutdown.callAsync(
|
||||
makeWebpackErrorCallback(callback, "Cache.hooks.shutdown")
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Cache.STAGE_MEMORY = -10;
|
||||
Cache.STAGE_DEFAULT = 0;
|
||||
Cache.STAGE_DISK = 10;
|
||||
Cache.STAGE_NETWORK = 20;
|
||||
|
||||
module.exports = Cache;
|
345
node_modules/webpack/lib/CacheFacade.js
generated
vendored
Normal file
345
node_modules/webpack/lib/CacheFacade.js
generated
vendored
Normal file
@@ -0,0 +1,345 @@
|
||||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
const { forEachBail } = require("enhanced-resolve");
|
||||
const asyncLib = require("neo-async");
|
||||
const getLazyHashedEtag = require("./cache/getLazyHashedEtag");
|
||||
const mergeEtags = require("./cache/mergeEtags");
|
||||
|
||||
/** @typedef {import("./Cache")} Cache */
|
||||
/** @typedef {import("./Cache").Etag} Etag */
|
||||
/** @typedef {import("./WebpackError")} WebpackError */
|
||||
/** @typedef {import("./cache/getLazyHashedEtag").HashableObject} HashableObject */
|
||||
/** @typedef {typeof import("./util/Hash")} HashConstructor */
|
||||
|
||||
/**
|
||||
* @template T
|
||||
* @callback CallbackCache
|
||||
* @param {(WebpackError | null)=} err
|
||||
* @param {T=} result
|
||||
* @returns {void}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @template T
|
||||
* @callback CallbackNormalErrorCache
|
||||
* @param {(Error | null)=} err
|
||||
* @param {T=} result
|
||||
* @returns {void}
|
||||
*/
|
||||
|
||||
class MultiItemCache {
|
||||
/**
|
||||
* @param {ItemCacheFacade[]} items item caches
|
||||
*/
|
||||
constructor(items) {
|
||||
this._items = items;
|
||||
if (items.length === 1) return /** @type {any} */ (items[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @template T
|
||||
* @param {CallbackCache<T>} callback signals when the value is retrieved
|
||||
* @returns {void}
|
||||
*/
|
||||
get(callback) {
|
||||
forEachBail(this._items, (item, callback) => item.get(callback), callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* @template T
|
||||
* @returns {Promise<T>} promise with the data
|
||||
*/
|
||||
getPromise() {
|
||||
const next = i => {
|
||||
return this._items[i].getPromise().then(result => {
|
||||
if (result !== undefined) return result;
|
||||
if (++i < this._items.length) return next(i);
|
||||
});
|
||||
};
|
||||
return next(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @template T
|
||||
* @param {T} data the value to store
|
||||
* @param {CallbackCache<void>} callback signals when the value is stored
|
||||
* @returns {void}
|
||||
*/
|
||||
store(data, callback) {
|
||||
asyncLib.each(
|
||||
this._items,
|
||||
(item, callback) => item.store(data, callback),
|
||||
callback
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @template T
|
||||
* @param {T} data the value to store
|
||||
* @returns {Promise<void>} promise signals when the value is stored
|
||||
*/
|
||||
storePromise(data) {
|
||||
return Promise.all(this._items.map(item => item.storePromise(data))).then(
|
||||
() => {}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class ItemCacheFacade {
|
||||
/**
|
||||
* @param {Cache} cache the root cache
|
||||
* @param {string} name the child cache item name
|
||||
* @param {Etag | null} etag the etag
|
||||
*/
|
||||
constructor(cache, name, etag) {
|
||||
this._cache = cache;
|
||||
this._name = name;
|
||||
this._etag = etag;
|
||||
}
|
||||
|
||||
/**
|
||||
* @template T
|
||||
* @param {CallbackCache<T>} callback signals when the value is retrieved
|
||||
* @returns {void}
|
||||
*/
|
||||
get(callback) {
|
||||
this._cache.get(this._name, this._etag, callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* @template T
|
||||
* @returns {Promise<T>} promise with the data
|
||||
*/
|
||||
getPromise() {
|
||||
return new Promise((resolve, reject) => {
|
||||
this._cache.get(this._name, this._etag, (err, data) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
} else {
|
||||
resolve(data);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @template T
|
||||
* @param {T} data the value to store
|
||||
* @param {CallbackCache<void>} callback signals when the value is stored
|
||||
* @returns {void}
|
||||
*/
|
||||
store(data, callback) {
|
||||
this._cache.store(this._name, this._etag, data, callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* @template T
|
||||
* @param {T} data the value to store
|
||||
* @returns {Promise<void>} promise signals when the value is stored
|
||||
*/
|
||||
storePromise(data) {
|
||||
return new Promise((resolve, reject) => {
|
||||
this._cache.store(this._name, this._etag, data, err => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
} else {
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @template T
|
||||
* @param {function(CallbackNormalErrorCache<T>): void} computer function to compute the value if not cached
|
||||
* @param {CallbackNormalErrorCache<T>} callback signals when the value is retrieved
|
||||
* @returns {void}
|
||||
*/
|
||||
provide(computer, callback) {
|
||||
this.get((err, cacheEntry) => {
|
||||
if (err) return callback(err);
|
||||
if (cacheEntry !== undefined) return cacheEntry;
|
||||
computer((err, result) => {
|
||||
if (err) return callback(err);
|
||||
this.store(result, err => {
|
||||
if (err) return callback(err);
|
||||
callback(null, result);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @template T
|
||||
* @param {function(): Promise<T> | T} computer function to compute the value if not cached
|
||||
* @returns {Promise<T>} promise with the data
|
||||
*/
|
||||
async providePromise(computer) {
|
||||
const cacheEntry = await this.getPromise();
|
||||
if (cacheEntry !== undefined) return cacheEntry;
|
||||
const result = await computer();
|
||||
await this.storePromise(result);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
class CacheFacade {
|
||||
/**
|
||||
* @param {Cache} cache the root cache
|
||||
* @param {string} name the child cache name
|
||||
* @param {string | HashConstructor} hashFunction the hash function to use
|
||||
*/
|
||||
constructor(cache, name, hashFunction) {
|
||||
this._cache = cache;
|
||||
this._name = name;
|
||||
this._hashFunction = hashFunction;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} name the child cache name#
|
||||
* @returns {CacheFacade} child cache
|
||||
*/
|
||||
getChildCache(name) {
|
||||
return new CacheFacade(
|
||||
this._cache,
|
||||
`${this._name}|${name}`,
|
||||
this._hashFunction
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} identifier the cache identifier
|
||||
* @param {Etag | null} etag the etag
|
||||
* @returns {ItemCacheFacade} item cache
|
||||
*/
|
||||
getItemCache(identifier, etag) {
|
||||
return new ItemCacheFacade(
|
||||
this._cache,
|
||||
`${this._name}|${identifier}`,
|
||||
etag
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {HashableObject} obj an hashable object
|
||||
* @returns {Etag} an etag that is lazy hashed
|
||||
*/
|
||||
getLazyHashedEtag(obj) {
|
||||
return getLazyHashedEtag(obj, this._hashFunction);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Etag} a an etag
|
||||
* @param {Etag} b another etag
|
||||
* @returns {Etag} an etag that represents both
|
||||
*/
|
||||
mergeEtags(a, b) {
|
||||
return mergeEtags(a, b);
|
||||
}
|
||||
|
||||
/**
|
||||
* @template T
|
||||
* @param {string} identifier the cache identifier
|
||||
* @param {Etag | null} etag the etag
|
||||
* @param {CallbackCache<T>} callback signals when the value is retrieved
|
||||
* @returns {void}
|
||||
*/
|
||||
get(identifier, etag, callback) {
|
||||
this._cache.get(`${this._name}|${identifier}`, etag, callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* @template T
|
||||
* @param {string} identifier the cache identifier
|
||||
* @param {Etag | null} etag the etag
|
||||
* @returns {Promise<T>} promise with the data
|
||||
*/
|
||||
getPromise(identifier, etag) {
|
||||
return new Promise((resolve, reject) => {
|
||||
this._cache.get(`${this._name}|${identifier}`, etag, (err, data) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
} else {
|
||||
resolve(data);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @template T
|
||||
* @param {string} identifier the cache identifier
|
||||
* @param {Etag | null} etag the etag
|
||||
* @param {T} data the value to store
|
||||
* @param {CallbackCache<void>} callback signals when the value is stored
|
||||
* @returns {void}
|
||||
*/
|
||||
store(identifier, etag, data, callback) {
|
||||
this._cache.store(`${this._name}|${identifier}`, etag, data, callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* @template T
|
||||
* @param {string} identifier the cache identifier
|
||||
* @param {Etag | null} etag the etag
|
||||
* @param {T} data the value to store
|
||||
* @returns {Promise<void>} promise signals when the value is stored
|
||||
*/
|
||||
storePromise(identifier, etag, data) {
|
||||
return new Promise((resolve, reject) => {
|
||||
this._cache.store(`${this._name}|${identifier}`, etag, data, err => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
} else {
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @template T
|
||||
* @param {string} identifier the cache identifier
|
||||
* @param {Etag | null} etag the etag
|
||||
* @param {function(CallbackNormalErrorCache<T>): void} computer function to compute the value if not cached
|
||||
* @param {CallbackNormalErrorCache<T>} callback signals when the value is retrieved
|
||||
* @returns {void}
|
||||
*/
|
||||
provide(identifier, etag, computer, callback) {
|
||||
this.get(identifier, etag, (err, cacheEntry) => {
|
||||
if (err) return callback(err);
|
||||
if (cacheEntry !== undefined) return cacheEntry;
|
||||
computer((err, result) => {
|
||||
if (err) return callback(err);
|
||||
this.store(identifier, etag, result, err => {
|
||||
if (err) return callback(err);
|
||||
callback(null, result);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @template T
|
||||
* @param {string} identifier the cache identifier
|
||||
* @param {Etag | null} etag the etag
|
||||
* @param {function(): Promise<T> | T} computer function to compute the value if not cached
|
||||
* @returns {Promise<T>} promise with the data
|
||||
*/
|
||||
async providePromise(identifier, etag, computer) {
|
||||
const cacheEntry = await this.getPromise(identifier, etag);
|
||||
if (cacheEntry !== undefined) return cacheEntry;
|
||||
const result = await computer();
|
||||
await this.storePromise(identifier, etag, result);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = CacheFacade;
|
||||
module.exports.ItemCacheFacade = ItemCacheFacade;
|
||||
module.exports.MultiItemCache = MultiItemCache;
|
71
node_modules/webpack/lib/CaseSensitiveModulesWarning.js
generated
vendored
Normal file
71
node_modules/webpack/lib/CaseSensitiveModulesWarning.js
generated
vendored
Normal file
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
const WebpackError = require("./WebpackError");
|
||||
|
||||
/** @typedef {import("./Module")} Module */
|
||||
/** @typedef {import("./ModuleGraph")} ModuleGraph */
|
||||
|
||||
/**
|
||||
* @param {Module[]} modules the modules to be sorted
|
||||
* @returns {Module[]} sorted version of original modules
|
||||
*/
|
||||
const sortModules = modules => {
|
||||
return modules.sort((a, b) => {
|
||||
const aIdent = a.identifier();
|
||||
const bIdent = b.identifier();
|
||||
/* istanbul ignore next */
|
||||
if (aIdent < bIdent) return -1;
|
||||
/* istanbul ignore next */
|
||||
if (aIdent > bIdent) return 1;
|
||||
/* istanbul ignore next */
|
||||
return 0;
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {Module[]} modules each module from throw
|
||||
* @param {ModuleGraph} moduleGraph the module graph
|
||||
* @returns {string} each message from provided modules
|
||||
*/
|
||||
const createModulesListMessage = (modules, moduleGraph) => {
|
||||
return modules
|
||||
.map(m => {
|
||||
let message = `* ${m.identifier()}`;
|
||||
const validReasons = Array.from(
|
||||
moduleGraph.getIncomingConnectionsByOriginModule(m).keys()
|
||||
).filter(x => x);
|
||||
|
||||
if (validReasons.length > 0) {
|
||||
message += `\n Used by ${validReasons.length} module(s), i. e.`;
|
||||
message += `\n ${validReasons[0].identifier()}`;
|
||||
}
|
||||
return message;
|
||||
})
|
||||
.join("\n");
|
||||
};
|
||||
|
||||
class CaseSensitiveModulesWarning extends WebpackError {
|
||||
/**
|
||||
* Creates an instance of CaseSensitiveModulesWarning.
|
||||
* @param {Iterable<Module>} modules modules that were detected
|
||||
* @param {ModuleGraph} moduleGraph the module graph
|
||||
*/
|
||||
constructor(modules, moduleGraph) {
|
||||
const sortedModules = sortModules(Array.from(modules));
|
||||
const modulesList = createModulesListMessage(sortedModules, moduleGraph);
|
||||
super(`There are multiple modules with names that only differ in casing.
|
||||
This can lead to unexpected behavior when compiling on a filesystem with other case-semantic.
|
||||
Use equal casing. Compare these module identifiers:
|
||||
${modulesList}`);
|
||||
|
||||
this.name = "CaseSensitiveModulesWarning";
|
||||
this.module = sortedModules[0];
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = CaseSensitiveModulesWarning;
|
820
node_modules/webpack/lib/Chunk.js
generated
vendored
Normal file
820
node_modules/webpack/lib/Chunk.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
1814
node_modules/webpack/lib/ChunkGraph.js
generated
vendored
Normal file
1814
node_modules/webpack/lib/ChunkGraph.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
584
node_modules/webpack/lib/ChunkGroup.js
generated
vendored
Normal file
584
node_modules/webpack/lib/ChunkGroup.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
31
node_modules/webpack/lib/ChunkRenderError.js
generated
vendored
Normal file
31
node_modules/webpack/lib/ChunkRenderError.js
generated
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
const WebpackError = require("./WebpackError");
|
||||
|
||||
/** @typedef {import("./Chunk")} Chunk */
|
||||
|
||||
class ChunkRenderError extends WebpackError {
|
||||
/**
|
||||
* Create a new ChunkRenderError
|
||||
* @param {Chunk} chunk A chunk
|
||||
* @param {string} file Related file
|
||||
* @param {Error} error Original error
|
||||
*/
|
||||
constructor(chunk, file, error) {
|
||||
super();
|
||||
|
||||
this.name = "ChunkRenderError";
|
||||
this.error = error;
|
||||
this.message = error.message;
|
||||
this.details = error.stack;
|
||||
this.file = file;
|
||||
this.chunk = chunk;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ChunkRenderError;
|
138
node_modules/webpack/lib/ChunkTemplate.js
generated
vendored
Normal file
138
node_modules/webpack/lib/ChunkTemplate.js
generated
vendored
Normal file
@@ -0,0 +1,138 @@
|
||||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
const util = require("util");
|
||||
const memoize = require("./util/memoize");
|
||||
|
||||
/** @typedef {import("../declarations/WebpackOptions").Output} OutputOptions */
|
||||
/** @typedef {import("./Compilation")} Compilation */
|
||||
|
||||
const getJavascriptModulesPlugin = memoize(() =>
|
||||
require("./javascript/JavascriptModulesPlugin")
|
||||
);
|
||||
|
||||
// TODO webpack 6 remove this class
|
||||
class ChunkTemplate {
|
||||
/**
|
||||
* @param {OutputOptions} outputOptions output options
|
||||
* @param {Compilation} compilation the compilation
|
||||
*/
|
||||
constructor(outputOptions, compilation) {
|
||||
this._outputOptions = outputOptions || {};
|
||||
this.hooks = Object.freeze({
|
||||
renderManifest: {
|
||||
tap: util.deprecate(
|
||||
(options, fn) => {
|
||||
compilation.hooks.renderManifest.tap(
|
||||
options,
|
||||
(entries, options) => {
|
||||
if (options.chunk.hasRuntime()) return entries;
|
||||
return fn(entries, options);
|
||||
}
|
||||
);
|
||||
},
|
||||
"ChunkTemplate.hooks.renderManifest is deprecated (use Compilation.hooks.renderManifest instead)",
|
||||
"DEP_WEBPACK_CHUNK_TEMPLATE_RENDER_MANIFEST"
|
||||
)
|
||||
},
|
||||
modules: {
|
||||
tap: util.deprecate(
|
||||
(options, fn) => {
|
||||
getJavascriptModulesPlugin()
|
||||
.getCompilationHooks(compilation)
|
||||
.renderChunk.tap(options, (source, renderContext) =>
|
||||
fn(
|
||||
source,
|
||||
compilation.moduleTemplates.javascript,
|
||||
renderContext
|
||||
)
|
||||
);
|
||||
},
|
||||
"ChunkTemplate.hooks.modules is deprecated (use JavascriptModulesPlugin.getCompilationHooks().renderChunk instead)",
|
||||
"DEP_WEBPACK_CHUNK_TEMPLATE_MODULES"
|
||||
)
|
||||
},
|
||||
render: {
|
||||
tap: util.deprecate(
|
||||
(options, fn) => {
|
||||
getJavascriptModulesPlugin()
|
||||
.getCompilationHooks(compilation)
|
||||
.renderChunk.tap(options, (source, renderContext) =>
|
||||
fn(
|
||||
source,
|
||||
compilation.moduleTemplates.javascript,
|
||||
renderContext
|
||||
)
|
||||
);
|
||||
},
|
||||
"ChunkTemplate.hooks.render is deprecated (use JavascriptModulesPlugin.getCompilationHooks().renderChunk instead)",
|
||||
"DEP_WEBPACK_CHUNK_TEMPLATE_RENDER"
|
||||
)
|
||||
},
|
||||
renderWithEntry: {
|
||||
tap: util.deprecate(
|
||||
(options, fn) => {
|
||||
getJavascriptModulesPlugin()
|
||||
.getCompilationHooks(compilation)
|
||||
.render.tap(options, (source, renderContext) => {
|
||||
if (
|
||||
renderContext.chunkGraph.getNumberOfEntryModules(
|
||||
renderContext.chunk
|
||||
) === 0 ||
|
||||
renderContext.chunk.hasRuntime()
|
||||
) {
|
||||
return source;
|
||||
}
|
||||
return fn(source, renderContext.chunk);
|
||||
});
|
||||
},
|
||||
"ChunkTemplate.hooks.renderWithEntry is deprecated (use JavascriptModulesPlugin.getCompilationHooks().render instead)",
|
||||
"DEP_WEBPACK_CHUNK_TEMPLATE_RENDER_WITH_ENTRY"
|
||||
)
|
||||
},
|
||||
hash: {
|
||||
tap: util.deprecate(
|
||||
(options, fn) => {
|
||||
compilation.hooks.fullHash.tap(options, fn);
|
||||
},
|
||||
"ChunkTemplate.hooks.hash is deprecated (use Compilation.hooks.fullHash instead)",
|
||||
"DEP_WEBPACK_CHUNK_TEMPLATE_HASH"
|
||||
)
|
||||
},
|
||||
hashForChunk: {
|
||||
tap: util.deprecate(
|
||||
(options, fn) => {
|
||||
getJavascriptModulesPlugin()
|
||||
.getCompilationHooks(compilation)
|
||||
.chunkHash.tap(options, (chunk, hash, context) => {
|
||||
if (chunk.hasRuntime()) return;
|
||||
fn(hash, chunk, context);
|
||||
});
|
||||
},
|
||||
"ChunkTemplate.hooks.hashForChunk is deprecated (use JavascriptModulesPlugin.getCompilationHooks().chunkHash instead)",
|
||||
"DEP_WEBPACK_CHUNK_TEMPLATE_HASH_FOR_CHUNK"
|
||||
)
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Object.defineProperty(ChunkTemplate.prototype, "outputOptions", {
|
||||
get: util.deprecate(
|
||||
/**
|
||||
* @this {ChunkTemplate}
|
||||
* @returns {OutputOptions} output options
|
||||
*/
|
||||
function () {
|
||||
return this._outputOptions;
|
||||
},
|
||||
"ChunkTemplate.outputOptions is deprecated (use Compilation.outputOptions instead)",
|
||||
"DEP_WEBPACK_CHUNK_TEMPLATE_OUTPUT_OPTIONS"
|
||||
)
|
||||
});
|
||||
|
||||
module.exports = ChunkTemplate;
|
420
node_modules/webpack/lib/CleanPlugin.js
generated
vendored
Normal file
420
node_modules/webpack/lib/CleanPlugin.js
generated
vendored
Normal file
@@ -0,0 +1,420 @@
|
||||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Sergey Melyukov @smelukov
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
const asyncLib = require("neo-async");
|
||||
const { SyncBailHook } = require("tapable");
|
||||
const Compilation = require("../lib/Compilation");
|
||||
const createSchemaValidation = require("./util/create-schema-validation");
|
||||
const { join } = require("./util/fs");
|
||||
const processAsyncTree = require("./util/processAsyncTree");
|
||||
|
||||
/** @typedef {import("../declarations/WebpackOptions").CleanOptions} CleanOptions */
|
||||
/** @typedef {import("./Compiler")} Compiler */
|
||||
/** @typedef {import("./logging/Logger").Logger} Logger */
|
||||
/** @typedef {import("./util/fs").OutputFileSystem} OutputFileSystem */
|
||||
/** @typedef {import("./util/fs").StatsCallback} StatsCallback */
|
||||
|
||||
/** @typedef {(function(string):boolean)|RegExp} IgnoreItem */
|
||||
/** @typedef {Map<string, number>} Assets */
|
||||
/** @typedef {function(IgnoreItem): void} AddToIgnoreCallback */
|
||||
|
||||
/**
|
||||
* @typedef {Object} CleanPluginCompilationHooks
|
||||
* @property {SyncBailHook<[string], boolean>} keep when returning true the file/directory will be kept during cleaning, returning false will clean it and ignore the following plugins and config
|
||||
*/
|
||||
|
||||
const validate = createSchemaValidation(
|
||||
undefined,
|
||||
() => {
|
||||
const { definitions } = require("../schemas/WebpackOptions.json");
|
||||
return {
|
||||
definitions,
|
||||
oneOf: [{ $ref: "#/definitions/CleanOptions" }]
|
||||
};
|
||||
},
|
||||
{
|
||||
name: "Clean Plugin",
|
||||
baseDataPath: "options"
|
||||
}
|
||||
);
|
||||
const _10sec = 10 * 1000;
|
||||
|
||||
/**
|
||||
* marge assets map 2 into map 1
|
||||
* @param {Assets} as1 assets
|
||||
* @param {Assets} as2 assets
|
||||
* @returns {void}
|
||||
*/
|
||||
const mergeAssets = (as1, as2) => {
|
||||
for (const [key, value1] of as2) {
|
||||
const value2 = as1.get(key);
|
||||
if (!value2 || value1 > value2) as1.set(key, value1);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {OutputFileSystem} fs filesystem
|
||||
* @param {string} outputPath output path
|
||||
* @param {Map<string, number>} currentAssets filename of the current assets (must not start with .. or ., must only use / as path separator)
|
||||
* @param {function((Error | null)=, Set<string>=): void} callback returns the filenames of the assets that shouldn't be there
|
||||
* @returns {void}
|
||||
*/
|
||||
const getDiffToFs = (fs, outputPath, currentAssets, callback) => {
|
||||
const directories = new Set();
|
||||
// get directories of assets
|
||||
for (const [asset] of currentAssets) {
|
||||
directories.add(asset.replace(/(^|\/)[^/]*$/, ""));
|
||||
}
|
||||
// and all parent directories
|
||||
for (const directory of directories) {
|
||||
directories.add(directory.replace(/(^|\/)[^/]*$/, ""));
|
||||
}
|
||||
const diff = new Set();
|
||||
asyncLib.forEachLimit(
|
||||
directories,
|
||||
10,
|
||||
(directory, callback) => {
|
||||
fs.readdir(join(fs, outputPath, directory), (err, entries) => {
|
||||
if (err) {
|
||||
if (err.code === "ENOENT") return callback();
|
||||
if (err.code === "ENOTDIR") {
|
||||
diff.add(directory);
|
||||
return callback();
|
||||
}
|
||||
return callback(err);
|
||||
}
|
||||
for (const entry of entries) {
|
||||
const file = /** @type {string} */ (entry);
|
||||
const filename = directory ? `${directory}/${file}` : file;
|
||||
if (!directories.has(filename) && !currentAssets.has(filename)) {
|
||||
diff.add(filename);
|
||||
}
|
||||
}
|
||||
callback();
|
||||
});
|
||||
},
|
||||
err => {
|
||||
if (err) return callback(err);
|
||||
|
||||
callback(null, diff);
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {Assets} currentAssets assets list
|
||||
* @param {Assets} oldAssets old assets list
|
||||
* @returns {Set<string>} diff
|
||||
*/
|
||||
const getDiffToOldAssets = (currentAssets, oldAssets) => {
|
||||
const diff = new Set();
|
||||
const now = Date.now();
|
||||
for (const [asset, ts] of oldAssets) {
|
||||
if (ts >= now) continue;
|
||||
if (!currentAssets.has(asset)) diff.add(asset);
|
||||
}
|
||||
return diff;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {OutputFileSystem} fs filesystem
|
||||
* @param {string} filename path to file
|
||||
* @param {StatsCallback} callback callback for provided filename
|
||||
* @returns {void}
|
||||
*/
|
||||
const doStat = (fs, filename, callback) => {
|
||||
if ("lstat" in fs) {
|
||||
fs.lstat(filename, callback);
|
||||
} else {
|
||||
fs.stat(filename, callback);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {OutputFileSystem} fs filesystem
|
||||
* @param {string} outputPath output path
|
||||
* @param {boolean} dry only log instead of fs modification
|
||||
* @param {Logger} logger logger
|
||||
* @param {Set<string>} diff filenames of the assets that shouldn't be there
|
||||
* @param {function(string): boolean} isKept check if the entry is ignored
|
||||
* @param {function(Error=, Assets=): void} callback callback
|
||||
* @returns {void}
|
||||
*/
|
||||
const applyDiff = (fs, outputPath, dry, logger, diff, isKept, callback) => {
|
||||
const log = msg => {
|
||||
if (dry) {
|
||||
logger.info(msg);
|
||||
} else {
|
||||
logger.log(msg);
|
||||
}
|
||||
};
|
||||
/** @typedef {{ type: "check" | "unlink" | "rmdir", filename: string, parent: { remaining: number, job: Job } | undefined }} Job */
|
||||
/** @type {Job[]} */
|
||||
const jobs = Array.from(diff.keys(), filename => ({
|
||||
type: "check",
|
||||
filename,
|
||||
parent: undefined
|
||||
}));
|
||||
/** @type {Assets} */
|
||||
const keptAssets = new Map();
|
||||
processAsyncTree(
|
||||
jobs,
|
||||
10,
|
||||
({ type, filename, parent }, push, callback) => {
|
||||
const handleError = err => {
|
||||
if (err.code === "ENOENT") {
|
||||
log(`${filename} was removed during cleaning by something else`);
|
||||
handleParent();
|
||||
return callback();
|
||||
}
|
||||
return callback(err);
|
||||
};
|
||||
const handleParent = () => {
|
||||
if (parent && --parent.remaining === 0) push(parent.job);
|
||||
};
|
||||
const path = join(fs, outputPath, filename);
|
||||
switch (type) {
|
||||
case "check":
|
||||
if (isKept(filename)) {
|
||||
keptAssets.set(filename, 0);
|
||||
// do not decrement parent entry as we don't want to delete the parent
|
||||
log(`${filename} will be kept`);
|
||||
return process.nextTick(callback);
|
||||
}
|
||||
doStat(fs, path, (err, stats) => {
|
||||
if (err) return handleError(err);
|
||||
if (!stats.isDirectory()) {
|
||||
push({
|
||||
type: "unlink",
|
||||
filename,
|
||||
parent
|
||||
});
|
||||
return callback();
|
||||
}
|
||||
fs.readdir(path, (err, entries) => {
|
||||
if (err) return handleError(err);
|
||||
/** @type {Job} */
|
||||
const deleteJob = {
|
||||
type: "rmdir",
|
||||
filename,
|
||||
parent
|
||||
};
|
||||
if (entries.length === 0) {
|
||||
push(deleteJob);
|
||||
} else {
|
||||
const parentToken = {
|
||||
remaining: entries.length,
|
||||
job: deleteJob
|
||||
};
|
||||
for (const entry of entries) {
|
||||
const file = /** @type {string} */ (entry);
|
||||
if (file.startsWith(".")) {
|
||||
log(
|
||||
`${filename} will be kept (dot-files will never be removed)`
|
||||
);
|
||||
continue;
|
||||
}
|
||||
push({
|
||||
type: "check",
|
||||
filename: `${filename}/${file}`,
|
||||
parent: parentToken
|
||||
});
|
||||
}
|
||||
}
|
||||
return callback();
|
||||
});
|
||||
});
|
||||
break;
|
||||
case "rmdir":
|
||||
log(`${filename} will be removed`);
|
||||
if (dry) {
|
||||
handleParent();
|
||||
return process.nextTick(callback);
|
||||
}
|
||||
if (!fs.rmdir) {
|
||||
logger.warn(
|
||||
`${filename} can't be removed because output file system doesn't support removing directories (rmdir)`
|
||||
);
|
||||
return process.nextTick(callback);
|
||||
}
|
||||
fs.rmdir(path, err => {
|
||||
if (err) return handleError(err);
|
||||
handleParent();
|
||||
callback();
|
||||
});
|
||||
break;
|
||||
case "unlink":
|
||||
log(`${filename} will be removed`);
|
||||
if (dry) {
|
||||
handleParent();
|
||||
return process.nextTick(callback);
|
||||
}
|
||||
if (!fs.unlink) {
|
||||
logger.warn(
|
||||
`${filename} can't be removed because output file system doesn't support removing files (rmdir)`
|
||||
);
|
||||
return process.nextTick(callback);
|
||||
}
|
||||
fs.unlink(path, err => {
|
||||
if (err) return handleError(err);
|
||||
handleParent();
|
||||
callback();
|
||||
});
|
||||
break;
|
||||
}
|
||||
},
|
||||
err => {
|
||||
if (err) return callback(err);
|
||||
callback(undefined, keptAssets);
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
/** @type {WeakMap<Compilation, CleanPluginCompilationHooks>} */
|
||||
const compilationHooksMap = new WeakMap();
|
||||
|
||||
class CleanPlugin {
|
||||
/**
|
||||
* @param {Compilation} compilation the compilation
|
||||
* @returns {CleanPluginCompilationHooks} the attached hooks
|
||||
*/
|
||||
static getCompilationHooks(compilation) {
|
||||
if (!(compilation instanceof Compilation)) {
|
||||
throw new TypeError(
|
||||
"The 'compilation' argument must be an instance of Compilation"
|
||||
);
|
||||
}
|
||||
let hooks = compilationHooksMap.get(compilation);
|
||||
if (hooks === undefined) {
|
||||
hooks = {
|
||||
/** @type {SyncBailHook<[string], boolean>} */
|
||||
keep: new SyncBailHook(["ignore"])
|
||||
};
|
||||
compilationHooksMap.set(compilation, hooks);
|
||||
}
|
||||
return hooks;
|
||||
}
|
||||
|
||||
/** @param {CleanOptions} options options */
|
||||
constructor(options = {}) {
|
||||
validate(options);
|
||||
this.options = { dry: false, ...options };
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply the plugin
|
||||
* @param {Compiler} compiler the compiler instance
|
||||
* @returns {void}
|
||||
*/
|
||||
apply(compiler) {
|
||||
const { dry, keep } = this.options;
|
||||
|
||||
const keepFn =
|
||||
typeof keep === "function"
|
||||
? keep
|
||||
: typeof keep === "string"
|
||||
? path => path.startsWith(keep)
|
||||
: typeof keep === "object" && keep.test
|
||||
? path => keep.test(path)
|
||||
: () => false;
|
||||
|
||||
// We assume that no external modification happens while the compiler is active
|
||||
// So we can store the old assets and only diff to them to avoid fs access on
|
||||
// incremental builds
|
||||
/** @type {undefined|Assets} */
|
||||
let oldAssets;
|
||||
|
||||
compiler.hooks.emit.tapAsync(
|
||||
{
|
||||
name: "CleanPlugin",
|
||||
stage: 100
|
||||
},
|
||||
(compilation, callback) => {
|
||||
const hooks = CleanPlugin.getCompilationHooks(compilation);
|
||||
const logger = compilation.getLogger("webpack.CleanPlugin");
|
||||
const fs = compiler.outputFileSystem;
|
||||
|
||||
if (!fs.readdir) {
|
||||
return callback(
|
||||
new Error(
|
||||
"CleanPlugin: Output filesystem doesn't support listing directories (readdir)"
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/** @type {Assets} */
|
||||
const currentAssets = new Map();
|
||||
const now = Date.now();
|
||||
for (const asset of Object.keys(compilation.assets)) {
|
||||
if (/^[A-Za-z]:\\|^\/|^\\\\/.test(asset)) continue;
|
||||
let normalizedAsset;
|
||||
let newNormalizedAsset = asset.replace(/\\/g, "/");
|
||||
do {
|
||||
normalizedAsset = newNormalizedAsset;
|
||||
newNormalizedAsset = normalizedAsset.replace(
|
||||
/(^|\/)(?!\.\.)[^/]+\/\.\.\//g,
|
||||
"$1"
|
||||
);
|
||||
} while (newNormalizedAsset !== normalizedAsset);
|
||||
if (normalizedAsset.startsWith("../")) continue;
|
||||
const assetInfo = compilation.assetsInfo.get(asset);
|
||||
if (assetInfo && assetInfo.hotModuleReplacement) {
|
||||
currentAssets.set(normalizedAsset, now + _10sec);
|
||||
} else {
|
||||
currentAssets.set(normalizedAsset, 0);
|
||||
}
|
||||
}
|
||||
|
||||
const outputPath = compilation.getPath(compiler.outputPath, {});
|
||||
|
||||
const isKept = path => {
|
||||
const result = hooks.keep.call(path);
|
||||
if (result !== undefined) return result;
|
||||
return keepFn(path);
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {Error=} err err
|
||||
* @param {Set<string>=} diff diff
|
||||
*/
|
||||
const diffCallback = (err, diff) => {
|
||||
if (err) {
|
||||
oldAssets = undefined;
|
||||
callback(err);
|
||||
return;
|
||||
}
|
||||
applyDiff(
|
||||
fs,
|
||||
outputPath,
|
||||
dry,
|
||||
logger,
|
||||
diff,
|
||||
isKept,
|
||||
(err, keptAssets) => {
|
||||
if (err) {
|
||||
oldAssets = undefined;
|
||||
} else {
|
||||
if (oldAssets) mergeAssets(currentAssets, oldAssets);
|
||||
oldAssets = currentAssets;
|
||||
if (keptAssets) mergeAssets(oldAssets, keptAssets);
|
||||
}
|
||||
callback(err);
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
if (oldAssets) {
|
||||
diffCallback(null, getDiffToOldAssets(currentAssets, oldAssets));
|
||||
} else {
|
||||
getDiffToFs(fs, outputPath, currentAssets, diffCallback);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = CleanPlugin;
|
29
node_modules/webpack/lib/CodeGenerationError.js
generated
vendored
Normal file
29
node_modules/webpack/lib/CodeGenerationError.js
generated
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
const WebpackError = require("./WebpackError");
|
||||
|
||||
/** @typedef {import("./Module")} Module */
|
||||
|
||||
class CodeGenerationError extends WebpackError {
|
||||
/**
|
||||
* Create a new CodeGenerationError
|
||||
* @param {Module} module related module
|
||||
* @param {Error} error Original error
|
||||
*/
|
||||
constructor(module, error) {
|
||||
super();
|
||||
|
||||
this.name = "CodeGenerationError";
|
||||
this.error = error;
|
||||
this.message = error.message;
|
||||
this.details = error.stack;
|
||||
this.module = module;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = CodeGenerationError;
|
155
node_modules/webpack/lib/CodeGenerationResults.js
generated
vendored
Normal file
155
node_modules/webpack/lib/CodeGenerationResults.js
generated
vendored
Normal file
@@ -0,0 +1,155 @@
|
||||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
const { provide } = require("./util/MapHelpers");
|
||||
const { first } = require("./util/SetHelpers");
|
||||
const createHash = require("./util/createHash");
|
||||
const { runtimeToString, RuntimeSpecMap } = require("./util/runtime");
|
||||
|
||||
/** @typedef {import("webpack-sources").Source} Source */
|
||||
/** @typedef {import("./Module")} Module */
|
||||
/** @typedef {import("./Module").CodeGenerationResult} CodeGenerationResult */
|
||||
/** @typedef {typeof import("./util/Hash")} Hash */
|
||||
/** @typedef {import("./util/runtime").RuntimeSpec} RuntimeSpec */
|
||||
|
||||
class CodeGenerationResults {
|
||||
/**
|
||||
* @param {string | Hash} hashFunction the hash function to use
|
||||
*/
|
||||
constructor(hashFunction = "md4") {
|
||||
/** @type {Map<Module, RuntimeSpecMap<CodeGenerationResult>>} */
|
||||
this.map = new Map();
|
||||
this._hashFunction = hashFunction;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Module} module the module
|
||||
* @param {RuntimeSpec} runtime runtime(s)
|
||||
* @returns {CodeGenerationResult} the CodeGenerationResult
|
||||
*/
|
||||
get(module, runtime) {
|
||||
const entry = this.map.get(module);
|
||||
if (entry === undefined) {
|
||||
throw new Error(
|
||||
`No code generation entry for ${module.identifier()} (existing entries: ${Array.from(
|
||||
this.map.keys(),
|
||||
m => m.identifier()
|
||||
).join(", ")})`
|
||||
);
|
||||
}
|
||||
if (runtime === undefined) {
|
||||
if (entry.size > 1) {
|
||||
const results = new Set(entry.values());
|
||||
if (results.size !== 1) {
|
||||
throw new Error(
|
||||
`No unique code generation entry for unspecified runtime for ${module.identifier()} (existing runtimes: ${Array.from(
|
||||
entry.keys(),
|
||||
r => runtimeToString(r)
|
||||
).join(", ")}).
|
||||
Caller might not support runtime-dependent code generation (opt-out via optimization.usedExports: "global").`
|
||||
);
|
||||
}
|
||||
return first(results);
|
||||
}
|
||||
return entry.values().next().value;
|
||||
}
|
||||
const result = entry.get(runtime);
|
||||
if (result === undefined) {
|
||||
throw new Error(
|
||||
`No code generation entry for runtime ${runtimeToString(
|
||||
runtime
|
||||
)} for ${module.identifier()} (existing runtimes: ${Array.from(
|
||||
entry.keys(),
|
||||
r => runtimeToString(r)
|
||||
).join(", ")})`
|
||||
);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Module} module the module
|
||||
* @param {RuntimeSpec} runtime runtime(s)
|
||||
* @returns {boolean} true, when we have data for this
|
||||
*/
|
||||
has(module, runtime) {
|
||||
const entry = this.map.get(module);
|
||||
if (entry === undefined) {
|
||||
return false;
|
||||
}
|
||||
if (runtime !== undefined) {
|
||||
return entry.has(runtime);
|
||||
} else if (entry.size > 1) {
|
||||
const results = new Set(entry.values());
|
||||
return results.size === 1;
|
||||
} else {
|
||||
return entry.size === 1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Module} module the module
|
||||
* @param {RuntimeSpec} runtime runtime(s)
|
||||
* @param {string} sourceType the source type
|
||||
* @returns {Source} a source
|
||||
*/
|
||||
getSource(module, runtime, sourceType) {
|
||||
return this.get(module, runtime).sources.get(sourceType);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Module} module the module
|
||||
* @param {RuntimeSpec} runtime runtime(s)
|
||||
* @returns {ReadonlySet<string>} runtime requirements
|
||||
*/
|
||||
getRuntimeRequirements(module, runtime) {
|
||||
return this.get(module, runtime).runtimeRequirements;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Module} module the module
|
||||
* @param {RuntimeSpec} runtime runtime(s)
|
||||
* @param {string} key data key
|
||||
* @returns {any} data generated by code generation
|
||||
*/
|
||||
getData(module, runtime, key) {
|
||||
const data = this.get(module, runtime).data;
|
||||
return data === undefined ? undefined : data.get(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Module} module the module
|
||||
* @param {RuntimeSpec} runtime runtime(s)
|
||||
* @returns {any} hash of the code generation
|
||||
*/
|
||||
getHash(module, runtime) {
|
||||
const info = this.get(module, runtime);
|
||||
if (info.hash !== undefined) return info.hash;
|
||||
const hash = createHash(this._hashFunction);
|
||||
for (const [type, source] of info.sources) {
|
||||
hash.update(type);
|
||||
source.updateHash(hash);
|
||||
}
|
||||
if (info.runtimeRequirements) {
|
||||
for (const rr of info.runtimeRequirements) hash.update(rr);
|
||||
}
|
||||
return (info.hash = /** @type {string} */ (hash.digest("hex")));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Module} module the module
|
||||
* @param {RuntimeSpec} runtime runtime(s)
|
||||
* @param {CodeGenerationResult} result result from module
|
||||
* @returns {void}
|
||||
*/
|
||||
add(module, runtime, result) {
|
||||
const map = provide(this.map, module, () => new RuntimeSpecMap());
|
||||
map.set(runtime, result);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = CodeGenerationResults;
|
33
node_modules/webpack/lib/CommentCompilationWarning.js
generated
vendored
Normal file
33
node_modules/webpack/lib/CommentCompilationWarning.js
generated
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
const WebpackError = require("./WebpackError");
|
||||
const makeSerializable = require("./util/makeSerializable");
|
||||
|
||||
/** @typedef {import("./Dependency").DependencyLocation} DependencyLocation */
|
||||
|
||||
class CommentCompilationWarning extends WebpackError {
|
||||
/**
|
||||
*
|
||||
* @param {string} message warning message
|
||||
* @param {DependencyLocation} loc affected lines of code
|
||||
*/
|
||||
constructor(message, loc) {
|
||||
super(message);
|
||||
|
||||
this.name = "CommentCompilationWarning";
|
||||
|
||||
this.loc = loc;
|
||||
}
|
||||
}
|
||||
|
||||
makeSerializable(
|
||||
CommentCompilationWarning,
|
||||
"webpack/lib/CommentCompilationWarning"
|
||||
);
|
||||
|
||||
module.exports = CommentCompilationWarning;
|
152
node_modules/webpack/lib/CompatibilityPlugin.js
generated
vendored
Normal file
152
node_modules/webpack/lib/CompatibilityPlugin.js
generated
vendored
Normal file
@@ -0,0 +1,152 @@
|
||||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
const ConstDependency = require("./dependencies/ConstDependency");
|
||||
|
||||
/** @typedef {import("./Compiler")} Compiler */
|
||||
/** @typedef {import("./javascript/JavascriptParser")} JavascriptParser */
|
||||
|
||||
const nestedWebpackRequireTag = Symbol("nested __webpack_require__");
|
||||
|
||||
class CompatibilityPlugin {
|
||||
/**
|
||||
* Apply the plugin
|
||||
* @param {Compiler} compiler the compiler instance
|
||||
* @returns {void}
|
||||
*/
|
||||
apply(compiler) {
|
||||
compiler.hooks.compilation.tap(
|
||||
"CompatibilityPlugin",
|
||||
(compilation, { normalModuleFactory }) => {
|
||||
compilation.dependencyTemplates.set(
|
||||
ConstDependency,
|
||||
new ConstDependency.Template()
|
||||
);
|
||||
|
||||
normalModuleFactory.hooks.parser
|
||||
.for("javascript/auto")
|
||||
.tap("CompatibilityPlugin", (parser, parserOptions) => {
|
||||
if (
|
||||
parserOptions.browserify !== undefined &&
|
||||
!parserOptions.browserify
|
||||
)
|
||||
return;
|
||||
|
||||
parser.hooks.call
|
||||
.for("require")
|
||||
.tap("CompatibilityPlugin", expr => {
|
||||
// support for browserify style require delegator: "require(o, !0)"
|
||||
if (expr.arguments.length !== 2) return;
|
||||
const second = parser.evaluateExpression(expr.arguments[1]);
|
||||
if (!second.isBoolean()) return;
|
||||
if (second.asBool() !== true) return;
|
||||
const dep = new ConstDependency("require", expr.callee.range);
|
||||
dep.loc = expr.loc;
|
||||
if (parser.state.current.dependencies.length > 0) {
|
||||
const last =
|
||||
parser.state.current.dependencies[
|
||||
parser.state.current.dependencies.length - 1
|
||||
];
|
||||
if (
|
||||
last.critical &&
|
||||
last.options &&
|
||||
last.options.request === "." &&
|
||||
last.userRequest === "." &&
|
||||
last.options.recursive
|
||||
)
|
||||
parser.state.current.dependencies.pop();
|
||||
}
|
||||
parser.state.module.addPresentationalDependency(dep);
|
||||
return true;
|
||||
});
|
||||
});
|
||||
|
||||
/**
|
||||
* @param {JavascriptParser} parser the parser
|
||||
* @returns {void}
|
||||
*/
|
||||
const handler = parser => {
|
||||
// Handle nested requires
|
||||
parser.hooks.preStatement.tap("CompatibilityPlugin", statement => {
|
||||
if (
|
||||
statement.type === "FunctionDeclaration" &&
|
||||
statement.id &&
|
||||
statement.id.name === "__webpack_require__"
|
||||
) {
|
||||
const newName = `__nested_webpack_require_${statement.range[0]}__`;
|
||||
parser.tagVariable(statement.id.name, nestedWebpackRequireTag, {
|
||||
name: newName,
|
||||
declaration: {
|
||||
updated: false,
|
||||
loc: statement.id.loc,
|
||||
range: statement.id.range
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
});
|
||||
parser.hooks.pattern
|
||||
.for("__webpack_require__")
|
||||
.tap("CompatibilityPlugin", pattern => {
|
||||
const newName = `__nested_webpack_require_${pattern.range[0]}__`;
|
||||
parser.tagVariable(pattern.name, nestedWebpackRequireTag, {
|
||||
name: newName,
|
||||
declaration: {
|
||||
updated: false,
|
||||
loc: pattern.loc,
|
||||
range: pattern.range
|
||||
}
|
||||
});
|
||||
return true;
|
||||
});
|
||||
parser.hooks.expression
|
||||
.for(nestedWebpackRequireTag)
|
||||
.tap("CompatibilityPlugin", expr => {
|
||||
const { name, declaration } = parser.currentTagData;
|
||||
if (!declaration.updated) {
|
||||
const dep = new ConstDependency(name, declaration.range);
|
||||
dep.loc = declaration.loc;
|
||||
parser.state.module.addPresentationalDependency(dep);
|
||||
declaration.updated = true;
|
||||
}
|
||||
const dep = new ConstDependency(name, expr.range);
|
||||
dep.loc = expr.loc;
|
||||
parser.state.module.addPresentationalDependency(dep);
|
||||
return true;
|
||||
});
|
||||
|
||||
// Handle hashbang
|
||||
parser.hooks.program.tap(
|
||||
"CompatibilityPlugin",
|
||||
(program, comments) => {
|
||||
if (comments.length === 0) return;
|
||||
const c = comments[0];
|
||||
if (c.type === "Line" && c.range[0] === 0) {
|
||||
if (parser.state.source.slice(0, 2).toString() !== "#!") return;
|
||||
// this is a hashbang comment
|
||||
const dep = new ConstDependency("//", 0);
|
||||
dep.loc = c.loc;
|
||||
parser.state.module.addPresentationalDependency(dep);
|
||||
}
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
normalModuleFactory.hooks.parser
|
||||
.for("javascript/auto")
|
||||
.tap("CompatibilityPlugin", handler);
|
||||
normalModuleFactory.hooks.parser
|
||||
.for("javascript/dynamic")
|
||||
.tap("CompatibilityPlugin", handler);
|
||||
normalModuleFactory.hooks.parser
|
||||
.for("javascript/esm")
|
||||
.tap("CompatibilityPlugin", handler);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
module.exports = CompatibilityPlugin;
|
5301
node_modules/webpack/lib/Compilation.js
generated
vendored
Normal file
5301
node_modules/webpack/lib/Compilation.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
1230
node_modules/webpack/lib/Compiler.js
generated
vendored
Normal file
1230
node_modules/webpack/lib/Compiler.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
159
node_modules/webpack/lib/ConcatenationScope.js
generated
vendored
Normal file
159
node_modules/webpack/lib/ConcatenationScope.js
generated
vendored
Normal file
@@ -0,0 +1,159 @@
|
||||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
/** @typedef {import("./Module")} Module */
|
||||
|
||||
const MODULE_REFERENCE_REGEXP =
|
||||
/^__WEBPACK_MODULE_REFERENCE__(\d+)_([\da-f]+|ns)(_call)?(_directImport)?(?:_asiSafe(\d))?__$/;
|
||||
|
||||
const DEFAULT_EXPORT = "__WEBPACK_DEFAULT_EXPORT__";
|
||||
const NAMESPACE_OBJECT_EXPORT = "__WEBPACK_NAMESPACE_OBJECT__";
|
||||
|
||||
/**
|
||||
* @typedef {Object} ExternalModuleInfo
|
||||
* @property {number} index
|
||||
* @property {Module} module
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object} ConcatenatedModuleInfo
|
||||
* @property {number} index
|
||||
* @property {Module} module
|
||||
* @property {Map<string, string>} exportMap mapping from export name to symbol
|
||||
* @property {Map<string, string>} rawExportMap mapping from export name to symbol
|
||||
* @property {string=} namespaceExportSymbol
|
||||
*/
|
||||
|
||||
/** @typedef {ConcatenatedModuleInfo | ExternalModuleInfo} ModuleInfo */
|
||||
|
||||
/**
|
||||
* @typedef {Object} ModuleReferenceOptions
|
||||
* @property {string[]} ids the properties/exports of the module
|
||||
* @property {boolean} call true, when this referenced export is called
|
||||
* @property {boolean} directImport true, when this referenced export is directly imported (not via property access)
|
||||
* @property {boolean | undefined} asiSafe if the position is ASI safe or unknown
|
||||
*/
|
||||
|
||||
class ConcatenationScope {
|
||||
/**
|
||||
* @param {ModuleInfo[] | Map<Module, ModuleInfo>} modulesMap all module info by module
|
||||
* @param {ConcatenatedModuleInfo} currentModule the current module info
|
||||
*/
|
||||
constructor(modulesMap, currentModule) {
|
||||
this._currentModule = currentModule;
|
||||
if (Array.isArray(modulesMap)) {
|
||||
const map = new Map();
|
||||
for (const info of modulesMap) {
|
||||
map.set(info.module, info);
|
||||
}
|
||||
modulesMap = map;
|
||||
}
|
||||
this._modulesMap = modulesMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Module} module the referenced module
|
||||
* @returns {boolean} true, when it's in the scope
|
||||
*/
|
||||
isModuleInScope(module) {
|
||||
return this._modulesMap.has(module);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {string} exportName name of the export
|
||||
* @param {string} symbol identifier of the export in source code
|
||||
*/
|
||||
registerExport(exportName, symbol) {
|
||||
if (!this._currentModule.exportMap) {
|
||||
this._currentModule.exportMap = new Map();
|
||||
}
|
||||
if (!this._currentModule.exportMap.has(exportName)) {
|
||||
this._currentModule.exportMap.set(exportName, symbol);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {string} exportName name of the export
|
||||
* @param {string} expression expression to be used
|
||||
*/
|
||||
registerRawExport(exportName, expression) {
|
||||
if (!this._currentModule.rawExportMap) {
|
||||
this._currentModule.rawExportMap = new Map();
|
||||
}
|
||||
if (!this._currentModule.rawExportMap.has(exportName)) {
|
||||
this._currentModule.rawExportMap.set(exportName, expression);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} symbol identifier of the export in source code
|
||||
*/
|
||||
registerNamespaceExport(symbol) {
|
||||
this._currentModule.namespaceExportSymbol = symbol;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {Module} module the referenced module
|
||||
* @param {Partial<ModuleReferenceOptions>} options options
|
||||
* @returns {string} the reference as identifier
|
||||
*/
|
||||
createModuleReference(
|
||||
module,
|
||||
{ ids = undefined, call = false, directImport = false, asiSafe = false }
|
||||
) {
|
||||
const info = this._modulesMap.get(module);
|
||||
const callFlag = call ? "_call" : "";
|
||||
const directImportFlag = directImport ? "_directImport" : "";
|
||||
const asiSafeFlag = asiSafe
|
||||
? "_asiSafe1"
|
||||
: asiSafe === false
|
||||
? "_asiSafe0"
|
||||
: "";
|
||||
const exportData = ids
|
||||
? Buffer.from(JSON.stringify(ids), "utf-8").toString("hex")
|
||||
: "ns";
|
||||
// a "._" is appended to allow "delete ...", which would cause a SyntaxError in strict mode
|
||||
return `__WEBPACK_MODULE_REFERENCE__${info.index}_${exportData}${callFlag}${directImportFlag}${asiSafeFlag}__._`;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} name the identifier
|
||||
* @returns {boolean} true, when it's an module reference
|
||||
*/
|
||||
static isModuleReference(name) {
|
||||
return MODULE_REFERENCE_REGEXP.test(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} name the identifier
|
||||
* @returns {ModuleReferenceOptions & { index: number }} parsed options and index
|
||||
*/
|
||||
static matchModuleReference(name) {
|
||||
const match = MODULE_REFERENCE_REGEXP.exec(name);
|
||||
if (!match) return null;
|
||||
const index = +match[1];
|
||||
const asiSafe = match[5];
|
||||
return {
|
||||
index,
|
||||
ids:
|
||||
match[2] === "ns"
|
||||
? []
|
||||
: JSON.parse(Buffer.from(match[2], "hex").toString("utf-8")),
|
||||
call: !!match[3],
|
||||
directImport: !!match[4],
|
||||
asiSafe: asiSafe ? asiSafe === "1" : undefined
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
ConcatenationScope.DEFAULT_EXPORT = DEFAULT_EXPORT;
|
||||
ConcatenationScope.NAMESPACE_OBJECT_EXPORT = NAMESPACE_OBJECT_EXPORT;
|
||||
|
||||
module.exports = ConcatenationScope;
|
18
node_modules/webpack/lib/ConcurrentCompilationError.js
generated
vendored
Normal file
18
node_modules/webpack/lib/ConcurrentCompilationError.js
generated
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Maksim Nazarjev @acupofspirt
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
const WebpackError = require("./WebpackError");
|
||||
|
||||
module.exports = class ConcurrentCompilationError extends WebpackError {
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.name = "ConcurrentCompilationError";
|
||||
this.message =
|
||||
"You ran Webpack twice. Each instance only supports a single concurrent compilation at a time.";
|
||||
}
|
||||
};
|
112
node_modules/webpack/lib/ConditionalInitFragment.js
generated
vendored
Normal file
112
node_modules/webpack/lib/ConditionalInitFragment.js
generated
vendored
Normal file
@@ -0,0 +1,112 @@
|
||||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
const { ConcatSource, PrefixSource } = require("webpack-sources");
|
||||
const InitFragment = require("./InitFragment");
|
||||
const Template = require("./Template");
|
||||
const { mergeRuntime } = require("./util/runtime");
|
||||
|
||||
/** @typedef {import("webpack-sources").Source} Source */
|
||||
/** @typedef {import("./Generator").GenerateContext} GenerateContext */
|
||||
/** @typedef {import("./util/runtime").RuntimeSpec} RuntimeSpec */
|
||||
|
||||
const wrapInCondition = (condition, source) => {
|
||||
if (typeof source === "string") {
|
||||
return Template.asString([
|
||||
`if (${condition}) {`,
|
||||
Template.indent(source),
|
||||
"}",
|
||||
""
|
||||
]);
|
||||
} else {
|
||||
return new ConcatSource(
|
||||
`if (${condition}) {\n`,
|
||||
new PrefixSource("\t", source),
|
||||
"}\n"
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @typedef {GenerateContext} Context
|
||||
*/
|
||||
class ConditionalInitFragment extends InitFragment {
|
||||
/**
|
||||
* @param {string|Source} content the source code that will be included as initialization code
|
||||
* @param {number} stage category of initialization code (contribute to order)
|
||||
* @param {number} position position in the category (contribute to order)
|
||||
* @param {string} key unique key to avoid emitting the same initialization code twice
|
||||
* @param {RuntimeSpec | boolean} runtimeCondition in which runtime this fragment should be executed
|
||||
* @param {string|Source=} endContent the source code that will be included at the end of the module
|
||||
*/
|
||||
constructor(
|
||||
content,
|
||||
stage,
|
||||
position,
|
||||
key,
|
||||
runtimeCondition = true,
|
||||
endContent
|
||||
) {
|
||||
super(content, stage, position, key, endContent);
|
||||
this.runtimeCondition = runtimeCondition;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Context} context context
|
||||
* @returns {string|Source} the source code that will be included as initialization code
|
||||
*/
|
||||
getContent(context) {
|
||||
if (this.runtimeCondition === false || !this.content) return "";
|
||||
if (this.runtimeCondition === true) return this.content;
|
||||
const expr = context.runtimeTemplate.runtimeConditionExpression({
|
||||
chunkGraph: context.chunkGraph,
|
||||
runtimeRequirements: context.runtimeRequirements,
|
||||
runtime: context.runtime,
|
||||
runtimeCondition: this.runtimeCondition
|
||||
});
|
||||
if (expr === "true") return this.content;
|
||||
return wrapInCondition(expr, this.content);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Context} context context
|
||||
* @returns {string|Source=} the source code that will be included at the end of the module
|
||||
*/
|
||||
getEndContent(context) {
|
||||
if (this.runtimeCondition === false || !this.endContent) return "";
|
||||
if (this.runtimeCondition === true) return this.endContent;
|
||||
const expr = context.runtimeTemplate.runtimeConditionExpression({
|
||||
chunkGraph: context.chunkGraph,
|
||||
runtimeRequirements: context.runtimeRequirements,
|
||||
runtime: context.runtime,
|
||||
runtimeCondition: this.runtimeCondition
|
||||
});
|
||||
if (expr === "true") return this.endContent;
|
||||
return wrapInCondition(expr, this.endContent);
|
||||
}
|
||||
|
||||
merge(other) {
|
||||
if (this.runtimeCondition === true) return this;
|
||||
if (other.runtimeCondition === true) return other;
|
||||
if (this.runtimeCondition === false) return other;
|
||||
if (other.runtimeCondition === false) return this;
|
||||
const runtimeCondition = mergeRuntime(
|
||||
this.runtimeCondition,
|
||||
other.runtimeCondition
|
||||
);
|
||||
return new ConditionalInitFragment(
|
||||
this.content,
|
||||
this.stage,
|
||||
this.position,
|
||||
this.key,
|
||||
runtimeCondition,
|
||||
this.endContent
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ConditionalInitFragment;
|
497
node_modules/webpack/lib/ConstPlugin.js
generated
vendored
Normal file
497
node_modules/webpack/lib/ConstPlugin.js
generated
vendored
Normal file
@@ -0,0 +1,497 @@
|
||||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
const CachedConstDependency = require("./dependencies/CachedConstDependency");
|
||||
const ConstDependency = require("./dependencies/ConstDependency");
|
||||
const { evaluateToString } = require("./javascript/JavascriptParserHelpers");
|
||||
const { parseResource } = require("./util/identifier");
|
||||
|
||||
/** @typedef {import("estree").Expression} ExpressionNode */
|
||||
/** @typedef {import("estree").Super} SuperNode */
|
||||
/** @typedef {import("./Compiler")} Compiler */
|
||||
|
||||
const collectDeclaration = (declarations, pattern) => {
|
||||
const stack = [pattern];
|
||||
while (stack.length > 0) {
|
||||
const node = stack.pop();
|
||||
switch (node.type) {
|
||||
case "Identifier":
|
||||
declarations.add(node.name);
|
||||
break;
|
||||
case "ArrayPattern":
|
||||
for (const element of node.elements) {
|
||||
if (element) {
|
||||
stack.push(element);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "AssignmentPattern":
|
||||
stack.push(node.left);
|
||||
break;
|
||||
case "ObjectPattern":
|
||||
for (const property of node.properties) {
|
||||
stack.push(property.value);
|
||||
}
|
||||
break;
|
||||
case "RestElement":
|
||||
stack.push(node.argument);
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const getHoistedDeclarations = (branch, includeFunctionDeclarations) => {
|
||||
const declarations = new Set();
|
||||
const stack = [branch];
|
||||
while (stack.length > 0) {
|
||||
const node = stack.pop();
|
||||
// Some node could be `null` or `undefined`.
|
||||
if (!node) continue;
|
||||
switch (node.type) {
|
||||
// Walk through control statements to look for hoisted declarations.
|
||||
// Some branches are skipped since they do not allow declarations.
|
||||
case "BlockStatement":
|
||||
for (const stmt of node.body) {
|
||||
stack.push(stmt);
|
||||
}
|
||||
break;
|
||||
case "IfStatement":
|
||||
stack.push(node.consequent);
|
||||
stack.push(node.alternate);
|
||||
break;
|
||||
case "ForStatement":
|
||||
stack.push(node.init);
|
||||
stack.push(node.body);
|
||||
break;
|
||||
case "ForInStatement":
|
||||
case "ForOfStatement":
|
||||
stack.push(node.left);
|
||||
stack.push(node.body);
|
||||
break;
|
||||
case "DoWhileStatement":
|
||||
case "WhileStatement":
|
||||
case "LabeledStatement":
|
||||
stack.push(node.body);
|
||||
break;
|
||||
case "SwitchStatement":
|
||||
for (const cs of node.cases) {
|
||||
for (const consequent of cs.consequent) {
|
||||
stack.push(consequent);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "TryStatement":
|
||||
stack.push(node.block);
|
||||
if (node.handler) {
|
||||
stack.push(node.handler.body);
|
||||
}
|
||||
stack.push(node.finalizer);
|
||||
break;
|
||||
case "FunctionDeclaration":
|
||||
if (includeFunctionDeclarations) {
|
||||
collectDeclaration(declarations, node.id);
|
||||
}
|
||||
break;
|
||||
case "VariableDeclaration":
|
||||
if (node.kind === "var") {
|
||||
for (const decl of node.declarations) {
|
||||
collectDeclaration(declarations, decl.id);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return Array.from(declarations);
|
||||
};
|
||||
|
||||
class ConstPlugin {
|
||||
/**
|
||||
* Apply the plugin
|
||||
* @param {Compiler} compiler the compiler instance
|
||||
* @returns {void}
|
||||
*/
|
||||
apply(compiler) {
|
||||
const cachedParseResource = parseResource.bindCache(compiler.root);
|
||||
compiler.hooks.compilation.tap(
|
||||
"ConstPlugin",
|
||||
(compilation, { normalModuleFactory }) => {
|
||||
compilation.dependencyTemplates.set(
|
||||
ConstDependency,
|
||||
new ConstDependency.Template()
|
||||
);
|
||||
|
||||
compilation.dependencyTemplates.set(
|
||||
CachedConstDependency,
|
||||
new CachedConstDependency.Template()
|
||||
);
|
||||
|
||||
const handler = parser => {
|
||||
parser.hooks.statementIf.tap("ConstPlugin", statement => {
|
||||
if (parser.scope.isAsmJs) return;
|
||||
const param = parser.evaluateExpression(statement.test);
|
||||
const bool = param.asBool();
|
||||
if (typeof bool === "boolean") {
|
||||
if (!param.couldHaveSideEffects()) {
|
||||
const dep = new ConstDependency(`${bool}`, param.range);
|
||||
dep.loc = statement.loc;
|
||||
parser.state.module.addPresentationalDependency(dep);
|
||||
} else {
|
||||
parser.walkExpression(statement.test);
|
||||
}
|
||||
const branchToRemove = bool
|
||||
? statement.alternate
|
||||
: statement.consequent;
|
||||
if (branchToRemove) {
|
||||
// Before removing the dead branch, the hoisted declarations
|
||||
// must be collected.
|
||||
//
|
||||
// Given the following code:
|
||||
//
|
||||
// if (true) f() else g()
|
||||
// if (false) {
|
||||
// function f() {}
|
||||
// const g = function g() {}
|
||||
// if (someTest) {
|
||||
// let a = 1
|
||||
// var x, {y, z} = obj
|
||||
// }
|
||||
// } else {
|
||||
// …
|
||||
// }
|
||||
//
|
||||
// the generated code is:
|
||||
//
|
||||
// if (true) f() else {}
|
||||
// if (false) {
|
||||
// var f, x, y, z; (in loose mode)
|
||||
// var x, y, z; (in strict mode)
|
||||
// } else {
|
||||
// …
|
||||
// }
|
||||
//
|
||||
// NOTE: When code runs in strict mode, `var` declarations
|
||||
// are hoisted but `function` declarations don't.
|
||||
//
|
||||
let declarations;
|
||||
if (parser.scope.isStrict) {
|
||||
// If the code runs in strict mode, variable declarations
|
||||
// using `var` must be hoisted.
|
||||
declarations = getHoistedDeclarations(branchToRemove, false);
|
||||
} else {
|
||||
// Otherwise, collect all hoisted declaration.
|
||||
declarations = getHoistedDeclarations(branchToRemove, true);
|
||||
}
|
||||
let replacement;
|
||||
if (declarations.length > 0) {
|
||||
replacement = `{ var ${declarations.join(", ")}; }`;
|
||||
} else {
|
||||
replacement = "{}";
|
||||
}
|
||||
const dep = new ConstDependency(
|
||||
replacement,
|
||||
branchToRemove.range
|
||||
);
|
||||
dep.loc = branchToRemove.loc;
|
||||
parser.state.module.addPresentationalDependency(dep);
|
||||
}
|
||||
return bool;
|
||||
}
|
||||
});
|
||||
parser.hooks.expressionConditionalOperator.tap(
|
||||
"ConstPlugin",
|
||||
expression => {
|
||||
if (parser.scope.isAsmJs) return;
|
||||
const param = parser.evaluateExpression(expression.test);
|
||||
const bool = param.asBool();
|
||||
if (typeof bool === "boolean") {
|
||||
if (!param.couldHaveSideEffects()) {
|
||||
const dep = new ConstDependency(` ${bool}`, param.range);
|
||||
dep.loc = expression.loc;
|
||||
parser.state.module.addPresentationalDependency(dep);
|
||||
} else {
|
||||
parser.walkExpression(expression.test);
|
||||
}
|
||||
// Expressions do not hoist.
|
||||
// It is safe to remove the dead branch.
|
||||
//
|
||||
// Given the following code:
|
||||
//
|
||||
// false ? someExpression() : otherExpression();
|
||||
//
|
||||
// the generated code is:
|
||||
//
|
||||
// false ? 0 : otherExpression();
|
||||
//
|
||||
const branchToRemove = bool
|
||||
? expression.alternate
|
||||
: expression.consequent;
|
||||
const dep = new ConstDependency("0", branchToRemove.range);
|
||||
dep.loc = branchToRemove.loc;
|
||||
parser.state.module.addPresentationalDependency(dep);
|
||||
return bool;
|
||||
}
|
||||
}
|
||||
);
|
||||
parser.hooks.expressionLogicalOperator.tap(
|
||||
"ConstPlugin",
|
||||
expression => {
|
||||
if (parser.scope.isAsmJs) return;
|
||||
if (
|
||||
expression.operator === "&&" ||
|
||||
expression.operator === "||"
|
||||
) {
|
||||
const param = parser.evaluateExpression(expression.left);
|
||||
const bool = param.asBool();
|
||||
if (typeof bool === "boolean") {
|
||||
// Expressions do not hoist.
|
||||
// It is safe to remove the dead branch.
|
||||
//
|
||||
// ------------------------------------------
|
||||
//
|
||||
// Given the following code:
|
||||
//
|
||||
// falsyExpression() && someExpression();
|
||||
//
|
||||
// the generated code is:
|
||||
//
|
||||
// falsyExpression() && false;
|
||||
//
|
||||
// ------------------------------------------
|
||||
//
|
||||
// Given the following code:
|
||||
//
|
||||
// truthyExpression() && someExpression();
|
||||
//
|
||||
// the generated code is:
|
||||
//
|
||||
// true && someExpression();
|
||||
//
|
||||
// ------------------------------------------
|
||||
//
|
||||
// Given the following code:
|
||||
//
|
||||
// truthyExpression() || someExpression();
|
||||
//
|
||||
// the generated code is:
|
||||
//
|
||||
// truthyExpression() || false;
|
||||
//
|
||||
// ------------------------------------------
|
||||
//
|
||||
// Given the following code:
|
||||
//
|
||||
// falsyExpression() || someExpression();
|
||||
//
|
||||
// the generated code is:
|
||||
//
|
||||
// false && someExpression();
|
||||
//
|
||||
const keepRight =
|
||||
(expression.operator === "&&" && bool) ||
|
||||
(expression.operator === "||" && !bool);
|
||||
|
||||
if (
|
||||
!param.couldHaveSideEffects() &&
|
||||
(param.isBoolean() || keepRight)
|
||||
) {
|
||||
// for case like
|
||||
//
|
||||
// return'development'===process.env.NODE_ENV&&'foo'
|
||||
//
|
||||
// we need a space before the bool to prevent result like
|
||||
//
|
||||
// returnfalse&&'foo'
|
||||
//
|
||||
const dep = new ConstDependency(` ${bool}`, param.range);
|
||||
dep.loc = expression.loc;
|
||||
parser.state.module.addPresentationalDependency(dep);
|
||||
} else {
|
||||
parser.walkExpression(expression.left);
|
||||
}
|
||||
if (!keepRight) {
|
||||
const dep = new ConstDependency(
|
||||
"0",
|
||||
expression.right.range
|
||||
);
|
||||
dep.loc = expression.loc;
|
||||
parser.state.module.addPresentationalDependency(dep);
|
||||
}
|
||||
return keepRight;
|
||||
}
|
||||
} else if (expression.operator === "??") {
|
||||
const param = parser.evaluateExpression(expression.left);
|
||||
const keepRight = param.asNullish();
|
||||
if (typeof keepRight === "boolean") {
|
||||
// ------------------------------------------
|
||||
//
|
||||
// Given the following code:
|
||||
//
|
||||
// nonNullish ?? someExpression();
|
||||
//
|
||||
// the generated code is:
|
||||
//
|
||||
// nonNullish ?? 0;
|
||||
//
|
||||
// ------------------------------------------
|
||||
//
|
||||
// Given the following code:
|
||||
//
|
||||
// nullish ?? someExpression();
|
||||
//
|
||||
// the generated code is:
|
||||
//
|
||||
// null ?? someExpression();
|
||||
//
|
||||
if (!param.couldHaveSideEffects() && keepRight) {
|
||||
// cspell:word returnnull
|
||||
// for case like
|
||||
//
|
||||
// return('development'===process.env.NODE_ENV&&null)??'foo'
|
||||
//
|
||||
// we need a space before the bool to prevent result like
|
||||
//
|
||||
// returnnull??'foo'
|
||||
//
|
||||
const dep = new ConstDependency(" null", param.range);
|
||||
dep.loc = expression.loc;
|
||||
parser.state.module.addPresentationalDependency(dep);
|
||||
} else {
|
||||
const dep = new ConstDependency(
|
||||
"0",
|
||||
expression.right.range
|
||||
);
|
||||
dep.loc = expression.loc;
|
||||
parser.state.module.addPresentationalDependency(dep);
|
||||
parser.walkExpression(expression.left);
|
||||
}
|
||||
|
||||
return keepRight;
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
parser.hooks.optionalChaining.tap("ConstPlugin", expr => {
|
||||
/** @type {ExpressionNode[]} */
|
||||
const optionalExpressionsStack = [];
|
||||
/** @type {ExpressionNode|SuperNode} */
|
||||
let next = expr.expression;
|
||||
|
||||
while (
|
||||
next.type === "MemberExpression" ||
|
||||
next.type === "CallExpression"
|
||||
) {
|
||||
if (next.type === "MemberExpression") {
|
||||
if (next.optional) {
|
||||
// SuperNode can not be optional
|
||||
optionalExpressionsStack.push(
|
||||
/** @type {ExpressionNode} */ (next.object)
|
||||
);
|
||||
}
|
||||
next = next.object;
|
||||
} else {
|
||||
if (next.optional) {
|
||||
// SuperNode can not be optional
|
||||
optionalExpressionsStack.push(
|
||||
/** @type {ExpressionNode} */ (next.callee)
|
||||
);
|
||||
}
|
||||
next = next.callee;
|
||||
}
|
||||
}
|
||||
|
||||
while (optionalExpressionsStack.length) {
|
||||
const expression = optionalExpressionsStack.pop();
|
||||
const evaluated = parser.evaluateExpression(expression);
|
||||
|
||||
if (evaluated.asNullish()) {
|
||||
// ------------------------------------------
|
||||
//
|
||||
// Given the following code:
|
||||
//
|
||||
// nullishMemberChain?.a.b();
|
||||
//
|
||||
// the generated code is:
|
||||
//
|
||||
// undefined;
|
||||
//
|
||||
// ------------------------------------------
|
||||
//
|
||||
const dep = new ConstDependency(" undefined", expr.range);
|
||||
dep.loc = expr.loc;
|
||||
parser.state.module.addPresentationalDependency(dep);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
});
|
||||
parser.hooks.evaluateIdentifier
|
||||
.for("__resourceQuery")
|
||||
.tap("ConstPlugin", expr => {
|
||||
if (parser.scope.isAsmJs) return;
|
||||
if (!parser.state.module) return;
|
||||
return evaluateToString(
|
||||
cachedParseResource(parser.state.module.resource).query
|
||||
)(expr);
|
||||
});
|
||||
parser.hooks.expression
|
||||
.for("__resourceQuery")
|
||||
.tap("ConstPlugin", expr => {
|
||||
if (parser.scope.isAsmJs) return;
|
||||
if (!parser.state.module) return;
|
||||
const dep = new CachedConstDependency(
|
||||
JSON.stringify(
|
||||
cachedParseResource(parser.state.module.resource).query
|
||||
),
|
||||
expr.range,
|
||||
"__resourceQuery"
|
||||
);
|
||||
dep.loc = expr.loc;
|
||||
parser.state.module.addPresentationalDependency(dep);
|
||||
return true;
|
||||
});
|
||||
|
||||
parser.hooks.evaluateIdentifier
|
||||
.for("__resourceFragment")
|
||||
.tap("ConstPlugin", expr => {
|
||||
if (parser.scope.isAsmJs) return;
|
||||
if (!parser.state.module) return;
|
||||
return evaluateToString(
|
||||
cachedParseResource(parser.state.module.resource).fragment
|
||||
)(expr);
|
||||
});
|
||||
parser.hooks.expression
|
||||
.for("__resourceFragment")
|
||||
.tap("ConstPlugin", expr => {
|
||||
if (parser.scope.isAsmJs) return;
|
||||
if (!parser.state.module) return;
|
||||
const dep = new CachedConstDependency(
|
||||
JSON.stringify(
|
||||
cachedParseResource(parser.state.module.resource).fragment
|
||||
),
|
||||
expr.range,
|
||||
"__resourceFragment"
|
||||
);
|
||||
dep.loc = expr.loc;
|
||||
parser.state.module.addPresentationalDependency(dep);
|
||||
return true;
|
||||
});
|
||||
};
|
||||
|
||||
normalModuleFactory.hooks.parser
|
||||
.for("javascript/auto")
|
||||
.tap("ConstPlugin", handler);
|
||||
normalModuleFactory.hooks.parser
|
||||
.for("javascript/dynamic")
|
||||
.tap("ConstPlugin", handler);
|
||||
normalModuleFactory.hooks.parser
|
||||
.for("javascript/esm")
|
||||
.tap("ConstPlugin", handler);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ConstPlugin;
|
32
node_modules/webpack/lib/ContextExclusionPlugin.js
generated
vendored
Normal file
32
node_modules/webpack/lib/ContextExclusionPlugin.js
generated
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
/** @typedef {import("./Compiler")} Compiler */
|
||||
/** @typedef {import("./ContextModuleFactory")} ContextModuleFactory */
|
||||
|
||||
class ContextExclusionPlugin {
|
||||
/**
|
||||
* @param {RegExp} negativeMatcher Matcher regular expression
|
||||
*/
|
||||
constructor(negativeMatcher) {
|
||||
this.negativeMatcher = negativeMatcher;
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply the plugin
|
||||
* @param {Compiler} compiler the compiler instance
|
||||
* @returns {void}
|
||||
*/
|
||||
apply(compiler) {
|
||||
compiler.hooks.contextModuleFactory.tap("ContextExclusionPlugin", cmf => {
|
||||
cmf.hooks.contextModuleFiles.tap("ContextExclusionPlugin", files => {
|
||||
return files.filter(filePath => !this.negativeMatcher.test(filePath));
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ContextExclusionPlugin;
|
1170
node_modules/webpack/lib/ContextModule.js
generated
vendored
Normal file
1170
node_modules/webpack/lib/ContextModule.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
433
node_modules/webpack/lib/ContextModuleFactory.js
generated
vendored
Normal file
433
node_modules/webpack/lib/ContextModuleFactory.js
generated
vendored
Normal file
@@ -0,0 +1,433 @@
|
||||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
const asyncLib = require("neo-async");
|
||||
const { AsyncSeriesWaterfallHook, SyncWaterfallHook } = require("tapable");
|
||||
const ContextModule = require("./ContextModule");
|
||||
const ModuleFactory = require("./ModuleFactory");
|
||||
const ContextElementDependency = require("./dependencies/ContextElementDependency");
|
||||
const LazySet = require("./util/LazySet");
|
||||
const { cachedSetProperty } = require("./util/cleverMerge");
|
||||
const { createFakeHook } = require("./util/deprecation");
|
||||
const { join } = require("./util/fs");
|
||||
|
||||
/** @typedef {import("./ContextModule").ContextModuleOptions} ContextModuleOptions */
|
||||
/** @typedef {import("./ContextModule").ResolveDependenciesCallback} ResolveDependenciesCallback */
|
||||
/** @typedef {import("./Module")} Module */
|
||||
/** @typedef {import("./ModuleFactory").ModuleFactoryCreateData} ModuleFactoryCreateData */
|
||||
/** @typedef {import("./ModuleFactory").ModuleFactoryResult} ModuleFactoryResult */
|
||||
/** @typedef {import("./ResolverFactory")} ResolverFactory */
|
||||
/** @typedef {import("./dependencies/ContextDependency")} ContextDependency */
|
||||
/** @template T @typedef {import("./util/deprecation").FakeHook<T>} FakeHook<T> */
|
||||
/** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */
|
||||
|
||||
const EMPTY_RESOLVE_OPTIONS = {};
|
||||
|
||||
module.exports = class ContextModuleFactory extends ModuleFactory {
|
||||
/**
|
||||
* @param {ResolverFactory} resolverFactory resolverFactory
|
||||
*/
|
||||
constructor(resolverFactory) {
|
||||
super();
|
||||
/** @type {AsyncSeriesWaterfallHook<[TODO[], ContextModuleOptions]>} */
|
||||
const alternativeRequests = new AsyncSeriesWaterfallHook([
|
||||
"modules",
|
||||
"options"
|
||||
]);
|
||||
this.hooks = Object.freeze({
|
||||
/** @type {AsyncSeriesWaterfallHook<[TODO]>} */
|
||||
beforeResolve: new AsyncSeriesWaterfallHook(["data"]),
|
||||
/** @type {AsyncSeriesWaterfallHook<[TODO]>} */
|
||||
afterResolve: new AsyncSeriesWaterfallHook(["data"]),
|
||||
/** @type {SyncWaterfallHook<[string[]]>} */
|
||||
contextModuleFiles: new SyncWaterfallHook(["files"]),
|
||||
/** @type {FakeHook<Pick<AsyncSeriesWaterfallHook<[TODO[]]>, "tap" | "tapAsync" | "tapPromise" | "name">>} */
|
||||
alternatives: createFakeHook(
|
||||
{
|
||||
name: "alternatives",
|
||||
/** @type {AsyncSeriesWaterfallHook<[TODO[]]>["intercept"]} */
|
||||
intercept: interceptor => {
|
||||
throw new Error(
|
||||
"Intercepting fake hook ContextModuleFactory.hooks.alternatives is not possible, use ContextModuleFactory.hooks.alternativeRequests instead"
|
||||
);
|
||||
},
|
||||
/** @type {AsyncSeriesWaterfallHook<[TODO[]]>["tap"]} */
|
||||
tap: (options, fn) => {
|
||||
alternativeRequests.tap(options, fn);
|
||||
},
|
||||
/** @type {AsyncSeriesWaterfallHook<[TODO[]]>["tapAsync"]} */
|
||||
tapAsync: (options, fn) => {
|
||||
alternativeRequests.tapAsync(options, (items, _options, callback) =>
|
||||
fn(items, callback)
|
||||
);
|
||||
},
|
||||
/** @type {AsyncSeriesWaterfallHook<[TODO[]]>["tapPromise"]} */
|
||||
tapPromise: (options, fn) => {
|
||||
alternativeRequests.tapPromise(options, fn);
|
||||
}
|
||||
},
|
||||
"ContextModuleFactory.hooks.alternatives has deprecated in favor of ContextModuleFactory.hooks.alternativeRequests with an additional options argument.",
|
||||
"DEP_WEBPACK_CONTEXT_MODULE_FACTORY_ALTERNATIVES"
|
||||
),
|
||||
alternativeRequests
|
||||
});
|
||||
this.resolverFactory = resolverFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {ModuleFactoryCreateData} data data object
|
||||
* @param {function(Error=, ModuleFactoryResult=): void} callback callback
|
||||
* @returns {void}
|
||||
*/
|
||||
create(data, callback) {
|
||||
const context = data.context;
|
||||
const dependencies = data.dependencies;
|
||||
const resolveOptions = data.resolveOptions;
|
||||
const dependency = /** @type {ContextDependency} */ (dependencies[0]);
|
||||
const fileDependencies = new LazySet();
|
||||
const missingDependencies = new LazySet();
|
||||
const contextDependencies = new LazySet();
|
||||
this.hooks.beforeResolve.callAsync(
|
||||
{
|
||||
context: context,
|
||||
dependencies: dependencies,
|
||||
resolveOptions,
|
||||
fileDependencies,
|
||||
missingDependencies,
|
||||
contextDependencies,
|
||||
...dependency.options
|
||||
},
|
||||
(err, beforeResolveResult) => {
|
||||
if (err) {
|
||||
return callback(err, {
|
||||
fileDependencies,
|
||||
missingDependencies,
|
||||
contextDependencies
|
||||
});
|
||||
}
|
||||
|
||||
// Ignored
|
||||
if (!beforeResolveResult) {
|
||||
return callback(null, {
|
||||
fileDependencies,
|
||||
missingDependencies,
|
||||
contextDependencies
|
||||
});
|
||||
}
|
||||
|
||||
const context = beforeResolveResult.context;
|
||||
const request = beforeResolveResult.request;
|
||||
const resolveOptions = beforeResolveResult.resolveOptions;
|
||||
|
||||
let loaders,
|
||||
resource,
|
||||
loadersPrefix = "";
|
||||
const idx = request.lastIndexOf("!");
|
||||
if (idx >= 0) {
|
||||
let loadersRequest = request.slice(0, idx + 1);
|
||||
let i;
|
||||
for (
|
||||
i = 0;
|
||||
i < loadersRequest.length && loadersRequest[i] === "!";
|
||||
i++
|
||||
) {
|
||||
loadersPrefix += "!";
|
||||
}
|
||||
loadersRequest = loadersRequest
|
||||
.slice(i)
|
||||
.replace(/!+$/, "")
|
||||
.replace(/!!+/g, "!");
|
||||
if (loadersRequest === "") {
|
||||
loaders = [];
|
||||
} else {
|
||||
loaders = loadersRequest.split("!");
|
||||
}
|
||||
resource = request.slice(idx + 1);
|
||||
} else {
|
||||
loaders = [];
|
||||
resource = request;
|
||||
}
|
||||
|
||||
const contextResolver = this.resolverFactory.get(
|
||||
"context",
|
||||
dependencies.length > 0
|
||||
? cachedSetProperty(
|
||||
resolveOptions || EMPTY_RESOLVE_OPTIONS,
|
||||
"dependencyType",
|
||||
dependencies[0].category
|
||||
)
|
||||
: resolveOptions
|
||||
);
|
||||
const loaderResolver = this.resolverFactory.get("loader");
|
||||
|
||||
asyncLib.parallel(
|
||||
[
|
||||
callback => {
|
||||
const results = [];
|
||||
const yield_ = obj => results.push(obj);
|
||||
|
||||
contextResolver.resolve(
|
||||
{},
|
||||
context,
|
||||
resource,
|
||||
{
|
||||
fileDependencies,
|
||||
missingDependencies,
|
||||
contextDependencies,
|
||||
yield: yield_
|
||||
},
|
||||
err => {
|
||||
if (err) return callback(err);
|
||||
callback(null, results);
|
||||
}
|
||||
);
|
||||
},
|
||||
callback => {
|
||||
asyncLib.map(
|
||||
loaders,
|
||||
(loader, callback) => {
|
||||
loaderResolver.resolve(
|
||||
{},
|
||||
context,
|
||||
loader,
|
||||
{
|
||||
fileDependencies,
|
||||
missingDependencies,
|
||||
contextDependencies
|
||||
},
|
||||
(err, result) => {
|
||||
if (err) return callback(err);
|
||||
callback(null, result);
|
||||
}
|
||||
);
|
||||
},
|
||||
callback
|
||||
);
|
||||
}
|
||||
],
|
||||
(err, result) => {
|
||||
if (err) {
|
||||
return callback(err, {
|
||||
fileDependencies,
|
||||
missingDependencies,
|
||||
contextDependencies
|
||||
});
|
||||
}
|
||||
let [contextResult, loaderResult] = result;
|
||||
if (contextResult.length > 1) {
|
||||
const first = contextResult[0];
|
||||
contextResult = contextResult.filter(r => r.path);
|
||||
if (contextResult.length === 0) contextResult.push(first);
|
||||
}
|
||||
this.hooks.afterResolve.callAsync(
|
||||
{
|
||||
addon:
|
||||
loadersPrefix +
|
||||
loaderResult.join("!") +
|
||||
(loaderResult.length > 0 ? "!" : ""),
|
||||
resource:
|
||||
contextResult.length > 1
|
||||
? contextResult.map(r => r.path)
|
||||
: contextResult[0].path,
|
||||
resolveDependencies: this.resolveDependencies.bind(this),
|
||||
resourceQuery: contextResult[0].query,
|
||||
resourceFragment: contextResult[0].fragment,
|
||||
...beforeResolveResult
|
||||
},
|
||||
(err, result) => {
|
||||
if (err) {
|
||||
return callback(err, {
|
||||
fileDependencies,
|
||||
missingDependencies,
|
||||
contextDependencies
|
||||
});
|
||||
}
|
||||
|
||||
// Ignored
|
||||
if (!result) {
|
||||
return callback(null, {
|
||||
fileDependencies,
|
||||
missingDependencies,
|
||||
contextDependencies
|
||||
});
|
||||
}
|
||||
|
||||
return callback(null, {
|
||||
module: new ContextModule(result.resolveDependencies, result),
|
||||
fileDependencies,
|
||||
missingDependencies,
|
||||
contextDependencies
|
||||
});
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {InputFileSystem} fs file system
|
||||
* @param {ContextModuleOptions} options options
|
||||
* @param {ResolveDependenciesCallback} callback callback function
|
||||
* @returns {void}
|
||||
*/
|
||||
resolveDependencies(fs, options, callback) {
|
||||
const cmf = this;
|
||||
const {
|
||||
resource,
|
||||
resourceQuery,
|
||||
resourceFragment,
|
||||
recursive,
|
||||
regExp,
|
||||
include,
|
||||
exclude,
|
||||
referencedExports,
|
||||
category,
|
||||
typePrefix
|
||||
} = options;
|
||||
if (!regExp || !resource) return callback(null, []);
|
||||
|
||||
const addDirectoryChecked = (ctx, directory, visited, callback) => {
|
||||
fs.realpath(directory, (err, realPath) => {
|
||||
if (err) return callback(err);
|
||||
if (visited.has(realPath)) return callback(null, []);
|
||||
let recursionStack;
|
||||
addDirectory(
|
||||
ctx,
|
||||
directory,
|
||||
(_, dir, callback) => {
|
||||
if (recursionStack === undefined) {
|
||||
recursionStack = new Set(visited);
|
||||
recursionStack.add(realPath);
|
||||
}
|
||||
addDirectoryChecked(ctx, dir, recursionStack, callback);
|
||||
},
|
||||
callback
|
||||
);
|
||||
});
|
||||
};
|
||||
|
||||
const addDirectory = (ctx, directory, addSubDirectory, callback) => {
|
||||
fs.readdir(directory, (err, files) => {
|
||||
if (err) return callback(err);
|
||||
const processedFiles = cmf.hooks.contextModuleFiles.call(
|
||||
/** @type {string[]} */ (files).map(file => file.normalize("NFC"))
|
||||
);
|
||||
if (!processedFiles || processedFiles.length === 0)
|
||||
return callback(null, []);
|
||||
asyncLib.map(
|
||||
processedFiles.filter(p => p.indexOf(".") !== 0),
|
||||
(segment, callback) => {
|
||||
const subResource = join(fs, directory, segment);
|
||||
|
||||
if (!exclude || !subResource.match(exclude)) {
|
||||
fs.stat(subResource, (err, stat) => {
|
||||
if (err) {
|
||||
if (err.code === "ENOENT") {
|
||||
// ENOENT is ok here because the file may have been deleted between
|
||||
// the readdir and stat calls.
|
||||
return callback();
|
||||
} else {
|
||||
return callback(err);
|
||||
}
|
||||
}
|
||||
|
||||
if (stat.isDirectory()) {
|
||||
if (!recursive) return callback();
|
||||
addSubDirectory(ctx, subResource, callback);
|
||||
} else if (
|
||||
stat.isFile() &&
|
||||
(!include || subResource.match(include))
|
||||
) {
|
||||
const obj = {
|
||||
context: ctx,
|
||||
request:
|
||||
"." + subResource.slice(ctx.length).replace(/\\/g, "/")
|
||||
};
|
||||
|
||||
this.hooks.alternativeRequests.callAsync(
|
||||
[obj],
|
||||
options,
|
||||
(err, alternatives) => {
|
||||
if (err) return callback(err);
|
||||
alternatives = alternatives
|
||||
.filter(obj => regExp.test(obj.request))
|
||||
.map(obj => {
|
||||
const dep = new ContextElementDependency(
|
||||
`${obj.request}${resourceQuery}${resourceFragment}`,
|
||||
obj.request,
|
||||
typePrefix,
|
||||
category,
|
||||
referencedExports,
|
||||
obj.context
|
||||
);
|
||||
dep.optional = true;
|
||||
return dep;
|
||||
});
|
||||
callback(null, alternatives);
|
||||
}
|
||||
);
|
||||
} else {
|
||||
callback();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
callback();
|
||||
}
|
||||
},
|
||||
(err, result) => {
|
||||
if (err) return callback(err);
|
||||
|
||||
if (!result) return callback(null, []);
|
||||
|
||||
const flattenedResult = [];
|
||||
|
||||
for (const item of result) {
|
||||
if (item) flattenedResult.push(...item);
|
||||
}
|
||||
|
||||
callback(null, flattenedResult);
|
||||
}
|
||||
);
|
||||
});
|
||||
};
|
||||
|
||||
const addSubDirectory = (ctx, dir, callback) =>
|
||||
addDirectory(ctx, dir, addSubDirectory, callback);
|
||||
|
||||
const visitResource = (resource, callback) => {
|
||||
if (typeof fs.realpath === "function") {
|
||||
addDirectoryChecked(resource, resource, new Set(), callback);
|
||||
} else {
|
||||
addDirectory(resource, resource, addSubDirectory, callback);
|
||||
}
|
||||
};
|
||||
|
||||
if (typeof resource === "string") {
|
||||
visitResource(resource, callback);
|
||||
} else {
|
||||
asyncLib.map(resource, visitResource, (err, result) => {
|
||||
if (err) return callback(err);
|
||||
|
||||
// result dependencies should have unique userRequest
|
||||
// ordered by resolve result
|
||||
const temp = new Set();
|
||||
const res = [];
|
||||
for (let i = 0; i < result.length; i++) {
|
||||
const inner = result[i];
|
||||
for (const el of inner) {
|
||||
if (temp.has(el.userRequest)) continue;
|
||||
res.push(el);
|
||||
temp.add(el.userRequest);
|
||||
}
|
||||
}
|
||||
callback(null, res);
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
157
node_modules/webpack/lib/ContextReplacementPlugin.js
generated
vendored
Normal file
157
node_modules/webpack/lib/ContextReplacementPlugin.js
generated
vendored
Normal file
@@ -0,0 +1,157 @@
|
||||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
const ContextElementDependency = require("./dependencies/ContextElementDependency");
|
||||
const { join } = require("./util/fs");
|
||||
|
||||
class ContextReplacementPlugin {
|
||||
constructor(
|
||||
resourceRegExp,
|
||||
newContentResource,
|
||||
newContentRecursive,
|
||||
newContentRegExp
|
||||
) {
|
||||
this.resourceRegExp = resourceRegExp;
|
||||
|
||||
if (typeof newContentResource === "function") {
|
||||
this.newContentCallback = newContentResource;
|
||||
} else if (
|
||||
typeof newContentResource === "string" &&
|
||||
typeof newContentRecursive === "object"
|
||||
) {
|
||||
this.newContentResource = newContentResource;
|
||||
this.newContentCreateContextMap = (fs, callback) => {
|
||||
callback(null, newContentRecursive);
|
||||
};
|
||||
} else if (
|
||||
typeof newContentResource === "string" &&
|
||||
typeof newContentRecursive === "function"
|
||||
) {
|
||||
this.newContentResource = newContentResource;
|
||||
this.newContentCreateContextMap = newContentRecursive;
|
||||
} else {
|
||||
if (typeof newContentResource !== "string") {
|
||||
newContentRegExp = newContentRecursive;
|
||||
newContentRecursive = newContentResource;
|
||||
newContentResource = undefined;
|
||||
}
|
||||
if (typeof newContentRecursive !== "boolean") {
|
||||
newContentRegExp = newContentRecursive;
|
||||
newContentRecursive = undefined;
|
||||
}
|
||||
this.newContentResource = newContentResource;
|
||||
this.newContentRecursive = newContentRecursive;
|
||||
this.newContentRegExp = newContentRegExp;
|
||||
}
|
||||
}
|
||||
|
||||
apply(compiler) {
|
||||
const resourceRegExp = this.resourceRegExp;
|
||||
const newContentCallback = this.newContentCallback;
|
||||
const newContentResource = this.newContentResource;
|
||||
const newContentRecursive = this.newContentRecursive;
|
||||
const newContentRegExp = this.newContentRegExp;
|
||||
const newContentCreateContextMap = this.newContentCreateContextMap;
|
||||
|
||||
compiler.hooks.contextModuleFactory.tap("ContextReplacementPlugin", cmf => {
|
||||
cmf.hooks.beforeResolve.tap("ContextReplacementPlugin", result => {
|
||||
if (!result) return;
|
||||
if (resourceRegExp.test(result.request)) {
|
||||
if (newContentResource !== undefined) {
|
||||
result.request = newContentResource;
|
||||
}
|
||||
if (newContentRecursive !== undefined) {
|
||||
result.recursive = newContentRecursive;
|
||||
}
|
||||
if (newContentRegExp !== undefined) {
|
||||
result.regExp = newContentRegExp;
|
||||
}
|
||||
if (typeof newContentCallback === "function") {
|
||||
newContentCallback(result);
|
||||
} else {
|
||||
for (const d of result.dependencies) {
|
||||
if (d.critical) d.critical = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
});
|
||||
cmf.hooks.afterResolve.tap("ContextReplacementPlugin", result => {
|
||||
if (!result) return;
|
||||
if (resourceRegExp.test(result.resource)) {
|
||||
if (newContentResource !== undefined) {
|
||||
if (
|
||||
newContentResource.startsWith("/") ||
|
||||
(newContentResource.length > 1 && newContentResource[1] === ":")
|
||||
) {
|
||||
result.resource = newContentResource;
|
||||
} else {
|
||||
result.resource = join(
|
||||
compiler.inputFileSystem,
|
||||
result.resource,
|
||||
newContentResource
|
||||
);
|
||||
}
|
||||
}
|
||||
if (newContentRecursive !== undefined) {
|
||||
result.recursive = newContentRecursive;
|
||||
}
|
||||
if (newContentRegExp !== undefined) {
|
||||
result.regExp = newContentRegExp;
|
||||
}
|
||||
if (typeof newContentCreateContextMap === "function") {
|
||||
result.resolveDependencies =
|
||||
createResolveDependenciesFromContextMap(
|
||||
newContentCreateContextMap
|
||||
);
|
||||
}
|
||||
if (typeof newContentCallback === "function") {
|
||||
const origResource = result.resource;
|
||||
newContentCallback(result);
|
||||
if (
|
||||
result.resource !== origResource &&
|
||||
!result.resource.startsWith("/") &&
|
||||
(result.resource.length <= 1 || result.resource[1] !== ":")
|
||||
) {
|
||||
// When the function changed it to an relative path
|
||||
result.resource = join(
|
||||
compiler.inputFileSystem,
|
||||
origResource,
|
||||
result.resource
|
||||
);
|
||||
}
|
||||
} else {
|
||||
for (const d of result.dependencies) {
|
||||
if (d.critical) d.critical = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const createResolveDependenciesFromContextMap = createContextMap => {
|
||||
const resolveDependenciesFromContextMap = (fs, options, callback) => {
|
||||
createContextMap(fs, (err, map) => {
|
||||
if (err) return callback(err);
|
||||
const dependencies = Object.keys(map).map(key => {
|
||||
return new ContextElementDependency(
|
||||
map[key] + options.resourceQuery + options.resourceFragment,
|
||||
key,
|
||||
options.category,
|
||||
options.referencedExports
|
||||
);
|
||||
});
|
||||
callback(null, dependencies);
|
||||
});
|
||||
};
|
||||
return resolveDependenciesFromContextMap;
|
||||
};
|
||||
|
||||
module.exports = ContextReplacementPlugin;
|
601
node_modules/webpack/lib/DefinePlugin.js
generated
vendored
Normal file
601
node_modules/webpack/lib/DefinePlugin.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
239
node_modules/webpack/lib/DelegatedModule.js
generated
vendored
Normal file
239
node_modules/webpack/lib/DelegatedModule.js
generated
vendored
Normal file
@@ -0,0 +1,239 @@
|
||||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
const { OriginalSource, RawSource } = require("webpack-sources");
|
||||
const Module = require("./Module");
|
||||
const RuntimeGlobals = require("./RuntimeGlobals");
|
||||
const DelegatedSourceDependency = require("./dependencies/DelegatedSourceDependency");
|
||||
const StaticExportsDependency = require("./dependencies/StaticExportsDependency");
|
||||
const makeSerializable = require("./util/makeSerializable");
|
||||
|
||||
/** @typedef {import("webpack-sources").Source} Source */
|
||||
/** @typedef {import("../declarations/WebpackOptions").WebpackOptionsNormalized} WebpackOptions */
|
||||
/** @typedef {import("./ChunkGraph")} ChunkGraph */
|
||||
/** @typedef {import("./Compilation")} Compilation */
|
||||
/** @typedef {import("./Dependency").UpdateHashContext} UpdateHashContext */
|
||||
/** @typedef {import("./DependencyTemplates")} DependencyTemplates */
|
||||
/** @typedef {import("./LibManifestPlugin").ManifestModuleData} ManifestModuleData */
|
||||
/** @typedef {import("./Module").CodeGenerationContext} CodeGenerationContext */
|
||||
/** @typedef {import("./Module").CodeGenerationResult} CodeGenerationResult */
|
||||
/** @typedef {import("./Module").LibIdentOptions} LibIdentOptions */
|
||||
/** @typedef {import("./Module").NeedBuildContext} NeedBuildContext */
|
||||
/** @typedef {import("./Module").SourceContext} SourceContext */
|
||||
/** @typedef {import("./RequestShortener")} RequestShortener */
|
||||
/** @typedef {import("./ResolverFactory").ResolverWithOptions} ResolverWithOptions */
|
||||
/** @typedef {import("./RuntimeTemplate")} RuntimeTemplate */
|
||||
/** @typedef {import("./WebpackError")} WebpackError */
|
||||
/** @typedef {import("./dependencies/ModuleDependency")} ModuleDependency */
|
||||
/** @typedef {import("./util/Hash")} Hash */
|
||||
/** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */
|
||||
|
||||
const TYPES = new Set(["javascript"]);
|
||||
const RUNTIME_REQUIREMENTS = new Set([
|
||||
RuntimeGlobals.module,
|
||||
RuntimeGlobals.require
|
||||
]);
|
||||
|
||||
class DelegatedModule extends Module {
|
||||
constructor(sourceRequest, data, type, userRequest, originalRequest) {
|
||||
super("javascript/dynamic", null);
|
||||
|
||||
// Info from Factory
|
||||
this.sourceRequest = sourceRequest;
|
||||
this.request = data.id;
|
||||
this.delegationType = type;
|
||||
this.userRequest = userRequest;
|
||||
this.originalRequest = originalRequest;
|
||||
/** @type {ManifestModuleData} */
|
||||
this.delegateData = data;
|
||||
|
||||
// Build info
|
||||
this.delegatedSourceDependency = undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {Set<string>} types available (do not mutate)
|
||||
*/
|
||||
getSourceTypes() {
|
||||
return TYPES;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {LibIdentOptions} options options
|
||||
* @returns {string | null} an identifier for library inclusion
|
||||
*/
|
||||
libIdent(options) {
|
||||
return typeof this.originalRequest === "string"
|
||||
? this.originalRequest
|
||||
: this.originalRequest.libIdent(options);
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {string} a unique identifier of the module
|
||||
*/
|
||||
identifier() {
|
||||
return `delegated ${JSON.stringify(this.request)} from ${
|
||||
this.sourceRequest
|
||||
}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {RequestShortener} requestShortener the request shortener
|
||||
* @returns {string} a user readable identifier of the module
|
||||
*/
|
||||
readableIdentifier(requestShortener) {
|
||||
return `delegated ${this.userRequest} from ${this.sourceRequest}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {NeedBuildContext} context context info
|
||||
* @param {function((WebpackError | null)=, boolean=): void} callback callback function, returns true, if the module needs a rebuild
|
||||
* @returns {void}
|
||||
*/
|
||||
needBuild(context, callback) {
|
||||
return callback(null, !this.buildMeta);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {WebpackOptions} options webpack options
|
||||
* @param {Compilation} compilation the compilation
|
||||
* @param {ResolverWithOptions} resolver the resolver
|
||||
* @param {InputFileSystem} fs the file system
|
||||
* @param {function(WebpackError=): void} callback callback function
|
||||
* @returns {void}
|
||||
*/
|
||||
build(options, compilation, resolver, fs, callback) {
|
||||
this.buildMeta = { ...this.delegateData.buildMeta };
|
||||
this.buildInfo = {};
|
||||
this.dependencies.length = 0;
|
||||
this.delegatedSourceDependency = new DelegatedSourceDependency(
|
||||
this.sourceRequest
|
||||
);
|
||||
this.addDependency(this.delegatedSourceDependency);
|
||||
this.addDependency(
|
||||
new StaticExportsDependency(this.delegateData.exports || true, false)
|
||||
);
|
||||
callback();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {CodeGenerationContext} context context for code generation
|
||||
* @returns {CodeGenerationResult} result
|
||||
*/
|
||||
codeGeneration({ runtimeTemplate, moduleGraph, chunkGraph }) {
|
||||
const dep = /** @type {DelegatedSourceDependency} */ (this.dependencies[0]);
|
||||
const sourceModule = moduleGraph.getModule(dep);
|
||||
let str;
|
||||
|
||||
if (!sourceModule) {
|
||||
str = runtimeTemplate.throwMissingModuleErrorBlock({
|
||||
request: this.sourceRequest
|
||||
});
|
||||
} else {
|
||||
str = `module.exports = (${runtimeTemplate.moduleExports({
|
||||
module: sourceModule,
|
||||
chunkGraph,
|
||||
request: dep.request,
|
||||
runtimeRequirements: new Set()
|
||||
})})`;
|
||||
|
||||
switch (this.delegationType) {
|
||||
case "require":
|
||||
str += `(${JSON.stringify(this.request)})`;
|
||||
break;
|
||||
case "object":
|
||||
str += `[${JSON.stringify(this.request)}]`;
|
||||
break;
|
||||
}
|
||||
|
||||
str += ";";
|
||||
}
|
||||
|
||||
const sources = new Map();
|
||||
if (this.useSourceMap || this.useSimpleSourceMap) {
|
||||
sources.set("javascript", new OriginalSource(str, this.identifier()));
|
||||
} else {
|
||||
sources.set("javascript", new RawSource(str));
|
||||
}
|
||||
|
||||
return {
|
||||
sources,
|
||||
runtimeRequirements: RUNTIME_REQUIREMENTS
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string=} type the source type for which the size should be estimated
|
||||
* @returns {number} the estimated size of the module (must be non-zero)
|
||||
*/
|
||||
size(type) {
|
||||
return 42;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Hash} hash the hash used to track dependencies
|
||||
* @param {UpdateHashContext} context context
|
||||
* @returns {void}
|
||||
*/
|
||||
updateHash(hash, context) {
|
||||
hash.update(this.delegationType);
|
||||
hash.update(JSON.stringify(this.request));
|
||||
super.updateHash(hash, context);
|
||||
}
|
||||
|
||||
serialize(context) {
|
||||
const { write } = context;
|
||||
// constructor
|
||||
write(this.sourceRequest);
|
||||
write(this.delegateData);
|
||||
write(this.delegationType);
|
||||
write(this.userRequest);
|
||||
write(this.originalRequest);
|
||||
super.serialize(context);
|
||||
}
|
||||
|
||||
static deserialize(context) {
|
||||
const { read } = context;
|
||||
const obj = new DelegatedModule(
|
||||
read(), // sourceRequest
|
||||
read(), // delegateData
|
||||
read(), // delegationType
|
||||
read(), // userRequest
|
||||
read() // originalRequest
|
||||
);
|
||||
obj.deserialize(context);
|
||||
return obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assuming this module is in the cache. Update the (cached) module with
|
||||
* the fresh module from the factory. Usually updates internal references
|
||||
* and properties.
|
||||
* @param {Module} module fresh module
|
||||
* @returns {void}
|
||||
*/
|
||||
updateCacheModule(module) {
|
||||
super.updateCacheModule(module);
|
||||
const m = /** @type {DelegatedModule} */ (module);
|
||||
this.delegationType = m.delegationType;
|
||||
this.userRequest = m.userRequest;
|
||||
this.originalRequest = m.originalRequest;
|
||||
this.delegateData = m.delegateData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assuming this module is in the cache. Remove internal references to allow freeing some memory.
|
||||
*/
|
||||
cleanupForCache() {
|
||||
super.cleanupForCache();
|
||||
this.delegateData = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
makeSerializable(DelegatedModule, "webpack/lib/DelegatedModule");
|
||||
|
||||
module.exports = DelegatedModule;
|
91
node_modules/webpack/lib/DelegatedModuleFactoryPlugin.js
generated
vendored
Normal file
91
node_modules/webpack/lib/DelegatedModuleFactoryPlugin.js
generated
vendored
Normal file
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
const DelegatedModule = require("./DelegatedModule");
|
||||
|
||||
// options.source
|
||||
// options.type
|
||||
// options.context
|
||||
// options.scope
|
||||
// options.content
|
||||
// options.associatedObjectForCache
|
||||
class DelegatedModuleFactoryPlugin {
|
||||
constructor(options) {
|
||||
this.options = options;
|
||||
options.type = options.type || "require";
|
||||
options.extensions = options.extensions || ["", ".js", ".json", ".wasm"];
|
||||
}
|
||||
|
||||
apply(normalModuleFactory) {
|
||||
const scope = this.options.scope;
|
||||
if (scope) {
|
||||
normalModuleFactory.hooks.factorize.tapAsync(
|
||||
"DelegatedModuleFactoryPlugin",
|
||||
(data, callback) => {
|
||||
const [dependency] = data.dependencies;
|
||||
const { request } = dependency;
|
||||
if (request && request.startsWith(`${scope}/`)) {
|
||||
const innerRequest = "." + request.slice(scope.length);
|
||||
let resolved;
|
||||
if (innerRequest in this.options.content) {
|
||||
resolved = this.options.content[innerRequest];
|
||||
return callback(
|
||||
null,
|
||||
new DelegatedModule(
|
||||
this.options.source,
|
||||
resolved,
|
||||
this.options.type,
|
||||
innerRequest,
|
||||
request
|
||||
)
|
||||
);
|
||||
}
|
||||
for (let i = 0; i < this.options.extensions.length; i++) {
|
||||
const extension = this.options.extensions[i];
|
||||
const requestPlusExt = innerRequest + extension;
|
||||
if (requestPlusExt in this.options.content) {
|
||||
resolved = this.options.content[requestPlusExt];
|
||||
return callback(
|
||||
null,
|
||||
new DelegatedModule(
|
||||
this.options.source,
|
||||
resolved,
|
||||
this.options.type,
|
||||
requestPlusExt,
|
||||
request + extension
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
return callback();
|
||||
}
|
||||
);
|
||||
} else {
|
||||
normalModuleFactory.hooks.module.tap(
|
||||
"DelegatedModuleFactoryPlugin",
|
||||
module => {
|
||||
const request = module.libIdent(this.options);
|
||||
if (request) {
|
||||
if (request in this.options.content) {
|
||||
const resolved = this.options.content[request];
|
||||
return new DelegatedModule(
|
||||
this.options.source,
|
||||
resolved,
|
||||
this.options.type,
|
||||
request,
|
||||
module
|
||||
);
|
||||
}
|
||||
}
|
||||
return module;
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
module.exports = DelegatedModuleFactoryPlugin;
|
43
node_modules/webpack/lib/DelegatedPlugin.js
generated
vendored
Normal file
43
node_modules/webpack/lib/DelegatedPlugin.js
generated
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
const DelegatedModuleFactoryPlugin = require("./DelegatedModuleFactoryPlugin");
|
||||
const DelegatedSourceDependency = require("./dependencies/DelegatedSourceDependency");
|
||||
|
||||
/** @typedef {import("./Compiler")} Compiler */
|
||||
|
||||
class DelegatedPlugin {
|
||||
constructor(options) {
|
||||
this.options = options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply the plugin
|
||||
* @param {Compiler} compiler the compiler instance
|
||||
* @returns {void}
|
||||
*/
|
||||
apply(compiler) {
|
||||
compiler.hooks.compilation.tap(
|
||||
"DelegatedPlugin",
|
||||
(compilation, { normalModuleFactory }) => {
|
||||
compilation.dependencyFactories.set(
|
||||
DelegatedSourceDependency,
|
||||
normalModuleFactory
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
compiler.hooks.compile.tap("DelegatedPlugin", ({ normalModuleFactory }) => {
|
||||
new DelegatedModuleFactoryPlugin({
|
||||
associatedObjectForCache: compiler.root,
|
||||
...this.options
|
||||
}).apply(normalModuleFactory);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = DelegatedPlugin;
|
107
node_modules/webpack/lib/DependenciesBlock.js
generated
vendored
Normal file
107
node_modules/webpack/lib/DependenciesBlock.js
generated
vendored
Normal file
@@ -0,0 +1,107 @@
|
||||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
const makeSerializable = require("./util/makeSerializable");
|
||||
|
||||
/** @typedef {import("./AsyncDependenciesBlock")} AsyncDependenciesBlock */
|
||||
/** @typedef {import("./ChunkGraph")} ChunkGraph */
|
||||
/** @typedef {import("./ChunkGroup")} ChunkGroup */
|
||||
/** @typedef {import("./Dependency")} Dependency */
|
||||
/** @typedef {import("./Dependency").UpdateHashContext} UpdateHashContext */
|
||||
/** @typedef {import("./util/Hash")} Hash */
|
||||
|
||||
/** @typedef {(d: Dependency) => boolean} DependencyFilterFunction */
|
||||
|
||||
class DependenciesBlock {
|
||||
constructor() {
|
||||
/** @type {Dependency[]} */
|
||||
this.dependencies = [];
|
||||
/** @type {AsyncDependenciesBlock[]} */
|
||||
this.blocks = [];
|
||||
/** @type {DependenciesBlock} */
|
||||
this.parent = undefined;
|
||||
}
|
||||
|
||||
getRootBlock() {
|
||||
/** @type {DependenciesBlock} */
|
||||
let current = this;
|
||||
while (current.parent) current = current.parent;
|
||||
return current;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a DependencyBlock to DependencyBlock relationship.
|
||||
* This is used for when a Module has a AsyncDependencyBlock tie (for code-splitting)
|
||||
*
|
||||
* @param {AsyncDependenciesBlock} block block being added
|
||||
* @returns {void}
|
||||
*/
|
||||
addBlock(block) {
|
||||
this.blocks.push(block);
|
||||
block.parent = this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Dependency} dependency dependency being tied to block.
|
||||
* This is an "edge" pointing to another "node" on module graph.
|
||||
* @returns {void}
|
||||
*/
|
||||
addDependency(dependency) {
|
||||
this.dependencies.push(dependency);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Dependency} dependency dependency being removed
|
||||
* @returns {void}
|
||||
*/
|
||||
removeDependency(dependency) {
|
||||
const idx = this.dependencies.indexOf(dependency);
|
||||
if (idx >= 0) {
|
||||
this.dependencies.splice(idx, 1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes all dependencies and blocks
|
||||
* @returns {void}
|
||||
*/
|
||||
clearDependenciesAndBlocks() {
|
||||
this.dependencies.length = 0;
|
||||
this.blocks.length = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Hash} hash the hash used to track dependencies
|
||||
* @param {UpdateHashContext} context context
|
||||
* @returns {void}
|
||||
*/
|
||||
updateHash(hash, context) {
|
||||
for (const dep of this.dependencies) {
|
||||
dep.updateHash(hash, context);
|
||||
}
|
||||
for (const block of this.blocks) {
|
||||
block.updateHash(hash, context);
|
||||
}
|
||||
}
|
||||
|
||||
serialize({ write }) {
|
||||
write(this.dependencies);
|
||||
write(this.blocks);
|
||||
}
|
||||
|
||||
deserialize({ read }) {
|
||||
this.dependencies = read();
|
||||
this.blocks = read();
|
||||
for (const block of this.blocks) {
|
||||
block.parent = this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
makeSerializable(DependenciesBlock, "webpack/lib/DependenciesBlock");
|
||||
|
||||
module.exports = DependenciesBlock;
|
355
node_modules/webpack/lib/Dependency.js
generated
vendored
Normal file
355
node_modules/webpack/lib/Dependency.js
generated
vendored
Normal file
@@ -0,0 +1,355 @@
|
||||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
const memoize = require("./util/memoize");
|
||||
|
||||
/** @typedef {import("webpack-sources").Source} Source */
|
||||
/** @typedef {import("./ChunkGraph")} ChunkGraph */
|
||||
/** @typedef {import("./DependenciesBlock")} DependenciesBlock */
|
||||
/** @typedef {import("./DependencyTemplates")} DependencyTemplates */
|
||||
/** @typedef {import("./Module")} Module */
|
||||
/** @typedef {import("./ModuleGraph")} ModuleGraph */
|
||||
/** @typedef {import("./ModuleGraphConnection")} ModuleGraphConnection */
|
||||
/** @typedef {import("./ModuleGraphConnection").ConnectionState} ConnectionState */
|
||||
/** @typedef {import("./RuntimeTemplate")} RuntimeTemplate */
|
||||
/** @typedef {import("./WebpackError")} WebpackError */
|
||||
/** @typedef {import("./util/Hash")} Hash */
|
||||
/** @typedef {import("./util/runtime").RuntimeSpec} RuntimeSpec */
|
||||
|
||||
/**
|
||||
* @typedef {Object} UpdateHashContext
|
||||
* @property {ChunkGraph} chunkGraph
|
||||
* @property {RuntimeSpec} runtime
|
||||
* @property {RuntimeTemplate=} runtimeTemplate
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object} SourcePosition
|
||||
* @property {number} line
|
||||
* @property {number=} column
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object} RealDependencyLocation
|
||||
* @property {SourcePosition} start
|
||||
* @property {SourcePosition=} end
|
||||
* @property {number=} index
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object} SyntheticDependencyLocation
|
||||
* @property {string} name
|
||||
* @property {number=} index
|
||||
*/
|
||||
|
||||
/** @typedef {SyntheticDependencyLocation|RealDependencyLocation} DependencyLocation */
|
||||
|
||||
/**
|
||||
* @typedef {Object} ExportSpec
|
||||
* @property {string} name the name of the export
|
||||
* @property {boolean=} canMangle can the export be renamed (defaults to true)
|
||||
* @property {boolean=} terminalBinding is the export a terminal binding that should be checked for export star conflicts
|
||||
* @property {(string | ExportSpec)[]=} exports nested exports
|
||||
* @property {ModuleGraphConnection=} from when reexported: from which module
|
||||
* @property {string[] | null=} export when reexported: from which export
|
||||
* @property {number=} priority when reexported: with which priority
|
||||
* @property {boolean=} hidden export is not visible, because another export blends over it
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object} ExportsSpec
|
||||
* @property {(string | ExportSpec)[] | true | null} exports exported names, true for unknown exports or null for no exports
|
||||
* @property {Set<string>=} excludeExports when exports = true, list of unaffected exports
|
||||
* @property {Set<string>=} hideExports list of maybe prior exposed, but now hidden exports
|
||||
* @property {ModuleGraphConnection=} from when reexported: from which module
|
||||
* @property {number=} priority when reexported: with which priority
|
||||
* @property {boolean=} canMangle can the export be renamed (defaults to true)
|
||||
* @property {boolean=} terminalBinding are the exports terminal bindings that should be checked for export star conflicts
|
||||
* @property {Module[]=} dependencies module on which the result depends on
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object} ReferencedExport
|
||||
* @property {string[]} name name of the referenced export
|
||||
* @property {boolean=} canMangle when false, referenced export can not be mangled, defaults to true
|
||||
*/
|
||||
|
||||
const TRANSITIVE = Symbol("transitive");
|
||||
|
||||
const getIgnoredModule = memoize(() => {
|
||||
const RawModule = require("./RawModule");
|
||||
return new RawModule("/* (ignored) */", `ignored`, `(ignored)`);
|
||||
});
|
||||
|
||||
class Dependency {
|
||||
constructor() {
|
||||
/** @type {Module} */
|
||||
this._parentModule = undefined;
|
||||
/** @type {DependenciesBlock} */
|
||||
this._parentDependenciesBlock = undefined;
|
||||
/** @type {number} */
|
||||
this._parentDependenciesBlockIndex = -1;
|
||||
// TODO check if this can be moved into ModuleDependency
|
||||
/** @type {boolean} */
|
||||
this.weak = false;
|
||||
// TODO check if this can be moved into ModuleDependency
|
||||
/** @type {boolean} */
|
||||
this.optional = false;
|
||||
this._locSL = 0;
|
||||
this._locSC = 0;
|
||||
this._locEL = 0;
|
||||
this._locEC = 0;
|
||||
this._locI = undefined;
|
||||
this._locN = undefined;
|
||||
this._loc = undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {string} a display name for the type of dependency
|
||||
*/
|
||||
get type() {
|
||||
return "unknown";
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {string} a dependency category, typical categories are "commonjs", "amd", "esm"
|
||||
*/
|
||||
get category() {
|
||||
return "unknown";
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {DependencyLocation} location
|
||||
*/
|
||||
get loc() {
|
||||
if (this._loc !== undefined) return this._loc;
|
||||
/** @type {SyntheticDependencyLocation & RealDependencyLocation} */
|
||||
const loc = {};
|
||||
if (this._locSL > 0) {
|
||||
loc.start = { line: this._locSL, column: this._locSC };
|
||||
}
|
||||
if (this._locEL > 0) {
|
||||
loc.end = { line: this._locEL, column: this._locEC };
|
||||
}
|
||||
if (this._locN !== undefined) {
|
||||
loc.name = this._locN;
|
||||
}
|
||||
if (this._locI !== undefined) {
|
||||
loc.index = this._locI;
|
||||
}
|
||||
return (this._loc = loc);
|
||||
}
|
||||
|
||||
set loc(loc) {
|
||||
if ("start" in loc && typeof loc.start === "object") {
|
||||
this._locSL = loc.start.line || 0;
|
||||
this._locSC = loc.start.column || 0;
|
||||
} else {
|
||||
this._locSL = 0;
|
||||
this._locSC = 0;
|
||||
}
|
||||
if ("end" in loc && typeof loc.end === "object") {
|
||||
this._locEL = loc.end.line || 0;
|
||||
this._locEC = loc.end.column || 0;
|
||||
} else {
|
||||
this._locEL = 0;
|
||||
this._locEC = 0;
|
||||
}
|
||||
if ("index" in loc) {
|
||||
this._locI = loc.index;
|
||||
} else {
|
||||
this._locI = undefined;
|
||||
}
|
||||
if ("name" in loc) {
|
||||
this._locN = loc.name;
|
||||
} else {
|
||||
this._locN = undefined;
|
||||
}
|
||||
this._loc = loc;
|
||||
}
|
||||
|
||||
setLoc(startLine, startColumn, endLine, endColumn) {
|
||||
this._locSL = startLine;
|
||||
this._locSC = startColumn;
|
||||
this._locEL = endLine;
|
||||
this._locEC = endColumn;
|
||||
this._locI = undefined;
|
||||
this._locN = undefined;
|
||||
this._loc = undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {string | undefined} a request context
|
||||
*/
|
||||
getContext() {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {string | null} an identifier to merge equal requests
|
||||
*/
|
||||
getResourceIdentifier() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {boolean | TRANSITIVE} true, when changes to the referenced module could affect the referencing module; TRANSITIVE, when changes to the referenced module could affect referencing modules of the referencing module
|
||||
*/
|
||||
couldAffectReferencingModule() {
|
||||
return TRANSITIVE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the referenced module and export
|
||||
* @deprecated
|
||||
* @param {ModuleGraph} moduleGraph module graph
|
||||
* @returns {never} throws error
|
||||
*/
|
||||
getReference(moduleGraph) {
|
||||
throw new Error(
|
||||
"Dependency.getReference was removed in favor of Dependency.getReferencedExports, ModuleGraph.getModule and ModuleGraph.getConnection().active"
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns list of exports referenced by this dependency
|
||||
* @param {ModuleGraph} moduleGraph module graph
|
||||
* @param {RuntimeSpec} runtime the runtime for which the module is analysed
|
||||
* @returns {(string[] | ReferencedExport)[]} referenced exports
|
||||
*/
|
||||
getReferencedExports(moduleGraph, runtime) {
|
||||
return Dependency.EXPORTS_OBJECT_REFERENCED;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {ModuleGraph} moduleGraph module graph
|
||||
* @returns {null | false | function(ModuleGraphConnection, RuntimeSpec): ConnectionState} function to determine if the connection is active
|
||||
*/
|
||||
getCondition(moduleGraph) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the exported names
|
||||
* @param {ModuleGraph} moduleGraph module graph
|
||||
* @returns {ExportsSpec | undefined} export names
|
||||
*/
|
||||
getExports(moduleGraph) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns warnings
|
||||
* @param {ModuleGraph} moduleGraph module graph
|
||||
* @returns {WebpackError[]} warnings
|
||||
*/
|
||||
getWarnings(moduleGraph) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns errors
|
||||
* @param {ModuleGraph} moduleGraph module graph
|
||||
* @returns {WebpackError[]} errors
|
||||
*/
|
||||
getErrors(moduleGraph) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the hash
|
||||
* @param {Hash} hash hash to be updated
|
||||
* @param {UpdateHashContext} context context
|
||||
* @returns {void}
|
||||
*/
|
||||
updateHash(hash, context) {}
|
||||
|
||||
/**
|
||||
* implement this method to allow the occurrence order plugin to count correctly
|
||||
* @returns {number} count how often the id is used in this dependency
|
||||
*/
|
||||
getNumberOfIdOccurrences() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {ModuleGraph} moduleGraph the module graph
|
||||
* @returns {ConnectionState} how this dependency connects the module to referencing modules
|
||||
*/
|
||||
getModuleEvaluationSideEffectsState(moduleGraph) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} context context directory
|
||||
* @returns {Module} a module
|
||||
*/
|
||||
createIgnoredModule(context) {
|
||||
return getIgnoredModule();
|
||||
}
|
||||
|
||||
serialize({ write }) {
|
||||
write(this.weak);
|
||||
write(this.optional);
|
||||
write(this._locSL);
|
||||
write(this._locSC);
|
||||
write(this._locEL);
|
||||
write(this._locEC);
|
||||
write(this._locI);
|
||||
write(this._locN);
|
||||
}
|
||||
|
||||
deserialize({ read }) {
|
||||
this.weak = read();
|
||||
this.optional = read();
|
||||
this._locSL = read();
|
||||
this._locSC = read();
|
||||
this._locEL = read();
|
||||
this._locEC = read();
|
||||
this._locI = read();
|
||||
this._locN = read();
|
||||
}
|
||||
}
|
||||
|
||||
/** @type {string[][]} */
|
||||
Dependency.NO_EXPORTS_REFERENCED = [];
|
||||
/** @type {string[][]} */
|
||||
Dependency.EXPORTS_OBJECT_REFERENCED = [[]];
|
||||
|
||||
Object.defineProperty(Dependency.prototype, "module", {
|
||||
/**
|
||||
* @deprecated
|
||||
* @returns {never} throws
|
||||
*/
|
||||
get() {
|
||||
throw new Error(
|
||||
"module property was removed from Dependency (use compilation.moduleGraph.getModule(dependency) instead)"
|
||||
);
|
||||
},
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
* @returns {never} throws
|
||||
*/
|
||||
set() {
|
||||
throw new Error(
|
||||
"module property was removed from Dependency (use compilation.moduleGraph.updateModule(dependency, module) instead)"
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
Object.defineProperty(Dependency.prototype, "disconnect", {
|
||||
get() {
|
||||
throw new Error(
|
||||
"disconnect was removed from Dependency (Dependency no longer carries graph specific information)"
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
Dependency.TRANSITIVE = TRANSITIVE;
|
||||
|
||||
module.exports = Dependency;
|
57
node_modules/webpack/lib/DependencyTemplate.js
generated
vendored
Normal file
57
node_modules/webpack/lib/DependencyTemplate.js
generated
vendored
Normal file
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
/** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
|
||||
/** @typedef {import("./ChunkGraph")} ChunkGraph */
|
||||
/** @typedef {import("./CodeGenerationResults")} CodeGenerationResults */
|
||||
/** @typedef {import("./ConcatenationScope")} ConcatenationScope */
|
||||
/** @typedef {import("./Dependency")} Dependency */
|
||||
/** @typedef {import("./Dependency").RuntimeSpec} RuntimeSpec */
|
||||
/** @typedef {import("./DependencyTemplates")} DependencyTemplates */
|
||||
/** @typedef {import("./Generator").GenerateContext} GenerateContext */
|
||||
/** @template T @typedef {import("./InitFragment")<T>} InitFragment */
|
||||
/** @typedef {import("./Module")} Module */
|
||||
/** @typedef {import("./ModuleGraph")} ModuleGraph */
|
||||
/** @typedef {import("./RuntimeTemplate")} RuntimeTemplate */
|
||||
|
||||
/**
|
||||
* @typedef {Object} DependencyTemplateContext
|
||||
* @property {RuntimeTemplate} runtimeTemplate the runtime template
|
||||
* @property {DependencyTemplates} dependencyTemplates the dependency templates
|
||||
* @property {ModuleGraph} moduleGraph the module graph
|
||||
* @property {ChunkGraph} chunkGraph the chunk graph
|
||||
* @property {Set<string>} runtimeRequirements the requirements for runtime
|
||||
* @property {Module} module current module
|
||||
* @property {RuntimeSpec} runtime current runtimes, for which code is generated
|
||||
* @property {InitFragment<GenerateContext>[]} initFragments mutable array of init fragments for the current module
|
||||
* @property {ConcatenationScope=} concatenationScope when in a concatenated module, information about other concatenated modules
|
||||
* @property {CodeGenerationResults} codeGenerationResults the code generation results
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object} CssDependencyTemplateContextExtras
|
||||
* @property {Map<string, string>} cssExports the css exports
|
||||
*/
|
||||
|
||||
/** @typedef {DependencyTemplateContext & CssDependencyTemplateContextExtras} CssDependencyTemplateContext */
|
||||
|
||||
class DependencyTemplate {
|
||||
/* istanbul ignore next */
|
||||
/**
|
||||
* @abstract
|
||||
* @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, templateContext) {
|
||||
const AbstractMethodError = require("./AbstractMethodError");
|
||||
throw new AbstractMethodError();
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = DependencyTemplate;
|
67
node_modules/webpack/lib/DependencyTemplates.js
generated
vendored
Normal file
67
node_modules/webpack/lib/DependencyTemplates.js
generated
vendored
Normal file
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
const createHash = require("./util/createHash");
|
||||
|
||||
/** @typedef {import("./Dependency")} Dependency */
|
||||
/** @typedef {import("./DependencyTemplate")} DependencyTemplate */
|
||||
/** @typedef {typeof import("./util/Hash")} Hash */
|
||||
|
||||
/** @typedef {new (...args: any[]) => Dependency} DependencyConstructor */
|
||||
|
||||
class DependencyTemplates {
|
||||
/**
|
||||
* @param {string | Hash} hashFunction the hash function to use
|
||||
*/
|
||||
constructor(hashFunction = "md4") {
|
||||
/** @type {Map<Function, DependencyTemplate>} */
|
||||
this._map = new Map();
|
||||
/** @type {string} */
|
||||
this._hash = "31d6cfe0d16ae931b73c59d7e0c089c0";
|
||||
this._hashFunction = hashFunction;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {DependencyConstructor} dependency Constructor of Dependency
|
||||
* @returns {DependencyTemplate} template for this dependency
|
||||
*/
|
||||
get(dependency) {
|
||||
return this._map.get(dependency);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {DependencyConstructor} dependency Constructor of Dependency
|
||||
* @param {DependencyTemplate} dependencyTemplate template for this dependency
|
||||
* @returns {void}
|
||||
*/
|
||||
set(dependency, dependencyTemplate) {
|
||||
this._map.set(dependency, dependencyTemplate);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} part additional hash contributor
|
||||
* @returns {void}
|
||||
*/
|
||||
updateHash(part) {
|
||||
const hash = createHash(this._hashFunction);
|
||||
hash.update(`${this._hash}${part}`);
|
||||
this._hash = /** @type {string} */ (hash.digest("hex"));
|
||||
}
|
||||
|
||||
getHash() {
|
||||
return this._hash;
|
||||
}
|
||||
|
||||
clone() {
|
||||
const newInstance = new DependencyTemplates(this._hashFunction);
|
||||
newInstance._map = new Map(this._map);
|
||||
newInstance._hash = this._hash;
|
||||
return newInstance;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = DependencyTemplates;
|
55
node_modules/webpack/lib/DllEntryPlugin.js
generated
vendored
Normal file
55
node_modules/webpack/lib/DllEntryPlugin.js
generated
vendored
Normal file
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
const DllModuleFactory = require("./DllModuleFactory");
|
||||
const DllEntryDependency = require("./dependencies/DllEntryDependency");
|
||||
const EntryDependency = require("./dependencies/EntryDependency");
|
||||
|
||||
class DllEntryPlugin {
|
||||
constructor(context, entries, options) {
|
||||
this.context = context;
|
||||
this.entries = entries;
|
||||
this.options = options;
|
||||
}
|
||||
|
||||
apply(compiler) {
|
||||
compiler.hooks.compilation.tap(
|
||||
"DllEntryPlugin",
|
||||
(compilation, { normalModuleFactory }) => {
|
||||
const dllModuleFactory = new DllModuleFactory();
|
||||
compilation.dependencyFactories.set(
|
||||
DllEntryDependency,
|
||||
dllModuleFactory
|
||||
);
|
||||
compilation.dependencyFactories.set(
|
||||
EntryDependency,
|
||||
normalModuleFactory
|
||||
);
|
||||
}
|
||||
);
|
||||
compiler.hooks.make.tapAsync("DllEntryPlugin", (compilation, callback) => {
|
||||
compilation.addEntry(
|
||||
this.context,
|
||||
new DllEntryDependency(
|
||||
this.entries.map((e, idx) => {
|
||||
const dep = new EntryDependency(e);
|
||||
dep.loc = {
|
||||
name: this.options.name,
|
||||
index: idx
|
||||
};
|
||||
return dep;
|
||||
}),
|
||||
this.options.name
|
||||
),
|
||||
this.options,
|
||||
callback
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = DllEntryPlugin;
|
157
node_modules/webpack/lib/DllModule.js
generated
vendored
Normal file
157
node_modules/webpack/lib/DllModule.js
generated
vendored
Normal file
@@ -0,0 +1,157 @@
|
||||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
const { RawSource } = require("webpack-sources");
|
||||
const Module = require("./Module");
|
||||
const RuntimeGlobals = require("./RuntimeGlobals");
|
||||
const makeSerializable = require("./util/makeSerializable");
|
||||
|
||||
/** @typedef {import("webpack-sources").Source} Source */
|
||||
/** @typedef {import("../declarations/WebpackOptions").WebpackOptionsNormalized} WebpackOptions */
|
||||
/** @typedef {import("./ChunkGraph")} ChunkGraph */
|
||||
/** @typedef {import("./Compilation")} Compilation */
|
||||
/** @typedef {import("./Dependency").UpdateHashContext} UpdateHashContext */
|
||||
/** @typedef {import("./DependencyTemplates")} DependencyTemplates */
|
||||
/** @typedef {import("./Module").CodeGenerationContext} CodeGenerationContext */
|
||||
/** @typedef {import("./Module").CodeGenerationResult} CodeGenerationResult */
|
||||
/** @typedef {import("./Module").NeedBuildContext} NeedBuildContext */
|
||||
/** @typedef {import("./Module").SourceContext} SourceContext */
|
||||
/** @typedef {import("./RequestShortener")} RequestShortener */
|
||||
/** @typedef {import("./ResolverFactory").ResolverWithOptions} ResolverWithOptions */
|
||||
/** @typedef {import("./RuntimeTemplate")} RuntimeTemplate */
|
||||
/** @typedef {import("./WebpackError")} WebpackError */
|
||||
/** @typedef {import("./util/Hash")} Hash */
|
||||
/** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */
|
||||
|
||||
const TYPES = new Set(["javascript"]);
|
||||
const RUNTIME_REQUIREMENTS = new Set([
|
||||
RuntimeGlobals.require,
|
||||
RuntimeGlobals.module
|
||||
]);
|
||||
|
||||
class DllModule extends Module {
|
||||
constructor(context, dependencies, name) {
|
||||
super("javascript/dynamic", context);
|
||||
|
||||
// Info from Factory
|
||||
this.dependencies = dependencies;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {Set<string>} types available (do not mutate)
|
||||
*/
|
||||
getSourceTypes() {
|
||||
return TYPES;
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {string} a unique identifier of the module
|
||||
*/
|
||||
identifier() {
|
||||
return `dll ${this.name}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {RequestShortener} requestShortener the request shortener
|
||||
* @returns {string} a user readable identifier of the module
|
||||
*/
|
||||
readableIdentifier(requestShortener) {
|
||||
return `dll ${this.name}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {WebpackOptions} options webpack options
|
||||
* @param {Compilation} compilation the compilation
|
||||
* @param {ResolverWithOptions} resolver the resolver
|
||||
* @param {InputFileSystem} fs the file system
|
||||
* @param {function(WebpackError=): void} callback callback function
|
||||
* @returns {void}
|
||||
*/
|
||||
build(options, compilation, resolver, fs, callback) {
|
||||
this.buildMeta = {};
|
||||
this.buildInfo = {};
|
||||
return callback();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {CodeGenerationContext} context context for code generation
|
||||
* @returns {CodeGenerationResult} result
|
||||
*/
|
||||
codeGeneration(context) {
|
||||
const sources = new Map();
|
||||
sources.set(
|
||||
"javascript",
|
||||
new RawSource("module.exports = __webpack_require__;")
|
||||
);
|
||||
return {
|
||||
sources,
|
||||
runtimeRequirements: RUNTIME_REQUIREMENTS
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {NeedBuildContext} context context info
|
||||
* @param {function((WebpackError | null)=, boolean=): void} callback callback function, returns true, if the module needs a rebuild
|
||||
* @returns {void}
|
||||
*/
|
||||
needBuild(context, callback) {
|
||||
return callback(null, !this.buildMeta);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string=} type the source type for which the size should be estimated
|
||||
* @returns {number} the estimated size of the module (must be non-zero)
|
||||
*/
|
||||
size(type) {
|
||||
return 12;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Hash} hash the hash used to track dependencies
|
||||
* @param {UpdateHashContext} context context
|
||||
* @returns {void}
|
||||
*/
|
||||
updateHash(hash, context) {
|
||||
hash.update(`dll module${this.name || ""}`);
|
||||
super.updateHash(hash, context);
|
||||
}
|
||||
|
||||
serialize(context) {
|
||||
context.write(this.name);
|
||||
super.serialize(context);
|
||||
}
|
||||
|
||||
deserialize(context) {
|
||||
this.name = context.read();
|
||||
super.deserialize(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assuming this module is in the cache. Update the (cached) module with
|
||||
* the fresh module from the factory. Usually updates internal references
|
||||
* and properties.
|
||||
* @param {Module} module fresh module
|
||||
* @returns {void}
|
||||
*/
|
||||
updateCacheModule(module) {
|
||||
super.updateCacheModule(module);
|
||||
this.dependencies = module.dependencies;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assuming this module is in the cache. Remove internal references to allow freeing some memory.
|
||||
*/
|
||||
cleanupForCache() {
|
||||
super.cleanupForCache();
|
||||
this.dependencies = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
makeSerializable(DllModule, "webpack/lib/DllModule");
|
||||
|
||||
module.exports = DllModule;
|
37
node_modules/webpack/lib/DllModuleFactory.js
generated
vendored
Normal file
37
node_modules/webpack/lib/DllModuleFactory.js
generated
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
const DllModule = require("./DllModule");
|
||||
const ModuleFactory = require("./ModuleFactory");
|
||||
|
||||
/** @typedef {import("./ModuleFactory").ModuleFactoryCreateData} ModuleFactoryCreateData */
|
||||
/** @typedef {import("./ModuleFactory").ModuleFactoryResult} ModuleFactoryResult */
|
||||
/** @typedef {import("./dependencies/DllEntryDependency")} DllEntryDependency */
|
||||
|
||||
class DllModuleFactory extends ModuleFactory {
|
||||
constructor() {
|
||||
super();
|
||||
this.hooks = Object.freeze({});
|
||||
}
|
||||
/**
|
||||
* @param {ModuleFactoryCreateData} data data object
|
||||
* @param {function(Error=, ModuleFactoryResult=): void} callback callback
|
||||
* @returns {void}
|
||||
*/
|
||||
create(data, callback) {
|
||||
const dependency = /** @type {DllEntryDependency} */ (data.dependencies[0]);
|
||||
callback(null, {
|
||||
module: new DllModule(
|
||||
data.context,
|
||||
dependency.dependencies,
|
||||
dependency.name
|
||||
)
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = DllModuleFactory;
|
68
node_modules/webpack/lib/DllPlugin.js
generated
vendored
Normal file
68
node_modules/webpack/lib/DllPlugin.js
generated
vendored
Normal file
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
const DllEntryPlugin = require("./DllEntryPlugin");
|
||||
const FlagAllModulesAsUsedPlugin = require("./FlagAllModulesAsUsedPlugin");
|
||||
const LibManifestPlugin = require("./LibManifestPlugin");
|
||||
const createSchemaValidation = require("./util/create-schema-validation");
|
||||
|
||||
/** @typedef {import("../declarations/plugins/DllPlugin").DllPluginOptions} DllPluginOptions */
|
||||
/** @typedef {import("./Compiler")} Compiler */
|
||||
|
||||
const validate = createSchemaValidation(
|
||||
require("../schemas/plugins/DllPlugin.check.js"),
|
||||
() => require("../schemas/plugins/DllPlugin.json"),
|
||||
{
|
||||
name: "Dll Plugin",
|
||||
baseDataPath: "options"
|
||||
}
|
||||
);
|
||||
|
||||
class DllPlugin {
|
||||
/**
|
||||
* @param {DllPluginOptions} options options object
|
||||
*/
|
||||
constructor(options) {
|
||||
validate(options);
|
||||
this.options = {
|
||||
...options,
|
||||
entryOnly: options.entryOnly !== false
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply the plugin
|
||||
* @param {Compiler} compiler the compiler instance
|
||||
* @returns {void}
|
||||
*/
|
||||
apply(compiler) {
|
||||
compiler.hooks.entryOption.tap("DllPlugin", (context, entry) => {
|
||||
if (typeof entry !== "function") {
|
||||
for (const name of Object.keys(entry)) {
|
||||
const options = {
|
||||
name,
|
||||
filename: entry.filename
|
||||
};
|
||||
new DllEntryPlugin(context, entry[name].import, options).apply(
|
||||
compiler
|
||||
);
|
||||
}
|
||||
} else {
|
||||
throw new Error(
|
||||
"DllPlugin doesn't support dynamic entry (function) yet"
|
||||
);
|
||||
}
|
||||
return true;
|
||||
});
|
||||
new LibManifestPlugin(this.options).apply(compiler);
|
||||
if (!this.options.entryOnly) {
|
||||
new FlagAllModulesAsUsedPlugin("DllPlugin").apply(compiler);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = DllPlugin;
|
162
node_modules/webpack/lib/DllReferencePlugin.js
generated
vendored
Normal file
162
node_modules/webpack/lib/DllReferencePlugin.js
generated
vendored
Normal file
@@ -0,0 +1,162 @@
|
||||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
const parseJson = require("json-parse-even-better-errors");
|
||||
const DelegatedModuleFactoryPlugin = require("./DelegatedModuleFactoryPlugin");
|
||||
const ExternalModuleFactoryPlugin = require("./ExternalModuleFactoryPlugin");
|
||||
const WebpackError = require("./WebpackError");
|
||||
const DelegatedSourceDependency = require("./dependencies/DelegatedSourceDependency");
|
||||
const createSchemaValidation = require("./util/create-schema-validation");
|
||||
const makePathsRelative = require("./util/identifier").makePathsRelative;
|
||||
|
||||
/** @typedef {import("../declarations/WebpackOptions").Externals} Externals */
|
||||
/** @typedef {import("../declarations/plugins/DllReferencePlugin").DllReferencePluginOptions} DllReferencePluginOptions */
|
||||
/** @typedef {import("../declarations/plugins/DllReferencePlugin").DllReferencePluginOptionsManifest} DllReferencePluginOptionsManifest */
|
||||
|
||||
const validate = createSchemaValidation(
|
||||
require("../schemas/plugins/DllReferencePlugin.check.js"),
|
||||
() => require("../schemas/plugins/DllReferencePlugin.json"),
|
||||
{
|
||||
name: "Dll Reference Plugin",
|
||||
baseDataPath: "options"
|
||||
}
|
||||
);
|
||||
|
||||
class DllReferencePlugin {
|
||||
/**
|
||||
* @param {DllReferencePluginOptions} options options object
|
||||
*/
|
||||
constructor(options) {
|
||||
validate(options);
|
||||
this.options = options;
|
||||
/** @type {WeakMap<Object, {path: string, data: DllReferencePluginOptionsManifest?, error: Error?}>} */
|
||||
this._compilationData = new WeakMap();
|
||||
}
|
||||
|
||||
apply(compiler) {
|
||||
compiler.hooks.compilation.tap(
|
||||
"DllReferencePlugin",
|
||||
(compilation, { normalModuleFactory }) => {
|
||||
compilation.dependencyFactories.set(
|
||||
DelegatedSourceDependency,
|
||||
normalModuleFactory
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
compiler.hooks.beforeCompile.tapAsync(
|
||||
"DllReferencePlugin",
|
||||
(params, callback) => {
|
||||
if ("manifest" in this.options) {
|
||||
const manifest = this.options.manifest;
|
||||
if (typeof manifest === "string") {
|
||||
compiler.inputFileSystem.readFile(manifest, (err, result) => {
|
||||
if (err) return callback(err);
|
||||
const data = {
|
||||
path: manifest,
|
||||
data: undefined,
|
||||
error: undefined
|
||||
};
|
||||
// Catch errors parsing the manifest so that blank
|
||||
// or malformed manifest files don't kill the process.
|
||||
try {
|
||||
data.data = parseJson(result.toString("utf-8"));
|
||||
} catch (e) {
|
||||
// Store the error in the params so that it can
|
||||
// be added as a compilation error later on.
|
||||
const manifestPath = makePathsRelative(
|
||||
compiler.options.context,
|
||||
manifest,
|
||||
compiler.root
|
||||
);
|
||||
data.error = new DllManifestError(manifestPath, e.message);
|
||||
}
|
||||
this._compilationData.set(params, data);
|
||||
return callback();
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
return callback();
|
||||
}
|
||||
);
|
||||
|
||||
compiler.hooks.compile.tap("DllReferencePlugin", params => {
|
||||
let name = this.options.name;
|
||||
let sourceType = this.options.sourceType;
|
||||
let content =
|
||||
"content" in this.options ? this.options.content : undefined;
|
||||
if ("manifest" in this.options) {
|
||||
let manifestParameter = this.options.manifest;
|
||||
let manifest;
|
||||
if (typeof manifestParameter === "string") {
|
||||
const data = this._compilationData.get(params);
|
||||
// If there was an error parsing the manifest
|
||||
// file, exit now because the error will be added
|
||||
// as a compilation error in the "compilation" hook.
|
||||
if (data.error) {
|
||||
return;
|
||||
}
|
||||
manifest = data.data;
|
||||
} else {
|
||||
manifest = manifestParameter;
|
||||
}
|
||||
if (manifest) {
|
||||
if (!name) name = manifest.name;
|
||||
if (!sourceType) sourceType = manifest.type;
|
||||
if (!content) content = manifest.content;
|
||||
}
|
||||
}
|
||||
/** @type {Externals} */
|
||||
const externals = {};
|
||||
const source = "dll-reference " + name;
|
||||
externals[source] = name;
|
||||
const normalModuleFactory = params.normalModuleFactory;
|
||||
new ExternalModuleFactoryPlugin(sourceType || "var", externals).apply(
|
||||
normalModuleFactory
|
||||
);
|
||||
new DelegatedModuleFactoryPlugin({
|
||||
source: source,
|
||||
type: this.options.type,
|
||||
scope: this.options.scope,
|
||||
context: this.options.context || compiler.options.context,
|
||||
content,
|
||||
extensions: this.options.extensions,
|
||||
associatedObjectForCache: compiler.root
|
||||
}).apply(normalModuleFactory);
|
||||
});
|
||||
|
||||
compiler.hooks.compilation.tap(
|
||||
"DllReferencePlugin",
|
||||
(compilation, params) => {
|
||||
if ("manifest" in this.options) {
|
||||
let manifest = this.options.manifest;
|
||||
if (typeof manifest === "string") {
|
||||
const data = this._compilationData.get(params);
|
||||
// If there was an error parsing the manifest file, add the
|
||||
// error as a compilation error to make the compilation fail.
|
||||
if (data.error) {
|
||||
compilation.errors.push(data.error);
|
||||
}
|
||||
compilation.fileDependencies.add(manifest);
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class DllManifestError extends WebpackError {
|
||||
constructor(filename, message) {
|
||||
super();
|
||||
|
||||
this.name = "DllManifestError";
|
||||
this.message = `Dll manifest ${filename}\n${message}`;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = DllReferencePlugin;
|
79
node_modules/webpack/lib/DynamicEntryPlugin.js
generated
vendored
Normal file
79
node_modules/webpack/lib/DynamicEntryPlugin.js
generated
vendored
Normal file
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Naoyuki Kanezawa @nkzawa
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
const EntryOptionPlugin = require("./EntryOptionPlugin");
|
||||
const EntryPlugin = require("./EntryPlugin");
|
||||
const EntryDependency = require("./dependencies/EntryDependency");
|
||||
|
||||
/** @typedef {import("../declarations/WebpackOptions").EntryDynamicNormalized} EntryDynamic */
|
||||
/** @typedef {import("../declarations/WebpackOptions").EntryItem} EntryItem */
|
||||
/** @typedef {import("../declarations/WebpackOptions").EntryStaticNormalized} EntryStatic */
|
||||
/** @typedef {import("./Compiler")} Compiler */
|
||||
|
||||
class DynamicEntryPlugin {
|
||||
/**
|
||||
* @param {string} context the context path
|
||||
* @param {EntryDynamic} entry the entry value
|
||||
*/
|
||||
constructor(context, entry) {
|
||||
this.context = context;
|
||||
this.entry = entry;
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply the plugin
|
||||
* @param {Compiler} compiler the compiler instance
|
||||
* @returns {void}
|
||||
*/
|
||||
apply(compiler) {
|
||||
compiler.hooks.compilation.tap(
|
||||
"DynamicEntryPlugin",
|
||||
(compilation, { normalModuleFactory }) => {
|
||||
compilation.dependencyFactories.set(
|
||||
EntryDependency,
|
||||
normalModuleFactory
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
compiler.hooks.make.tapPromise(
|
||||
"DynamicEntryPlugin",
|
||||
(compilation, callback) =>
|
||||
Promise.resolve(this.entry())
|
||||
.then(entry => {
|
||||
const promises = [];
|
||||
for (const name of Object.keys(entry)) {
|
||||
const desc = entry[name];
|
||||
const options = EntryOptionPlugin.entryDescriptionToOptions(
|
||||
compiler,
|
||||
name,
|
||||
desc
|
||||
);
|
||||
for (const entry of desc.import) {
|
||||
promises.push(
|
||||
new Promise((resolve, reject) => {
|
||||
compilation.addEntry(
|
||||
this.context,
|
||||
EntryPlugin.createDependency(entry, options),
|
||||
options,
|
||||
err => {
|
||||
if (err) return reject(err);
|
||||
resolve();
|
||||
}
|
||||
);
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
return Promise.all(promises);
|
||||
})
|
||||
.then(x => {})
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = DynamicEntryPlugin;
|
93
node_modules/webpack/lib/EntryOptionPlugin.js
generated
vendored
Normal file
93
node_modules/webpack/lib/EntryOptionPlugin.js
generated
vendored
Normal file
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
/** @typedef {import("../declarations/WebpackOptions").EntryDescriptionNormalized} EntryDescription */
|
||||
/** @typedef {import("../declarations/WebpackOptions").EntryNormalized} Entry */
|
||||
/** @typedef {import("./Compiler")} Compiler */
|
||||
/** @typedef {import("./Entrypoint").EntryOptions} EntryOptions */
|
||||
|
||||
class EntryOptionPlugin {
|
||||
/**
|
||||
* @param {Compiler} compiler the compiler instance one is tapping into
|
||||
* @returns {void}
|
||||
*/
|
||||
apply(compiler) {
|
||||
compiler.hooks.entryOption.tap("EntryOptionPlugin", (context, entry) => {
|
||||
EntryOptionPlugin.applyEntryOption(compiler, context, entry);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Compiler} compiler the compiler
|
||||
* @param {string} context context directory
|
||||
* @param {Entry} entry request
|
||||
* @returns {void}
|
||||
*/
|
||||
static applyEntryOption(compiler, context, entry) {
|
||||
if (typeof entry === "function") {
|
||||
const DynamicEntryPlugin = require("./DynamicEntryPlugin");
|
||||
new DynamicEntryPlugin(context, entry).apply(compiler);
|
||||
} else {
|
||||
const EntryPlugin = require("./EntryPlugin");
|
||||
for (const name of Object.keys(entry)) {
|
||||
const desc = entry[name];
|
||||
const options = EntryOptionPlugin.entryDescriptionToOptions(
|
||||
compiler,
|
||||
name,
|
||||
desc
|
||||
);
|
||||
for (const entry of desc.import) {
|
||||
new EntryPlugin(context, entry, options).apply(compiler);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Compiler} compiler the compiler
|
||||
* @param {string} name entry name
|
||||
* @param {EntryDescription} desc entry description
|
||||
* @returns {EntryOptions} options for the entry
|
||||
*/
|
||||
static entryDescriptionToOptions(compiler, name, desc) {
|
||||
/** @type {EntryOptions} */
|
||||
const options = {
|
||||
name,
|
||||
filename: desc.filename,
|
||||
runtime: desc.runtime,
|
||||
layer: desc.layer,
|
||||
dependOn: desc.dependOn,
|
||||
baseUri: desc.baseUri,
|
||||
publicPath: desc.publicPath,
|
||||
chunkLoading: desc.chunkLoading,
|
||||
asyncChunks: desc.asyncChunks,
|
||||
wasmLoading: desc.wasmLoading,
|
||||
library: desc.library
|
||||
};
|
||||
if (desc.layer !== undefined && !compiler.options.experiments.layers) {
|
||||
throw new Error(
|
||||
"'entryOptions.layer' is only allowed when 'experiments.layers' is enabled"
|
||||
);
|
||||
}
|
||||
if (desc.chunkLoading) {
|
||||
const EnableChunkLoadingPlugin = require("./javascript/EnableChunkLoadingPlugin");
|
||||
EnableChunkLoadingPlugin.checkEnabled(compiler, desc.chunkLoading);
|
||||
}
|
||||
if (desc.wasmLoading) {
|
||||
const EnableWasmLoadingPlugin = require("./wasm/EnableWasmLoadingPlugin");
|
||||
EnableWasmLoadingPlugin.checkEnabled(compiler, desc.wasmLoading);
|
||||
}
|
||||
if (desc.library) {
|
||||
const EnableLibraryPlugin = require("./library/EnableLibraryPlugin");
|
||||
EnableLibraryPlugin.checkEnabled(compiler, desc.library.type);
|
||||
}
|
||||
return options;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = EntryOptionPlugin;
|
67
node_modules/webpack/lib/EntryPlugin.js
generated
vendored
Normal file
67
node_modules/webpack/lib/EntryPlugin.js
generated
vendored
Normal file
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
const EntryDependency = require("./dependencies/EntryDependency");
|
||||
|
||||
/** @typedef {import("./Compiler")} Compiler */
|
||||
/** @typedef {import("./Entrypoint").EntryOptions} EntryOptions */
|
||||
|
||||
class EntryPlugin {
|
||||
/**
|
||||
* An entry plugin which will handle
|
||||
* creation of the EntryDependency
|
||||
*
|
||||
* @param {string} context context path
|
||||
* @param {string} entry entry path
|
||||
* @param {EntryOptions | string=} options entry options (passing a string is deprecated)
|
||||
*/
|
||||
constructor(context, entry, options) {
|
||||
this.context = context;
|
||||
this.entry = entry;
|
||||
this.options = options || "";
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply the plugin
|
||||
* @param {Compiler} compiler the compiler instance
|
||||
* @returns {void}
|
||||
*/
|
||||
apply(compiler) {
|
||||
compiler.hooks.compilation.tap(
|
||||
"EntryPlugin",
|
||||
(compilation, { normalModuleFactory }) => {
|
||||
compilation.dependencyFactories.set(
|
||||
EntryDependency,
|
||||
normalModuleFactory
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
const { entry, options, context } = this;
|
||||
const dep = EntryPlugin.createDependency(entry, options);
|
||||
|
||||
compiler.hooks.make.tapAsync("EntryPlugin", (compilation, callback) => {
|
||||
compilation.addEntry(context, dep, options, err => {
|
||||
callback(err);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} entry entry request
|
||||
* @param {EntryOptions | string} options entry options (passing string is deprecated)
|
||||
* @returns {EntryDependency} the dependency
|
||||
*/
|
||||
static createDependency(entry, options) {
|
||||
const dep = new EntryDependency(entry);
|
||||
// TODO webpack 6 remove string option
|
||||
dep.loc = { name: typeof options === "object" ? options.name : options };
|
||||
return dep;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = EntryPlugin;
|
101
node_modules/webpack/lib/Entrypoint.js
generated
vendored
Normal file
101
node_modules/webpack/lib/Entrypoint.js
generated
vendored
Normal file
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
const ChunkGroup = require("./ChunkGroup");
|
||||
|
||||
/** @typedef {import("../declarations/WebpackOptions").EntryDescriptionNormalized} EntryDescription */
|
||||
/** @typedef {import("./Chunk")} Chunk */
|
||||
|
||||
/** @typedef {{ name?: string } & Omit<EntryDescription, "import">} EntryOptions */
|
||||
|
||||
/**
|
||||
* Entrypoint serves as an encapsulation primitive for chunks that are
|
||||
* a part of a single ChunkGroup. They represent all bundles that need to be loaded for a
|
||||
* single instance of a page. Multi-page application architectures will typically yield multiple Entrypoint objects
|
||||
* inside of the compilation, whereas a Single Page App may only contain one with many lazy-loaded chunks.
|
||||
*/
|
||||
class Entrypoint extends ChunkGroup {
|
||||
/**
|
||||
* Creates an instance of Entrypoint.
|
||||
* @param {EntryOptions | string} entryOptions the options for the entrypoint (or name)
|
||||
* @param {boolean=} initial false, when the entrypoint is not initial loaded
|
||||
*/
|
||||
constructor(entryOptions, initial = true) {
|
||||
if (typeof entryOptions === "string") {
|
||||
entryOptions = { name: entryOptions };
|
||||
}
|
||||
super({
|
||||
name: entryOptions.name
|
||||
});
|
||||
this.options = entryOptions;
|
||||
/** @type {Chunk=} */
|
||||
this._runtimeChunk = undefined;
|
||||
/** @type {Chunk=} */
|
||||
this._entrypointChunk = undefined;
|
||||
/** @type {boolean} */
|
||||
this._initial = initial;
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {boolean} true, when this chunk group will be loaded on initial page load
|
||||
*/
|
||||
isInitial() {
|
||||
return this._initial;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the runtimeChunk for an entrypoint.
|
||||
* @param {Chunk} chunk the chunk being set as the runtime chunk.
|
||||
* @returns {void}
|
||||
*/
|
||||
setRuntimeChunk(chunk) {
|
||||
this._runtimeChunk = chunk;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches the chunk reference containing the webpack bootstrap code
|
||||
* @returns {Chunk | null} returns the runtime chunk or null if there is none
|
||||
*/
|
||||
getRuntimeChunk() {
|
||||
if (this._runtimeChunk) return this._runtimeChunk;
|
||||
for (const parent of this.parentsIterable) {
|
||||
if (parent instanceof Entrypoint) return parent.getRuntimeChunk();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the chunk with the entrypoint modules for an entrypoint.
|
||||
* @param {Chunk} chunk the chunk being set as the entrypoint chunk.
|
||||
* @returns {void}
|
||||
*/
|
||||
setEntrypointChunk(chunk) {
|
||||
this._entrypointChunk = chunk;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the chunk which contains the entrypoint modules
|
||||
* (or at least the execution of them)
|
||||
* @returns {Chunk} chunk
|
||||
*/
|
||||
getEntrypointChunk() {
|
||||
return this._entrypointChunk;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Chunk} oldChunk chunk to be replaced
|
||||
* @param {Chunk} newChunk New chunk that will be replaced with
|
||||
* @returns {boolean} returns true if the replacement was successful
|
||||
*/
|
||||
replaceChunk(oldChunk, newChunk) {
|
||||
if (this._runtimeChunk === oldChunk) this._runtimeChunk = newChunk;
|
||||
if (this._entrypointChunk === oldChunk) this._entrypointChunk = newChunk;
|
||||
return super.replaceChunk(oldChunk, newChunk);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Entrypoint;
|
63
node_modules/webpack/lib/EnvironmentPlugin.js
generated
vendored
Normal file
63
node_modules/webpack/lib/EnvironmentPlugin.js
generated
vendored
Normal file
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Authors Simen Brekken @simenbrekken, Einar Löve @einarlove
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
const DefinePlugin = require("./DefinePlugin");
|
||||
const WebpackError = require("./WebpackError");
|
||||
|
||||
/** @typedef {import("./Compiler")} Compiler */
|
||||
/** @typedef {import("./DefinePlugin").CodeValue} CodeValue */
|
||||
|
||||
class EnvironmentPlugin {
|
||||
constructor(...keys) {
|
||||
if (keys.length === 1 && Array.isArray(keys[0])) {
|
||||
this.keys = keys[0];
|
||||
this.defaultValues = {};
|
||||
} else if (keys.length === 1 && keys[0] && typeof keys[0] === "object") {
|
||||
this.keys = Object.keys(keys[0]);
|
||||
this.defaultValues = keys[0];
|
||||
} else {
|
||||
this.keys = keys;
|
||||
this.defaultValues = {};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply the plugin
|
||||
* @param {Compiler} compiler the compiler instance
|
||||
* @returns {void}
|
||||
*/
|
||||
apply(compiler) {
|
||||
/** @type {Record<string, CodeValue>} */
|
||||
const definitions = {};
|
||||
for (const key of this.keys) {
|
||||
const value =
|
||||
process.env[key] !== undefined
|
||||
? process.env[key]
|
||||
: this.defaultValues[key];
|
||||
|
||||
if (value === undefined) {
|
||||
compiler.hooks.thisCompilation.tap("EnvironmentPlugin", compilation => {
|
||||
const error = new WebpackError(
|
||||
`EnvironmentPlugin - ${key} environment variable is undefined.\n\n` +
|
||||
"You can pass an object with default values to suppress this warning.\n" +
|
||||
"See https://webpack.js.org/plugins/environment-plugin for example."
|
||||
);
|
||||
|
||||
error.name = "EnvVariableNotDefinedError";
|
||||
compilation.errors.push(error);
|
||||
});
|
||||
}
|
||||
|
||||
definitions[`process.env.${key}`] =
|
||||
value === undefined ? "undefined" : JSON.stringify(value);
|
||||
}
|
||||
|
||||
new DefinePlugin(definitions).apply(compiler);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = EnvironmentPlugin;
|
61
node_modules/webpack/lib/ErrorHelpers.js
generated
vendored
Normal file
61
node_modules/webpack/lib/ErrorHelpers.js
generated
vendored
Normal file
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
const loaderFlag = "LOADER_EXECUTION";
|
||||
|
||||
const webpackOptionsFlag = "WEBPACK_OPTIONS";
|
||||
|
||||
exports.cutOffByFlag = (stack, flag) => {
|
||||
stack = stack.split("\n");
|
||||
for (let i = 0; i < stack.length; i++) {
|
||||
if (stack[i].includes(flag)) {
|
||||
stack.length = i;
|
||||
}
|
||||
}
|
||||
return stack.join("\n");
|
||||
};
|
||||
|
||||
exports.cutOffLoaderExecution = stack =>
|
||||
exports.cutOffByFlag(stack, loaderFlag);
|
||||
|
||||
exports.cutOffWebpackOptions = stack =>
|
||||
exports.cutOffByFlag(stack, webpackOptionsFlag);
|
||||
|
||||
exports.cutOffMultilineMessage = (stack, message) => {
|
||||
stack = stack.split("\n");
|
||||
message = message.split("\n");
|
||||
|
||||
const result = [];
|
||||
|
||||
stack.forEach((line, idx) => {
|
||||
if (!line.includes(message[idx])) result.push(line);
|
||||
});
|
||||
|
||||
return result.join("\n");
|
||||
};
|
||||
|
||||
exports.cutOffMessage = (stack, message) => {
|
||||
const nextLine = stack.indexOf("\n");
|
||||
if (nextLine === -1) {
|
||||
return stack === message ? "" : stack;
|
||||
} else {
|
||||
const firstLine = stack.slice(0, nextLine);
|
||||
return firstLine === message ? stack.slice(nextLine + 1) : stack;
|
||||
}
|
||||
};
|
||||
|
||||
exports.cleanUp = (stack, message) => {
|
||||
stack = exports.cutOffLoaderExecution(stack);
|
||||
stack = exports.cutOffMessage(stack, message);
|
||||
return stack;
|
||||
};
|
||||
|
||||
exports.cleanUpWebpackOptions = (stack, message) => {
|
||||
stack = exports.cutOffWebpackOptions(stack);
|
||||
stack = exports.cutOffMultilineMessage(stack, message);
|
||||
return stack;
|
||||
};
|
117
node_modules/webpack/lib/EvalDevToolModulePlugin.js
generated
vendored
Normal file
117
node_modules/webpack/lib/EvalDevToolModulePlugin.js
generated
vendored
Normal file
@@ -0,0 +1,117 @@
|
||||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
const { ConcatSource, RawSource } = require("webpack-sources");
|
||||
const ExternalModule = require("./ExternalModule");
|
||||
const ModuleFilenameHelpers = require("./ModuleFilenameHelpers");
|
||||
const RuntimeGlobals = require("./RuntimeGlobals");
|
||||
const JavascriptModulesPlugin = require("./javascript/JavascriptModulesPlugin");
|
||||
|
||||
/** @typedef {import("webpack-sources").Source} Source */
|
||||
/** @typedef {import("./Compiler")} Compiler */
|
||||
|
||||
/** @type {WeakMap<Source, Source>} */
|
||||
const cache = new WeakMap();
|
||||
|
||||
const devtoolWarning = new RawSource(`/*
|
||||
* ATTENTION: The "eval" devtool has been used (maybe by default in mode: "development").
|
||||
* This devtool is neither made for production nor for readable output files.
|
||||
* It uses "eval()" calls to create a separate source file in the browser devtools.
|
||||
* If you are trying to read the output file, select a different devtool (https://webpack.js.org/configuration/devtool/)
|
||||
* or disable the default devtool with "devtool: false".
|
||||
* If you are looking for production-ready output files, see mode: "production" (https://webpack.js.org/configuration/mode/).
|
||||
*/
|
||||
`);
|
||||
|
||||
class EvalDevToolModulePlugin {
|
||||
constructor(options) {
|
||||
this.namespace = options.namespace || "";
|
||||
this.sourceUrlComment = options.sourceUrlComment || "\n//# sourceURL=[url]";
|
||||
this.moduleFilenameTemplate =
|
||||
options.moduleFilenameTemplate ||
|
||||
"webpack://[namespace]/[resourcePath]?[loaders]";
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply the plugin
|
||||
* @param {Compiler} compiler the compiler instance
|
||||
* @returns {void}
|
||||
*/
|
||||
apply(compiler) {
|
||||
compiler.hooks.compilation.tap("EvalDevToolModulePlugin", compilation => {
|
||||
const hooks = JavascriptModulesPlugin.getCompilationHooks(compilation);
|
||||
hooks.renderModuleContent.tap(
|
||||
"EvalDevToolModulePlugin",
|
||||
(source, module, { runtimeTemplate, chunkGraph }) => {
|
||||
const cacheEntry = cache.get(source);
|
||||
if (cacheEntry !== undefined) return cacheEntry;
|
||||
if (module instanceof ExternalModule) {
|
||||
cache.set(source, source);
|
||||
return source;
|
||||
}
|
||||
const content = source.source();
|
||||
const str = ModuleFilenameHelpers.createFilename(
|
||||
module,
|
||||
{
|
||||
moduleFilenameTemplate: this.moduleFilenameTemplate,
|
||||
namespace: this.namespace
|
||||
},
|
||||
{
|
||||
requestShortener: runtimeTemplate.requestShortener,
|
||||
chunkGraph,
|
||||
hashFunction: compilation.outputOptions.hashFunction
|
||||
}
|
||||
);
|
||||
const footer =
|
||||
"\n" +
|
||||
this.sourceUrlComment.replace(
|
||||
/\[url\]/g,
|
||||
encodeURI(str)
|
||||
.replace(/%2F/g, "/")
|
||||
.replace(/%20/g, "_")
|
||||
.replace(/%5E/g, "^")
|
||||
.replace(/%5C/g, "\\")
|
||||
.replace(/^\//, "")
|
||||
);
|
||||
const result = new RawSource(
|
||||
`eval(${
|
||||
compilation.outputOptions.trustedTypes
|
||||
? `${RuntimeGlobals.createScript}(${JSON.stringify(
|
||||
content + footer
|
||||
)})`
|
||||
: JSON.stringify(content + footer)
|
||||
});`
|
||||
);
|
||||
cache.set(source, result);
|
||||
return result;
|
||||
}
|
||||
);
|
||||
hooks.inlineInRuntimeBailout.tap(
|
||||
"EvalDevToolModulePlugin",
|
||||
() => "the eval devtool is used."
|
||||
);
|
||||
hooks.render.tap(
|
||||
"EvalDevToolModulePlugin",
|
||||
source => new ConcatSource(devtoolWarning, source)
|
||||
);
|
||||
hooks.chunkHash.tap("EvalDevToolModulePlugin", (chunk, hash) => {
|
||||
hash.update("EvalDevToolModulePlugin");
|
||||
hash.update("2");
|
||||
});
|
||||
if (compilation.outputOptions.trustedTypes) {
|
||||
compilation.hooks.additionalModuleRuntimeRequirements.tap(
|
||||
"EvalDevToolModulePlugin",
|
||||
(module, set, context) => {
|
||||
set.add(RuntimeGlobals.createScript);
|
||||
}
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = EvalDevToolModulePlugin;
|
210
node_modules/webpack/lib/EvalSourceMapDevToolPlugin.js
generated
vendored
Normal file
210
node_modules/webpack/lib/EvalSourceMapDevToolPlugin.js
generated
vendored
Normal file
@@ -0,0 +1,210 @@
|
||||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
const { ConcatSource, RawSource } = require("webpack-sources");
|
||||
const ModuleFilenameHelpers = require("./ModuleFilenameHelpers");
|
||||
const NormalModule = require("./NormalModule");
|
||||
const RuntimeGlobals = require("./RuntimeGlobals");
|
||||
const SourceMapDevToolModuleOptionsPlugin = require("./SourceMapDevToolModuleOptionsPlugin");
|
||||
const JavascriptModulesPlugin = require("./javascript/JavascriptModulesPlugin");
|
||||
const ConcatenatedModule = require("./optimize/ConcatenatedModule");
|
||||
const { makePathsAbsolute } = require("./util/identifier");
|
||||
|
||||
/** @typedef {import("webpack-sources").Source} Source */
|
||||
/** @typedef {import("../declarations/WebpackOptions").DevTool} DevToolOptions */
|
||||
/** @typedef {import("../declarations/plugins/SourceMapDevToolPlugin").SourceMapDevToolPluginOptions} SourceMapDevToolPluginOptions */
|
||||
/** @typedef {import("./Compiler")} Compiler */
|
||||
/** @typedef {import("./NormalModule").SourceMap} SourceMap */
|
||||
|
||||
/** @type {WeakMap<Source, Source>} */
|
||||
const cache = new WeakMap();
|
||||
|
||||
const devtoolWarning = new RawSource(`/*
|
||||
* ATTENTION: An "eval-source-map" devtool has been used.
|
||||
* This devtool is neither made for production nor for readable output files.
|
||||
* It uses "eval()" calls to create a separate source file with attached SourceMaps in the browser devtools.
|
||||
* If you are trying to read the output file, select a different devtool (https://webpack.js.org/configuration/devtool/)
|
||||
* or disable the default devtool with "devtool: false".
|
||||
* If you are looking for production-ready output files, see mode: "production" (https://webpack.js.org/configuration/mode/).
|
||||
*/
|
||||
`);
|
||||
|
||||
class EvalSourceMapDevToolPlugin {
|
||||
/**
|
||||
* @param {SourceMapDevToolPluginOptions|string} inputOptions Options object
|
||||
*/
|
||||
constructor(inputOptions) {
|
||||
/** @type {SourceMapDevToolPluginOptions} */
|
||||
let options;
|
||||
if (typeof inputOptions === "string") {
|
||||
options = {
|
||||
append: inputOptions
|
||||
};
|
||||
} else {
|
||||
options = inputOptions;
|
||||
}
|
||||
this.sourceMapComment =
|
||||
options.append || "//# sourceURL=[module]\n//# sourceMappingURL=[url]";
|
||||
this.moduleFilenameTemplate =
|
||||
options.moduleFilenameTemplate ||
|
||||
"webpack://[namespace]/[resource-path]?[hash]";
|
||||
this.namespace = options.namespace || "";
|
||||
this.options = options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply the plugin
|
||||
* @param {Compiler} compiler the compiler instance
|
||||
* @returns {void}
|
||||
*/
|
||||
apply(compiler) {
|
||||
const options = this.options;
|
||||
compiler.hooks.compilation.tap(
|
||||
"EvalSourceMapDevToolPlugin",
|
||||
compilation => {
|
||||
const hooks = JavascriptModulesPlugin.getCompilationHooks(compilation);
|
||||
new SourceMapDevToolModuleOptionsPlugin(options).apply(compilation);
|
||||
const matchModule = ModuleFilenameHelpers.matchObject.bind(
|
||||
ModuleFilenameHelpers,
|
||||
options
|
||||
);
|
||||
hooks.renderModuleContent.tap(
|
||||
"EvalSourceMapDevToolPlugin",
|
||||
(source, m, { runtimeTemplate, chunkGraph }) => {
|
||||
const cachedSource = cache.get(source);
|
||||
if (cachedSource !== undefined) {
|
||||
return cachedSource;
|
||||
}
|
||||
|
||||
const result = r => {
|
||||
cache.set(source, r);
|
||||
return r;
|
||||
};
|
||||
|
||||
if (m instanceof NormalModule) {
|
||||
const module = /** @type {NormalModule} */ (m);
|
||||
if (!matchModule(module.resource)) {
|
||||
return result(source);
|
||||
}
|
||||
} else if (m instanceof ConcatenatedModule) {
|
||||
const concatModule = /** @type {ConcatenatedModule} */ (m);
|
||||
if (concatModule.rootModule instanceof NormalModule) {
|
||||
const module = /** @type {NormalModule} */ (
|
||||
concatModule.rootModule
|
||||
);
|
||||
if (!matchModule(module.resource)) {
|
||||
return result(source);
|
||||
}
|
||||
} else {
|
||||
return result(source);
|
||||
}
|
||||
} else {
|
||||
return result(source);
|
||||
}
|
||||
|
||||
/** @type {SourceMap} */
|
||||
let sourceMap;
|
||||
let content;
|
||||
if (source.sourceAndMap) {
|
||||
const sourceAndMap = source.sourceAndMap(options);
|
||||
sourceMap = /** @type {SourceMap} */ (sourceAndMap.map);
|
||||
content = sourceAndMap.source;
|
||||
} else {
|
||||
sourceMap = /** @type {SourceMap} */ (source.map(options));
|
||||
content = source.source();
|
||||
}
|
||||
if (!sourceMap) {
|
||||
return result(source);
|
||||
}
|
||||
|
||||
// Clone (flat) the sourcemap to ensure that the mutations below do not persist.
|
||||
sourceMap = { ...sourceMap };
|
||||
const context = compiler.options.context;
|
||||
const root = compiler.root;
|
||||
const modules = sourceMap.sources.map(source => {
|
||||
if (!source.startsWith("webpack://")) return source;
|
||||
source = makePathsAbsolute(context, source.slice(10), root);
|
||||
const module = compilation.findModule(source);
|
||||
return module || source;
|
||||
});
|
||||
let moduleFilenames = modules.map(module => {
|
||||
return ModuleFilenameHelpers.createFilename(
|
||||
module,
|
||||
{
|
||||
moduleFilenameTemplate: this.moduleFilenameTemplate,
|
||||
namespace: this.namespace
|
||||
},
|
||||
{
|
||||
requestShortener: runtimeTemplate.requestShortener,
|
||||
chunkGraph,
|
||||
hashFunction: compilation.outputOptions.hashFunction
|
||||
}
|
||||
);
|
||||
});
|
||||
moduleFilenames = ModuleFilenameHelpers.replaceDuplicates(
|
||||
moduleFilenames,
|
||||
(filename, i, n) => {
|
||||
for (let j = 0; j < n; j++) filename += "*";
|
||||
return filename;
|
||||
}
|
||||
);
|
||||
sourceMap.sources = moduleFilenames;
|
||||
if (options.noSources) {
|
||||
sourceMap.sourcesContent = undefined;
|
||||
}
|
||||
sourceMap.sourceRoot = options.sourceRoot || "";
|
||||
const moduleId = chunkGraph.getModuleId(m);
|
||||
sourceMap.file = `${moduleId}.js`;
|
||||
|
||||
const footer =
|
||||
this.sourceMapComment.replace(
|
||||
/\[url\]/g,
|
||||
`data:application/json;charset=utf-8;base64,${Buffer.from(
|
||||
JSON.stringify(sourceMap),
|
||||
"utf8"
|
||||
).toString("base64")}`
|
||||
) + `\n//# sourceURL=webpack-internal:///${moduleId}\n`; // workaround for chrome bug
|
||||
|
||||
return result(
|
||||
new RawSource(
|
||||
`eval(${
|
||||
compilation.outputOptions.trustedTypes
|
||||
? `${RuntimeGlobals.createScript}(${JSON.stringify(
|
||||
content + footer
|
||||
)})`
|
||||
: JSON.stringify(content + footer)
|
||||
});`
|
||||
)
|
||||
);
|
||||
}
|
||||
);
|
||||
hooks.inlineInRuntimeBailout.tap(
|
||||
"EvalDevToolModulePlugin",
|
||||
() => "the eval-source-map devtool is used."
|
||||
);
|
||||
hooks.render.tap(
|
||||
"EvalSourceMapDevToolPlugin",
|
||||
source => new ConcatSource(devtoolWarning, source)
|
||||
);
|
||||
hooks.chunkHash.tap("EvalSourceMapDevToolPlugin", (chunk, hash) => {
|
||||
hash.update("EvalSourceMapDevToolPlugin");
|
||||
hash.update("2");
|
||||
});
|
||||
if (compilation.outputOptions.trustedTypes) {
|
||||
compilation.hooks.additionalModuleRuntimeRequirements.tap(
|
||||
"EvalSourceMapDevToolPlugin",
|
||||
(module, set, context) => {
|
||||
set.add(RuntimeGlobals.createScript);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = EvalSourceMapDevToolPlugin;
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user