commit node_modules and generated files
This commit is contained in:
parent
6d7a135fea
commit
34b372292b
3379 changed files with 449603 additions and 2029 deletions
84
node_modules/webpack/lib/APIPlugin.js
generated
vendored
Normal file
84
node_modules/webpack/lib/APIPlugin.js
generated
vendored
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
"use strict";
|
||||
|
||||
const ConstDependency = require("./dependencies/ConstDependency");
|
||||
const ParserHelpers = require("./ParserHelpers");
|
||||
|
||||
const NullFactory = require("./NullFactory");
|
||||
|
||||
/* eslint-disable camelcase */
|
||||
const REPLACEMENTS = {
|
||||
__webpack_require__: "__webpack_require__",
|
||||
__webpack_public_path__: "__webpack_require__.p",
|
||||
__webpack_modules__: "__webpack_require__.m",
|
||||
__webpack_chunk_load__: "__webpack_require__.e",
|
||||
__non_webpack_require__: "require",
|
||||
__webpack_nonce__: "__webpack_require__.nc",
|
||||
"require.onError": "__webpack_require__.oe"
|
||||
};
|
||||
const NO_WEBPACK_REQUIRE = {
|
||||
__non_webpack_require__: true
|
||||
};
|
||||
const REPLACEMENT_TYPES = {
|
||||
__webpack_public_path__: "string",
|
||||
__webpack_require__: "function",
|
||||
__webpack_modules__: "object",
|
||||
__webpack_chunk_load__: "function",
|
||||
__webpack_nonce__: "string"
|
||||
};
|
||||
/* eslint-enable camelcase */
|
||||
|
||||
class APIPlugin {
|
||||
apply(compiler) {
|
||||
compiler.hooks.compilation.tap(
|
||||
"APIPlugin",
|
||||
(compilation, { normalModuleFactory }) => {
|
||||
compilation.dependencyFactories.set(ConstDependency, new NullFactory());
|
||||
compilation.dependencyTemplates.set(
|
||||
ConstDependency,
|
||||
new ConstDependency.Template()
|
||||
);
|
||||
|
||||
const handler = parser => {
|
||||
Object.keys(REPLACEMENTS).forEach(key => {
|
||||
parser.hooks.expression
|
||||
.for(key)
|
||||
.tap(
|
||||
"APIPlugin",
|
||||
NO_WEBPACK_REQUIRE[key]
|
||||
? ParserHelpers.toConstantDependency(
|
||||
parser,
|
||||
REPLACEMENTS[key]
|
||||
)
|
||||
: ParserHelpers.toConstantDependencyWithWebpackRequire(
|
||||
parser,
|
||||
REPLACEMENTS[key]
|
||||
)
|
||||
);
|
||||
const type = REPLACEMENT_TYPES[key];
|
||||
if (type) {
|
||||
parser.hooks.evaluateTypeof
|
||||
.for(key)
|
||||
.tap("APIPlugin", ParserHelpers.evaluateToString(type));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
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;
|
||||
43
node_modules/webpack/lib/AbstractMethodError.js
generated
vendored
Normal file
43
node_modules/webpack/lib/AbstractMethodError.js
generated
vendored
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
"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() {
|
||||
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 overriden.
|
||||
* }
|
||||
* }
|
||||
*
|
||||
*/
|
||||
class AbstractMethodError extends WebpackError {
|
||||
constructor() {
|
||||
super(new Message().message);
|
||||
this.name = "AbstractMethodError";
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = AbstractMethodError;
|
||||
106
node_modules/webpack/lib/AmdMainTemplatePlugin.js
generated
vendored
Normal file
106
node_modules/webpack/lib/AmdMainTemplatePlugin.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 { ConcatSource } = require("webpack-sources");
|
||||
const Template = require("./Template");
|
||||
|
||||
/** @typedef {import("./Compilation")} Compilation */
|
||||
|
||||
/**
|
||||
* @typedef {Object} AmdMainTemplatePluginOptions
|
||||
* @param {string=} name the library name
|
||||
* @property {boolean=} requireAsWrapper
|
||||
*/
|
||||
|
||||
class AmdMainTemplatePlugin {
|
||||
/**
|
||||
* @param {AmdMainTemplatePluginOptions} options the plugin options
|
||||
*/
|
||||
constructor(options) {
|
||||
if (!options || typeof options === "string") {
|
||||
this.name = options;
|
||||
this.requireAsWrapper = false;
|
||||
} else {
|
||||
this.name = options.name;
|
||||
this.requireAsWrapper = options.requireAsWrapper;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Compilation} compilation the compilation instance
|
||||
* @returns {void}
|
||||
*/
|
||||
apply(compilation) {
|
||||
const { mainTemplate, chunkTemplate } = compilation;
|
||||
|
||||
const onRenderWithEntry = (source, chunk, hash) => {
|
||||
const externals = chunk.getModules().filter(m => m.external);
|
||||
const externalsDepsArray = JSON.stringify(
|
||||
externals.map(m =>
|
||||
typeof m.request === "object" ? m.request.amd : m.request
|
||||
)
|
||||
);
|
||||
const externalsArguments = externals
|
||||
.map(
|
||||
m => `__WEBPACK_EXTERNAL_MODULE_${Template.toIdentifier(`${m.id}`)}__`
|
||||
)
|
||||
.join(", ");
|
||||
|
||||
if (this.requireAsWrapper) {
|
||||
return new ConcatSource(
|
||||
`require(${externalsDepsArray}, function(${externalsArguments}) { return `,
|
||||
source,
|
||||
"});"
|
||||
);
|
||||
} else if (this.name) {
|
||||
const name = mainTemplate.getAssetPath(this.name, {
|
||||
hash,
|
||||
chunk
|
||||
});
|
||||
|
||||
return new ConcatSource(
|
||||
`define(${JSON.stringify(
|
||||
name
|
||||
)}, ${externalsDepsArray}, function(${externalsArguments}) { return `,
|
||||
source,
|
||||
"});"
|
||||
);
|
||||
} else if (externalsArguments) {
|
||||
return new ConcatSource(
|
||||
`define(${externalsDepsArray}, function(${externalsArguments}) { return `,
|
||||
source,
|
||||
"});"
|
||||
);
|
||||
} else {
|
||||
return new ConcatSource("define(function() { return ", source, "});");
|
||||
}
|
||||
};
|
||||
|
||||
for (const template of [mainTemplate, chunkTemplate]) {
|
||||
template.hooks.renderWithEntry.tap(
|
||||
"AmdMainTemplatePlugin",
|
||||
onRenderWithEntry
|
||||
);
|
||||
}
|
||||
|
||||
mainTemplate.hooks.globalHashPaths.tap("AmdMainTemplatePlugin", paths => {
|
||||
if (this.name) {
|
||||
paths.push(this.name);
|
||||
}
|
||||
return paths;
|
||||
});
|
||||
|
||||
mainTemplate.hooks.hash.tap("AmdMainTemplatePlugin", hash => {
|
||||
hash.update("exports amd");
|
||||
if (this.name) {
|
||||
hash.update(this.name);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = AmdMainTemplatePlugin;
|
||||
110
node_modules/webpack/lib/AsyncDependenciesBlock.js
generated
vendored
Normal file
110
node_modules/webpack/lib/AsyncDependenciesBlock.js
generated
vendored
Normal file
|
|
@ -0,0 +1,110 @@
|
|||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
"use strict";
|
||||
|
||||
const DependenciesBlock = require("./DependenciesBlock");
|
||||
|
||||
/** @typedef {import("./ChunkGroup")} ChunkGroup */
|
||||
/** @typedef {import("./Module")} Module */
|
||||
/** @typedef {import("./Dependency").DependencyLocation} DependencyLocation */
|
||||
/** @typedef {import("./util/createHash").Hash} Hash */
|
||||
/** @typedef {TODO} GroupOptions */
|
||||
|
||||
module.exports = class AsyncDependenciesBlock extends DependenciesBlock {
|
||||
/**
|
||||
* @param {GroupOptions} groupOptions options for the group
|
||||
* @param {Module} module the Module object
|
||||
* @param {DependencyLocation=} loc the line of code
|
||||
* @param {TODO=} request the request
|
||||
*/
|
||||
constructor(groupOptions, module, loc, request) {
|
||||
super();
|
||||
if (typeof groupOptions === "string") {
|
||||
groupOptions = { name: groupOptions };
|
||||
} else if (!groupOptions) {
|
||||
groupOptions = { name: undefined };
|
||||
}
|
||||
this.groupOptions = groupOptions;
|
||||
/** @type {ChunkGroup=} */
|
||||
this.chunkGroup = undefined;
|
||||
this.module = module;
|
||||
this.loc = loc;
|
||||
this.request = request;
|
||||
/** @type {DependenciesBlock} */
|
||||
this.parent = 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) {
|
||||
this.groupOptions.name = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {never} this throws and should never be called
|
||||
*/
|
||||
get chunks() {
|
||||
throw new Error("Moved to AsyncDependenciesBlock.chunkGroup");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {never} value setter value
|
||||
* @returns {never} this is going to throw therefore we should throw type
|
||||
* assertions by returning never
|
||||
*/
|
||||
set chunks(value) {
|
||||
throw new Error("Moved to AsyncDependenciesBlock.chunkGroup");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Hash} hash the hash used to track block changes, from "crypto" module
|
||||
* @returns {void}
|
||||
*/
|
||||
updateHash(hash) {
|
||||
hash.update(JSON.stringify(this.groupOptions));
|
||||
hash.update(
|
||||
(this.chunkGroup &&
|
||||
this.chunkGroup.chunks
|
||||
.map(chunk => {
|
||||
return chunk.id !== null ? chunk.id : "";
|
||||
})
|
||||
.join(",")) ||
|
||||
""
|
||||
);
|
||||
super.updateHash(hash);
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {void}
|
||||
*/
|
||||
disconnect() {
|
||||
this.chunkGroup = undefined;
|
||||
super.disconnect();
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {void}
|
||||
*/
|
||||
unseal() {
|
||||
this.chunkGroup = undefined;
|
||||
super.unseal();
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {void}
|
||||
*/
|
||||
sortItems() {
|
||||
super.sortItems();
|
||||
}
|
||||
};
|
||||
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("./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 {TODO} 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;
|
||||
|
||||
Error.captureStackTrace(this, this.constructor);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = AsyncDependencyToInitialChunkError;
|
||||
57
node_modules/webpack/lib/AutomaticPrefetchPlugin.js
generated
vendored
Normal file
57
node_modules/webpack/lib/AutomaticPrefetchPlugin.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";
|
||||
|
||||
const asyncLib = require("neo-async");
|
||||
const PrefetchDependency = require("./dependencies/PrefetchDependency");
|
||||
const NormalModule = require("./NormalModule");
|
||||
|
||||
/** @typedef {import("./Compiler")} Compiler */
|
||||
|
||||
class AutomaticPrefetchPlugin {
|
||||
/**
|
||||
* Apply the plugin
|
||||
* @param {Compiler} compiler Webpack Compiler
|
||||
* @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 = compilation.modules
|
||||
.filter(m => m instanceof NormalModule)
|
||||
.map((/** @type {NormalModule} */ m) => ({
|
||||
context: m.context,
|
||||
request: m.request
|
||||
}));
|
||||
});
|
||||
compiler.hooks.make.tapAsync(
|
||||
"AutomaticPrefetchPlugin",
|
||||
(compilation, callback) => {
|
||||
if (!lastModules) return callback();
|
||||
asyncLib.forEach(
|
||||
lastModules,
|
||||
(m, callback) => {
|
||||
compilation.prefetch(
|
||||
m.context || compiler.context,
|
||||
new PrefetchDependency(m.request),
|
||||
callback
|
||||
);
|
||||
},
|
||||
callback
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
module.exports = AutomaticPrefetchPlugin;
|
||||
122
node_modules/webpack/lib/BannerPlugin.js
generated
vendored
Normal file
122
node_modules/webpack/lib/BannerPlugin.js
generated
vendored
Normal file
|
|
@ -0,0 +1,122 @@
|
|||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
const { ConcatSource } = require("webpack-sources");
|
||||
const ModuleFilenameHelpers = require("./ModuleFilenameHelpers");
|
||||
const Template = require("./Template");
|
||||
|
||||
const validateOptions = require("schema-utils");
|
||||
const schema = require("../schemas/plugins/BannerPlugin.json");
|
||||
|
||||
/** @typedef {import("../declarations/plugins/BannerPlugin").BannerPluginArgument} BannerPluginArgument */
|
||||
/** @typedef {import("../declarations/plugins/BannerPlugin").BannerPluginOptions} BannerPluginOptions */
|
||||
|
||||
const wrapComment = str => {
|
||||
if (!str.includes("\n")) {
|
||||
return Template.toComment(str);
|
||||
}
|
||||
return `/*!\n * ${str
|
||||
.replace(/\*\//g, "* /")
|
||||
.split("\n")
|
||||
.join("\n * ")}\n */`;
|
||||
};
|
||||
|
||||
class BannerPlugin {
|
||||
/**
|
||||
* @param {BannerPluginArgument} options options object
|
||||
*/
|
||||
constructor(options) {
|
||||
if (arguments.length > 1) {
|
||||
throw new Error(
|
||||
"BannerPlugin only takes one argument (pass an options object)"
|
||||
);
|
||||
}
|
||||
|
||||
validateOptions(schema, options, "Banner Plugin");
|
||||
|
||||
if (typeof options === "string" || typeof options === "function") {
|
||||
options = {
|
||||
banner: options
|
||||
};
|
||||
}
|
||||
|
||||
/** @type {BannerPluginOptions} */
|
||||
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(compiler) {
|
||||
const options = this.options;
|
||||
const banner = this.banner;
|
||||
const matchObject = ModuleFilenameHelpers.matchObject.bind(
|
||||
undefined,
|
||||
options
|
||||
);
|
||||
|
||||
compiler.hooks.compilation.tap("BannerPlugin", compilation => {
|
||||
compilation.hooks.optimizeChunkAssets.tap("BannerPlugin", chunks => {
|
||||
for (const chunk of chunks) {
|
||||
if (options.entryOnly && !chunk.canBeInitial()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (const file of chunk.files) {
|
||||
if (!matchObject(file)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
let query = "";
|
||||
let filename = file;
|
||||
const hash = compilation.hash;
|
||||
const querySplit = filename.indexOf("?");
|
||||
|
||||
if (querySplit >= 0) {
|
||||
query = filename.substr(querySplit);
|
||||
filename = filename.substr(0, querySplit);
|
||||
}
|
||||
|
||||
const lastSlashIndex = filename.lastIndexOf("/");
|
||||
|
||||
const basename =
|
||||
lastSlashIndex === -1
|
||||
? filename
|
||||
: filename.substr(lastSlashIndex + 1);
|
||||
|
||||
const data = {
|
||||
hash,
|
||||
chunk,
|
||||
filename,
|
||||
basename,
|
||||
query
|
||||
};
|
||||
|
||||
const comment = compilation.getPath(banner(data), data);
|
||||
|
||||
compilation.updateAsset(
|
||||
file,
|
||||
old => new ConcatSource(comment, "\n", old)
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = BannerPlugin;
|
||||
248
node_modules/webpack/lib/BasicEvaluatedExpression.js
generated
vendored
Normal file
248
node_modules/webpack/lib/BasicEvaluatedExpression.js
generated
vendored
Normal file
|
|
@ -0,0 +1,248 @@
|
|||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
const TypeUnknown = 0;
|
||||
const TypeNull = 1;
|
||||
const TypeString = 2;
|
||||
const TypeNumber = 3;
|
||||
const TypeBoolean = 4;
|
||||
const TypeRegExp = 5;
|
||||
const TypeConditional = 6;
|
||||
const TypeArray = 7;
|
||||
const TypeConstArray = 8;
|
||||
const TypeIdentifier = 9;
|
||||
const TypeWrapped = 10;
|
||||
const TypeTemplateString = 11;
|
||||
|
||||
class BasicEvaluatedExpression {
|
||||
constructor() {
|
||||
this.type = TypeUnknown;
|
||||
this.range = null;
|
||||
this.falsy = false;
|
||||
this.truthy = false;
|
||||
this.bool = null;
|
||||
this.number = null;
|
||||
this.regExp = null;
|
||||
this.string = null;
|
||||
this.quasis = null;
|
||||
this.parts = null;
|
||||
this.array = null;
|
||||
this.items = null;
|
||||
this.options = null;
|
||||
this.prefix = null;
|
||||
this.postfix = null;
|
||||
this.wrappedInnerExpressions = null;
|
||||
this.expression = null;
|
||||
}
|
||||
|
||||
isNull() {
|
||||
return this.type === TypeNull;
|
||||
}
|
||||
|
||||
isString() {
|
||||
return this.type === TypeString;
|
||||
}
|
||||
|
||||
isNumber() {
|
||||
return this.type === TypeNumber;
|
||||
}
|
||||
|
||||
isBoolean() {
|
||||
return this.type === TypeBoolean;
|
||||
}
|
||||
|
||||
isRegExp() {
|
||||
return this.type === TypeRegExp;
|
||||
}
|
||||
|
||||
isConditional() {
|
||||
return this.type === TypeConditional;
|
||||
}
|
||||
|
||||
isArray() {
|
||||
return this.type === TypeArray;
|
||||
}
|
||||
|
||||
isConstArray() {
|
||||
return this.type === TypeConstArray;
|
||||
}
|
||||
|
||||
isIdentifier() {
|
||||
return this.type === TypeIdentifier;
|
||||
}
|
||||
|
||||
isWrapped() {
|
||||
return this.type === TypeWrapped;
|
||||
}
|
||||
|
||||
isTemplateString() {
|
||||
return this.type === TypeTemplateString;
|
||||
}
|
||||
|
||||
isTruthy() {
|
||||
return this.truthy;
|
||||
}
|
||||
|
||||
isFalsy() {
|
||||
return this.falsy;
|
||||
}
|
||||
|
||||
asBool() {
|
||||
if (this.truthy) return true;
|
||||
if (this.falsy) return false;
|
||||
if (this.isBoolean()) return this.bool;
|
||||
if (this.isNull()) return false;
|
||||
if (this.isString()) return this.string !== "";
|
||||
if (this.isNumber()) return this.number !== 0;
|
||||
if (this.isRegExp()) return true;
|
||||
if (this.isArray()) return true;
|
||||
if (this.isConstArray()) return true;
|
||||
if (this.isWrapped()) {
|
||||
return (this.prefix && this.prefix.asBool()) ||
|
||||
(this.postfix && this.postfix.asBool())
|
||||
? true
|
||||
: undefined;
|
||||
}
|
||||
if (this.isTemplateString()) {
|
||||
const str = this.asString();
|
||||
if (typeof str === "string") return str !== "";
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
asString() {
|
||||
if (this.isBoolean()) return `${this.bool}`;
|
||||
if (this.isNull()) return "null";
|
||||
if (this.isString()) return this.string;
|
||||
if (this.isNumber()) return `${this.number}`;
|
||||
if (this.isRegExp()) return `${this.regExp}`;
|
||||
if (this.isArray()) {
|
||||
let array = [];
|
||||
for (const item of this.items) {
|
||||
const itemStr = item.asString();
|
||||
if (itemStr === undefined) return undefined;
|
||||
array.push(itemStr);
|
||||
}
|
||||
return `${array}`;
|
||||
}
|
||||
if (this.isConstArray()) return `${this.array}`;
|
||||
if (this.isTemplateString()) {
|
||||
let str = "";
|
||||
for (const part of this.parts) {
|
||||
const partStr = part.asString();
|
||||
if (partStr === undefined) return undefined;
|
||||
str += partStr;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
setString(string) {
|
||||
this.type = TypeString;
|
||||
this.string = string;
|
||||
return this;
|
||||
}
|
||||
|
||||
setNull() {
|
||||
this.type = TypeNull;
|
||||
return this;
|
||||
}
|
||||
|
||||
setNumber(number) {
|
||||
this.type = TypeNumber;
|
||||
this.number = number;
|
||||
return this;
|
||||
}
|
||||
|
||||
setBoolean(bool) {
|
||||
this.type = TypeBoolean;
|
||||
this.bool = bool;
|
||||
return this;
|
||||
}
|
||||
|
||||
setRegExp(regExp) {
|
||||
this.type = TypeRegExp;
|
||||
this.regExp = regExp;
|
||||
return this;
|
||||
}
|
||||
|
||||
setIdentifier(identifier) {
|
||||
this.type = TypeIdentifier;
|
||||
this.identifier = identifier;
|
||||
return this;
|
||||
}
|
||||
|
||||
setWrapped(prefix, postfix, innerExpressions) {
|
||||
this.type = TypeWrapped;
|
||||
this.prefix = prefix;
|
||||
this.postfix = postfix;
|
||||
this.wrappedInnerExpressions = innerExpressions;
|
||||
return this;
|
||||
}
|
||||
|
||||
setOptions(options) {
|
||||
this.type = TypeConditional;
|
||||
this.options = options;
|
||||
return this;
|
||||
}
|
||||
|
||||
addOptions(options) {
|
||||
if (!this.options) {
|
||||
this.type = TypeConditional;
|
||||
this.options = [];
|
||||
}
|
||||
for (const item of options) {
|
||||
this.options.push(item);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
setItems(items) {
|
||||
this.type = TypeArray;
|
||||
this.items = items;
|
||||
return this;
|
||||
}
|
||||
|
||||
setArray(array) {
|
||||
this.type = TypeConstArray;
|
||||
this.array = array;
|
||||
return this;
|
||||
}
|
||||
|
||||
setTemplateString(quasis, parts, kind) {
|
||||
this.type = TypeTemplateString;
|
||||
this.quasis = quasis;
|
||||
this.parts = parts;
|
||||
this.templateStringKind = kind;
|
||||
return this;
|
||||
}
|
||||
|
||||
setTruthy() {
|
||||
this.falsy = false;
|
||||
this.truthy = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
setFalsy() {
|
||||
this.falsy = true;
|
||||
this.truthy = false;
|
||||
return this;
|
||||
}
|
||||
|
||||
setRange(range) {
|
||||
this.range = range;
|
||||
return this;
|
||||
}
|
||||
|
||||
setExpression(expression) {
|
||||
this.expression = expression;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = BasicEvaluatedExpression;
|
||||
100
node_modules/webpack/lib/CachePlugin.js
generated
vendored
Normal file
100
node_modules/webpack/lib/CachePlugin.js
generated
vendored
Normal file
|
|
@ -0,0 +1,100 @@
|
|||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
"use strict";
|
||||
|
||||
const asyncLib = require("neo-async");
|
||||
|
||||
class CachePlugin {
|
||||
constructor(cache) {
|
||||
this.cache = cache || {};
|
||||
this.FS_ACCURACY = 2000;
|
||||
}
|
||||
|
||||
apply(compiler) {
|
||||
if (Array.isArray(compiler.compilers)) {
|
||||
compiler.compilers.forEach((c, idx) => {
|
||||
new CachePlugin((this.cache[idx] = this.cache[idx] || {})).apply(c);
|
||||
});
|
||||
} else {
|
||||
const registerCacheToCompiler = (compiler, cache) => {
|
||||
compiler.hooks.thisCompilation.tap("CachePlugin", compilation => {
|
||||
compilation.cache = cache;
|
||||
compilation.hooks.childCompiler.tap(
|
||||
"CachePlugin",
|
||||
(childCompiler, compilerName, compilerIndex) => {
|
||||
let childCache;
|
||||
if (!cache.children) {
|
||||
cache.children = {};
|
||||
}
|
||||
if (!cache.children[compilerName]) {
|
||||
cache.children[compilerName] = [];
|
||||
}
|
||||
if (cache.children[compilerName][compilerIndex]) {
|
||||
childCache = cache.children[compilerName][compilerIndex];
|
||||
} else {
|
||||
cache.children[compilerName].push((childCache = {}));
|
||||
}
|
||||
registerCacheToCompiler(childCompiler, childCache);
|
||||
}
|
||||
);
|
||||
});
|
||||
};
|
||||
registerCacheToCompiler(compiler, this.cache);
|
||||
compiler.hooks.watchRun.tap("CachePlugin", () => {
|
||||
this.watching = true;
|
||||
});
|
||||
compiler.hooks.run.tapAsync("CachePlugin", (compiler, callback) => {
|
||||
if (!compiler._lastCompilationFileDependencies) {
|
||||
return callback();
|
||||
}
|
||||
const fs = compiler.inputFileSystem;
|
||||
const fileTs = (compiler.fileTimestamps = new Map());
|
||||
asyncLib.forEach(
|
||||
compiler._lastCompilationFileDependencies,
|
||||
(file, callback) => {
|
||||
fs.stat(file, (err, stat) => {
|
||||
if (err) {
|
||||
if (err.code === "ENOENT") return callback();
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
if (stat.mtime) this.applyMtime(+stat.mtime);
|
||||
|
||||
fileTs.set(file, +stat.mtime || Infinity);
|
||||
|
||||
callback();
|
||||
});
|
||||
},
|
||||
err => {
|
||||
if (err) return callback(err);
|
||||
|
||||
for (const [file, ts] of fileTs) {
|
||||
fileTs.set(file, ts + this.FS_ACCURACY);
|
||||
}
|
||||
|
||||
callback();
|
||||
}
|
||||
);
|
||||
});
|
||||
compiler.hooks.afterCompile.tap("CachePlugin", compilation => {
|
||||
compilation.compiler._lastCompilationFileDependencies =
|
||||
compilation.fileDependencies;
|
||||
compilation.compiler._lastCompilationContextDependencies =
|
||||
compilation.contextDependencies;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/* istanbul ignore next */
|
||||
applyMtime(mtime) {
|
||||
if (this.FS_ACCURACY > 1 && mtime % 2 !== 0) this.FS_ACCURACY = 1;
|
||||
else if (this.FS_ACCURACY > 10 && mtime % 20 !== 0) this.FS_ACCURACY = 10;
|
||||
else if (this.FS_ACCURACY > 100 && mtime % 200 !== 0)
|
||||
this.FS_ACCURACY = 100;
|
||||
else if (this.FS_ACCURACY > 1000 && mtime % 2000 !== 0)
|
||||
this.FS_ACCURACY = 1000;
|
||||
}
|
||||
}
|
||||
module.exports = CachePlugin;
|
||||
67
node_modules/webpack/lib/CaseSensitiveModulesWarning.js
generated
vendored
Normal file
67
node_modules/webpack/lib/CaseSensitiveModulesWarning.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 WebpackError = require("./WebpackError");
|
||||
|
||||
/** @typedef {import("./Module")} Module */
|
||||
|
||||
/**
|
||||
* @param {Module[]} modules the modules to be sorted
|
||||
* @returns {Module[]} sorted version of original modules
|
||||
*/
|
||||
const sortModules = modules => {
|
||||
return modules.slice().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
|
||||
* @returns {string} each message from provided moduels
|
||||
*/
|
||||
const createModulesListMessage = modules => {
|
||||
return modules
|
||||
.map(m => {
|
||||
let message = `* ${m.identifier()}`;
|
||||
const validReasons = m.reasons.filter(reason => reason.module);
|
||||
|
||||
if (validReasons.length > 0) {
|
||||
message += `\n Used by ${validReasons.length} module(s), i. e.`;
|
||||
message += `\n ${validReasons[0].module.identifier()}`;
|
||||
}
|
||||
return message;
|
||||
})
|
||||
.join("\n");
|
||||
};
|
||||
|
||||
class CaseSensitiveModulesWarning extends WebpackError {
|
||||
/**
|
||||
* Creates an instance of CaseSensitiveModulesWarning.
|
||||
* @param {Module[]} modules modules that were detected
|
||||
*/
|
||||
constructor(modules) {
|
||||
const sortedModules = sortModules(modules);
|
||||
const modulesList = createModulesListMessage(sortedModules);
|
||||
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.origin = this.module = sortedModules[0];
|
||||
|
||||
Error.captureStackTrace(this, this.constructor);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = CaseSensitiveModulesWarning;
|
||||
875
node_modules/webpack/lib/Chunk.js
generated
vendored
Normal file
875
node_modules/webpack/lib/Chunk.js
generated
vendored
Normal file
|
|
@ -0,0 +1,875 @@
|
|||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
"use strict";
|
||||
|
||||
const util = require("util");
|
||||
const SortableSet = require("./util/SortableSet");
|
||||
const intersect = require("./util/SetHelpers").intersect;
|
||||
const GraphHelpers = require("./GraphHelpers");
|
||||
const Entrypoint = require("./Entrypoint");
|
||||
let debugId = 1000;
|
||||
const ERR_CHUNK_ENTRY = "Chunk.entry was removed. Use hasRuntime()";
|
||||
const ERR_CHUNK_INITIAL =
|
||||
"Chunk.initial was removed. Use canBeInitial/isOnlyInitial()";
|
||||
|
||||
/** @typedef {import("./Module")} Module */
|
||||
/** @typedef {import("./ChunkGroup")} ChunkGroup */
|
||||
/** @typedef {import("./ModuleReason")} ModuleReason */
|
||||
/** @typedef {import("webpack-sources").Source} Source */
|
||||
/** @typedef {import("./util/createHash").Hash} Hash */
|
||||
|
||||
/**
|
||||
* @typedef {Object} WithId an object who has an id property *
|
||||
* @property {string | number} id the id of the object
|
||||
*/
|
||||
|
||||
/**
|
||||
* Compare two Modules based on their ids for sorting
|
||||
* @param {Module} a module
|
||||
* @param {Module} b module
|
||||
* @returns {-1|0|1} sort value
|
||||
*/
|
||||
|
||||
// TODO use @callback
|
||||
/** @typedef {(a: Module, b: Module) => -1|0|1} ModuleSortPredicate */
|
||||
/** @typedef {(m: Module) => boolean} ModuleFilterPredicate */
|
||||
/** @typedef {(c: Chunk) => boolean} ChunkFilterPredicate */
|
||||
|
||||
const sortModuleById = (a, b) => {
|
||||
if (a.id < b.id) return -1;
|
||||
if (b.id < a.id) return 1;
|
||||
return 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* Compare two ChunkGroups based on their ids for sorting
|
||||
* @param {ChunkGroup} a chunk group
|
||||
* @param {ChunkGroup} b chunk group
|
||||
* @returns {-1|0|1} sort value
|
||||
*/
|
||||
const sortChunkGroupById = (a, b) => {
|
||||
if (a.id < b.id) return -1;
|
||||
if (b.id < a.id) return 1;
|
||||
return 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* Compare two Identifiables , based on their ids for sorting
|
||||
* @param {Module} a first object with ident fn
|
||||
* @param {Module} b second object with ident fn
|
||||
* @returns {-1|0|1} The order number of the sort
|
||||
*/
|
||||
const sortByIdentifier = (a, b) => {
|
||||
if (a.identifier() > b.identifier()) return 1;
|
||||
if (a.identifier() < b.identifier()) return -1;
|
||||
return 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* @returns {string} a concatenation of module identifiers sorted
|
||||
* @param {SortableSet} set to pull module identifiers from
|
||||
*/
|
||||
const getModulesIdent = set => {
|
||||
set.sort();
|
||||
let str = "";
|
||||
for (const m of set) {
|
||||
str += m.identifier() + "#";
|
||||
}
|
||||
return str;
|
||||
};
|
||||
|
||||
/**
|
||||
* @template T
|
||||
* @param {SortableSet<T>} set the sortable set to convert to array
|
||||
* @returns {Array<T>} the array returned from Array.from(set)
|
||||
*/
|
||||
const getArray = set => Array.from(set);
|
||||
|
||||
/**
|
||||
* @param {SortableSet<Module>} set the sortable Set to get the count/size of
|
||||
* @returns {number} the size of the modules
|
||||
*/
|
||||
const getModulesSize = set => {
|
||||
let size = 0;
|
||||
for (const module of set) {
|
||||
size += module.size();
|
||||
}
|
||||
return size;
|
||||
};
|
||||
|
||||
/**
|
||||
* A Chunk is a unit of encapsulation for Modules.
|
||||
* Chunks are "rendered" into bundles that get emitted when the build completes.
|
||||
*/
|
||||
class Chunk {
|
||||
/**
|
||||
* @param {string=} name of chunk being created, is optional (for subclasses)
|
||||
*/
|
||||
constructor(name) {
|
||||
/** @type {number | null} */
|
||||
this.id = null;
|
||||
/** @type {number[] | null} */
|
||||
this.ids = null;
|
||||
/** @type {number} */
|
||||
this.debugId = debugId++;
|
||||
/** @type {string} */
|
||||
this.name = name;
|
||||
/** @type {boolean} */
|
||||
this.preventIntegration = false;
|
||||
/** @type {Module=} */
|
||||
this.entryModule = undefined;
|
||||
/** @private @type {SortableSet<Module>} */
|
||||
this._modules = new SortableSet(undefined, sortByIdentifier);
|
||||
/** @type {string?} */
|
||||
this.filenameTemplate = undefined;
|
||||
/** @private @type {SortableSet<ChunkGroup>} */
|
||||
this._groups = new SortableSet(undefined, sortChunkGroupById);
|
||||
/** @type {string[]} */
|
||||
this.files = [];
|
||||
/** @type {boolean} */
|
||||
this.rendered = false;
|
||||
/** @type {string=} */
|
||||
this.hash = undefined;
|
||||
/** @type {Object} */
|
||||
this.contentHash = Object.create(null);
|
||||
/** @type {string=} */
|
||||
this.renderedHash = undefined;
|
||||
/** @type {string=} */
|
||||
this.chunkReason = undefined;
|
||||
/** @type {boolean} */
|
||||
this.extraAsync = false;
|
||||
this.removedModules = undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Chunk.entry has been deprecated. Please use .hasRuntime() instead
|
||||
* @returns {never} Throws an error trying to access this property
|
||||
*/
|
||||
get entry() {
|
||||
throw new Error(ERR_CHUNK_ENTRY);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated .entry has been deprecated. Please use .hasRuntime() instead
|
||||
* @param {never} data The data that was attempting to be set
|
||||
* @returns {never} Throws an error trying to access this property
|
||||
*/
|
||||
set entry(data) {
|
||||
throw new Error(ERR_CHUNK_ENTRY);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Chunk.initial was removed. Use canBeInitial/isOnlyInitial()
|
||||
* @returns {never} Throws an error trying to access this property
|
||||
*/
|
||||
get initial() {
|
||||
throw new Error(ERR_CHUNK_INITIAL);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Chunk.initial was removed. Use canBeInitial/isOnlyInitial()
|
||||
* @param {never} data The data attempting to be set
|
||||
* @returns {never} Throws an error trying to access this property
|
||||
*/
|
||||
set initial(data) {
|
||||
throw new Error(ERR_CHUNK_INITIAL);
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {boolean} whether or not the Chunk will have a runtime
|
||||
*/
|
||||
hasRuntime() {
|
||||
for (const chunkGroup of this._groups) {
|
||||
if (
|
||||
chunkGroup.isInitial() &&
|
||||
chunkGroup instanceof Entrypoint &&
|
||||
chunkGroup.getRuntimeChunk() === this
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {boolean} whether or not this chunk can be an initial chunk
|
||||
*/
|
||||
canBeInitial() {
|
||||
for (const chunkGroup of this._groups) {
|
||||
if (chunkGroup.isInitial()) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {boolean} whether this chunk can only be an initial chunk
|
||||
*/
|
||||
isOnlyInitial() {
|
||||
if (this._groups.size <= 0) return false;
|
||||
for (const chunkGroup of this._groups) {
|
||||
if (!chunkGroup.isInitial()) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {boolean} if this chunk contains the entry module
|
||||
*/
|
||||
hasEntryModule() {
|
||||
return !!this.entryModule;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Module} module the module that will be added to this chunk.
|
||||
* @returns {boolean} returns true if the chunk doesn't have the module and it was added
|
||||
*/
|
||||
addModule(module) {
|
||||
if (!this._modules.has(module)) {
|
||||
this._modules.add(module);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Module} module the module that will be removed from this chunk
|
||||
* @returns {boolean} returns true if chunk exists and is successfully deleted
|
||||
*/
|
||||
removeModule(module) {
|
||||
if (this._modules.delete(module)) {
|
||||
module.removeChunk(this);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Module[]} modules the new modules to be set
|
||||
* @returns {void} set new modules to this chunk and return nothing
|
||||
*/
|
||||
setModules(modules) {
|
||||
this._modules = new SortableSet(modules, sortByIdentifier);
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {number} the amount of modules in chunk
|
||||
*/
|
||||
getNumberOfModules() {
|
||||
return this._modules.size;
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {SortableSet} return the modules SortableSet for this chunk
|
||||
*/
|
||||
get modulesIterable() {
|
||||
return this._modules;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {ChunkGroup} chunkGroup the chunkGroup the chunk is being added
|
||||
* @returns {boolean} returns true if chunk is not apart of chunkGroup and is added successfully
|
||||
*/
|
||||
addGroup(chunkGroup) {
|
||||
if (this._groups.has(chunkGroup)) return false;
|
||||
this._groups.add(chunkGroup);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {ChunkGroup} chunkGroup the chunkGroup the chunk is being removed from
|
||||
* @returns {boolean} returns true if chunk does exist in chunkGroup and is removed
|
||||
*/
|
||||
removeGroup(chunkGroup) {
|
||||
if (!this._groups.has(chunkGroup)) return false;
|
||||
this._groups.delete(chunkGroup);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {ChunkGroup} chunkGroup the chunkGroup to check
|
||||
* @returns {boolean} returns true if chunk has chunkGroup reference and exists in chunkGroup
|
||||
*/
|
||||
isInGroup(chunkGroup) {
|
||||
return this._groups.has(chunkGroup);
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {number} the amount of groups said chunk is in
|
||||
*/
|
||||
getNumberOfGroups() {
|
||||
return this._groups.size;
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {SortableSet<ChunkGroup>} the chunkGroups that said chunk is referenced in
|
||||
*/
|
||||
get groupsIterable() {
|
||||
return this._groups;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Chunk} otherChunk the chunk to compare itself with
|
||||
* @returns {-1|0|1} this is a comparitor function like sort and returns -1, 0, or 1 based on sort order
|
||||
*/
|
||||
compareTo(otherChunk) {
|
||||
if (this.name && !otherChunk.name) return -1;
|
||||
if (!this.name && otherChunk.name) return 1;
|
||||
if (this.name < otherChunk.name) return -1;
|
||||
if (this.name > otherChunk.name) return 1;
|
||||
if (this._modules.size > otherChunk._modules.size) return -1;
|
||||
if (this._modules.size < otherChunk._modules.size) return 1;
|
||||
this._modules.sort();
|
||||
otherChunk._modules.sort();
|
||||
const a = this._modules[Symbol.iterator]();
|
||||
const b = otherChunk._modules[Symbol.iterator]();
|
||||
// eslint-disable-next-line no-constant-condition
|
||||
while (true) {
|
||||
const aItem = a.next();
|
||||
if (aItem.done) return 0;
|
||||
const bItem = b.next();
|
||||
const aModuleIdentifier = aItem.value.identifier();
|
||||
const bModuleIdentifier = bItem.value.identifier();
|
||||
if (aModuleIdentifier < bModuleIdentifier) return -1;
|
||||
if (aModuleIdentifier > bModuleIdentifier) return 1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Module} module Module to check
|
||||
* @returns {boolean} returns true if module does exist in this chunk
|
||||
*/
|
||||
containsModule(module) {
|
||||
return this._modules.has(module);
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {Module[]} an array of modules (do not modify)
|
||||
*/
|
||||
getModules() {
|
||||
return this._modules.getFromCache(getArray);
|
||||
}
|
||||
|
||||
getModulesIdent() {
|
||||
return this._modules.getFromUnorderedCache(getModulesIdent);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string=} reason reason why chunk is removed
|
||||
* @returns {void}
|
||||
*/
|
||||
remove(reason) {
|
||||
// cleanup modules
|
||||
// Array.from is used here to create a clone, because removeChunk modifies this._modules
|
||||
for (const module of Array.from(this._modules)) {
|
||||
module.removeChunk(this);
|
||||
}
|
||||
for (const chunkGroup of this._groups) {
|
||||
chunkGroup.removeChunk(this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {Module} module module to move
|
||||
* @param {Chunk} otherChunk other chunk to move it to
|
||||
* @returns {void}
|
||||
*/
|
||||
moveModule(module, otherChunk) {
|
||||
GraphHelpers.disconnectChunkAndModule(this, module);
|
||||
GraphHelpers.connectChunkAndModule(otherChunk, module);
|
||||
module.rewriteChunkInReasons(this, [otherChunk]);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {Chunk} otherChunk the chunk to integrate with
|
||||
* @param {string} reason reason why the module is being integrated
|
||||
* @returns {boolean} returns true or false if integration succeeds or fails
|
||||
*/
|
||||
integrate(otherChunk, reason) {
|
||||
if (!this.canBeIntegrated(otherChunk)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Pick a new name for the integrated chunk
|
||||
if (this.name && otherChunk.name) {
|
||||
if (this.hasEntryModule() === otherChunk.hasEntryModule()) {
|
||||
// When both chunks have entry modules or none have one, use
|
||||
// shortest name
|
||||
if (this.name.length !== otherChunk.name.length) {
|
||||
this.name =
|
||||
this.name.length < otherChunk.name.length
|
||||
? this.name
|
||||
: otherChunk.name;
|
||||
} else {
|
||||
this.name = this.name < otherChunk.name ? this.name : otherChunk.name;
|
||||
}
|
||||
} else if (otherChunk.hasEntryModule()) {
|
||||
// Pick the name of the chunk with the entry module
|
||||
this.name = otherChunk.name;
|
||||
}
|
||||
} else if (otherChunk.name) {
|
||||
this.name = otherChunk.name;
|
||||
}
|
||||
|
||||
// Array.from is used here to create a clone, because moveModule modifies otherChunk._modules
|
||||
for (const module of Array.from(otherChunk._modules)) {
|
||||
otherChunk.moveModule(module, this);
|
||||
}
|
||||
otherChunk._modules.clear();
|
||||
|
||||
if (otherChunk.entryModule) {
|
||||
this.entryModule = otherChunk.entryModule;
|
||||
}
|
||||
|
||||
for (const chunkGroup of otherChunk._groups) {
|
||||
chunkGroup.replaceChunk(otherChunk, this);
|
||||
this.addGroup(chunkGroup);
|
||||
}
|
||||
otherChunk._groups.clear();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Chunk} newChunk the new chunk that will be split out of the current chunk
|
||||
* @returns {void}
|
||||
*/
|
||||
split(newChunk) {
|
||||
for (const chunkGroup of this._groups) {
|
||||
chunkGroup.insertChunk(newChunk, this);
|
||||
newChunk.addGroup(chunkGroup);
|
||||
}
|
||||
}
|
||||
|
||||
isEmpty() {
|
||||
return this._modules.size === 0;
|
||||
}
|
||||
|
||||
updateHash(hash) {
|
||||
hash.update(`${this.id} `);
|
||||
hash.update(this.ids ? this.ids.join(",") : "");
|
||||
hash.update(`${this.name || ""} `);
|
||||
for (const m of this._modules) {
|
||||
hash.update(m.hash);
|
||||
}
|
||||
}
|
||||
|
||||
canBeIntegrated(otherChunk) {
|
||||
if (this.preventIntegration || otherChunk.preventIntegration) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Chunk} a chunk
|
||||
* @param {Chunk} b chunk
|
||||
* @returns {boolean} true, if a is always available when b is reached
|
||||
*/
|
||||
const isAvailable = (a, b) => {
|
||||
const queue = new Set(b.groupsIterable);
|
||||
for (const chunkGroup of queue) {
|
||||
if (a.isInGroup(chunkGroup)) continue;
|
||||
if (chunkGroup.isInitial()) return false;
|
||||
for (const parent of chunkGroup.parentsIterable) {
|
||||
queue.add(parent);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
const selfHasRuntime = this.hasRuntime();
|
||||
const otherChunkHasRuntime = otherChunk.hasRuntime();
|
||||
|
||||
if (selfHasRuntime !== otherChunkHasRuntime) {
|
||||
if (selfHasRuntime) {
|
||||
return isAvailable(this, otherChunk);
|
||||
} else if (otherChunkHasRuntime) {
|
||||
return isAvailable(otherChunk, this);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.hasEntryModule() || otherChunk.hasEntryModule()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {number} size the size
|
||||
* @param {Object} options the options passed in
|
||||
* @returns {number} the multiplier returned
|
||||
*/
|
||||
addMultiplierAndOverhead(size, options) {
|
||||
const overhead =
|
||||
typeof options.chunkOverhead === "number" ? options.chunkOverhead : 10000;
|
||||
const multiplicator = this.canBeInitial()
|
||||
? options.entryChunkMultiplicator || 10
|
||||
: 1;
|
||||
|
||||
return size * multiplicator + overhead;
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {number} the size of all modules
|
||||
*/
|
||||
modulesSize() {
|
||||
return this._modules.getFromUnorderedCache(getModulesSize);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Object} options the size display options
|
||||
* @returns {number} the chunk size
|
||||
*/
|
||||
size(options = {}) {
|
||||
return this.addMultiplierAndOverhead(this.modulesSize(), options);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Chunk} otherChunk the other chunk
|
||||
* @param {TODO} options the options for this function
|
||||
* @returns {number | false} the size, or false if it can't be integrated
|
||||
*/
|
||||
integratedSize(otherChunk, options) {
|
||||
// Chunk if it's possible to integrate this chunk
|
||||
if (!this.canBeIntegrated(otherChunk)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
let integratedModulesSize = this.modulesSize();
|
||||
// only count modules that do not exist in this chunk!
|
||||
for (const otherModule of otherChunk._modules) {
|
||||
if (!this._modules.has(otherModule)) {
|
||||
integratedModulesSize += otherModule.size();
|
||||
}
|
||||
}
|
||||
|
||||
return this.addMultiplierAndOverhead(integratedModulesSize, options);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {function(Module, Module): -1|0|1=} sortByFn a predicate function used to sort modules
|
||||
* @returns {void}
|
||||
*/
|
||||
sortModules(sortByFn) {
|
||||
this._modules.sortWith(sortByFn || sortModuleById);
|
||||
}
|
||||
|
||||
sortItems() {
|
||||
this.sortModules();
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {Set<Chunk>} a set of all the async chunks
|
||||
*/
|
||||
getAllAsyncChunks() {
|
||||
const queue = new Set();
|
||||
const chunks = new Set();
|
||||
|
||||
const initialChunks = intersect(
|
||||
Array.from(this.groupsIterable, g => new Set(g.chunks))
|
||||
);
|
||||
|
||||
for (const chunkGroup of this.groupsIterable) {
|
||||
for (const child of chunkGroup.childrenIterable) {
|
||||
queue.add(child);
|
||||
}
|
||||
}
|
||||
|
||||
for (const chunkGroup of queue) {
|
||||
for (const chunk of chunkGroup.chunks) {
|
||||
if (!initialChunks.has(chunk)) {
|
||||
chunks.add(chunk);
|
||||
}
|
||||
}
|
||||
for (const child of chunkGroup.childrenIterable) {
|
||||
queue.add(child);
|
||||
}
|
||||
}
|
||||
|
||||
return chunks;
|
||||
}
|
||||
|
||||
/**
|
||||
* @typedef {Object} ChunkMaps
|
||||
* @property {Record<string|number, string>} hash
|
||||
* @property {Record<string|number, Record<string, string>>} contentHash
|
||||
* @property {Record<string|number, string>} name
|
||||
*/
|
||||
|
||||
/**
|
||||
* @param {boolean} realHash should the full hash or the rendered hash be used
|
||||
* @returns {ChunkMaps} the chunk map information
|
||||
*/
|
||||
getChunkMaps(realHash) {
|
||||
/** @type {Record<string|number, string>} */
|
||||
const chunkHashMap = Object.create(null);
|
||||
/** @type {Record<string|number, Record<string, string>>} */
|
||||
const chunkContentHashMap = Object.create(null);
|
||||
/** @type {Record<string|number, string>} */
|
||||
const chunkNameMap = Object.create(null);
|
||||
|
||||
for (const chunk of this.getAllAsyncChunks()) {
|
||||
chunkHashMap[chunk.id] = realHash ? chunk.hash : chunk.renderedHash;
|
||||
for (const key of Object.keys(chunk.contentHash)) {
|
||||
if (!chunkContentHashMap[key]) {
|
||||
chunkContentHashMap[key] = Object.create(null);
|
||||
}
|
||||
chunkContentHashMap[key][chunk.id] = chunk.contentHash[key];
|
||||
}
|
||||
if (chunk.name) {
|
||||
chunkNameMap[chunk.id] = chunk.name;
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
hash: chunkHashMap,
|
||||
contentHash: chunkContentHashMap,
|
||||
name: chunkNameMap
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {Record<string, Set<TODO>[]>} a record object of names to lists of child ids(?)
|
||||
*/
|
||||
getChildIdsByOrders() {
|
||||
const lists = new Map();
|
||||
for (const group of this.groupsIterable) {
|
||||
if (group.chunks[group.chunks.length - 1] === this) {
|
||||
for (const childGroup of group.childrenIterable) {
|
||||
// TODO webpack 5 remove this check for options
|
||||
if (typeof childGroup.options === "object") {
|
||||
for (const key of Object.keys(childGroup.options)) {
|
||||
if (key.endsWith("Order")) {
|
||||
const name = key.substr(0, key.length - "Order".length);
|
||||
let list = lists.get(name);
|
||||
if (list === undefined) lists.set(name, (list = []));
|
||||
list.push({
|
||||
order: childGroup.options[key],
|
||||
group: childGroup
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
const result = Object.create(null);
|
||||
for (const [name, list] of lists) {
|
||||
list.sort((a, b) => {
|
||||
const cmp = b.order - a.order;
|
||||
if (cmp !== 0) return cmp;
|
||||
// TODO webpack 5 remove this check of compareTo
|
||||
if (a.group.compareTo) {
|
||||
return a.group.compareTo(b.group);
|
||||
}
|
||||
return 0;
|
||||
});
|
||||
result[name] = Array.from(
|
||||
list.reduce((set, item) => {
|
||||
for (const chunk of item.group.chunks) {
|
||||
set.add(chunk.id);
|
||||
}
|
||||
return set;
|
||||
}, new Set())
|
||||
);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
getChildIdsByOrdersMap(includeDirectChildren) {
|
||||
const chunkMaps = Object.create(null);
|
||||
|
||||
const addChildIdsByOrdersToMap = chunk => {
|
||||
const data = chunk.getChildIdsByOrders();
|
||||
for (const key of Object.keys(data)) {
|
||||
let chunkMap = chunkMaps[key];
|
||||
if (chunkMap === undefined) {
|
||||
chunkMaps[key] = chunkMap = Object.create(null);
|
||||
}
|
||||
chunkMap[chunk.id] = data[key];
|
||||
}
|
||||
};
|
||||
|
||||
if (includeDirectChildren) {
|
||||
const chunks = new Set();
|
||||
for (const chunkGroup of this.groupsIterable) {
|
||||
for (const chunk of chunkGroup.chunks) {
|
||||
chunks.add(chunk);
|
||||
}
|
||||
}
|
||||
for (const chunk of chunks) {
|
||||
addChildIdsByOrdersToMap(chunk);
|
||||
}
|
||||
}
|
||||
|
||||
for (const chunk of this.getAllAsyncChunks()) {
|
||||
addChildIdsByOrdersToMap(chunk);
|
||||
}
|
||||
|
||||
return chunkMaps;
|
||||
}
|
||||
|
||||
/**
|
||||
* @typedef {Object} ChunkModuleMaps
|
||||
* @property {Record<string|number, (string|number)[]>} id
|
||||
* @property {Record<string|number, string>} hash
|
||||
*/
|
||||
|
||||
/**
|
||||
* @param {ModuleFilterPredicate} filterFn function used to filter modules
|
||||
* @returns {ChunkModuleMaps} module map information
|
||||
*/
|
||||
getChunkModuleMaps(filterFn) {
|
||||
/** @type {Record<string|number, (string|number)[]>} */
|
||||
const chunkModuleIdMap = Object.create(null);
|
||||
/** @type {Record<string|number, string>} */
|
||||
const chunkModuleHashMap = Object.create(null);
|
||||
|
||||
for (const chunk of this.getAllAsyncChunks()) {
|
||||
/** @type {(string|number)[]} */
|
||||
let array;
|
||||
for (const module of chunk.modulesIterable) {
|
||||
if (filterFn(module)) {
|
||||
if (array === undefined) {
|
||||
array = [];
|
||||
chunkModuleIdMap[chunk.id] = array;
|
||||
}
|
||||
array.push(module.id);
|
||||
chunkModuleHashMap[module.id] = module.renderedHash;
|
||||
}
|
||||
}
|
||||
if (array !== undefined) {
|
||||
array.sort();
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
id: chunkModuleIdMap,
|
||||
hash: chunkModuleHashMap
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {function(Module): boolean} filterFn predicate function used to filter modules
|
||||
* @param {function(Chunk): boolean} filterChunkFn predicate function used to filter chunks
|
||||
* @returns {boolean} return true if module exists in graph
|
||||
*/
|
||||
hasModuleInGraph(filterFn, filterChunkFn) {
|
||||
const queue = new Set(this.groupsIterable);
|
||||
const chunksProcessed = new Set();
|
||||
|
||||
for (const chunkGroup of queue) {
|
||||
for (const chunk of chunkGroup.chunks) {
|
||||
if (!chunksProcessed.has(chunk)) {
|
||||
chunksProcessed.add(chunk);
|
||||
if (!filterChunkFn || filterChunkFn(chunk)) {
|
||||
for (const module of chunk.modulesIterable) {
|
||||
if (filterFn(module)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for (const child of chunkGroup.childrenIterable) {
|
||||
queue.add(child);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
toString() {
|
||||
return `Chunk[${Array.from(this._modules).join()}]`;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO remove in webpack 5
|
||||
Object.defineProperty(Chunk.prototype, "forEachModule", {
|
||||
configurable: false,
|
||||
value: util.deprecate(
|
||||
/**
|
||||
* @deprecated
|
||||
* @this {Chunk}
|
||||
* @typedef {function(any, any, Set<any>): void} ForEachModuleCallback
|
||||
* @param {ForEachModuleCallback} fn Callback function
|
||||
* @returns {void}
|
||||
*/
|
||||
function(fn) {
|
||||
this._modules.forEach(fn);
|
||||
},
|
||||
"Chunk.forEachModule: Use for(const module of chunk.modulesIterable) instead"
|
||||
)
|
||||
});
|
||||
|
||||
// TODO remove in webpack 5
|
||||
Object.defineProperty(Chunk.prototype, "mapModules", {
|
||||
configurable: false,
|
||||
value: util.deprecate(
|
||||
/**
|
||||
* @deprecated
|
||||
* @this {Chunk}
|
||||
* @typedef {function(any, number): any} MapModulesCallback
|
||||
* @param {MapModulesCallback} fn Callback function
|
||||
* @returns {TODO[]} result of mapped modules
|
||||
*/
|
||||
function(fn) {
|
||||
return Array.from(this._modules, fn);
|
||||
},
|
||||
"Chunk.mapModules: Use Array.from(chunk.modulesIterable, fn) instead"
|
||||
)
|
||||
});
|
||||
|
||||
// TODO remove in webpack 5
|
||||
Object.defineProperty(Chunk.prototype, "chunks", {
|
||||
configurable: false,
|
||||
get() {
|
||||
throw new Error("Chunk.chunks: Use ChunkGroup.getChildren() instead");
|
||||
},
|
||||
set() {
|
||||
throw new Error("Chunk.chunks: Use ChunkGroup.add/removeChild() instead");
|
||||
}
|
||||
});
|
||||
|
||||
// TODO remove in webpack 5
|
||||
Object.defineProperty(Chunk.prototype, "parents", {
|
||||
configurable: false,
|
||||
get() {
|
||||
throw new Error("Chunk.parents: Use ChunkGroup.getParents() instead");
|
||||
},
|
||||
set() {
|
||||
throw new Error("Chunk.parents: Use ChunkGroup.add/removeParent() instead");
|
||||
}
|
||||
});
|
||||
|
||||
// TODO remove in webpack 5
|
||||
Object.defineProperty(Chunk.prototype, "blocks", {
|
||||
configurable: false,
|
||||
get() {
|
||||
throw new Error("Chunk.blocks: Use ChunkGroup.getBlocks() instead");
|
||||
},
|
||||
set() {
|
||||
throw new Error("Chunk.blocks: Use ChunkGroup.add/removeBlock() instead");
|
||||
}
|
||||
});
|
||||
|
||||
// TODO remove in webpack 5
|
||||
Object.defineProperty(Chunk.prototype, "entrypoints", {
|
||||
configurable: false,
|
||||
get() {
|
||||
throw new Error(
|
||||
"Chunk.entrypoints: Use Chunks.groupsIterable and filter by instanceof Entrypoint instead"
|
||||
);
|
||||
},
|
||||
set() {
|
||||
throw new Error("Chunk.entrypoints: Use Chunks.addGroup instead");
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = Chunk;
|
||||
513
node_modules/webpack/lib/ChunkGroup.js
generated
vendored
Normal file
513
node_modules/webpack/lib/ChunkGroup.js
generated
vendored
Normal file
|
|
@ -0,0 +1,513 @@
|
|||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
"use strict";
|
||||
|
||||
const SortableSet = require("./util/SortableSet");
|
||||
const compareLocations = require("./compareLocations");
|
||||
|
||||
/** @typedef {import("./Chunk")} Chunk */
|
||||
/** @typedef {import("./Module")} Module */
|
||||
/** @typedef {import("./ModuleReason")} ModuleReason */
|
||||
|
||||
/** @typedef {{module: Module, loc: TODO, request: string}} OriginRecord */
|
||||
/** @typedef {string|{name: string}} ChunkGroupOptions */
|
||||
|
||||
let debugId = 5000;
|
||||
|
||||
/**
|
||||
* @template T
|
||||
* @param {SortableSet<T>} set set to convert to array.
|
||||
* @returns {T[]} the array format of existing set
|
||||
*/
|
||||
const getArray = set => Array.from(set);
|
||||
|
||||
/**
|
||||
* A convenience method used to sort chunks based on their id's
|
||||
* @param {ChunkGroup} a first sorting comparator
|
||||
* @param {ChunkGroup} b second sorting comparator
|
||||
* @returns {1|0|-1} a sorting index to determine order
|
||||
*/
|
||||
const sortById = (a, b) => {
|
||||
if (a.id < b.id) return -1;
|
||||
if (b.id < a.id) return 1;
|
||||
return 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {OriginRecord} a the first comparator in sort
|
||||
* @param {OriginRecord} b the second comparator in sort
|
||||
* @returns {1|-1|0} returns sorting order as index
|
||||
*/
|
||||
const sortOrigin = (a, b) => {
|
||||
const aIdent = a.module ? a.module.identifier() : "";
|
||||
const bIdent = b.module ? b.module.identifier() : "";
|
||||
if (aIdent < bIdent) return -1;
|
||||
if (aIdent > bIdent) return 1;
|
||||
return compareLocations(a.loc, b.loc);
|
||||
};
|
||||
|
||||
class ChunkGroup {
|
||||
/**
|
||||
* Creates an instance of ChunkGroup.
|
||||
* @param {ChunkGroupOptions=} options chunk group options passed to chunkGroup
|
||||
*/
|
||||
constructor(options) {
|
||||
if (typeof options === "string") {
|
||||
options = { name: options };
|
||||
} else if (!options) {
|
||||
options = { name: undefined };
|
||||
}
|
||||
/** @type {number} */
|
||||
this.groupDebugId = debugId++;
|
||||
this.options = options;
|
||||
/** @type {SortableSet<ChunkGroup>} */
|
||||
this._children = new SortableSet(undefined, sortById);
|
||||
this._parents = new SortableSet(undefined, sortById);
|
||||
this._blocks = new SortableSet();
|
||||
/** @type {Chunk[]} */
|
||||
this.chunks = [];
|
||||
/** @type {OriginRecord[]} */
|
||||
this.origins = [];
|
||||
/** Indices in top-down order */
|
||||
/** @private @type {Map<Module, number>} */
|
||||
this._moduleIndices = new Map();
|
||||
/** Indices in bottom-up order */
|
||||
/** @private @type {Map<Module, number>} */
|
||||
this._moduleIndices2 = new Map();
|
||||
}
|
||||
|
||||
/**
|
||||
* when a new chunk is added to a chunkGroup, addingOptions will occur.
|
||||
* @param {ChunkGroupOptions} options the chunkGroup options passed to addOptions
|
||||
* @returns {void}
|
||||
*/
|
||||
addOptions(options) {
|
||||
for (const key of Object.keys(options)) {
|
||||
if (this.options[key] === undefined) {
|
||||
this.options[key] = options[key];
|
||||
} else if (this.options[key] !== options[key]) {
|
||||
if (key.endsWith("Order")) {
|
||||
this.options[key] = Math.max(this.options[key], options[key]);
|
||||
} else {
|
||||
throw new Error(
|
||||
`ChunkGroup.addOptions: No option merge strategy for ${key}`
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the name of current ChunkGroup
|
||||
* @returns {string|undefined} returns the ChunkGroup name
|
||||
*/
|
||||
get name() {
|
||||
return this.options.name;
|
||||
}
|
||||
|
||||
/**
|
||||
* sets a new name for current ChunkGroup
|
||||
* @param {string} value the new name for ChunkGroup
|
||||
* @returns {void}
|
||||
*/
|
||||
set name(value) {
|
||||
this.options.name = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* get a uniqueId for ChunkGroup, made up of its member Chunk debugId's
|
||||
* @returns {string} a unique concatenation of chunk debugId's
|
||||
*/
|
||||
get debugId() {
|
||||
return Array.from(this.chunks, x => x.debugId).join("+");
|
||||
}
|
||||
|
||||
/**
|
||||
* get a unique id for ChunkGroup, made up of its member Chunk id's
|
||||
* @returns {string} a unique concatenation of chunk ids
|
||||
*/
|
||||
get id() {
|
||||
return Array.from(this.chunks, x => x.id).join("+");
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs an unshift of a specific chunk
|
||||
* @param {Chunk} chunk chunk being unshifted
|
||||
* @returns {boolean} returns true if attempted chunk shift is accepted
|
||||
*/
|
||||
unshiftChunk(chunk) {
|
||||
const oldIdx = this.chunks.indexOf(chunk);
|
||||
if (oldIdx > 0) {
|
||||
this.chunks.splice(oldIdx, 1);
|
||||
this.chunks.unshift(chunk);
|
||||
} else if (oldIdx < 0) {
|
||||
this.chunks.unshift(chunk);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* inserts a chunk before another existing chunk in group
|
||||
* @param {Chunk} chunk Chunk being inserted
|
||||
* @param {Chunk} before Placeholder/target chunk marking new chunk insertion point
|
||||
* @returns {boolean} return true if insertion was successful
|
||||
*/
|
||||
insertChunk(chunk, before) {
|
||||
const oldIdx = this.chunks.indexOf(chunk);
|
||||
const idx = this.chunks.indexOf(before);
|
||||
if (idx < 0) {
|
||||
throw new Error("before chunk not found");
|
||||
}
|
||||
if (oldIdx >= 0 && oldIdx > idx) {
|
||||
this.chunks.splice(oldIdx, 1);
|
||||
this.chunks.splice(idx, 0, chunk);
|
||||
} else if (oldIdx < 0) {
|
||||
this.chunks.splice(idx, 0, chunk);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* add a chunk into ChunkGroup. Is pushed on or prepended
|
||||
* @param {Chunk} chunk chunk being pushed into ChunkGroupS
|
||||
* @returns {boolean} returns true if chunk addition was successful.
|
||||
*/
|
||||
pushChunk(chunk) {
|
||||
const oldIdx = this.chunks.indexOf(chunk);
|
||||
if (oldIdx >= 0) {
|
||||
return false;
|
||||
}
|
||||
this.chunks.push(chunk);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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) {
|
||||
const oldIdx = this.chunks.indexOf(oldChunk);
|
||||
if (oldIdx < 0) return false;
|
||||
const newIdx = this.chunks.indexOf(newChunk);
|
||||
if (newIdx < 0) {
|
||||
this.chunks[oldIdx] = newChunk;
|
||||
return true;
|
||||
}
|
||||
if (newIdx < oldIdx) {
|
||||
this.chunks.splice(oldIdx, 1);
|
||||
return true;
|
||||
} else if (newIdx !== oldIdx) {
|
||||
this.chunks[oldIdx] = newChunk;
|
||||
this.chunks.splice(newIdx, 1);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
removeChunk(chunk) {
|
||||
const idx = this.chunks.indexOf(chunk);
|
||||
if (idx >= 0) {
|
||||
this.chunks.splice(idx, 1);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
isInitial() {
|
||||
return false;
|
||||
}
|
||||
|
||||
addChild(chunk) {
|
||||
if (this._children.has(chunk)) {
|
||||
return false;
|
||||
}
|
||||
this._children.add(chunk);
|
||||
return true;
|
||||
}
|
||||
|
||||
getChildren() {
|
||||
return this._children.getFromCache(getArray);
|
||||
}
|
||||
|
||||
getNumberOfChildren() {
|
||||
return this._children.size;
|
||||
}
|
||||
|
||||
get childrenIterable() {
|
||||
return this._children;
|
||||
}
|
||||
|
||||
removeChild(chunk) {
|
||||
if (!this._children.has(chunk)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this._children.delete(chunk);
|
||||
chunk.removeParent(this);
|
||||
return true;
|
||||
}
|
||||
|
||||
addParent(parentChunk) {
|
||||
if (!this._parents.has(parentChunk)) {
|
||||
this._parents.add(parentChunk);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
getParents() {
|
||||
return this._parents.getFromCache(getArray);
|
||||
}
|
||||
|
||||
setParents(newParents) {
|
||||
this._parents.clear();
|
||||
for (const p of newParents) {
|
||||
this._parents.add(p);
|
||||
}
|
||||
}
|
||||
|
||||
getNumberOfParents() {
|
||||
return this._parents.size;
|
||||
}
|
||||
|
||||
hasParent(parent) {
|
||||
return this._parents.has(parent);
|
||||
}
|
||||
|
||||
get parentsIterable() {
|
||||
return this._parents;
|
||||
}
|
||||
|
||||
removeParent(chunk) {
|
||||
if (this._parents.delete(chunk)) {
|
||||
chunk.removeChunk(this);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {Array} - an array containing the blocks
|
||||
*/
|
||||
getBlocks() {
|
||||
return this._blocks.getFromCache(getArray);
|
||||
}
|
||||
|
||||
getNumberOfBlocks() {
|
||||
return this._blocks.size;
|
||||
}
|
||||
|
||||
hasBlock(block) {
|
||||
return this._blocks.has(block);
|
||||
}
|
||||
|
||||
get blocksIterable() {
|
||||
return this._blocks;
|
||||
}
|
||||
|
||||
addBlock(block) {
|
||||
if (!this._blocks.has(block)) {
|
||||
this._blocks.add(block);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
addOrigin(module, loc, request) {
|
||||
this.origins.push({
|
||||
module,
|
||||
loc,
|
||||
request
|
||||
});
|
||||
}
|
||||
|
||||
containsModule(module) {
|
||||
for (const chunk of this.chunks) {
|
||||
if (chunk.containsModule(module)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
getFiles() {
|
||||
const files = new Set();
|
||||
|
||||
for (const chunk of this.chunks) {
|
||||
for (const file of chunk.files) {
|
||||
files.add(file);
|
||||
}
|
||||
}
|
||||
|
||||
return Array.from(files);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string=} reason reason for removing ChunkGroup
|
||||
* @returns {void}
|
||||
*/
|
||||
remove(reason) {
|
||||
// cleanup parents
|
||||
for (const parentChunkGroup of this._parents) {
|
||||
// remove this chunk from its parents
|
||||
parentChunkGroup._children.delete(this);
|
||||
|
||||
// cleanup "sub chunks"
|
||||
for (const chunkGroup of this._children) {
|
||||
/**
|
||||
* remove this chunk as "intermediary" and connect
|
||||
* it "sub chunks" and parents directly
|
||||
*/
|
||||
// add parent to each "sub chunk"
|
||||
chunkGroup.addParent(parentChunkGroup);
|
||||
// add "sub chunk" to parent
|
||||
parentChunkGroup.addChild(chunkGroup);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* we need to iterate again over the children
|
||||
* to remove this from the child's parents.
|
||||
* This can not be done in the above loop
|
||||
* as it is not guaranteed that `this._parents` contains anything.
|
||||
*/
|
||||
for (const chunkGroup of this._children) {
|
||||
// remove this as parent of every "sub chunk"
|
||||
chunkGroup._parents.delete(this);
|
||||
}
|
||||
|
||||
// cleanup blocks
|
||||
for (const block of this._blocks) {
|
||||
block.chunkGroup = null;
|
||||
}
|
||||
|
||||
// remove chunks
|
||||
for (const chunk of this.chunks) {
|
||||
chunk.removeGroup(this);
|
||||
}
|
||||
}
|
||||
|
||||
sortItems() {
|
||||
this.origins.sort(sortOrigin);
|
||||
this._parents.sort();
|
||||
this._children.sort();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorting predicate which allows current ChunkGroup to be compared against another.
|
||||
* Sorting values are based off of number of chunks in ChunkGroup.
|
||||
*
|
||||
* @param {ChunkGroup} otherGroup the chunkGroup to compare this against
|
||||
* @returns {-1|0|1} sort position for comparison
|
||||
*/
|
||||
compareTo(otherGroup) {
|
||||
if (this.chunks.length > otherGroup.chunks.length) return -1;
|
||||
if (this.chunks.length < otherGroup.chunks.length) return 1;
|
||||
const a = this.chunks[Symbol.iterator]();
|
||||
const b = otherGroup.chunks[Symbol.iterator]();
|
||||
// eslint-disable-next-line no-constant-condition
|
||||
while (true) {
|
||||
const aItem = a.next();
|
||||
const bItem = b.next();
|
||||
if (aItem.done) return 0;
|
||||
const cmp = aItem.value.compareTo(bItem.value);
|
||||
if (cmp !== 0) return cmp;
|
||||
}
|
||||
}
|
||||
|
||||
getChildrenByOrders() {
|
||||
const lists = new Map();
|
||||
for (const childGroup of this._children) {
|
||||
// TODO webpack 5 remove this check for options
|
||||
if (typeof childGroup.options === "object") {
|
||||
for (const key of Object.keys(childGroup.options)) {
|
||||
if (key.endsWith("Order")) {
|
||||
const name = key.substr(0, key.length - "Order".length);
|
||||
let list = lists.get(name);
|
||||
if (list === undefined) {
|
||||
lists.set(name, (list = []));
|
||||
}
|
||||
list.push({
|
||||
order: childGroup.options[key],
|
||||
group: childGroup
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
const result = Object.create(null);
|
||||
for (const [name, list] of lists) {
|
||||
list.sort((a, b) => {
|
||||
const cmp = b.order - a.order;
|
||||
if (cmp !== 0) return cmp;
|
||||
// TODO webpack 5 remove this check of compareTo
|
||||
if (a.group.compareTo) {
|
||||
return a.group.compareTo(b.group);
|
||||
}
|
||||
return 0;
|
||||
});
|
||||
result[name] = list.map(i => i.group);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the top-down index of a module in this ChunkGroup
|
||||
* @param {Module} module module for which the index should be set
|
||||
* @param {number} index the index of the module
|
||||
* @returns {void}
|
||||
*/
|
||||
setModuleIndex(module, index) {
|
||||
this._moduleIndices.set(module, index);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the top-down index of a module in this ChunkGroup
|
||||
* @param {Module} module the module
|
||||
* @returns {number} index
|
||||
*/
|
||||
getModuleIndex(module) {
|
||||
return this._moduleIndices.get(module);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the bottom-up index of a module in this ChunkGroup
|
||||
* @param {Module} module module for which the index should be set
|
||||
* @param {number} index the index of the module
|
||||
* @returns {void}
|
||||
*/
|
||||
setModuleIndex2(module, index) {
|
||||
this._moduleIndices2.set(module, index);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the bottom-up index of a module in this ChunkGroup
|
||||
* @param {Module} module the module
|
||||
* @returns {number} index
|
||||
*/
|
||||
getModuleIndex2(module) {
|
||||
return this._moduleIndices2.get(module);
|
||||
}
|
||||
|
||||
checkConstraints() {
|
||||
const chunk = this;
|
||||
for (const child of chunk._children) {
|
||||
if (!child._parents.has(chunk)) {
|
||||
throw new Error(
|
||||
`checkConstraints: child missing parent ${chunk.debugId} -> ${child.debugId}`
|
||||
);
|
||||
}
|
||||
}
|
||||
for (const parentChunk of chunk._parents) {
|
||||
if (!parentChunk._children.has(chunk)) {
|
||||
throw new Error(
|
||||
`checkConstraints: parent missing child ${parentChunk.debugId} <- ${chunk.debugId}`
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ChunkGroup;
|
||||
32
node_modules/webpack/lib/ChunkRenderError.js
generated
vendored
Normal file
32
node_modules/webpack/lib/ChunkRenderError.js
generated
vendored
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
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;
|
||||
|
||||
Error.captureStackTrace(this, this.constructor);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ChunkRenderError;
|
||||
87
node_modules/webpack/lib/ChunkTemplate.js
generated
vendored
Normal file
87
node_modules/webpack/lib/ChunkTemplate.js
generated
vendored
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
"use strict";
|
||||
|
||||
const { Tapable, SyncWaterfallHook, SyncHook } = require("tapable");
|
||||
|
||||
/** @typedef {import("./ModuleTemplate")} ModuleTemplate */
|
||||
/** @typedef {import("./Chunk")} Chunk */
|
||||
/** @typedef {import("./Module")} Module} */
|
||||
/** @typedef {import("./Dependency").DependencyTemplate} DependencyTemplate} */
|
||||
/** @typedef {import("./util/createHash").Hash} Hash} */
|
||||
|
||||
/**
|
||||
* @typedef {Object} RenderManifestOptions
|
||||
* @property {Chunk} chunk the chunk used to render
|
||||
* @property {string} hash
|
||||
* @property {string} fullHash
|
||||
* @property {TODO} outputOptions
|
||||
* @property {{javascript: ModuleTemplate, webassembly: ModuleTemplate}} moduleTemplates
|
||||
* @property {Map<TODO, TODO>} dependencyTemplates
|
||||
*/
|
||||
|
||||
module.exports = class ChunkTemplate extends Tapable {
|
||||
constructor(outputOptions) {
|
||||
super();
|
||||
this.outputOptions = outputOptions || {};
|
||||
this.hooks = {
|
||||
/** @type {SyncWaterfallHook<TODO[], RenderManifestOptions>} */
|
||||
renderManifest: new SyncWaterfallHook(["result", "options"]),
|
||||
modules: new SyncWaterfallHook([
|
||||
"source",
|
||||
"chunk",
|
||||
"moduleTemplate",
|
||||
"dependencyTemplates"
|
||||
]),
|
||||
render: new SyncWaterfallHook([
|
||||
"source",
|
||||
"chunk",
|
||||
"moduleTemplate",
|
||||
"dependencyTemplates"
|
||||
]),
|
||||
renderWithEntry: new SyncWaterfallHook(["source", "chunk"]),
|
||||
hash: new SyncHook(["hash"]),
|
||||
hashForChunk: new SyncHook(["hash", "chunk"])
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {RenderManifestOptions} options render manifest options
|
||||
* @returns {TODO[]} returns render manifest
|
||||
*/
|
||||
getRenderManifest(options) {
|
||||
const result = [];
|
||||
|
||||
this.hooks.renderManifest.call(result, options);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates hash with information from this template
|
||||
* @param {Hash} hash the hash to update
|
||||
* @returns {void}
|
||||
*/
|
||||
updateHash(hash) {
|
||||
hash.update("ChunkTemplate");
|
||||
hash.update("2");
|
||||
this.hooks.hash.call(hash);
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO webpack 5: remove moduleTemplate and dependencyTemplates
|
||||
* Updates hash with chunk-specific information from this template
|
||||
* @param {Hash} hash the hash to update
|
||||
* @param {Chunk} chunk the chunk
|
||||
* @param {ModuleTemplate} moduleTemplate ModuleTemplate instance for render
|
||||
* @param {Map<Function, DependencyTemplate>} dependencyTemplates dependency templates
|
||||
* @returns {void}
|
||||
*/
|
||||
updateHashForChunk(hash, chunk, moduleTemplate, dependencyTemplates) {
|
||||
this.updateHash(hash);
|
||||
this.hooks.hashForChunk.call(hash, chunk);
|
||||
}
|
||||
};
|
||||
32
node_modules/webpack/lib/CommentCompilationWarning.js
generated
vendored
Normal file
32
node_modules/webpack/lib/CommentCompilationWarning.js
generated
vendored
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
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("./Dependency").DependencyLocation} DependencyLocation */
|
||||
|
||||
class CommentCompilationWarning extends WebpackError {
|
||||
/**
|
||||
*
|
||||
* @param {string} message warning message
|
||||
* @param {Module} module affected module
|
||||
* @param {DependencyLocation} loc affected lines of code
|
||||
*/
|
||||
constructor(message, module, loc) {
|
||||
super(message);
|
||||
|
||||
this.name = "CommentCompilationWarning";
|
||||
|
||||
this.module = module;
|
||||
this.loc = loc;
|
||||
|
||||
Error.captureStackTrace(this, this.constructor);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = CommentCompilationWarning;
|
||||
116
node_modules/webpack/lib/CommonJsStuffPlugin.js
generated
vendored
Normal file
116
node_modules/webpack/lib/CommonJsStuffPlugin.js
generated
vendored
Normal file
|
|
@ -0,0 +1,116 @@
|
|||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
"use strict";
|
||||
|
||||
const path = require("path");
|
||||
const ParserHelpers = require("./ParserHelpers");
|
||||
|
||||
class CommonJsStuffPlugin {
|
||||
apply(compiler) {
|
||||
compiler.hooks.compilation.tap(
|
||||
"CommonJsStuffPlugin",
|
||||
(compilation, { normalModuleFactory }) => {
|
||||
const handler = (parser, parserOptions) => {
|
||||
parser.hooks.expression
|
||||
.for("require.main.require")
|
||||
.tap(
|
||||
"CommonJsStuffPlugin",
|
||||
ParserHelpers.expressionIsUnsupported(
|
||||
parser,
|
||||
"require.main.require is not supported by webpack."
|
||||
)
|
||||
);
|
||||
parser.hooks.expression
|
||||
.for("module.parent.require")
|
||||
.tap(
|
||||
"CommonJsStuffPlugin",
|
||||
ParserHelpers.expressionIsUnsupported(
|
||||
parser,
|
||||
"module.parent.require is not supported by webpack."
|
||||
)
|
||||
);
|
||||
parser.hooks.expression
|
||||
.for("require.main")
|
||||
.tap(
|
||||
"CommonJsStuffPlugin",
|
||||
ParserHelpers.toConstantDependencyWithWebpackRequire(
|
||||
parser,
|
||||
"__webpack_require__.c[__webpack_require__.s]"
|
||||
)
|
||||
);
|
||||
parser.hooks.expression
|
||||
.for("module.loaded")
|
||||
.tap("CommonJsStuffPlugin", expr => {
|
||||
parser.state.module.buildMeta.moduleConcatenationBailout =
|
||||
"module.loaded";
|
||||
return ParserHelpers.toConstantDependency(
|
||||
parser,
|
||||
"module.l"
|
||||
)(expr);
|
||||
});
|
||||
parser.hooks.expression
|
||||
.for("module.id")
|
||||
.tap("CommonJsStuffPlugin", expr => {
|
||||
parser.state.module.buildMeta.moduleConcatenationBailout =
|
||||
"module.id";
|
||||
return ParserHelpers.toConstantDependency(
|
||||
parser,
|
||||
"module.i"
|
||||
)(expr);
|
||||
});
|
||||
parser.hooks.expression
|
||||
.for("module.exports")
|
||||
.tap("CommonJsStuffPlugin", () => {
|
||||
const module = parser.state.module;
|
||||
const isHarmony =
|
||||
module.buildMeta && module.buildMeta.exportsType;
|
||||
if (!isHarmony) return true;
|
||||
});
|
||||
parser.hooks.evaluateIdentifier
|
||||
.for("module.hot")
|
||||
.tap(
|
||||
"CommonJsStuffPlugin",
|
||||
ParserHelpers.evaluateToIdentifier("module.hot", false)
|
||||
);
|
||||
parser.hooks.expression
|
||||
.for("module")
|
||||
.tap("CommonJsStuffPlugin", () => {
|
||||
const module = parser.state.module;
|
||||
const isHarmony =
|
||||
module.buildMeta && module.buildMeta.exportsType;
|
||||
let moduleJsPath = path.join(
|
||||
__dirname,
|
||||
"..",
|
||||
"buildin",
|
||||
isHarmony ? "harmony-module.js" : "module.js"
|
||||
);
|
||||
if (module.context) {
|
||||
moduleJsPath = path.relative(
|
||||
parser.state.module.context,
|
||||
moduleJsPath
|
||||
);
|
||||
if (!/^[A-Z]:/i.test(moduleJsPath)) {
|
||||
moduleJsPath = `./${moduleJsPath.replace(/\\/g, "/")}`;
|
||||
}
|
||||
}
|
||||
return ParserHelpers.addParsedVariableToModule(
|
||||
parser,
|
||||
"module",
|
||||
`require(${JSON.stringify(moduleJsPath)})(module)`
|
||||
);
|
||||
});
|
||||
};
|
||||
|
||||
normalModuleFactory.hooks.parser
|
||||
.for("javascript/auto")
|
||||
.tap("CommonJsStuffPlugin", handler);
|
||||
normalModuleFactory.hooks.parser
|
||||
.for("javascript/dynamic")
|
||||
.tap("CommonJsStuffPlugin", handler);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
module.exports = CommonJsStuffPlugin;
|
||||
70
node_modules/webpack/lib/CompatibilityPlugin.js
generated
vendored
Normal file
70
node_modules/webpack/lib/CompatibilityPlugin.js
generated
vendored
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
"use strict";
|
||||
|
||||
const ConstDependency = require("./dependencies/ConstDependency");
|
||||
|
||||
const NullFactory = require("./NullFactory");
|
||||
|
||||
/** @typedef {import("./Compiler")} Compiler */
|
||||
|
||||
class CompatibilityPlugin {
|
||||
/**
|
||||
* Apply the plugin
|
||||
* @param {Compiler} compiler Webpack Compiler
|
||||
* @returns {void}
|
||||
*/
|
||||
apply(compiler) {
|
||||
compiler.hooks.compilation.tap(
|
||||
"CompatibilityPlugin",
|
||||
(compilation, { normalModuleFactory }) => {
|
||||
compilation.dependencyFactories.set(ConstDependency, new NullFactory());
|
||||
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 > 1) {
|
||||
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.current.addDependency(dep);
|
||||
return true;
|
||||
});
|
||||
});
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
module.exports = CompatibilityPlugin;
|
||||
2327
node_modules/webpack/lib/Compilation.js
generated
vendored
Normal file
2327
node_modules/webpack/lib/Compilation.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load diff
735
node_modules/webpack/lib/Compiler.js
generated
vendored
Normal file
735
node_modules/webpack/lib/Compiler.js
generated
vendored
Normal file
|
|
@ -0,0 +1,735 @@
|
|||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
"use strict";
|
||||
|
||||
const parseJson = require("json-parse-better-errors");
|
||||
const asyncLib = require("neo-async");
|
||||
const path = require("path");
|
||||
const { Source } = require("webpack-sources");
|
||||
const util = require("util");
|
||||
const {
|
||||
Tapable,
|
||||
SyncHook,
|
||||
SyncBailHook,
|
||||
AsyncParallelHook,
|
||||
AsyncSeriesHook
|
||||
} = require("tapable");
|
||||
|
||||
const Compilation = require("./Compilation");
|
||||
const Stats = require("./Stats");
|
||||
const Watching = require("./Watching");
|
||||
const NormalModuleFactory = require("./NormalModuleFactory");
|
||||
const ContextModuleFactory = require("./ContextModuleFactory");
|
||||
const ResolverFactory = require("./ResolverFactory");
|
||||
|
||||
const RequestShortener = require("./RequestShortener");
|
||||
const { makePathsRelative } = require("./util/identifier");
|
||||
const ConcurrentCompilationError = require("./ConcurrentCompilationError");
|
||||
const { Logger } = require("./logging/Logger");
|
||||
|
||||
/** @typedef {import("../declarations/WebpackOptions").Entry} Entry */
|
||||
/** @typedef {import("../declarations/WebpackOptions").WebpackOptions} WebpackOptions */
|
||||
|
||||
/**
|
||||
* @typedef {Object} CompilationParams
|
||||
* @property {NormalModuleFactory} normalModuleFactory
|
||||
* @property {ContextModuleFactory} contextModuleFactory
|
||||
* @property {Set<string>} compilationDependencies
|
||||
*/
|
||||
|
||||
class Compiler extends Tapable {
|
||||
constructor(context) {
|
||||
super();
|
||||
this.hooks = {
|
||||
/** @type {SyncBailHook<Compilation>} */
|
||||
shouldEmit: new SyncBailHook(["compilation"]),
|
||||
/** @type {AsyncSeriesHook<Stats>} */
|
||||
done: new AsyncSeriesHook(["stats"]),
|
||||
/** @type {AsyncSeriesHook<>} */
|
||||
additionalPass: new AsyncSeriesHook([]),
|
||||
/** @type {AsyncSeriesHook<Compiler>} */
|
||||
beforeRun: new AsyncSeriesHook(["compiler"]),
|
||||
/** @type {AsyncSeriesHook<Compiler>} */
|
||||
run: new AsyncSeriesHook(["compiler"]),
|
||||
/** @type {AsyncSeriesHook<Compilation>} */
|
||||
emit: new AsyncSeriesHook(["compilation"]),
|
||||
/** @type {AsyncSeriesHook<string, Buffer>} */
|
||||
assetEmitted: new AsyncSeriesHook(["file", "content"]),
|
||||
/** @type {AsyncSeriesHook<Compilation>} */
|
||||
afterEmit: new AsyncSeriesHook(["compilation"]),
|
||||
|
||||
/** @type {SyncHook<Compilation, CompilationParams>} */
|
||||
thisCompilation: new SyncHook(["compilation", "params"]),
|
||||
/** @type {SyncHook<Compilation, CompilationParams>} */
|
||||
compilation: new SyncHook(["compilation", "params"]),
|
||||
/** @type {SyncHook<NormalModuleFactory>} */
|
||||
normalModuleFactory: new SyncHook(["normalModuleFactory"]),
|
||||
/** @type {SyncHook<ContextModuleFactory>} */
|
||||
contextModuleFactory: new SyncHook(["contextModulefactory"]),
|
||||
|
||||
/** @type {AsyncSeriesHook<CompilationParams>} */
|
||||
beforeCompile: new AsyncSeriesHook(["params"]),
|
||||
/** @type {SyncHook<CompilationParams>} */
|
||||
compile: new SyncHook(["params"]),
|
||||
/** @type {AsyncParallelHook<Compilation>} */
|
||||
make: new AsyncParallelHook(["compilation"]),
|
||||
/** @type {AsyncSeriesHook<Compilation>} */
|
||||
afterCompile: new AsyncSeriesHook(["compilation"]),
|
||||
|
||||
/** @type {AsyncSeriesHook<Compiler>} */
|
||||
watchRun: new AsyncSeriesHook(["compiler"]),
|
||||
/** @type {SyncHook<Error>} */
|
||||
failed: new SyncHook(["error"]),
|
||||
/** @type {SyncHook<string, string>} */
|
||||
invalid: new SyncHook(["filename", "changeTime"]),
|
||||
/** @type {SyncHook} */
|
||||
watchClose: new SyncHook([]),
|
||||
|
||||
/** @type {SyncBailHook<string, string, any[]>} */
|
||||
infrastructureLog: new SyncBailHook(["origin", "type", "args"]),
|
||||
|
||||
// TODO the following hooks are weirdly located here
|
||||
// TODO move them for webpack 5
|
||||
/** @type {SyncHook} */
|
||||
environment: new SyncHook([]),
|
||||
/** @type {SyncHook} */
|
||||
afterEnvironment: new SyncHook([]),
|
||||
/** @type {SyncHook<Compiler>} */
|
||||
afterPlugins: new SyncHook(["compiler"]),
|
||||
/** @type {SyncHook<Compiler>} */
|
||||
afterResolvers: new SyncHook(["compiler"]),
|
||||
/** @type {SyncBailHook<string, Entry>} */
|
||||
entryOption: new SyncBailHook(["context", "entry"])
|
||||
};
|
||||
// TODO webpack 5 remove this
|
||||
this.hooks.infrastructurelog = this.hooks.infrastructureLog;
|
||||
|
||||
this._pluginCompat.tap("Compiler", options => {
|
||||
switch (options.name) {
|
||||
case "additional-pass":
|
||||
case "before-run":
|
||||
case "run":
|
||||
case "emit":
|
||||
case "after-emit":
|
||||
case "before-compile":
|
||||
case "make":
|
||||
case "after-compile":
|
||||
case "watch-run":
|
||||
options.async = true;
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
/** @type {string=} */
|
||||
this.name = undefined;
|
||||
/** @type {Compilation=} */
|
||||
this.parentCompilation = undefined;
|
||||
/** @type {string} */
|
||||
this.outputPath = "";
|
||||
|
||||
this.outputFileSystem = null;
|
||||
this.inputFileSystem = null;
|
||||
|
||||
/** @type {string|null} */
|
||||
this.recordsInputPath = null;
|
||||
/** @type {string|null} */
|
||||
this.recordsOutputPath = null;
|
||||
this.records = {};
|
||||
this.removedFiles = new Set();
|
||||
/** @type {Map<string, number>} */
|
||||
this.fileTimestamps = new Map();
|
||||
/** @type {Map<string, number>} */
|
||||
this.contextTimestamps = new Map();
|
||||
/** @type {ResolverFactory} */
|
||||
this.resolverFactory = new ResolverFactory();
|
||||
|
||||
this.infrastructureLogger = undefined;
|
||||
|
||||
// TODO remove in webpack 5
|
||||
this.resolvers = {
|
||||
normal: {
|
||||
plugins: util.deprecate((hook, fn) => {
|
||||
this.resolverFactory.plugin("resolver normal", resolver => {
|
||||
resolver.plugin(hook, fn);
|
||||
});
|
||||
}, "webpack: Using compiler.resolvers.normal is deprecated.\n" + 'Use compiler.resolverFactory.plugin("resolver normal", resolver => {\n resolver.plugin(/* … */);\n}); instead.'),
|
||||
apply: util.deprecate((...args) => {
|
||||
this.resolverFactory.plugin("resolver normal", resolver => {
|
||||
resolver.apply(...args);
|
||||
});
|
||||
}, "webpack: Using compiler.resolvers.normal is deprecated.\n" + 'Use compiler.resolverFactory.plugin("resolver normal", resolver => {\n resolver.apply(/* … */);\n}); instead.')
|
||||
},
|
||||
loader: {
|
||||
plugins: util.deprecate((hook, fn) => {
|
||||
this.resolverFactory.plugin("resolver loader", resolver => {
|
||||
resolver.plugin(hook, fn);
|
||||
});
|
||||
}, "webpack: Using compiler.resolvers.loader is deprecated.\n" + 'Use compiler.resolverFactory.plugin("resolver loader", resolver => {\n resolver.plugin(/* … */);\n}); instead.'),
|
||||
apply: util.deprecate((...args) => {
|
||||
this.resolverFactory.plugin("resolver loader", resolver => {
|
||||
resolver.apply(...args);
|
||||
});
|
||||
}, "webpack: Using compiler.resolvers.loader is deprecated.\n" + 'Use compiler.resolverFactory.plugin("resolver loader", resolver => {\n resolver.apply(/* … */);\n}); instead.')
|
||||
},
|
||||
context: {
|
||||
plugins: util.deprecate((hook, fn) => {
|
||||
this.resolverFactory.plugin("resolver context", resolver => {
|
||||
resolver.plugin(hook, fn);
|
||||
});
|
||||
}, "webpack: Using compiler.resolvers.context is deprecated.\n" + 'Use compiler.resolverFactory.plugin("resolver context", resolver => {\n resolver.plugin(/* … */);\n}); instead.'),
|
||||
apply: util.deprecate((...args) => {
|
||||
this.resolverFactory.plugin("resolver context", resolver => {
|
||||
resolver.apply(...args);
|
||||
});
|
||||
}, "webpack: Using compiler.resolvers.context is deprecated.\n" + 'Use compiler.resolverFactory.plugin("resolver context", resolver => {\n resolver.apply(/* … */);\n}); instead.')
|
||||
}
|
||||
};
|
||||
|
||||
/** @type {WebpackOptions} */
|
||||
this.options = /** @type {WebpackOptions} */ ({});
|
||||
|
||||
this.context = context;
|
||||
|
||||
this.requestShortener = new RequestShortener(context);
|
||||
|
||||
/** @type {boolean} */
|
||||
this.running = false;
|
||||
|
||||
/** @type {boolean} */
|
||||
this.watchMode = false;
|
||||
|
||||
/** @private @type {WeakMap<Source, { sizeOnlySource: SizeOnlySource, writtenTo: Map<string, number> }>} */
|
||||
this._assetEmittingSourceCache = new WeakMap();
|
||||
/** @private @type {Map<string, number>} */
|
||||
this._assetEmittingWrittenFiles = new Map();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string | (function(): string)} name name of the logger, or function called once to get the logger name
|
||||
* @returns {Logger} a logger with that name
|
||||
*/
|
||||
getInfrastructureLogger(name) {
|
||||
if (!name) {
|
||||
throw new TypeError(
|
||||
"Compiler.getInfrastructureLogger(name) called without a name"
|
||||
);
|
||||
}
|
||||
return new Logger((type, args) => {
|
||||
if (typeof name === "function") {
|
||||
name = name();
|
||||
if (!name) {
|
||||
throw new TypeError(
|
||||
"Compiler.getInfrastructureLogger(name) called with a function not returning a name"
|
||||
);
|
||||
}
|
||||
}
|
||||
if (this.hooks.infrastructureLog.call(name, type, args) === undefined) {
|
||||
if (this.infrastructureLogger !== undefined) {
|
||||
this.infrastructureLogger(name, type, args);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
watch(watchOptions, handler) {
|
||||
if (this.running) return handler(new ConcurrentCompilationError());
|
||||
|
||||
this.running = true;
|
||||
this.watchMode = true;
|
||||
this.fileTimestamps = new Map();
|
||||
this.contextTimestamps = new Map();
|
||||
this.removedFiles = new Set();
|
||||
return new Watching(this, watchOptions, handler);
|
||||
}
|
||||
|
||||
run(callback) {
|
||||
if (this.running) return callback(new ConcurrentCompilationError());
|
||||
|
||||
const finalCallback = (err, stats) => {
|
||||
this.running = false;
|
||||
|
||||
if (err) {
|
||||
this.hooks.failed.call(err);
|
||||
}
|
||||
|
||||
if (callback !== undefined) return callback(err, stats);
|
||||
};
|
||||
|
||||
const startTime = Date.now();
|
||||
|
||||
this.running = true;
|
||||
|
||||
const onCompiled = (err, compilation) => {
|
||||
if (err) return finalCallback(err);
|
||||
|
||||
if (this.hooks.shouldEmit.call(compilation) === false) {
|
||||
const stats = new Stats(compilation);
|
||||
stats.startTime = startTime;
|
||||
stats.endTime = Date.now();
|
||||
this.hooks.done.callAsync(stats, err => {
|
||||
if (err) return finalCallback(err);
|
||||
return finalCallback(null, stats);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
this.emitAssets(compilation, err => {
|
||||
if (err) return finalCallback(err);
|
||||
|
||||
if (compilation.hooks.needAdditionalPass.call()) {
|
||||
compilation.needAdditionalPass = true;
|
||||
|
||||
const stats = new Stats(compilation);
|
||||
stats.startTime = startTime;
|
||||
stats.endTime = Date.now();
|
||||
this.hooks.done.callAsync(stats, err => {
|
||||
if (err) return finalCallback(err);
|
||||
|
||||
this.hooks.additionalPass.callAsync(err => {
|
||||
if (err) return finalCallback(err);
|
||||
this.compile(onCompiled);
|
||||
});
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
this.emitRecords(err => {
|
||||
if (err) return finalCallback(err);
|
||||
|
||||
const stats = new Stats(compilation);
|
||||
stats.startTime = startTime;
|
||||
stats.endTime = Date.now();
|
||||
this.hooks.done.callAsync(stats, err => {
|
||||
if (err) return finalCallback(err);
|
||||
return finalCallback(null, stats);
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
this.hooks.beforeRun.callAsync(this, err => {
|
||||
if (err) return finalCallback(err);
|
||||
|
||||
this.hooks.run.callAsync(this, err => {
|
||||
if (err) return finalCallback(err);
|
||||
|
||||
this.readRecords(err => {
|
||||
if (err) return finalCallback(err);
|
||||
|
||||
this.compile(onCompiled);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
runAsChild(callback) {
|
||||
this.compile((err, compilation) => {
|
||||
if (err) return callback(err);
|
||||
|
||||
this.parentCompilation.children.push(compilation);
|
||||
for (const { name, source, info } of compilation.getAssets()) {
|
||||
this.parentCompilation.emitAsset(name, source, info);
|
||||
}
|
||||
|
||||
const entries = Array.from(
|
||||
compilation.entrypoints.values(),
|
||||
ep => ep.chunks
|
||||
).reduce((array, chunks) => {
|
||||
return array.concat(chunks);
|
||||
}, []);
|
||||
|
||||
return callback(null, entries, compilation);
|
||||
});
|
||||
}
|
||||
|
||||
purgeInputFileSystem() {
|
||||
if (this.inputFileSystem && this.inputFileSystem.purge) {
|
||||
this.inputFileSystem.purge();
|
||||
}
|
||||
}
|
||||
|
||||
emitAssets(compilation, callback) {
|
||||
let outputPath;
|
||||
const emitFiles = err => {
|
||||
if (err) return callback(err);
|
||||
|
||||
asyncLib.forEachLimit(
|
||||
compilation.getAssets(),
|
||||
15,
|
||||
({ name: file, source }, callback) => {
|
||||
let targetFile = file;
|
||||
const queryStringIdx = targetFile.indexOf("?");
|
||||
if (queryStringIdx >= 0) {
|
||||
targetFile = targetFile.substr(0, queryStringIdx);
|
||||
}
|
||||
|
||||
const writeOut = err => {
|
||||
if (err) return callback(err);
|
||||
const targetPath = this.outputFileSystem.join(
|
||||
outputPath,
|
||||
targetFile
|
||||
);
|
||||
// TODO webpack 5 remove futureEmitAssets option and make it on by default
|
||||
if (this.options.output.futureEmitAssets) {
|
||||
// check if the target file has already been written by this Compiler
|
||||
const targetFileGeneration = this._assetEmittingWrittenFiles.get(
|
||||
targetPath
|
||||
);
|
||||
|
||||
// create an cache entry for this Source if not already existing
|
||||
let cacheEntry = this._assetEmittingSourceCache.get(source);
|
||||
if (cacheEntry === undefined) {
|
||||
cacheEntry = {
|
||||
sizeOnlySource: undefined,
|
||||
writtenTo: new Map()
|
||||
};
|
||||
this._assetEmittingSourceCache.set(source, cacheEntry);
|
||||
}
|
||||
|
||||
// if the target file has already been written
|
||||
if (targetFileGeneration !== undefined) {
|
||||
// check if the Source has been written to this target file
|
||||
const writtenGeneration = cacheEntry.writtenTo.get(targetPath);
|
||||
if (writtenGeneration === targetFileGeneration) {
|
||||
// if yes, we skip writing the file
|
||||
// as it's already there
|
||||
// (we assume one doesn't remove files while the Compiler is running)
|
||||
|
||||
compilation.updateAsset(file, cacheEntry.sizeOnlySource, {
|
||||
size: cacheEntry.sizeOnlySource.size()
|
||||
});
|
||||
|
||||
return callback();
|
||||
}
|
||||
}
|
||||
|
||||
// TODO webpack 5: if info.immutable check if file already exists in output
|
||||
// skip emitting if it's already there
|
||||
|
||||
// get the binary (Buffer) content from the Source
|
||||
/** @type {Buffer} */
|
||||
let content;
|
||||
if (typeof source.buffer === "function") {
|
||||
content = source.buffer();
|
||||
} else {
|
||||
const bufferOrString = source.source();
|
||||
if (Buffer.isBuffer(bufferOrString)) {
|
||||
content = bufferOrString;
|
||||
} else {
|
||||
content = Buffer.from(bufferOrString, "utf8");
|
||||
}
|
||||
}
|
||||
|
||||
// Create a replacement resource which only allows to ask for size
|
||||
// This allows to GC all memory allocated by the Source
|
||||
// (expect when the Source is stored in any other cache)
|
||||
cacheEntry.sizeOnlySource = new SizeOnlySource(content.length);
|
||||
compilation.updateAsset(file, cacheEntry.sizeOnlySource, {
|
||||
size: content.length
|
||||
});
|
||||
|
||||
// Write the file to output file system
|
||||
this.outputFileSystem.writeFile(targetPath, content, err => {
|
||||
if (err) return callback(err);
|
||||
|
||||
// information marker that the asset has been emitted
|
||||
compilation.emittedAssets.add(file);
|
||||
|
||||
// cache the information that the Source has been written to that location
|
||||
const newGeneration =
|
||||
targetFileGeneration === undefined
|
||||
? 1
|
||||
: targetFileGeneration + 1;
|
||||
cacheEntry.writtenTo.set(targetPath, newGeneration);
|
||||
this._assetEmittingWrittenFiles.set(targetPath, newGeneration);
|
||||
this.hooks.assetEmitted.callAsync(file, content, callback);
|
||||
});
|
||||
} else {
|
||||
if (source.existsAt === targetPath) {
|
||||
source.emitted = false;
|
||||
return callback();
|
||||
}
|
||||
let content = source.source();
|
||||
|
||||
if (!Buffer.isBuffer(content)) {
|
||||
content = Buffer.from(content, "utf8");
|
||||
}
|
||||
|
||||
source.existsAt = targetPath;
|
||||
source.emitted = true;
|
||||
this.outputFileSystem.writeFile(targetPath, content, err => {
|
||||
if (err) return callback(err);
|
||||
this.hooks.assetEmitted.callAsync(file, content, callback);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
if (targetFile.match(/\/|\\/)) {
|
||||
const dir = path.dirname(targetFile);
|
||||
this.outputFileSystem.mkdirp(
|
||||
this.outputFileSystem.join(outputPath, dir),
|
||||
writeOut
|
||||
);
|
||||
} else {
|
||||
writeOut();
|
||||
}
|
||||
},
|
||||
err => {
|
||||
if (err) return callback(err);
|
||||
|
||||
this.hooks.afterEmit.callAsync(compilation, err => {
|
||||
if (err) return callback(err);
|
||||
|
||||
return callback();
|
||||
});
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
this.hooks.emit.callAsync(compilation, err => {
|
||||
if (err) return callback(err);
|
||||
outputPath = compilation.getPath(this.outputPath);
|
||||
this.outputFileSystem.mkdirp(outputPath, emitFiles);
|
||||
});
|
||||
}
|
||||
|
||||
emitRecords(callback) {
|
||||
if (!this.recordsOutputPath) return callback();
|
||||
const idx1 = this.recordsOutputPath.lastIndexOf("/");
|
||||
const idx2 = this.recordsOutputPath.lastIndexOf("\\");
|
||||
let recordsOutputPathDirectory = null;
|
||||
if (idx1 > idx2) {
|
||||
recordsOutputPathDirectory = this.recordsOutputPath.substr(0, idx1);
|
||||
} else if (idx1 < idx2) {
|
||||
recordsOutputPathDirectory = this.recordsOutputPath.substr(0, idx2);
|
||||
}
|
||||
|
||||
const writeFile = () => {
|
||||
this.outputFileSystem.writeFile(
|
||||
this.recordsOutputPath,
|
||||
JSON.stringify(this.records, undefined, 2),
|
||||
callback
|
||||
);
|
||||
};
|
||||
|
||||
if (!recordsOutputPathDirectory) {
|
||||
return writeFile();
|
||||
}
|
||||
this.outputFileSystem.mkdirp(recordsOutputPathDirectory, err => {
|
||||
if (err) return callback(err);
|
||||
writeFile();
|
||||
});
|
||||
}
|
||||
|
||||
readRecords(callback) {
|
||||
if (!this.recordsInputPath) {
|
||||
this.records = {};
|
||||
return callback();
|
||||
}
|
||||
this.inputFileSystem.stat(this.recordsInputPath, err => {
|
||||
// It doesn't exist
|
||||
// We can ignore this.
|
||||
if (err) return callback();
|
||||
|
||||
this.inputFileSystem.readFile(this.recordsInputPath, (err, content) => {
|
||||
if (err) return callback(err);
|
||||
|
||||
try {
|
||||
this.records = parseJson(content.toString("utf-8"));
|
||||
} catch (e) {
|
||||
e.message = "Cannot parse records: " + e.message;
|
||||
return callback(e);
|
||||
}
|
||||
|
||||
return callback();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
createChildCompiler(
|
||||
compilation,
|
||||
compilerName,
|
||||
compilerIndex,
|
||||
outputOptions,
|
||||
plugins
|
||||
) {
|
||||
const childCompiler = new Compiler(this.context);
|
||||
if (Array.isArray(plugins)) {
|
||||
for (const plugin of plugins) {
|
||||
plugin.apply(childCompiler);
|
||||
}
|
||||
}
|
||||
for (const name in this.hooks) {
|
||||
if (
|
||||
![
|
||||
"make",
|
||||
"compile",
|
||||
"emit",
|
||||
"afterEmit",
|
||||
"invalid",
|
||||
"done",
|
||||
"thisCompilation"
|
||||
].includes(name)
|
||||
) {
|
||||
if (childCompiler.hooks[name]) {
|
||||
childCompiler.hooks[name].taps = this.hooks[name].taps.slice();
|
||||
}
|
||||
}
|
||||
}
|
||||
childCompiler.name = compilerName;
|
||||
childCompiler.outputPath = this.outputPath;
|
||||
childCompiler.inputFileSystem = this.inputFileSystem;
|
||||
childCompiler.outputFileSystem = null;
|
||||
childCompiler.resolverFactory = this.resolverFactory;
|
||||
childCompiler.fileTimestamps = this.fileTimestamps;
|
||||
childCompiler.contextTimestamps = this.contextTimestamps;
|
||||
|
||||
const relativeCompilerName = makePathsRelative(this.context, compilerName);
|
||||
if (!this.records[relativeCompilerName]) {
|
||||
this.records[relativeCompilerName] = [];
|
||||
}
|
||||
if (this.records[relativeCompilerName][compilerIndex]) {
|
||||
childCompiler.records = this.records[relativeCompilerName][compilerIndex];
|
||||
} else {
|
||||
this.records[relativeCompilerName].push((childCompiler.records = {}));
|
||||
}
|
||||
|
||||
childCompiler.options = Object.create(this.options);
|
||||
childCompiler.options.output = Object.create(childCompiler.options.output);
|
||||
for (const name in outputOptions) {
|
||||
childCompiler.options.output[name] = outputOptions[name];
|
||||
}
|
||||
childCompiler.parentCompilation = compilation;
|
||||
|
||||
compilation.hooks.childCompiler.call(
|
||||
childCompiler,
|
||||
compilerName,
|
||||
compilerIndex
|
||||
);
|
||||
|
||||
return childCompiler;
|
||||
}
|
||||
|
||||
isChild() {
|
||||
return !!this.parentCompilation;
|
||||
}
|
||||
|
||||
createCompilation() {
|
||||
return new Compilation(this);
|
||||
}
|
||||
|
||||
newCompilation(params) {
|
||||
const compilation = this.createCompilation();
|
||||
compilation.fileTimestamps = this.fileTimestamps;
|
||||
compilation.contextTimestamps = this.contextTimestamps;
|
||||
compilation.name = this.name;
|
||||
compilation.records = this.records;
|
||||
compilation.compilationDependencies = params.compilationDependencies;
|
||||
this.hooks.thisCompilation.call(compilation, params);
|
||||
this.hooks.compilation.call(compilation, params);
|
||||
return compilation;
|
||||
}
|
||||
|
||||
createNormalModuleFactory() {
|
||||
const normalModuleFactory = new NormalModuleFactory(
|
||||
this.options.context,
|
||||
this.resolverFactory,
|
||||
this.options.module || {}
|
||||
);
|
||||
this.hooks.normalModuleFactory.call(normalModuleFactory);
|
||||
return normalModuleFactory;
|
||||
}
|
||||
|
||||
createContextModuleFactory() {
|
||||
const contextModuleFactory = new ContextModuleFactory(this.resolverFactory);
|
||||
this.hooks.contextModuleFactory.call(contextModuleFactory);
|
||||
return contextModuleFactory;
|
||||
}
|
||||
|
||||
newCompilationParams() {
|
||||
const params = {
|
||||
normalModuleFactory: this.createNormalModuleFactory(),
|
||||
contextModuleFactory: this.createContextModuleFactory(),
|
||||
compilationDependencies: new Set()
|
||||
};
|
||||
return params;
|
||||
}
|
||||
|
||||
compile(callback) {
|
||||
const params = this.newCompilationParams();
|
||||
this.hooks.beforeCompile.callAsync(params, err => {
|
||||
if (err) return callback(err);
|
||||
|
||||
this.hooks.compile.call(params);
|
||||
|
||||
const compilation = this.newCompilation(params);
|
||||
|
||||
this.hooks.make.callAsync(compilation, err => {
|
||||
if (err) return callback(err);
|
||||
|
||||
compilation.finish(err => {
|
||||
if (err) return callback(err);
|
||||
|
||||
compilation.seal(err => {
|
||||
if (err) return callback(err);
|
||||
|
||||
this.hooks.afterCompile.callAsync(compilation, err => {
|
||||
if (err) return callback(err);
|
||||
|
||||
return callback(null, compilation);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Compiler;
|
||||
|
||||
class SizeOnlySource extends Source {
|
||||
constructor(size) {
|
||||
super();
|
||||
this._size = size;
|
||||
}
|
||||
|
||||
_error() {
|
||||
return new Error(
|
||||
"Content and Map of this Source is no longer available (only size() is supported)"
|
||||
);
|
||||
}
|
||||
|
||||
size() {
|
||||
return this._size;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {any} options options
|
||||
* @returns {string} the source
|
||||
*/
|
||||
source(options) {
|
||||
throw this._error();
|
||||
}
|
||||
|
||||
node() {
|
||||
throw this._error();
|
||||
}
|
||||
|
||||
listMap() {
|
||||
throw this._error();
|
||||
}
|
||||
|
||||
map() {
|
||||
throw this._error();
|
||||
}
|
||||
|
||||
listNode() {
|
||||
throw this._error();
|
||||
}
|
||||
|
||||
updateHash() {
|
||||
throw this._error();
|
||||
}
|
||||
}
|
||||
19
node_modules/webpack/lib/ConcurrentCompilationError.js
generated
vendored
Normal file
19
node_modules/webpack/lib/ConcurrentCompilationError.js
generated
vendored
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
/*
|
||||
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.";
|
||||
|
||||
Error.captureStackTrace(this, this.constructor);
|
||||
}
|
||||
};
|
||||
348
node_modules/webpack/lib/ConstPlugin.js
generated
vendored
Normal file
348
node_modules/webpack/lib/ConstPlugin.js
generated
vendored
Normal file
|
|
@ -0,0 +1,348 @@
|
|||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
"use strict";
|
||||
const ConstDependency = require("./dependencies/ConstDependency");
|
||||
const NullFactory = require("./NullFactory");
|
||||
const ParserHelpers = require("./ParserHelpers");
|
||||
|
||||
const getQuery = request => {
|
||||
const i = request.indexOf("?");
|
||||
return i !== -1 ? request.substr(i) : "";
|
||||
};
|
||||
|
||||
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(compiler) {
|
||||
compiler.hooks.compilation.tap(
|
||||
"ConstPlugin",
|
||||
(compilation, { normalModuleFactory }) => {
|
||||
compilation.dependencyFactories.set(ConstDependency, new NullFactory());
|
||||
compilation.dependencyTemplates.set(
|
||||
ConstDependency,
|
||||
new ConstDependency.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 (statement.test.type !== "Literal") {
|
||||
const dep = new ConstDependency(`${bool}`, param.range);
|
||||
dep.loc = statement.loc;
|
||||
parser.state.current.addDependency(dep);
|
||||
}
|
||||
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.current.addDependency(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 (expression.test.type !== "Literal") {
|
||||
const dep = new ConstDependency(` ${bool}`, param.range);
|
||||
dep.loc = expression.loc;
|
||||
parser.state.current.addDependency(dep);
|
||||
}
|
||||
// Expressions do not hoist.
|
||||
// It is safe to remove the dead branch.
|
||||
//
|
||||
// Given the following code:
|
||||
//
|
||||
// false ? someExpression() : otherExpression();
|
||||
//
|
||||
// the generated code is:
|
||||
//
|
||||
// false ? undefined : otherExpression();
|
||||
//
|
||||
const branchToRemove = bool
|
||||
? expression.alternate
|
||||
: expression.consequent;
|
||||
const dep = new ConstDependency(
|
||||
"undefined",
|
||||
branchToRemove.range
|
||||
);
|
||||
dep.loc = branchToRemove.loc;
|
||||
parser.state.current.addDependency(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.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.current.addDependency(dep);
|
||||
} else {
|
||||
parser.walkExpression(expression.left);
|
||||
}
|
||||
if (!keepRight) {
|
||||
const dep = new ConstDependency(
|
||||
"false",
|
||||
expression.right.range
|
||||
);
|
||||
dep.loc = expression.loc;
|
||||
parser.state.current.addDependency(dep);
|
||||
}
|
||||
return keepRight;
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
parser.hooks.evaluateIdentifier
|
||||
.for("__resourceQuery")
|
||||
.tap("ConstPlugin", expr => {
|
||||
if (parser.scope.isAsmJs) return;
|
||||
if (!parser.state.module) return;
|
||||
return ParserHelpers.evaluateToString(
|
||||
getQuery(parser.state.module.resource)
|
||||
)(expr);
|
||||
});
|
||||
parser.hooks.expression
|
||||
.for("__resourceQuery")
|
||||
.tap("ConstPlugin", () => {
|
||||
if (parser.scope.isAsmJs) return;
|
||||
if (!parser.state.module) return;
|
||||
parser.state.current.addVariable(
|
||||
"__resourceQuery",
|
||||
JSON.stringify(getQuery(parser.state.module.resource))
|
||||
);
|
||||
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;
|
||||
28
node_modules/webpack/lib/ContextExclusionPlugin.js
generated
vendored
Normal file
28
node_modules/webpack/lib/ContextExclusionPlugin.js
generated
vendored
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
"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 Webpack Compiler
|
||||
* @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;
|
||||
872
node_modules/webpack/lib/ContextModule.js
generated
vendored
Normal file
872
node_modules/webpack/lib/ContextModule.js
generated
vendored
Normal file
|
|
@ -0,0 +1,872 @@
|
|||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
"use strict";
|
||||
const util = require("util");
|
||||
const { OriginalSource, RawSource } = require("webpack-sources");
|
||||
const Module = require("./Module");
|
||||
const AsyncDependenciesBlock = require("./AsyncDependenciesBlock");
|
||||
const Template = require("./Template");
|
||||
const contextify = require("./util/identifier").contextify;
|
||||
|
||||
/** @typedef {"sync" | "eager" | "weak" | "async-weak" | "lazy" | "lazy-once"} ContextMode Context mode */
|
||||
/** @typedef {import("./dependencies/ContextElementDependency")} ContextElementDependency */
|
||||
|
||||
/**
|
||||
* @callback ResolveDependenciesCallback
|
||||
* @param {Error=} err
|
||||
* @param {ContextElementDependency[]} dependencies
|
||||
*/
|
||||
|
||||
/**
|
||||
* @callback ResolveDependencies
|
||||
* @param {TODO} fs
|
||||
* @param {TODO} options
|
||||
* @param {ResolveDependenciesCallback} callback
|
||||
*/
|
||||
|
||||
class ContextModule extends Module {
|
||||
// type ContextMode = "sync" | "eager" | "weak" | "async-weak" | "lazy" | "lazy-once"
|
||||
// type ContextOptions = { resource: string, recursive: boolean, regExp: RegExp, addon?: string, mode?: ContextMode, chunkName?: string, include?: RegExp, exclude?: RegExp, groupOptions?: Object }
|
||||
// resolveDependencies: (fs: FS, options: ContextOptions, (err: Error?, dependencies: Dependency[]) => void) => void
|
||||
// options: ContextOptions
|
||||
/**
|
||||
* @param {ResolveDependencies} resolveDependencies function to get dependencies in this context
|
||||
* @param {TODO} options options object
|
||||
*/
|
||||
constructor(resolveDependencies, options) {
|
||||
let resource;
|
||||
let resourceQuery;
|
||||
const queryIdx = options.resource.indexOf("?");
|
||||
if (queryIdx >= 0) {
|
||||
resource = options.resource.substr(0, queryIdx);
|
||||
resourceQuery = options.resource.substr(queryIdx);
|
||||
} else {
|
||||
resource = options.resource;
|
||||
resourceQuery = "";
|
||||
}
|
||||
|
||||
super("javascript/dynamic", resource);
|
||||
|
||||
// Info from Factory
|
||||
this.resolveDependencies = resolveDependencies;
|
||||
this.options = Object.assign({}, options, {
|
||||
resource: resource,
|
||||
resourceQuery: resourceQuery
|
||||
});
|
||||
if (options.resolveOptions !== undefined) {
|
||||
this.resolveOptions = options.resolveOptions;
|
||||
}
|
||||
|
||||
// Info from Build
|
||||
this._contextDependencies = new Set([this.context]);
|
||||
|
||||
if (typeof options.mode !== "string") {
|
||||
throw new Error("options.mode is a required option");
|
||||
}
|
||||
|
||||
this._identifier = this._createIdentifier();
|
||||
}
|
||||
|
||||
updateCacheModule(module) {
|
||||
this.resolveDependencies = module.resolveDependencies;
|
||||
this.options = module.options;
|
||||
this.resolveOptions = module.resolveOptions;
|
||||
}
|
||||
|
||||
prettyRegExp(regexString) {
|
||||
// remove the "/" at the front and the beginning
|
||||
// "/foo/" -> "foo"
|
||||
return regexString.substring(1, regexString.length - 1);
|
||||
}
|
||||
|
||||
_createIdentifier() {
|
||||
let identifier = this.context;
|
||||
if (this.options.resourceQuery) {
|
||||
identifier += ` ${this.options.resourceQuery}`;
|
||||
}
|
||||
if (this.options.mode) {
|
||||
identifier += ` ${this.options.mode}`;
|
||||
}
|
||||
if (!this.options.recursive) {
|
||||
identifier += " nonrecursive";
|
||||
}
|
||||
if (this.options.addon) {
|
||||
identifier += ` ${this.options.addon}`;
|
||||
}
|
||||
if (this.options.regExp) {
|
||||
identifier += ` ${this.options.regExp}`;
|
||||
}
|
||||
if (this.options.include) {
|
||||
identifier += ` include: ${this.options.include}`;
|
||||
}
|
||||
if (this.options.exclude) {
|
||||
identifier += ` exclude: ${this.options.exclude}`;
|
||||
}
|
||||
if (this.options.groupOptions) {
|
||||
identifier += ` groupOptions: ${JSON.stringify(
|
||||
this.options.groupOptions
|
||||
)}`;
|
||||
}
|
||||
if (this.options.namespaceObject === "strict") {
|
||||
identifier += " strict namespace object";
|
||||
} else if (this.options.namespaceObject) {
|
||||
identifier += " namespace object";
|
||||
}
|
||||
|
||||
return identifier;
|
||||
}
|
||||
|
||||
identifier() {
|
||||
return this._identifier;
|
||||
}
|
||||
|
||||
readableIdentifier(requestShortener) {
|
||||
let identifier = requestShortener.shorten(this.context);
|
||||
if (this.options.resourceQuery) {
|
||||
identifier += ` ${this.options.resourceQuery}`;
|
||||
}
|
||||
if (this.options.mode) {
|
||||
identifier += ` ${this.options.mode}`;
|
||||
}
|
||||
if (!this.options.recursive) {
|
||||
identifier += " nonrecursive";
|
||||
}
|
||||
if (this.options.addon) {
|
||||
identifier += ` ${requestShortener.shorten(this.options.addon)}`;
|
||||
}
|
||||
if (this.options.regExp) {
|
||||
identifier += ` ${this.prettyRegExp(this.options.regExp + "")}`;
|
||||
}
|
||||
if (this.options.include) {
|
||||
identifier += ` include: ${this.prettyRegExp(this.options.include + "")}`;
|
||||
}
|
||||
if (this.options.exclude) {
|
||||
identifier += ` exclude: ${this.prettyRegExp(this.options.exclude + "")}`;
|
||||
}
|
||||
if (this.options.groupOptions) {
|
||||
const groupOptions = this.options.groupOptions;
|
||||
for (const key of Object.keys(groupOptions)) {
|
||||
identifier += ` ${key}: ${groupOptions[key]}`;
|
||||
}
|
||||
}
|
||||
if (this.options.namespaceObject === "strict") {
|
||||
identifier += " strict namespace object";
|
||||
} else if (this.options.namespaceObject) {
|
||||
identifier += " namespace object";
|
||||
}
|
||||
|
||||
return identifier;
|
||||
}
|
||||
|
||||
libIdent(options) {
|
||||
let identifier = contextify(options.context, this.context);
|
||||
if (this.options.mode) {
|
||||
identifier += ` ${this.options.mode}`;
|
||||
}
|
||||
if (this.options.recursive) {
|
||||
identifier += " recursive";
|
||||
}
|
||||
if (this.options.addon) {
|
||||
identifier += ` ${contextify(options.context, this.options.addon)}`;
|
||||
}
|
||||
if (this.options.regExp) {
|
||||
identifier += ` ${this.prettyRegExp(this.options.regExp + "")}`;
|
||||
}
|
||||
if (this.options.include) {
|
||||
identifier += ` include: ${this.prettyRegExp(this.options.include + "")}`;
|
||||
}
|
||||
if (this.options.exclude) {
|
||||
identifier += ` exclude: ${this.prettyRegExp(this.options.exclude + "")}`;
|
||||
}
|
||||
|
||||
return identifier;
|
||||
}
|
||||
|
||||
needRebuild(fileTimestamps, contextTimestamps) {
|
||||
const ts = contextTimestamps.get(this.context);
|
||||
if (!ts) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return ts >= this.buildInfo.builtTime;
|
||||
}
|
||||
|
||||
build(options, compilation, resolver, fs, callback) {
|
||||
this.built = true;
|
||||
this.buildMeta = {};
|
||||
this.buildInfo = {
|
||||
builtTime: Date.now(),
|
||||
contextDependencies: this._contextDependencies
|
||||
};
|
||||
this.resolveDependencies(fs, this.options, (err, dependencies) => {
|
||||
if (err) return callback(err);
|
||||
|
||||
// abort if something failed
|
||||
// this will create an empty context
|
||||
if (!dependencies) {
|
||||
callback();
|
||||
return;
|
||||
}
|
||||
|
||||
// enhance dependencies with meta info
|
||||
for (const dep of dependencies) {
|
||||
dep.loc = {
|
||||
name: dep.userRequest
|
||||
};
|
||||
dep.request = this.options.addon + dep.request;
|
||||
}
|
||||
|
||||
if (this.options.mode === "sync" || this.options.mode === "eager") {
|
||||
// if we have an sync or eager context
|
||||
// just add all dependencies and continue
|
||||
this.dependencies = dependencies;
|
||||
} else if (this.options.mode === "lazy-once") {
|
||||
// for the lazy-once mode create a new async dependency block
|
||||
// and add that block to this context
|
||||
if (dependencies.length > 0) {
|
||||
const block = new AsyncDependenciesBlock(
|
||||
Object.assign({}, this.options.groupOptions, {
|
||||
name: this.options.chunkName
|
||||
}),
|
||||
this
|
||||
);
|
||||
for (const dep of dependencies) {
|
||||
block.addDependency(dep);
|
||||
}
|
||||
this.addBlock(block);
|
||||
}
|
||||
} else if (
|
||||
this.options.mode === "weak" ||
|
||||
this.options.mode === "async-weak"
|
||||
) {
|
||||
// we mark all dependencies as weak
|
||||
for (const dep of dependencies) {
|
||||
dep.weak = true;
|
||||
}
|
||||
this.dependencies = dependencies;
|
||||
} else if (this.options.mode === "lazy") {
|
||||
// if we are lazy create a new async dependency block per dependency
|
||||
// and add all blocks to this context
|
||||
let index = 0;
|
||||
for (const dep of dependencies) {
|
||||
let chunkName = this.options.chunkName;
|
||||
if (chunkName) {
|
||||
if (!/\[(index|request)\]/.test(chunkName)) {
|
||||
chunkName += "[index]";
|
||||
}
|
||||
chunkName = chunkName.replace(/\[index\]/g, index++);
|
||||
chunkName = chunkName.replace(
|
||||
/\[request\]/g,
|
||||
Template.toPath(dep.userRequest)
|
||||
);
|
||||
}
|
||||
const block = new AsyncDependenciesBlock(
|
||||
Object.assign({}, this.options.groupOptions, {
|
||||
name: chunkName
|
||||
}),
|
||||
dep.module,
|
||||
dep.loc,
|
||||
dep.userRequest
|
||||
);
|
||||
block.addDependency(dep);
|
||||
this.addBlock(block);
|
||||
}
|
||||
} else {
|
||||
callback(
|
||||
new Error(`Unsupported mode "${this.options.mode}" in context`)
|
||||
);
|
||||
return;
|
||||
}
|
||||
callback();
|
||||
});
|
||||
}
|
||||
|
||||
getUserRequestMap(dependencies) {
|
||||
// if we filter first we get a new array
|
||||
// therefor we dont need to create a clone of dependencies explicitly
|
||||
// therefore the order of this is !important!
|
||||
return dependencies
|
||||
.filter(dependency => dependency.module)
|
||||
.sort((a, b) => {
|
||||
if (a.userRequest === b.userRequest) {
|
||||
return 0;
|
||||
}
|
||||
return a.userRequest < b.userRequest ? -1 : 1;
|
||||
})
|
||||
.reduce((map, dep) => {
|
||||
map[dep.userRequest] = dep.module.id;
|
||||
return map;
|
||||
}, Object.create(null));
|
||||
}
|
||||
|
||||
getFakeMap(dependencies) {
|
||||
if (!this.options.namespaceObject) {
|
||||
return 9;
|
||||
}
|
||||
// if we filter first we get a new array
|
||||
// therefor we dont need to create a clone of dependencies explicitly
|
||||
// therefore the order of this is !important!
|
||||
let hasNonHarmony = false;
|
||||
let hasNamespace = false;
|
||||
let hasNamed = false;
|
||||
const fakeMap = dependencies
|
||||
.filter(dependency => dependency.module)
|
||||
.sort((a, b) => {
|
||||
return b.module.id - a.module.id;
|
||||
})
|
||||
.reduce((map, dep) => {
|
||||
const exportsType =
|
||||
dep.module.buildMeta && dep.module.buildMeta.exportsType;
|
||||
const id = dep.module.id;
|
||||
if (!exportsType) {
|
||||
map[id] = this.options.namespaceObject === "strict" ? 1 : 7;
|
||||
hasNonHarmony = true;
|
||||
} else if (exportsType === "namespace") {
|
||||
map[id] = 9;
|
||||
hasNamespace = true;
|
||||
} else if (exportsType === "named") {
|
||||
map[id] = 3;
|
||||
hasNamed = true;
|
||||
}
|
||||
return map;
|
||||
}, Object.create(null));
|
||||
if (!hasNamespace && hasNonHarmony && !hasNamed) {
|
||||
return this.options.namespaceObject === "strict" ? 1 : 7;
|
||||
}
|
||||
if (hasNamespace && !hasNonHarmony && !hasNamed) {
|
||||
return 9;
|
||||
}
|
||||
if (!hasNamespace && !hasNonHarmony && hasNamed) {
|
||||
return 3;
|
||||
}
|
||||
if (!hasNamespace && !hasNonHarmony && !hasNamed) {
|
||||
return 9;
|
||||
}
|
||||
return fakeMap;
|
||||
}
|
||||
|
||||
getFakeMapInitStatement(fakeMap) {
|
||||
return typeof fakeMap === "object"
|
||||
? `var fakeMap = ${JSON.stringify(fakeMap, null, "\t")};`
|
||||
: "";
|
||||
}
|
||||
|
||||
getReturn(type) {
|
||||
if (type === 9) {
|
||||
return "__webpack_require__(id)";
|
||||
}
|
||||
return `__webpack_require__.t(id, ${type})`;
|
||||
}
|
||||
|
||||
getReturnModuleObjectSource(fakeMap, fakeMapDataExpression = "fakeMap[id]") {
|
||||
if (typeof fakeMap === "number") {
|
||||
return `return ${this.getReturn(fakeMap)};`;
|
||||
}
|
||||
return `return __webpack_require__.t(id, ${fakeMapDataExpression})`;
|
||||
}
|
||||
|
||||
getSyncSource(dependencies, id) {
|
||||
const map = this.getUserRequestMap(dependencies);
|
||||
const fakeMap = this.getFakeMap(dependencies);
|
||||
const returnModuleObject = this.getReturnModuleObjectSource(fakeMap);
|
||||
|
||||
return `var map = ${JSON.stringify(map, null, "\t")};
|
||||
${this.getFakeMapInitStatement(fakeMap)}
|
||||
|
||||
function webpackContext(req) {
|
||||
var id = webpackContextResolve(req);
|
||||
${returnModuleObject}
|
||||
}
|
||||
function webpackContextResolve(req) {
|
||||
if(!__webpack_require__.o(map, req)) {
|
||||
var e = new Error("Cannot find module '" + req + "'");
|
||||
e.code = 'MODULE_NOT_FOUND';
|
||||
throw e;
|
||||
}
|
||||
return map[req];
|
||||
}
|
||||
webpackContext.keys = function webpackContextKeys() {
|
||||
return Object.keys(map);
|
||||
};
|
||||
webpackContext.resolve = webpackContextResolve;
|
||||
module.exports = webpackContext;
|
||||
webpackContext.id = ${JSON.stringify(id)};`;
|
||||
}
|
||||
|
||||
getWeakSyncSource(dependencies, id) {
|
||||
const map = this.getUserRequestMap(dependencies);
|
||||
const fakeMap = this.getFakeMap(dependencies);
|
||||
const returnModuleObject = this.getReturnModuleObjectSource(fakeMap);
|
||||
|
||||
return `var map = ${JSON.stringify(map, null, "\t")};
|
||||
${this.getFakeMapInitStatement(fakeMap)}
|
||||
|
||||
function webpackContext(req) {
|
||||
var id = webpackContextResolve(req);
|
||||
if(!__webpack_require__.m[id]) {
|
||||
var e = new Error("Module '" + req + "' ('" + id + "') is not available (weak dependency)");
|
||||
e.code = 'MODULE_NOT_FOUND';
|
||||
throw e;
|
||||
}
|
||||
${returnModuleObject}
|
||||
}
|
||||
function webpackContextResolve(req) {
|
||||
if(!__webpack_require__.o(map, req)) {
|
||||
var e = new Error("Cannot find module '" + req + "'");
|
||||
e.code = 'MODULE_NOT_FOUND';
|
||||
throw e;
|
||||
}
|
||||
return map[req];
|
||||
}
|
||||
webpackContext.keys = function webpackContextKeys() {
|
||||
return Object.keys(map);
|
||||
};
|
||||
webpackContext.resolve = webpackContextResolve;
|
||||
webpackContext.id = ${JSON.stringify(id)};
|
||||
module.exports = webpackContext;`;
|
||||
}
|
||||
|
||||
getAsyncWeakSource(dependencies, id) {
|
||||
const map = this.getUserRequestMap(dependencies);
|
||||
const fakeMap = this.getFakeMap(dependencies);
|
||||
const returnModuleObject = this.getReturnModuleObjectSource(fakeMap);
|
||||
|
||||
return `var map = ${JSON.stringify(map, null, "\t")};
|
||||
${this.getFakeMapInitStatement(fakeMap)}
|
||||
|
||||
function webpackAsyncContext(req) {
|
||||
return webpackAsyncContextResolve(req).then(function(id) {
|
||||
if(!__webpack_require__.m[id]) {
|
||||
var e = new Error("Module '" + req + "' ('" + id + "') is not available (weak dependency)");
|
||||
e.code = 'MODULE_NOT_FOUND';
|
||||
throw e;
|
||||
}
|
||||
${returnModuleObject}
|
||||
});
|
||||
}
|
||||
function webpackAsyncContextResolve(req) {
|
||||
// Here Promise.resolve().then() is used instead of new Promise() to prevent
|
||||
// uncaught exception popping up in devtools
|
||||
return Promise.resolve().then(function() {
|
||||
if(!__webpack_require__.o(map, req)) {
|
||||
var e = new Error("Cannot find module '" + req + "'");
|
||||
e.code = 'MODULE_NOT_FOUND';
|
||||
throw e;
|
||||
}
|
||||
return map[req];
|
||||
});
|
||||
}
|
||||
webpackAsyncContext.keys = function webpackAsyncContextKeys() {
|
||||
return Object.keys(map);
|
||||
};
|
||||
webpackAsyncContext.resolve = webpackAsyncContextResolve;
|
||||
webpackAsyncContext.id = ${JSON.stringify(id)};
|
||||
module.exports = webpackAsyncContext;`;
|
||||
}
|
||||
|
||||
getEagerSource(dependencies, id) {
|
||||
const map = this.getUserRequestMap(dependencies);
|
||||
const fakeMap = this.getFakeMap(dependencies);
|
||||
const thenFunction =
|
||||
fakeMap !== 9
|
||||
? `function(id) {
|
||||
${this.getReturnModuleObjectSource(fakeMap)}
|
||||
}`
|
||||
: "__webpack_require__";
|
||||
return `var map = ${JSON.stringify(map, null, "\t")};
|
||||
${this.getFakeMapInitStatement(fakeMap)}
|
||||
|
||||
function webpackAsyncContext(req) {
|
||||
return webpackAsyncContextResolve(req).then(${thenFunction});
|
||||
}
|
||||
function webpackAsyncContextResolve(req) {
|
||||
// Here Promise.resolve().then() is used instead of new Promise() to prevent
|
||||
// uncaught exception popping up in devtools
|
||||
return Promise.resolve().then(function() {
|
||||
if(!__webpack_require__.o(map, req)) {
|
||||
var e = new Error("Cannot find module '" + req + "'");
|
||||
e.code = 'MODULE_NOT_FOUND';
|
||||
throw e;
|
||||
}
|
||||
return map[req];
|
||||
});
|
||||
}
|
||||
webpackAsyncContext.keys = function webpackAsyncContextKeys() {
|
||||
return Object.keys(map);
|
||||
};
|
||||
webpackAsyncContext.resolve = webpackAsyncContextResolve;
|
||||
webpackAsyncContext.id = ${JSON.stringify(id)};
|
||||
module.exports = webpackAsyncContext;`;
|
||||
}
|
||||
|
||||
getLazyOnceSource(block, dependencies, id, runtimeTemplate) {
|
||||
const promise = runtimeTemplate.blockPromise({
|
||||
block,
|
||||
message: "lazy-once context"
|
||||
});
|
||||
const map = this.getUserRequestMap(dependencies);
|
||||
const fakeMap = this.getFakeMap(dependencies);
|
||||
const thenFunction =
|
||||
fakeMap !== 9
|
||||
? `function(id) {
|
||||
${this.getReturnModuleObjectSource(fakeMap)};
|
||||
}`
|
||||
: "__webpack_require__";
|
||||
|
||||
return `var map = ${JSON.stringify(map, null, "\t")};
|
||||
${this.getFakeMapInitStatement(fakeMap)}
|
||||
|
||||
function webpackAsyncContext(req) {
|
||||
return webpackAsyncContextResolve(req).then(${thenFunction});
|
||||
}
|
||||
function webpackAsyncContextResolve(req) {
|
||||
return ${promise}.then(function() {
|
||||
if(!__webpack_require__.o(map, req)) {
|
||||
var e = new Error("Cannot find module '" + req + "'");
|
||||
e.code = 'MODULE_NOT_FOUND';
|
||||
throw e;
|
||||
}
|
||||
return map[req];
|
||||
});
|
||||
}
|
||||
webpackAsyncContext.keys = function webpackAsyncContextKeys() {
|
||||
return Object.keys(map);
|
||||
};
|
||||
webpackAsyncContext.resolve = webpackAsyncContextResolve;
|
||||
webpackAsyncContext.id = ${JSON.stringify(id)};
|
||||
module.exports = webpackAsyncContext;`;
|
||||
}
|
||||
|
||||
getLazySource(blocks, id) {
|
||||
let hasMultipleOrNoChunks = false;
|
||||
let hasNoChunk = true;
|
||||
const fakeMap = this.getFakeMap(blocks.map(b => b.dependencies[0]));
|
||||
const hasFakeMap = typeof fakeMap === "object";
|
||||
const map = blocks
|
||||
.filter(block => block.dependencies[0].module)
|
||||
.map(block => {
|
||||
const chunks = block.chunkGroup ? block.chunkGroup.chunks : [];
|
||||
if (chunks.length > 0) {
|
||||
hasNoChunk = false;
|
||||
}
|
||||
if (chunks.length !== 1) {
|
||||
hasMultipleOrNoChunks = true;
|
||||
}
|
||||
return {
|
||||
dependency: block.dependencies[0],
|
||||
block: block,
|
||||
userRequest: block.dependencies[0].userRequest,
|
||||
chunks
|
||||
};
|
||||
})
|
||||
.sort((a, b) => {
|
||||
if (a.userRequest === b.userRequest) return 0;
|
||||
return a.userRequest < b.userRequest ? -1 : 1;
|
||||
})
|
||||
.reduce((map, item) => {
|
||||
const chunks = item.chunks;
|
||||
|
||||
if (hasNoChunk && !hasFakeMap) {
|
||||
map[item.userRequest] = item.dependency.module.id;
|
||||
} else {
|
||||
const arrayStart = [item.dependency.module.id];
|
||||
if (typeof fakeMap === "object") {
|
||||
arrayStart.push(fakeMap[item.dependency.module.id]);
|
||||
}
|
||||
map[item.userRequest] = arrayStart.concat(
|
||||
chunks.map(chunk => chunk.id)
|
||||
);
|
||||
}
|
||||
|
||||
return map;
|
||||
}, Object.create(null));
|
||||
|
||||
const shortMode = hasNoChunk && !hasFakeMap;
|
||||
const chunksStartPosition = hasFakeMap ? 2 : 1;
|
||||
const requestPrefix = hasNoChunk
|
||||
? "Promise.resolve()"
|
||||
: hasMultipleOrNoChunks
|
||||
? `Promise.all(ids.slice(${chunksStartPosition}).map(__webpack_require__.e))`
|
||||
: `__webpack_require__.e(ids[${chunksStartPosition}])`;
|
||||
const returnModuleObject = this.getReturnModuleObjectSource(
|
||||
fakeMap,
|
||||
shortMode ? "invalid" : "ids[1]"
|
||||
);
|
||||
|
||||
const webpackAsyncContext =
|
||||
requestPrefix === "Promise.resolve()"
|
||||
? `${shortMode ? "" : ""}
|
||||
function webpackAsyncContext(req) {
|
||||
return Promise.resolve().then(function() {
|
||||
if(!__webpack_require__.o(map, req)) {
|
||||
var e = new Error("Cannot find module '" + req + "'");
|
||||
e.code = 'MODULE_NOT_FOUND';
|
||||
throw e;
|
||||
}
|
||||
|
||||
${shortMode ? "var id = map[req];" : "var ids = map[req], id = ids[0];"}
|
||||
${returnModuleObject}
|
||||
});
|
||||
}`
|
||||
: `function webpackAsyncContext(req) {
|
||||
if(!__webpack_require__.o(map, req)) {
|
||||
return Promise.resolve().then(function() {
|
||||
var e = new Error("Cannot find module '" + req + "'");
|
||||
e.code = 'MODULE_NOT_FOUND';
|
||||
throw e;
|
||||
});
|
||||
}
|
||||
|
||||
var ids = map[req], id = ids[0];
|
||||
return ${requestPrefix}.then(function() {
|
||||
${returnModuleObject}
|
||||
});
|
||||
}`;
|
||||
|
||||
return `var map = ${JSON.stringify(map, null, "\t")};
|
||||
${webpackAsyncContext}
|
||||
webpackAsyncContext.keys = function webpackAsyncContextKeys() {
|
||||
return Object.keys(map);
|
||||
};
|
||||
webpackAsyncContext.id = ${JSON.stringify(id)};
|
||||
module.exports = webpackAsyncContext;`;
|
||||
}
|
||||
|
||||
getSourceForEmptyContext(id) {
|
||||
return `function webpackEmptyContext(req) {
|
||||
var e = new Error("Cannot find module '" + req + "'");
|
||||
e.code = 'MODULE_NOT_FOUND';
|
||||
throw e;
|
||||
}
|
||||
webpackEmptyContext.keys = function() { return []; };
|
||||
webpackEmptyContext.resolve = webpackEmptyContext;
|
||||
module.exports = webpackEmptyContext;
|
||||
webpackEmptyContext.id = ${JSON.stringify(id)};`;
|
||||
}
|
||||
|
||||
getSourceForEmptyAsyncContext(id) {
|
||||
return `function webpackEmptyAsyncContext(req) {
|
||||
// Here Promise.resolve().then() is used instead of new Promise() to prevent
|
||||
// uncaught exception popping up in devtools
|
||||
return Promise.resolve().then(function() {
|
||||
var e = new Error("Cannot find module '" + req + "'");
|
||||
e.code = 'MODULE_NOT_FOUND';
|
||||
throw e;
|
||||
});
|
||||
}
|
||||
webpackEmptyAsyncContext.keys = function() { return []; };
|
||||
webpackEmptyAsyncContext.resolve = webpackEmptyAsyncContext;
|
||||
module.exports = webpackEmptyAsyncContext;
|
||||
webpackEmptyAsyncContext.id = ${JSON.stringify(id)};`;
|
||||
}
|
||||
|
||||
getSourceString(asyncMode, runtimeTemplate) {
|
||||
if (asyncMode === "lazy") {
|
||||
if (this.blocks && this.blocks.length > 0) {
|
||||
return this.getLazySource(this.blocks, this.id);
|
||||
}
|
||||
return this.getSourceForEmptyAsyncContext(this.id);
|
||||
}
|
||||
if (asyncMode === "eager") {
|
||||
if (this.dependencies && this.dependencies.length > 0) {
|
||||
return this.getEagerSource(this.dependencies, this.id);
|
||||
}
|
||||
return this.getSourceForEmptyAsyncContext(this.id);
|
||||
}
|
||||
if (asyncMode === "lazy-once") {
|
||||
const block = this.blocks[0];
|
||||
if (block) {
|
||||
return this.getLazyOnceSource(
|
||||
block,
|
||||
block.dependencies,
|
||||
this.id,
|
||||
runtimeTemplate
|
||||
);
|
||||
}
|
||||
return this.getSourceForEmptyAsyncContext(this.id);
|
||||
}
|
||||
if (asyncMode === "async-weak") {
|
||||
if (this.dependencies && this.dependencies.length > 0) {
|
||||
return this.getAsyncWeakSource(this.dependencies, this.id);
|
||||
}
|
||||
return this.getSourceForEmptyAsyncContext(this.id);
|
||||
}
|
||||
if (asyncMode === "weak") {
|
||||
if (this.dependencies && this.dependencies.length > 0) {
|
||||
return this.getWeakSyncSource(this.dependencies, this.id);
|
||||
}
|
||||
}
|
||||
if (this.dependencies && this.dependencies.length > 0) {
|
||||
return this.getSyncSource(this.dependencies, this.id);
|
||||
}
|
||||
return this.getSourceForEmptyContext(this.id);
|
||||
}
|
||||
|
||||
getSource(sourceString) {
|
||||
if (this.useSourceMap) {
|
||||
return new OriginalSource(sourceString, this.identifier());
|
||||
}
|
||||
return new RawSource(sourceString);
|
||||
}
|
||||
|
||||
source(dependencyTemplates, runtimeTemplate) {
|
||||
return this.getSource(
|
||||
this.getSourceString(this.options.mode, runtimeTemplate)
|
||||
);
|
||||
}
|
||||
|
||||
size() {
|
||||
// base penalty
|
||||
const initialSize = 160;
|
||||
|
||||
// if we dont have dependencies we stop here.
|
||||
return this.dependencies.reduce((size, dependency) => {
|
||||
const element = /** @type {ContextElementDependency} */ (dependency);
|
||||
return size + 5 + element.userRequest.length;
|
||||
}, initialSize);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO remove in webpack 5
|
||||
Object.defineProperty(ContextModule.prototype, "recursive", {
|
||||
configurable: false,
|
||||
get: util.deprecate(
|
||||
/**
|
||||
* @deprecated
|
||||
* @this {ContextModule}
|
||||
* @returns {boolean} is recursive
|
||||
*/
|
||||
function() {
|
||||
return this.options.recursive;
|
||||
},
|
||||
"ContextModule.recursive has been moved to ContextModule.options.recursive"
|
||||
),
|
||||
set: util.deprecate(
|
||||
/**
|
||||
* @deprecated
|
||||
* @this {ContextModule}
|
||||
* @param {boolean} value is recursive
|
||||
* @returns {void}
|
||||
*/
|
||||
function(value) {
|
||||
this.options.recursive = value;
|
||||
},
|
||||
"ContextModule.recursive has been moved to ContextModule.options.recursive"
|
||||
)
|
||||
});
|
||||
|
||||
// TODO remove in webpack 5
|
||||
Object.defineProperty(ContextModule.prototype, "regExp", {
|
||||
configurable: false,
|
||||
get: util.deprecate(
|
||||
/**
|
||||
* @deprecated
|
||||
* @this {ContextModule}
|
||||
* @returns {RegExp} regular expression
|
||||
*/
|
||||
function() {
|
||||
return this.options.regExp;
|
||||
},
|
||||
"ContextModule.regExp has been moved to ContextModule.options.regExp"
|
||||
),
|
||||
set: util.deprecate(
|
||||
/**
|
||||
* @deprecated
|
||||
* @this {ContextModule}
|
||||
* @param {RegExp} value Regular expression
|
||||
* @returns {void}
|
||||
*/
|
||||
function(value) {
|
||||
this.options.regExp = value;
|
||||
},
|
||||
"ContextModule.regExp has been moved to ContextModule.options.regExp"
|
||||
)
|
||||
});
|
||||
|
||||
// TODO remove in webpack 5
|
||||
Object.defineProperty(ContextModule.prototype, "addon", {
|
||||
configurable: false,
|
||||
get: util.deprecate(
|
||||
/**
|
||||
* @deprecated
|
||||
* @this {ContextModule}
|
||||
* @returns {string} addon
|
||||
*/
|
||||
function() {
|
||||
return this.options.addon;
|
||||
},
|
||||
"ContextModule.addon has been moved to ContextModule.options.addon"
|
||||
),
|
||||
set: util.deprecate(
|
||||
/**
|
||||
* @deprecated
|
||||
* @this {ContextModule}
|
||||
* @param {string} value addon
|
||||
* @returns {void}
|
||||
*/
|
||||
function(value) {
|
||||
this.options.addon = value;
|
||||
},
|
||||
"ContextModule.addon has been moved to ContextModule.options.addon"
|
||||
)
|
||||
});
|
||||
|
||||
// TODO remove in webpack 5
|
||||
Object.defineProperty(ContextModule.prototype, "async", {
|
||||
configurable: false,
|
||||
get: util.deprecate(
|
||||
/**
|
||||
* @deprecated
|
||||
* @this {ContextModule}
|
||||
* @returns {boolean} is async
|
||||
*/
|
||||
function() {
|
||||
return this.options.mode;
|
||||
},
|
||||
"ContextModule.async has been moved to ContextModule.options.mode"
|
||||
),
|
||||
set: util.deprecate(
|
||||
/**
|
||||
* @deprecated
|
||||
* @this {ContextModule}
|
||||
* @param {ContextMode} value Context mode
|
||||
* @returns {void}
|
||||
*/
|
||||
function(value) {
|
||||
this.options.mode = value;
|
||||
},
|
||||
"ContextModule.async has been moved to ContextModule.options.mode"
|
||||
)
|
||||
});
|
||||
|
||||
// TODO remove in webpack 5
|
||||
Object.defineProperty(ContextModule.prototype, "chunkName", {
|
||||
configurable: false,
|
||||
get: util.deprecate(
|
||||
/**
|
||||
* @deprecated
|
||||
* @this {ContextModule}
|
||||
* @returns {string} chunk name
|
||||
*/
|
||||
function() {
|
||||
return this.options.chunkName;
|
||||
},
|
||||
"ContextModule.chunkName has been moved to ContextModule.options.chunkName"
|
||||
),
|
||||
set: util.deprecate(
|
||||
/**
|
||||
* @deprecated
|
||||
* @this {ContextModule}
|
||||
* @param {string} value chunk name
|
||||
* @returns {void}
|
||||
*/
|
||||
function(value) {
|
||||
this.options.chunkName = value;
|
||||
},
|
||||
"ContextModule.chunkName has been moved to ContextModule.options.chunkName"
|
||||
)
|
||||
});
|
||||
|
||||
module.exports = ContextModule;
|
||||
262
node_modules/webpack/lib/ContextModuleFactory.js
generated
vendored
Normal file
262
node_modules/webpack/lib/ContextModuleFactory.js
generated
vendored
Normal file
|
|
@ -0,0 +1,262 @@
|
|||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
"use strict";
|
||||
|
||||
const asyncLib = require("neo-async");
|
||||
const path = require("path");
|
||||
|
||||
const {
|
||||
Tapable,
|
||||
AsyncSeriesWaterfallHook,
|
||||
SyncWaterfallHook
|
||||
} = require("tapable");
|
||||
const ContextModule = require("./ContextModule");
|
||||
const ContextElementDependency = require("./dependencies/ContextElementDependency");
|
||||
|
||||
/** @typedef {import("./Module")} Module */
|
||||
|
||||
const EMPTY_RESOLVE_OPTIONS = {};
|
||||
|
||||
module.exports = class ContextModuleFactory extends Tapable {
|
||||
constructor(resolverFactory) {
|
||||
super();
|
||||
this.hooks = {
|
||||
/** @type {AsyncSeriesWaterfallHook<TODO>} */
|
||||
beforeResolve: new AsyncSeriesWaterfallHook(["data"]),
|
||||
/** @type {AsyncSeriesWaterfallHook<TODO>} */
|
||||
afterResolve: new AsyncSeriesWaterfallHook(["data"]),
|
||||
/** @type {SyncWaterfallHook<string[]>} */
|
||||
contextModuleFiles: new SyncWaterfallHook(["files"]),
|
||||
/** @type {SyncWaterfallHook<TODO[]>} */
|
||||
alternatives: new AsyncSeriesWaterfallHook(["modules"])
|
||||
};
|
||||
this._pluginCompat.tap("ContextModuleFactory", options => {
|
||||
switch (options.name) {
|
||||
case "before-resolve":
|
||||
case "after-resolve":
|
||||
case "alternatives":
|
||||
options.async = true;
|
||||
break;
|
||||
}
|
||||
});
|
||||
this.resolverFactory = resolverFactory;
|
||||
}
|
||||
|
||||
create(data, callback) {
|
||||
const context = data.context;
|
||||
const dependencies = data.dependencies;
|
||||
const resolveOptions = data.resolveOptions;
|
||||
const dependency = dependencies[0];
|
||||
this.hooks.beforeResolve.callAsync(
|
||||
Object.assign(
|
||||
{
|
||||
context: context,
|
||||
dependencies: dependencies,
|
||||
resolveOptions
|
||||
},
|
||||
dependency.options
|
||||
),
|
||||
(err, beforeResolveResult) => {
|
||||
if (err) return callback(err);
|
||||
|
||||
// Ignored
|
||||
if (!beforeResolveResult) return callback();
|
||||
|
||||
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.substr(0, idx + 1);
|
||||
let i;
|
||||
for (
|
||||
i = 0;
|
||||
i < loadersRequest.length && loadersRequest[i] === "!";
|
||||
i++
|
||||
) {
|
||||
loadersPrefix += "!";
|
||||
}
|
||||
loadersRequest = loadersRequest
|
||||
.substr(i)
|
||||
.replace(/!+$/, "")
|
||||
.replace(/!!+/g, "!");
|
||||
if (loadersRequest === "") {
|
||||
loaders = [];
|
||||
} else {
|
||||
loaders = loadersRequest.split("!");
|
||||
}
|
||||
resource = request.substr(idx + 1);
|
||||
} else {
|
||||
loaders = [];
|
||||
resource = request;
|
||||
}
|
||||
|
||||
const contextResolver = this.resolverFactory.get(
|
||||
"context",
|
||||
resolveOptions || EMPTY_RESOLVE_OPTIONS
|
||||
);
|
||||
const loaderResolver = this.resolverFactory.get(
|
||||
"loader",
|
||||
EMPTY_RESOLVE_OPTIONS
|
||||
);
|
||||
|
||||
asyncLib.parallel(
|
||||
[
|
||||
callback => {
|
||||
contextResolver.resolve(
|
||||
{},
|
||||
context,
|
||||
resource,
|
||||
{},
|
||||
(err, result) => {
|
||||
if (err) return callback(err);
|
||||
callback(null, result);
|
||||
}
|
||||
);
|
||||
},
|
||||
callback => {
|
||||
asyncLib.map(
|
||||
loaders,
|
||||
(loader, callback) => {
|
||||
loaderResolver.resolve(
|
||||
{},
|
||||
context,
|
||||
loader,
|
||||
{},
|
||||
(err, result) => {
|
||||
if (err) return callback(err);
|
||||
callback(null, result);
|
||||
}
|
||||
);
|
||||
},
|
||||
callback
|
||||
);
|
||||
}
|
||||
],
|
||||
(err, result) => {
|
||||
if (err) return callback(err);
|
||||
|
||||
this.hooks.afterResolve.callAsync(
|
||||
Object.assign(
|
||||
{
|
||||
addon:
|
||||
loadersPrefix +
|
||||
result[1].join("!") +
|
||||
(result[1].length > 0 ? "!" : ""),
|
||||
resource: result[0],
|
||||
resolveDependencies: this.resolveDependencies.bind(this)
|
||||
},
|
||||
beforeResolveResult
|
||||
),
|
||||
(err, result) => {
|
||||
if (err) return callback(err);
|
||||
|
||||
// Ignored
|
||||
if (!result) return callback();
|
||||
|
||||
return callback(
|
||||
null,
|
||||
new ContextModule(result.resolveDependencies, result)
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
resolveDependencies(fs, options, callback) {
|
||||
const cmf = this;
|
||||
let resource = options.resource;
|
||||
let resourceQuery = options.resourceQuery;
|
||||
let recursive = options.recursive;
|
||||
let regExp = options.regExp;
|
||||
let include = options.include;
|
||||
let exclude = options.exclude;
|
||||
if (!regExp || !resource) return callback(null, []);
|
||||
|
||||
const addDirectory = (directory, callback) => {
|
||||
fs.readdir(directory, (err, files) => {
|
||||
if (err) return callback(err);
|
||||
files = cmf.hooks.contextModuleFiles.call(files);
|
||||
if (!files || files.length === 0) return callback(null, []);
|
||||
asyncLib.map(
|
||||
files.filter(p => p.indexOf(".") !== 0),
|
||||
(segment, callback) => {
|
||||
const subResource = path.join(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();
|
||||
addDirectory.call(this, subResource, callback);
|
||||
} else if (
|
||||
stat.isFile() &&
|
||||
(!include || subResource.match(include))
|
||||
) {
|
||||
const obj = {
|
||||
context: resource,
|
||||
request:
|
||||
"." +
|
||||
subResource.substr(resource.length).replace(/\\/g, "/")
|
||||
};
|
||||
|
||||
this.hooks.alternatives.callAsync(
|
||||
[obj],
|
||||
(err, alternatives) => {
|
||||
if (err) return callback(err);
|
||||
alternatives = alternatives
|
||||
.filter(obj => regExp.test(obj.request))
|
||||
.map(obj => {
|
||||
const dep = new ContextElementDependency(
|
||||
obj.request + resourceQuery,
|
||||
obj.request
|
||||
);
|
||||
dep.optional = true;
|
||||
return dep;
|
||||
});
|
||||
callback(null, alternatives);
|
||||
}
|
||||
);
|
||||
} else {
|
||||
callback();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
callback();
|
||||
}
|
||||
},
|
||||
(err, result) => {
|
||||
if (err) return callback(err);
|
||||
|
||||
if (!result) return callback(null, []);
|
||||
|
||||
callback(
|
||||
null,
|
||||
result.filter(Boolean).reduce((a, i) => a.concat(i), [])
|
||||
);
|
||||
}
|
||||
);
|
||||
});
|
||||
};
|
||||
|
||||
addDirectory(resource, callback);
|
||||
}
|
||||
};
|
||||
133
node_modules/webpack/lib/ContextReplacementPlugin.js
generated
vendored
Normal file
133
node_modules/webpack/lib/ContextReplacementPlugin.js
generated
vendored
Normal file
|
|
@ -0,0 +1,133 @@
|
|||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
"use strict";
|
||||
|
||||
const path = require("path");
|
||||
const ContextElementDependency = require("./dependencies/ContextElementDependency");
|
||||
|
||||
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) {
|
||||
result.resource = path.resolve(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 = path.resolve(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,
|
||||
key
|
||||
);
|
||||
});
|
||||
callback(null, dependencies);
|
||||
});
|
||||
};
|
||||
return resolveDependenciesFromContextMap;
|
||||
};
|
||||
|
||||
module.exports = ContextReplacementPlugin;
|
||||
289
node_modules/webpack/lib/DefinePlugin.js
generated
vendored
Normal file
289
node_modules/webpack/lib/DefinePlugin.js
generated
vendored
Normal file
|
|
@ -0,0 +1,289 @@
|
|||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
"use strict";
|
||||
|
||||
const ConstDependency = require("./dependencies/ConstDependency");
|
||||
const BasicEvaluatedExpression = require("./BasicEvaluatedExpression");
|
||||
const ParserHelpers = require("./ParserHelpers");
|
||||
const NullFactory = require("./NullFactory");
|
||||
|
||||
/** @typedef {import("./Compiler")} Compiler */
|
||||
/** @typedef {import("./Parser")} Parser */
|
||||
/** @typedef {null|undefined|RegExp|Function|string|number} CodeValuePrimitive */
|
||||
/** @typedef {CodeValuePrimitive|Record<string, CodeValuePrimitive>|RuntimeValue} CodeValue */
|
||||
|
||||
class RuntimeValue {
|
||||
constructor(fn, fileDependencies) {
|
||||
this.fn = fn;
|
||||
this.fileDependencies = fileDependencies || [];
|
||||
}
|
||||
|
||||
exec(parser) {
|
||||
if (this.fileDependencies === true) {
|
||||
parser.state.module.buildInfo.cacheable = false;
|
||||
} else {
|
||||
for (const fileDependency of this.fileDependencies) {
|
||||
parser.state.module.buildInfo.fileDependencies.add(fileDependency);
|
||||
}
|
||||
}
|
||||
|
||||
return this.fn({ module: parser.state.module });
|
||||
}
|
||||
}
|
||||
|
||||
const stringifyObj = (obj, parser) => {
|
||||
return (
|
||||
"Object({" +
|
||||
Object.keys(obj)
|
||||
.map(key => {
|
||||
const code = obj[key];
|
||||
return JSON.stringify(key) + ":" + toCode(code, parser);
|
||||
})
|
||||
.join(",") +
|
||||
"})"
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Convert code to a string that evaluates
|
||||
* @param {CodeValue} code Code to evaluate
|
||||
* @param {Parser} parser Parser
|
||||
* @returns {string} code converted to string that evaluates
|
||||
*/
|
||||
const toCode = (code, parser) => {
|
||||
if (code === null) {
|
||||
return "null";
|
||||
}
|
||||
if (code === undefined) {
|
||||
return "undefined";
|
||||
}
|
||||
if (code instanceof RuntimeValue) {
|
||||
return toCode(code.exec(parser), parser);
|
||||
}
|
||||
if (code instanceof RegExp && code.toString) {
|
||||
return code.toString();
|
||||
}
|
||||
if (typeof code === "function" && code.toString) {
|
||||
return "(" + code.toString() + ")";
|
||||
}
|
||||
if (typeof code === "object") {
|
||||
return stringifyObj(code, parser);
|
||||
}
|
||||
return code + "";
|
||||
};
|
||||
|
||||
class DefinePlugin {
|
||||
/**
|
||||
* Create a new define plugin
|
||||
* @param {Record<string, CodeValue>} definitions A map of global object definitions
|
||||
*/
|
||||
constructor(definitions) {
|
||||
this.definitions = definitions;
|
||||
}
|
||||
|
||||
static runtimeValue(fn, fileDependencies) {
|
||||
return new RuntimeValue(fn, fileDependencies);
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply the plugin
|
||||
* @param {Compiler} compiler Webpack compiler
|
||||
* @returns {void}
|
||||
*/
|
||||
apply(compiler) {
|
||||
const definitions = this.definitions;
|
||||
compiler.hooks.compilation.tap(
|
||||
"DefinePlugin",
|
||||
(compilation, { normalModuleFactory }) => {
|
||||
compilation.dependencyFactories.set(ConstDependency, new NullFactory());
|
||||
compilation.dependencyTemplates.set(
|
||||
ConstDependency,
|
||||
new ConstDependency.Template()
|
||||
);
|
||||
|
||||
/**
|
||||
* Handler
|
||||
* @param {Parser} parser Parser
|
||||
* @returns {void}
|
||||
*/
|
||||
const handler = parser => {
|
||||
/**
|
||||
* Walk definitions
|
||||
* @param {Object} definitions Definitions map
|
||||
* @param {string} prefix Prefix string
|
||||
* @returns {void}
|
||||
*/
|
||||
const walkDefinitions = (definitions, prefix) => {
|
||||
Object.keys(definitions).forEach(key => {
|
||||
const code = definitions[key];
|
||||
if (
|
||||
code &&
|
||||
typeof code === "object" &&
|
||||
!(code instanceof RuntimeValue) &&
|
||||
!(code instanceof RegExp)
|
||||
) {
|
||||
walkDefinitions(code, prefix + key + ".");
|
||||
applyObjectDefine(prefix + key, code);
|
||||
return;
|
||||
}
|
||||
applyDefineKey(prefix, key);
|
||||
applyDefine(prefix + key, code);
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Apply define key
|
||||
* @param {string} prefix Prefix
|
||||
* @param {string} key Key
|
||||
* @returns {void}
|
||||
*/
|
||||
const applyDefineKey = (prefix, key) => {
|
||||
const splittedKey = key.split(".");
|
||||
splittedKey.slice(1).forEach((_, i) => {
|
||||
const fullKey = prefix + splittedKey.slice(0, i + 1).join(".");
|
||||
parser.hooks.canRename
|
||||
.for(fullKey)
|
||||
.tap("DefinePlugin", ParserHelpers.approve);
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Apply Code
|
||||
* @param {string} key Key
|
||||
* @param {CodeValue} code Code
|
||||
* @returns {void}
|
||||
*/
|
||||
const applyDefine = (key, code) => {
|
||||
const isTypeof = /^typeof\s+/.test(key);
|
||||
if (isTypeof) key = key.replace(/^typeof\s+/, "");
|
||||
let recurse = false;
|
||||
let recurseTypeof = false;
|
||||
if (!isTypeof) {
|
||||
parser.hooks.canRename
|
||||
.for(key)
|
||||
.tap("DefinePlugin", ParserHelpers.approve);
|
||||
parser.hooks.evaluateIdentifier
|
||||
.for(key)
|
||||
.tap("DefinePlugin", expr => {
|
||||
/**
|
||||
* this is needed in case there is a recursion in the DefinePlugin
|
||||
* to prevent an endless recursion
|
||||
* e.g.: new DefinePlugin({
|
||||
* "a": "b",
|
||||
* "b": "a"
|
||||
* });
|
||||
*/
|
||||
if (recurse) return;
|
||||
recurse = true;
|
||||
const res = parser.evaluate(toCode(code, parser));
|
||||
recurse = false;
|
||||
res.setRange(expr.range);
|
||||
return res;
|
||||
});
|
||||
parser.hooks.expression.for(key).tap("DefinePlugin", expr => {
|
||||
const strCode = toCode(code, parser);
|
||||
if (/__webpack_require__/.test(strCode)) {
|
||||
return ParserHelpers.toConstantDependencyWithWebpackRequire(
|
||||
parser,
|
||||
strCode
|
||||
)(expr);
|
||||
} else {
|
||||
return ParserHelpers.toConstantDependency(
|
||||
parser,
|
||||
strCode
|
||||
)(expr);
|
||||
}
|
||||
});
|
||||
}
|
||||
parser.hooks.evaluateTypeof.for(key).tap("DefinePlugin", expr => {
|
||||
/**
|
||||
* this is needed in case there is a recursion in the DefinePlugin
|
||||
* to prevent an endless recursion
|
||||
* e.g.: new DefinePlugin({
|
||||
* "typeof a": "typeof b",
|
||||
* "typeof b": "typeof a"
|
||||
* });
|
||||
*/
|
||||
if (recurseTypeof) return;
|
||||
recurseTypeof = true;
|
||||
const typeofCode = isTypeof
|
||||
? toCode(code, parser)
|
||||
: "typeof (" + toCode(code, parser) + ")";
|
||||
const res = parser.evaluate(typeofCode);
|
||||
recurseTypeof = false;
|
||||
res.setRange(expr.range);
|
||||
return res;
|
||||
});
|
||||
parser.hooks.typeof.for(key).tap("DefinePlugin", expr => {
|
||||
const typeofCode = isTypeof
|
||||
? toCode(code, parser)
|
||||
: "typeof (" + toCode(code, parser) + ")";
|
||||
const res = parser.evaluate(typeofCode);
|
||||
if (!res.isString()) return;
|
||||
return ParserHelpers.toConstantDependency(
|
||||
parser,
|
||||
JSON.stringify(res.string)
|
||||
).bind(parser)(expr);
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Apply Object
|
||||
* @param {string} key Key
|
||||
* @param {Object} obj Object
|
||||
* @returns {void}
|
||||
*/
|
||||
const applyObjectDefine = (key, obj) => {
|
||||
parser.hooks.canRename
|
||||
.for(key)
|
||||
.tap("DefinePlugin", ParserHelpers.approve);
|
||||
parser.hooks.evaluateIdentifier
|
||||
.for(key)
|
||||
.tap("DefinePlugin", expr =>
|
||||
new BasicEvaluatedExpression().setTruthy().setRange(expr.range)
|
||||
);
|
||||
parser.hooks.evaluateTypeof.for(key).tap("DefinePlugin", expr => {
|
||||
return ParserHelpers.evaluateToString("object")(expr);
|
||||
});
|
||||
parser.hooks.expression.for(key).tap("DefinePlugin", expr => {
|
||||
const strCode = stringifyObj(obj, parser);
|
||||
|
||||
if (/__webpack_require__/.test(strCode)) {
|
||||
return ParserHelpers.toConstantDependencyWithWebpackRequire(
|
||||
parser,
|
||||
strCode
|
||||
)(expr);
|
||||
} else {
|
||||
return ParserHelpers.toConstantDependency(
|
||||
parser,
|
||||
strCode
|
||||
)(expr);
|
||||
}
|
||||
});
|
||||
parser.hooks.typeof.for(key).tap("DefinePlugin", expr => {
|
||||
return ParserHelpers.toConstantDependency(
|
||||
parser,
|
||||
JSON.stringify("object")
|
||||
)(expr);
|
||||
});
|
||||
};
|
||||
|
||||
walkDefinitions(definitions, "");
|
||||
};
|
||||
|
||||
normalModuleFactory.hooks.parser
|
||||
.for("javascript/auto")
|
||||
.tap("DefinePlugin", handler);
|
||||
normalModuleFactory.hooks.parser
|
||||
.for("javascript/dynamic")
|
||||
.tap("DefinePlugin", handler);
|
||||
normalModuleFactory.hooks.parser
|
||||
.for("javascript/esm")
|
||||
.tap("DefinePlugin", handler);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
module.exports = DefinePlugin;
|
||||
114
node_modules/webpack/lib/DelegatedModule.js
generated
vendored
Normal file
114
node_modules/webpack/lib/DelegatedModule.js
generated
vendored
Normal file
|
|
@ -0,0 +1,114 @@
|
|||
/*
|
||||
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 WebpackMissingModule = require("./dependencies/WebpackMissingModule");
|
||||
const DelegatedSourceDependency = require("./dependencies/DelegatedSourceDependency");
|
||||
const DelegatedExportsDependency = require("./dependencies/DelegatedExportsDependency");
|
||||
|
||||
/** @typedef {import("./dependencies/ModuleDependency")} ModuleDependency */
|
||||
/** @typedef {import("./util/createHash").Hash} Hash */
|
||||
|
||||
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.type = type;
|
||||
this.userRequest = userRequest;
|
||||
this.originalRequest = originalRequest;
|
||||
this.delegateData = data;
|
||||
|
||||
// Build info
|
||||
this.delegatedSourceDependency = undefined;
|
||||
}
|
||||
|
||||
libIdent(options) {
|
||||
return typeof this.originalRequest === "string"
|
||||
? this.originalRequest
|
||||
: this.originalRequest.libIdent(options);
|
||||
}
|
||||
|
||||
identifier() {
|
||||
return `delegated ${JSON.stringify(this.request)} from ${
|
||||
this.sourceRequest
|
||||
}`;
|
||||
}
|
||||
|
||||
readableIdentifier() {
|
||||
return `delegated ${this.userRequest} from ${this.sourceRequest}`;
|
||||
}
|
||||
|
||||
needRebuild() {
|
||||
return false;
|
||||
}
|
||||
|
||||
build(options, compilation, resolver, fs, callback) {
|
||||
this.built = true;
|
||||
this.buildMeta = Object.assign({}, this.delegateData.buildMeta);
|
||||
this.buildInfo = {};
|
||||
this.delegatedSourceDependency = new DelegatedSourceDependency(
|
||||
this.sourceRequest
|
||||
);
|
||||
this.addDependency(this.delegatedSourceDependency);
|
||||
this.addDependency(
|
||||
new DelegatedExportsDependency(this, this.delegateData.exports || true)
|
||||
);
|
||||
callback();
|
||||
}
|
||||
|
||||
source(depTemplates, runtime) {
|
||||
const dep = /** @type {DelegatedSourceDependency} */ (this.dependencies[0]);
|
||||
const sourceModule = dep.module;
|
||||
let str;
|
||||
|
||||
if (!sourceModule) {
|
||||
str = WebpackMissingModule.moduleCode(this.sourceRequest);
|
||||
} else {
|
||||
str = `module.exports = (${runtime.moduleExports({
|
||||
module: sourceModule,
|
||||
request: dep.request
|
||||
})})`;
|
||||
|
||||
switch (this.type) {
|
||||
case "require":
|
||||
str += `(${JSON.stringify(this.request)})`;
|
||||
break;
|
||||
case "object":
|
||||
str += `[${JSON.stringify(this.request)}]`;
|
||||
break;
|
||||
}
|
||||
|
||||
str += ";";
|
||||
}
|
||||
|
||||
if (this.useSourceMap) {
|
||||
return new OriginalSource(str, this.identifier());
|
||||
} else {
|
||||
return new RawSource(str);
|
||||
}
|
||||
}
|
||||
|
||||
size() {
|
||||
return 42;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Hash} hash the hash used to track dependencies
|
||||
* @returns {void}
|
||||
*/
|
||||
updateHash(hash) {
|
||||
hash.update(this.type);
|
||||
hash.update(JSON.stringify(this.request));
|
||||
super.updateHash(hash);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = DelegatedModule;
|
||||
95
node_modules/webpack/lib/DelegatedModuleFactoryPlugin.js
generated
vendored
Normal file
95
node_modules/webpack/lib/DelegatedModuleFactoryPlugin.js
generated
vendored
Normal file
|
|
@ -0,0 +1,95 @@
|
|||
/*
|
||||
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
|
||||
class DelegatedModuleFactoryPlugin {
|
||||
constructor(options) {
|
||||
this.options = options;
|
||||
options.type = options.type || "require";
|
||||
options.extensions = options.extensions || [
|
||||
"",
|
||||
".wasm",
|
||||
".mjs",
|
||||
".js",
|
||||
".json"
|
||||
];
|
||||
}
|
||||
|
||||
apply(normalModuleFactory) {
|
||||
const scope = this.options.scope;
|
||||
if (scope) {
|
||||
normalModuleFactory.hooks.factory.tap(
|
||||
"DelegatedModuleFactoryPlugin",
|
||||
factory => (data, callback) => {
|
||||
const dependency = data.dependencies[0];
|
||||
const request = dependency.request;
|
||||
if (request && request.indexOf(scope + "/") === 0) {
|
||||
const innerRequest = "." + request.substr(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 factory(data, callback);
|
||||
}
|
||||
);
|
||||
} else {
|
||||
normalModuleFactory.hooks.module.tap(
|
||||
"DelegatedModuleFactoryPlugin",
|
||||
module => {
|
||||
if (module.libIdent) {
|
||||
const request = module.libIdent(this.options);
|
||||
if (request && 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;
|
||||
39
node_modules/webpack/lib/DelegatedPlugin.js
generated
vendored
Normal file
39
node_modules/webpack/lib/DelegatedPlugin.js
generated
vendored
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
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");
|
||||
const DelegatedExportsDependency = require("./dependencies/DelegatedExportsDependency");
|
||||
const NullFactory = require("./NullFactory");
|
||||
|
||||
class DelegatedPlugin {
|
||||
constructor(options) {
|
||||
this.options = options;
|
||||
}
|
||||
|
||||
apply(compiler) {
|
||||
compiler.hooks.compilation.tap(
|
||||
"DelegatedPlugin",
|
||||
(compilation, { normalModuleFactory }) => {
|
||||
compilation.dependencyFactories.set(
|
||||
DelegatedSourceDependency,
|
||||
normalModuleFactory
|
||||
);
|
||||
compilation.dependencyFactories.set(
|
||||
DelegatedExportsDependency,
|
||||
new NullFactory()
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
compiler.hooks.compile.tap("DelegatedPlugin", ({ normalModuleFactory }) => {
|
||||
new DelegatedModuleFactoryPlugin(this.options).apply(normalModuleFactory);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = DelegatedPlugin;
|
||||
124
node_modules/webpack/lib/DependenciesBlock.js
generated
vendored
Normal file
124
node_modules/webpack/lib/DependenciesBlock.js
generated
vendored
Normal file
|
|
@ -0,0 +1,124 @@
|
|||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
"use strict";
|
||||
|
||||
const DependenciesBlockVariable = require("./DependenciesBlockVariable");
|
||||
|
||||
/** @typedef {import("./ChunkGroup")} ChunkGroup */
|
||||
/** @typedef {import("./Dependency")} Dependency */
|
||||
/** @typedef {import("./AsyncDependenciesBlock")} AsyncDependenciesBlock */
|
||||
/** @typedef {import("./DependenciesBlockVariable")} DependenciesBlockVariable */
|
||||
/** @typedef {(d: Dependency) => boolean} DependencyFilterFunction */
|
||||
/** @typedef {import("./util/createHash").Hash} Hash */
|
||||
|
||||
class DependenciesBlock {
|
||||
constructor() {
|
||||
/** @type {Dependency[]} */
|
||||
this.dependencies = [];
|
||||
/** @type {AsyncDependenciesBlock[]} */
|
||||
this.blocks = [];
|
||||
/** @type {DependenciesBlockVariable[]} */
|
||||
this.variables = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 {string} name name of dependency
|
||||
* @param {string} expression expression string for variable
|
||||
* @param {Dependency[]} dependencies dependency instances tied to variable
|
||||
* @returns {void}
|
||||
*/
|
||||
addVariable(name, expression, dependencies) {
|
||||
for (let v of this.variables) {
|
||||
if (v.name === name && v.expression === expression) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
this.variables.push(
|
||||
new DependenciesBlockVariable(name, expression, dependencies)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Hash} hash the hash used to track dependencies
|
||||
* @returns {void}
|
||||
*/
|
||||
updateHash(hash) {
|
||||
for (const dep of this.dependencies) dep.updateHash(hash);
|
||||
for (const block of this.blocks) block.updateHash(hash);
|
||||
for (const variable of this.variables) variable.updateHash(hash);
|
||||
}
|
||||
|
||||
disconnect() {
|
||||
for (const dep of this.dependencies) dep.disconnect();
|
||||
for (const block of this.blocks) block.disconnect();
|
||||
for (const variable of this.variables) variable.disconnect();
|
||||
}
|
||||
|
||||
unseal() {
|
||||
for (const block of this.blocks) block.unseal();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {DependencyFilterFunction} filter filter function for dependencies, gets passed all dependency ties from current instance
|
||||
* @returns {boolean} returns boolean for filter
|
||||
*/
|
||||
hasDependencies(filter) {
|
||||
if (filter) {
|
||||
for (const dep of this.dependencies) {
|
||||
if (filter(dep)) return true;
|
||||
}
|
||||
} else {
|
||||
if (this.dependencies.length > 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
for (const block of this.blocks) {
|
||||
if (block.hasDependencies(filter)) return true;
|
||||
}
|
||||
for (const variable of this.variables) {
|
||||
if (variable.hasDependencies(filter)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
sortItems() {
|
||||
for (const block of this.blocks) block.sortItems();
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = DependenciesBlock;
|
||||
72
node_modules/webpack/lib/DependenciesBlockVariable.js
generated
vendored
Normal file
72
node_modules/webpack/lib/DependenciesBlockVariable.js
generated
vendored
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
"use strict";
|
||||
|
||||
const { RawSource, ReplaceSource } = require("webpack-sources");
|
||||
|
||||
/** @typedef {import("./Dependency")} Dependency */
|
||||
/** @typedef {import("./Dependency").DependencyTemplate} DependencyTemplate */
|
||||
/** @typedef {import("./RuntimeTemplate")} RuntimeTemplate */
|
||||
/** @typedef {import("./util/createHash").Hash} Hash */
|
||||
/** @typedef {(d: Dependency) => boolean} DependencyFilterFunction */
|
||||
/** @typedef {Map<Function, DependencyTemplate>} DependencyTemplates */
|
||||
|
||||
class DependenciesBlockVariable {
|
||||
/**
|
||||
* Creates an instance of DependenciesBlockVariable.
|
||||
* @param {string} name name of DependenciesBlockVariable
|
||||
* @param {string} expression expression string
|
||||
* @param {Dependency[]=} dependencies dependencies tied to this varaiable
|
||||
*/
|
||||
constructor(name, expression, dependencies) {
|
||||
this.name = name;
|
||||
this.expression = expression;
|
||||
this.dependencies = dependencies || [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Hash} hash hash for instance to update
|
||||
* @returns {void}
|
||||
*/
|
||||
updateHash(hash) {
|
||||
hash.update(this.name);
|
||||
hash.update(this.expression);
|
||||
for (const d of this.dependencies) {
|
||||
d.updateHash(hash);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {DependencyTemplates} dependencyTemplates Dependency constructors and templates Map.
|
||||
* @param {RuntimeTemplate} runtimeTemplate runtimeTemplate to generate expression souce
|
||||
* @returns {ReplaceSource} returns constructed source for expression via templates
|
||||
*/
|
||||
expressionSource(dependencyTemplates, runtimeTemplate) {
|
||||
const source = new ReplaceSource(new RawSource(this.expression));
|
||||
for (const dep of this.dependencies) {
|
||||
const template = dependencyTemplates.get(dep.constructor);
|
||||
if (!template) {
|
||||
throw new Error(`No template for dependency: ${dep.constructor.name}`);
|
||||
}
|
||||
template.apply(dep, source, runtimeTemplate, dependencyTemplates);
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
disconnect() {
|
||||
for (const d of this.dependencies) {
|
||||
d.disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
hasDependencies(filter) {
|
||||
if (filter) {
|
||||
return this.dependencies.some(filter);
|
||||
}
|
||||
return this.dependencies.length > 0;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = DependenciesBlockVariable;
|
||||
89
node_modules/webpack/lib/Dependency.js
generated
vendored
Normal file
89
node_modules/webpack/lib/Dependency.js
generated
vendored
Normal file
|
|
@ -0,0 +1,89 @@
|
|||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
"use strict";
|
||||
|
||||
const util = require("util");
|
||||
const compareLocations = require("./compareLocations");
|
||||
const DependencyReference = require("./dependencies/DependencyReference");
|
||||
|
||||
/** @typedef {import("./Module")} Module */
|
||||
/** @typedef {import("webpack-sources").Source} Source */
|
||||
/** @typedef {import("./RuntimeTemplate")} RuntimeTemplate */
|
||||
|
||||
/**
|
||||
* @typedef {Object} DependencyTemplate
|
||||
* @property {function(Dependency, Source, RuntimeTemplate, Map<Function, DependencyTemplate>): void} apply
|
||||
*/
|
||||
|
||||
/** @typedef {Object} SourcePosition
|
||||
* @property {number} line
|
||||
* @property {number=} column
|
||||
*/
|
||||
|
||||
/** @typedef {Object} RealDependencyLocation
|
||||
* @property {SourcePosition} start
|
||||
* @property {SourcePosition=} end
|
||||
* @property {number=} index
|
||||
*/
|
||||
|
||||
/** @typedef {Object} SynteticDependencyLocation
|
||||
* @property {string} name
|
||||
* @property {number=} index
|
||||
*/
|
||||
|
||||
/** @typedef {SynteticDependencyLocation|RealDependencyLocation} DependencyLocation */
|
||||
|
||||
class Dependency {
|
||||
constructor() {
|
||||
/** @type {Module|null} */
|
||||
this.module = null;
|
||||
// TODO remove in webpack 5
|
||||
/** @type {boolean} */
|
||||
this.weak = false;
|
||||
/** @type {boolean} */
|
||||
this.optional = false;
|
||||
/** @type {DependencyLocation} */
|
||||
this.loc = undefined;
|
||||
}
|
||||
|
||||
getResourceIdentifier() {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Returns the referenced module and export
|
||||
getReference() {
|
||||
if (!this.module) return null;
|
||||
return new DependencyReference(this.module, true, this.weak);
|
||||
}
|
||||
|
||||
// Returns the exported names
|
||||
getExports() {
|
||||
return null;
|
||||
}
|
||||
|
||||
getWarnings() {
|
||||
return null;
|
||||
}
|
||||
|
||||
getErrors() {
|
||||
return null;
|
||||
}
|
||||
|
||||
updateHash(hash) {
|
||||
hash.update((this.module && this.module.id) + "");
|
||||
}
|
||||
|
||||
disconnect() {
|
||||
this.module = null;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO remove in webpack 5
|
||||
Dependency.compare = util.deprecate(
|
||||
(a, b) => compareLocations(a.loc, b.loc),
|
||||
"Dependency.compare is deprecated and will be removed in the next major version"
|
||||
);
|
||||
|
||||
module.exports = Dependency;
|
||||
54
node_modules/webpack/lib/DllEntryPlugin.js
generated
vendored
Normal file
54
node_modules/webpack/lib/DllEntryPlugin.js
generated
vendored
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
"use strict";
|
||||
|
||||
const DllEntryDependency = require("./dependencies/DllEntryDependency");
|
||||
const SingleEntryDependency = require("./dependencies/SingleEntryDependency");
|
||||
const DllModuleFactory = require("./DllModuleFactory");
|
||||
|
||||
class DllEntryPlugin {
|
||||
constructor(context, entries, name) {
|
||||
this.context = context;
|
||||
this.entries = entries;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
apply(compiler) {
|
||||
compiler.hooks.compilation.tap(
|
||||
"DllEntryPlugin",
|
||||
(compilation, { normalModuleFactory }) => {
|
||||
const dllModuleFactory = new DllModuleFactory();
|
||||
compilation.dependencyFactories.set(
|
||||
DllEntryDependency,
|
||||
dllModuleFactory
|
||||
);
|
||||
compilation.dependencyFactories.set(
|
||||
SingleEntryDependency,
|
||||
normalModuleFactory
|
||||
);
|
||||
}
|
||||
);
|
||||
compiler.hooks.make.tapAsync("DllEntryPlugin", (compilation, callback) => {
|
||||
compilation.addEntry(
|
||||
this.context,
|
||||
new DllEntryDependency(
|
||||
this.entries.map((e, idx) => {
|
||||
const dep = new SingleEntryDependency(e);
|
||||
dep.loc = {
|
||||
name: this.name,
|
||||
index: idx
|
||||
};
|
||||
return dep;
|
||||
}),
|
||||
this.name
|
||||
),
|
||||
this.name,
|
||||
callback
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = DllEntryPlugin;
|
||||
60
node_modules/webpack/lib/DllModule.js
generated
vendored
Normal file
60
node_modules/webpack/lib/DllModule.js
generated
vendored
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
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");
|
||||
|
||||
/** @typedef {import("./util/createHash").Hash} Hash */
|
||||
|
||||
class DllModule extends Module {
|
||||
constructor(context, dependencies, name, type) {
|
||||
super("javascript/dynamic", context);
|
||||
|
||||
// Info from Factory
|
||||
this.dependencies = dependencies;
|
||||
this.name = name;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
identifier() {
|
||||
return `dll ${this.name}`;
|
||||
}
|
||||
|
||||
readableIdentifier() {
|
||||
return `dll ${this.name}`;
|
||||
}
|
||||
|
||||
build(options, compilation, resolver, fs, callback) {
|
||||
this.built = true;
|
||||
this.buildMeta = {};
|
||||
this.buildInfo = {};
|
||||
return callback();
|
||||
}
|
||||
|
||||
source() {
|
||||
return new RawSource("module.exports = __webpack_require__;");
|
||||
}
|
||||
|
||||
needRebuild() {
|
||||
return false;
|
||||
}
|
||||
|
||||
size() {
|
||||
return 12;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Hash} hash the hash used to track dependencies
|
||||
* @returns {void}
|
||||
*/
|
||||
updateHash(hash) {
|
||||
hash.update("dll module");
|
||||
hash.update(this.name || "");
|
||||
super.updateHash(hash);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = DllModule;
|
||||
29
node_modules/webpack/lib/DllModuleFactory.js
generated
vendored
Normal file
29
node_modules/webpack/lib/DllModuleFactory.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 { Tapable } = require("tapable");
|
||||
const DllModule = require("./DllModule");
|
||||
|
||||
class DllModuleFactory extends Tapable {
|
||||
constructor() {
|
||||
super();
|
||||
this.hooks = {};
|
||||
}
|
||||
create(data, callback) {
|
||||
const dependency = data.dependencies[0];
|
||||
callback(
|
||||
null,
|
||||
new DllModule(
|
||||
data.context,
|
||||
dependency.dependencies,
|
||||
dependency.name,
|
||||
dependency.type
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = DllModuleFactory;
|
||||
49
node_modules/webpack/lib/DllPlugin.js
generated
vendored
Normal file
49
node_modules/webpack/lib/DllPlugin.js
generated
vendored
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
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 validateOptions = require("schema-utils");
|
||||
const schema = require("../schemas/plugins/DllPlugin.json");
|
||||
|
||||
/** @typedef {import("../declarations/plugins/DllPlugin").DllPluginOptions} DllPluginOptions */
|
||||
|
||||
class DllPlugin {
|
||||
/**
|
||||
* @param {DllPluginOptions} options options object
|
||||
*/
|
||||
constructor(options) {
|
||||
validateOptions(schema, options, "Dll Plugin");
|
||||
this.options = options;
|
||||
}
|
||||
|
||||
apply(compiler) {
|
||||
compiler.hooks.entryOption.tap("DllPlugin", (context, entry) => {
|
||||
const itemToPlugin = (item, name) => {
|
||||
if (Array.isArray(item)) {
|
||||
return new DllEntryPlugin(context, item, name);
|
||||
}
|
||||
throw new Error("DllPlugin: supply an Array as entry");
|
||||
};
|
||||
if (typeof entry === "object" && !Array.isArray(entry)) {
|
||||
Object.keys(entry).forEach(name => {
|
||||
itemToPlugin(entry[name], name).apply(compiler);
|
||||
});
|
||||
} else {
|
||||
itemToPlugin(entry, "main").apply(compiler);
|
||||
}
|
||||
return true;
|
||||
});
|
||||
new LibManifestPlugin(this.options).apply(compiler);
|
||||
if (!this.options.entryOnly) {
|
||||
new FlagAllModulesAsUsedPlugin("DllPlugin").apply(compiler);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = DllPlugin;
|
||||
156
node_modules/webpack/lib/DllReferencePlugin.js
generated
vendored
Normal file
156
node_modules/webpack/lib/DllReferencePlugin.js
generated
vendored
Normal file
|
|
@ -0,0 +1,156 @@
|
|||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
"use strict";
|
||||
|
||||
const parseJson = require("json-parse-better-errors");
|
||||
const DelegatedSourceDependency = require("./dependencies/DelegatedSourceDependency");
|
||||
const DelegatedModuleFactoryPlugin = require("./DelegatedModuleFactoryPlugin");
|
||||
const ExternalModuleFactoryPlugin = require("./ExternalModuleFactoryPlugin");
|
||||
const DelegatedExportsDependency = require("./dependencies/DelegatedExportsDependency");
|
||||
const NullFactory = require("./NullFactory");
|
||||
const makePathsRelative = require("./util/identifier").makePathsRelative;
|
||||
const WebpackError = require("./WebpackError");
|
||||
|
||||
const validateOptions = require("schema-utils");
|
||||
const schema = require("../schemas/plugins/DllReferencePlugin.json");
|
||||
|
||||
/** @typedef {import("../declarations/plugins/DllReferencePlugin").DllReferencePluginOptions} DllReferencePluginOptions */
|
||||
/** @typedef {import("../declarations/plugins/DllReferencePlugin").DllReferencePluginOptionsManifest} DllReferencePluginOptionsManifest */
|
||||
|
||||
class DllReferencePlugin {
|
||||
/**
|
||||
* @param {DllReferencePluginOptions} options options object
|
||||
*/
|
||||
constructor(options) {
|
||||
validateOptions(schema, options, "Dll Reference Plugin");
|
||||
this.options = options;
|
||||
}
|
||||
|
||||
apply(compiler) {
|
||||
compiler.hooks.compilation.tap(
|
||||
"DllReferencePlugin",
|
||||
(compilation, { normalModuleFactory }) => {
|
||||
compilation.dependencyFactories.set(
|
||||
DelegatedSourceDependency,
|
||||
normalModuleFactory
|
||||
);
|
||||
compilation.dependencyFactories.set(
|
||||
DelegatedExportsDependency,
|
||||
new NullFactory()
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
compiler.hooks.beforeCompile.tapAsync(
|
||||
"DllReferencePlugin",
|
||||
(params, callback) => {
|
||||
if ("manifest" in this.options) {
|
||||
const manifest = this.options.manifest;
|
||||
if (typeof manifest === "string") {
|
||||
params.compilationDependencies.add(manifest);
|
||||
compiler.inputFileSystem.readFile(manifest, (err, result) => {
|
||||
if (err) return callback(err);
|
||||
// Catch errors parsing the manifest so that blank
|
||||
// or malformed manifest files don't kill the process.
|
||||
try {
|
||||
params["dll reference " + manifest] = 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
|
||||
);
|
||||
params[
|
||||
"dll reference parse error " + manifest
|
||||
] = new DllManifestError(manifestPath, e.message);
|
||||
}
|
||||
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") {
|
||||
// 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 (params["dll reference parse error " + manifestParameter]) {
|
||||
return;
|
||||
}
|
||||
manifest =
|
||||
/** @type {DllReferencePluginOptionsManifest} */ (params[
|
||||
"dll reference " + manifestParameter
|
||||
]);
|
||||
} else {
|
||||
manifest = manifestParameter;
|
||||
}
|
||||
if (manifest) {
|
||||
if (!name) name = manifest.name;
|
||||
if (!sourceType) sourceType = manifest.type;
|
||||
if (!content) content = manifest.content;
|
||||
}
|
||||
}
|
||||
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
|
||||
}).apply(normalModuleFactory);
|
||||
});
|
||||
|
||||
compiler.hooks.compilation.tap(
|
||||
"DllReferencePlugin",
|
||||
(compilation, params) => {
|
||||
if ("manifest" in this.options) {
|
||||
let manifest = this.options.manifest;
|
||||
if (typeof manifest === "string") {
|
||||
// If there was an error parsing the manifest file, add the
|
||||
// error as a compilation error to make the compilation fail.
|
||||
let e = params["dll reference parse error " + manifest];
|
||||
if (e) {
|
||||
compilation.errors.push(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class DllManifestError extends WebpackError {
|
||||
constructor(filename, message) {
|
||||
super();
|
||||
|
||||
this.name = "DllManifestError";
|
||||
this.message = `Dll manifest ${filename}\n${message}`;
|
||||
|
||||
Error.captureStackTrace(this, this.constructor);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = DllReferencePlugin;
|
||||
94
node_modules/webpack/lib/DynamicEntryPlugin.js
generated
vendored
Normal file
94
node_modules/webpack/lib/DynamicEntryPlugin.js
generated
vendored
Normal file
|
|
@ -0,0 +1,94 @@
|
|||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Naoyuki Kanezawa @nkzawa
|
||||
*/
|
||||
"use strict";
|
||||
|
||||
const MultiEntryDependency = require("./dependencies/MultiEntryDependency");
|
||||
const SingleEntryDependency = require("./dependencies/SingleEntryDependency");
|
||||
const MultiModuleFactory = require("./MultiModuleFactory");
|
||||
const MultiEntryPlugin = require("./MultiEntryPlugin");
|
||||
const SingleEntryPlugin = require("./SingleEntryPlugin");
|
||||
|
||||
/** @typedef {import("../declarations/WebpackOptions").EntryDynamic} EntryDynamic */
|
||||
/** @typedef {import("../declarations/WebpackOptions").EntryStatic} 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Compiler} compiler the compiler instance
|
||||
* @returns {void}
|
||||
*/
|
||||
apply(compiler) {
|
||||
compiler.hooks.compilation.tap(
|
||||
"DynamicEntryPlugin",
|
||||
(compilation, { normalModuleFactory }) => {
|
||||
const multiModuleFactory = new MultiModuleFactory();
|
||||
|
||||
compilation.dependencyFactories.set(
|
||||
MultiEntryDependency,
|
||||
multiModuleFactory
|
||||
);
|
||||
compilation.dependencyFactories.set(
|
||||
SingleEntryDependency,
|
||||
normalModuleFactory
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
compiler.hooks.make.tapAsync(
|
||||
"DynamicEntryPlugin",
|
||||
(compilation, callback) => {
|
||||
/**
|
||||
* @param {string|string[]} entry entry value or array of entry values
|
||||
* @param {string} name name of entry
|
||||
* @returns {Promise<EntryStatic>} returns the promise resolving the Compilation#addEntry function
|
||||
*/
|
||||
const addEntry = (entry, name) => {
|
||||
const dep = DynamicEntryPlugin.createDependency(entry, name);
|
||||
return new Promise((resolve, reject) => {
|
||||
compilation.addEntry(this.context, dep, name, err => {
|
||||
if (err) return reject(err);
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
Promise.resolve(this.entry()).then(entry => {
|
||||
if (typeof entry === "string" || Array.isArray(entry)) {
|
||||
addEntry(entry, "main").then(() => callback(), callback);
|
||||
} else if (typeof entry === "object") {
|
||||
Promise.all(
|
||||
Object.keys(entry).map(name => {
|
||||
return addEntry(entry[name], name);
|
||||
})
|
||||
).then(() => callback(), callback);
|
||||
}
|
||||
});
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = DynamicEntryPlugin;
|
||||
/**
|
||||
* @param {string|string[]} entry entry value or array of entry paths
|
||||
* @param {string} name name of entry
|
||||
* @returns {SingleEntryDependency|MultiEntryDependency} returns dep
|
||||
*/
|
||||
DynamicEntryPlugin.createDependency = (entry, name) => {
|
||||
if (Array.isArray(entry)) {
|
||||
return MultiEntryPlugin.createDependency(entry, name);
|
||||
} else {
|
||||
return SingleEntryPlugin.createDependency(entry, name);
|
||||
}
|
||||
};
|
||||
21
node_modules/webpack/lib/EntryModuleNotFoundError.js
generated
vendored
Normal file
21
node_modules/webpack/lib/EntryModuleNotFoundError.js
generated
vendored
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
"use strict";
|
||||
|
||||
const WebpackError = require("./WebpackError");
|
||||
|
||||
class EntryModuleNotFoundError extends WebpackError {
|
||||
constructor(err) {
|
||||
super("Entry module not found: " + err);
|
||||
|
||||
this.name = "EntryModuleNotFoundError";
|
||||
this.details = err.details;
|
||||
this.error = err;
|
||||
|
||||
Error.captureStackTrace(this, this.constructor);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = EntryModuleNotFoundError;
|
||||
46
node_modules/webpack/lib/EntryOptionPlugin.js
generated
vendored
Normal file
46
node_modules/webpack/lib/EntryOptionPlugin.js
generated
vendored
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
"use strict";
|
||||
|
||||
const SingleEntryPlugin = require("./SingleEntryPlugin");
|
||||
const MultiEntryPlugin = require("./MultiEntryPlugin");
|
||||
const DynamicEntryPlugin = require("./DynamicEntryPlugin");
|
||||
|
||||
/** @typedef {import("../declarations/WebpackOptions").EntryItem} EntryItem */
|
||||
/** @typedef {import("./Compiler")} Compiler */
|
||||
|
||||
/**
|
||||
* @param {string} context context path
|
||||
* @param {EntryItem} item entry array or single path
|
||||
* @param {string} name entry key name
|
||||
* @returns {SingleEntryPlugin | MultiEntryPlugin} returns either a single or multi entry plugin
|
||||
*/
|
||||
const itemToPlugin = (context, item, name) => {
|
||||
if (Array.isArray(item)) {
|
||||
return new MultiEntryPlugin(context, item, name);
|
||||
}
|
||||
return new SingleEntryPlugin(context, item, name);
|
||||
};
|
||||
|
||||
module.exports = class EntryOptionPlugin {
|
||||
/**
|
||||
* @param {Compiler} compiler the compiler instance one is tapping into
|
||||
* @returns {void}
|
||||
*/
|
||||
apply(compiler) {
|
||||
compiler.hooks.entryOption.tap("EntryOptionPlugin", (context, entry) => {
|
||||
if (typeof entry === "string" || Array.isArray(entry)) {
|
||||
itemToPlugin(context, entry, "main").apply(compiler);
|
||||
} else if (typeof entry === "object") {
|
||||
for (const name of Object.keys(entry)) {
|
||||
itemToPlugin(context, entry[name], name).apply(compiler);
|
||||
}
|
||||
} else if (typeof entry === "function") {
|
||||
new DynamicEntryPlugin(context, entry).apply(compiler);
|
||||
}
|
||||
return true;
|
||||
});
|
||||
}
|
||||
};
|
||||
64
node_modules/webpack/lib/Entrypoint.js
generated
vendored
Normal file
64
node_modules/webpack/lib/Entrypoint.js
generated
vendored
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
"use strict";
|
||||
|
||||
const ChunkGroup = require("./ChunkGroup");
|
||||
|
||||
/** @typedef {import("./Chunk")} Chunk */
|
||||
|
||||
/**
|
||||
* 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 {string} name the name of the entrypoint
|
||||
*/
|
||||
constructor(name) {
|
||||
super(name);
|
||||
/** @type {Chunk=} */
|
||||
this.runtimeChunk = undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* isInitial will always return true for Entrypoint ChunkGroup.
|
||||
* @returns {true} returns true as all entrypoints are initial ChunkGroups
|
||||
*/
|
||||
isInitial() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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} returns the runtime chunk or first chunk in `this.chunks`
|
||||
*/
|
||||
getRuntimeChunk() {
|
||||
return this.runtimeChunk || this.chunks[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* @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;
|
||||
return super.replaceChunk(oldChunk, newChunk);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Entrypoint;
|
||||
72
node_modules/webpack/lib/EnvironmentPlugin.js
generated
vendored
Normal file
72
node_modules/webpack/lib/EnvironmentPlugin.js
generated
vendored
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Authors Simen Brekken @simenbrekken, Einar Löve @einarlove
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
/** @typedef {import("./Compiler")} Compiler */
|
||||
|
||||
const WebpackError = require("./WebpackError");
|
||||
const DefinePlugin = require("./DefinePlugin");
|
||||
|
||||
const needsEnvVarFix =
|
||||
["8", "9"].indexOf(process.versions.node.split(".")[0]) >= 0 &&
|
||||
process.platform === "win32";
|
||||
|
||||
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 = {};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Compiler} compiler webpack compiler instance
|
||||
* @returns {void}
|
||||
*/
|
||||
apply(compiler) {
|
||||
const definitions = this.keys.reduce((defs, key) => {
|
||||
// TODO remove once the fix has made its way into Node 8.
|
||||
// Work around https://github.com/nodejs/node/pull/18463,
|
||||
// affecting Node 8 & 9 by performing an OS-level
|
||||
// operation that always succeeds before reading
|
||||
// environment variables:
|
||||
if (needsEnvVarFix) require("os").cpus();
|
||||
|
||||
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.warnings.push(error);
|
||||
});
|
||||
}
|
||||
|
||||
defs[`process.env.${key}`] =
|
||||
value === undefined ? "undefined" : JSON.stringify(value);
|
||||
|
||||
return defs;
|
||||
}, {});
|
||||
|
||||
new DefinePlugin(definitions).apply(compiler);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = EnvironmentPlugin;
|
||||
60
node_modules/webpack/lib/ErrorHelpers.js
generated
vendored
Normal file
60
node_modules/webpack/lib/ErrorHelpers.js
generated
vendored
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
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");
|
||||
|
||||
return stack
|
||||
.reduce(
|
||||
(acc, line, idx) =>
|
||||
line.includes(message[idx]) ? acc : acc.concat(line),
|
||||
[]
|
||||
)
|
||||
.join("\n");
|
||||
};
|
||||
|
||||
exports.cutOffMessage = (stack, message) => {
|
||||
const nextLine = stack.indexOf("\n");
|
||||
if (nextLine === -1) {
|
||||
return stack === message ? "" : stack;
|
||||
} else {
|
||||
const firstLine = stack.substr(0, nextLine);
|
||||
return firstLine === message ? stack.substr(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;
|
||||
};
|
||||
27
node_modules/webpack/lib/EvalDevToolModulePlugin.js
generated
vendored
Normal file
27
node_modules/webpack/lib/EvalDevToolModulePlugin.js
generated
vendored
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
"use strict";
|
||||
|
||||
const EvalDevToolModuleTemplatePlugin = require("./EvalDevToolModuleTemplatePlugin");
|
||||
|
||||
class EvalDevToolModulePlugin {
|
||||
constructor(options) {
|
||||
this.sourceUrlComment = options.sourceUrlComment;
|
||||
this.moduleFilenameTemplate = options.moduleFilenameTemplate;
|
||||
this.namespace = options.namespace;
|
||||
}
|
||||
|
||||
apply(compiler) {
|
||||
compiler.hooks.compilation.tap("EvalDevToolModulePlugin", compilation => {
|
||||
new EvalDevToolModuleTemplatePlugin({
|
||||
sourceUrlComment: this.sourceUrlComment,
|
||||
moduleFilenameTemplate: this.moduleFilenameTemplate,
|
||||
namespace: this.namespace
|
||||
}).apply(compilation.moduleTemplates.javascript);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = EvalDevToolModulePlugin;
|
||||
61
node_modules/webpack/lib/EvalDevToolModuleTemplatePlugin.js
generated
vendored
Normal file
61
node_modules/webpack/lib/EvalDevToolModuleTemplatePlugin.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 { RawSource } = require("webpack-sources");
|
||||
const ModuleFilenameHelpers = require("./ModuleFilenameHelpers");
|
||||
|
||||
const cache = new WeakMap();
|
||||
|
||||
class EvalDevToolModuleTemplatePlugin {
|
||||
constructor(options) {
|
||||
this.sourceUrlComment = options.sourceUrlComment || "\n//# sourceURL=[url]";
|
||||
this.moduleFilenameTemplate =
|
||||
options.moduleFilenameTemplate ||
|
||||
"webpack://[namespace]/[resourcePath]?[loaders]";
|
||||
this.namespace = options.namespace || "";
|
||||
}
|
||||
|
||||
apply(moduleTemplate) {
|
||||
moduleTemplate.hooks.module.tap(
|
||||
"EvalDevToolModuleTemplatePlugin",
|
||||
(source, module) => {
|
||||
const cacheEntry = cache.get(source);
|
||||
if (cacheEntry !== undefined) return cacheEntry;
|
||||
const content = source.source();
|
||||
const str = ModuleFilenameHelpers.createFilename(
|
||||
module,
|
||||
{
|
||||
moduleFilenameTemplate: this.moduleFilenameTemplate,
|
||||
namespace: this.namespace
|
||||
},
|
||||
moduleTemplate.runtimeTemplate.requestShortener
|
||||
);
|
||||
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(${JSON.stringify(content + footer)});`
|
||||
);
|
||||
cache.set(source, result);
|
||||
return result;
|
||||
}
|
||||
);
|
||||
moduleTemplate.hooks.hash.tap("EvalDevToolModuleTemplatePlugin", hash => {
|
||||
hash.update("EvalDevToolModuleTemplatePlugin");
|
||||
hash.update("2");
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = EvalDevToolModuleTemplatePlugin;
|
||||
120
node_modules/webpack/lib/EvalSourceMapDevToolModuleTemplatePlugin.js
generated
vendored
Normal file
120
node_modules/webpack/lib/EvalSourceMapDevToolModuleTemplatePlugin.js
generated
vendored
Normal file
|
|
@ -0,0 +1,120 @@
|
|||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
"use strict";
|
||||
|
||||
const { RawSource } = require("webpack-sources");
|
||||
const ModuleFilenameHelpers = require("./ModuleFilenameHelpers");
|
||||
const { absolutify } = require("./util/identifier");
|
||||
|
||||
const cache = new WeakMap();
|
||||
|
||||
class EvalSourceMapDevToolModuleTemplatePlugin {
|
||||
constructor(compilation, options) {
|
||||
this.compilation = compilation;
|
||||
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(moduleTemplate) {
|
||||
const self = this;
|
||||
const options = this.options;
|
||||
const matchModule = ModuleFilenameHelpers.matchObject.bind(
|
||||
ModuleFilenameHelpers,
|
||||
options
|
||||
);
|
||||
moduleTemplate.hooks.module.tap(
|
||||
"EvalSourceMapDevToolModuleTemplatePlugin",
|
||||
(source, module) => {
|
||||
const cachedSource = cache.get(source);
|
||||
if (cachedSource !== undefined) {
|
||||
return cachedSource;
|
||||
}
|
||||
|
||||
if (!matchModule(module.resource)) {
|
||||
return source;
|
||||
}
|
||||
|
||||
/** @type {{ [key: string]: TODO; }} */
|
||||
let sourceMap;
|
||||
let content;
|
||||
if (source.sourceAndMap) {
|
||||
const sourceAndMap = source.sourceAndMap(options);
|
||||
sourceMap = sourceAndMap.map;
|
||||
content = sourceAndMap.source;
|
||||
} else {
|
||||
sourceMap = source.map(options);
|
||||
content = source.source();
|
||||
}
|
||||
if (!sourceMap) {
|
||||
return source;
|
||||
}
|
||||
|
||||
// Clone (flat) the sourcemap to ensure that the mutations below do not persist.
|
||||
sourceMap = Object.keys(sourceMap).reduce((obj, key) => {
|
||||
obj[key] = sourceMap[key];
|
||||
return obj;
|
||||
}, {});
|
||||
const context = this.compilation.compiler.options.context;
|
||||
const modules = sourceMap.sources.map(source => {
|
||||
if (source.startsWith("webpack://")) {
|
||||
source = absolutify(context, source.slice(10));
|
||||
}
|
||||
const module = self.compilation.findModule(source);
|
||||
return module || source;
|
||||
});
|
||||
let moduleFilenames = modules.map(module => {
|
||||
return ModuleFilenameHelpers.createFilename(
|
||||
module,
|
||||
{
|
||||
moduleFilenameTemplate: self.moduleFilenameTemplate,
|
||||
namespace: self.namespace
|
||||
},
|
||||
moduleTemplate.runtimeTemplate.requestShortener
|
||||
);
|
||||
});
|
||||
moduleFilenames = ModuleFilenameHelpers.replaceDuplicates(
|
||||
moduleFilenames,
|
||||
(filename, i, n) => {
|
||||
for (let j = 0; j < n; j++) filename += "*";
|
||||
return filename;
|
||||
}
|
||||
);
|
||||
sourceMap.sources = moduleFilenames;
|
||||
sourceMap.sourceRoot = options.sourceRoot || "";
|
||||
sourceMap.file = `${module.id}.js`;
|
||||
|
||||
const footer =
|
||||
self.sourceMapComment.replace(
|
||||
/\[url\]/g,
|
||||
`data:application/json;charset=utf-8;base64,${Buffer.from(
|
||||
JSON.stringify(sourceMap),
|
||||
"utf8"
|
||||
).toString("base64")}`
|
||||
) + `\n//# sourceURL=webpack-internal:///${module.id}\n`; // workaround for chrome bug
|
||||
|
||||
const evalSource = new RawSource(
|
||||
`eval(${JSON.stringify(content + footer)});`
|
||||
);
|
||||
|
||||
cache.set(source, evalSource);
|
||||
|
||||
return evalSource;
|
||||
}
|
||||
);
|
||||
moduleTemplate.hooks.hash.tap(
|
||||
"EvalSourceMapDevToolModuleTemplatePlugin",
|
||||
hash => {
|
||||
hash.update("eval-source-map");
|
||||
hash.update("2");
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
module.exports = EvalSourceMapDevToolModuleTemplatePlugin;
|
||||
41
node_modules/webpack/lib/EvalSourceMapDevToolPlugin.js
generated
vendored
Normal file
41
node_modules/webpack/lib/EvalSourceMapDevToolPlugin.js
generated
vendored
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
"use strict";
|
||||
|
||||
const EvalSourceMapDevToolModuleTemplatePlugin = require("./EvalSourceMapDevToolModuleTemplatePlugin");
|
||||
const SourceMapDevToolModuleOptionsPlugin = require("./SourceMapDevToolModuleOptionsPlugin");
|
||||
|
||||
class EvalSourceMapDevToolPlugin {
|
||||
constructor(options) {
|
||||
if (arguments.length > 1) {
|
||||
throw new Error(
|
||||
"EvalSourceMapDevToolPlugin only takes one argument (pass an options object)"
|
||||
);
|
||||
}
|
||||
if (typeof options === "string") {
|
||||
options = {
|
||||
append: options
|
||||
};
|
||||
}
|
||||
if (!options) options = {};
|
||||
this.options = options;
|
||||
}
|
||||
|
||||
apply(compiler) {
|
||||
const options = this.options;
|
||||
compiler.hooks.compilation.tap(
|
||||
"EvalSourceMapDevToolPlugin",
|
||||
compilation => {
|
||||
new SourceMapDevToolModuleOptionsPlugin(options).apply(compilation);
|
||||
new EvalSourceMapDevToolModuleTemplatePlugin(
|
||||
compilation,
|
||||
options
|
||||
).apply(compilation.moduleTemplates.javascript);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = EvalSourceMapDevToolPlugin;
|
||||
53
node_modules/webpack/lib/ExportPropertyMainTemplatePlugin.js
generated
vendored
Normal file
53
node_modules/webpack/lib/ExportPropertyMainTemplatePlugin.js
generated
vendored
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
"use strict";
|
||||
|
||||
const { ConcatSource } = require("webpack-sources");
|
||||
|
||||
/** @typedef {import("./Compilation")} Compilation */
|
||||
|
||||
/**
|
||||
* @param {string[]} accessor the accessor to convert to path
|
||||
* @returns {string} the path
|
||||
*/
|
||||
const accessorToObjectAccess = accessor => {
|
||||
return accessor.map(a => `[${JSON.stringify(a)}]`).join("");
|
||||
};
|
||||
|
||||
class ExportPropertyMainTemplatePlugin {
|
||||
/**
|
||||
* @param {string|string[]} property the name of the property to export
|
||||
*/
|
||||
constructor(property) {
|
||||
this.property = property;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Compilation} compilation the compilation instance
|
||||
* @returns {void}
|
||||
*/
|
||||
apply(compilation) {
|
||||
const { mainTemplate, chunkTemplate } = compilation;
|
||||
|
||||
const onRenderWithEntry = (source, chunk, hash) => {
|
||||
const postfix = `${accessorToObjectAccess([].concat(this.property))}`;
|
||||
return new ConcatSource(source, postfix);
|
||||
};
|
||||
|
||||
for (const template of [mainTemplate, chunkTemplate]) {
|
||||
template.hooks.renderWithEntry.tap(
|
||||
"ExportPropertyMainTemplatePlugin",
|
||||
onRenderWithEntry
|
||||
);
|
||||
}
|
||||
|
||||
mainTemplate.hooks.hash.tap("ExportPropertyMainTemplatePlugin", hash => {
|
||||
hash.update("export property");
|
||||
hash.update(`${this.property}`);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ExportPropertyMainTemplatePlugin;
|
||||
88
node_modules/webpack/lib/ExtendedAPIPlugin.js
generated
vendored
Normal file
88
node_modules/webpack/lib/ExtendedAPIPlugin.js
generated
vendored
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
"use strict";
|
||||
|
||||
const Template = require("./Template");
|
||||
const ConstDependency = require("./dependencies/ConstDependency");
|
||||
const ParserHelpers = require("./ParserHelpers");
|
||||
const NullFactory = require("./NullFactory");
|
||||
|
||||
const REPLACEMENTS = {
|
||||
// eslint-disable-next-line camelcase
|
||||
__webpack_hash__: "__webpack_require__.h",
|
||||
// eslint-disable-next-line camelcase
|
||||
__webpack_chunkname__: "__webpack_require__.cn"
|
||||
};
|
||||
const REPLACEMENT_TYPES = {
|
||||
// eslint-disable-next-line camelcase
|
||||
__webpack_hash__: "string",
|
||||
// eslint-disable-next-line camelcase
|
||||
__webpack_chunkname__: "string"
|
||||
};
|
||||
|
||||
class ExtendedAPIPlugin {
|
||||
apply(compiler) {
|
||||
compiler.hooks.compilation.tap(
|
||||
"ExtendedAPIPlugin",
|
||||
(compilation, { normalModuleFactory }) => {
|
||||
compilation.dependencyFactories.set(ConstDependency, new NullFactory());
|
||||
compilation.dependencyTemplates.set(
|
||||
ConstDependency,
|
||||
new ConstDependency.Template()
|
||||
);
|
||||
|
||||
const mainTemplate = compilation.mainTemplate;
|
||||
mainTemplate.hooks.requireExtensions.tap(
|
||||
"ExtendedAPIPlugin",
|
||||
(source, chunk, hash) => {
|
||||
const buf = [source];
|
||||
buf.push("");
|
||||
buf.push("// __webpack_hash__");
|
||||
buf.push(`${mainTemplate.requireFn}.h = ${JSON.stringify(hash)};`);
|
||||
buf.push("");
|
||||
buf.push("// __webpack_chunkname__");
|
||||
buf.push(
|
||||
`${mainTemplate.requireFn}.cn = ${JSON.stringify(chunk.name)};`
|
||||
);
|
||||
return Template.asString(buf);
|
||||
}
|
||||
);
|
||||
mainTemplate.hooks.globalHash.tap("ExtendedAPIPlugin", () => true);
|
||||
|
||||
const handler = (parser, parserOptions) => {
|
||||
Object.keys(REPLACEMENTS).forEach(key => {
|
||||
parser.hooks.expression
|
||||
.for(key)
|
||||
.tap(
|
||||
"ExtendedAPIPlugin",
|
||||
ParserHelpers.toConstantDependencyWithWebpackRequire(
|
||||
parser,
|
||||
REPLACEMENTS[key]
|
||||
)
|
||||
);
|
||||
parser.hooks.evaluateTypeof
|
||||
.for(key)
|
||||
.tap(
|
||||
"ExtendedAPIPlugin",
|
||||
ParserHelpers.evaluateToString(REPLACEMENT_TYPES[key])
|
||||
);
|
||||
});
|
||||
};
|
||||
|
||||
normalModuleFactory.hooks.parser
|
||||
.for("javascript/auto")
|
||||
.tap("ExtendedAPIPlugin", handler);
|
||||
normalModuleFactory.hooks.parser
|
||||
.for("javascript/dynamic")
|
||||
.tap("ExtendedAPIPlugin", handler);
|
||||
normalModuleFactory.hooks.parser
|
||||
.for("javascript/esm")
|
||||
.tap("ExtendedAPIPlugin", handler);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ExtendedAPIPlugin;
|
||||
179
node_modules/webpack/lib/ExternalModule.js
generated
vendored
Normal file
179
node_modules/webpack/lib/ExternalModule.js
generated
vendored
Normal file
|
|
@ -0,0 +1,179 @@
|
|||
/*
|
||||
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 WebpackMissingModule = require("./dependencies/WebpackMissingModule");
|
||||
const Template = require("./Template");
|
||||
|
||||
/** @typedef {import("./util/createHash").Hash} Hash */
|
||||
|
||||
class ExternalModule extends Module {
|
||||
constructor(request, type, userRequest) {
|
||||
super("javascript/dynamic", null);
|
||||
|
||||
// Info from Factory
|
||||
this.request = request;
|
||||
this.externalType = type;
|
||||
this.userRequest = userRequest;
|
||||
this.external = true;
|
||||
}
|
||||
|
||||
libIdent() {
|
||||
return this.userRequest;
|
||||
}
|
||||
|
||||
chunkCondition(chunk) {
|
||||
return chunk.hasEntryModule();
|
||||
}
|
||||
|
||||
identifier() {
|
||||
return "external " + JSON.stringify(this.request);
|
||||
}
|
||||
|
||||
readableIdentifier() {
|
||||
return "external " + JSON.stringify(this.request);
|
||||
}
|
||||
|
||||
needRebuild() {
|
||||
return false;
|
||||
}
|
||||
|
||||
build(options, compilation, resolver, fs, callback) {
|
||||
this.built = true;
|
||||
this.buildMeta = {};
|
||||
this.buildInfo = {};
|
||||
callback();
|
||||
}
|
||||
|
||||
getSourceForGlobalVariableExternal(variableName, type) {
|
||||
if (!Array.isArray(variableName)) {
|
||||
// make it an array as the look up works the same basically
|
||||
variableName = [variableName];
|
||||
}
|
||||
|
||||
// needed for e.g. window["some"]["thing"]
|
||||
const objectLookup = variableName
|
||||
.map(r => `[${JSON.stringify(r)}]`)
|
||||
.join("");
|
||||
return `(function() { module.exports = ${type}${objectLookup}; }());`;
|
||||
}
|
||||
|
||||
getSourceForCommonJsExternal(moduleAndSpecifiers) {
|
||||
if (!Array.isArray(moduleAndSpecifiers)) {
|
||||
return `module.exports = require(${JSON.stringify(
|
||||
moduleAndSpecifiers
|
||||
)});`;
|
||||
}
|
||||
|
||||
const moduleName = moduleAndSpecifiers[0];
|
||||
const objectLookup = moduleAndSpecifiers
|
||||
.slice(1)
|
||||
.map(r => `[${JSON.stringify(r)}]`)
|
||||
.join("");
|
||||
return `module.exports = require(${JSON.stringify(
|
||||
moduleName
|
||||
)})${objectLookup};`;
|
||||
}
|
||||
|
||||
checkExternalVariable(variableToCheck, request) {
|
||||
return `if(typeof ${variableToCheck} === 'undefined') {${WebpackMissingModule.moduleCode(
|
||||
request
|
||||
)}}\n`;
|
||||
}
|
||||
|
||||
getSourceForAmdOrUmdExternal(id, optional, request) {
|
||||
const externalVariable = `__WEBPACK_EXTERNAL_MODULE_${Template.toIdentifier(
|
||||
`${id}`
|
||||
)}__`;
|
||||
const missingModuleError = optional
|
||||
? this.checkExternalVariable(externalVariable, request)
|
||||
: "";
|
||||
return `${missingModuleError}module.exports = ${externalVariable};`;
|
||||
}
|
||||
|
||||
getSourceForDefaultCase(optional, request) {
|
||||
if (!Array.isArray(request)) {
|
||||
// make it an array as the look up works the same basically
|
||||
request = [request];
|
||||
}
|
||||
|
||||
const variableName = request[0];
|
||||
const missingModuleError = optional
|
||||
? this.checkExternalVariable(variableName, request.join("."))
|
||||
: "";
|
||||
const objectLookup = request
|
||||
.slice(1)
|
||||
.map(r => `[${JSON.stringify(r)}]`)
|
||||
.join("");
|
||||
return `${missingModuleError}module.exports = ${variableName}${objectLookup};`;
|
||||
}
|
||||
|
||||
getSourceString(runtime) {
|
||||
const request =
|
||||
typeof this.request === "object" && !Array.isArray(this.request)
|
||||
? this.request[this.externalType]
|
||||
: this.request;
|
||||
switch (this.externalType) {
|
||||
case "this":
|
||||
case "window":
|
||||
case "self":
|
||||
return this.getSourceForGlobalVariableExternal(
|
||||
request,
|
||||
this.externalType
|
||||
);
|
||||
case "global":
|
||||
return this.getSourceForGlobalVariableExternal(
|
||||
request,
|
||||
runtime.outputOptions.globalObject
|
||||
);
|
||||
case "commonjs":
|
||||
case "commonjs2":
|
||||
return this.getSourceForCommonJsExternal(request);
|
||||
case "amd":
|
||||
case "amd-require":
|
||||
case "umd":
|
||||
case "umd2":
|
||||
case "system":
|
||||
return this.getSourceForAmdOrUmdExternal(
|
||||
this.id,
|
||||
this.optional,
|
||||
request
|
||||
);
|
||||
default:
|
||||
return this.getSourceForDefaultCase(this.optional, request);
|
||||
}
|
||||
}
|
||||
|
||||
getSource(sourceString) {
|
||||
if (this.useSourceMap) {
|
||||
return new OriginalSource(sourceString, this.identifier());
|
||||
}
|
||||
|
||||
return new RawSource(sourceString);
|
||||
}
|
||||
|
||||
source(dependencyTemplates, runtime) {
|
||||
return this.getSource(this.getSourceString(runtime));
|
||||
}
|
||||
|
||||
size() {
|
||||
return 42;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Hash} hash the hash used to track dependencies
|
||||
* @returns {void}
|
||||
*/
|
||||
updateHash(hash) {
|
||||
hash.update(this.externalType);
|
||||
hash.update(JSON.stringify(this.request));
|
||||
hash.update(JSON.stringify(Boolean(this.optional)));
|
||||
super.updateHash(hash);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ExternalModule;
|
||||
110
node_modules/webpack/lib/ExternalModuleFactoryPlugin.js
generated
vendored
Normal file
110
node_modules/webpack/lib/ExternalModuleFactoryPlugin.js
generated
vendored
Normal file
|
|
@ -0,0 +1,110 @@
|
|||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
"use strict";
|
||||
|
||||
const ExternalModule = require("./ExternalModule");
|
||||
|
||||
class ExternalModuleFactoryPlugin {
|
||||
constructor(type, externals) {
|
||||
this.type = type;
|
||||
this.externals = externals;
|
||||
}
|
||||
|
||||
apply(normalModuleFactory) {
|
||||
const globalType = this.type;
|
||||
normalModuleFactory.hooks.factory.tap(
|
||||
"ExternalModuleFactoryPlugin",
|
||||
factory => (data, callback) => {
|
||||
const context = data.context;
|
||||
const dependency = data.dependencies[0];
|
||||
|
||||
const handleExternal = (value, type, callback) => {
|
||||
if (typeof type === "function") {
|
||||
callback = type;
|
||||
type = undefined;
|
||||
}
|
||||
if (value === false) return factory(data, callback);
|
||||
if (value === true) value = dependency.request;
|
||||
if (type === undefined && /^[a-z0-9]+ /.test(value)) {
|
||||
const idx = value.indexOf(" ");
|
||||
type = value.substr(0, idx);
|
||||
value = value.substr(idx + 1);
|
||||
}
|
||||
callback(
|
||||
null,
|
||||
new ExternalModule(value, type || globalType, dependency.request)
|
||||
);
|
||||
return true;
|
||||
};
|
||||
|
||||
const handleExternals = (externals, callback) => {
|
||||
if (typeof externals === "string") {
|
||||
if (externals === dependency.request) {
|
||||
return handleExternal(dependency.request, callback);
|
||||
}
|
||||
} else if (Array.isArray(externals)) {
|
||||
let i = 0;
|
||||
const next = () => {
|
||||
let asyncFlag;
|
||||
const handleExternalsAndCallback = (err, module) => {
|
||||
if (err) return callback(err);
|
||||
if (!module) {
|
||||
if (asyncFlag) {
|
||||
asyncFlag = false;
|
||||
return;
|
||||
}
|
||||
return next();
|
||||
}
|
||||
callback(null, module);
|
||||
};
|
||||
|
||||
do {
|
||||
asyncFlag = true;
|
||||
if (i >= externals.length) return callback();
|
||||
handleExternals(externals[i++], handleExternalsAndCallback);
|
||||
} while (!asyncFlag);
|
||||
asyncFlag = false;
|
||||
};
|
||||
|
||||
next();
|
||||
return;
|
||||
} else if (externals instanceof RegExp) {
|
||||
if (externals.test(dependency.request)) {
|
||||
return handleExternal(dependency.request, callback);
|
||||
}
|
||||
} else if (typeof externals === "function") {
|
||||
externals.call(
|
||||
null,
|
||||
context,
|
||||
dependency.request,
|
||||
(err, value, type) => {
|
||||
if (err) return callback(err);
|
||||
if (value !== undefined) {
|
||||
handleExternal(value, type, callback);
|
||||
} else {
|
||||
callback();
|
||||
}
|
||||
}
|
||||
);
|
||||
return;
|
||||
} else if (
|
||||
typeof externals === "object" &&
|
||||
Object.prototype.hasOwnProperty.call(externals, dependency.request)
|
||||
) {
|
||||
return handleExternal(externals[dependency.request], callback);
|
||||
}
|
||||
callback();
|
||||
};
|
||||
|
||||
handleExternals(this.externals, (err, module) => {
|
||||
if (err) return callback(err);
|
||||
if (!module) return handleExternal(false, callback);
|
||||
return callback(null, module);
|
||||
});
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
module.exports = ExternalModuleFactoryPlugin;
|
||||
23
node_modules/webpack/lib/ExternalsPlugin.js
generated
vendored
Normal file
23
node_modules/webpack/lib/ExternalsPlugin.js
generated
vendored
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
"use strict";
|
||||
|
||||
const ExternalModuleFactoryPlugin = require("./ExternalModuleFactoryPlugin");
|
||||
|
||||
class ExternalsPlugin {
|
||||
constructor(type, externals) {
|
||||
this.type = type;
|
||||
this.externals = externals;
|
||||
}
|
||||
apply(compiler) {
|
||||
compiler.hooks.compile.tap("ExternalsPlugin", ({ normalModuleFactory }) => {
|
||||
new ExternalModuleFactoryPlugin(this.type, this.externals).apply(
|
||||
normalModuleFactory
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ExternalsPlugin;
|
||||
38
node_modules/webpack/lib/FlagAllModulesAsUsedPlugin.js
generated
vendored
Normal file
38
node_modules/webpack/lib/FlagAllModulesAsUsedPlugin.js
generated
vendored
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
/** @typedef {import("./Compiler")} Compiler */
|
||||
|
||||
class FlagAllModulesAsUsedPlugin {
|
||||
constructor(explanation) {
|
||||
this.explanation = explanation;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Compiler} compiler webpack compiler
|
||||
* @returns {void}
|
||||
*/
|
||||
apply(compiler) {
|
||||
compiler.hooks.compilation.tap(
|
||||
"FlagAllModulesAsUsedPlugin",
|
||||
compilation => {
|
||||
compilation.hooks.optimizeDependencies.tap(
|
||||
"FlagAllModulesAsUsedPlugin",
|
||||
modules => {
|
||||
for (const module of modules) {
|
||||
module.used = true;
|
||||
module.usedExports = true;
|
||||
module.addReason(null, null, this.explanation);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = FlagAllModulesAsUsedPlugin;
|
||||
174
node_modules/webpack/lib/FlagDependencyExportsPlugin.js
generated
vendored
Normal file
174
node_modules/webpack/lib/FlagDependencyExportsPlugin.js
generated
vendored
Normal file
|
|
@ -0,0 +1,174 @@
|
|||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
"use strict";
|
||||
|
||||
const Queue = require("./util/Queue");
|
||||
|
||||
const addToSet = (a, b) => {
|
||||
for (const item of b) {
|
||||
a.add(item);
|
||||
}
|
||||
};
|
||||
|
||||
class FlagDependencyExportsPlugin {
|
||||
apply(compiler) {
|
||||
compiler.hooks.compilation.tap(
|
||||
"FlagDependencyExportsPlugin",
|
||||
compilation => {
|
||||
compilation.hooks.finishModules.tap(
|
||||
"FlagDependencyExportsPlugin",
|
||||
modules => {
|
||||
const dependencies = new Map();
|
||||
|
||||
const queue = new Queue();
|
||||
|
||||
let module;
|
||||
let moduleWithExports;
|
||||
let moduleProvidedExports;
|
||||
let providedExportsAreTemporary;
|
||||
|
||||
const processDependenciesBlock = depBlock => {
|
||||
for (const dep of depBlock.dependencies) {
|
||||
if (processDependency(dep)) return true;
|
||||
}
|
||||
for (const variable of depBlock.variables) {
|
||||
for (const dep of variable.dependencies) {
|
||||
if (processDependency(dep)) return true;
|
||||
}
|
||||
}
|
||||
for (const block of depBlock.blocks) {
|
||||
if (processDependenciesBlock(block)) return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
const processDependency = dep => {
|
||||
const exportDesc = dep.getExports && dep.getExports();
|
||||
if (!exportDesc) return;
|
||||
moduleWithExports = true;
|
||||
const exports = exportDesc.exports;
|
||||
// break early if it's only in the worst state
|
||||
if (module.buildMeta.providedExports === true) {
|
||||
return true;
|
||||
}
|
||||
// break if it should move to the worst state
|
||||
if (exports === true) {
|
||||
module.buildMeta.providedExports = true;
|
||||
return true;
|
||||
}
|
||||
// merge in new exports
|
||||
if (Array.isArray(exports)) {
|
||||
addToSet(moduleProvidedExports, exports);
|
||||
}
|
||||
// store dependencies
|
||||
const exportDeps = exportDesc.dependencies;
|
||||
if (exportDeps) {
|
||||
providedExportsAreTemporary = true;
|
||||
for (const exportDependency of exportDeps) {
|
||||
// add dependency for this module
|
||||
const set = dependencies.get(exportDependency);
|
||||
if (set === undefined) {
|
||||
dependencies.set(exportDependency, new Set([module]));
|
||||
} else {
|
||||
set.add(module);
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
const notifyDependencies = () => {
|
||||
const deps = dependencies.get(module);
|
||||
if (deps !== undefined) {
|
||||
for (const dep of deps) {
|
||||
queue.enqueue(dep);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const notifyDependenciesIfDifferent = (set, array) => {
|
||||
const deps = dependencies.get(module);
|
||||
if (deps !== undefined) {
|
||||
if (set.size === array.length) {
|
||||
let i = 0;
|
||||
let different = false;
|
||||
for (const item of set) {
|
||||
if (item !== array[i++]) {
|
||||
different = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!different) return;
|
||||
}
|
||||
for (const dep of deps) {
|
||||
queue.enqueue(dep);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Start with all modules without provided exports
|
||||
for (const module of modules) {
|
||||
if (module.buildInfo.temporaryProvidedExports) {
|
||||
// Clear exports when they are temporary
|
||||
// and recreate them
|
||||
module.buildMeta.providedExports = null;
|
||||
queue.enqueue(module);
|
||||
} else if (!module.buildMeta.providedExports) {
|
||||
queue.enqueue(module);
|
||||
}
|
||||
}
|
||||
|
||||
while (queue.length > 0) {
|
||||
module = queue.dequeue();
|
||||
|
||||
if (module.buildMeta.providedExports !== true) {
|
||||
moduleWithExports =
|
||||
module.buildMeta && module.buildMeta.exportsType;
|
||||
moduleProvidedExports = new Set();
|
||||
providedExportsAreTemporary = false;
|
||||
processDependenciesBlock(module);
|
||||
module.buildInfo.temporaryProvidedExports = providedExportsAreTemporary;
|
||||
if (!moduleWithExports) {
|
||||
notifyDependencies();
|
||||
module.buildMeta.providedExports = true;
|
||||
} else if (module.buildMeta.providedExports === true) {
|
||||
notifyDependencies();
|
||||
} else if (!module.buildMeta.providedExports) {
|
||||
notifyDependencies();
|
||||
module.buildMeta.providedExports = Array.from(
|
||||
moduleProvidedExports
|
||||
);
|
||||
} else {
|
||||
notifyDependenciesIfDifferent(
|
||||
moduleProvidedExports,
|
||||
module.buildMeta.providedExports
|
||||
);
|
||||
module.buildMeta.providedExports = Array.from(
|
||||
moduleProvidedExports
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
const providedExportsCache = new WeakMap();
|
||||
compilation.hooks.rebuildModule.tap(
|
||||
"FlagDependencyExportsPlugin",
|
||||
module => {
|
||||
providedExportsCache.set(module, module.buildMeta.providedExports);
|
||||
}
|
||||
);
|
||||
compilation.hooks.finishRebuildingModule.tap(
|
||||
"FlagDependencyExportsPlugin",
|
||||
module => {
|
||||
module.buildMeta.providedExports = providedExportsCache.get(module);
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = FlagDependencyExportsPlugin;
|
||||
116
node_modules/webpack/lib/FlagDependencyUsagePlugin.js
generated
vendored
Normal file
116
node_modules/webpack/lib/FlagDependencyUsagePlugin.js
generated
vendored
Normal file
|
|
@ -0,0 +1,116 @@
|
|||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
"use strict";
|
||||
|
||||
/** @typedef {import("./Module")} Module */
|
||||
/** @typedef {import("./DependenciesBlock")} DependenciesBlock */
|
||||
|
||||
/** @typedef {false | true | string[]} UsedExports */
|
||||
|
||||
const addToSet = (a, b) => {
|
||||
for (const item of b) {
|
||||
if (!a.includes(item)) a.push(item);
|
||||
}
|
||||
return a;
|
||||
};
|
||||
|
||||
const isSubset = (biggerSet, subset) => {
|
||||
if (biggerSet === true) return true;
|
||||
if (subset === true) return false;
|
||||
return subset.every(item => biggerSet.indexOf(item) >= 0);
|
||||
};
|
||||
|
||||
class FlagDependencyUsagePlugin {
|
||||
apply(compiler) {
|
||||
compiler.hooks.compilation.tap("FlagDependencyUsagePlugin", compilation => {
|
||||
compilation.hooks.optimizeDependencies.tap(
|
||||
"FlagDependencyUsagePlugin",
|
||||
modules => {
|
||||
const processModule = (module, usedExports) => {
|
||||
module.used = true;
|
||||
if (module.usedExports === true) return;
|
||||
if (usedExports === true) {
|
||||
module.usedExports = true;
|
||||
} else if (Array.isArray(usedExports)) {
|
||||
const old = module.usedExports ? module.usedExports.length : -1;
|
||||
module.usedExports = addToSet(
|
||||
module.usedExports || [],
|
||||
usedExports
|
||||
);
|
||||
if (module.usedExports.length === old) {
|
||||
return;
|
||||
}
|
||||
} else if (Array.isArray(module.usedExports)) {
|
||||
return;
|
||||
} else {
|
||||
module.usedExports = false;
|
||||
}
|
||||
|
||||
// for a module without side effects we stop tracking usage here when no export is used
|
||||
// This module won't be evaluated in this case
|
||||
if (module.factoryMeta.sideEffectFree) {
|
||||
if (module.usedExports === false) return;
|
||||
if (
|
||||
Array.isArray(module.usedExports) &&
|
||||
module.usedExports.length === 0
|
||||
)
|
||||
return;
|
||||
}
|
||||
|
||||
queue.push([module, module, module.usedExports]);
|
||||
};
|
||||
|
||||
const processDependenciesBlock = (module, depBlock, usedExports) => {
|
||||
for (const dep of depBlock.dependencies) {
|
||||
processDependency(module, dep);
|
||||
}
|
||||
for (const variable of depBlock.variables) {
|
||||
for (const dep of variable.dependencies) {
|
||||
processDependency(module, dep);
|
||||
}
|
||||
}
|
||||
for (const block of depBlock.blocks) {
|
||||
queue.push([module, block, usedExports]);
|
||||
}
|
||||
};
|
||||
|
||||
const processDependency = (module, dep) => {
|
||||
const reference = compilation.getDependencyReference(module, dep);
|
||||
if (!reference) return;
|
||||
const referenceModule = reference.module;
|
||||
const importedNames = reference.importedNames;
|
||||
const oldUsed = referenceModule.used;
|
||||
const oldUsedExports = referenceModule.usedExports;
|
||||
if (
|
||||
!oldUsed ||
|
||||
(importedNames &&
|
||||
(!oldUsedExports || !isSubset(oldUsedExports, importedNames)))
|
||||
) {
|
||||
processModule(referenceModule, importedNames);
|
||||
}
|
||||
};
|
||||
|
||||
for (const module of modules) {
|
||||
if (!module.used) module.used = false;
|
||||
}
|
||||
|
||||
/** @type {[Module, DependenciesBlock, UsedExports][]} */
|
||||
const queue = [];
|
||||
for (const preparedEntrypoint of compilation._preparedEntrypoints) {
|
||||
if (preparedEntrypoint.module) {
|
||||
processModule(preparedEntrypoint.module, true);
|
||||
}
|
||||
}
|
||||
|
||||
while (queue.length) {
|
||||
const queueItem = queue.pop();
|
||||
processDependenciesBlock(queueItem[0], queueItem[1], queueItem[2]);
|
||||
}
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
module.exports = FlagDependencyUsagePlugin;
|
||||
36
node_modules/webpack/lib/FlagInitialModulesAsUsedPlugin.js
generated
vendored
Normal file
36
node_modules/webpack/lib/FlagInitialModulesAsUsedPlugin.js
generated
vendored
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
"use strict";
|
||||
|
||||
class FlagInitialModulesAsUsedPlugin {
|
||||
constructor(explanation) {
|
||||
this.explanation = explanation;
|
||||
}
|
||||
|
||||
apply(compiler) {
|
||||
compiler.hooks.compilation.tap(
|
||||
"FlagInitialModulesAsUsedPlugin",
|
||||
compilation => {
|
||||
compilation.hooks.afterOptimizeChunks.tap(
|
||||
"FlagInitialModulesAsUsedPlugin",
|
||||
chunks => {
|
||||
for (const chunk of chunks) {
|
||||
if (!chunk.isOnlyInitial()) {
|
||||
return;
|
||||
}
|
||||
for (const module of chunk.modulesIterable) {
|
||||
module.used = true;
|
||||
module.usedExports = true;
|
||||
module.addReason(null, null, this.explanation);
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = FlagInitialModulesAsUsedPlugin;
|
||||
19
node_modules/webpack/lib/FunctionModulePlugin.js
generated
vendored
Normal file
19
node_modules/webpack/lib/FunctionModulePlugin.js
generated
vendored
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
"use strict";
|
||||
|
||||
const FunctionModuleTemplatePlugin = require("./FunctionModuleTemplatePlugin");
|
||||
|
||||
class FunctionModulePlugin {
|
||||
apply(compiler) {
|
||||
compiler.hooks.compilation.tap("FunctionModulePlugin", compilation => {
|
||||
new FunctionModuleTemplatePlugin().apply(
|
||||
compilation.moduleTemplates.javascript
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = FunctionModulePlugin;
|
||||
102
node_modules/webpack/lib/FunctionModuleTemplatePlugin.js
generated
vendored
Normal file
102
node_modules/webpack/lib/FunctionModuleTemplatePlugin.js
generated
vendored
Normal file
|
|
@ -0,0 +1,102 @@
|
|||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
"use strict";
|
||||
|
||||
const { ConcatSource } = require("webpack-sources");
|
||||
const Template = require("./Template");
|
||||
|
||||
class FunctionModuleTemplatePlugin {
|
||||
apply(moduleTemplate) {
|
||||
moduleTemplate.hooks.render.tap(
|
||||
"FunctionModuleTemplatePlugin",
|
||||
(moduleSource, module) => {
|
||||
const source = new ConcatSource();
|
||||
const args = [module.moduleArgument];
|
||||
// TODO remove HACK checking type for javascript
|
||||
if (module.type && module.type.startsWith("javascript")) {
|
||||
args.push(module.exportsArgument);
|
||||
if (module.hasDependencies(d => d.requireWebpackRequire !== false)) {
|
||||
args.push("__webpack_require__");
|
||||
}
|
||||
} else if (module.type && module.type.startsWith("json")) {
|
||||
// no additional arguments needed
|
||||
} else {
|
||||
args.push(module.exportsArgument, "__webpack_require__");
|
||||
}
|
||||
source.add("/***/ (function(" + args.join(", ") + ") {\n\n");
|
||||
if (module.buildInfo.strict) source.add('"use strict";\n');
|
||||
source.add(moduleSource);
|
||||
source.add("\n\n/***/ })");
|
||||
return source;
|
||||
}
|
||||
);
|
||||
|
||||
moduleTemplate.hooks.package.tap(
|
||||
"FunctionModuleTemplatePlugin",
|
||||
(moduleSource, module) => {
|
||||
if (moduleTemplate.runtimeTemplate.outputOptions.pathinfo) {
|
||||
const source = new ConcatSource();
|
||||
const req = module.readableIdentifier(
|
||||
moduleTemplate.runtimeTemplate.requestShortener
|
||||
);
|
||||
const reqStr = req.replace(/\*\//g, "*_/");
|
||||
const reqStrStar = "*".repeat(reqStr.length);
|
||||
source.add("/*!****" + reqStrStar + "****!*\\\n");
|
||||
source.add(" !*** " + reqStr + " ***!\n");
|
||||
source.add(" \\****" + reqStrStar + "****/\n");
|
||||
if (
|
||||
Array.isArray(module.buildMeta.providedExports) &&
|
||||
module.buildMeta.providedExports.length === 0
|
||||
) {
|
||||
source.add(Template.toComment("no exports provided") + "\n");
|
||||
} else if (Array.isArray(module.buildMeta.providedExports)) {
|
||||
source.add(
|
||||
Template.toComment(
|
||||
"exports provided: " +
|
||||
module.buildMeta.providedExports.join(", ")
|
||||
) + "\n"
|
||||
);
|
||||
} else if (module.buildMeta.providedExports) {
|
||||
source.add(Template.toComment("no static exports found") + "\n");
|
||||
}
|
||||
if (
|
||||
Array.isArray(module.usedExports) &&
|
||||
module.usedExports.length === 0
|
||||
) {
|
||||
source.add(Template.toComment("no exports used") + "\n");
|
||||
} else if (Array.isArray(module.usedExports)) {
|
||||
source.add(
|
||||
Template.toComment(
|
||||
"exports used: " + module.usedExports.join(", ")
|
||||
) + "\n"
|
||||
);
|
||||
} else if (module.usedExports) {
|
||||
source.add(Template.toComment("all exports used") + "\n");
|
||||
}
|
||||
if (module.optimizationBailout) {
|
||||
for (const text of module.optimizationBailout) {
|
||||
let code;
|
||||
if (typeof text === "function") {
|
||||
code = text(moduleTemplate.runtimeTemplate.requestShortener);
|
||||
} else {
|
||||
code = text;
|
||||
}
|
||||
source.add(Template.toComment(`${code}`) + "\n");
|
||||
}
|
||||
}
|
||||
source.add(moduleSource);
|
||||
return source;
|
||||
}
|
||||
return moduleSource;
|
||||
}
|
||||
);
|
||||
|
||||
moduleTemplate.hooks.hash.tap("FunctionModuleTemplatePlugin", hash => {
|
||||
hash.update("FunctionModuleTemplatePlugin");
|
||||
hash.update("2");
|
||||
});
|
||||
}
|
||||
}
|
||||
module.exports = FunctionModuleTemplatePlugin;
|
||||
60
node_modules/webpack/lib/Generator.js
generated
vendored
Normal file
60
node_modules/webpack/lib/Generator.js
generated
vendored
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
"use strict";
|
||||
|
||||
/** @typedef {import("./NormalModule")} NormalModule */
|
||||
/** @typedef {import("./RuntimeTemplate")} RuntimeTemplate */
|
||||
/** @typedef {import("webpack-sources").Source} Source */
|
||||
/** @typedef {import("./Dependency").DependencyTemplate} DependencyTemplate */
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class Generator {
|
||||
static byType(map) {
|
||||
return new ByTypeGenerator(map);
|
||||
}
|
||||
|
||||
/**
|
||||
* @abstract
|
||||
* @param {NormalModule} module module for which the code should be generated
|
||||
* @param {Map<Function, DependencyTemplate>} dependencyTemplates mapping from dependencies to templates
|
||||
* @param {RuntimeTemplate} runtimeTemplate the runtime template
|
||||
* @param {string} type which kind of code should be generated
|
||||
* @returns {Source} generated code
|
||||
*/
|
||||
generate(module, dependencyTemplates, runtimeTemplate, type) {
|
||||
throw new Error("Generator.generate: must be overridden");
|
||||
}
|
||||
}
|
||||
|
||||
class ByTypeGenerator extends Generator {
|
||||
constructor(map) {
|
||||
super();
|
||||
this.map = map;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {NormalModule} module module for which the code should be generated
|
||||
* @param {Map<Function, DependencyTemplate>} dependencyTemplates mapping from dependencies to templates
|
||||
* @param {RuntimeTemplate} runtimeTemplate the runtime template
|
||||
* @param {string} type which kind of code should be generated
|
||||
* @returns {Source} generated code
|
||||
*/
|
||||
generate(module, dependencyTemplates, runtimeTemplate, type) {
|
||||
const generator = this.map[type];
|
||||
if (!generator) {
|
||||
throw new Error(`Generator.byType: no generator specified for ${type}`);
|
||||
}
|
||||
return generator.generate(
|
||||
module,
|
||||
dependencyTemplates,
|
||||
runtimeTemplate,
|
||||
type
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Generator;
|
||||
65
node_modules/webpack/lib/GraphHelpers.js
generated
vendored
Normal file
65
node_modules/webpack/lib/GraphHelpers.js
generated
vendored
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
/** @typedef {import("./Chunk")} Chunk */
|
||||
/** @typedef {import("./ChunkGroup")} ChunkGroup */
|
||||
/** @typedef {import("./Module")} Module */
|
||||
/** @typedef {import("./DependenciesBlock")} DependenciesBlock */
|
||||
/** @typedef {import("./AsyncDependenciesBlock")} AsyncDependenciesBlock */
|
||||
|
||||
/**
|
||||
* @param {ChunkGroup} chunkGroup the ChunkGroup to connect
|
||||
* @param {Chunk} chunk chunk to tie to ChunkGroup
|
||||
* @returns {void}
|
||||
*/
|
||||
const connectChunkGroupAndChunk = (chunkGroup, chunk) => {
|
||||
if (chunkGroup.pushChunk(chunk)) {
|
||||
chunk.addGroup(chunkGroup);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {ChunkGroup} parent parent ChunkGroup to connect
|
||||
* @param {ChunkGroup} child child ChunkGroup to connect
|
||||
* @returns {void}
|
||||
*/
|
||||
const connectChunkGroupParentAndChild = (parent, child) => {
|
||||
if (parent.addChild(child)) {
|
||||
child.addParent(parent);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {Chunk} chunk Chunk to connect to Module
|
||||
* @param {Module} module Module to connect to Chunk
|
||||
* @returns {void}
|
||||
*/
|
||||
const connectChunkAndModule = (chunk, module) => {
|
||||
if (module.addChunk(chunk)) {
|
||||
chunk.addModule(module);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {Chunk} chunk Chunk being disconnected
|
||||
* @param {Module} module Module being disconnected
|
||||
* @returns {void}
|
||||
*/
|
||||
const disconnectChunkAndModule = (chunk, module) => {
|
||||
chunk.removeModule(module);
|
||||
module.removeChunk(chunk);
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {AsyncDependenciesBlock} depBlock DepBlock being tied to ChunkGroup
|
||||
* @param {ChunkGroup} chunkGroup ChunkGroup being tied to DepBlock
|
||||
* @returns {void}
|
||||
*/
|
||||
const connectDependenciesBlockAndChunkGroup = (depBlock, chunkGroup) => {
|
||||
if (chunkGroup.addBlock(depBlock)) {
|
||||
depBlock.chunkGroup = chunkGroup;
|
||||
}
|
||||
};
|
||||
|
||||
exports.connectChunkGroupAndChunk = connectChunkGroupAndChunk;
|
||||
exports.connectChunkGroupParentAndChild = connectChunkGroupParentAndChild;
|
||||
exports.connectChunkAndModule = connectChunkAndModule;
|
||||
exports.disconnectChunkAndModule = disconnectChunkAndModule;
|
||||
exports.connectDependenciesBlockAndChunkGroup = connectDependenciesBlockAndChunkGroup;
|
||||
17
node_modules/webpack/lib/HarmonyLinkingError.js
generated
vendored
Normal file
17
node_modules/webpack/lib/HarmonyLinkingError.js
generated
vendored
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
*/
|
||||
"use strict";
|
||||
|
||||
const WebpackError = require("./WebpackError");
|
||||
|
||||
module.exports = class HarmonyLinkingError extends WebpackError {
|
||||
/** @param {string} message Error message */
|
||||
constructor(message) {
|
||||
super(message);
|
||||
this.name = "HarmonyLinkingError";
|
||||
this.hideStack = true;
|
||||
|
||||
Error.captureStackTrace(this, this.constructor);
|
||||
}
|
||||
};
|
||||
63
node_modules/webpack/lib/HashedModuleIdsPlugin.js
generated
vendored
Normal file
63
node_modules/webpack/lib/HashedModuleIdsPlugin.js
generated
vendored
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
"use strict";
|
||||
const createHash = require("./util/createHash");
|
||||
|
||||
const validateOptions = require("schema-utils");
|
||||
const schema = require("../schemas/plugins/HashedModuleIdsPlugin.json");
|
||||
|
||||
/** @typedef {import("../declarations/plugins/HashedModuleIdsPlugin").HashedModuleIdsPluginOptions} HashedModuleIdsPluginOptions */
|
||||
|
||||
class HashedModuleIdsPlugin {
|
||||
/**
|
||||
* @param {HashedModuleIdsPluginOptions=} options options object
|
||||
*/
|
||||
constructor(options) {
|
||||
if (!options) options = {};
|
||||
|
||||
validateOptions(schema, options, "Hashed Module Ids Plugin");
|
||||
|
||||
/** @type {HashedModuleIdsPluginOptions} */
|
||||
this.options = Object.assign(
|
||||
{
|
||||
context: null,
|
||||
hashFunction: "md4",
|
||||
hashDigest: "base64",
|
||||
hashDigestLength: 4
|
||||
},
|
||||
options
|
||||
);
|
||||
}
|
||||
|
||||
apply(compiler) {
|
||||
const options = this.options;
|
||||
compiler.hooks.compilation.tap("HashedModuleIdsPlugin", compilation => {
|
||||
const usedIds = new Set();
|
||||
compilation.hooks.beforeModuleIds.tap(
|
||||
"HashedModuleIdsPlugin",
|
||||
modules => {
|
||||
for (const module of modules) {
|
||||
if (module.id === null && module.libIdent) {
|
||||
const id = module.libIdent({
|
||||
context: this.options.context || compiler.options.context
|
||||
});
|
||||
const hash = createHash(options.hashFunction);
|
||||
hash.update(id);
|
||||
const hashId = /** @type {string} */ (hash.digest(
|
||||
options.hashDigest
|
||||
));
|
||||
let len = options.hashDigestLength;
|
||||
while (usedIds.has(hashId.substr(0, len))) len++;
|
||||
module.id = hashId.substr(0, len);
|
||||
usedIds.add(module.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = HashedModuleIdsPlugin;
|
||||
721
node_modules/webpack/lib/HotModuleReplacement.runtime.js
generated
vendored
Normal file
721
node_modules/webpack/lib/HotModuleReplacement.runtime.js
generated
vendored
Normal file
|
|
@ -0,0 +1,721 @@
|
|||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
// eslint-disable no-unused-vars
|
||||
var $hash$ = undefined;
|
||||
var $requestTimeout$ = undefined;
|
||||
var installedModules = undefined;
|
||||
var $require$ = undefined;
|
||||
var hotDownloadManifest = undefined;
|
||||
var hotDownloadUpdateChunk = undefined;
|
||||
var hotDisposeChunk = undefined;
|
||||
var modules = undefined;
|
||||
var chunkId = undefined;
|
||||
|
||||
module.exports = function() {
|
||||
var hotApplyOnUpdate = true;
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
var hotCurrentHash = $hash$;
|
||||
var hotRequestTimeout = $requestTimeout$;
|
||||
var hotCurrentModuleData = {};
|
||||
var hotCurrentChildModule;
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
var hotCurrentParents = [];
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
var hotCurrentParentsTemp = [];
|
||||
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
function hotCreateRequire(moduleId) {
|
||||
var me = installedModules[moduleId];
|
||||
if (!me) return $require$;
|
||||
var fn = function(request) {
|
||||
if (me.hot.active) {
|
||||
if (installedModules[request]) {
|
||||
if (installedModules[request].parents.indexOf(moduleId) === -1) {
|
||||
installedModules[request].parents.push(moduleId);
|
||||
}
|
||||
} else {
|
||||
hotCurrentParents = [moduleId];
|
||||
hotCurrentChildModule = request;
|
||||
}
|
||||
if (me.children.indexOf(request) === -1) {
|
||||
me.children.push(request);
|
||||
}
|
||||
} else {
|
||||
console.warn(
|
||||
"[HMR] unexpected require(" +
|
||||
request +
|
||||
") from disposed module " +
|
||||
moduleId
|
||||
);
|
||||
hotCurrentParents = [];
|
||||
}
|
||||
return $require$(request);
|
||||
};
|
||||
var ObjectFactory = function ObjectFactory(name) {
|
||||
return {
|
||||
configurable: true,
|
||||
enumerable: true,
|
||||
get: function() {
|
||||
return $require$[name];
|
||||
},
|
||||
set: function(value) {
|
||||
$require$[name] = value;
|
||||
}
|
||||
};
|
||||
};
|
||||
for (var name in $require$) {
|
||||
if (
|
||||
Object.prototype.hasOwnProperty.call($require$, name) &&
|
||||
name !== "e" &&
|
||||
name !== "t"
|
||||
) {
|
||||
Object.defineProperty(fn, name, ObjectFactory(name));
|
||||
}
|
||||
}
|
||||
fn.e = function(chunkId) {
|
||||
if (hotStatus === "ready") hotSetStatus("prepare");
|
||||
hotChunksLoading++;
|
||||
return $require$.e(chunkId).then(finishChunkLoading, function(err) {
|
||||
finishChunkLoading();
|
||||
throw err;
|
||||
});
|
||||
|
||||
function finishChunkLoading() {
|
||||
hotChunksLoading--;
|
||||
if (hotStatus === "prepare") {
|
||||
if (!hotWaitingFilesMap[chunkId]) {
|
||||
hotEnsureUpdateChunk(chunkId);
|
||||
}
|
||||
if (hotChunksLoading === 0 && hotWaitingFiles === 0) {
|
||||
hotUpdateDownloaded();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
fn.t = function(value, mode) {
|
||||
if (mode & 1) value = fn(value);
|
||||
return $require$.t(value, mode & ~1);
|
||||
};
|
||||
return fn;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
function hotCreateModule(moduleId) {
|
||||
var hot = {
|
||||
// private stuff
|
||||
_acceptedDependencies: {},
|
||||
_declinedDependencies: {},
|
||||
_selfAccepted: false,
|
||||
_selfDeclined: false,
|
||||
_selfInvalidated: false,
|
||||
_disposeHandlers: [],
|
||||
_main: hotCurrentChildModule !== moduleId,
|
||||
|
||||
// Module API
|
||||
active: true,
|
||||
accept: function(dep, callback) {
|
||||
if (dep === undefined) hot._selfAccepted = true;
|
||||
else if (typeof dep === "function") hot._selfAccepted = dep;
|
||||
else if (typeof dep === "object")
|
||||
for (var i = 0; i < dep.length; i++)
|
||||
hot._acceptedDependencies[dep[i]] = callback || function() {};
|
||||
else hot._acceptedDependencies[dep] = callback || function() {};
|
||||
},
|
||||
decline: function(dep) {
|
||||
if (dep === undefined) hot._selfDeclined = true;
|
||||
else if (typeof dep === "object")
|
||||
for (var i = 0; i < dep.length; i++)
|
||||
hot._declinedDependencies[dep[i]] = true;
|
||||
else hot._declinedDependencies[dep] = true;
|
||||
},
|
||||
dispose: function(callback) {
|
||||
hot._disposeHandlers.push(callback);
|
||||
},
|
||||
addDisposeHandler: function(callback) {
|
||||
hot._disposeHandlers.push(callback);
|
||||
},
|
||||
removeDisposeHandler: function(callback) {
|
||||
var idx = hot._disposeHandlers.indexOf(callback);
|
||||
if (idx >= 0) hot._disposeHandlers.splice(idx, 1);
|
||||
},
|
||||
invalidate: function() {
|
||||
this._selfInvalidated = true;
|
||||
switch (hotStatus) {
|
||||
case "idle":
|
||||
hotUpdate = {};
|
||||
hotUpdate[moduleId] = modules[moduleId];
|
||||
hotSetStatus("ready");
|
||||
break;
|
||||
case "ready":
|
||||
hotApplyInvalidatedModule(moduleId);
|
||||
break;
|
||||
case "prepare":
|
||||
case "check":
|
||||
case "dispose":
|
||||
case "apply":
|
||||
(hotQueuedInvalidatedModules =
|
||||
hotQueuedInvalidatedModules || []).push(moduleId);
|
||||
break;
|
||||
default:
|
||||
// ignore requests in error states
|
||||
break;
|
||||
}
|
||||
},
|
||||
|
||||
// Management API
|
||||
check: hotCheck,
|
||||
apply: hotApply,
|
||||
status: function(l) {
|
||||
if (!l) return hotStatus;
|
||||
hotStatusHandlers.push(l);
|
||||
},
|
||||
addStatusHandler: function(l) {
|
||||
hotStatusHandlers.push(l);
|
||||
},
|
||||
removeStatusHandler: function(l) {
|
||||
var idx = hotStatusHandlers.indexOf(l);
|
||||
if (idx >= 0) hotStatusHandlers.splice(idx, 1);
|
||||
},
|
||||
|
||||
//inherit from previous dispose call
|
||||
data: hotCurrentModuleData[moduleId]
|
||||
};
|
||||
hotCurrentChildModule = undefined;
|
||||
return hot;
|
||||
}
|
||||
|
||||
var hotStatusHandlers = [];
|
||||
var hotStatus = "idle";
|
||||
|
||||
function hotSetStatus(newStatus) {
|
||||
hotStatus = newStatus;
|
||||
for (var i = 0; i < hotStatusHandlers.length; i++)
|
||||
hotStatusHandlers[i].call(null, newStatus);
|
||||
}
|
||||
|
||||
// while downloading
|
||||
var hotWaitingFiles = 0;
|
||||
var hotChunksLoading = 0;
|
||||
var hotWaitingFilesMap = {};
|
||||
var hotRequestedFilesMap = {};
|
||||
var hotAvailableFilesMap = {};
|
||||
var hotDeferred;
|
||||
|
||||
// The update info
|
||||
var hotUpdate, hotUpdateNewHash, hotQueuedInvalidatedModules;
|
||||
|
||||
function toModuleId(id) {
|
||||
var isNumber = +id + "" === id;
|
||||
return isNumber ? +id : id;
|
||||
}
|
||||
|
||||
function hotCheck(apply) {
|
||||
if (hotStatus !== "idle") {
|
||||
throw new Error("check() is only allowed in idle status");
|
||||
}
|
||||
hotApplyOnUpdate = apply;
|
||||
hotSetStatus("check");
|
||||
return hotDownloadManifest(hotRequestTimeout).then(function(update) {
|
||||
if (!update) {
|
||||
hotSetStatus(hotApplyInvalidatedModules() ? "ready" : "idle");
|
||||
return null;
|
||||
}
|
||||
hotRequestedFilesMap = {};
|
||||
hotWaitingFilesMap = {};
|
||||
hotAvailableFilesMap = update.c;
|
||||
hotUpdateNewHash = update.h;
|
||||
|
||||
hotSetStatus("prepare");
|
||||
var promise = new Promise(function(resolve, reject) {
|
||||
hotDeferred = {
|
||||
resolve: resolve,
|
||||
reject: reject
|
||||
};
|
||||
});
|
||||
hotUpdate = {};
|
||||
/*foreachInstalledChunks*/
|
||||
// eslint-disable-next-line no-lone-blocks
|
||||
{
|
||||
hotEnsureUpdateChunk(chunkId);
|
||||
}
|
||||
if (
|
||||
hotStatus === "prepare" &&
|
||||
hotChunksLoading === 0 &&
|
||||
hotWaitingFiles === 0
|
||||
) {
|
||||
hotUpdateDownloaded();
|
||||
}
|
||||
return promise;
|
||||
});
|
||||
}
|
||||
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
function hotAddUpdateChunk(chunkId, moreModules) {
|
||||
if (!hotAvailableFilesMap[chunkId] || !hotRequestedFilesMap[chunkId])
|
||||
return;
|
||||
hotRequestedFilesMap[chunkId] = false;
|
||||
for (var moduleId in moreModules) {
|
||||
if (Object.prototype.hasOwnProperty.call(moreModules, moduleId)) {
|
||||
hotUpdate[moduleId] = moreModules[moduleId];
|
||||
}
|
||||
}
|
||||
if (--hotWaitingFiles === 0 && hotChunksLoading === 0) {
|
||||
hotUpdateDownloaded();
|
||||
}
|
||||
}
|
||||
|
||||
function hotEnsureUpdateChunk(chunkId) {
|
||||
if (!hotAvailableFilesMap[chunkId]) {
|
||||
hotWaitingFilesMap[chunkId] = true;
|
||||
} else {
|
||||
hotRequestedFilesMap[chunkId] = true;
|
||||
hotWaitingFiles++;
|
||||
hotDownloadUpdateChunk(chunkId);
|
||||
}
|
||||
}
|
||||
|
||||
function hotUpdateDownloaded() {
|
||||
hotSetStatus("ready");
|
||||
var deferred = hotDeferred;
|
||||
hotDeferred = null;
|
||||
if (!deferred) return;
|
||||
if (hotApplyOnUpdate) {
|
||||
// Wrap deferred object in Promise to mark it as a well-handled Promise to
|
||||
// avoid triggering uncaught exception warning in Chrome.
|
||||
// See https://bugs.chromium.org/p/chromium/issues/detail?id=465666
|
||||
Promise.resolve()
|
||||
.then(function() {
|
||||
return hotApply(hotApplyOnUpdate);
|
||||
})
|
||||
.then(
|
||||
function(result) {
|
||||
deferred.resolve(result);
|
||||
},
|
||||
function(err) {
|
||||
deferred.reject(err);
|
||||
}
|
||||
);
|
||||
} else {
|
||||
var outdatedModules = [];
|
||||
for (var id in hotUpdate) {
|
||||
if (Object.prototype.hasOwnProperty.call(hotUpdate, id)) {
|
||||
outdatedModules.push(toModuleId(id));
|
||||
}
|
||||
}
|
||||
deferred.resolve(outdatedModules);
|
||||
}
|
||||
}
|
||||
|
||||
function hotApply(options) {
|
||||
if (hotStatus !== "ready")
|
||||
throw new Error("apply() is only allowed in ready status");
|
||||
options = options || {};
|
||||
return hotApplyInternal(options);
|
||||
}
|
||||
|
||||
function hotApplyInternal(options) {
|
||||
hotApplyInvalidatedModules();
|
||||
|
||||
var cb;
|
||||
var i;
|
||||
var j;
|
||||
var module;
|
||||
var moduleId;
|
||||
|
||||
function getAffectedStuff(updateModuleId) {
|
||||
var outdatedModules = [updateModuleId];
|
||||
var outdatedDependencies = {};
|
||||
|
||||
var queue = outdatedModules.map(function(id) {
|
||||
return {
|
||||
chain: [id],
|
||||
id: id
|
||||
};
|
||||
});
|
||||
while (queue.length > 0) {
|
||||
var queueItem = queue.pop();
|
||||
var moduleId = queueItem.id;
|
||||
var chain = queueItem.chain;
|
||||
module = installedModules[moduleId];
|
||||
if (
|
||||
!module ||
|
||||
(module.hot._selfAccepted && !module.hot._selfInvalidated)
|
||||
)
|
||||
continue;
|
||||
if (module.hot._selfDeclined) {
|
||||
return {
|
||||
type: "self-declined",
|
||||
chain: chain,
|
||||
moduleId: moduleId
|
||||
};
|
||||
}
|
||||
if (module.hot._main) {
|
||||
return {
|
||||
type: "unaccepted",
|
||||
chain: chain,
|
||||
moduleId: moduleId
|
||||
};
|
||||
}
|
||||
for (var i = 0; i < module.parents.length; i++) {
|
||||
var parentId = module.parents[i];
|
||||
var parent = installedModules[parentId];
|
||||
if (!parent) continue;
|
||||
if (parent.hot._declinedDependencies[moduleId]) {
|
||||
return {
|
||||
type: "declined",
|
||||
chain: chain.concat([parentId]),
|
||||
moduleId: moduleId,
|
||||
parentId: parentId
|
||||
};
|
||||
}
|
||||
if (outdatedModules.indexOf(parentId) !== -1) continue;
|
||||
if (parent.hot._acceptedDependencies[moduleId]) {
|
||||
if (!outdatedDependencies[parentId])
|
||||
outdatedDependencies[parentId] = [];
|
||||
addAllToSet(outdatedDependencies[parentId], [moduleId]);
|
||||
continue;
|
||||
}
|
||||
delete outdatedDependencies[parentId];
|
||||
outdatedModules.push(parentId);
|
||||
queue.push({
|
||||
chain: chain.concat([parentId]),
|
||||
id: parentId
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
type: "accepted",
|
||||
moduleId: updateModuleId,
|
||||
outdatedModules: outdatedModules,
|
||||
outdatedDependencies: outdatedDependencies
|
||||
};
|
||||
}
|
||||
|
||||
function addAllToSet(a, b) {
|
||||
for (var i = 0; i < b.length; i++) {
|
||||
var item = b[i];
|
||||
if (a.indexOf(item) === -1) a.push(item);
|
||||
}
|
||||
}
|
||||
|
||||
// at begin all updates modules are outdated
|
||||
// the "outdated" status can propagate to parents if they don't accept the children
|
||||
var outdatedDependencies = {};
|
||||
var outdatedModules = [];
|
||||
var appliedUpdate = {};
|
||||
|
||||
var warnUnexpectedRequire = function warnUnexpectedRequire() {
|
||||
console.warn(
|
||||
"[HMR] unexpected require(" + result.moduleId + ") to disposed module"
|
||||
);
|
||||
};
|
||||
|
||||
for (var id in hotUpdate) {
|
||||
if (Object.prototype.hasOwnProperty.call(hotUpdate, id)) {
|
||||
moduleId = toModuleId(id);
|
||||
/** @type {TODO} */
|
||||
var result;
|
||||
if (hotUpdate[id]) {
|
||||
result = getAffectedStuff(moduleId);
|
||||
} else {
|
||||
result = {
|
||||
type: "disposed",
|
||||
moduleId: id
|
||||
};
|
||||
}
|
||||
/** @type {Error|false} */
|
||||
var abortError = false;
|
||||
var doApply = false;
|
||||
var doDispose = false;
|
||||
var chainInfo = "";
|
||||
if (result.chain) {
|
||||
chainInfo = "\nUpdate propagation: " + result.chain.join(" -> ");
|
||||
}
|
||||
switch (result.type) {
|
||||
case "self-declined":
|
||||
if (options.onDeclined) options.onDeclined(result);
|
||||
if (!options.ignoreDeclined)
|
||||
abortError = new Error(
|
||||
"Aborted because of self decline: " +
|
||||
result.moduleId +
|
||||
chainInfo
|
||||
);
|
||||
break;
|
||||
case "declined":
|
||||
if (options.onDeclined) options.onDeclined(result);
|
||||
if (!options.ignoreDeclined)
|
||||
abortError = new Error(
|
||||
"Aborted because of declined dependency: " +
|
||||
result.moduleId +
|
||||
" in " +
|
||||
result.parentId +
|
||||
chainInfo
|
||||
);
|
||||
break;
|
||||
case "unaccepted":
|
||||
if (options.onUnaccepted) options.onUnaccepted(result);
|
||||
if (!options.ignoreUnaccepted)
|
||||
abortError = new Error(
|
||||
"Aborted because " + moduleId + " is not accepted" + chainInfo
|
||||
);
|
||||
break;
|
||||
case "accepted":
|
||||
if (options.onAccepted) options.onAccepted(result);
|
||||
doApply = true;
|
||||
break;
|
||||
case "disposed":
|
||||
if (options.onDisposed) options.onDisposed(result);
|
||||
doDispose = true;
|
||||
break;
|
||||
default:
|
||||
throw new Error("Unexception type " + result.type);
|
||||
}
|
||||
if (abortError) {
|
||||
hotSetStatus("abort");
|
||||
return Promise.reject(abortError);
|
||||
}
|
||||
if (doApply) {
|
||||
appliedUpdate[moduleId] = hotUpdate[moduleId];
|
||||
addAllToSet(outdatedModules, result.outdatedModules);
|
||||
for (moduleId in result.outdatedDependencies) {
|
||||
if (
|
||||
Object.prototype.hasOwnProperty.call(
|
||||
result.outdatedDependencies,
|
||||
moduleId
|
||||
)
|
||||
) {
|
||||
if (!outdatedDependencies[moduleId])
|
||||
outdatedDependencies[moduleId] = [];
|
||||
addAllToSet(
|
||||
outdatedDependencies[moduleId],
|
||||
result.outdatedDependencies[moduleId]
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (doDispose) {
|
||||
addAllToSet(outdatedModules, [result.moduleId]);
|
||||
appliedUpdate[moduleId] = warnUnexpectedRequire;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Store self accepted outdated modules to require them later by the module system
|
||||
var outdatedSelfAcceptedModules = [];
|
||||
for (i = 0; i < outdatedModules.length; i++) {
|
||||
moduleId = outdatedModules[i];
|
||||
if (
|
||||
installedModules[moduleId] &&
|
||||
installedModules[moduleId].hot._selfAccepted &&
|
||||
// removed self-accepted modules should not be required
|
||||
appliedUpdate[moduleId] !== warnUnexpectedRequire &&
|
||||
// when called invalidate self-accepting is not possible
|
||||
!installedModules[moduleId].hot._selfInvalidated
|
||||
) {
|
||||
outdatedSelfAcceptedModules.push({
|
||||
module: moduleId,
|
||||
parents: installedModules[moduleId].parents.slice(),
|
||||
errorHandler: installedModules[moduleId].hot._selfAccepted
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Now in "dispose" phase
|
||||
hotSetStatus("dispose");
|
||||
Object.keys(hotAvailableFilesMap).forEach(function(chunkId) {
|
||||
if (hotAvailableFilesMap[chunkId] === false) {
|
||||
hotDisposeChunk(chunkId);
|
||||
}
|
||||
});
|
||||
|
||||
var idx;
|
||||
var queue = outdatedModules.slice();
|
||||
while (queue.length > 0) {
|
||||
moduleId = queue.pop();
|
||||
module = installedModules[moduleId];
|
||||
if (!module) continue;
|
||||
|
||||
var data = {};
|
||||
|
||||
// Call dispose handlers
|
||||
var disposeHandlers = module.hot._disposeHandlers;
|
||||
for (j = 0; j < disposeHandlers.length; j++) {
|
||||
cb = disposeHandlers[j];
|
||||
cb(data);
|
||||
}
|
||||
hotCurrentModuleData[moduleId] = data;
|
||||
|
||||
// disable module (this disables requires from this module)
|
||||
module.hot.active = false;
|
||||
|
||||
// remove module from cache
|
||||
delete installedModules[moduleId];
|
||||
|
||||
// when disposing there is no need to call dispose handler
|
||||
delete outdatedDependencies[moduleId];
|
||||
|
||||
// remove "parents" references from all children
|
||||
for (j = 0; j < module.children.length; j++) {
|
||||
var child = installedModules[module.children[j]];
|
||||
if (!child) continue;
|
||||
idx = child.parents.indexOf(moduleId);
|
||||
if (idx >= 0) {
|
||||
child.parents.splice(idx, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// remove outdated dependency from module children
|
||||
var dependency;
|
||||
var moduleOutdatedDependencies;
|
||||
for (moduleId in outdatedDependencies) {
|
||||
if (
|
||||
Object.prototype.hasOwnProperty.call(outdatedDependencies, moduleId)
|
||||
) {
|
||||
module = installedModules[moduleId];
|
||||
if (module) {
|
||||
moduleOutdatedDependencies = outdatedDependencies[moduleId];
|
||||
for (j = 0; j < moduleOutdatedDependencies.length; j++) {
|
||||
dependency = moduleOutdatedDependencies[j];
|
||||
idx = module.children.indexOf(dependency);
|
||||
if (idx >= 0) module.children.splice(idx, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Now in "apply" phase
|
||||
hotSetStatus("apply");
|
||||
|
||||
if (hotUpdateNewHash !== undefined) {
|
||||
hotCurrentHash = hotUpdateNewHash;
|
||||
hotUpdateNewHash = undefined;
|
||||
}
|
||||
hotUpdate = undefined;
|
||||
|
||||
// insert new code
|
||||
for (moduleId in appliedUpdate) {
|
||||
if (Object.prototype.hasOwnProperty.call(appliedUpdate, moduleId)) {
|
||||
modules[moduleId] = appliedUpdate[moduleId];
|
||||
}
|
||||
}
|
||||
|
||||
// call accept handlers
|
||||
var error = null;
|
||||
for (moduleId in outdatedDependencies) {
|
||||
if (
|
||||
Object.prototype.hasOwnProperty.call(outdatedDependencies, moduleId)
|
||||
) {
|
||||
module = installedModules[moduleId];
|
||||
if (module) {
|
||||
moduleOutdatedDependencies = outdatedDependencies[moduleId];
|
||||
var callbacks = [];
|
||||
for (i = 0; i < moduleOutdatedDependencies.length; i++) {
|
||||
dependency = moduleOutdatedDependencies[i];
|
||||
cb = module.hot._acceptedDependencies[dependency];
|
||||
if (cb) {
|
||||
if (callbacks.indexOf(cb) !== -1) continue;
|
||||
callbacks.push(cb);
|
||||
}
|
||||
}
|
||||
for (i = 0; i < callbacks.length; i++) {
|
||||
cb = callbacks[i];
|
||||
try {
|
||||
cb(moduleOutdatedDependencies);
|
||||
} catch (err) {
|
||||
if (options.onErrored) {
|
||||
options.onErrored({
|
||||
type: "accept-errored",
|
||||
moduleId: moduleId,
|
||||
dependencyId: moduleOutdatedDependencies[i],
|
||||
error: err
|
||||
});
|
||||
}
|
||||
if (!options.ignoreErrored) {
|
||||
if (!error) error = err;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Load self accepted modules
|
||||
for (i = 0; i < outdatedSelfAcceptedModules.length; i++) {
|
||||
var item = outdatedSelfAcceptedModules[i];
|
||||
moduleId = item.module;
|
||||
hotCurrentParents = item.parents;
|
||||
hotCurrentChildModule = moduleId;
|
||||
try {
|
||||
$require$(moduleId);
|
||||
} catch (err) {
|
||||
if (typeof item.errorHandler === "function") {
|
||||
try {
|
||||
item.errorHandler(err);
|
||||
} catch (err2) {
|
||||
if (options.onErrored) {
|
||||
options.onErrored({
|
||||
type: "self-accept-error-handler-errored",
|
||||
moduleId: moduleId,
|
||||
error: err2,
|
||||
originalError: err
|
||||
});
|
||||
}
|
||||
if (!options.ignoreErrored) {
|
||||
if (!error) error = err2;
|
||||
}
|
||||
if (!error) error = err;
|
||||
}
|
||||
} else {
|
||||
if (options.onErrored) {
|
||||
options.onErrored({
|
||||
type: "self-accept-errored",
|
||||
moduleId: moduleId,
|
||||
error: err
|
||||
});
|
||||
}
|
||||
if (!options.ignoreErrored) {
|
||||
if (!error) error = err;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// handle errors in accept handlers and self accepted module load
|
||||
if (error) {
|
||||
hotSetStatus("fail");
|
||||
return Promise.reject(error);
|
||||
}
|
||||
|
||||
if (hotQueuedInvalidatedModules) {
|
||||
return hotApplyInternal(options).then(function(list) {
|
||||
outdatedModules.forEach(function(moduleId) {
|
||||
if (list.indexOf(moduleId) < 0) list.push(moduleId);
|
||||
});
|
||||
return list;
|
||||
});
|
||||
}
|
||||
|
||||
hotSetStatus("idle");
|
||||
return new Promise(function(resolve) {
|
||||
resolve(outdatedModules);
|
||||
});
|
||||
}
|
||||
|
||||
function hotApplyInvalidatedModules() {
|
||||
if (hotQueuedInvalidatedModules) {
|
||||
if (!hotUpdate) hotUpdate = {};
|
||||
hotQueuedInvalidatedModules.forEach(hotApplyInvalidatedModule);
|
||||
hotQueuedInvalidatedModules = undefined;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
function hotApplyInvalidatedModule(moduleId) {
|
||||
if (!Object.prototype.hasOwnProperty.call(hotUpdate, moduleId))
|
||||
hotUpdate[moduleId] = modules[moduleId];
|
||||
}
|
||||
};
|
||||
425
node_modules/webpack/lib/HotModuleReplacementPlugin.js
generated
vendored
Normal file
425
node_modules/webpack/lib/HotModuleReplacementPlugin.js
generated
vendored
Normal file
|
|
@ -0,0 +1,425 @@
|
|||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
"use strict";
|
||||
|
||||
const { SyncBailHook } = require("tapable");
|
||||
const { RawSource } = require("webpack-sources");
|
||||
const Template = require("./Template");
|
||||
const ModuleHotAcceptDependency = require("./dependencies/ModuleHotAcceptDependency");
|
||||
const ModuleHotDeclineDependency = require("./dependencies/ModuleHotDeclineDependency");
|
||||
const ConstDependency = require("./dependencies/ConstDependency");
|
||||
const NullFactory = require("./NullFactory");
|
||||
const ParserHelpers = require("./ParserHelpers");
|
||||
|
||||
module.exports = class HotModuleReplacementPlugin {
|
||||
constructor(options) {
|
||||
this.options = options || {};
|
||||
this.multiStep = this.options.multiStep;
|
||||
this.fullBuildTimeout = this.options.fullBuildTimeout || 200;
|
||||
this.requestTimeout = this.options.requestTimeout || 10000;
|
||||
}
|
||||
|
||||
apply(compiler) {
|
||||
const multiStep = this.multiStep;
|
||||
const fullBuildTimeout = this.fullBuildTimeout;
|
||||
const requestTimeout = this.requestTimeout;
|
||||
const hotUpdateChunkFilename =
|
||||
compiler.options.output.hotUpdateChunkFilename;
|
||||
const hotUpdateMainFilename = compiler.options.output.hotUpdateMainFilename;
|
||||
compiler.hooks.additionalPass.tapAsync(
|
||||
"HotModuleReplacementPlugin",
|
||||
callback => {
|
||||
if (multiStep) return setTimeout(callback, fullBuildTimeout);
|
||||
return callback();
|
||||
}
|
||||
);
|
||||
|
||||
const addParserPlugins = (parser, parserOptions) => {
|
||||
parser.hooks.expression
|
||||
.for("__webpack_hash__")
|
||||
.tap(
|
||||
"HotModuleReplacementPlugin",
|
||||
ParserHelpers.toConstantDependencyWithWebpackRequire(
|
||||
parser,
|
||||
"__webpack_require__.h()"
|
||||
)
|
||||
);
|
||||
parser.hooks.evaluateTypeof
|
||||
.for("__webpack_hash__")
|
||||
.tap(
|
||||
"HotModuleReplacementPlugin",
|
||||
ParserHelpers.evaluateToString("string")
|
||||
);
|
||||
parser.hooks.evaluateIdentifier.for("module.hot").tap(
|
||||
{
|
||||
name: "HotModuleReplacementPlugin",
|
||||
before: "NodeStuffPlugin"
|
||||
},
|
||||
expr => {
|
||||
return ParserHelpers.evaluateToIdentifier(
|
||||
"module.hot",
|
||||
!!parser.state.compilation.hotUpdateChunkTemplate
|
||||
)(expr);
|
||||
}
|
||||
);
|
||||
// TODO webpack 5: refactor this, no custom hooks
|
||||
if (!parser.hooks.hotAcceptCallback) {
|
||||
parser.hooks.hotAcceptCallback = new SyncBailHook([
|
||||
"expression",
|
||||
"requests"
|
||||
]);
|
||||
}
|
||||
if (!parser.hooks.hotAcceptWithoutCallback) {
|
||||
parser.hooks.hotAcceptWithoutCallback = new SyncBailHook([
|
||||
"expression",
|
||||
"requests"
|
||||
]);
|
||||
}
|
||||
parser.hooks.call
|
||||
.for("module.hot.accept")
|
||||
.tap("HotModuleReplacementPlugin", expr => {
|
||||
if (!parser.state.compilation.hotUpdateChunkTemplate) {
|
||||
return false;
|
||||
}
|
||||
if (expr.arguments.length >= 1) {
|
||||
const arg = parser.evaluateExpression(expr.arguments[0]);
|
||||
let params = [];
|
||||
let requests = [];
|
||||
if (arg.isString()) {
|
||||
params = [arg];
|
||||
} else if (arg.isArray()) {
|
||||
params = arg.items.filter(param => param.isString());
|
||||
}
|
||||
if (params.length > 0) {
|
||||
params.forEach((param, idx) => {
|
||||
const request = param.string;
|
||||
const dep = new ModuleHotAcceptDependency(request, param.range);
|
||||
dep.optional = true;
|
||||
dep.loc = Object.create(expr.loc);
|
||||
dep.loc.index = idx;
|
||||
parser.state.module.addDependency(dep);
|
||||
requests.push(request);
|
||||
});
|
||||
if (expr.arguments.length > 1) {
|
||||
parser.hooks.hotAcceptCallback.call(
|
||||
expr.arguments[1],
|
||||
requests
|
||||
);
|
||||
parser.walkExpression(expr.arguments[1]); // other args are ignored
|
||||
return true;
|
||||
} else {
|
||||
parser.hooks.hotAcceptWithoutCallback.call(expr, requests);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
parser.hooks.call
|
||||
.for("module.hot.decline")
|
||||
.tap("HotModuleReplacementPlugin", expr => {
|
||||
if (!parser.state.compilation.hotUpdateChunkTemplate) {
|
||||
return false;
|
||||
}
|
||||
if (expr.arguments.length === 1) {
|
||||
const arg = parser.evaluateExpression(expr.arguments[0]);
|
||||
let params = [];
|
||||
if (arg.isString()) {
|
||||
params = [arg];
|
||||
} else if (arg.isArray()) {
|
||||
params = arg.items.filter(param => param.isString());
|
||||
}
|
||||
params.forEach((param, idx) => {
|
||||
const dep = new ModuleHotDeclineDependency(
|
||||
param.string,
|
||||
param.range
|
||||
);
|
||||
dep.optional = true;
|
||||
dep.loc = Object.create(expr.loc);
|
||||
dep.loc.index = idx;
|
||||
parser.state.module.addDependency(dep);
|
||||
});
|
||||
}
|
||||
});
|
||||
parser.hooks.expression
|
||||
.for("module.hot")
|
||||
.tap("HotModuleReplacementPlugin", ParserHelpers.skipTraversal);
|
||||
};
|
||||
|
||||
compiler.hooks.compilation.tap(
|
||||
"HotModuleReplacementPlugin",
|
||||
(compilation, { normalModuleFactory }) => {
|
||||
// This applies the HMR plugin only to the targeted compiler
|
||||
// It should not affect child compilations
|
||||
if (compilation.compiler !== compiler) return;
|
||||
|
||||
const hotUpdateChunkTemplate = compilation.hotUpdateChunkTemplate;
|
||||
if (!hotUpdateChunkTemplate) return;
|
||||
|
||||
compilation.dependencyFactories.set(ConstDependency, new NullFactory());
|
||||
compilation.dependencyTemplates.set(
|
||||
ConstDependency,
|
||||
new ConstDependency.Template()
|
||||
);
|
||||
|
||||
compilation.dependencyFactories.set(
|
||||
ModuleHotAcceptDependency,
|
||||
normalModuleFactory
|
||||
);
|
||||
compilation.dependencyTemplates.set(
|
||||
ModuleHotAcceptDependency,
|
||||
new ModuleHotAcceptDependency.Template()
|
||||
);
|
||||
|
||||
compilation.dependencyFactories.set(
|
||||
ModuleHotDeclineDependency,
|
||||
normalModuleFactory
|
||||
);
|
||||
compilation.dependencyTemplates.set(
|
||||
ModuleHotDeclineDependency,
|
||||
new ModuleHotDeclineDependency.Template()
|
||||
);
|
||||
|
||||
compilation.hooks.record.tap(
|
||||
"HotModuleReplacementPlugin",
|
||||
(compilation, records) => {
|
||||
if (records.hash === compilation.hash) return;
|
||||
records.hash = compilation.hash;
|
||||
records.moduleHashs = {};
|
||||
for (const module of compilation.modules) {
|
||||
const identifier = module.identifier();
|
||||
records.moduleHashs[identifier] = module.hash;
|
||||
}
|
||||
records.chunkHashs = {};
|
||||
for (const chunk of compilation.chunks) {
|
||||
records.chunkHashs[chunk.id] = chunk.hash;
|
||||
}
|
||||
records.chunkModuleIds = {};
|
||||
for (const chunk of compilation.chunks) {
|
||||
records.chunkModuleIds[chunk.id] = Array.from(
|
||||
chunk.modulesIterable,
|
||||
m => m.id
|
||||
);
|
||||
}
|
||||
}
|
||||
);
|
||||
let initialPass = false;
|
||||
let recompilation = false;
|
||||
compilation.hooks.afterHash.tap("HotModuleReplacementPlugin", () => {
|
||||
let records = compilation.records;
|
||||
if (!records) {
|
||||
initialPass = true;
|
||||
return;
|
||||
}
|
||||
if (!records.hash) initialPass = true;
|
||||
const preHash = records.preHash || "x";
|
||||
const prepreHash = records.prepreHash || "x";
|
||||
if (preHash === compilation.hash) {
|
||||
recompilation = true;
|
||||
compilation.modifyHash(prepreHash);
|
||||
return;
|
||||
}
|
||||
records.prepreHash = records.hash || "x";
|
||||
records.preHash = compilation.hash;
|
||||
compilation.modifyHash(records.prepreHash);
|
||||
});
|
||||
compilation.hooks.shouldGenerateChunkAssets.tap(
|
||||
"HotModuleReplacementPlugin",
|
||||
() => {
|
||||
if (multiStep && !recompilation && !initialPass) return false;
|
||||
}
|
||||
);
|
||||
compilation.hooks.needAdditionalPass.tap(
|
||||
"HotModuleReplacementPlugin",
|
||||
() => {
|
||||
if (multiStep && !recompilation && !initialPass) return true;
|
||||
}
|
||||
);
|
||||
compilation.hooks.additionalChunkAssets.tap(
|
||||
"HotModuleReplacementPlugin",
|
||||
() => {
|
||||
const records = compilation.records;
|
||||
if (records.hash === compilation.hash) return;
|
||||
if (
|
||||
!records.moduleHashs ||
|
||||
!records.chunkHashs ||
|
||||
!records.chunkModuleIds
|
||||
)
|
||||
return;
|
||||
for (const module of compilation.modules) {
|
||||
const identifier = module.identifier();
|
||||
let hash = module.hash;
|
||||
module.hotUpdate = records.moduleHashs[identifier] !== hash;
|
||||
}
|
||||
const hotUpdateMainContent = {
|
||||
h: compilation.hash,
|
||||
c: {}
|
||||
};
|
||||
for (const key of Object.keys(records.chunkHashs)) {
|
||||
const chunkId = isNaN(+key) ? key : +key;
|
||||
const currentChunk = compilation.chunks.find(
|
||||
chunk => `${chunk.id}` === key
|
||||
);
|
||||
if (currentChunk) {
|
||||
const newModules = currentChunk
|
||||
.getModules()
|
||||
.filter(module => module.hotUpdate);
|
||||
const allModules = new Set();
|
||||
for (const module of currentChunk.modulesIterable) {
|
||||
allModules.add(module.id);
|
||||
}
|
||||
const removedModules = records.chunkModuleIds[chunkId].filter(
|
||||
id => !allModules.has(id)
|
||||
);
|
||||
if (newModules.length > 0 || removedModules.length > 0) {
|
||||
const source = hotUpdateChunkTemplate.render(
|
||||
chunkId,
|
||||
newModules,
|
||||
removedModules,
|
||||
compilation.hash,
|
||||
compilation.moduleTemplates.javascript,
|
||||
compilation.dependencyTemplates
|
||||
);
|
||||
const {
|
||||
path: filename,
|
||||
info: assetInfo
|
||||
} = compilation.getPathWithInfo(hotUpdateChunkFilename, {
|
||||
hash: records.hash,
|
||||
chunk: currentChunk
|
||||
});
|
||||
compilation.additionalChunkAssets.push(filename);
|
||||
compilation.emitAsset(
|
||||
filename,
|
||||
source,
|
||||
Object.assign({ hotModuleReplacement: true }, assetInfo)
|
||||
);
|
||||
hotUpdateMainContent.c[chunkId] = true;
|
||||
currentChunk.files.push(filename);
|
||||
compilation.hooks.chunkAsset.call(currentChunk, filename);
|
||||
}
|
||||
} else {
|
||||
hotUpdateMainContent.c[chunkId] = false;
|
||||
}
|
||||
}
|
||||
const source = new RawSource(JSON.stringify(hotUpdateMainContent));
|
||||
const {
|
||||
path: filename,
|
||||
info: assetInfo
|
||||
} = compilation.getPathWithInfo(hotUpdateMainFilename, {
|
||||
hash: records.hash
|
||||
});
|
||||
compilation.emitAsset(
|
||||
filename,
|
||||
source,
|
||||
Object.assign({ hotModuleReplacement: true }, assetInfo)
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
const mainTemplate = compilation.mainTemplate;
|
||||
|
||||
mainTemplate.hooks.hash.tap("HotModuleReplacementPlugin", hash => {
|
||||
hash.update("HotMainTemplateDecorator");
|
||||
});
|
||||
|
||||
mainTemplate.hooks.moduleRequire.tap(
|
||||
"HotModuleReplacementPlugin",
|
||||
(_, chunk, hash, varModuleId) => {
|
||||
return `hotCreateRequire(${varModuleId})`;
|
||||
}
|
||||
);
|
||||
|
||||
mainTemplate.hooks.requireExtensions.tap(
|
||||
"HotModuleReplacementPlugin",
|
||||
source => {
|
||||
const buf = [source];
|
||||
buf.push("");
|
||||
buf.push("// __webpack_hash__");
|
||||
buf.push(
|
||||
mainTemplate.requireFn +
|
||||
".h = function() { return hotCurrentHash; };"
|
||||
);
|
||||
return Template.asString(buf);
|
||||
}
|
||||
);
|
||||
|
||||
const needChunkLoadingCode = chunk => {
|
||||
for (const chunkGroup of chunk.groupsIterable) {
|
||||
if (chunkGroup.chunks.length > 1) return true;
|
||||
if (chunkGroup.getNumberOfChildren() > 0) return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
mainTemplate.hooks.bootstrap.tap(
|
||||
"HotModuleReplacementPlugin",
|
||||
(source, chunk, hash) => {
|
||||
source = mainTemplate.hooks.hotBootstrap.call(source, chunk, hash);
|
||||
return Template.asString([
|
||||
source,
|
||||
"",
|
||||
hotInitCode
|
||||
.replace(/\$require\$/g, mainTemplate.requireFn)
|
||||
.replace(/\$hash\$/g, JSON.stringify(hash))
|
||||
.replace(/\$requestTimeout\$/g, requestTimeout)
|
||||
.replace(
|
||||
/\/\*foreachInstalledChunks\*\//g,
|
||||
needChunkLoadingCode(chunk)
|
||||
? "for(var chunkId in installedChunks)"
|
||||
: `var chunkId = ${JSON.stringify(chunk.id)};`
|
||||
)
|
||||
]);
|
||||
}
|
||||
);
|
||||
|
||||
mainTemplate.hooks.globalHash.tap(
|
||||
"HotModuleReplacementPlugin",
|
||||
() => true
|
||||
);
|
||||
|
||||
mainTemplate.hooks.currentHash.tap(
|
||||
"HotModuleReplacementPlugin",
|
||||
(_, length) => {
|
||||
if (isFinite(length)) {
|
||||
return `hotCurrentHash.substr(0, ${length})`;
|
||||
} else {
|
||||
return "hotCurrentHash";
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
mainTemplate.hooks.moduleObj.tap(
|
||||
"HotModuleReplacementPlugin",
|
||||
(source, chunk, hash, varModuleId) => {
|
||||
return Template.asString([
|
||||
`${source},`,
|
||||
`hot: hotCreateModule(${varModuleId}),`,
|
||||
"parents: (hotCurrentParentsTemp = hotCurrentParents, hotCurrentParents = [], hotCurrentParentsTemp),",
|
||||
"children: []"
|
||||
]);
|
||||
}
|
||||
);
|
||||
|
||||
// TODO add HMR support for javascript/esm
|
||||
normalModuleFactory.hooks.parser
|
||||
.for("javascript/auto")
|
||||
.tap("HotModuleReplacementPlugin", addParserPlugins);
|
||||
normalModuleFactory.hooks.parser
|
||||
.for("javascript/dynamic")
|
||||
.tap("HotModuleReplacementPlugin", addParserPlugins);
|
||||
|
||||
compilation.hooks.normalModuleLoader.tap(
|
||||
"HotModuleReplacementPlugin",
|
||||
context => {
|
||||
context.hot = true;
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
const hotInitCode = Template.getFunctionContent(
|
||||
require("./HotModuleReplacement.runtime")
|
||||
);
|
||||
17
node_modules/webpack/lib/HotUpdateChunk.js
generated
vendored
Normal file
17
node_modules/webpack/lib/HotUpdateChunk.js
generated
vendored
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
"use strict";
|
||||
|
||||
const Chunk = require("./Chunk");
|
||||
|
||||
class HotUpdateChunk extends Chunk {
|
||||
constructor() {
|
||||
super();
|
||||
/** @type {(string|number)[]} */
|
||||
this.removedModules = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = HotUpdateChunk;
|
||||
78
node_modules/webpack/lib/HotUpdateChunkTemplate.js
generated
vendored
Normal file
78
node_modules/webpack/lib/HotUpdateChunkTemplate.js
generated
vendored
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
"use strict";
|
||||
|
||||
const Template = require("./Template");
|
||||
const HotUpdateChunk = require("./HotUpdateChunk");
|
||||
const { Tapable, SyncWaterfallHook, SyncHook } = require("tapable");
|
||||
|
||||
module.exports = class HotUpdateChunkTemplate extends Tapable {
|
||||
constructor(outputOptions) {
|
||||
super();
|
||||
this.outputOptions = outputOptions || {};
|
||||
this.hooks = {
|
||||
modules: new SyncWaterfallHook([
|
||||
"source",
|
||||
"modules",
|
||||
"removedModules",
|
||||
"moduleTemplate",
|
||||
"dependencyTemplates"
|
||||
]),
|
||||
render: new SyncWaterfallHook([
|
||||
"source",
|
||||
"modules",
|
||||
"removedModules",
|
||||
"hash",
|
||||
"id",
|
||||
"moduleTemplate",
|
||||
"dependencyTemplates"
|
||||
]),
|
||||
hash: new SyncHook(["hash"])
|
||||
};
|
||||
}
|
||||
|
||||
render(
|
||||
id,
|
||||
modules,
|
||||
removedModules,
|
||||
hash,
|
||||
moduleTemplate,
|
||||
dependencyTemplates
|
||||
) {
|
||||
const hotUpdateChunk = new HotUpdateChunk();
|
||||
hotUpdateChunk.id = id;
|
||||
hotUpdateChunk.setModules(modules);
|
||||
hotUpdateChunk.removedModules = removedModules;
|
||||
const modulesSource = Template.renderChunkModules(
|
||||
hotUpdateChunk,
|
||||
m => typeof m.source === "function",
|
||||
moduleTemplate,
|
||||
dependencyTemplates
|
||||
);
|
||||
const core = this.hooks.modules.call(
|
||||
modulesSource,
|
||||
modules,
|
||||
removedModules,
|
||||
moduleTemplate,
|
||||
dependencyTemplates
|
||||
);
|
||||
const source = this.hooks.render.call(
|
||||
core,
|
||||
modules,
|
||||
removedModules,
|
||||
hash,
|
||||
id,
|
||||
moduleTemplate,
|
||||
dependencyTemplates
|
||||
);
|
||||
return source;
|
||||
}
|
||||
|
||||
updateHash(hash) {
|
||||
hash.update("HotUpdateChunkTemplate");
|
||||
hash.update("1");
|
||||
this.hooks.hash.call(hash);
|
||||
}
|
||||
};
|
||||
91
node_modules/webpack/lib/IgnorePlugin.js
generated
vendored
Normal file
91
node_modules/webpack/lib/IgnorePlugin.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 validateOptions = require("schema-utils");
|
||||
const schema = require("../schemas/plugins/IgnorePlugin.json");
|
||||
|
||||
/** @typedef {import("../declarations/plugins/IgnorePlugin").IgnorePluginOptions} IgnorePluginOptions */
|
||||
/** @typedef {import("./Compiler")} Compiler */
|
||||
|
||||
class IgnorePlugin {
|
||||
/**
|
||||
* @param {IgnorePluginOptions} options IgnorePlugin options
|
||||
*/
|
||||
constructor(options) {
|
||||
// TODO webpack 5 remove this compat-layer
|
||||
if (arguments.length > 1 || options instanceof RegExp) {
|
||||
options = {
|
||||
resourceRegExp: arguments[0],
|
||||
contextRegExp: arguments[1]
|
||||
};
|
||||
}
|
||||
|
||||
validateOptions(schema, options, "IgnorePlugin");
|
||||
this.options = options;
|
||||
|
||||
/** @private @type {Function} */
|
||||
this.checkIgnore = this.checkIgnore.bind(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Note that if "contextRegExp" is given, both the "resourceRegExp"
|
||||
* and "contextRegExp" have to match.
|
||||
*
|
||||
* @param {TODO} result result
|
||||
* @returns {TODO|null} returns result or null if result should be ignored
|
||||
*/
|
||||
checkIgnore(result) {
|
||||
if (!result) return result;
|
||||
|
||||
if (
|
||||
"checkResource" in this.options &&
|
||||
this.options.checkResource &&
|
||||
this.options.checkResource(result.request, result.context)
|
||||
) {
|
||||
// TODO webpack 5 remove checkContext, as checkResource already gets context
|
||||
if ("checkContext" in this.options && this.options.checkContext) {
|
||||
if (this.options.checkContext(result.context)) {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
if (
|
||||
"resourceRegExp" in this.options &&
|
||||
this.options.resourceRegExp &&
|
||||
this.options.resourceRegExp.test(result.request)
|
||||
) {
|
||||
if ("contextRegExp" in this.options && this.options.contextRegExp) {
|
||||
// if "contextRegExp" is given,
|
||||
// both the "resourceRegExp" and "contextRegExp" have to match.
|
||||
if (this.options.contextRegExp.test(result.context)) {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Compiler} compiler Webpack Compiler
|
||||
* @returns {void}
|
||||
*/
|
||||
apply(compiler) {
|
||||
compiler.hooks.normalModuleFactory.tap("IgnorePlugin", nmf => {
|
||||
nmf.hooks.beforeResolve.tap("IgnorePlugin", this.checkIgnore);
|
||||
});
|
||||
compiler.hooks.contextModuleFactory.tap("IgnorePlugin", cmf => {
|
||||
cmf.hooks.beforeResolve.tap("IgnorePlugin", this.checkIgnore);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = IgnorePlugin;
|
||||
229
node_modules/webpack/lib/JavascriptGenerator.js
generated
vendored
Normal file
229
node_modules/webpack/lib/JavascriptGenerator.js
generated
vendored
Normal file
|
|
@ -0,0 +1,229 @@
|
|||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
"use strict";
|
||||
|
||||
const { RawSource, ReplaceSource } = require("webpack-sources");
|
||||
|
||||
// TODO: clean up this file
|
||||
// replace with newer constructs
|
||||
|
||||
// TODO: remove DependencyVariables and replace them with something better
|
||||
|
||||
class JavascriptGenerator {
|
||||
generate(module, dependencyTemplates, runtimeTemplate) {
|
||||
const originalSource = module.originalSource();
|
||||
if (!originalSource) {
|
||||
return new RawSource("throw new Error('No source available');");
|
||||
}
|
||||
|
||||
const source = new ReplaceSource(originalSource);
|
||||
|
||||
this.sourceBlock(
|
||||
module,
|
||||
module,
|
||||
[],
|
||||
dependencyTemplates,
|
||||
source,
|
||||
runtimeTemplate
|
||||
);
|
||||
|
||||
return source;
|
||||
}
|
||||
|
||||
sourceBlock(
|
||||
module,
|
||||
block,
|
||||
availableVars,
|
||||
dependencyTemplates,
|
||||
source,
|
||||
runtimeTemplate
|
||||
) {
|
||||
for (const dependency of block.dependencies) {
|
||||
this.sourceDependency(
|
||||
dependency,
|
||||
dependencyTemplates,
|
||||
source,
|
||||
runtimeTemplate
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the variables of all blocks that we need to inject.
|
||||
* These will contain the variable name and its expression.
|
||||
* The name will be added as a parameter in a IIFE the expression as its value.
|
||||
*/
|
||||
const vars = block.variables.reduce((result, value) => {
|
||||
const variable = this.sourceVariables(
|
||||
value,
|
||||
availableVars,
|
||||
dependencyTemplates,
|
||||
runtimeTemplate
|
||||
);
|
||||
|
||||
if (variable) {
|
||||
result.push(variable);
|
||||
}
|
||||
|
||||
return result;
|
||||
}, []);
|
||||
|
||||
/**
|
||||
* if we actually have variables
|
||||
* this is important as how #splitVariablesInUniqueNamedChunks works
|
||||
* it will always return an array in an array which would lead to a IIFE wrapper around
|
||||
* a module if we do this with an empty vars array.
|
||||
*/
|
||||
if (vars.length > 0) {
|
||||
/**
|
||||
* Split all variables up into chunks of unique names.
|
||||
* e.g. imagine you have the following variable names that need to be injected:
|
||||
* [foo, bar, baz, foo, some, more]
|
||||
* we can not inject "foo" twice, therefore we just make two IIFEs like so:
|
||||
* (function(foo, bar, baz){
|
||||
* (function(foo, some, more){
|
||||
* …
|
||||
* }(…));
|
||||
* }(…));
|
||||
*
|
||||
* "splitVariablesInUniqueNamedChunks" splits the variables shown above up to this:
|
||||
* [[foo, bar, baz], [foo, some, more]]
|
||||
*/
|
||||
const injectionVariableChunks = this.splitVariablesInUniqueNamedChunks(
|
||||
vars
|
||||
);
|
||||
|
||||
// create all the beginnings of IIFEs
|
||||
const functionWrapperStarts = injectionVariableChunks.map(
|
||||
variableChunk => {
|
||||
return this.variableInjectionFunctionWrapperStartCode(
|
||||
variableChunk.map(variable => variable.name)
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
// and all the ends
|
||||
const functionWrapperEnds = injectionVariableChunks.map(variableChunk => {
|
||||
return this.variableInjectionFunctionWrapperEndCode(
|
||||
module,
|
||||
variableChunk.map(variable => variable.expression),
|
||||
block
|
||||
);
|
||||
});
|
||||
|
||||
// join them to one big string
|
||||
const varStartCode = functionWrapperStarts.join("");
|
||||
|
||||
// reverse the ends first before joining them, as the last added must be the inner most
|
||||
const varEndCode = functionWrapperEnds.reverse().join("");
|
||||
|
||||
// if we have anything, add it to the source
|
||||
if (varStartCode && varEndCode) {
|
||||
const start = block.range ? block.range[0] : -10;
|
||||
const end = block.range
|
||||
? block.range[1]
|
||||
: module.originalSource().size() + 1;
|
||||
source.insert(start + 0.5, varStartCode);
|
||||
source.insert(end + 0.5, "\n/* WEBPACK VAR INJECTION */" + varEndCode);
|
||||
}
|
||||
}
|
||||
|
||||
for (const childBlock of block.blocks) {
|
||||
this.sourceBlock(
|
||||
module,
|
||||
childBlock,
|
||||
availableVars.concat(vars),
|
||||
dependencyTemplates,
|
||||
source,
|
||||
runtimeTemplate
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
sourceDependency(dependency, dependencyTemplates, source, runtimeTemplate) {
|
||||
const template = dependencyTemplates.get(dependency.constructor);
|
||||
if (!template) {
|
||||
throw new Error(
|
||||
"No template for dependency: " + dependency.constructor.name
|
||||
);
|
||||
}
|
||||
template.apply(dependency, source, runtimeTemplate, dependencyTemplates);
|
||||
}
|
||||
|
||||
sourceVariables(
|
||||
variable,
|
||||
availableVars,
|
||||
dependencyTemplates,
|
||||
runtimeTemplate
|
||||
) {
|
||||
const name = variable.name;
|
||||
const expr = variable.expressionSource(
|
||||
dependencyTemplates,
|
||||
runtimeTemplate
|
||||
);
|
||||
|
||||
if (
|
||||
availableVars.some(
|
||||
v => v.name === name && v.expression.source() === expr.source()
|
||||
)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
return {
|
||||
name: name,
|
||||
expression: expr
|
||||
};
|
||||
}
|
||||
|
||||
/*
|
||||
* creates the start part of a IIFE around the module to inject a variable name
|
||||
* (function(…){ <- this part
|
||||
* }.call(…))
|
||||
*/
|
||||
variableInjectionFunctionWrapperStartCode(varNames) {
|
||||
const args = varNames.join(", ");
|
||||
return `/* WEBPACK VAR INJECTION */(function(${args}) {`;
|
||||
}
|
||||
|
||||
contextArgument(module, block) {
|
||||
if (this === block) {
|
||||
return module.exportsArgument;
|
||||
}
|
||||
return "this";
|
||||
}
|
||||
|
||||
/*
|
||||
* creates the end part of a IIFE around the module to inject a variable name
|
||||
* (function(…){
|
||||
* }.call(…)) <- this part
|
||||
*/
|
||||
variableInjectionFunctionWrapperEndCode(module, varExpressions, block) {
|
||||
const firstParam = this.contextArgument(module, block);
|
||||
const furtherParams = varExpressions.map(e => e.source()).join(", ");
|
||||
return `}.call(${firstParam}, ${furtherParams}))`;
|
||||
}
|
||||
|
||||
splitVariablesInUniqueNamedChunks(vars) {
|
||||
const startState = [[]];
|
||||
return vars.reduce((chunks, variable) => {
|
||||
const current = chunks[chunks.length - 1];
|
||||
// check if variable with same name exists already
|
||||
// if so create a new chunk of variables.
|
||||
const variableNameAlreadyExists = current.some(
|
||||
v => v.name === variable.name
|
||||
);
|
||||
|
||||
if (variableNameAlreadyExists) {
|
||||
// start new chunk with current variable
|
||||
chunks.push([variable]);
|
||||
} else {
|
||||
// else add it to current chunk
|
||||
current.push(variable);
|
||||
}
|
||||
return chunks;
|
||||
}, startState);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = JavascriptGenerator;
|
||||
185
node_modules/webpack/lib/JavascriptModulesPlugin.js
generated
vendored
Normal file
185
node_modules/webpack/lib/JavascriptModulesPlugin.js
generated
vendored
Normal file
|
|
@ -0,0 +1,185 @@
|
|||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
"use strict";
|
||||
|
||||
const Parser = require("./Parser");
|
||||
const Template = require("./Template");
|
||||
const { ConcatSource } = require("webpack-sources");
|
||||
const JavascriptGenerator = require("./JavascriptGenerator");
|
||||
const createHash = require("./util/createHash");
|
||||
|
||||
class JavascriptModulesPlugin {
|
||||
apply(compiler) {
|
||||
compiler.hooks.compilation.tap(
|
||||
"JavascriptModulesPlugin",
|
||||
(compilation, { normalModuleFactory }) => {
|
||||
normalModuleFactory.hooks.createParser
|
||||
.for("javascript/auto")
|
||||
.tap("JavascriptModulesPlugin", options => {
|
||||
return new Parser(options, "auto");
|
||||
});
|
||||
normalModuleFactory.hooks.createParser
|
||||
.for("javascript/dynamic")
|
||||
.tap("JavascriptModulesPlugin", options => {
|
||||
return new Parser(options, "script");
|
||||
});
|
||||
normalModuleFactory.hooks.createParser
|
||||
.for("javascript/esm")
|
||||
.tap("JavascriptModulesPlugin", options => {
|
||||
return new Parser(options, "module");
|
||||
});
|
||||
normalModuleFactory.hooks.createGenerator
|
||||
.for("javascript/auto")
|
||||
.tap("JavascriptModulesPlugin", () => {
|
||||
return new JavascriptGenerator();
|
||||
});
|
||||
normalModuleFactory.hooks.createGenerator
|
||||
.for("javascript/dynamic")
|
||||
.tap("JavascriptModulesPlugin", () => {
|
||||
return new JavascriptGenerator();
|
||||
});
|
||||
normalModuleFactory.hooks.createGenerator
|
||||
.for("javascript/esm")
|
||||
.tap("JavascriptModulesPlugin", () => {
|
||||
return new JavascriptGenerator();
|
||||
});
|
||||
compilation.mainTemplate.hooks.renderManifest.tap(
|
||||
"JavascriptModulesPlugin",
|
||||
(result, options) => {
|
||||
const chunk = options.chunk;
|
||||
const hash = options.hash;
|
||||
const fullHash = options.fullHash;
|
||||
const outputOptions = options.outputOptions;
|
||||
const moduleTemplates = options.moduleTemplates;
|
||||
const dependencyTemplates = options.dependencyTemplates;
|
||||
|
||||
const filenameTemplate =
|
||||
chunk.filenameTemplate || outputOptions.filename;
|
||||
|
||||
const useChunkHash = compilation.mainTemplate.useChunkHash(chunk);
|
||||
|
||||
result.push({
|
||||
render: () =>
|
||||
compilation.mainTemplate.render(
|
||||
hash,
|
||||
chunk,
|
||||
moduleTemplates.javascript,
|
||||
dependencyTemplates
|
||||
),
|
||||
filenameTemplate,
|
||||
pathOptions: {
|
||||
noChunkHash: !useChunkHash,
|
||||
contentHashType: "javascript",
|
||||
chunk
|
||||
},
|
||||
identifier: `chunk${chunk.id}`,
|
||||
hash: useChunkHash ? chunk.hash : fullHash
|
||||
});
|
||||
return result;
|
||||
}
|
||||
);
|
||||
compilation.mainTemplate.hooks.modules.tap(
|
||||
"JavascriptModulesPlugin",
|
||||
(source, chunk, hash, moduleTemplate, dependencyTemplates) => {
|
||||
return Template.renderChunkModules(
|
||||
chunk,
|
||||
m => typeof m.source === "function",
|
||||
moduleTemplate,
|
||||
dependencyTemplates,
|
||||
"/******/ "
|
||||
);
|
||||
}
|
||||
);
|
||||
compilation.chunkTemplate.hooks.renderManifest.tap(
|
||||
"JavascriptModulesPlugin",
|
||||
(result, options) => {
|
||||
const chunk = options.chunk;
|
||||
const outputOptions = options.outputOptions;
|
||||
const moduleTemplates = options.moduleTemplates;
|
||||
const dependencyTemplates = options.dependencyTemplates;
|
||||
const filenameTemplate =
|
||||
chunk.filenameTemplate || outputOptions.chunkFilename;
|
||||
|
||||
result.push({
|
||||
render: () =>
|
||||
this.renderJavascript(
|
||||
compilation.chunkTemplate,
|
||||
chunk,
|
||||
moduleTemplates.javascript,
|
||||
dependencyTemplates
|
||||
),
|
||||
filenameTemplate,
|
||||
pathOptions: {
|
||||
chunk,
|
||||
contentHashType: "javascript"
|
||||
},
|
||||
identifier: `chunk${chunk.id}`,
|
||||
hash: chunk.hash
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
);
|
||||
compilation.hooks.contentHash.tap("JavascriptModulesPlugin", chunk => {
|
||||
const outputOptions = compilation.outputOptions;
|
||||
const {
|
||||
hashSalt,
|
||||
hashDigest,
|
||||
hashDigestLength,
|
||||
hashFunction
|
||||
} = outputOptions;
|
||||
const hash = createHash(hashFunction);
|
||||
if (hashSalt) hash.update(hashSalt);
|
||||
const template = chunk.hasRuntime()
|
||||
? compilation.mainTemplate
|
||||
: compilation.chunkTemplate;
|
||||
hash.update(`${chunk.id} `);
|
||||
hash.update(chunk.ids ? chunk.ids.join(",") : "");
|
||||
template.updateHashForChunk(
|
||||
hash,
|
||||
chunk,
|
||||
compilation.moduleTemplates.javascript,
|
||||
compilation.dependencyTemplates
|
||||
);
|
||||
for (const m of chunk.modulesIterable) {
|
||||
if (typeof m.source === "function") {
|
||||
hash.update(m.hash);
|
||||
}
|
||||
}
|
||||
const digest = /** @type {string} */ (hash.digest(hashDigest));
|
||||
chunk.contentHash.javascript = digest.substr(0, hashDigestLength);
|
||||
});
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
renderJavascript(chunkTemplate, chunk, moduleTemplate, dependencyTemplates) {
|
||||
const moduleSources = Template.renderChunkModules(
|
||||
chunk,
|
||||
m => typeof m.source === "function",
|
||||
moduleTemplate,
|
||||
dependencyTemplates
|
||||
);
|
||||
const core = chunkTemplate.hooks.modules.call(
|
||||
moduleSources,
|
||||
chunk,
|
||||
moduleTemplate,
|
||||
dependencyTemplates
|
||||
);
|
||||
let source = chunkTemplate.hooks.render.call(
|
||||
core,
|
||||
chunk,
|
||||
moduleTemplate,
|
||||
dependencyTemplates
|
||||
);
|
||||
if (chunk.hasEntryModule()) {
|
||||
source = chunkTemplate.hooks.renderWithEntry.call(source, chunk);
|
||||
}
|
||||
chunk.rendered = true;
|
||||
return new ConcatSource(source, ";");
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = JavascriptModulesPlugin;
|
||||
57
node_modules/webpack/lib/JsonGenerator.js
generated
vendored
Normal file
57
node_modules/webpack/lib/JsonGenerator.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";
|
||||
|
||||
const { ConcatSource, RawSource } = require("webpack-sources");
|
||||
|
||||
const stringifySafe = data => {
|
||||
const stringified = JSON.stringify(data);
|
||||
if (!stringified) {
|
||||
return undefined; // Invalid JSON
|
||||
}
|
||||
|
||||
return stringified.replace(/\u2028|\u2029/g, str =>
|
||||
str === "\u2029" ? "\\u2029" : "\\u2028"
|
||||
); // invalid in JavaScript but valid JSON
|
||||
};
|
||||
|
||||
class JsonGenerator {
|
||||
generate(module, dependencyTemplates, runtimeTemplate) {
|
||||
const source = new ConcatSource();
|
||||
const data = module.buildInfo.jsonData;
|
||||
if (data === undefined) {
|
||||
return new RawSource(
|
||||
runtimeTemplate.missingModuleStatement({
|
||||
request: module.rawRequest
|
||||
})
|
||||
);
|
||||
}
|
||||
let finalJson;
|
||||
if (
|
||||
Array.isArray(module.buildMeta.providedExports) &&
|
||||
!module.isUsed("default")
|
||||
) {
|
||||
// Only some exports are used: We can optimize here, by only generating a part of the JSON
|
||||
const reducedJson = {};
|
||||
for (const exportName of module.buildMeta.providedExports) {
|
||||
if (exportName === "default") continue;
|
||||
const used = module.isUsed(exportName);
|
||||
if (used) {
|
||||
reducedJson[used] = data[exportName];
|
||||
}
|
||||
}
|
||||
finalJson = reducedJson;
|
||||
} else {
|
||||
finalJson = data;
|
||||
}
|
||||
// Use JSON because JSON.parse() is much faster than JavaScript evaluation
|
||||
const jsonSource = JSON.stringify(stringifySafe(finalJson));
|
||||
const jsonExpr = `JSON.parse(${jsonSource})`;
|
||||
source.add(`${module.moduleArgument}.exports = ${jsonExpr};`);
|
||||
return source;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = JsonGenerator;
|
||||
30
node_modules/webpack/lib/JsonModulesPlugin.js
generated
vendored
Normal file
30
node_modules/webpack/lib/JsonModulesPlugin.js
generated
vendored
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
"use strict";
|
||||
|
||||
const JsonParser = require("./JsonParser");
|
||||
const JsonGenerator = require("./JsonGenerator");
|
||||
|
||||
class JsonModulesPlugin {
|
||||
apply(compiler) {
|
||||
compiler.hooks.compilation.tap(
|
||||
"JsonModulesPlugin",
|
||||
(compilation, { normalModuleFactory }) => {
|
||||
normalModuleFactory.hooks.createParser
|
||||
.for("json")
|
||||
.tap("JsonModulesPlugin", () => {
|
||||
return new JsonParser();
|
||||
});
|
||||
normalModuleFactory.hooks.createGenerator
|
||||
.for("json")
|
||||
.tap("JsonModulesPlugin", () => {
|
||||
return new JsonGenerator();
|
||||
});
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = JsonModulesPlugin;
|
||||
27
node_modules/webpack/lib/JsonParser.js
generated
vendored
Normal file
27
node_modules/webpack/lib/JsonParser.js
generated
vendored
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
"use strict";
|
||||
|
||||
const parseJson = require("json-parse-better-errors");
|
||||
const JsonExportsDependency = require("./dependencies/JsonExportsDependency");
|
||||
|
||||
class JsonParser {
|
||||
constructor(options) {
|
||||
this.options = options;
|
||||
}
|
||||
|
||||
parse(source, state) {
|
||||
const data = parseJson(source[0] === "\ufeff" ? source.slice(1) : source);
|
||||
state.module.buildInfo.jsonData = data;
|
||||
state.module.buildMeta.exportsType = "named";
|
||||
if (typeof data === "object" && data) {
|
||||
state.module.addDependency(new JsonExportsDependency(Object.keys(data)));
|
||||
}
|
||||
state.module.addDependency(new JsonExportsDependency(["default"]));
|
||||
return state;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = JsonParser;
|
||||
90
node_modules/webpack/lib/LibManifestPlugin.js
generated
vendored
Normal file
90
node_modules/webpack/lib/LibManifestPlugin.js
generated
vendored
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
"use strict";
|
||||
|
||||
const path = require("path");
|
||||
const asyncLib = require("neo-async");
|
||||
const SingleEntryDependency = require("./dependencies/SingleEntryDependency");
|
||||
|
||||
class LibManifestPlugin {
|
||||
constructor(options) {
|
||||
this.options = options;
|
||||
}
|
||||
|
||||
apply(compiler) {
|
||||
compiler.hooks.emit.tapAsync(
|
||||
"LibManifestPlugin",
|
||||
(compilation, callback) => {
|
||||
asyncLib.forEach(
|
||||
compilation.chunks,
|
||||
(chunk, callback) => {
|
||||
if (!chunk.isOnlyInitial()) {
|
||||
callback();
|
||||
return;
|
||||
}
|
||||
const targetPath = compilation.getPath(this.options.path, {
|
||||
hash: compilation.hash,
|
||||
chunk
|
||||
});
|
||||
const name =
|
||||
this.options.name &&
|
||||
compilation.getPath(this.options.name, {
|
||||
hash: compilation.hash,
|
||||
chunk
|
||||
});
|
||||
const manifest = {
|
||||
name,
|
||||
type: this.options.type,
|
||||
content: Array.from(chunk.modulesIterable, module => {
|
||||
if (
|
||||
this.options.entryOnly &&
|
||||
!module.reasons.some(
|
||||
r => r.dependency instanceof SingleEntryDependency
|
||||
)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
if (module.libIdent) {
|
||||
const ident = module.libIdent({
|
||||
context: this.options.context || compiler.options.context
|
||||
});
|
||||
if (ident) {
|
||||
return {
|
||||
ident,
|
||||
data: {
|
||||
id: module.id,
|
||||
buildMeta: module.buildMeta
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
})
|
||||
.filter(Boolean)
|
||||
.reduce((obj, item) => {
|
||||
obj[item.ident] = item.data;
|
||||
return obj;
|
||||
}, Object.create(null))
|
||||
};
|
||||
// Apply formatting to content if format flag is true;
|
||||
const manifestContent = this.options.format
|
||||
? JSON.stringify(manifest, null, 2)
|
||||
: JSON.stringify(manifest);
|
||||
const content = Buffer.from(manifestContent, "utf8");
|
||||
compiler.outputFileSystem.mkdirp(path.dirname(targetPath), err => {
|
||||
if (err) return callback(err);
|
||||
compiler.outputFileSystem.writeFile(
|
||||
targetPath,
|
||||
content,
|
||||
callback
|
||||
);
|
||||
});
|
||||
},
|
||||
callback
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
module.exports = LibManifestPlugin;
|
||||
186
node_modules/webpack/lib/LibraryTemplatePlugin.js
generated
vendored
Normal file
186
node_modules/webpack/lib/LibraryTemplatePlugin.js
generated
vendored
Normal file
|
|
@ -0,0 +1,186 @@
|
|||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
"use strict";
|
||||
|
||||
const SetVarMainTemplatePlugin = require("./SetVarMainTemplatePlugin");
|
||||
|
||||
/** @typedef {import("../declarations/WebpackOptions").LibraryCustomUmdObject} LibraryCustomUmdObject */
|
||||
/** @typedef {import("./Compiler")} Compiler */
|
||||
|
||||
/**
|
||||
* @param {string[]} accessor the accessor to convert to path
|
||||
* @returns {string} the path
|
||||
*/
|
||||
const accessorToObjectAccess = accessor => {
|
||||
return accessor.map(a => `[${JSON.stringify(a)}]`).join("");
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {string=} base the path prefix
|
||||
* @param {string|string[]|LibraryCustomUmdObject} accessor the accessor
|
||||
* @param {"amd" | "commonjs" | "root"} umdProperty property used when a custom umd object is provided
|
||||
* @param {string=} joinWith the element separator
|
||||
* @returns {string} the path
|
||||
*/
|
||||
const accessorAccess = (base, accessor, umdProperty, joinWith = "; ") => {
|
||||
const normalizedAccessor =
|
||||
typeof accessor === "object" && !Array.isArray(accessor)
|
||||
? accessor[umdProperty]
|
||||
: accessor;
|
||||
const accessors = Array.isArray(normalizedAccessor)
|
||||
? normalizedAccessor
|
||||
: [normalizedAccessor];
|
||||
return accessors
|
||||
.map((_, idx) => {
|
||||
const a = base
|
||||
? base + accessorToObjectAccess(accessors.slice(0, idx + 1))
|
||||
: accessors[0] + accessorToObjectAccess(accessors.slice(1, idx + 1));
|
||||
if (idx === accessors.length - 1) return a;
|
||||
if (idx === 0 && base === undefined) {
|
||||
return `${a} = typeof ${a} === "object" ? ${a} : {}`;
|
||||
}
|
||||
return `${a} = ${a} || {}`;
|
||||
})
|
||||
.join(joinWith);
|
||||
};
|
||||
|
||||
class LibraryTemplatePlugin {
|
||||
/**
|
||||
* @param {string|string[]|LibraryCustomUmdObject} name name of library
|
||||
* @param {string} target type of library
|
||||
* @param {boolean} umdNamedDefine setting this to true will name the UMD module
|
||||
* @param {string|TODO} auxiliaryComment comment in the UMD wrapper
|
||||
* @param {string|string[]} exportProperty which export should be exposed as library
|
||||
*/
|
||||
constructor(name, target, umdNamedDefine, auxiliaryComment, exportProperty) {
|
||||
this.name = name;
|
||||
this.target = target;
|
||||
this.umdNamedDefine = umdNamedDefine;
|
||||
this.auxiliaryComment = auxiliaryComment;
|
||||
this.exportProperty = exportProperty;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Compiler} compiler the compiler instance
|
||||
* @returns {void}
|
||||
*/
|
||||
apply(compiler) {
|
||||
compiler.hooks.thisCompilation.tap("LibraryTemplatePlugin", compilation => {
|
||||
if (this.exportProperty) {
|
||||
const ExportPropertyMainTemplatePlugin = require("./ExportPropertyMainTemplatePlugin");
|
||||
new ExportPropertyMainTemplatePlugin(this.exportProperty).apply(
|
||||
compilation
|
||||
);
|
||||
}
|
||||
switch (this.target) {
|
||||
case "var":
|
||||
if (
|
||||
!this.name ||
|
||||
(typeof this.name === "object" && !Array.isArray(this.name))
|
||||
) {
|
||||
throw new Error(
|
||||
"library name must be set and not an UMD custom object for non-UMD target"
|
||||
);
|
||||
}
|
||||
new SetVarMainTemplatePlugin(
|
||||
`var ${accessorAccess(undefined, this.name, "root")}`,
|
||||
false
|
||||
).apply(compilation);
|
||||
break;
|
||||
case "assign":
|
||||
new SetVarMainTemplatePlugin(
|
||||
accessorAccess(undefined, this.name, "root"),
|
||||
false
|
||||
).apply(compilation);
|
||||
break;
|
||||
case "this":
|
||||
case "self":
|
||||
case "window":
|
||||
if (this.name) {
|
||||
new SetVarMainTemplatePlugin(
|
||||
accessorAccess(this.target, this.name, "root"),
|
||||
false
|
||||
).apply(compilation);
|
||||
} else {
|
||||
new SetVarMainTemplatePlugin(this.target, true).apply(compilation);
|
||||
}
|
||||
break;
|
||||
case "global":
|
||||
if (this.name) {
|
||||
new SetVarMainTemplatePlugin(
|
||||
accessorAccess(
|
||||
compilation.runtimeTemplate.outputOptions.globalObject,
|
||||
this.name,
|
||||
"root"
|
||||
),
|
||||
false
|
||||
).apply(compilation);
|
||||
} else {
|
||||
new SetVarMainTemplatePlugin(
|
||||
compilation.runtimeTemplate.outputOptions.globalObject,
|
||||
true
|
||||
).apply(compilation);
|
||||
}
|
||||
break;
|
||||
case "commonjs":
|
||||
if (this.name) {
|
||||
new SetVarMainTemplatePlugin(
|
||||
accessorAccess("exports", this.name, "commonjs"),
|
||||
false
|
||||
).apply(compilation);
|
||||
} else {
|
||||
new SetVarMainTemplatePlugin("exports", true).apply(compilation);
|
||||
}
|
||||
break;
|
||||
case "commonjs2":
|
||||
case "commonjs-module":
|
||||
new SetVarMainTemplatePlugin("module.exports", false).apply(
|
||||
compilation
|
||||
);
|
||||
break;
|
||||
case "amd":
|
||||
case "amd-require": {
|
||||
const AmdMainTemplatePlugin = require("./AmdMainTemplatePlugin");
|
||||
if (this.name && typeof this.name !== "string") {
|
||||
throw new Error("library name must be a string for amd target");
|
||||
}
|
||||
new AmdMainTemplatePlugin({
|
||||
name: this.name,
|
||||
requireAsWrapper: this.target === "amd-require"
|
||||
}).apply(compilation);
|
||||
break;
|
||||
}
|
||||
case "umd":
|
||||
case "umd2": {
|
||||
const UmdMainTemplatePlugin = require("./UmdMainTemplatePlugin");
|
||||
new UmdMainTemplatePlugin(this.name, {
|
||||
optionalAmdExternalAsGlobal: this.target === "umd2",
|
||||
namedDefine: this.umdNamedDefine,
|
||||
auxiliaryComment: this.auxiliaryComment
|
||||
}).apply(compilation);
|
||||
break;
|
||||
}
|
||||
case "jsonp": {
|
||||
const JsonpExportMainTemplatePlugin = require("./web/JsonpExportMainTemplatePlugin");
|
||||
if (typeof this.name !== "string")
|
||||
throw new Error("library name must be a string for jsonp target");
|
||||
new JsonpExportMainTemplatePlugin(this.name).apply(compilation);
|
||||
break;
|
||||
}
|
||||
case "system": {
|
||||
const SystemMainTemplatePlugin = require("./SystemMainTemplatePlugin");
|
||||
new SystemMainTemplatePlugin({
|
||||
name: this.name
|
||||
}).apply(compilation);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
throw new Error(`${this.target} is not a valid Library target`);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = LibraryTemplatePlugin;
|
||||
58
node_modules/webpack/lib/LoaderOptionsPlugin.js
generated
vendored
Normal file
58
node_modules/webpack/lib/LoaderOptionsPlugin.js
generated
vendored
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
"use strict";
|
||||
|
||||
const ModuleFilenameHelpers = require("./ModuleFilenameHelpers");
|
||||
|
||||
const validateOptions = require("schema-utils");
|
||||
const schema = require("../schemas/plugins/LoaderOptionsPlugin.json");
|
||||
|
||||
/** @typedef {import("../declarations/plugins/LoaderOptionsPlugin").LoaderOptionsPluginOptions} LoaderOptionsPluginOptions */
|
||||
|
||||
class LoaderOptionsPlugin {
|
||||
/**
|
||||
* @param {LoaderOptionsPluginOptions} options options object
|
||||
*/
|
||||
constructor(options) {
|
||||
validateOptions(schema, options || {}, "Loader Options Plugin");
|
||||
|
||||
if (typeof options !== "object") options = {};
|
||||
if (!options.test) {
|
||||
options.test = {
|
||||
test: () => true
|
||||
};
|
||||
}
|
||||
this.options = options;
|
||||
}
|
||||
|
||||
apply(compiler) {
|
||||
const options = this.options;
|
||||
compiler.hooks.compilation.tap("LoaderOptionsPlugin", compilation => {
|
||||
compilation.hooks.normalModuleLoader.tap(
|
||||
"LoaderOptionsPlugin",
|
||||
(context, module) => {
|
||||
const resource = module.resource;
|
||||
if (!resource) return;
|
||||
const i = resource.indexOf("?");
|
||||
if (
|
||||
ModuleFilenameHelpers.matchObject(
|
||||
options,
|
||||
i < 0 ? resource : resource.substr(0, i)
|
||||
)
|
||||
) {
|
||||
for (const key of Object.keys(options)) {
|
||||
if (key === "include" || key === "exclude" || key === "test") {
|
||||
continue;
|
||||
}
|
||||
context[key] = options[key];
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = LoaderOptionsPlugin;
|
||||
24
node_modules/webpack/lib/LoaderTargetPlugin.js
generated
vendored
Normal file
24
node_modules/webpack/lib/LoaderTargetPlugin.js
generated
vendored
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
"use strict";
|
||||
|
||||
class LoaderTargetPlugin {
|
||||
constructor(target) {
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
apply(compiler) {
|
||||
compiler.hooks.compilation.tap("LoaderTargetPlugin", compilation => {
|
||||
compilation.hooks.normalModuleLoader.tap(
|
||||
"LoaderTargetPlugin",
|
||||
loaderContext => {
|
||||
loaderContext.target = this.target;
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = LoaderTargetPlugin;
|
||||
568
node_modules/webpack/lib/MainTemplate.js
generated
vendored
Normal file
568
node_modules/webpack/lib/MainTemplate.js
generated
vendored
Normal file
|
|
@ -0,0 +1,568 @@
|
|||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
"use strict";
|
||||
|
||||
const {
|
||||
ConcatSource,
|
||||
OriginalSource,
|
||||
PrefixSource,
|
||||
RawSource
|
||||
} = require("webpack-sources");
|
||||
const {
|
||||
Tapable,
|
||||
SyncWaterfallHook,
|
||||
SyncHook,
|
||||
SyncBailHook
|
||||
} = require("tapable");
|
||||
const Template = require("./Template");
|
||||
|
||||
/** @typedef {import("webpack-sources").ConcatSource} ConcatSource */
|
||||
/** @typedef {import("webpack-sources").Source} Source */
|
||||
/** @typedef {import("./ModuleTemplate")} ModuleTemplate */
|
||||
/** @typedef {import("./Chunk")} Chunk */
|
||||
/** @typedef {import("./Module")} Module} */
|
||||
/** @typedef {import("./util/createHash").Hash} Hash} */
|
||||
/** @typedef {import("./Dependency").DependencyTemplate} DependencyTemplate} */
|
||||
|
||||
/**
|
||||
* @typedef {Object} RenderManifestOptions
|
||||
* @property {Chunk} chunk the chunk used to render
|
||||
* @property {string} hash
|
||||
* @property {string} fullHash
|
||||
* @property {TODO} outputOptions
|
||||
* @property {{javascript: ModuleTemplate, webassembly: ModuleTemplate}} moduleTemplates
|
||||
* @property {Map<TODO, TODO>} dependencyTemplates
|
||||
*/
|
||||
|
||||
// require function shortcuts:
|
||||
// __webpack_require__.s = the module id of the entry point
|
||||
// __webpack_require__.c = the module cache
|
||||
// __webpack_require__.m = the module functions
|
||||
// __webpack_require__.p = the bundle public path
|
||||
// __webpack_require__.i = the identity function used for harmony imports
|
||||
// __webpack_require__.e = the chunk ensure function
|
||||
// __webpack_require__.d = the exported property define getter function
|
||||
// __webpack_require__.o = Object.prototype.hasOwnProperty.call
|
||||
// __webpack_require__.r = define compatibility on export
|
||||
// __webpack_require__.t = create a fake namespace object
|
||||
// __webpack_require__.n = compatibility get default export
|
||||
// __webpack_require__.h = the webpack hash
|
||||
// __webpack_require__.w = an object containing all installed WebAssembly.Instance export objects keyed by module id
|
||||
// __webpack_require__.oe = the uncaught error handler for the webpack runtime
|
||||
// __webpack_require__.nc = the script nonce
|
||||
|
||||
module.exports = class MainTemplate extends Tapable {
|
||||
/**
|
||||
*
|
||||
* @param {TODO=} outputOptions output options for the MainTemplate
|
||||
*/
|
||||
constructor(outputOptions) {
|
||||
super();
|
||||
/** @type {TODO?} */
|
||||
this.outputOptions = outputOptions || {};
|
||||
this.hooks = {
|
||||
/** @type {SyncWaterfallHook<TODO[], RenderManifestOptions>} */
|
||||
renderManifest: new SyncWaterfallHook(["result", "options"]),
|
||||
modules: new SyncWaterfallHook([
|
||||
"modules",
|
||||
"chunk",
|
||||
"hash",
|
||||
"moduleTemplate",
|
||||
"dependencyTemplates"
|
||||
]),
|
||||
moduleObj: new SyncWaterfallHook([
|
||||
"source",
|
||||
"chunk",
|
||||
"hash",
|
||||
"moduleIdExpression"
|
||||
]),
|
||||
requireEnsure: new SyncWaterfallHook([
|
||||
"source",
|
||||
"chunk",
|
||||
"hash",
|
||||
"chunkIdExpression"
|
||||
]),
|
||||
bootstrap: new SyncWaterfallHook([
|
||||
"source",
|
||||
"chunk",
|
||||
"hash",
|
||||
"moduleTemplate",
|
||||
"dependencyTemplates"
|
||||
]),
|
||||
localVars: new SyncWaterfallHook(["source", "chunk", "hash"]),
|
||||
require: new SyncWaterfallHook(["source", "chunk", "hash"]),
|
||||
requireExtensions: new SyncWaterfallHook(["source", "chunk", "hash"]),
|
||||
/** @type {SyncWaterfallHook<string, Chunk, string>} */
|
||||
beforeStartup: new SyncWaterfallHook(["source", "chunk", "hash"]),
|
||||
/** @type {SyncWaterfallHook<string, Chunk, string>} */
|
||||
startup: new SyncWaterfallHook(["source", "chunk", "hash"]),
|
||||
/** @type {SyncWaterfallHook<string, Chunk, string>} */
|
||||
afterStartup: new SyncWaterfallHook(["source", "chunk", "hash"]),
|
||||
render: new SyncWaterfallHook([
|
||||
"source",
|
||||
"chunk",
|
||||
"hash",
|
||||
"moduleTemplate",
|
||||
"dependencyTemplates"
|
||||
]),
|
||||
renderWithEntry: new SyncWaterfallHook(["source", "chunk", "hash"]),
|
||||
moduleRequire: new SyncWaterfallHook([
|
||||
"source",
|
||||
"chunk",
|
||||
"hash",
|
||||
"moduleIdExpression"
|
||||
]),
|
||||
addModule: new SyncWaterfallHook([
|
||||
"source",
|
||||
"chunk",
|
||||
"hash",
|
||||
"moduleIdExpression",
|
||||
"moduleExpression"
|
||||
]),
|
||||
currentHash: new SyncWaterfallHook(["source", "requestedLength"]),
|
||||
assetPath: new SyncWaterfallHook(["path", "options", "assetInfo"]),
|
||||
hash: new SyncHook(["hash"]),
|
||||
hashForChunk: new SyncHook(["hash", "chunk"]),
|
||||
globalHashPaths: new SyncWaterfallHook(["paths"]),
|
||||
globalHash: new SyncBailHook(["chunk", "paths"]),
|
||||
|
||||
// TODO this should be moved somewhere else
|
||||
// It's weird here
|
||||
hotBootstrap: new SyncWaterfallHook(["source", "chunk", "hash"])
|
||||
};
|
||||
this.hooks.startup.tap("MainTemplate", (source, chunk, hash) => {
|
||||
/** @type {string[]} */
|
||||
const buf = [];
|
||||
if (chunk.entryModule) {
|
||||
buf.push("// Load entry module and return exports");
|
||||
buf.push(
|
||||
`return ${this.renderRequireFunctionForModule(
|
||||
hash,
|
||||
chunk,
|
||||
JSON.stringify(chunk.entryModule.id)
|
||||
)}(${this.requireFn}.s = ${JSON.stringify(chunk.entryModule.id)});`
|
||||
);
|
||||
}
|
||||
return Template.asString(buf);
|
||||
});
|
||||
this.hooks.render.tap(
|
||||
"MainTemplate",
|
||||
(bootstrapSource, chunk, hash, moduleTemplate, dependencyTemplates) => {
|
||||
const source = new ConcatSource();
|
||||
source.add("/******/ (function(modules) { // webpackBootstrap\n");
|
||||
source.add(new PrefixSource("/******/", bootstrapSource));
|
||||
source.add("/******/ })\n");
|
||||
source.add(
|
||||
"/************************************************************************/\n"
|
||||
);
|
||||
source.add("/******/ (");
|
||||
source.add(
|
||||
this.hooks.modules.call(
|
||||
new RawSource(""),
|
||||
chunk,
|
||||
hash,
|
||||
moduleTemplate,
|
||||
dependencyTemplates
|
||||
)
|
||||
);
|
||||
source.add(")");
|
||||
return source;
|
||||
}
|
||||
);
|
||||
this.hooks.localVars.tap("MainTemplate", (source, chunk, hash) => {
|
||||
return Template.asString([
|
||||
source,
|
||||
"// The module cache",
|
||||
"var installedModules = {};"
|
||||
]);
|
||||
});
|
||||
this.hooks.require.tap("MainTemplate", (source, chunk, hash) => {
|
||||
return Template.asString([
|
||||
source,
|
||||
"// Check if module is in cache",
|
||||
"if(installedModules[moduleId]) {",
|
||||
Template.indent("return installedModules[moduleId].exports;"),
|
||||
"}",
|
||||
"// Create a new module (and put it into the cache)",
|
||||
"var module = installedModules[moduleId] = {",
|
||||
Template.indent(this.hooks.moduleObj.call("", chunk, hash, "moduleId")),
|
||||
"};",
|
||||
"",
|
||||
Template.asString(
|
||||
outputOptions.strictModuleExceptionHandling
|
||||
? [
|
||||
"// Execute the module function",
|
||||
"var threw = true;",
|
||||
"try {",
|
||||
Template.indent([
|
||||
`modules[moduleId].call(module.exports, module, module.exports, ${this.renderRequireFunctionForModule(
|
||||
hash,
|
||||
chunk,
|
||||
"moduleId"
|
||||
)});`,
|
||||
"threw = false;"
|
||||
]),
|
||||
"} finally {",
|
||||
Template.indent([
|
||||
"if(threw) delete installedModules[moduleId];"
|
||||
]),
|
||||
"}"
|
||||
]
|
||||
: [
|
||||
"// Execute the module function",
|
||||
`modules[moduleId].call(module.exports, module, module.exports, ${this.renderRequireFunctionForModule(
|
||||
hash,
|
||||
chunk,
|
||||
"moduleId"
|
||||
)});`
|
||||
]
|
||||
),
|
||||
"",
|
||||
"// Flag the module as loaded",
|
||||
"module.l = true;",
|
||||
"",
|
||||
"// Return the exports of the module",
|
||||
"return module.exports;"
|
||||
]);
|
||||
});
|
||||
this.hooks.moduleObj.tap(
|
||||
"MainTemplate",
|
||||
(source, chunk, hash, varModuleId) => {
|
||||
return Template.asString(["i: moduleId,", "l: false,", "exports: {}"]);
|
||||
}
|
||||
);
|
||||
this.hooks.requireExtensions.tap("MainTemplate", (source, chunk, hash) => {
|
||||
const buf = [];
|
||||
const chunkMaps = chunk.getChunkMaps();
|
||||
// Check if there are non initial chunks which need to be imported using require-ensure
|
||||
if (Object.keys(chunkMaps.hash).length) {
|
||||
buf.push("// This file contains only the entry chunk.");
|
||||
buf.push("// The chunk loading function for additional chunks");
|
||||
buf.push(`${this.requireFn}.e = function requireEnsure(chunkId) {`);
|
||||
buf.push(Template.indent("var promises = [];"));
|
||||
buf.push(
|
||||
Template.indent(
|
||||
this.hooks.requireEnsure.call("", chunk, hash, "chunkId")
|
||||
)
|
||||
);
|
||||
buf.push(Template.indent("return Promise.all(promises);"));
|
||||
buf.push("};");
|
||||
} else if (
|
||||
chunk.hasModuleInGraph(m =>
|
||||
m.blocks.some(b => b.chunkGroup && b.chunkGroup.chunks.length > 0)
|
||||
)
|
||||
) {
|
||||
// There async blocks in the graph, so we need to add an empty requireEnsure
|
||||
// function anyway. This can happen with multiple entrypoints.
|
||||
buf.push("// The chunk loading function for additional chunks");
|
||||
buf.push("// Since all referenced chunks are already included");
|
||||
buf.push("// in this file, this function is empty here.");
|
||||
buf.push(`${this.requireFn}.e = function requireEnsure() {`);
|
||||
buf.push(Template.indent("return Promise.resolve();"));
|
||||
buf.push("};");
|
||||
}
|
||||
buf.push("");
|
||||
buf.push("// expose the modules object (__webpack_modules__)");
|
||||
buf.push(`${this.requireFn}.m = modules;`);
|
||||
|
||||
buf.push("");
|
||||
buf.push("// expose the module cache");
|
||||
buf.push(`${this.requireFn}.c = installedModules;`);
|
||||
|
||||
buf.push("");
|
||||
buf.push("// define getter function for harmony exports");
|
||||
buf.push(`${this.requireFn}.d = function(exports, name, getter) {`);
|
||||
buf.push(
|
||||
Template.indent([
|
||||
`if(!${this.requireFn}.o(exports, name)) {`,
|
||||
Template.indent([
|
||||
"Object.defineProperty(exports, name, { enumerable: true, get: getter });"
|
||||
]),
|
||||
"}"
|
||||
])
|
||||
);
|
||||
buf.push("};");
|
||||
|
||||
buf.push("");
|
||||
buf.push("// define __esModule on exports");
|
||||
buf.push(`${this.requireFn}.r = function(exports) {`);
|
||||
buf.push(
|
||||
Template.indent([
|
||||
"if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {",
|
||||
Template.indent([
|
||||
"Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });"
|
||||
]),
|
||||
"}",
|
||||
"Object.defineProperty(exports, '__esModule', { value: true });"
|
||||
])
|
||||
);
|
||||
buf.push("};");
|
||||
|
||||
buf.push("");
|
||||
buf.push("// create a fake namespace object");
|
||||
buf.push("// mode & 1: value is a module id, require it");
|
||||
buf.push("// mode & 2: merge all properties of value into the ns");
|
||||
buf.push("// mode & 4: return value when already ns object");
|
||||
buf.push("// mode & 8|1: behave like require");
|
||||
buf.push(`${this.requireFn}.t = function(value, mode) {`);
|
||||
buf.push(
|
||||
Template.indent([
|
||||
`if(mode & 1) value = ${this.requireFn}(value);`,
|
||||
`if(mode & 8) return value;`,
|
||||
"if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;",
|
||||
"var ns = Object.create(null);",
|
||||
`${this.requireFn}.r(ns);`,
|
||||
"Object.defineProperty(ns, 'default', { enumerable: true, value: value });",
|
||||
"if(mode & 2 && typeof value != 'string') for(var key in value) " +
|
||||
`${this.requireFn}.d(ns, key, function(key) { ` +
|
||||
"return value[key]; " +
|
||||
"}.bind(null, key));",
|
||||
"return ns;"
|
||||
])
|
||||
);
|
||||
buf.push("};");
|
||||
|
||||
buf.push("");
|
||||
buf.push(
|
||||
"// getDefaultExport function for compatibility with non-harmony modules"
|
||||
);
|
||||
buf.push(this.requireFn + ".n = function(module) {");
|
||||
buf.push(
|
||||
Template.indent([
|
||||
"var getter = module && module.__esModule ?",
|
||||
Template.indent([
|
||||
"function getDefault() { return module['default']; } :",
|
||||
"function getModuleExports() { return module; };"
|
||||
]),
|
||||
`${this.requireFn}.d(getter, 'a', getter);`,
|
||||
"return getter;"
|
||||
])
|
||||
);
|
||||
buf.push("};");
|
||||
|
||||
buf.push("");
|
||||
buf.push("// Object.prototype.hasOwnProperty.call");
|
||||
buf.push(
|
||||
`${this.requireFn}.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };`
|
||||
);
|
||||
|
||||
const publicPath = this.getPublicPath({
|
||||
hash: hash
|
||||
});
|
||||
buf.push("");
|
||||
buf.push("// __webpack_public_path__");
|
||||
buf.push(`${this.requireFn}.p = ${JSON.stringify(publicPath)};`);
|
||||
return Template.asString(buf);
|
||||
});
|
||||
|
||||
this.requireFn = "__webpack_require__";
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {RenderManifestOptions} options render manifest options
|
||||
* @returns {TODO[]} returns render manifest
|
||||
*/
|
||||
getRenderManifest(options) {
|
||||
const result = [];
|
||||
|
||||
this.hooks.renderManifest.call(result, options);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO webpack 5: remove moduleTemplate and dependencyTemplates
|
||||
* @param {string} hash hash to be used for render call
|
||||
* @param {Chunk} chunk Chunk instance
|
||||
* @param {ModuleTemplate} moduleTemplate ModuleTemplate instance for render
|
||||
* @param {Map<Function, DependencyTemplate>} dependencyTemplates dependency templates
|
||||
* @returns {string[]} the generated source of the bootstrap code
|
||||
*/
|
||||
renderBootstrap(hash, chunk, moduleTemplate, dependencyTemplates) {
|
||||
const buf = [];
|
||||
buf.push(
|
||||
this.hooks.bootstrap.call(
|
||||
"",
|
||||
chunk,
|
||||
hash,
|
||||
moduleTemplate,
|
||||
dependencyTemplates
|
||||
)
|
||||
);
|
||||
buf.push(this.hooks.localVars.call("", chunk, hash));
|
||||
buf.push("");
|
||||
buf.push("// The require function");
|
||||
buf.push(`function ${this.requireFn}(moduleId) {`);
|
||||
buf.push(Template.indent(this.hooks.require.call("", chunk, hash)));
|
||||
buf.push("}");
|
||||
buf.push("");
|
||||
buf.push(
|
||||
Template.asString(this.hooks.requireExtensions.call("", chunk, hash))
|
||||
);
|
||||
buf.push("");
|
||||
buf.push(Template.asString(this.hooks.beforeStartup.call("", chunk, hash)));
|
||||
const afterStartupCode = Template.asString(
|
||||
this.hooks.afterStartup.call("", chunk, hash)
|
||||
);
|
||||
if (afterStartupCode) {
|
||||
// TODO webpack 5: this is a bit hacky to avoid a breaking change
|
||||
// change it to a better way
|
||||
buf.push("var startupResult = (function() {");
|
||||
}
|
||||
buf.push(Template.asString(this.hooks.startup.call("", chunk, hash)));
|
||||
if (afterStartupCode) {
|
||||
buf.push("})();");
|
||||
buf.push(afterStartupCode);
|
||||
buf.push("return startupResult;");
|
||||
}
|
||||
return buf;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} hash hash to be used for render call
|
||||
* @param {Chunk} chunk Chunk instance
|
||||
* @param {ModuleTemplate} moduleTemplate ModuleTemplate instance for render
|
||||
* @param {Map<Function, DependencyTemplate>} dependencyTemplates dependency templates
|
||||
* @returns {ConcatSource} the newly generated source from rendering
|
||||
*/
|
||||
render(hash, chunk, moduleTemplate, dependencyTemplates) {
|
||||
const buf = this.renderBootstrap(
|
||||
hash,
|
||||
chunk,
|
||||
moduleTemplate,
|
||||
dependencyTemplates
|
||||
);
|
||||
let source = this.hooks.render.call(
|
||||
new OriginalSource(
|
||||
Template.prefix(buf, " \t") + "\n",
|
||||
"webpack/bootstrap"
|
||||
),
|
||||
chunk,
|
||||
hash,
|
||||
moduleTemplate,
|
||||
dependencyTemplates
|
||||
);
|
||||
if (chunk.hasEntryModule()) {
|
||||
source = this.hooks.renderWithEntry.call(source, chunk, hash);
|
||||
}
|
||||
if (!source) {
|
||||
throw new Error(
|
||||
"Compiler error: MainTemplate plugin 'render' should return something"
|
||||
);
|
||||
}
|
||||
chunk.rendered = true;
|
||||
return new ConcatSource(source, ";");
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {string} hash hash for render fn
|
||||
* @param {Chunk} chunk Chunk instance for require
|
||||
* @param {(number|string)=} varModuleId module id
|
||||
* @returns {TODO} the moduleRequire hook call return signature
|
||||
*/
|
||||
renderRequireFunctionForModule(hash, chunk, varModuleId) {
|
||||
return this.hooks.moduleRequire.call(
|
||||
this.requireFn,
|
||||
chunk,
|
||||
hash,
|
||||
varModuleId
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {string} hash hash for render add fn
|
||||
* @param {Chunk} chunk Chunk instance for require add fn
|
||||
* @param {(string|number)=} varModuleId module id
|
||||
* @param {Module} varModule Module instance
|
||||
* @returns {TODO} renderAddModule call
|
||||
*/
|
||||
renderAddModule(hash, chunk, varModuleId, varModule) {
|
||||
return this.hooks.addModule.call(
|
||||
`modules[${varModuleId}] = ${varModule};`,
|
||||
chunk,
|
||||
hash,
|
||||
varModuleId,
|
||||
varModule
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {string} hash string hash
|
||||
* @param {number=} length length
|
||||
* @returns {string} call hook return
|
||||
*/
|
||||
renderCurrentHashCode(hash, length) {
|
||||
length = length || Infinity;
|
||||
return this.hooks.currentHash.call(
|
||||
JSON.stringify(hash.substr(0, length)),
|
||||
length
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {object} options get public path options
|
||||
* @returns {string} hook call
|
||||
*/
|
||||
getPublicPath(options) {
|
||||
return this.hooks.assetPath.call(
|
||||
this.outputOptions.publicPath || "",
|
||||
options
|
||||
);
|
||||
}
|
||||
|
||||
getAssetPath(path, options) {
|
||||
return this.hooks.assetPath.call(path, options);
|
||||
}
|
||||
|
||||
getAssetPathWithInfo(path, options) {
|
||||
const assetInfo = {};
|
||||
// TODO webpack 5: refactor assetPath hook to receive { path, info } object
|
||||
const newPath = this.hooks.assetPath.call(path, options, assetInfo);
|
||||
return { path: newPath, info: assetInfo };
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates hash with information from this template
|
||||
* @param {Hash} hash the hash to update
|
||||
* @returns {void}
|
||||
*/
|
||||
updateHash(hash) {
|
||||
hash.update("maintemplate");
|
||||
hash.update("3");
|
||||
this.hooks.hash.call(hash);
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO webpack 5: remove moduleTemplate and dependencyTemplates
|
||||
* Updates hash with chunk-specific information from this template
|
||||
* @param {Hash} hash the hash to update
|
||||
* @param {Chunk} chunk the chunk
|
||||
* @param {ModuleTemplate} moduleTemplate ModuleTemplate instance for render
|
||||
* @param {Map<Function, DependencyTemplate>} dependencyTemplates dependency templates
|
||||
* @returns {void}
|
||||
*/
|
||||
updateHashForChunk(hash, chunk, moduleTemplate, dependencyTemplates) {
|
||||
this.updateHash(hash);
|
||||
this.hooks.hashForChunk.call(hash, chunk);
|
||||
for (const line of this.renderBootstrap(
|
||||
"0000",
|
||||
chunk,
|
||||
moduleTemplate,
|
||||
dependencyTemplates
|
||||
)) {
|
||||
hash.update(line);
|
||||
}
|
||||
}
|
||||
|
||||
useChunkHash(chunk) {
|
||||
const paths = this.hooks.globalHashPaths.call([]);
|
||||
return !this.hooks.globalHash.call(chunk, paths);
|
||||
}
|
||||
};
|
||||
5
node_modules/webpack/lib/MemoryOutputFileSystem.js
generated
vendored
Normal file
5
node_modules/webpack/lib/MemoryOutputFileSystem.js
generated
vendored
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
module.exports = require("memory-fs");
|
||||
435
node_modules/webpack/lib/Module.js
generated
vendored
Normal file
435
node_modules/webpack/lib/Module.js
generated
vendored
Normal file
|
|
@ -0,0 +1,435 @@
|
|||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
"use strict";
|
||||
|
||||
const util = require("util");
|
||||
|
||||
const DependenciesBlock = require("./DependenciesBlock");
|
||||
const ModuleReason = require("./ModuleReason");
|
||||
const SortableSet = require("./util/SortableSet");
|
||||
const Template = require("./Template");
|
||||
|
||||
/** @typedef {import("./Chunk")} Chunk */
|
||||
/** @typedef {import("./RequestShortener")} RequestShortener */
|
||||
/** @typedef {import("./WebpackError")} WebpackError */
|
||||
/** @typedef {import("./util/createHash").Hash} Hash */
|
||||
|
||||
const EMPTY_RESOLVE_OPTIONS = {};
|
||||
|
||||
let debugId = 1000;
|
||||
|
||||
const sortById = (a, b) => {
|
||||
return a.id - b.id;
|
||||
};
|
||||
|
||||
const sortByDebugId = (a, b) => {
|
||||
return a.debugId - b.debugId;
|
||||
};
|
||||
|
||||
/** @typedef {(requestShortener: RequestShortener) => string} OptimizationBailoutFunction */
|
||||
|
||||
class Module extends DependenciesBlock {
|
||||
constructor(type, context = null) {
|
||||
super();
|
||||
/** @type {string} */
|
||||
this.type = type;
|
||||
/** @type {string} */
|
||||
this.context = context;
|
||||
|
||||
// Unique Id
|
||||
/** @type {number} */
|
||||
this.debugId = debugId++;
|
||||
|
||||
// Hash
|
||||
/** @type {string} */
|
||||
this.hash = undefined;
|
||||
/** @type {string} */
|
||||
this.renderedHash = undefined;
|
||||
|
||||
// Info from Factory
|
||||
/** @type {TODO} */
|
||||
this.resolveOptions = EMPTY_RESOLVE_OPTIONS;
|
||||
/** @type {object} */
|
||||
this.factoryMeta = {};
|
||||
|
||||
// Info from Build
|
||||
/** @type {WebpackError[]} */
|
||||
this.warnings = [];
|
||||
/** @type {WebpackError[]} */
|
||||
this.errors = [];
|
||||
/** @type {object} */
|
||||
this.buildMeta = undefined;
|
||||
/** @type {object} */
|
||||
this.buildInfo = undefined;
|
||||
|
||||
// Graph (per Compilation)
|
||||
/** @type {ModuleReason[]} */
|
||||
this.reasons = [];
|
||||
/** @type {SortableSet<Chunk>} */
|
||||
this._chunks = new SortableSet(undefined, sortById);
|
||||
|
||||
// Info from Compilation (per Compilation)
|
||||
/** @type {number|string} */
|
||||
this.id = null;
|
||||
/** @type {number} */
|
||||
this.index = null;
|
||||
/** @type {number} */
|
||||
this.index2 = null;
|
||||
/** @type {number} */
|
||||
this.depth = null;
|
||||
/** @type {Module} */
|
||||
this.issuer = null;
|
||||
/** @type {undefined | object} */
|
||||
this.profile = undefined;
|
||||
/** @type {boolean} */
|
||||
this.prefetched = false;
|
||||
/** @type {boolean} */
|
||||
this.built = false;
|
||||
|
||||
// Info from Optimization (per Compilation)
|
||||
/** @type {null | boolean} */
|
||||
this.used = null;
|
||||
/** @type {false | true | string[]} */
|
||||
this.usedExports = null;
|
||||
/** @type {(string | OptimizationBailoutFunction)[]} */
|
||||
this.optimizationBailout = [];
|
||||
|
||||
// delayed operations
|
||||
/** @type {undefined | {oldChunk: Chunk, newChunks: Chunk[]}[] } */
|
||||
this._rewriteChunkInReasons = undefined;
|
||||
|
||||
/** @type {boolean} */
|
||||
this.useSourceMap = false;
|
||||
|
||||
// info from build
|
||||
this._source = null;
|
||||
}
|
||||
|
||||
get exportsArgument() {
|
||||
return (this.buildInfo && this.buildInfo.exportsArgument) || "exports";
|
||||
}
|
||||
|
||||
get moduleArgument() {
|
||||
return (this.buildInfo && this.buildInfo.moduleArgument) || "module";
|
||||
}
|
||||
|
||||
disconnect() {
|
||||
this.hash = undefined;
|
||||
this.renderedHash = undefined;
|
||||
|
||||
this.reasons.length = 0;
|
||||
this._rewriteChunkInReasons = undefined;
|
||||
this._chunks.clear();
|
||||
|
||||
this.id = null;
|
||||
this.index = null;
|
||||
this.index2 = null;
|
||||
this.depth = null;
|
||||
this.issuer = null;
|
||||
this.profile = undefined;
|
||||
this.prefetched = false;
|
||||
this.built = false;
|
||||
|
||||
this.used = null;
|
||||
this.usedExports = null;
|
||||
this.optimizationBailout.length = 0;
|
||||
super.disconnect();
|
||||
}
|
||||
|
||||
unseal() {
|
||||
this.id = null;
|
||||
this.index = null;
|
||||
this.index2 = null;
|
||||
this.depth = null;
|
||||
this._chunks.clear();
|
||||
super.unseal();
|
||||
}
|
||||
|
||||
setChunks(chunks) {
|
||||
this._chunks = new SortableSet(chunks, sortById);
|
||||
}
|
||||
|
||||
addChunk(chunk) {
|
||||
if (this._chunks.has(chunk)) return false;
|
||||
this._chunks.add(chunk);
|
||||
return true;
|
||||
}
|
||||
|
||||
removeChunk(chunk) {
|
||||
if (this._chunks.delete(chunk)) {
|
||||
chunk.removeModule(this);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
isInChunk(chunk) {
|
||||
return this._chunks.has(chunk);
|
||||
}
|
||||
|
||||
isEntryModule() {
|
||||
for (const chunk of this._chunks) {
|
||||
if (chunk.entryModule === this) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
get optional() {
|
||||
return (
|
||||
this.reasons.length > 0 &&
|
||||
this.reasons.every(r => r.dependency && r.dependency.optional)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {Chunk[]} all chunks which contain the module
|
||||
*/
|
||||
getChunks() {
|
||||
return Array.from(this._chunks);
|
||||
}
|
||||
|
||||
getNumberOfChunks() {
|
||||
return this._chunks.size;
|
||||
}
|
||||
|
||||
get chunksIterable() {
|
||||
return this._chunks;
|
||||
}
|
||||
|
||||
hasEqualsChunks(otherModule) {
|
||||
if (this._chunks.size !== otherModule._chunks.size) return false;
|
||||
this._chunks.sortWith(sortByDebugId);
|
||||
otherModule._chunks.sortWith(sortByDebugId);
|
||||
const a = this._chunks[Symbol.iterator]();
|
||||
const b = otherModule._chunks[Symbol.iterator]();
|
||||
// eslint-disable-next-line no-constant-condition
|
||||
while (true) {
|
||||
const aItem = a.next();
|
||||
const bItem = b.next();
|
||||
if (aItem.done) return true;
|
||||
if (aItem.value !== bItem.value) return false;
|
||||
}
|
||||
}
|
||||
|
||||
addReason(module, dependency, explanation) {
|
||||
this.reasons.push(new ModuleReason(module, dependency, explanation));
|
||||
}
|
||||
|
||||
removeReason(module, dependency) {
|
||||
for (let i = 0; i < this.reasons.length; i++) {
|
||||
let r = this.reasons[i];
|
||||
if (r.module === module && r.dependency === dependency) {
|
||||
this.reasons.splice(i, 1);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
hasReasonForChunk(chunk) {
|
||||
if (this._rewriteChunkInReasons) {
|
||||
for (const operation of this._rewriteChunkInReasons) {
|
||||
this._doRewriteChunkInReasons(operation.oldChunk, operation.newChunks);
|
||||
}
|
||||
this._rewriteChunkInReasons = undefined;
|
||||
}
|
||||
for (let i = 0; i < this.reasons.length; i++) {
|
||||
if (this.reasons[i].hasChunk(chunk)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
hasReasons() {
|
||||
return this.reasons.length > 0;
|
||||
}
|
||||
|
||||
rewriteChunkInReasons(oldChunk, newChunks) {
|
||||
// This is expensive. Delay operation until we really need the data
|
||||
if (this._rewriteChunkInReasons === undefined) {
|
||||
this._rewriteChunkInReasons = [];
|
||||
}
|
||||
this._rewriteChunkInReasons.push({
|
||||
oldChunk,
|
||||
newChunks
|
||||
});
|
||||
}
|
||||
|
||||
_doRewriteChunkInReasons(oldChunk, newChunks) {
|
||||
for (let i = 0; i < this.reasons.length; i++) {
|
||||
this.reasons[i].rewriteChunks(oldChunk, newChunks);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string=} exportName the name of the export
|
||||
* @returns {boolean|string} false if the export isn't used, true if no exportName is provided and the module is used, or the name to access it if the export is used
|
||||
*/
|
||||
isUsed(exportName) {
|
||||
if (!exportName) return this.used !== false;
|
||||
if (this.used === null || this.usedExports === null) return exportName;
|
||||
if (!this.used) return false;
|
||||
if (!this.usedExports) return false;
|
||||
if (this.usedExports === true) return exportName;
|
||||
let idx = this.usedExports.indexOf(exportName);
|
||||
if (idx < 0) return false;
|
||||
|
||||
// Mangle export name if possible
|
||||
if (this.isProvided(exportName)) {
|
||||
if (this.buildMeta.exportsType === "namespace") {
|
||||
return Template.numberToIdentifer(idx);
|
||||
}
|
||||
if (
|
||||
this.buildMeta.exportsType === "named" &&
|
||||
!this.usedExports.includes("default")
|
||||
) {
|
||||
return Template.numberToIdentifer(idx);
|
||||
}
|
||||
}
|
||||
return exportName;
|
||||
}
|
||||
|
||||
isProvided(exportName) {
|
||||
if (!Array.isArray(this.buildMeta.providedExports)) return null;
|
||||
return this.buildMeta.providedExports.includes(exportName);
|
||||
}
|
||||
|
||||
toString() {
|
||||
return `Module[${this.id || this.debugId}]`;
|
||||
}
|
||||
|
||||
needRebuild(fileTimestamps, contextTimestamps) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Hash} hash the hash used to track dependencies
|
||||
* @returns {void}
|
||||
*/
|
||||
updateHash(hash) {
|
||||
hash.update(`${this.id}`);
|
||||
hash.update(JSON.stringify(this.usedExports));
|
||||
super.updateHash(hash);
|
||||
}
|
||||
|
||||
sortItems(sortChunks) {
|
||||
super.sortItems();
|
||||
if (sortChunks) this._chunks.sort();
|
||||
this.reasons.sort((a, b) => {
|
||||
if (a.module === b.module) return 0;
|
||||
if (!a.module) return -1;
|
||||
if (!b.module) return 1;
|
||||
return sortById(a.module, b.module);
|
||||
});
|
||||
if (Array.isArray(this.usedExports)) {
|
||||
this.usedExports.sort();
|
||||
}
|
||||
}
|
||||
|
||||
unbuild() {
|
||||
this.dependencies.length = 0;
|
||||
this.blocks.length = 0;
|
||||
this.variables.length = 0;
|
||||
this.buildMeta = undefined;
|
||||
this.buildInfo = undefined;
|
||||
this.disconnect();
|
||||
}
|
||||
|
||||
get arguments() {
|
||||
throw new Error("Module.arguments was removed, there is no replacement.");
|
||||
}
|
||||
|
||||
set arguments(value) {
|
||||
throw new Error("Module.arguments was removed, there is no replacement.");
|
||||
}
|
||||
}
|
||||
|
||||
// TODO remove in webpack 5
|
||||
Object.defineProperty(Module.prototype, "forEachChunk", {
|
||||
configurable: false,
|
||||
value: util.deprecate(
|
||||
/**
|
||||
* @deprecated
|
||||
* @param {function(any, any, Set<any>): void} fn callback function
|
||||
* @returns {void}
|
||||
* @this {Module}
|
||||
*/
|
||||
function(fn) {
|
||||
this._chunks.forEach(fn);
|
||||
},
|
||||
"Module.forEachChunk: Use for(const chunk of module.chunksIterable) instead"
|
||||
)
|
||||
});
|
||||
|
||||
// TODO remove in webpack 5
|
||||
Object.defineProperty(Module.prototype, "mapChunks", {
|
||||
configurable: false,
|
||||
value: util.deprecate(
|
||||
/**
|
||||
* @deprecated
|
||||
* @param {function(any, any): void} fn Mapper function
|
||||
* @returns {Array<TODO>} Array of chunks mapped
|
||||
* @this {Module}
|
||||
*/
|
||||
function(fn) {
|
||||
return Array.from(this._chunks, fn);
|
||||
},
|
||||
"Module.mapChunks: Use Array.from(module.chunksIterable, fn) instead"
|
||||
)
|
||||
});
|
||||
|
||||
// TODO remove in webpack 5
|
||||
Object.defineProperty(Module.prototype, "entry", {
|
||||
configurable: false,
|
||||
get() {
|
||||
throw new Error("Module.entry was removed. Use Chunk.entryModule");
|
||||
},
|
||||
set() {
|
||||
throw new Error("Module.entry was removed. Use Chunk.entryModule");
|
||||
}
|
||||
});
|
||||
|
||||
// TODO remove in webpack 5
|
||||
Object.defineProperty(Module.prototype, "meta", {
|
||||
configurable: false,
|
||||
get: util.deprecate(
|
||||
/**
|
||||
* @deprecated
|
||||
* @returns {void}
|
||||
* @this {Module}
|
||||
*/
|
||||
function() {
|
||||
return this.buildMeta;
|
||||
},
|
||||
"Module.meta was renamed to Module.buildMeta"
|
||||
),
|
||||
set: util.deprecate(
|
||||
/**
|
||||
* @deprecated
|
||||
* @param {TODO} value Value
|
||||
* @returns {void}
|
||||
* @this {Module}
|
||||
*/
|
||||
function(value) {
|
||||
this.buildMeta = value;
|
||||
},
|
||||
"Module.meta was renamed to Module.buildMeta"
|
||||
)
|
||||
});
|
||||
|
||||
/** @type {function(): string} */
|
||||
Module.prototype.identifier = null;
|
||||
|
||||
/** @type {function(RequestShortener): string} */
|
||||
Module.prototype.readableIdentifier = null;
|
||||
|
||||
Module.prototype.build = null;
|
||||
Module.prototype.source = null;
|
||||
Module.prototype.size = null;
|
||||
Module.prototype.nameForCondition = null;
|
||||
/** @type {null | function(Chunk): boolean} */
|
||||
Module.prototype.chunkCondition = null;
|
||||
Module.prototype.updateCacheModule = null;
|
||||
|
||||
module.exports = Module;
|
||||
52
node_modules/webpack/lib/ModuleBuildError.js
generated
vendored
Normal file
52
node_modules/webpack/lib/ModuleBuildError.js
generated
vendored
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
"use strict";
|
||||
|
||||
const WebpackError = require("./WebpackError");
|
||||
const { cutOffLoaderExecution } = require("./ErrorHelpers");
|
||||
|
||||
class ModuleBuildError extends WebpackError {
|
||||
constructor(module, err, { from = null } = {}) {
|
||||
let message = "Module build failed";
|
||||
let details = undefined;
|
||||
if (from) {
|
||||
message += ` (from ${from}):\n`;
|
||||
} else {
|
||||
message += ": ";
|
||||
}
|
||||
if (err !== null && typeof err === "object") {
|
||||
if (typeof err.stack === "string" && err.stack) {
|
||||
const stack = cutOffLoaderExecution(err.stack);
|
||||
if (!err.hideStack) {
|
||||
message += stack;
|
||||
} else {
|
||||
details = stack;
|
||||
if (typeof err.message === "string" && err.message) {
|
||||
message += err.message;
|
||||
} else {
|
||||
message += err;
|
||||
}
|
||||
}
|
||||
} else if (typeof err.message === "string" && err.message) {
|
||||
message += err.message;
|
||||
} else {
|
||||
message += err;
|
||||
}
|
||||
} else {
|
||||
message = err;
|
||||
}
|
||||
|
||||
super(message);
|
||||
|
||||
this.name = "ModuleBuildError";
|
||||
this.details = details;
|
||||
this.module = module;
|
||||
this.error = err;
|
||||
|
||||
Error.captureStackTrace(this, this.constructor);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ModuleBuildError;
|
||||
35
node_modules/webpack/lib/ModuleDependencyError.js
generated
vendored
Normal file
35
node_modules/webpack/lib/ModuleDependencyError.js
generated
vendored
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
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 ModuleDependencyError extends WebpackError {
|
||||
/**
|
||||
* Creates an instance of ModuleDependencyError.
|
||||
* @param {Module} module module tied to dependency
|
||||
* @param {Error} err error thrown
|
||||
* @param {TODO} loc location of dependency
|
||||
*/
|
||||
constructor(module, err, loc) {
|
||||
super(err.message);
|
||||
|
||||
this.name = "ModuleDependencyError";
|
||||
this.details = err.stack
|
||||
.split("\n")
|
||||
.slice(1)
|
||||
.join("\n");
|
||||
this.module = module;
|
||||
this.loc = loc;
|
||||
this.error = err;
|
||||
this.origin = module.issuer;
|
||||
|
||||
Error.captureStackTrace(this, this.constructor);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ModuleDependencyError;
|
||||
25
node_modules/webpack/lib/ModuleDependencyWarning.js
generated
vendored
Normal file
25
node_modules/webpack/lib/ModuleDependencyWarning.js
generated
vendored
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
"use strict";
|
||||
|
||||
const WebpackError = require("./WebpackError");
|
||||
|
||||
module.exports = class ModuleDependencyWarning extends WebpackError {
|
||||
constructor(module, err, loc) {
|
||||
super(err.message);
|
||||
|
||||
this.name = "ModuleDependencyWarning";
|
||||
this.details = err.stack
|
||||
.split("\n")
|
||||
.slice(1)
|
||||
.join("\n");
|
||||
this.module = module;
|
||||
this.loc = loc;
|
||||
this.error = err;
|
||||
this.origin = module.issuer;
|
||||
|
||||
Error.captureStackTrace(this, this.constructor);
|
||||
}
|
||||
};
|
||||
36
node_modules/webpack/lib/ModuleError.js
generated
vendored
Normal file
36
node_modules/webpack/lib/ModuleError.js
generated
vendored
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
"use strict";
|
||||
|
||||
const WebpackError = require("./WebpackError");
|
||||
const { cleanUp } = require("./ErrorHelpers");
|
||||
|
||||
class ModuleError extends WebpackError {
|
||||
constructor(module, err, { from = null } = {}) {
|
||||
let message = "Module Error";
|
||||
if (from) {
|
||||
message += ` (from ${from}):\n`;
|
||||
} else {
|
||||
message += ": ";
|
||||
}
|
||||
if (err && typeof err === "object" && err.message) {
|
||||
message += err.message;
|
||||
} else if (err) {
|
||||
message += err;
|
||||
}
|
||||
super(message);
|
||||
this.name = "ModuleError";
|
||||
this.module = module;
|
||||
this.error = err;
|
||||
this.details =
|
||||
err && typeof err === "object" && err.stack
|
||||
? cleanUp(err.stack, this.message)
|
||||
: undefined;
|
||||
|
||||
Error.captureStackTrace(this, this.constructor);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ModuleError;
|
||||
179
node_modules/webpack/lib/ModuleFilenameHelpers.js
generated
vendored
Normal file
179
node_modules/webpack/lib/ModuleFilenameHelpers.js
generated
vendored
Normal file
|
|
@ -0,0 +1,179 @@
|
|||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
"use strict";
|
||||
|
||||
const createHash = require("./util/createHash");
|
||||
|
||||
const ModuleFilenameHelpers = exports;
|
||||
|
||||
ModuleFilenameHelpers.ALL_LOADERS_RESOURCE = "[all-loaders][resource]";
|
||||
ModuleFilenameHelpers.REGEXP_ALL_LOADERS_RESOURCE = /\[all-?loaders\]\[resource\]/gi;
|
||||
ModuleFilenameHelpers.LOADERS_RESOURCE = "[loaders][resource]";
|
||||
ModuleFilenameHelpers.REGEXP_LOADERS_RESOURCE = /\[loaders\]\[resource\]/gi;
|
||||
ModuleFilenameHelpers.RESOURCE = "[resource]";
|
||||
ModuleFilenameHelpers.REGEXP_RESOURCE = /\[resource\]/gi;
|
||||
ModuleFilenameHelpers.ABSOLUTE_RESOURCE_PATH = "[absolute-resource-path]";
|
||||
ModuleFilenameHelpers.REGEXP_ABSOLUTE_RESOURCE_PATH = /\[abs(olute)?-?resource-?path\]/gi;
|
||||
ModuleFilenameHelpers.RESOURCE_PATH = "[resource-path]";
|
||||
ModuleFilenameHelpers.REGEXP_RESOURCE_PATH = /\[resource-?path\]/gi;
|
||||
ModuleFilenameHelpers.ALL_LOADERS = "[all-loaders]";
|
||||
ModuleFilenameHelpers.REGEXP_ALL_LOADERS = /\[all-?loaders\]/gi;
|
||||
ModuleFilenameHelpers.LOADERS = "[loaders]";
|
||||
ModuleFilenameHelpers.REGEXP_LOADERS = /\[loaders\]/gi;
|
||||
ModuleFilenameHelpers.QUERY = "[query]";
|
||||
ModuleFilenameHelpers.REGEXP_QUERY = /\[query\]/gi;
|
||||
ModuleFilenameHelpers.ID = "[id]";
|
||||
ModuleFilenameHelpers.REGEXP_ID = /\[id\]/gi;
|
||||
ModuleFilenameHelpers.HASH = "[hash]";
|
||||
ModuleFilenameHelpers.REGEXP_HASH = /\[hash\]/gi;
|
||||
ModuleFilenameHelpers.NAMESPACE = "[namespace]";
|
||||
ModuleFilenameHelpers.REGEXP_NAMESPACE = /\[namespace\]/gi;
|
||||
|
||||
const getAfter = (str, token) => {
|
||||
const idx = str.indexOf(token);
|
||||
return idx < 0 ? "" : str.substr(idx);
|
||||
};
|
||||
|
||||
const getBefore = (str, token) => {
|
||||
const idx = str.lastIndexOf(token);
|
||||
return idx < 0 ? "" : str.substr(0, idx);
|
||||
};
|
||||
|
||||
const getHash = str => {
|
||||
const hash = createHash("md4");
|
||||
hash.update(str);
|
||||
const digest = /** @type {string} */ (hash.digest("hex"));
|
||||
return digest.substr(0, 4);
|
||||
};
|
||||
|
||||
const asRegExp = test => {
|
||||
if (typeof test === "string") {
|
||||
test = new RegExp("^" + test.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"));
|
||||
}
|
||||
return test;
|
||||
};
|
||||
|
||||
ModuleFilenameHelpers.createFilename = (module, options, requestShortener) => {
|
||||
const opts = Object.assign(
|
||||
{
|
||||
namespace: "",
|
||||
moduleFilenameTemplate: ""
|
||||
},
|
||||
typeof options === "object"
|
||||
? options
|
||||
: {
|
||||
moduleFilenameTemplate: options
|
||||
}
|
||||
);
|
||||
|
||||
let absoluteResourcePath;
|
||||
let hash;
|
||||
let identifier;
|
||||
let moduleId;
|
||||
let shortIdentifier;
|
||||
if (module === undefined) module = "";
|
||||
if (typeof module === "string") {
|
||||
shortIdentifier = requestShortener.shorten(module);
|
||||
identifier = shortIdentifier;
|
||||
moduleId = "";
|
||||
absoluteResourcePath = module.split("!").pop();
|
||||
hash = getHash(identifier);
|
||||
} else {
|
||||
shortIdentifier = module.readableIdentifier(requestShortener);
|
||||
identifier = requestShortener.shorten(module.identifier());
|
||||
moduleId = module.id;
|
||||
absoluteResourcePath = module
|
||||
.identifier()
|
||||
.split("!")
|
||||
.pop();
|
||||
hash = getHash(identifier);
|
||||
}
|
||||
const resource = shortIdentifier.split("!").pop();
|
||||
const loaders = getBefore(shortIdentifier, "!");
|
||||
const allLoaders = getBefore(identifier, "!");
|
||||
const query = getAfter(resource, "?");
|
||||
const resourcePath = resource.substr(0, resource.length - query.length);
|
||||
if (typeof opts.moduleFilenameTemplate === "function") {
|
||||
return opts.moduleFilenameTemplate({
|
||||
identifier: identifier,
|
||||
shortIdentifier: shortIdentifier,
|
||||
resource: resource,
|
||||
resourcePath: resourcePath,
|
||||
absoluteResourcePath: absoluteResourcePath,
|
||||
allLoaders: allLoaders,
|
||||
query: query,
|
||||
moduleId: moduleId,
|
||||
hash: hash,
|
||||
namespace: opts.namespace
|
||||
});
|
||||
}
|
||||
return opts.moduleFilenameTemplate
|
||||
.replace(ModuleFilenameHelpers.REGEXP_ALL_LOADERS_RESOURCE, identifier)
|
||||
.replace(ModuleFilenameHelpers.REGEXP_LOADERS_RESOURCE, shortIdentifier)
|
||||
.replace(ModuleFilenameHelpers.REGEXP_RESOURCE, resource)
|
||||
.replace(ModuleFilenameHelpers.REGEXP_RESOURCE_PATH, resourcePath)
|
||||
.replace(
|
||||
ModuleFilenameHelpers.REGEXP_ABSOLUTE_RESOURCE_PATH,
|
||||
absoluteResourcePath
|
||||
)
|
||||
.replace(ModuleFilenameHelpers.REGEXP_ALL_LOADERS, allLoaders)
|
||||
.replace(ModuleFilenameHelpers.REGEXP_LOADERS, loaders)
|
||||
.replace(ModuleFilenameHelpers.REGEXP_QUERY, query)
|
||||
.replace(ModuleFilenameHelpers.REGEXP_ID, moduleId)
|
||||
.replace(ModuleFilenameHelpers.REGEXP_HASH, hash)
|
||||
.replace(ModuleFilenameHelpers.REGEXP_NAMESPACE, opts.namespace);
|
||||
};
|
||||
|
||||
ModuleFilenameHelpers.replaceDuplicates = (array, fn, comparator) => {
|
||||
const countMap = Object.create(null);
|
||||
const posMap = Object.create(null);
|
||||
array.forEach((item, idx) => {
|
||||
countMap[item] = countMap[item] || [];
|
||||
countMap[item].push(idx);
|
||||
posMap[item] = 0;
|
||||
});
|
||||
if (comparator) {
|
||||
Object.keys(countMap).forEach(item => {
|
||||
countMap[item].sort(comparator);
|
||||
});
|
||||
}
|
||||
return array.map((item, i) => {
|
||||
if (countMap[item].length > 1) {
|
||||
if (comparator && countMap[item][0] === i) return item;
|
||||
return fn(item, i, posMap[item]++);
|
||||
} else {
|
||||
return item;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
ModuleFilenameHelpers.matchPart = (str, test) => {
|
||||
if (!test) return true;
|
||||
test = asRegExp(test);
|
||||
if (Array.isArray(test)) {
|
||||
return test.map(asRegExp).some(regExp => regExp.test(str));
|
||||
} else {
|
||||
return test.test(str);
|
||||
}
|
||||
};
|
||||
|
||||
ModuleFilenameHelpers.matchObject = (obj, str) => {
|
||||
if (obj.test) {
|
||||
if (!ModuleFilenameHelpers.matchPart(str, obj.test)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (obj.include) {
|
||||
if (!ModuleFilenameHelpers.matchPart(str, obj.include)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (obj.exclude) {
|
||||
if (ModuleFilenameHelpers.matchPart(str, obj.exclude)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
};
|
||||
23
node_modules/webpack/lib/ModuleNotFoundError.js
generated
vendored
Normal file
23
node_modules/webpack/lib/ModuleNotFoundError.js
generated
vendored
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
"use strict";
|
||||
|
||||
const WebpackError = require("./WebpackError");
|
||||
|
||||
class ModuleNotFoundError extends WebpackError {
|
||||
constructor(module, err) {
|
||||
super("Module not found: " + err);
|
||||
|
||||
this.name = "ModuleNotFoundError";
|
||||
this.details = err.details;
|
||||
this.missing = err.missing;
|
||||
this.module = module;
|
||||
this.error = err;
|
||||
|
||||
Error.captureStackTrace(this, this.constructor);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ModuleNotFoundError;
|
||||
67
node_modules/webpack/lib/ModuleParseError.js
generated
vendored
Normal file
67
node_modules/webpack/lib/ModuleParseError.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 WebpackError = require("./WebpackError");
|
||||
|
||||
/** @typedef {import("./Module")} Module */
|
||||
|
||||
class ModuleParseError extends WebpackError {
|
||||
/**
|
||||
* @param {Module} module the errored module
|
||||
* @param {string} source source code
|
||||
* @param {Error&any} err the parse error
|
||||
* @param {string[]} loaders the loaders used
|
||||
*/
|
||||
constructor(module, source, err, loaders) {
|
||||
let message = "Module parse failed: " + err.message;
|
||||
let loc = undefined;
|
||||
if (loaders.length >= 1) {
|
||||
message += `\nFile was processed with these loaders:${loaders
|
||||
.map(loader => `\n * ${loader}`)
|
||||
.join("")}`;
|
||||
message +=
|
||||
"\nYou may need an additional loader to handle the result of these loaders.";
|
||||
} else {
|
||||
message +=
|
||||
"\nYou may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders";
|
||||
}
|
||||
if (
|
||||
err.loc &&
|
||||
typeof err.loc === "object" &&
|
||||
typeof err.loc.line === "number"
|
||||
) {
|
||||
var lineNumber = err.loc.line;
|
||||
if (/[\0\u0001\u0002\u0003\u0004\u0005\u0006\u0007]/.test(source)) {
|
||||
// binary file
|
||||
message += "\n(Source code omitted for this binary file)";
|
||||
} else {
|
||||
const sourceLines = source.split(/\r?\n/);
|
||||
const start = Math.max(0, lineNumber - 3);
|
||||
const linesBefore = sourceLines.slice(start, lineNumber - 1);
|
||||
const theLine = sourceLines[lineNumber - 1];
|
||||
const linesAfter = sourceLines.slice(lineNumber, lineNumber + 2);
|
||||
message +=
|
||||
linesBefore.map(l => `\n| ${l}`).join("") +
|
||||
`\n> ${theLine}` +
|
||||
linesAfter.map(l => `\n| ${l}`).join("");
|
||||
}
|
||||
loc = err.loc;
|
||||
} else {
|
||||
message += "\n" + err.stack;
|
||||
}
|
||||
|
||||
super(message);
|
||||
|
||||
this.name = "ModuleParseError";
|
||||
this.module = module;
|
||||
this.loc = loc;
|
||||
this.error = err;
|
||||
|
||||
Error.captureStackTrace(this, this.constructor);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ModuleParseError;
|
||||
48
node_modules/webpack/lib/ModuleReason.js
generated
vendored
Normal file
48
node_modules/webpack/lib/ModuleReason.js
generated
vendored
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
"use strict";
|
||||
|
||||
/** @typedef {import("./Module")} Module */
|
||||
/** @typedef {import("./Dependency")} Dependency */
|
||||
|
||||
class ModuleReason {
|
||||
/**
|
||||
* @param {Module} module the referencing module
|
||||
* @param {Dependency} dependency the referencing dependency
|
||||
* @param {string=} explanation some extra detail
|
||||
*/
|
||||
constructor(module, dependency, explanation) {
|
||||
this.module = module;
|
||||
this.dependency = dependency;
|
||||
this.explanation = explanation;
|
||||
this._chunks = null;
|
||||
}
|
||||
|
||||
hasChunk(chunk) {
|
||||
if (this._chunks) {
|
||||
if (this._chunks.has(chunk)) return true;
|
||||
} else if (this.module && this.module._chunks.has(chunk)) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
rewriteChunks(oldChunk, newChunks) {
|
||||
if (!this._chunks) {
|
||||
if (this.module) {
|
||||
if (!this.module._chunks.has(oldChunk)) return;
|
||||
this._chunks = new Set(this.module._chunks);
|
||||
} else {
|
||||
this._chunks = new Set();
|
||||
}
|
||||
}
|
||||
if (this._chunks.has(oldChunk)) {
|
||||
this._chunks.delete(oldChunk);
|
||||
for (let i = 0; i < newChunks.length; i++) {
|
||||
this._chunks.add(newChunks[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ModuleReason;
|
||||
93
node_modules/webpack/lib/ModuleTemplate.js
generated
vendored
Normal file
93
node_modules/webpack/lib/ModuleTemplate.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";
|
||||
|
||||
const { Tapable, SyncWaterfallHook, SyncHook } = require("tapable");
|
||||
|
||||
/** @typedef {import("webpack-sources").Source} Source */
|
||||
/** @typedef {import("./Module")} Module */
|
||||
|
||||
module.exports = class ModuleTemplate extends Tapable {
|
||||
constructor(runtimeTemplate, type) {
|
||||
super();
|
||||
this.runtimeTemplate = runtimeTemplate;
|
||||
this.type = type;
|
||||
this.hooks = {
|
||||
content: new SyncWaterfallHook([
|
||||
"source",
|
||||
"module",
|
||||
"options",
|
||||
"dependencyTemplates"
|
||||
]),
|
||||
module: new SyncWaterfallHook([
|
||||
"source",
|
||||
"module",
|
||||
"options",
|
||||
"dependencyTemplates"
|
||||
]),
|
||||
render: new SyncWaterfallHook([
|
||||
"source",
|
||||
"module",
|
||||
"options",
|
||||
"dependencyTemplates"
|
||||
]),
|
||||
package: new SyncWaterfallHook([
|
||||
"source",
|
||||
"module",
|
||||
"options",
|
||||
"dependencyTemplates"
|
||||
]),
|
||||
hash: new SyncHook(["hash"])
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Module} module the module
|
||||
* @param {TODO} dependencyTemplates templates for dependencies
|
||||
* @param {TODO} options render options
|
||||
* @returns {Source} the source
|
||||
*/
|
||||
render(module, dependencyTemplates, options) {
|
||||
try {
|
||||
const moduleSource = module.source(
|
||||
dependencyTemplates,
|
||||
this.runtimeTemplate,
|
||||
this.type
|
||||
);
|
||||
const moduleSourcePostContent = this.hooks.content.call(
|
||||
moduleSource,
|
||||
module,
|
||||
options,
|
||||
dependencyTemplates
|
||||
);
|
||||
const moduleSourcePostModule = this.hooks.module.call(
|
||||
moduleSourcePostContent,
|
||||
module,
|
||||
options,
|
||||
dependencyTemplates
|
||||
);
|
||||
const moduleSourcePostRender = this.hooks.render.call(
|
||||
moduleSourcePostModule,
|
||||
module,
|
||||
options,
|
||||
dependencyTemplates
|
||||
);
|
||||
return this.hooks.package.call(
|
||||
moduleSourcePostRender,
|
||||
module,
|
||||
options,
|
||||
dependencyTemplates
|
||||
);
|
||||
} catch (e) {
|
||||
e.message = `${module.identifier()}\n${e.message}`;
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
updateHash(hash) {
|
||||
hash.update("1");
|
||||
this.hooks.hash.call(hash);
|
||||
}
|
||||
};
|
||||
36
node_modules/webpack/lib/ModuleWarning.js
generated
vendored
Normal file
36
node_modules/webpack/lib/ModuleWarning.js
generated
vendored
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
"use strict";
|
||||
|
||||
const WebpackError = require("./WebpackError");
|
||||
const { cleanUp } = require("./ErrorHelpers");
|
||||
|
||||
class ModuleWarning extends WebpackError {
|
||||
constructor(module, warning, { from = null } = {}) {
|
||||
let message = "Module Warning";
|
||||
if (from) {
|
||||
message += ` (from ${from}):\n`;
|
||||
} else {
|
||||
message += ": ";
|
||||
}
|
||||
if (warning && typeof warning === "object" && warning.message) {
|
||||
message += warning.message;
|
||||
} else if (warning) {
|
||||
message += warning;
|
||||
}
|
||||
super(message);
|
||||
this.name = "ModuleWarning";
|
||||
this.module = module;
|
||||
this.warning = warning;
|
||||
this.details =
|
||||
warning && typeof warning === "object" && warning.stack
|
||||
? cleanUp(warning.stack, this.message)
|
||||
: undefined;
|
||||
|
||||
Error.captureStackTrace(this, this.constructor);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ModuleWarning;
|
||||
290
node_modules/webpack/lib/MultiCompiler.js
generated
vendored
Normal file
290
node_modules/webpack/lib/MultiCompiler.js
generated
vendored
Normal file
|
|
@ -0,0 +1,290 @@
|
|||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
"use strict";
|
||||
|
||||
const { Tapable, SyncHook, MultiHook } = require("tapable");
|
||||
const asyncLib = require("neo-async");
|
||||
const MultiWatching = require("./MultiWatching");
|
||||
const MultiStats = require("./MultiStats");
|
||||
const ConcurrentCompilationError = require("./ConcurrentCompilationError");
|
||||
|
||||
module.exports = class MultiCompiler extends Tapable {
|
||||
constructor(compilers) {
|
||||
super();
|
||||
this.hooks = {
|
||||
done: new SyncHook(["stats"]),
|
||||
invalid: new MultiHook(compilers.map(c => c.hooks.invalid)),
|
||||
run: new MultiHook(compilers.map(c => c.hooks.run)),
|
||||
watchClose: new SyncHook([]),
|
||||
watchRun: new MultiHook(compilers.map(c => c.hooks.watchRun)),
|
||||
infrastructureLog: new MultiHook(
|
||||
compilers.map(c => c.hooks.infrastructureLog)
|
||||
)
|
||||
};
|
||||
if (!Array.isArray(compilers)) {
|
||||
compilers = Object.keys(compilers).map(name => {
|
||||
compilers[name].name = name;
|
||||
return compilers[name];
|
||||
});
|
||||
}
|
||||
this.compilers = compilers;
|
||||
let doneCompilers = 0;
|
||||
let compilerStats = [];
|
||||
let index = 0;
|
||||
for (const compiler of this.compilers) {
|
||||
let compilerDone = false;
|
||||
const compilerIndex = index++;
|
||||
// eslint-disable-next-line no-loop-func
|
||||
compiler.hooks.done.tap("MultiCompiler", stats => {
|
||||
if (!compilerDone) {
|
||||
compilerDone = true;
|
||||
doneCompilers++;
|
||||
}
|
||||
compilerStats[compilerIndex] = stats;
|
||||
if (doneCompilers === this.compilers.length) {
|
||||
this.hooks.done.call(new MultiStats(compilerStats));
|
||||
}
|
||||
});
|
||||
// eslint-disable-next-line no-loop-func
|
||||
compiler.hooks.invalid.tap("MultiCompiler", () => {
|
||||
if (compilerDone) {
|
||||
compilerDone = false;
|
||||
doneCompilers--;
|
||||
}
|
||||
});
|
||||
}
|
||||
this.running = false;
|
||||
}
|
||||
|
||||
get outputPath() {
|
||||
let commonPath = this.compilers[0].outputPath;
|
||||
for (const compiler of this.compilers) {
|
||||
while (
|
||||
compiler.outputPath.indexOf(commonPath) !== 0 &&
|
||||
/[/\\]/.test(commonPath)
|
||||
) {
|
||||
commonPath = commonPath.replace(/[/\\][^/\\]*$/, "");
|
||||
}
|
||||
}
|
||||
|
||||
if (!commonPath && this.compilers[0].outputPath[0] === "/") return "/";
|
||||
return commonPath;
|
||||
}
|
||||
|
||||
get inputFileSystem() {
|
||||
throw new Error("Cannot read inputFileSystem of a MultiCompiler");
|
||||
}
|
||||
|
||||
get outputFileSystem() {
|
||||
throw new Error("Cannot read outputFileSystem of a MultiCompiler");
|
||||
}
|
||||
|
||||
set inputFileSystem(value) {
|
||||
for (const compiler of this.compilers) {
|
||||
compiler.inputFileSystem = value;
|
||||
}
|
||||
}
|
||||
|
||||
set outputFileSystem(value) {
|
||||
for (const compiler of this.compilers) {
|
||||
compiler.outputFileSystem = value;
|
||||
}
|
||||
}
|
||||
|
||||
getInfrastructureLogger(name) {
|
||||
return this.compilers[0].getInfrastructureLogger(name);
|
||||
}
|
||||
|
||||
validateDependencies(callback) {
|
||||
const edges = new Set();
|
||||
const missing = [];
|
||||
const targetFound = compiler => {
|
||||
for (const edge of edges) {
|
||||
if (edge.target === compiler) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
const sortEdges = (e1, e2) => {
|
||||
return (
|
||||
e1.source.name.localeCompare(e2.source.name) ||
|
||||
e1.target.name.localeCompare(e2.target.name)
|
||||
);
|
||||
};
|
||||
for (const source of this.compilers) {
|
||||
if (source.dependencies) {
|
||||
for (const dep of source.dependencies) {
|
||||
const target = this.compilers.find(c => c.name === dep);
|
||||
if (!target) {
|
||||
missing.push(dep);
|
||||
} else {
|
||||
edges.add({
|
||||
source,
|
||||
target
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
const errors = missing.map(m => `Compiler dependency \`${m}\` not found.`);
|
||||
const stack = this.compilers.filter(c => !targetFound(c));
|
||||
while (stack.length > 0) {
|
||||
const current = stack.pop();
|
||||
for (const edge of edges) {
|
||||
if (edge.source === current) {
|
||||
edges.delete(edge);
|
||||
const target = edge.target;
|
||||
if (!targetFound(target)) {
|
||||
stack.push(target);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (edges.size > 0) {
|
||||
const lines = Array.from(edges)
|
||||
.sort(sortEdges)
|
||||
.map(edge => `${edge.source.name} -> ${edge.target.name}`);
|
||||
lines.unshift("Circular dependency found in compiler dependencies.");
|
||||
errors.unshift(lines.join("\n"));
|
||||
}
|
||||
if (errors.length > 0) {
|
||||
const message = errors.join("\n");
|
||||
callback(new Error(message));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
runWithDependencies(compilers, fn, callback) {
|
||||
const fulfilledNames = new Set();
|
||||
let remainingCompilers = compilers;
|
||||
const isDependencyFulfilled = d => fulfilledNames.has(d);
|
||||
const getReadyCompilers = () => {
|
||||
let readyCompilers = [];
|
||||
let list = remainingCompilers;
|
||||
remainingCompilers = [];
|
||||
for (const c of list) {
|
||||
const ready =
|
||||
!c.dependencies || c.dependencies.every(isDependencyFulfilled);
|
||||
if (ready) {
|
||||
readyCompilers.push(c);
|
||||
} else {
|
||||
remainingCompilers.push(c);
|
||||
}
|
||||
}
|
||||
return readyCompilers;
|
||||
};
|
||||
const runCompilers = callback => {
|
||||
if (remainingCompilers.length === 0) return callback();
|
||||
asyncLib.map(
|
||||
getReadyCompilers(),
|
||||
(compiler, callback) => {
|
||||
fn(compiler, err => {
|
||||
if (err) return callback(err);
|
||||
fulfilledNames.add(compiler.name);
|
||||
runCompilers(callback);
|
||||
});
|
||||
},
|
||||
callback
|
||||
);
|
||||
};
|
||||
runCompilers(callback);
|
||||
}
|
||||
|
||||
watch(watchOptions, handler) {
|
||||
if (this.running) return handler(new ConcurrentCompilationError());
|
||||
|
||||
let watchings = [];
|
||||
let allStats = this.compilers.map(() => null);
|
||||
let compilerStatus = this.compilers.map(() => false);
|
||||
if (this.validateDependencies(handler)) {
|
||||
this.running = true;
|
||||
this.runWithDependencies(
|
||||
this.compilers,
|
||||
(compiler, callback) => {
|
||||
const compilerIdx = this.compilers.indexOf(compiler);
|
||||
let firstRun = true;
|
||||
let watching = compiler.watch(
|
||||
Array.isArray(watchOptions)
|
||||
? watchOptions[compilerIdx]
|
||||
: watchOptions,
|
||||
(err, stats) => {
|
||||
if (err) handler(err);
|
||||
if (stats) {
|
||||
allStats[compilerIdx] = stats;
|
||||
compilerStatus[compilerIdx] = "new";
|
||||
if (compilerStatus.every(Boolean)) {
|
||||
const freshStats = allStats.filter((s, idx) => {
|
||||
return compilerStatus[idx] === "new";
|
||||
});
|
||||
compilerStatus.fill(true);
|
||||
const multiStats = new MultiStats(freshStats);
|
||||
handler(null, multiStats);
|
||||
}
|
||||
}
|
||||
if (firstRun && !err) {
|
||||
firstRun = false;
|
||||
callback();
|
||||
}
|
||||
}
|
||||
);
|
||||
watchings.push(watching);
|
||||
},
|
||||
() => {
|
||||
// ignore
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
return new MultiWatching(watchings, this);
|
||||
}
|
||||
|
||||
run(callback) {
|
||||
if (this.running) {
|
||||
return callback(new ConcurrentCompilationError());
|
||||
}
|
||||
|
||||
const finalCallback = (err, stats) => {
|
||||
this.running = false;
|
||||
|
||||
if (callback !== undefined) {
|
||||
return callback(err, stats);
|
||||
}
|
||||
};
|
||||
|
||||
const allStats = this.compilers.map(() => null);
|
||||
if (this.validateDependencies(callback)) {
|
||||
this.running = true;
|
||||
this.runWithDependencies(
|
||||
this.compilers,
|
||||
(compiler, callback) => {
|
||||
const compilerIdx = this.compilers.indexOf(compiler);
|
||||
compiler.run((err, stats) => {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
allStats[compilerIdx] = stats;
|
||||
callback();
|
||||
});
|
||||
},
|
||||
err => {
|
||||
if (err) {
|
||||
return finalCallback(err);
|
||||
}
|
||||
finalCallback(null, new MultiStats(allStats));
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
purgeInputFileSystem() {
|
||||
for (const compiler of this.compilers) {
|
||||
if (compiler.inputFileSystem && compiler.inputFileSystem.purge) {
|
||||
compiler.inputFileSystem.purge();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
80
node_modules/webpack/lib/MultiEntryPlugin.js
generated
vendored
Normal file
80
node_modules/webpack/lib/MultiEntryPlugin.js
generated
vendored
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
"use strict";
|
||||
|
||||
const MultiEntryDependency = require("./dependencies/MultiEntryDependency");
|
||||
const SingleEntryDependency = require("./dependencies/SingleEntryDependency");
|
||||
const MultiModuleFactory = require("./MultiModuleFactory");
|
||||
|
||||
/** @typedef {import("./Compiler")} Compiler */
|
||||
|
||||
class MultiEntryPlugin {
|
||||
/**
|
||||
* The MultiEntryPlugin is invoked whenever this.options.entry value is an array of paths
|
||||
* @param {string} context context path
|
||||
* @param {string[]} entries array of entry paths
|
||||
* @param {string} name entry key name
|
||||
*/
|
||||
constructor(context, entries, name) {
|
||||
this.context = context;
|
||||
this.entries = entries;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Compiler} compiler the compiler instance
|
||||
* @returns {void}
|
||||
*/
|
||||
apply(compiler) {
|
||||
compiler.hooks.compilation.tap(
|
||||
"MultiEntryPlugin",
|
||||
(compilation, { normalModuleFactory }) => {
|
||||
const multiModuleFactory = new MultiModuleFactory();
|
||||
|
||||
compilation.dependencyFactories.set(
|
||||
MultiEntryDependency,
|
||||
multiModuleFactory
|
||||
);
|
||||
compilation.dependencyFactories.set(
|
||||
SingleEntryDependency,
|
||||
normalModuleFactory
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
compiler.hooks.make.tapAsync(
|
||||
"MultiEntryPlugin",
|
||||
(compilation, callback) => {
|
||||
const { context, entries, name } = this;
|
||||
|
||||
const dep = MultiEntryPlugin.createDependency(entries, name);
|
||||
compilation.addEntry(context, dep, name, callback);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string[]} entries each entry path string
|
||||
* @param {string} name name of the entry
|
||||
* @returns {MultiEntryDependency} returns a constructed Dependency
|
||||
*/
|
||||
static createDependency(entries, name) {
|
||||
return new MultiEntryDependency(
|
||||
entries.map((e, idx) => {
|
||||
const dep = new SingleEntryDependency(e);
|
||||
// Because entrypoints are not dependencies found in an
|
||||
// existing module, we give it a synthetic id
|
||||
dep.loc = {
|
||||
name,
|
||||
index: idx
|
||||
};
|
||||
return dep;
|
||||
}),
|
||||
name
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = MultiEntryPlugin;
|
||||
87
node_modules/webpack/lib/MultiModule.js
generated
vendored
Normal file
87
node_modules/webpack/lib/MultiModule.js
generated
vendored
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
"use strict";
|
||||
|
||||
const Module = require("./Module");
|
||||
const Template = require("./Template");
|
||||
const { RawSource } = require("webpack-sources");
|
||||
|
||||
/** @typedef {import("./util/createHash").Hash} Hash */
|
||||
|
||||
class MultiModule extends Module {
|
||||
constructor(context, dependencies, name) {
|
||||
super("javascript/dynamic", context);
|
||||
|
||||
// Info from Factory
|
||||
this.dependencies = dependencies;
|
||||
this.name = name;
|
||||
this._identifier = `multi ${this.dependencies
|
||||
.map(d => d.request)
|
||||
.join(" ")}`;
|
||||
}
|
||||
|
||||
identifier() {
|
||||
return this._identifier;
|
||||
}
|
||||
|
||||
readableIdentifier(requestShortener) {
|
||||
return `multi ${this.dependencies
|
||||
.map(d => requestShortener.shorten(d.request))
|
||||
.join(" ")}`;
|
||||
}
|
||||
|
||||
build(options, compilation, resolver, fs, callback) {
|
||||
this.built = true;
|
||||
this.buildMeta = {};
|
||||
this.buildInfo = {};
|
||||
return callback();
|
||||
}
|
||||
|
||||
needRebuild() {
|
||||
return false;
|
||||
}
|
||||
|
||||
size() {
|
||||
return 16 + this.dependencies.length * 12;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Hash} hash the hash used to track dependencies
|
||||
* @returns {void}
|
||||
*/
|
||||
updateHash(hash) {
|
||||
hash.update("multi module");
|
||||
hash.update(this.name || "");
|
||||
super.updateHash(hash);
|
||||
}
|
||||
|
||||
source(dependencyTemplates, runtimeTemplate) {
|
||||
const str = [];
|
||||
let idx = 0;
|
||||
for (const dep of this.dependencies) {
|
||||
if (dep.module) {
|
||||
if (idx === this.dependencies.length - 1) {
|
||||
str.push("module.exports = ");
|
||||
}
|
||||
str.push("__webpack_require__(");
|
||||
if (runtimeTemplate.outputOptions.pathinfo) {
|
||||
str.push(Template.toComment(dep.request));
|
||||
}
|
||||
str.push(`${JSON.stringify(dep.module.id)}`);
|
||||
str.push(")");
|
||||
} else {
|
||||
const content = require("./dependencies/WebpackMissingModule").module(
|
||||
dep.request
|
||||
);
|
||||
str.push(content);
|
||||
}
|
||||
str.push(";\n");
|
||||
idx++;
|
||||
}
|
||||
return new RawSource(str.join(""));
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = MultiModule;
|
||||
23
node_modules/webpack/lib/MultiModuleFactory.js
generated
vendored
Normal file
23
node_modules/webpack/lib/MultiModuleFactory.js
generated
vendored
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
"use strict";
|
||||
|
||||
const { Tapable } = require("tapable");
|
||||
const MultiModule = require("./MultiModule");
|
||||
|
||||
module.exports = class MultiModuleFactory extends Tapable {
|
||||
constructor() {
|
||||
super();
|
||||
this.hooks = {};
|
||||
}
|
||||
|
||||
create(data, callback) {
|
||||
const dependency = data.dependencies[0];
|
||||
callback(
|
||||
null,
|
||||
new MultiModule(data.context, dependency.dependencies, dependency.name)
|
||||
);
|
||||
}
|
||||
};
|
||||
92
node_modules/webpack/lib/MultiStats.js
generated
vendored
Normal file
92
node_modules/webpack/lib/MultiStats.js
generated
vendored
Normal file
|
|
@ -0,0 +1,92 @@
|
|||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
"use strict";
|
||||
|
||||
const Stats = require("./Stats");
|
||||
|
||||
const optionOrFallback = (optionValue, fallbackValue) =>
|
||||
optionValue !== undefined ? optionValue : fallbackValue;
|
||||
|
||||
class MultiStats {
|
||||
constructor(stats) {
|
||||
this.stats = stats;
|
||||
this.hash = stats.map(stat => stat.hash).join("");
|
||||
}
|
||||
|
||||
hasErrors() {
|
||||
return this.stats
|
||||
.map(stat => stat.hasErrors())
|
||||
.reduce((a, b) => a || b, false);
|
||||
}
|
||||
|
||||
hasWarnings() {
|
||||
return this.stats
|
||||
.map(stat => stat.hasWarnings())
|
||||
.reduce((a, b) => a || b, false);
|
||||
}
|
||||
|
||||
toJson(options, forToString) {
|
||||
if (typeof options === "boolean" || typeof options === "string") {
|
||||
options = Stats.presetToOptions(options);
|
||||
} else if (!options) {
|
||||
options = {};
|
||||
}
|
||||
const jsons = this.stats.map((stat, idx) => {
|
||||
const childOptions = Stats.getChildOptions(options, idx);
|
||||
const obj = stat.toJson(childOptions, forToString);
|
||||
obj.name = stat.compilation && stat.compilation.name;
|
||||
return obj;
|
||||
});
|
||||
const showVersion =
|
||||
options.version === undefined
|
||||
? jsons.every(j => j.version)
|
||||
: options.version !== false;
|
||||
const showHash =
|
||||
options.hash === undefined
|
||||
? jsons.every(j => j.hash)
|
||||
: options.hash !== false;
|
||||
if (showVersion) {
|
||||
for (const j of jsons) {
|
||||
delete j.version;
|
||||
}
|
||||
}
|
||||
const obj = {
|
||||
errors: jsons.reduce((arr, j) => {
|
||||
return arr.concat(
|
||||
j.errors.map(msg => {
|
||||
return `(${j.name}) ${msg}`;
|
||||
})
|
||||
);
|
||||
}, []),
|
||||
warnings: jsons.reduce((arr, j) => {
|
||||
return arr.concat(
|
||||
j.warnings.map(msg => {
|
||||
return `(${j.name}) ${msg}`;
|
||||
})
|
||||
);
|
||||
}, [])
|
||||
};
|
||||
if (showVersion) obj.version = require("../package.json").version;
|
||||
if (showHash) obj.hash = this.hash;
|
||||
if (options.children !== false) obj.children = jsons;
|
||||
return obj;
|
||||
}
|
||||
|
||||
toString(options) {
|
||||
if (typeof options === "boolean" || typeof options === "string") {
|
||||
options = Stats.presetToOptions(options);
|
||||
} else if (!options) {
|
||||
options = {};
|
||||
}
|
||||
|
||||
const useColors = optionOrFallback(options.colors, false);
|
||||
|
||||
const obj = this.toJson(options, true);
|
||||
|
||||
return Stats.jsonToString(obj, useColors);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = MultiStats;
|
||||
50
node_modules/webpack/lib/MultiWatching.js
generated
vendored
Normal file
50
node_modules/webpack/lib/MultiWatching.js
generated
vendored
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
"use strict";
|
||||
|
||||
const asyncLib = require("neo-async");
|
||||
|
||||
class MultiWatching {
|
||||
constructor(watchings, compiler) {
|
||||
this.watchings = watchings;
|
||||
this.compiler = compiler;
|
||||
}
|
||||
|
||||
invalidate() {
|
||||
for (const watching of this.watchings) {
|
||||
watching.invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
suspend() {
|
||||
for (const watching of this.watchings) {
|
||||
watching.suspend();
|
||||
}
|
||||
}
|
||||
|
||||
resume() {
|
||||
for (const watching of this.watchings) {
|
||||
watching.resume();
|
||||
}
|
||||
}
|
||||
|
||||
close(callback) {
|
||||
asyncLib.forEach(
|
||||
this.watchings,
|
||||
(watching, finishedCallback) => {
|
||||
watching.close(finishedCallback);
|
||||
},
|
||||
err => {
|
||||
this.compiler.hooks.watchClose.call();
|
||||
if (typeof callback === "function") {
|
||||
this.compiler.running = false;
|
||||
callback(err);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = MultiWatching;
|
||||
29
node_modules/webpack/lib/NamedChunksPlugin.js
generated
vendored
Normal file
29
node_modules/webpack/lib/NamedChunksPlugin.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";
|
||||
|
||||
class NamedChunksPlugin {
|
||||
static defaultNameResolver(chunk) {
|
||||
return chunk.name || null;
|
||||
}
|
||||
|
||||
constructor(nameResolver) {
|
||||
this.nameResolver = nameResolver || NamedChunksPlugin.defaultNameResolver;
|
||||
}
|
||||
|
||||
apply(compiler) {
|
||||
compiler.hooks.compilation.tap("NamedChunksPlugin", compilation => {
|
||||
compilation.hooks.beforeChunkIds.tap("NamedChunksPlugin", chunks => {
|
||||
for (const chunk of chunks) {
|
||||
if (chunk.id === null) {
|
||||
chunk.id = this.nameResolver(chunk);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = NamedChunksPlugin;
|
||||
58
node_modules/webpack/lib/NamedModulesPlugin.js
generated
vendored
Normal file
58
node_modules/webpack/lib/NamedModulesPlugin.js
generated
vendored
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
"use strict";
|
||||
|
||||
const createHash = require("./util/createHash");
|
||||
const RequestShortener = require("./RequestShortener");
|
||||
|
||||
const getHash = str => {
|
||||
const hash = createHash("md4");
|
||||
hash.update(str);
|
||||
const digest = /** @type {string} */ (hash.digest("hex"));
|
||||
return digest.substr(0, 4);
|
||||
};
|
||||
|
||||
class NamedModulesPlugin {
|
||||
constructor(options) {
|
||||
this.options = options || {};
|
||||
}
|
||||
|
||||
apply(compiler) {
|
||||
compiler.hooks.compilation.tap("NamedModulesPlugin", compilation => {
|
||||
compilation.hooks.beforeModuleIds.tap("NamedModulesPlugin", modules => {
|
||||
const namedModules = new Map();
|
||||
const context = this.options.context || compiler.options.context;
|
||||
|
||||
for (const module of modules) {
|
||||
if (module.id === null && module.libIdent) {
|
||||
module.id = module.libIdent({ context });
|
||||
}
|
||||
|
||||
if (module.id !== null) {
|
||||
const namedModule = namedModules.get(module.id);
|
||||
if (namedModule !== undefined) {
|
||||
namedModule.push(module);
|
||||
} else {
|
||||
namedModules.set(module.id, [module]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (const namedModule of namedModules.values()) {
|
||||
if (namedModule.length > 1) {
|
||||
for (const module of namedModule) {
|
||||
const requestShortener = new RequestShortener(context);
|
||||
module.id = `${module.id}?${getHash(
|
||||
requestShortener.shorten(module.identifier())
|
||||
)}`;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = NamedModulesPlugin;
|
||||
20
node_modules/webpack/lib/NoEmitOnErrorsPlugin.js
generated
vendored
Normal file
20
node_modules/webpack/lib/NoEmitOnErrorsPlugin.js
generated
vendored
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
"use strict";
|
||||
|
||||
class NoEmitOnErrorsPlugin {
|
||||
apply(compiler) {
|
||||
compiler.hooks.shouldEmit.tap("NoEmitOnErrorsPlugin", compilation => {
|
||||
if (compilation.getStats().hasErrors()) return false;
|
||||
});
|
||||
compiler.hooks.compilation.tap("NoEmitOnErrorsPlugin", compilation => {
|
||||
compilation.hooks.shouldRecord.tap("NoEmitOnErrorsPlugin", () => {
|
||||
if (compilation.getStats().hasErrors()) return false;
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = NoEmitOnErrorsPlugin;
|
||||
23
node_modules/webpack/lib/NoModeWarning.js
generated
vendored
Normal file
23
node_modules/webpack/lib/NoModeWarning.js
generated
vendored
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
"use strict";
|
||||
|
||||
const WebpackError = require("./WebpackError");
|
||||
|
||||
module.exports = class NoModeWarning extends WebpackError {
|
||||
constructor(modules) {
|
||||
super();
|
||||
|
||||
this.name = "NoModeWarning";
|
||||
this.message =
|
||||
"configuration\n" +
|
||||
"The 'mode' option has not been set, webpack will fallback to 'production' for this value. " +
|
||||
"Set 'mode' option to 'development' or 'production' to enable defaults for each environment.\n" +
|
||||
"You can also set it to 'none' to disable any default behavior. " +
|
||||
"Learn more: https://webpack.js.org/configuration/mode/";
|
||||
|
||||
Error.captureStackTrace(this, this.constructor);
|
||||
}
|
||||
};
|
||||
118
node_modules/webpack/lib/NodeStuffPlugin.js
generated
vendored
Normal file
118
node_modules/webpack/lib/NodeStuffPlugin.js
generated
vendored
Normal file
|
|
@ -0,0 +1,118 @@
|
|||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
"use strict";
|
||||
|
||||
const path = require("path");
|
||||
const ParserHelpers = require("./ParserHelpers");
|
||||
const ConstDependency = require("./dependencies/ConstDependency");
|
||||
|
||||
const NullFactory = require("./NullFactory");
|
||||
|
||||
class NodeStuffPlugin {
|
||||
constructor(options) {
|
||||
this.options = options;
|
||||
}
|
||||
|
||||
apply(compiler) {
|
||||
const options = this.options;
|
||||
compiler.hooks.compilation.tap(
|
||||
"NodeStuffPlugin",
|
||||
(compilation, { normalModuleFactory }) => {
|
||||
compilation.dependencyFactories.set(ConstDependency, new NullFactory());
|
||||
compilation.dependencyTemplates.set(
|
||||
ConstDependency,
|
||||
new ConstDependency.Template()
|
||||
);
|
||||
|
||||
const handler = (parser, parserOptions) => {
|
||||
if (parserOptions.node === false) return;
|
||||
|
||||
let localOptions = options;
|
||||
if (parserOptions.node) {
|
||||
localOptions = Object.assign({}, localOptions, parserOptions.node);
|
||||
}
|
||||
|
||||
const setConstant = (expressionName, value) => {
|
||||
parser.hooks.expression
|
||||
.for(expressionName)
|
||||
.tap("NodeStuffPlugin", () => {
|
||||
parser.state.current.addVariable(
|
||||
expressionName,
|
||||
JSON.stringify(value)
|
||||
);
|
||||
return true;
|
||||
});
|
||||
};
|
||||
|
||||
const setModuleConstant = (expressionName, fn) => {
|
||||
parser.hooks.expression
|
||||
.for(expressionName)
|
||||
.tap("NodeStuffPlugin", () => {
|
||||
parser.state.current.addVariable(
|
||||
expressionName,
|
||||
JSON.stringify(fn(parser.state.module))
|
||||
);
|
||||
return true;
|
||||
});
|
||||
};
|
||||
const context = compiler.context;
|
||||
if (localOptions.__filename) {
|
||||
if (localOptions.__filename === "mock") {
|
||||
setConstant("__filename", "/index.js");
|
||||
} else {
|
||||
setModuleConstant("__filename", module =>
|
||||
path.relative(context, module.resource)
|
||||
);
|
||||
}
|
||||
parser.hooks.evaluateIdentifier
|
||||
.for("__filename")
|
||||
.tap("NodeStuffPlugin", expr => {
|
||||
if (!parser.state.module) return;
|
||||
const resource = parser.state.module.resource;
|
||||
const i = resource.indexOf("?");
|
||||
return ParserHelpers.evaluateToString(
|
||||
i < 0 ? resource : resource.substr(0, i)
|
||||
)(expr);
|
||||
});
|
||||
}
|
||||
if (localOptions.__dirname) {
|
||||
if (localOptions.__dirname === "mock") {
|
||||
setConstant("__dirname", "/");
|
||||
} else {
|
||||
setModuleConstant("__dirname", module =>
|
||||
path.relative(context, module.context)
|
||||
);
|
||||
}
|
||||
parser.hooks.evaluateIdentifier
|
||||
.for("__dirname")
|
||||
.tap("NodeStuffPlugin", expr => {
|
||||
if (!parser.state.module) return;
|
||||
return ParserHelpers.evaluateToString(
|
||||
parser.state.module.context
|
||||
)(expr);
|
||||
});
|
||||
}
|
||||
parser.hooks.expression
|
||||
.for("require.extensions")
|
||||
.tap(
|
||||
"NodeStuffPlugin",
|
||||
ParserHelpers.expressionIsUnsupported(
|
||||
parser,
|
||||
"require.extensions is not supported by webpack. Use a loader instead."
|
||||
)
|
||||
);
|
||||
};
|
||||
|
||||
normalModuleFactory.hooks.parser
|
||||
.for("javascript/auto")
|
||||
.tap("NodeStuffPlugin", handler);
|
||||
normalModuleFactory.hooks.parser
|
||||
.for("javascript/dynamic")
|
||||
.tap("NodeStuffPlugin", handler);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
module.exports = NodeStuffPlugin;
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue