mirror of https://github.com/webpack/webpack.git
Prettify source code
This commit is contained in:
parent
093d93fcb8
commit
b25ff237bb
|
@ -206,8 +206,8 @@ const tests = {
|
||||||
const suite = new Benchmark.Suite();
|
const suite = new Benchmark.Suite();
|
||||||
|
|
||||||
Object.keys(tests)
|
Object.keys(tests)
|
||||||
.filter(
|
.filter(name =>
|
||||||
name => (process.argv.length > 2 ? name.includes(process.argv[2]) : true)
|
process.argv.length > 2 ? name.includes(process.argv[2]) : true
|
||||||
)
|
)
|
||||||
.forEach(name => {
|
.forEach(name => {
|
||||||
const test = tests[name];
|
const test = tests[name];
|
||||||
|
|
|
@ -234,8 +234,8 @@ interface RuleSetConditionsRecursive
|
||||||
extends Array<import("./declarations/WebpackOptions").RuleSetCondition> {}
|
extends Array<import("./declarations/WebpackOptions").RuleSetCondition> {}
|
||||||
interface RuleSetConditionsAbsoluteRecursive
|
interface RuleSetConditionsAbsoluteRecursive
|
||||||
extends Array<
|
extends Array<
|
||||||
import("./declarations/WebpackOptions").RuleSetConditionAbsolute
|
import("./declarations/WebpackOptions").RuleSetConditionAbsolute
|
||||||
> {}
|
> {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Global variable declarations
|
* Global variable declarations
|
||||||
|
|
|
@ -15,7 +15,7 @@ export type Entry = EntryDynamic | EntryStatic;
|
||||||
* This interface was referenced by `WebpackOptions`'s JSON-Schema
|
* This interface was referenced by `WebpackOptions`'s JSON-Schema
|
||||||
* via the `definition` "EntryDynamic".
|
* via the `definition` "EntryDynamic".
|
||||||
*/
|
*/
|
||||||
export type EntryDynamic = (() => EntryStatic | Promise<EntryStatic>);
|
export type EntryDynamic = () => EntryStatic | Promise<EntryStatic>;
|
||||||
/**
|
/**
|
||||||
* This interface was referenced by `WebpackOptions`'s JSON-Schema
|
* This interface was referenced by `WebpackOptions`'s JSON-Schema
|
||||||
* via the `definition` "EntryStatic".
|
* via the `definition` "EntryStatic".
|
||||||
|
|
|
@ -11,15 +11,13 @@ export type BannerPluginArgument =
|
||||||
/**
|
/**
|
||||||
* The banner as function, it will be wrapped in a comment
|
* The banner as function, it will be wrapped in a comment
|
||||||
*/
|
*/
|
||||||
export type BannerFunction = (
|
export type BannerFunction = (data: {
|
||||||
data: {
|
hash: string;
|
||||||
hash: string;
|
chunk: import("../../lib/Chunk");
|
||||||
chunk: import("../../lib/Chunk");
|
filename: string;
|
||||||
filename: string;
|
basename: string;
|
||||||
basename: string;
|
query: string;
|
||||||
query: string;
|
}) => string;
|
||||||
}
|
|
||||||
) => string;
|
|
||||||
export type Rules = Rule[] | Rule;
|
export type Rules = Rule[] | Rule;
|
||||||
export type Rule = RegExp | string;
|
export type Rule = RegExp | string;
|
||||||
|
|
||||||
|
|
|
@ -19,9 +19,9 @@ export type IgnorePluginOptions =
|
||||||
/**
|
/**
|
||||||
* A filter function for context
|
* A filter function for context
|
||||||
*/
|
*/
|
||||||
checkContext?: ((context: string) => boolean);
|
checkContext?: (context: string) => boolean;
|
||||||
/**
|
/**
|
||||||
* A filter function for resource and context
|
* A filter function for resource and context
|
||||||
*/
|
*/
|
||||||
checkResource?: ((resource: string, context: string) => boolean);
|
checkResource?: (resource: string, context: string) => boolean;
|
||||||
};
|
};
|
||||||
|
|
|
@ -8,11 +8,11 @@ export type ProgressPluginArgument = ProgressPluginOptions | HandlerFunction;
|
||||||
/**
|
/**
|
||||||
* Function that executes for every progress step
|
* Function that executes for every progress step
|
||||||
*/
|
*/
|
||||||
export type HandlerFunction = ((
|
export type HandlerFunction = (
|
||||||
percentage: number,
|
percentage: number,
|
||||||
msg: string,
|
msg: string,
|
||||||
...args: string[]
|
...args: string[]
|
||||||
) => void);
|
) => void;
|
||||||
|
|
||||||
export interface ProgressPluginOptions {
|
export interface ProgressPluginOptions {
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -40,8 +40,8 @@ class AmdMainTemplatePlugin {
|
||||||
const onRenderWithEntry = (source, chunk, hash) => {
|
const onRenderWithEntry = (source, chunk, hash) => {
|
||||||
const externals = chunk.getModules().filter(m => m.external);
|
const externals = chunk.getModules().filter(m => m.external);
|
||||||
const externalsDepsArray = JSON.stringify(
|
const externalsDepsArray = JSON.stringify(
|
||||||
externals.map(
|
externals.map(m =>
|
||||||
m => (typeof m.request === "object" ? m.request.amd : m.request)
|
typeof m.request === "object" ? m.request.amd : m.request
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
const externalsArguments = externals
|
const externalsArguments = externals
|
||||||
|
|
|
@ -12,9 +12,8 @@ const stringifySafe = data => {
|
||||||
return undefined; // Invalid JSON
|
return undefined; // Invalid JSON
|
||||||
}
|
}
|
||||||
|
|
||||||
return stringified.replace(
|
return stringified.replace(/\u2028|\u2029/g, str =>
|
||||||
/\u2028|\u2029/g,
|
str === "\u2029" ? "\\u2029" : "\\u2028"
|
||||||
str => (str === "\u2029" ? "\\u2029" : "\\u2028")
|
|
||||||
); // invalid in JavaScript but valid JSON
|
); // invalid in JavaScript but valid JSON
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1335,8 +1335,8 @@ class Parser extends Tapable {
|
||||||
statement.kind === "const"
|
statement.kind === "const"
|
||||||
? this.hooks.varDeclarationConst
|
? this.hooks.varDeclarationConst
|
||||||
: statement.kind === "let"
|
: statement.kind === "let"
|
||||||
? this.hooks.varDeclarationLet
|
? this.hooks.varDeclarationLet
|
||||||
: this.hooks.varDeclarationVar;
|
: this.hooks.varDeclarationVar;
|
||||||
for (const declarator of statement.declarations) {
|
for (const declarator of statement.declarations) {
|
||||||
switch (declarator.type) {
|
switch (declarator.type) {
|
||||||
case "VariableDeclarator": {
|
case "VariableDeclarator": {
|
||||||
|
|
|
@ -288,8 +288,8 @@ class Stats {
|
||||||
e.chunk.hasRuntime()
|
e.chunk.hasRuntime()
|
||||||
? " [entry]"
|
? " [entry]"
|
||||||
: e.chunk.canBeInitial()
|
: e.chunk.canBeInitial()
|
||||||
? " [initial]"
|
? " [initial]"
|
||||||
: ""
|
: ""
|
||||||
}\n`;
|
}\n`;
|
||||||
}
|
}
|
||||||
if (e.file) {
|
if (e.file) {
|
||||||
|
|
|
@ -236,12 +236,12 @@ class UmdMainTemplatePlugin {
|
||||||
amdFactory +
|
amdFactory +
|
||||||
");\n"
|
");\n"
|
||||||
: this.names.amd && this.namedDefine === true
|
: this.names.amd && this.namedDefine === true
|
||||||
? " define(" +
|
? " define(" +
|
||||||
libraryName(this.names.amd) +
|
libraryName(this.names.amd) +
|
||||||
", [], " +
|
", [], " +
|
||||||
amdFactory +
|
amdFactory +
|
||||||
");\n"
|
");\n"
|
||||||
: " define([], " + amdFactory + ");\n") +
|
: " define([], " + amdFactory + ");\n") +
|
||||||
(this.names.root || this.names.commonjs
|
(this.names.root || this.names.commonjs
|
||||||
? getAuxilaryComment("commonjs") +
|
? getAuxilaryComment("commonjs") +
|
||||||
" else if(typeof exports === 'object')\n" +
|
" else if(typeof exports === 'object')\n" +
|
||||||
|
|
|
@ -17,8 +17,8 @@ class IgnoringWatchFileSystem {
|
||||||
|
|
||||||
watch(files, dirs, missing, startTime, options, callback, callbackUndelayed) {
|
watch(files, dirs, missing, startTime, options, callback, callbackUndelayed) {
|
||||||
const ignored = path =>
|
const ignored = path =>
|
||||||
this.paths.some(
|
this.paths.some(p =>
|
||||||
p => (p instanceof RegExp ? p.test(path) : path.indexOf(p) === 0)
|
p instanceof RegExp ? p.test(path) : path.indexOf(p) === 0
|
||||||
);
|
);
|
||||||
|
|
||||||
const notIgnored = path => !ignored(path);
|
const notIgnored = path => !ignored(path);
|
||||||
|
|
|
@ -260,10 +260,10 @@ class WebpackOptionsApply extends OptionsApply {
|
||||||
"MappingURL=[url]\n//# source" +
|
"MappingURL=[url]\n//# source" +
|
||||||
"MappingURL=[url]\n*/"
|
"MappingURL=[url]\n*/"
|
||||||
: legacy
|
: legacy
|
||||||
? "\n/*\n//@ source" + "MappingURL=[url]\n*/"
|
? "\n/*\n//@ source" + "MappingURL=[url]\n*/"
|
||||||
: modern
|
: modern
|
||||||
? "\n//# source" + "MappingURL=[url]"
|
? "\n//# source" + "MappingURL=[url]"
|
||||||
: null;
|
: null;
|
||||||
const Plugin = evalWrapped
|
const Plugin = evalWrapped
|
||||||
? EvalSourceMapDevToolPlugin
|
? EvalSourceMapDevToolPlugin
|
||||||
: SourceMapDevToolPlugin;
|
: SourceMapDevToolPlugin;
|
||||||
|
@ -286,10 +286,10 @@ class WebpackOptionsApply extends OptionsApply {
|
||||||
legacy && modern
|
legacy && modern
|
||||||
? "\n//@ sourceURL=[url]\n//# sourceURL=[url]"
|
? "\n//@ sourceURL=[url]\n//# sourceURL=[url]"
|
||||||
: legacy
|
: legacy
|
||||||
? "\n//@ sourceURL=[url]"
|
? "\n//@ sourceURL=[url]"
|
||||||
: modern
|
: modern
|
||||||
? "\n//# sourceURL=[url]"
|
? "\n//# sourceURL=[url]"
|
||||||
: null;
|
: null;
|
||||||
new EvalDevToolModulePlugin({
|
new EvalDevToolModulePlugin({
|
||||||
sourceUrlComment: comment,
|
sourceUrlComment: comment,
|
||||||
moduleFilenameTemplate: options.output.devtoolModuleFilenameTemplate,
|
moduleFilenameTemplate: options.output.devtoolModuleFilenameTemplate,
|
||||||
|
|
|
@ -33,10 +33,8 @@ class WebpackOptionsDefaulter extends OptionsDefaulter {
|
||||||
|
|
||||||
this.set("entry", "./src");
|
this.set("entry", "./src");
|
||||||
|
|
||||||
this.set(
|
this.set("devtool", "make", options =>
|
||||||
"devtool",
|
options.mode === "development" ? "eval" : false
|
||||||
"make",
|
|
||||||
options => (options.mode === "development" ? "eval" : false)
|
|
||||||
);
|
);
|
||||||
this.set("cache", "make", options => options.mode === "development");
|
this.set("cache", "make", options => options.mode === "development");
|
||||||
|
|
||||||
|
@ -193,10 +191,8 @@ class WebpackOptionsDefaulter extends OptionsDefaulter {
|
||||||
});
|
});
|
||||||
this.set("performance.maxAssetSize", 250000);
|
this.set("performance.maxAssetSize", 250000);
|
||||||
this.set("performance.maxEntrypointSize", 250000);
|
this.set("performance.maxEntrypointSize", 250000);
|
||||||
this.set(
|
this.set("performance.hints", "make", options =>
|
||||||
"performance.hints",
|
isProductionLikeMode(options) ? "warning" : false
|
||||||
"make",
|
|
||||||
options => (isProductionLikeMode(options) ? "warning" : false)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
this.set("optimization", "call", value => Object.assign({}, value));
|
this.set("optimization", "call", value => Object.assign({}, value));
|
||||||
|
|
|
@ -123,7 +123,7 @@ class SideEffectsFlagPlugin {
|
||||||
dep,
|
dep,
|
||||||
reason.explanation
|
reason.explanation
|
||||||
? reason.explanation +
|
? reason.explanation +
|
||||||
" (skipped side-effect-free modules)"
|
" (skipped side-effect-free modules)"
|
||||||
: "(skipped side-effect-free modules)"
|
: "(skipped side-effect-free modules)"
|
||||||
);
|
);
|
||||||
// removing the currect reason, by not adding it to the newReasons array
|
// removing the currect reason, by not adding it to the newReasons array
|
||||||
|
|
|
@ -534,8 +534,8 @@ module.exports = class SplitChunksPlugin {
|
||||||
cacheGroupSource.minSize !== undefined
|
cacheGroupSource.minSize !== undefined
|
||||||
? cacheGroupSource.minSize
|
? cacheGroupSource.minSize
|
||||||
: cacheGroupSource.enforce
|
: cacheGroupSource.enforce
|
||||||
? 0
|
? 0
|
||||||
: this.options.minSize,
|
: this.options.minSize,
|
||||||
minSizeForMaxSize:
|
minSizeForMaxSize:
|
||||||
cacheGroupSource.minSize !== undefined
|
cacheGroupSource.minSize !== undefined
|
||||||
? cacheGroupSource.minSize
|
? cacheGroupSource.minSize
|
||||||
|
@ -544,26 +544,26 @@ module.exports = class SplitChunksPlugin {
|
||||||
cacheGroupSource.maxSize !== undefined
|
cacheGroupSource.maxSize !== undefined
|
||||||
? cacheGroupSource.maxSize
|
? cacheGroupSource.maxSize
|
||||||
: cacheGroupSource.enforce
|
: cacheGroupSource.enforce
|
||||||
? 0
|
? 0
|
||||||
: this.options.maxSize,
|
: this.options.maxSize,
|
||||||
minChunks:
|
minChunks:
|
||||||
cacheGroupSource.minChunks !== undefined
|
cacheGroupSource.minChunks !== undefined
|
||||||
? cacheGroupSource.minChunks
|
? cacheGroupSource.minChunks
|
||||||
: cacheGroupSource.enforce
|
: cacheGroupSource.enforce
|
||||||
? 1
|
? 1
|
||||||
: this.options.minChunks,
|
: this.options.minChunks,
|
||||||
maxAsyncRequests:
|
maxAsyncRequests:
|
||||||
cacheGroupSource.maxAsyncRequests !== undefined
|
cacheGroupSource.maxAsyncRequests !== undefined
|
||||||
? cacheGroupSource.maxAsyncRequests
|
? cacheGroupSource.maxAsyncRequests
|
||||||
: cacheGroupSource.enforce
|
: cacheGroupSource.enforce
|
||||||
? Infinity
|
? Infinity
|
||||||
: this.options.maxAsyncRequests,
|
: this.options.maxAsyncRequests,
|
||||||
maxInitialRequests:
|
maxInitialRequests:
|
||||||
cacheGroupSource.maxInitialRequests !== undefined
|
cacheGroupSource.maxInitialRequests !== undefined
|
||||||
? cacheGroupSource.maxInitialRequests
|
? cacheGroupSource.maxInitialRequests
|
||||||
: cacheGroupSource.enforce
|
: cacheGroupSource.enforce
|
||||||
? Infinity
|
? Infinity
|
||||||
: this.options.maxInitialRequests,
|
: this.options.maxInitialRequests,
|
||||||
getName:
|
getName:
|
||||||
cacheGroupSource.getName !== undefined
|
cacheGroupSource.getName !== undefined
|
||||||
? cacheGroupSource.getName
|
? cacheGroupSource.getName
|
||||||
|
@ -683,11 +683,11 @@ module.exports = class SplitChunksPlugin {
|
||||||
const maxRequests = chunk.isOnlyInitial()
|
const maxRequests = chunk.isOnlyInitial()
|
||||||
? item.cacheGroup.maxInitialRequests
|
? item.cacheGroup.maxInitialRequests
|
||||||
: chunk.canBeInitial()
|
: chunk.canBeInitial()
|
||||||
? Math.min(
|
? Math.min(
|
||||||
item.cacheGroup.maxInitialRequests,
|
item.cacheGroup.maxInitialRequests,
|
||||||
item.cacheGroup.maxAsyncRequests
|
item.cacheGroup.maxAsyncRequests
|
||||||
)
|
)
|
||||||
: item.cacheGroup.maxAsyncRequests;
|
: item.cacheGroup.maxAsyncRequests;
|
||||||
return (
|
return (
|
||||||
!isFinite(maxRequests) || getRequests(chunk) < maxRequests
|
!isFinite(maxRequests) || getRequests(chunk) < maxRequests
|
||||||
);
|
);
|
||||||
|
|
|
@ -96,12 +96,10 @@ class StackedSetMap {
|
||||||
|
|
||||||
asPairArray() {
|
asPairArray() {
|
||||||
this._compress();
|
this._compress();
|
||||||
return Array.from(
|
return Array.from(this.map.entries(), pair =>
|
||||||
this.map.entries(),
|
/** @type {[TODO, TODO]} */ (pair[1] === UNDEFINED_MARKER
|
||||||
pair =>
|
? [pair[0], undefined]
|
||||||
/** @type {[TODO, TODO]} */ (pair[1] === UNDEFINED_MARKER
|
: pair)
|
||||||
? [pair[0], undefined]
|
|
||||||
: pair)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -156,8 +156,8 @@ module.exports = ({ maxSize, minSize, items, getSize, getKey }) => {
|
||||||
// We hit an edgecase where the working set is already smaller than minSize
|
// We hit an edgecase where the working set is already smaller than minSize
|
||||||
// We merge it with the smallest result node to keep minSize intact
|
// We merge it with the smallest result node to keep minSize intact
|
||||||
if (result.length > 0) {
|
if (result.length > 0) {
|
||||||
const smallestGroup = result.reduce(
|
const smallestGroup = result.reduce((min, group) =>
|
||||||
(min, group) => (min.size > group.size ? group : min)
|
min.size > group.size ? group : min
|
||||||
);
|
);
|
||||||
for (const node of initialGroup.nodes) smallestGroup.nodes.push(node);
|
for (const node of initialGroup.nodes) smallestGroup.nodes.push(node);
|
||||||
smallestGroup.nodes.sort((a, b) => {
|
smallestGroup.nodes.sort((a, b) => {
|
||||||
|
|
|
@ -36,11 +36,10 @@ const normalizePathSeparator = p => p.replace(/\\/g, "/");
|
||||||
const _makePathsRelative = (context, identifier) => {
|
const _makePathsRelative = (context, identifier) => {
|
||||||
return identifier
|
return identifier
|
||||||
.split(/([|! ])/)
|
.split(/([|! ])/)
|
||||||
.map(
|
.map(str =>
|
||||||
str =>
|
looksLikeAbsolutePath(str)
|
||||||
looksLikeAbsolutePath(str)
|
? normalizePathSeparator(path.relative(context, str))
|
||||||
? normalizePathSeparator(path.relative(context, str))
|
: str
|
||||||
: str
|
|
||||||
)
|
)
|
||||||
.join("");
|
.join("");
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue