mirror of https://github.com/webpack/webpack.git
style: improve style of code
This commit is contained in:
parent
9e2ead389c
commit
9943f3506a
|
@ -246,9 +246,9 @@ module.exports = [
|
|||
string: true
|
||||
}
|
||||
],
|
||||
"arrow-body-style": ["error", "as-needed"],
|
||||
|
||||
// TODO Enable
|
||||
"arrow-body-style": "off",
|
||||
"no-sequences": "off",
|
||||
"prefer-spread": "off",
|
||||
"default-case": "off",
|
||||
|
|
|
@ -38,8 +38,7 @@ const {
|
|||
* @param {function(Error=): void} callback callback
|
||||
* @returns {function(Error=): void} callback
|
||||
*/
|
||||
const needCalls = (times, callback) => {
|
||||
return err => {
|
||||
const needCalls = (times, callback) => err => {
|
||||
if (--times === 0) {
|
||||
return callback(err);
|
||||
}
|
||||
|
@ -48,7 +47,6 @@ const needCalls = (times, callback) => {
|
|||
return callback(err);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
class Cache {
|
||||
constructor() {
|
||||
|
|
|
@ -60,12 +60,11 @@ class MultiItemCache {
|
|||
* @param {number} i index
|
||||
* @returns {Promise<T>} promise with the data
|
||||
*/
|
||||
const next = i => {
|
||||
return this._items[i].getPromise().then(result => {
|
||||
const next = i =>
|
||||
this._items[i].getPromise().then(result => {
|
||||
if (result !== undefined) return result;
|
||||
if (++i < this._items.length) return next(i);
|
||||
});
|
||||
};
|
||||
return next(0);
|
||||
}
|
||||
|
||||
|
|
|
@ -14,8 +14,8 @@ const WebpackError = require("./WebpackError");
|
|||
* @param {Module[]} modules the modules to be sorted
|
||||
* @returns {Module[]} sorted version of original modules
|
||||
*/
|
||||
const sortModules = modules => {
|
||||
return modules.sort((a, b) => {
|
||||
const sortModules = modules =>
|
||||
modules.sort((a, b) => {
|
||||
const aIdent = a.identifier();
|
||||
const bIdent = b.identifier();
|
||||
/* istanbul ignore next */
|
||||
|
@ -25,15 +25,14 @@ const sortModules = modules => {
|
|||
/* istanbul ignore next */
|
||||
return 0;
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {Module[]} modules each module from throw
|
||||
* @param {ModuleGraph} moduleGraph the module graph
|
||||
* @returns {string} each message from provided modules
|
||||
*/
|
||||
const createModulesListMessage = (modules, moduleGraph) => {
|
||||
return modules
|
||||
const createModulesListMessage = (modules, moduleGraph) =>
|
||||
modules
|
||||
.map(m => {
|
||||
let message = `* ${m.identifier()}`;
|
||||
const validReasons = Array.from(
|
||||
|
@ -49,7 +48,6 @@ const createModulesListMessage = (modules, moduleGraph) => {
|
|||
return message;
|
||||
})
|
||||
.join("\n");
|
||||
};
|
||||
|
||||
class CaseSensitiveModulesWarning extends WebpackError {
|
||||
/**
|
||||
|
|
|
@ -73,9 +73,7 @@ class ModuleHashInfo {
|
|||
* @param {SortableSet<T>} set the set
|
||||
* @returns {T[]} set as array
|
||||
*/
|
||||
const getArray = set => {
|
||||
return Array.from(set);
|
||||
};
|
||||
const getArray = set => Array.from(set);
|
||||
|
||||
/**
|
||||
* @param {SortableSet<Chunk>} chunks the chunks
|
||||
|
|
|
@ -369,9 +369,8 @@ const deprecatedNormalModuleLoaderHook = util.deprecate(
|
|||
* @param {Compilation} compilation compilation
|
||||
* @returns {NormalModuleCompilationHooks["loader"]} hooks
|
||||
*/
|
||||
compilation => {
|
||||
return require("./NormalModule").getCompilationHooks(compilation).loader;
|
||||
},
|
||||
compilation =>
|
||||
require("./NormalModule").getCompilationHooks(compilation).loader,
|
||||
"Compilation.hooks.normalModuleLoader was moved to NormalModule.getCompilationHooks(compilation).loader",
|
||||
"DEP_WEBPACK_COMPILATION_NORMAL_MODULE_LOADER_HOOK"
|
||||
);
|
||||
|
|
|
@ -22,9 +22,9 @@ class ContextExclusionPlugin {
|
|||
*/
|
||||
apply(compiler) {
|
||||
compiler.hooks.contextModuleFactory.tap("ContextExclusionPlugin", cmf => {
|
||||
cmf.hooks.contextModuleFiles.tap("ContextExclusionPlugin", files => {
|
||||
return files.filter(filePath => !this.negativeMatcher.test(filePath));
|
||||
});
|
||||
cmf.hooks.contextModuleFiles.tap("ContextExclusionPlugin", files =>
|
||||
files.filter(filePath => !this.negativeMatcher.test(filePath))
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -154,14 +154,15 @@ 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(
|
||||
const dependencies = Object.keys(map).map(
|
||||
key =>
|
||||
new ContextElementDependency(
|
||||
map[key] + options.resourceQuery + options.resourceFragment,
|
||||
key,
|
||||
options.category,
|
||||
options.referencedExports
|
||||
)
|
||||
);
|
||||
});
|
||||
callback(null, dependencies);
|
||||
});
|
||||
};
|
||||
|
|
|
@ -85,9 +85,9 @@ const memoize = require("./util/memoize");
|
|||
|
||||
const TRANSITIVE = Symbol("transitive");
|
||||
|
||||
const getIgnoredModule = memoize(() => {
|
||||
return new RawModule("/* (ignored) */", `ignored`, `(ignored)`);
|
||||
});
|
||||
const getIgnoredModule = memoize(
|
||||
() => new RawModule("/* (ignored) */", `ignored`, `(ignored)`)
|
||||
);
|
||||
|
||||
class Dependency {
|
||||
constructor() {
|
||||
|
|
|
@ -137,8 +137,8 @@ class EvalSourceMapDevToolPlugin {
|
|||
const module = compilation.findModule(source);
|
||||
return module || source;
|
||||
});
|
||||
let moduleFilenames = modules.map(module => {
|
||||
return ModuleFilenameHelpers.createFilename(
|
||||
let moduleFilenames = modules.map(module =>
|
||||
ModuleFilenameHelpers.createFilename(
|
||||
module,
|
||||
{
|
||||
moduleFilenameTemplate: this.moduleFilenameTemplate,
|
||||
|
@ -149,8 +149,8 @@ class EvalSourceMapDevToolPlugin {
|
|||
chunkGraph,
|
||||
hashFunction: compilation.outputOptions.hashFunction
|
||||
}
|
||||
)
|
||||
);
|
||||
});
|
||||
moduleFilenames = ModuleFilenameHelpers.replaceDuplicates(
|
||||
moduleFilenames,
|
||||
(filename, i, n) => {
|
||||
|
|
|
@ -415,11 +415,10 @@ const getSourceForScriptExternal = (urlAndGlobal, runtimeTemplate) => {
|
|||
* @param {RuntimeTemplate} runtimeTemplate the runtime template
|
||||
* @returns {string} the generated source
|
||||
*/
|
||||
const checkExternalVariable = (variableName, request, runtimeTemplate) => {
|
||||
return `if(typeof ${variableName} === 'undefined') { ${runtimeTemplate.throwMissingModuleErrorBlock(
|
||||
const checkExternalVariable = (variableName, request, runtimeTemplate) =>
|
||||
`if(typeof ${variableName} === 'undefined') { ${runtimeTemplate.throwMissingModuleErrorBlock(
|
||||
{ request }
|
||||
)} }\n`;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {string|number} id the module id
|
||||
|
|
|
@ -1444,9 +1444,8 @@ class FileSystemInfo {
|
|||
* @param {string} expected expected result
|
||||
* @returns {string} expected result
|
||||
*/
|
||||
const expectedToString = expected => {
|
||||
return expected ? ` (expected ${expected})` : "";
|
||||
};
|
||||
const expectedToString = expected =>
|
||||
expected ? ` (expected ${expected})` : "";
|
||||
const jobToString = job => {
|
||||
switch (job.type) {
|
||||
case RBDT_RESOLVE_CJS:
|
||||
|
|
|
@ -55,8 +55,7 @@ module.exports.makeWebpackError = makeWebpackError;
|
|||
* @param {string} hook name of hook
|
||||
* @returns {Callback<T>} generic callback
|
||||
*/
|
||||
const makeWebpackErrorCallback = (callback, hook) => {
|
||||
return (err, result) => {
|
||||
const makeWebpackErrorCallback = (callback, hook) => (err, result) => {
|
||||
if (err) {
|
||||
if (err instanceof WebpackError) {
|
||||
callback(err);
|
||||
|
@ -67,7 +66,6 @@ const makeWebpackErrorCallback = (callback, hook) => {
|
|||
}
|
||||
callback(null, result);
|
||||
};
|
||||
};
|
||||
|
||||
module.exports.makeWebpackErrorCallback = makeWebpackErrorCallback;
|
||||
|
||||
|
|
|
@ -243,14 +243,13 @@ class HotModuleReplacementPlugin {
|
|||
name: PLUGIN_NAME,
|
||||
before: "NodeStuffPlugin"
|
||||
},
|
||||
expr => {
|
||||
return evaluateToIdentifier(
|
||||
expr =>
|
||||
evaluateToIdentifier(
|
||||
"module.hot",
|
||||
"module",
|
||||
() => ["hot"],
|
||||
true
|
||||
)(expr);
|
||||
}
|
||||
)(expr)
|
||||
);
|
||||
parser.hooks.call
|
||||
.for("module.hot.accept")
|
||||
|
@ -276,14 +275,14 @@ class HotModuleReplacementPlugin {
|
|||
const applyImportMetaHot = parser => {
|
||||
parser.hooks.evaluateIdentifier
|
||||
.for("import.meta.webpackHot")
|
||||
.tap(PLUGIN_NAME, expr => {
|
||||
return evaluateToIdentifier(
|
||||
.tap(PLUGIN_NAME, expr =>
|
||||
evaluateToIdentifier(
|
||||
"import.meta.webpackHot",
|
||||
"import.meta",
|
||||
() => ["webpackHot"],
|
||||
true
|
||||
)(expr);
|
||||
});
|
||||
)(expr)
|
||||
);
|
||||
parser.hooks.call
|
||||
.for("import.meta.webpackHot.accept")
|
||||
.tap(
|
||||
|
|
|
@ -30,9 +30,9 @@ class IgnoreErrorModuleFactory extends ModuleFactory {
|
|||
* @returns {void}
|
||||
*/
|
||||
create(data, callback) {
|
||||
this.normalModuleFactory.create(data, (err, result) => {
|
||||
return callback(null, result);
|
||||
});
|
||||
this.normalModuleFactory.create(data, (err, result) =>
|
||||
callback(null, result)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -22,15 +22,11 @@ class IgnoreWarningsPlugin {
|
|||
*/
|
||||
apply(compiler) {
|
||||
compiler.hooks.compilation.tap("IgnoreWarningsPlugin", compilation => {
|
||||
compilation.hooks.processWarnings.tap(
|
||||
"IgnoreWarningsPlugin",
|
||||
warnings => {
|
||||
return warnings.filter(warning => {
|
||||
return !this._ignoreWarnings.some(ignore =>
|
||||
ignore(warning, compilation)
|
||||
);
|
||||
});
|
||||
}
|
||||
compilation.hooks.processWarnings.tap("IgnoreWarningsPlugin", warnings =>
|
||||
warnings.filter(
|
||||
warning =>
|
||||
!this._ignoreWarnings.some(ignore => ignore(warning, compilation))
|
||||
)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -165,9 +165,7 @@ class MainTemplate {
|
|||
"DEP_WEBPACK_MAIN_TEMPLATE_ASSET_PATH"
|
||||
),
|
||||
call: util.deprecate(
|
||||
(filename, options) => {
|
||||
return compilation.getAssetPath(filename, options);
|
||||
},
|
||||
(filename, options) => compilation.getAssetPath(filename, options),
|
||||
"MainTemplate.hooks.assetPath is deprecated (use Compilation.hooks.assetPath instead)",
|
||||
"DEP_WEBPACK_MAIN_TEMPLATE_ASSET_PATH"
|
||||
)
|
||||
|
@ -274,28 +272,20 @@ class MainTemplate {
|
|||
/**
|
||||
* @param {object} options get public path options
|
||||
* @returns {string} hook call
|
||||
*/ options => {
|
||||
return compilation.getAssetPath(
|
||||
compilation.outputOptions.publicPath,
|
||||
options
|
||||
);
|
||||
},
|
||||
*/ options =>
|
||||
compilation.getAssetPath(compilation.outputOptions.publicPath, options),
|
||||
"MainTemplate.getPublicPath is deprecated (use Compilation.getAssetPath(compilation.outputOptions.publicPath, options) instead)",
|
||||
"DEP_WEBPACK_MAIN_TEMPLATE_GET_PUBLIC_PATH"
|
||||
);
|
||||
|
||||
this.getAssetPath = util.deprecate(
|
||||
(path, options) => {
|
||||
return compilation.getAssetPath(path, options);
|
||||
},
|
||||
(path, options) => compilation.getAssetPath(path, options),
|
||||
"MainTemplate.getAssetPath is deprecated (use Compilation.getAssetPath instead)",
|
||||
"DEP_WEBPACK_MAIN_TEMPLATE_GET_ASSET_PATH"
|
||||
);
|
||||
|
||||
this.getAssetPathWithInfo = util.deprecate(
|
||||
(path, options) => {
|
||||
return compilation.getAssetPathWithInfo(path, options);
|
||||
},
|
||||
(path, options) => compilation.getAssetPathWithInfo(path, options),
|
||||
"MainTemplate.getAssetPathWithInfo is deprecated (use Compilation.getAssetPath instead)",
|
||||
"DEP_WEBPACK_MAIN_TEMPLATE_GET_ASSET_PATH_WITH_INFO"
|
||||
);
|
||||
|
|
|
@ -151,12 +151,11 @@ const deprecatedNeedRebuild = util.deprecate(
|
|||
* @param {NeedBuildContext} context context info
|
||||
* @returns {boolean} true, when rebuild is needed
|
||||
*/
|
||||
(module, context) => {
|
||||
return module.needRebuild(
|
||||
(module, context) =>
|
||||
module.needRebuild(
|
||||
context.fileSystemInfo.getDeprecatedFileTimestamps(),
|
||||
context.fileSystemInfo.getDeprecatedContextTimestamps()
|
||||
);
|
||||
},
|
||||
),
|
||||
"Module.needRebuild is deprecated in favor of Module.needBuild",
|
||||
"DEP_WEBPACK_MODULE_NEED_REBUILD"
|
||||
);
|
||||
|
|
|
@ -54,13 +54,11 @@ ModuleFilenameHelpers.REGEXP_NAMESPACE = /\[namespace\]/gi;
|
|||
* @param {string} token the token to search for
|
||||
* @returns {ReturnStringCallback} a function that returns the part of the string after the token
|
||||
*/
|
||||
const getAfter = (strFn, token) => {
|
||||
return () => {
|
||||
const getAfter = (strFn, token) => () => {
|
||||
const str = strFn();
|
||||
const idx = str.indexOf(token);
|
||||
return idx < 0 ? "" : str.slice(idx);
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns a function that returns the part of the string before the token
|
||||
|
@ -68,13 +66,11 @@ const getAfter = (strFn, token) => {
|
|||
* @param {string} token the token to search for
|
||||
* @returns {ReturnStringCallback} a function that returns the part of the string before the token
|
||||
*/
|
||||
const getBefore = (strFn, token) => {
|
||||
return () => {
|
||||
const getBefore = (strFn, token) => () => {
|
||||
const str = strFn();
|
||||
const idx = str.lastIndexOf(token);
|
||||
return idx < 0 ? "" : str.slice(0, idx);
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns a function that returns a hash of the string
|
||||
|
@ -82,14 +78,14 @@ const getBefore = (strFn, token) => {
|
|||
* @param {string | Hash=} hashFunction the hash function to use
|
||||
* @returns {ReturnStringCallback} a function that returns the hash of the string
|
||||
*/
|
||||
const getHash = (strFn, hashFunction = "md4") => {
|
||||
return () => {
|
||||
const getHash =
|
||||
(strFn, hashFunction = "md4") =>
|
||||
() => {
|
||||
const hash = createHash(hashFunction);
|
||||
hash.update(strFn());
|
||||
const digest = /** @type {string} */ (hash.digest("hex"));
|
||||
return digest.slice(0, 4);
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns a function that returns the string with the token replaced with the replacement
|
||||
|
|
|
@ -263,16 +263,11 @@ module.exports = class MultiCompiler {
|
|||
* @param {{source: Compiler, target: Compiler}} e2 edge 2
|
||||
* @returns {number} result
|
||||
*/
|
||||
const sortEdges = (e1, e2) => {
|
||||
return (
|
||||
const sortEdges = (e1, e2) =>
|
||||
/** @type {string} */
|
||||
(e1.source.name).localeCompare(
|
||||
/** @type {string} */ (e2.source.name)
|
||||
) ||
|
||||
(e1.source.name).localeCompare(/** @type {string} */ (e2.source.name)) ||
|
||||
/** @type {string} */
|
||||
(e1.target.name).localeCompare(/** @type {string} */ (e2.target.name))
|
||||
);
|
||||
};
|
||||
(e1.target.name).localeCompare(/** @type {string} */ (e2.target.name));
|
||||
for (const source of this.compilers) {
|
||||
const dependencies = this.dependencies.get(source);
|
||||
if (dependencies) {
|
||||
|
|
|
@ -103,14 +103,10 @@ class MultiStats {
|
|||
if (options.hash) {
|
||||
obj.hash = obj.children.map(j => j.hash).join("");
|
||||
}
|
||||
const mapError = (j, obj) => {
|
||||
return {
|
||||
const mapError = (j, obj) => ({
|
||||
...obj,
|
||||
compilerPath: obj.compilerPath
|
||||
? `${j.name}.${obj.compilerPath}`
|
||||
: j.name
|
||||
};
|
||||
};
|
||||
compilerPath: obj.compilerPath ? `${j.name}.${obj.compilerPath}` : j.name
|
||||
});
|
||||
if (options.errors) {
|
||||
obj.errors = [];
|
||||
for (const j of obj.children) {
|
||||
|
|
|
@ -554,8 +554,7 @@ class NormalModule extends Module {
|
|||
/**
|
||||
* @returns {ResolveContext} resolve context
|
||||
*/
|
||||
const getResolveContext = () => {
|
||||
return {
|
||||
const getResolveContext = () => ({
|
||||
fileDependencies: {
|
||||
add: d => /** @type {TODO} */ (loaderContext).addDependency(d)
|
||||
},
|
||||
|
@ -565,8 +564,7 @@ class NormalModule extends Module {
|
|||
missingDependencies: {
|
||||
add: d => /** @type {TODO} */ (loaderContext).addMissingDependency(d)
|
||||
}
|
||||
};
|
||||
};
|
||||
});
|
||||
const getAbsolutify = memoize(() =>
|
||||
absolutify.bindCache(compilation.compiler.root)
|
||||
);
|
||||
|
@ -585,28 +583,25 @@ class NormalModule extends Module {
|
|||
* @param {string} request request
|
||||
* @returns {string} result
|
||||
*/
|
||||
absolutify: (context, request) => {
|
||||
return context === this.context
|
||||
absolutify: (context, request) =>
|
||||
context === this.context
|
||||
? getAbsolutifyInContext()(request)
|
||||
: getAbsolutify()(context, request);
|
||||
},
|
||||
: getAbsolutify()(context, request),
|
||||
/**
|
||||
* @param {string} context context
|
||||
* @param {string} request request
|
||||
* @returns {string} result
|
||||
*/
|
||||
contextify: (context, request) => {
|
||||
return context === this.context
|
||||
contextify: (context, request) =>
|
||||
context === this.context
|
||||
? getContextifyInContext()(request)
|
||||
: getContextify()(context, request);
|
||||
},
|
||||
: getContextify()(context, request),
|
||||
/**
|
||||
* @param {(string | typeof import("./util/Hash"))=} type type
|
||||
* @returns {Hash} hash
|
||||
*/
|
||||
createHash: type => {
|
||||
return createHash(type || compilation.outputOptions.hashFunction);
|
||||
}
|
||||
createHash: type =>
|
||||
createHash(type || compilation.outputOptions.hashFunction)
|
||||
};
|
||||
/** @type {import("../declarations/LoaderContext").NormalModuleLoaderContext<T>} */
|
||||
const loaderContext = {
|
||||
|
@ -1345,9 +1340,7 @@ class NormalModule extends Module {
|
|||
}
|
||||
|
||||
/** @type {function(): Map<string, any>} */
|
||||
const getData = () => {
|
||||
return this._codeGeneratorData;
|
||||
};
|
||||
const getData = () => this._codeGeneratorData;
|
||||
|
||||
const sources = new Map();
|
||||
for (const type of sourceTypes || chunkGraph.getModuleSourceTypes(this)) {
|
||||
|
|
|
@ -145,8 +145,7 @@ const stringifyLoadersAndResource = (loaders, resource) => {
|
|||
* @param {(err?: null | Error) => void} callback callback
|
||||
* @returns {(err?: null | Error) => void} callback
|
||||
*/
|
||||
const needCalls = (times, callback) => {
|
||||
return err => {
|
||||
const needCalls = (times, callback) => err => {
|
||||
if (--times === 0) {
|
||||
return callback(err);
|
||||
}
|
||||
|
@ -155,7 +154,6 @@ const needCalls = (times, callback) => {
|
|||
return callback(err);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* @template T
|
||||
|
@ -199,9 +197,7 @@ const deprecationChangedHookMessage = (name, hook) => {
|
|||
* @param {TODO} tapped tapped
|
||||
* @returns {string} name
|
||||
*/
|
||||
tapped => {
|
||||
return tapped.name;
|
||||
}
|
||||
tapped => tapped.name
|
||||
)
|
||||
.join(", ");
|
||||
|
||||
|
|
|
@ -41,9 +41,7 @@ const validate = createSchemaValidation(
|
|||
* @param {number} c c
|
||||
* @returns {number} median
|
||||
*/
|
||||
const median3 = (a, b, c) => {
|
||||
return a + b + c - Math.max(a, b, c) - Math.min(a, b, c);
|
||||
};
|
||||
const median3 = (a, b, c) => a + b + c - Math.max(a, b, c) - Math.min(a, b, c);
|
||||
|
||||
/**
|
||||
* @param {boolean | null | undefined} profile need profile
|
||||
|
|
|
@ -34,8 +34,10 @@ const { forEachRuntime, subtractRuntime } = require("./util/runtime");
|
|||
* @param {ChunkGraph} chunkGraph the chunk graph
|
||||
* @returns {string} error message
|
||||
*/
|
||||
const noModuleIdErrorMessage = (module, chunkGraph) => {
|
||||
return `Module ${module.identifier()} has no id assigned.
|
||||
const noModuleIdErrorMessage = (
|
||||
module,
|
||||
chunkGraph
|
||||
) => `Module ${module.identifier()} has no id assigned.
|
||||
This should not happen.
|
||||
It's in these chunks: ${
|
||||
Array.from(
|
||||
|
@ -54,7 +56,6 @@ Module has these incoming connections: ${Array.from(
|
|||
""
|
||||
}`
|
||||
).join("")}`;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {string | undefined} definition global object definition
|
||||
|
|
|
@ -73,9 +73,7 @@ const resetRegexpState = regexp => {
|
|||
* @param {string} str String to quote
|
||||
* @returns {string} Escaped string
|
||||
*/
|
||||
const quoteMeta = str => {
|
||||
return str.replace(METACHARACTERS_REGEXP, "\\$&");
|
||||
};
|
||||
const quoteMeta = str => str.replace(METACHARACTERS_REGEXP, "\\$&");
|
||||
|
||||
/**
|
||||
* Creating {@link SourceMapTask} for given file
|
||||
|
|
|
@ -292,12 +292,10 @@ class Template {
|
|||
return null;
|
||||
}
|
||||
/** @type {{id: string|number, source: Source|string}[]} */
|
||||
const allModules = modules.map(module => {
|
||||
return {
|
||||
const allModules = modules.map(module => ({
|
||||
id: chunkGraph.getModuleId(module),
|
||||
source: renderModule(module) || "false"
|
||||
};
|
||||
});
|
||||
}));
|
||||
const bounds = Template.getModulesArrayBounds(allModules);
|
||||
if (bounds) {
|
||||
// Render a spare array
|
||||
|
|
|
@ -60,8 +60,8 @@ const getArguments = (schema = webpackSchema) => {
|
|||
/** @type {Record<string, Argument>} */
|
||||
const flags = {};
|
||||
|
||||
const pathToArgumentName = input => {
|
||||
return input
|
||||
const pathToArgumentName = input =>
|
||||
input
|
||||
.replace(/\./g, "-")
|
||||
.replace(/\[\]/g, "")
|
||||
.replace(
|
||||
|
@ -70,7 +70,6 @@ const getArguments = (schema = webpackSchema) => {
|
|||
)
|
||||
.replace(/-?[^\p{Uppercase_Letter}\p{Lowercase_Letter}\d]+/gu, "-")
|
||||
.toLowerCase();
|
||||
};
|
||||
|
||||
const getSchemaPart = path => {
|
||||
const newPath = path.split("/");
|
||||
|
|
|
@ -80,8 +80,8 @@ const resolve = browsers => {
|
|||
* @param {Record<string, number | [number, number]>} versions first supported version
|
||||
* @returns {boolean} true if supports
|
||||
*/
|
||||
const rawChecker = versions => {
|
||||
return browsers.every(v => {
|
||||
const rawChecker = versions =>
|
||||
browsers.every(v => {
|
||||
const [name, parsedVersion] = v.split(" ");
|
||||
if (!name) return false;
|
||||
const requiredVersion = versions[name];
|
||||
|
@ -100,7 +100,6 @@ const resolve = browsers => {
|
|||
? Number(parserMinor) >= requiredVersion[1]
|
||||
: Number(parsedMajor) > requiredVersion[0];
|
||||
});
|
||||
};
|
||||
const anyNode = browsers.some(b => /^node /.test(b));
|
||||
const anyBrowser = browsers.some(b => /^(?!node)/.test(b));
|
||||
const browserProperty = !anyBrowser ? false : anyNode ? null : true;
|
||||
|
|
|
@ -161,9 +161,9 @@ const applyWebpackOptionsBaseDefaults = options => {
|
|||
*/
|
||||
const applyWebpackOptionsDefaults = (options, compilerIndex) => {
|
||||
F(options, "context", () => process.cwd());
|
||||
F(options, "target", () => {
|
||||
return getDefaultTarget(/** @type {string} */ (options.context));
|
||||
});
|
||||
F(options, "target", () =>
|
||||
getDefaultTarget(/** @type {string} */ (options.context))
|
||||
);
|
||||
|
||||
const { mode, name, target } = options;
|
||||
|
||||
|
|
|
@ -56,10 +56,7 @@ const nestedConfig = (value, fn) =>
|
|||
* @param {T|undefined} value value or not
|
||||
* @returns {T} result value
|
||||
*/
|
||||
const cloneObject = value => {
|
||||
return /** @type {T} */ ({ ...value });
|
||||
};
|
||||
|
||||
const cloneObject = value => /** @type {T} */ ({ ...value });
|
||||
/**
|
||||
* @template T
|
||||
* @template R
|
||||
|
@ -124,8 +121,7 @@ const keyedNestedConfig = (value, fn, customKeys) => {
|
|||
* @param {WebpackOptions} config input config
|
||||
* @returns {WebpackOptionsNormalized} normalized options
|
||||
*/
|
||||
const getNormalizedWebpackOptions = config => {
|
||||
return {
|
||||
const getNormalizedWebpackOptions = config => ({
|
||||
amd: config.amd,
|
||||
bail: config.bail,
|
||||
cache:
|
||||
|
@ -154,8 +150,7 @@ const getNormalizedWebpackOptions = config => {
|
|||
compression: cache.compression,
|
||||
idleTimeout: cache.idleTimeout,
|
||||
idleTimeoutForInitialStore: cache.idleTimeoutForInitialStore,
|
||||
idleTimeoutAfterLargeChanges:
|
||||
cache.idleTimeoutAfterLargeChanges,
|
||||
idleTimeoutAfterLargeChanges: cache.idleTimeoutAfterLargeChanges,
|
||||
name: cache.name,
|
||||
store: cache.store,
|
||||
version: cache.version,
|
||||
|
@ -268,8 +263,7 @@ const getNormalizedWebpackOptions = config => {
|
|||
...node
|
||||
}
|
||||
),
|
||||
optimization: nestedConfig(config.optimization, optimization => {
|
||||
return {
|
||||
optimization: nestedConfig(config.optimization, optimization => ({
|
||||
...optimization,
|
||||
runtimeChunk: getNormalizedOptimizationRuntimeChunk(
|
||||
optimization.runtimeChunk
|
||||
|
@ -292,8 +286,7 @@ const getNormalizedWebpackOptions = config => {
|
|||
optimization.emitOnErrors
|
||||
)
|
||||
: optimization.emitOnErrors
|
||||
};
|
||||
}),
|
||||
})),
|
||||
output: nestedConfig(config.output, output => {
|
||||
const { library } = output;
|
||||
const libraryAsName = /** @type {LibraryName} */ (library);
|
||||
|
@ -383,15 +376,12 @@ const getNormalizedWebpackOptions = config => {
|
|||
sourcePrefix: output.sourcePrefix,
|
||||
strictModuleErrorHandling: output.strictModuleErrorHandling,
|
||||
strictModuleExceptionHandling: output.strictModuleExceptionHandling,
|
||||
trustedTypes: optionalNestedConfig(
|
||||
output.trustedTypes,
|
||||
trustedTypes => {
|
||||
trustedTypes: optionalNestedConfig(output.trustedTypes, trustedTypes => {
|
||||
if (trustedTypes === true) return {};
|
||||
if (typeof trustedTypes === "string")
|
||||
return { policyName: trustedTypes };
|
||||
return { ...trustedTypes };
|
||||
}
|
||||
),
|
||||
}),
|
||||
uniqueName: output.uniqueName,
|
||||
wasmLoading: output.wasmLoading,
|
||||
webassemblyModuleFilename: output.webassemblyModuleFilename,
|
||||
|
@ -473,8 +463,7 @@ const getNormalizedWebpackOptions = config => {
|
|||
target: config.target,
|
||||
watch: config.watch,
|
||||
watchOptions: cloneObject(config.watchOptions)
|
||||
};
|
||||
};
|
||||
});
|
||||
|
||||
/**
|
||||
* @param {EntryStatic} entry static entry options
|
||||
|
|
|
@ -93,9 +93,8 @@ const versionDependent = (major, minor) => {
|
|||
const nMajor = Number(major);
|
||||
/** @type {number} */
|
||||
const nMinor = minor ? Number(minor) : 0;
|
||||
return (vMajor, vMinor = 0) => {
|
||||
return nMajor > vMajor || (nMajor === vMajor && nMinor >= vMinor);
|
||||
};
|
||||
return (vMajor, vMinor = 0) =>
|
||||
nMajor > vMajor || (nMajor === vMajor && nMinor >= vMinor);
|
||||
};
|
||||
|
||||
/** @type {[string, string, RegExp, (...args: string[]) => Partial<TargetProperties>][]} */
|
||||
|
@ -124,8 +123,7 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis
|
|||
"web",
|
||||
"Web browser.",
|
||||
/^web$/,
|
||||
() => {
|
||||
return {
|
||||
() => ({
|
||||
web: true,
|
||||
browser: true,
|
||||
webworker: null,
|
||||
|
@ -140,15 +138,13 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis
|
|||
importScripts: false,
|
||||
require: false,
|
||||
global: false
|
||||
};
|
||||
}
|
||||
})
|
||||
],
|
||||
[
|
||||
"webworker",
|
||||
"Web Worker, SharedWorker or Service Worker.",
|
||||
/^webworker$/,
|
||||
() => {
|
||||
return {
|
||||
() => ({
|
||||
web: true,
|
||||
browser: true,
|
||||
webworker: true,
|
||||
|
@ -163,8 +159,7 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis
|
|||
require: false,
|
||||
document: false,
|
||||
global: false
|
||||
};
|
||||
}
|
||||
})
|
||||
],
|
||||
[
|
||||
"[async-]node[X[.Y]]",
|
||||
|
@ -376,11 +371,8 @@ const mergeTargetProperties = targetProperties => {
|
|||
* @param {string} context the context directory
|
||||
* @returns {TargetProperties} target properties
|
||||
*/
|
||||
const getTargetsProperties = (targets, context) => {
|
||||
return mergeTargetProperties(
|
||||
targets.map(t => getTargetProperties(t, context))
|
||||
);
|
||||
};
|
||||
const getTargetsProperties = (targets, context) =>
|
||||
mergeTargetProperties(targets.map(t => getTargetProperties(t, context)));
|
||||
|
||||
module.exports.getDefaultTarget = getDefaultTarget;
|
||||
module.exports.getTargetProperties = getTargetProperties;
|
||||
|
|
|
@ -467,12 +467,10 @@ class CssModulesPlugin {
|
|||
// Lists are in reverse order to allow to use Array.pop()
|
||||
const modulesByChunkGroup = Array.from(chunk.groupsIterable, chunkGroup => {
|
||||
const sortedModules = modulesList
|
||||
.map(module => {
|
||||
return {
|
||||
.map(module => ({
|
||||
module,
|
||||
index: chunkGroup.getModulePostOrderIndex(module)
|
||||
};
|
||||
})
|
||||
}))
|
||||
.filter(item => item.index !== undefined)
|
||||
.sort(
|
||||
(a, b) =>
|
||||
|
|
|
@ -423,9 +423,7 @@ class CssParser extends Parser {
|
|||
const eatKeyframes = eatUntil("{};/");
|
||||
const eatNameInVar = eatUntil(",)};/");
|
||||
walkCssTokens(source, {
|
||||
isSelector: () => {
|
||||
return isNextRulePrelude;
|
||||
},
|
||||
isSelector: () => isNextRulePrelude,
|
||||
url: (input, start, end, contentStart, contentEnd) => {
|
||||
const value = normalizeUrl(
|
||||
input.slice(contentStart, contentEnd),
|
||||
|
|
|
@ -80,11 +80,8 @@ const CC_GREATER_THAN_SIGN = ">".charCodeAt(0);
|
|||
* @param {number} cc char code
|
||||
* @returns {boolean} true, if cc is a newline
|
||||
*/
|
||||
const _isNewLine = cc => {
|
||||
return (
|
||||
cc === CC_LINE_FEED || cc === CC_CARRIAGE_RETURN || cc === CC_FORM_FEED
|
||||
);
|
||||
};
|
||||
const _isNewLine = cc =>
|
||||
cc === CC_LINE_FEED || cc === CC_CARRIAGE_RETURN || cc === CC_FORM_FEED;
|
||||
|
||||
/** @type {CharHandler} */
|
||||
const consumeSpace = (input, pos, callbacks) => {
|
||||
|
@ -101,27 +98,20 @@ const consumeSpace = (input, pos, callbacks) => {
|
|||
* @param {number} cc char code
|
||||
* @returns {boolean} true, if cc is a newline
|
||||
*/
|
||||
const _isNewline = cc => {
|
||||
return (
|
||||
cc === CC_LINE_FEED || cc === CC_CARRIAGE_RETURN || cc === CC_FORM_FEED
|
||||
);
|
||||
};
|
||||
const _isNewline = cc =>
|
||||
cc === CC_LINE_FEED || cc === CC_CARRIAGE_RETURN || cc === CC_FORM_FEED;
|
||||
|
||||
/**
|
||||
* @param {number} cc char code
|
||||
* @returns {boolean} true, if cc is a space (U+0009 CHARACTER TABULATION or U+0020 SPACE)
|
||||
*/
|
||||
const _isSpace = cc => {
|
||||
return cc === CC_TAB || cc === CC_SPACE;
|
||||
};
|
||||
const _isSpace = cc => cc === CC_TAB || cc === CC_SPACE;
|
||||
|
||||
/**
|
||||
* @param {number} cc char code
|
||||
* @returns {boolean} true, if cc is a whitespace
|
||||
*/
|
||||
const _isWhiteSpace = cc => {
|
||||
return _isNewline(cc) || _isSpace(cc);
|
||||
};
|
||||
const _isWhiteSpace = cc => _isNewline(cc) || _isSpace(cc);
|
||||
|
||||
/**
|
||||
* ident-start code point
|
||||
|
@ -130,19 +120,14 @@ const _isWhiteSpace = cc => {
|
|||
* @param {number} cc char code
|
||||
* @returns {boolean} true, if cc is a start code point of an identifier
|
||||
*/
|
||||
const isIdentStartCodePoint = cc => {
|
||||
return (
|
||||
const isIdentStartCodePoint = cc =>
|
||||
(cc >= CC_LOWER_A && cc <= CC_LOWER_Z) ||
|
||||
(cc >= CC_UPPER_A && cc <= CC_UPPER_Z) ||
|
||||
cc === CC_LOW_LINE ||
|
||||
cc >= 0x80
|
||||
);
|
||||
};
|
||||
cc >= 0x80;
|
||||
|
||||
/** @type {CharHandler} */
|
||||
const consumeDelimToken = (input, pos, callbacks) => {
|
||||
return pos + 1;
|
||||
};
|
||||
const consumeDelimToken = (input, pos, callbacks) => pos + 1;
|
||||
|
||||
/** @type {CharHandler} */
|
||||
const consumeComments = (input, pos, callbacks) => {
|
||||
|
@ -214,14 +199,11 @@ const _consumeString = (input, pos, quoteCc) => {
|
|||
* @param {number} cc char code
|
||||
* @returns {boolean} is identifier start code
|
||||
*/
|
||||
const _isIdentifierStartCode = cc => {
|
||||
return (
|
||||
const _isIdentifierStartCode = cc =>
|
||||
cc === CC_LOW_LINE ||
|
||||
(cc >= CC_LOWER_A && cc <= CC_LOWER_Z) ||
|
||||
(cc >= CC_UPPER_A && cc <= CC_UPPER_Z) ||
|
||||
cc > 0x80
|
||||
);
|
||||
};
|
||||
cc > 0x80;
|
||||
|
||||
/**
|
||||
* @param {number} first first code point
|
||||
|
@ -238,9 +220,7 @@ const _isTwoCodePointsAreValidEscape = (first, second) => {
|
|||
* @param {number} cc char code
|
||||
* @returns {boolean} is digit
|
||||
*/
|
||||
const _isDigit = cc => {
|
||||
return cc >= CC_0 && cc <= CC_9;
|
||||
};
|
||||
const _isDigit = cc => cc >= CC_0 && cc <= CC_9;
|
||||
|
||||
/**
|
||||
* @param {string} input input
|
||||
|
|
|
@ -89,9 +89,9 @@ AMDRequireArrayDependency.Template = class AMDRequireArrayDependencyTemplate ext
|
|||
* @returns {string} content
|
||||
*/
|
||||
getContent(dep, templateContext) {
|
||||
const requires = dep.depsArray.map(dependency => {
|
||||
return this.contentForDependency(dependency, templateContext);
|
||||
});
|
||||
const requires = dep.depsArray.map(dependency =>
|
||||
this.contentForDependency(dependency, templateContext)
|
||||
);
|
||||
return `[${requires.join(", ")}]`;
|
||||
}
|
||||
|
||||
|
|
|
@ -49,11 +49,12 @@ class AMDRequireDependenciesBlockParserPlugin {
|
|||
const fnData = getFunctionExpression(expression);
|
||||
if (fnData) {
|
||||
parser.inScope(
|
||||
fnData.fn.params.filter(i => {
|
||||
return !["require", "module", "exports"].includes(
|
||||
fnData.fn.params.filter(
|
||||
i =>
|
||||
!["require", "module", "exports"].includes(
|
||||
/** @type {Identifier} */ (i).name
|
||||
);
|
||||
}),
|
||||
)
|
||||
),
|
||||
() => {
|
||||
if (fnData.fn.body.type === "BlockStatement") {
|
||||
parser.walkStatement(fnData.fn.body);
|
||||
|
|
|
@ -190,14 +190,12 @@ class CommonJsExportRequireDependency extends ModuleDependency {
|
|||
return {
|
||||
exports: Array.from(
|
||||
/** @type {TODO} */ (reexportInfo).exports,
|
||||
name => {
|
||||
return {
|
||||
name => ({
|
||||
name,
|
||||
from,
|
||||
export: ids.concat(name),
|
||||
canMangle: !(name in EMPTY_OBJECT) && false
|
||||
};
|
||||
}
|
||||
})
|
||||
),
|
||||
// TODO handle deep reexports
|
||||
dependencies: [from.module]
|
||||
|
|
|
@ -237,9 +237,9 @@ class CommonJsExportsParserPlugin {
|
|||
};
|
||||
parser.hooks.assignMemberChain
|
||||
.for("exports")
|
||||
.tap("CommonJsExportsParserPlugin", (expr, members) => {
|
||||
return handleAssignExport(expr, "exports", members);
|
||||
});
|
||||
.tap("CommonJsExportsParserPlugin", (expr, members) =>
|
||||
handleAssignExport(expr, "exports", members)
|
||||
);
|
||||
parser.hooks.assignMemberChain
|
||||
.for("this")
|
||||
.tap("CommonJsExportsParserPlugin", (expr, members) => {
|
||||
|
@ -335,19 +335,19 @@ class CommonJsExportsParserPlugin {
|
|||
};
|
||||
parser.hooks.callMemberChain
|
||||
.for("exports")
|
||||
.tap("CommonJsExportsParserPlugin", (expr, members) => {
|
||||
return handleAccessExport(expr.callee, "exports", members, expr);
|
||||
});
|
||||
.tap("CommonJsExportsParserPlugin", (expr, members) =>
|
||||
handleAccessExport(expr.callee, "exports", members, expr)
|
||||
);
|
||||
parser.hooks.expressionMemberChain
|
||||
.for("exports")
|
||||
.tap("CommonJsExportsParserPlugin", (expr, members) => {
|
||||
return handleAccessExport(expr, "exports", members);
|
||||
});
|
||||
.tap("CommonJsExportsParserPlugin", (expr, members) =>
|
||||
handleAccessExport(expr, "exports", members)
|
||||
);
|
||||
parser.hooks.expression
|
||||
.for("exports")
|
||||
.tap("CommonJsExportsParserPlugin", expr => {
|
||||
return handleAccessExport(expr, "exports", []);
|
||||
});
|
||||
.tap("CommonJsExportsParserPlugin", expr =>
|
||||
handleAccessExport(expr, "exports", [])
|
||||
);
|
||||
parser.hooks.callMemberChain
|
||||
.for("module")
|
||||
.tap("CommonJsExportsParserPlugin", (expr, members) => {
|
||||
|
@ -367,9 +367,9 @@ class CommonJsExportsParserPlugin {
|
|||
});
|
||||
parser.hooks.expression
|
||||
.for("module.exports")
|
||||
.tap("CommonJsExportsParserPlugin", expr => {
|
||||
return handleAccessExport(expr, "module.exports", []);
|
||||
});
|
||||
.tap("CommonJsExportsParserPlugin", expr =>
|
||||
handleAccessExport(expr, "module.exports", [])
|
||||
);
|
||||
parser.hooks.callMemberChain
|
||||
.for("this")
|
||||
.tap("CommonJsExportsParserPlugin", (expr, members) => {
|
||||
|
|
|
@ -544,14 +544,10 @@ class CommonJsImportsParserPlugin {
|
|||
|
||||
parser.hooks.call
|
||||
.for("require.resolve")
|
||||
.tap("CommonJsImportsParserPlugin", expr => {
|
||||
return processResolve(expr, false);
|
||||
});
|
||||
.tap("CommonJsImportsParserPlugin", expr => processResolve(expr, false));
|
||||
parser.hooks.call
|
||||
.for("require.resolveWeak")
|
||||
.tap("CommonJsImportsParserPlugin", expr => {
|
||||
return processResolve(expr, true);
|
||||
});
|
||||
.tap("CommonJsImportsParserPlugin", expr => processResolve(expr, true));
|
||||
//#endregion
|
||||
|
||||
//#region Create require
|
||||
|
@ -607,12 +603,12 @@ class CommonJsImportsParserPlugin {
|
|||
});
|
||||
parser.hooks.unhandledExpressionMemberChain
|
||||
.for(createdRequireIdentifierTag)
|
||||
.tap("CommonJsImportsParserPlugin", (expr, members) => {
|
||||
return expressionIsUnsupported(
|
||||
.tap("CommonJsImportsParserPlugin", (expr, members) =>
|
||||
expressionIsUnsupported(
|
||||
parser,
|
||||
`createRequire().${members.join(".")} is not supported by webpack.`
|
||||
)(expr);
|
||||
});
|
||||
)(expr)
|
||||
);
|
||||
parser.hooks.canRename
|
||||
.for(createdRequireIdentifierTag)
|
||||
.tap("CommonJsImportsParserPlugin", () => true);
|
||||
|
|
|
@ -22,9 +22,7 @@ const { parseResource } = require("../util/identifier");
|
|||
* @param {string} str String to quote
|
||||
* @returns {string} Escaped string
|
||||
*/
|
||||
const quoteMeta = str => {
|
||||
return str.replace(/[-[\]\\/{}()*+?.^$|]/g, "\\$&");
|
||||
};
|
||||
const quoteMeta = str => str.replace(/[-[\]\\/{}()*+?.^$|]/g, "\\$&");
|
||||
|
||||
/**
|
||||
* @param {string} prefix prefix
|
||||
|
|
|
@ -25,9 +25,9 @@ const ModuleDependency = require("./ModuleDependency");
|
|||
/** @typedef {import("../util/Hash")} Hash */
|
||||
/** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
|
||||
|
||||
const getIgnoredRawDataUrlModule = memoize(() => {
|
||||
return new RawDataUrlModule("data:,", `ignored-asset`, `(ignored asset)`);
|
||||
});
|
||||
const getIgnoredRawDataUrlModule = memoize(
|
||||
() => new RawDataUrlModule("data:,", `ignored-asset`, `(ignored asset)`)
|
||||
);
|
||||
|
||||
class CssUrlDependency extends ModuleDependency {
|
||||
/**
|
||||
|
|
|
@ -57,14 +57,14 @@ module.exports = class ImportMetaContextDependencyParserPlugin {
|
|||
apply(parser) {
|
||||
parser.hooks.evaluateIdentifier
|
||||
.for("import.meta.webpackContext")
|
||||
.tap("ImportMetaContextDependencyParserPlugin", expr => {
|
||||
return evaluateToIdentifier(
|
||||
.tap("ImportMetaContextDependencyParserPlugin", expr =>
|
||||
evaluateToIdentifier(
|
||||
"import.meta.webpackContext",
|
||||
"import.meta",
|
||||
() => ["webpackContext"],
|
||||
true
|
||||
)(expr);
|
||||
});
|
||||
)(expr)
|
||||
);
|
||||
parser.hooks.call
|
||||
.for("import.meta.webpackContext")
|
||||
.tap("ImportMetaContextDependencyParserPlugin", expr => {
|
||||
|
|
|
@ -49,9 +49,7 @@ class ImportMetaPlugin {
|
|||
* @param {NormalModule} module module
|
||||
* @returns {string} file url
|
||||
*/
|
||||
const getUrl = module => {
|
||||
return pathToFileURL(module.resource).toString();
|
||||
};
|
||||
const getUrl = module => pathToFileURL(module.resource).toString();
|
||||
/**
|
||||
* @param {Parser} parser parser parser
|
||||
* @param {JavascriptParserOptions} parserOptions parserOptions
|
||||
|
@ -185,11 +183,11 @@ class ImportMetaPlugin {
|
|||
.tap(PLUGIN_NAME, evaluateToString("string"));
|
||||
parser.hooks.evaluateIdentifier
|
||||
.for("import.meta.url")
|
||||
.tap(PLUGIN_NAME, expr => {
|
||||
return new BasicEvaluatedExpression()
|
||||
.tap(PLUGIN_NAME, expr =>
|
||||
new BasicEvaluatedExpression()
|
||||
.setString(getUrl(parser.state.module))
|
||||
.setRange(/** @type {Range} */ (expr.range));
|
||||
});
|
||||
.setRange(/** @type {Range} */ (expr.range))
|
||||
);
|
||||
|
||||
/// import.meta.webpack ///
|
||||
parser.hooks.typeof
|
||||
|
|
|
@ -22,13 +22,11 @@ const getExportsFromData = data => {
|
|||
if (data && typeof data === "object") {
|
||||
if (Array.isArray(data)) {
|
||||
return data.length < 100
|
||||
? data.map((item, idx) => {
|
||||
return {
|
||||
? data.map((item, idx) => ({
|
||||
name: `${idx}`,
|
||||
canMangle: true,
|
||||
exports: getExportsFromData(item)
|
||||
};
|
||||
})
|
||||
}))
|
||||
: undefined;
|
||||
}
|
||||
const exports = [];
|
||||
|
|
|
@ -30,9 +30,9 @@ const ModuleDependency = require("./ModuleDependency");
|
|||
/** @typedef {import("../util/Hash")} Hash */
|
||||
/** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
|
||||
|
||||
const getIgnoredRawDataUrlModule = memoize(() => {
|
||||
return new RawDataUrlModule("data:,", `ignored-asset`, `(ignored asset)`);
|
||||
});
|
||||
const getIgnoredRawDataUrlModule = memoize(
|
||||
() => new RawDataUrlModule("data:,", `ignored-asset`, `(ignored asset)`)
|
||||
);
|
||||
|
||||
class URLDependency extends ModuleDependency {
|
||||
/**
|
||||
|
|
|
@ -44,9 +44,7 @@ class URLPlugin {
|
|||
* @param {NormalModule} module module
|
||||
* @returns {URL} file url
|
||||
*/
|
||||
const getUrl = module => {
|
||||
return pathToFileURL(module.resource);
|
||||
};
|
||||
const getUrl = module => pathToFileURL(module.resource);
|
||||
|
||||
/**
|
||||
* @param {Parser} parser parser parser
|
||||
|
|
|
@ -51,9 +51,7 @@ const WorkerDependency = require("./WorkerDependency");
|
|||
* @param {NormalModule} module module
|
||||
* @returns {string} url
|
||||
*/
|
||||
const getUrl = module => {
|
||||
return pathToFileURL(module.resource).toString();
|
||||
};
|
||||
const getUrl = module => pathToFileURL(module.resource).toString();
|
||||
|
||||
const WorkerSpecifierTag = Symbol("worker specifier tag");
|
||||
|
||||
|
|
|
@ -70,9 +70,7 @@ class ChunkModuleIdRangePlugin {
|
|||
chunkModules = chunkGraph.getOrderedChunkModules(chunk, cmpFn);
|
||||
} else {
|
||||
chunkModules = Array.from(modules)
|
||||
.filter(m => {
|
||||
return chunkGraph.isModuleInChunk(m, chunk);
|
||||
})
|
||||
.filter(m => chunkGraph.isModuleInChunk(m, chunk))
|
||||
.sort(compareModulesByPreOrderIndexOrIdentifier(moduleGraph));
|
||||
}
|
||||
|
||||
|
|
|
@ -51,9 +51,7 @@ class DeterministicChunkIdsPlugin {
|
|||
|
||||
const usedIds = getUsedChunkIds(compilation);
|
||||
assignDeterministicIds(
|
||||
Array.from(chunks).filter(chunk => {
|
||||
return chunk.id === null;
|
||||
}),
|
||||
Array.from(chunks).filter(chunk => chunk.id === null),
|
||||
chunk =>
|
||||
getFullChunkName(chunk, chunkGraph, context, compiler.root),
|
||||
compareNatural,
|
||||
|
|
|
@ -53,11 +53,8 @@ const avoidNumber = str => {
|
|||
* @param {string} request the request
|
||||
* @returns {string} id representation
|
||||
*/
|
||||
const requestToId = request => {
|
||||
return request
|
||||
.replace(/^(\.\.?\/)+/, "")
|
||||
.replace(/(^[.-]|[^a-zA-Z0-9_-])+/g, "_");
|
||||
};
|
||||
const requestToId = request =>
|
||||
request.replace(/^(\.\.?\/)+/, "").replace(/(^[.-]|[^a-zA-Z0-9_-])+/g, "_");
|
||||
module.exports.requestToId = requestToId;
|
||||
|
||||
/**
|
||||
|
@ -119,13 +116,8 @@ module.exports.getLongModuleName = getLongModuleName;
|
|||
* @param {object=} associatedObjectForCache an object to which the cache will be attached
|
||||
* @returns {string} full module name
|
||||
*/
|
||||
const getFullModuleName = (module, context, associatedObjectForCache) => {
|
||||
return makePathsRelative(
|
||||
context,
|
||||
module.identifier(),
|
||||
associatedObjectForCache
|
||||
);
|
||||
};
|
||||
const getFullModuleName = (module, context, associatedObjectForCache) =>
|
||||
makePathsRelative(context, module.identifier(), associatedObjectForCache);
|
||||
module.exports.getFullModuleName = getFullModuleName;
|
||||
|
||||
/**
|
||||
|
|
|
@ -70,11 +70,7 @@ const memoize = require("./util/memoize");
|
|||
*/
|
||||
const lazyFunction = factory => {
|
||||
const fac = memoize(factory);
|
||||
const f = /** @type {any} */ (
|
||||
(...args) => {
|
||||
return fac()(...args);
|
||||
}
|
||||
);
|
||||
const f = /** @type {any} */ ((...args) => fac()(...args));
|
||||
return /** @type {T} */ (f);
|
||||
};
|
||||
|
||||
|
|
|
@ -226,34 +226,22 @@ class JavascriptModulesPlugin {
|
|||
const hooks = JavascriptModulesPlugin.getCompilationHooks(compilation);
|
||||
normalModuleFactory.hooks.createParser
|
||||
.for(JAVASCRIPT_MODULE_TYPE_AUTO)
|
||||
.tap(PLUGIN_NAME, options => {
|
||||
return new JavascriptParser("auto");
|
||||
});
|
||||
.tap(PLUGIN_NAME, options => new JavascriptParser("auto"));
|
||||
normalModuleFactory.hooks.createParser
|
||||
.for(JAVASCRIPT_MODULE_TYPE_DYNAMIC)
|
||||
.tap(PLUGIN_NAME, options => {
|
||||
return new JavascriptParser("script");
|
||||
});
|
||||
.tap(PLUGIN_NAME, options => new JavascriptParser("script"));
|
||||
normalModuleFactory.hooks.createParser
|
||||
.for(JAVASCRIPT_MODULE_TYPE_ESM)
|
||||
.tap(PLUGIN_NAME, options => {
|
||||
return new JavascriptParser("module");
|
||||
});
|
||||
.tap(PLUGIN_NAME, options => new JavascriptParser("module"));
|
||||
normalModuleFactory.hooks.createGenerator
|
||||
.for(JAVASCRIPT_MODULE_TYPE_AUTO)
|
||||
.tap(PLUGIN_NAME, () => {
|
||||
return new JavascriptGenerator();
|
||||
});
|
||||
.tap(PLUGIN_NAME, () => new JavascriptGenerator());
|
||||
normalModuleFactory.hooks.createGenerator
|
||||
.for(JAVASCRIPT_MODULE_TYPE_DYNAMIC)
|
||||
.tap(PLUGIN_NAME, () => {
|
||||
return new JavascriptGenerator();
|
||||
});
|
||||
.tap(PLUGIN_NAME, () => new JavascriptGenerator());
|
||||
normalModuleFactory.hooks.createGenerator
|
||||
.for(JAVASCRIPT_MODULE_TYPE_ESM)
|
||||
.tap(PLUGIN_NAME, () => {
|
||||
return new JavascriptGenerator();
|
||||
});
|
||||
.tap(PLUGIN_NAME, () => new JavascriptGenerator());
|
||||
compilation.hooks.renderManifest.tap(PLUGIN_NAME, (result, options) => {
|
||||
const {
|
||||
hash,
|
||||
|
|
|
@ -1196,11 +1196,13 @@ class JavascriptParser extends Parser {
|
|||
return handleConstOperation(v => -v);
|
||||
}
|
||||
});
|
||||
this.hooks.evaluateTypeof.for("undefined").tap("JavascriptParser", expr => {
|
||||
return new BasicEvaluatedExpression()
|
||||
this.hooks.evaluateTypeof
|
||||
.for("undefined")
|
||||
.tap("JavascriptParser", expr =>
|
||||
new BasicEvaluatedExpression()
|
||||
.setString("undefined")
|
||||
.setRange(/** @type {Range} */ (expr.range));
|
||||
});
|
||||
.setRange(/** @type {Range} */ (expr.range))
|
||||
);
|
||||
this.hooks.evaluate.for("Identifier").tap("JavascriptParser", expr => {
|
||||
if (/** @type {Identifier} */ (expr).name === "undefined") {
|
||||
return new BasicEvaluatedExpression()
|
||||
|
@ -1642,13 +1644,12 @@ class JavascriptParser extends Parser {
|
|||
.tap("JavascriptParser", _expr => {
|
||||
const expr = /** @type {ArrayExpression} */ (_expr);
|
||||
|
||||
const items = expr.elements.map(element => {
|
||||
return (
|
||||
const items = expr.elements.map(
|
||||
element =>
|
||||
element !== null &&
|
||||
element.type !== "SpreadElement" &&
|
||||
this.evaluateExpression(element)
|
||||
);
|
||||
});
|
||||
if (!items.every(Boolean)) return;
|
||||
return new BasicEvaluatedExpression()
|
||||
.setItems(/** @type {BasicEvaluatedExpression[]} */ (items))
|
||||
|
@ -3421,9 +3422,8 @@ class JavascriptParser extends Parser {
|
|||
* @param {CallExpression} expression expression
|
||||
*/
|
||||
walkCallExpression(expression) {
|
||||
const isSimpleFunction = fn => {
|
||||
return fn.params.every(p => p.type === "Identifier");
|
||||
};
|
||||
const isSimpleFunction = fn =>
|
||||
fn.params.every(p => p.type === "Identifier");
|
||||
if (
|
||||
expression.callee.type === "MemberExpression" &&
|
||||
expression.callee.object.type.endsWith("FunctionExpression") &&
|
||||
|
|
|
@ -21,8 +21,8 @@ const BasicEvaluatedExpression = require("./BasicEvaluatedExpression");
|
|||
* @param {(string[] | null)=} runtimeRequirements runtime requirements
|
||||
* @returns {function(Expression): true} plugin function
|
||||
*/
|
||||
module.exports.toConstantDependency = (parser, value, runtimeRequirements) => {
|
||||
return function constDependency(expr) {
|
||||
module.exports.toConstantDependency = (parser, value, runtimeRequirements) =>
|
||||
function constDependency(expr) {
|
||||
const dep = new ConstDependency(
|
||||
value,
|
||||
/** @type {Range} */ (expr.range),
|
||||
|
@ -32,43 +32,39 @@ module.exports.toConstantDependency = (parser, value, runtimeRequirements) => {
|
|||
parser.state.module.addPresentationalDependency(dep);
|
||||
return true;
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {string} value the string value
|
||||
* @returns {function(Expression): BasicEvaluatedExpression} plugin function
|
||||
*/
|
||||
module.exports.evaluateToString = value => {
|
||||
return function stringExpression(expr) {
|
||||
module.exports.evaluateToString = value =>
|
||||
function stringExpression(expr) {
|
||||
return new BasicEvaluatedExpression()
|
||||
.setString(value)
|
||||
.setRange(/** @type {Range} */ (expr.range));
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {number} value the number value
|
||||
* @returns {function(Expression): BasicEvaluatedExpression} plugin function
|
||||
*/
|
||||
module.exports.evaluateToNumber = value => {
|
||||
return function stringExpression(expr) {
|
||||
module.exports.evaluateToNumber = value =>
|
||||
function stringExpression(expr) {
|
||||
return new BasicEvaluatedExpression()
|
||||
.setNumber(value)
|
||||
.setRange(/** @type {Range} */ (expr.range));
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {boolean} value the boolean value
|
||||
* @returns {function(Expression): BasicEvaluatedExpression} plugin function
|
||||
*/
|
||||
module.exports.evaluateToBoolean = value => {
|
||||
return function booleanExpression(expr) {
|
||||
module.exports.evaluateToBoolean = value =>
|
||||
function booleanExpression(expr) {
|
||||
return new BasicEvaluatedExpression()
|
||||
.setBoolean(value)
|
||||
.setRange(/** @type {Range} */ (expr.range));
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {string} identifier identifier
|
||||
|
@ -82,8 +78,8 @@ module.exports.evaluateToIdentifier = (
|
|||
rootInfo,
|
||||
getMembers,
|
||||
truthy
|
||||
) => {
|
||||
return function identifierExpression(expr) {
|
||||
) =>
|
||||
function identifierExpression(expr) {
|
||||
const evaluatedExpression = new BasicEvaluatedExpression()
|
||||
.setIdentifier(identifier, rootInfo, getMembers)
|
||||
.setSideEffects(false)
|
||||
|
@ -102,15 +98,14 @@ module.exports.evaluateToIdentifier = (
|
|||
|
||||
return evaluatedExpression;
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {JavascriptParser} parser the parser
|
||||
* @param {string} message the message
|
||||
* @returns {function(Expression): boolean | undefined} callback to handle unsupported expression
|
||||
*/
|
||||
module.exports.expressionIsUnsupported = (parser, message) => {
|
||||
return function unsupportedExpression(expr) {
|
||||
module.exports.expressionIsUnsupported = (parser, message) =>
|
||||
function unsupportedExpression(expr) {
|
||||
const dep = new ConstDependency(
|
||||
"(void 0)",
|
||||
/** @type {Range} */ (expr.range),
|
||||
|
@ -127,7 +122,6 @@ module.exports.expressionIsUnsupported = (parser, message) => {
|
|||
);
|
||||
return true;
|
||||
};
|
||||
};
|
||||
|
||||
module.exports.skipTraversal = () => true;
|
||||
|
||||
|
|
|
@ -46,9 +46,7 @@ module.exports.generateEntryStartup = (
|
|||
)}`
|
||||
];
|
||||
|
||||
const runModule = id => {
|
||||
return `__webpack_exec__(${JSON.stringify(id)})`;
|
||||
};
|
||||
const runModule = id => `__webpack_exec__(${JSON.stringify(id)})`;
|
||||
const outputCombination = (chunks, moduleIds, final) => {
|
||||
if (chunks.size === 0) {
|
||||
runtime.push(
|
||||
|
|
|
@ -47,9 +47,7 @@ class JsonModulesPlugin {
|
|||
});
|
||||
normalModuleFactory.hooks.createGenerator
|
||||
.for(JSON_MODULE_TYPE)
|
||||
.tap(PLUGIN_NAME, () => {
|
||||
return new JsonGenerator();
|
||||
});
|
||||
.tap(PLUGIN_NAME, () => new JsonGenerator());
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
|
@ -36,9 +36,8 @@ const IDENTIFIER_REGEX =
|
|||
* @param {string} name name to be validated
|
||||
* @returns {boolean} true, when valid
|
||||
*/
|
||||
const isNameValid = name => {
|
||||
return !KEYWORD_REGEX.test(name) && IDENTIFIER_REGEX.test(name);
|
||||
};
|
||||
const isNameValid = name =>
|
||||
!KEYWORD_REGEX.test(name) && IDENTIFIER_REGEX.test(name);
|
||||
|
||||
/**
|
||||
* @param {string[]} accessor variable plus properties
|
||||
|
|
|
@ -46,9 +46,7 @@ class ModernModuleLibraryPlugin extends AbstractLibraryPlugin {
|
|||
compiler.hooks.compilation.tap("ModernModuleLibraryPlugin", compilation => {
|
||||
const { exportsDefinitions } =
|
||||
ConcatenatedModule.getCompilationHooks(compilation);
|
||||
exportsDefinitions.tap("ModernModuleLibraryPlugin", () => {
|
||||
return true;
|
||||
});
|
||||
exportsDefinitions.tap("ModernModuleLibraryPlugin", () => true);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -30,9 +30,8 @@ const AbstractLibraryPlugin = require("./AbstractLibraryPlugin");
|
|||
* @param {string[]} accessor the accessor to convert to path
|
||||
* @returns {string} the path
|
||||
*/
|
||||
const accessorToObjectAccess = accessor => {
|
||||
return accessor.map(a => `[${JSON.stringify(a)}]`).join("");
|
||||
};
|
||||
const accessorToObjectAccess = accessor =>
|
||||
accessor.map(a => `[${JSON.stringify(a)}]`).join("");
|
||||
|
||||
/**
|
||||
* @param {string|undefined} base the path prefix
|
||||
|
@ -157,18 +156,17 @@ class UmdLibraryPlugin extends AbstractLibraryPlugin {
|
|||
* @param {string} str the string to replace
|
||||
* @returns {string} the replaced keys
|
||||
*/
|
||||
const replaceKeys = str => {
|
||||
return compilation.getPath(str, {
|
||||
const replaceKeys = str =>
|
||||
compilation.getPath(str, {
|
||||
chunk
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {ExternalModule[]} modules external modules
|
||||
* @returns {string} result
|
||||
*/
|
||||
const externalsDepsArray = modules => {
|
||||
return `[${replaceKeys(
|
||||
const externalsDepsArray = modules =>
|
||||
`[${replaceKeys(
|
||||
modules
|
||||
.map(m =>
|
||||
JSON.stringify(
|
||||
|
@ -180,14 +178,13 @@ class UmdLibraryPlugin extends AbstractLibraryPlugin {
|
|||
)
|
||||
.join(", ")
|
||||
)}]`;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {ExternalModule[]} modules external modules
|
||||
* @returns {string} result
|
||||
*/
|
||||
const externalsRootArray = modules => {
|
||||
return replaceKeys(
|
||||
const externalsRootArray = modules =>
|
||||
replaceKeys(
|
||||
modules
|
||||
.map(m => {
|
||||
let request = m.request;
|
||||
|
@ -199,14 +196,13 @@ class UmdLibraryPlugin extends AbstractLibraryPlugin {
|
|||
})
|
||||
.join(", ")
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {string} type the type
|
||||
* @returns {string} external require array
|
||||
*/
|
||||
const externalsRequireArray = type => {
|
||||
return replaceKeys(
|
||||
const externalsRequireArray = type =>
|
||||
replaceKeys(
|
||||
externals
|
||||
.map(m => {
|
||||
let expr;
|
||||
|
@ -235,14 +231,13 @@ class UmdLibraryPlugin extends AbstractLibraryPlugin {
|
|||
})
|
||||
.join(", ")
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {ExternalModule[]} modules external modules
|
||||
* @returns {string} arguments
|
||||
*/
|
||||
const externalsArguments = modules => {
|
||||
return modules
|
||||
const externalsArguments = modules =>
|
||||
modules
|
||||
.map(
|
||||
m =>
|
||||
`__WEBPACK_EXTERNAL_MODULE_${Template.toIdentifier(
|
||||
|
@ -250,17 +245,15 @@ class UmdLibraryPlugin extends AbstractLibraryPlugin {
|
|||
)}__`
|
||||
)
|
||||
.join(", ");
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {string| string[]} library library name
|
||||
* @returns {string} stringified library name
|
||||
*/
|
||||
const libraryName = library => {
|
||||
return JSON.stringify(
|
||||
const libraryName = library =>
|
||||
JSON.stringify(
|
||||
replaceKeys(/** @type {string[]} */ ([]).concat(library).pop())
|
||||
);
|
||||
};
|
||||
|
||||
let amdFactory;
|
||||
if (optionalExternals.length > 0) {
|
||||
|
|
|
@ -21,8 +21,8 @@ let currentDefaultLogger = createConsoleLogger(currentDefaultLoggerOptions);
|
|||
* @param {string} name name of the logger
|
||||
* @returns {Logger} a logger
|
||||
*/
|
||||
module.exports.getLogger = name => {
|
||||
return new Logger(
|
||||
module.exports.getLogger = name =>
|
||||
new Logger(
|
||||
(type, args) => {
|
||||
if (module.exports.hooks.log.call(name, type, args) === undefined) {
|
||||
currentDefaultLogger(name, type, args);
|
||||
|
@ -30,7 +30,6 @@ module.exports.getLogger = name => {
|
|||
},
|
||||
childName => module.exports.getLogger(`${name}/${childName}`)
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {createConsoleLogger.LoggerOptions} options new options, merge with old options
|
||||
|
|
|
@ -161,16 +161,12 @@ class NodeWatchFileSystem {
|
|||
"DEP_WEBPACK_WATCHER_GET_AGGREGATED_CHANGES"
|
||||
),
|
||||
getFileTimeInfoEntries: util.deprecate(
|
||||
() => {
|
||||
return fetchTimeInfo().fileTimeInfoEntries;
|
||||
},
|
||||
() => fetchTimeInfo().fileTimeInfoEntries,
|
||||
"Watcher.getFileTimeInfoEntries is deprecated in favor of Watcher.getInfo since that's more performant.",
|
||||
"DEP_WEBPACK_WATCHER_FILE_TIME_INFO_ENTRIES"
|
||||
),
|
||||
getContextTimeInfoEntries: util.deprecate(
|
||||
() => {
|
||||
return fetchTimeInfo().contextTimeInfoEntries;
|
||||
},
|
||||
() => fetchTimeInfo().contextTimeInfoEntries,
|
||||
"Watcher.getContextTimeInfoEntries is deprecated in favor of Watcher.getInfo since that's more performant.",
|
||||
"DEP_WEBPACK_WATCHER_CONTEXT_TIME_INFO_ENTRIES"
|
||||
),
|
||||
|
|
|
@ -69,8 +69,9 @@ module.exports = ({ colors, appendOnly, stream }) => {
|
|||
* @param {string} colorSuffix color suffix
|
||||
* @returns {(function(...any[]): void)} function to write with colors
|
||||
*/
|
||||
const writeColored = (prefix, colorPrefix, colorSuffix) => {
|
||||
return (...args) => {
|
||||
const writeColored =
|
||||
(prefix, colorPrefix, colorSuffix) =>
|
||||
(...args) => {
|
||||
if (currentCollapsed > 0) return;
|
||||
clearStatusMessage();
|
||||
const str = indent(
|
||||
|
@ -82,7 +83,6 @@ module.exports = ({ colors, appendOnly, stream }) => {
|
|||
stream.write(`${str}\n`);
|
||||
writeStatusMessage();
|
||||
};
|
||||
};
|
||||
|
||||
const writeGroupMessage = writeColored(
|
||||
"<-> ",
|
||||
|
|
|
@ -78,9 +78,7 @@ class AggressiveMergingPlugin {
|
|||
}
|
||||
}
|
||||
|
||||
combinations.sort((a, b) => {
|
||||
return b.improvement - a.improvement;
|
||||
});
|
||||
combinations.sort((a, b) => b.improvement - a.improvement);
|
||||
|
||||
const pair = combinations[0];
|
||||
|
||||
|
|
|
@ -36,23 +36,18 @@ const validate = createSchemaValidation(
|
|||
* @param {Chunk} newChunk the new chunk
|
||||
* @returns {(module: Module) => void} function to move module between chunks
|
||||
*/
|
||||
const moveModuleBetween = (chunkGraph, oldChunk, newChunk) => {
|
||||
return module => {
|
||||
const moveModuleBetween = (chunkGraph, oldChunk, newChunk) => module => {
|
||||
chunkGraph.disconnectChunkAndModule(oldChunk, module);
|
||||
chunkGraph.connectChunkAndModule(newChunk, module);
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {ChunkGraph} chunkGraph the chunk graph
|
||||
* @param {Chunk} chunk the chunk
|
||||
* @returns {function(Module): boolean} filter for entry module
|
||||
*/
|
||||
const isNotAEntryModule = (chunkGraph, chunk) => {
|
||||
return module => {
|
||||
return !chunkGraph.isEntryModuleInChunk(module, chunk);
|
||||
};
|
||||
};
|
||||
const isNotAEntryModule = (chunkGraph, chunk) => module =>
|
||||
!chunkGraph.isEntryModuleInChunk(module, chunk);
|
||||
|
||||
/** @type {WeakSet<Chunk>} */
|
||||
const recordedChunks = new WeakSet();
|
||||
|
|
|
@ -45,9 +45,7 @@ const ConcatenatedModule = require("./ConcatenatedModule");
|
|||
* @param {string} msg message
|
||||
* @returns {string} formatted message
|
||||
*/
|
||||
const formatBailoutReason = msg => {
|
||||
return `ModuleConcatenation bailout: ${msg}`;
|
||||
};
|
||||
const formatBailoutReason = msg => `ModuleConcatenation bailout: ${msg}`;
|
||||
|
||||
class ModuleConcatenationPlugin {
|
||||
/**
|
||||
|
@ -188,11 +186,10 @@ class ModuleConcatenationPlugin {
|
|||
// Exports must be known (and not dynamic)
|
||||
const exportsInfo = moduleGraph.getExportsInfo(module);
|
||||
const relevantExports = exportsInfo.getRelevantExports(undefined);
|
||||
const unknownReexports = relevantExports.filter(exportInfo => {
|
||||
return (
|
||||
const unknownReexports = relevantExports.filter(
|
||||
exportInfo =>
|
||||
exportInfo.isReexport() && !exportInfo.getTarget(moduleGraph)
|
||||
);
|
||||
});
|
||||
if (unknownReexports.length > 0) {
|
||||
setBailoutReason(
|
||||
module,
|
||||
|
@ -209,9 +206,7 @@ class ModuleConcatenationPlugin {
|
|||
|
||||
// Root modules must have a static list of exports
|
||||
const unknownProvidedExports = relevantExports.filter(
|
||||
exportInfo => {
|
||||
return exportInfo.provided !== true;
|
||||
}
|
||||
exportInfo => exportInfo.provided !== true
|
||||
);
|
||||
if (unknownProvidedExports.length > 0) {
|
||||
setBailoutReason(
|
||||
|
@ -244,12 +239,11 @@ class ModuleConcatenationPlugin {
|
|||
// modules with lower depth are more likely suited as roots
|
||||
// this improves performance, because modules already selected as inner are skipped
|
||||
logger.time("sort relevant modules");
|
||||
relevantModules.sort((a, b) => {
|
||||
return (
|
||||
relevantModules.sort(
|
||||
(a, b) =>
|
||||
/** @type {number} */ (moduleGraph.getDepth(a)) -
|
||||
/** @type {number} */ (moduleGraph.getDepth(b))
|
||||
);
|
||||
});
|
||||
logger.timeEnd("sort relevant modules");
|
||||
|
||||
/** @type {Statistics} */
|
||||
|
@ -376,9 +370,7 @@ class ModuleConcatenationPlugin {
|
|||
// TODO: Allow to reuse existing configuration while trying to add dependencies.
|
||||
// This would improve performance. O(n^2) -> O(n)
|
||||
logger.time(`sort concat configurations`);
|
||||
concatConfigurations.sort((a, b) => {
|
||||
return b.modules.size - a.modules.size;
|
||||
});
|
||||
concatConfigurations.sort((a, b) => b.modules.size - a.modules.size);
|
||||
logger.timeEnd(`sort concat configurations`);
|
||||
const usedModules = new Set();
|
||||
|
||||
|
@ -447,16 +439,13 @@ class ModuleConcatenationPlugin {
|
|||
moduleGraph.copyOutgoingModuleConnections(
|
||||
m,
|
||||
newModule,
|
||||
c => {
|
||||
return (
|
||||
c =>
|
||||
c.originModule === m &&
|
||||
!(
|
||||
c.dependency instanceof HarmonyImportDependency &&
|
||||
modules.has(c.module)
|
||||
)
|
||||
);
|
||||
}
|
||||
);
|
||||
// remove module from chunk
|
||||
for (const chunk of chunkGraph.getModuleChunksIterable(
|
||||
rootModule
|
||||
|
@ -638,11 +627,11 @@ class ModuleConcatenationPlugin {
|
|||
incomingConnections.get(null) || incomingConnections.get(undefined);
|
||||
if (incomingConnectionsFromNonModules) {
|
||||
const activeNonModulesConnections =
|
||||
incomingConnectionsFromNonModules.filter(connection => {
|
||||
incomingConnectionsFromNonModules.filter(connection =>
|
||||
// We are not interested in inactive connections
|
||||
// or connections without dependency
|
||||
return connection.isActive(runtime);
|
||||
});
|
||||
connection.isActive(runtime)
|
||||
);
|
||||
if (activeNonModulesConnections.length > 0) {
|
||||
/**
|
||||
* @param {RequestShortener} requestShortener request shortener
|
||||
|
@ -742,8 +731,9 @@ class ModuleConcatenationPlugin {
|
|||
*/
|
||||
const problem = requestShortener => {
|
||||
const names = Array.from(nonHarmonyConnections)
|
||||
.map(([originModule, connections]) => {
|
||||
return `${originModule.readableIdentifier(
|
||||
.map(
|
||||
([originModule, connections]) =>
|
||||
`${originModule.readableIdentifier(
|
||||
requestShortener
|
||||
)} (referenced with ${Array.from(
|
||||
new Set(
|
||||
|
@ -753,8 +743,8 @@ class ModuleConcatenationPlugin {
|
|||
)
|
||||
)
|
||||
.sort()
|
||||
.join(", ")})`;
|
||||
})
|
||||
.join(", ")})`
|
||||
)
|
||||
.sort();
|
||||
return `Module ${module.readableIdentifier(
|
||||
requestShortener
|
||||
|
@ -778,9 +768,9 @@ class ModuleConcatenationPlugin {
|
|||
/** @type {false | RuntimeSpec} */
|
||||
let currentRuntimeCondition = false;
|
||||
for (const connection of connections) {
|
||||
const runtimeCondition = filterRuntime(runtime, runtime => {
|
||||
return connection.isTargetActive(runtime);
|
||||
});
|
||||
const runtimeCondition = filterRuntime(runtime, runtime =>
|
||||
connection.isTargetActive(runtime)
|
||||
);
|
||||
if (runtimeCondition === false) continue;
|
||||
if (runtimeCondition === true) continue outer;
|
||||
if (currentRuntimeCondition !== false) {
|
||||
|
@ -804,8 +794,8 @@ class ModuleConcatenationPlugin {
|
|||
* @param {RequestShortener} requestShortener request shortener
|
||||
* @returns {string} problem description
|
||||
*/
|
||||
const problem = requestShortener => {
|
||||
return `Module ${module.readableIdentifier(
|
||||
const problem = requestShortener =>
|
||||
`Module ${module.readableIdentifier(
|
||||
requestShortener
|
||||
)} is runtime-dependent referenced by these modules: ${Array.from(
|
||||
otherRuntimeConnections,
|
||||
|
@ -818,7 +808,6 @@ class ModuleConcatenationPlugin {
|
|||
/** @type {RuntimeSpec} */ (runtimeCondition)
|
||||
)})`
|
||||
).join(", ")}`;
|
||||
};
|
||||
statistics.incorrectRuntimeCondition++;
|
||||
failureCache.set(module, problem); // cache failures for performance
|
||||
return problem;
|
||||
|
|
|
@ -61,9 +61,7 @@ const mapAndDeduplicateBuffers = (input, fn) => {
|
|||
* @param {string} str String to quote
|
||||
* @returns {string} Escaped string
|
||||
*/
|
||||
const quoteMeta = str => {
|
||||
return str.replace(/[-[\]\\/{}()*+?.^$|]/g, "\\$&");
|
||||
};
|
||||
const quoteMeta = str => str.replace(/[-[\]\\/{}()*+?.^$|]/g, "\\$&");
|
||||
|
||||
const cachedSourceMap = new WeakMap();
|
||||
|
||||
|
|
|
@ -424,9 +424,7 @@ const normalizeChunksFilter = chunks => {
|
|||
return ALL_CHUNK_FILTER;
|
||||
}
|
||||
if (chunks instanceof RegExp) {
|
||||
return chunk => {
|
||||
return chunk.name ? chunks.test(chunk.name) : false;
|
||||
};
|
||||
return chunk => (chunk.name ? chunks.test(chunk.name) : false);
|
||||
}
|
||||
if (typeof chunks === "function") {
|
||||
return chunks;
|
||||
|
|
|
@ -231,17 +231,14 @@ class GetChunkFilenameRuntimeModule extends RuntimeModule {
|
|||
* @param {function(Chunk): string | number} fn function from chunk to value
|
||||
* @returns {string} code with static mapping of results of fn for including in quoted string
|
||||
*/
|
||||
const mapExpr = fn => {
|
||||
return `" + ${createMap(fn)} + "`;
|
||||
};
|
||||
const mapExpr = fn => `" + ${createMap(fn)} + "`;
|
||||
|
||||
/**
|
||||
* @param {function(Chunk): string | number} fn function from chunk to value
|
||||
* @returns {function(number): string} function which generates code with static mapping of results of fn for including in quoted string for specific length
|
||||
*/
|
||||
const mapExprWithLength = fn => length => {
|
||||
return `" + ${createMap(c => `${fn(c)}`.slice(0, length))} + "`;
|
||||
};
|
||||
const mapExprWithLength = fn => length =>
|
||||
`" + ${createMap(c => `${fn(c)}`.slice(0, length))} + "`;
|
||||
|
||||
const url =
|
||||
dynamicFilename &&
|
||||
|
|
|
@ -30,9 +30,7 @@ class StartupChunkDependenciesRuntimeModule extends RuntimeModule {
|
|||
const chunk = /** @type {Chunk} */ (this.chunk);
|
||||
const chunkIds = Array.from(
|
||||
chunkGraph.getChunkEntryDependentChunksIterable(chunk)
|
||||
).map(chunk => {
|
||||
return chunk.id;
|
||||
});
|
||||
).map(chunk => chunk.id);
|
||||
const compilation = /** @type {Compilation} */ (this.compilation);
|
||||
const { runtimeTemplate } = compilation;
|
||||
return Template.asString([
|
||||
|
|
|
@ -157,21 +157,17 @@ const parseCacheControl = (cacheControl, requestTime) => {
|
|||
* @property {string} contentType
|
||||
*/
|
||||
|
||||
const areLockfileEntriesEqual = (a, b) => {
|
||||
return (
|
||||
const areLockfileEntriesEqual = (a, b) =>
|
||||
a.resolved === b.resolved &&
|
||||
a.integrity === b.integrity &&
|
||||
a.contentType === b.contentType
|
||||
);
|
||||
};
|
||||
a.contentType === b.contentType;
|
||||
|
||||
/**
|
||||
* @param {LockfileEntry} entry lockfile entry
|
||||
* @returns {`resolved: ${string}, integrity: ${string}, contentType: ${*}`} stringified entry
|
||||
*/
|
||||
const entryToString = entry => {
|
||||
return `resolved: ${entry.resolved}, integrity: ${entry.integrity}, contentType: ${entry.contentType}`;
|
||||
};
|
||||
const entryToString = entry =>
|
||||
`resolved: ${entry.resolved}, integrity: ${entry.integrity}, contentType: ${entry.contentType}`;
|
||||
|
||||
class Lockfile {
|
||||
constructor() {
|
||||
|
@ -1057,13 +1053,13 @@ Run build with un-frozen lockfile to automatically fix lockfile.`
|
|||
const hooks = NormalModule.getCompilationHooks(compilation);
|
||||
hooks.readResourceForScheme
|
||||
.for(scheme)
|
||||
.tapAsync("HttpUriPlugin", (resource, module, callback) => {
|
||||
return getInfo(resource, (err, result) => {
|
||||
.tapAsync("HttpUriPlugin", (resource, module, callback) =>
|
||||
getInfo(resource, (err, result) => {
|
||||
if (err) return callback(err);
|
||||
module.buildInfo.resourceIntegrity = result.entry.integrity;
|
||||
callback(null, result.content);
|
||||
});
|
||||
});
|
||||
})
|
||||
);
|
||||
hooks.needBuild.tapAsync(
|
||||
"HttpUriPlugin",
|
||||
(module, context, callback) => {
|
||||
|
|
|
@ -676,9 +676,8 @@ class BinaryMiddleware extends SerializerMiddleware {
|
|||
currentIsBuffer = Buffer.isBuffer(currentBuffer);
|
||||
}
|
||||
};
|
||||
const isInCurrentBuffer = n => {
|
||||
return currentIsBuffer && n + currentPosition <= currentBuffer.length;
|
||||
};
|
||||
const isInCurrentBuffer = n =>
|
||||
currentIsBuffer && n + currentPosition <= currentBuffer.length;
|
||||
const ensureBuffer = () => {
|
||||
if (!currentIsBuffer) {
|
||||
throw new Error(
|
||||
|
@ -755,9 +754,7 @@ class BinaryMiddleware extends SerializerMiddleware {
|
|||
/**
|
||||
* @returns {number} U32
|
||||
*/
|
||||
const readU32 = () => {
|
||||
return read(I32_SIZE).readUInt32LE(0);
|
||||
};
|
||||
const readU32 = () => read(I32_SIZE).readUInt32LE(0);
|
||||
const readBits = (data, n) => {
|
||||
let mask = 1;
|
||||
while (n !== 0) {
|
||||
|
|
|
@ -69,9 +69,7 @@ const writeUInt64LE = Buffer.prototype.writeBigUInt64LE
|
|||
};
|
||||
|
||||
const readUInt64LE = Buffer.prototype.readBigUInt64LE
|
||||
? (buf, offset) => {
|
||||
return Number(buf.readBigUInt64LE(offset));
|
||||
}
|
||||
? (buf, offset) => Number(buf.readBigUInt64LE(offset))
|
||||
: (buf, offset) => {
|
||||
const low = buf.readUInt32LE(offset);
|
||||
const high = buf.readUInt32LE(offset + 4);
|
||||
|
|
|
@ -257,8 +257,9 @@ class ConsumeSharedPlugin {
|
|||
}
|
||||
);
|
||||
})
|
||||
]).then(([importResolved, requiredVersion]) => {
|
||||
return new ConsumeSharedModule(
|
||||
]).then(
|
||||
([importResolved, requiredVersion]) =>
|
||||
new ConsumeSharedModule(
|
||||
directFallback ? compiler.context : context,
|
||||
{
|
||||
...config,
|
||||
|
@ -266,8 +267,8 @@ class ConsumeSharedPlugin {
|
|||
import: importResolved ? config.import : undefined,
|
||||
requiredVersion
|
||||
}
|
||||
)
|
||||
);
|
||||
});
|
||||
};
|
||||
|
||||
normalModuleFactory.hooks.factorize.tapPromise(
|
||||
|
|
|
@ -341,9 +341,8 @@ const uniqueArray = (items, selector) => {
|
|||
* @param {Comparator<I>} comparator comparator function
|
||||
* @returns {I[]} array of values
|
||||
*/
|
||||
const uniqueOrderedArray = (items, selector, comparator) => {
|
||||
return uniqueArray(items, selector).sort(comparator);
|
||||
};
|
||||
const uniqueOrderedArray = (items, selector, comparator) =>
|
||||
uniqueArray(items, selector).sort(comparator);
|
||||
|
||||
/** @template T @template R @typedef {{ [P in keyof T]: R }} MappedValues<T, R> */
|
||||
|
||||
|
@ -470,25 +469,19 @@ const SIMPLE_EXTRACTORS = {
|
|||
}
|
||||
if (!context.cachedGetErrors) {
|
||||
const map = new WeakMap();
|
||||
context.cachedGetErrors = compilation => {
|
||||
return (
|
||||
context.cachedGetErrors = compilation =>
|
||||
map.get(compilation) ||
|
||||
(errors => (map.set(compilation, errors), errors))(
|
||||
compilation.getErrors()
|
||||
)
|
||||
);
|
||||
};
|
||||
}
|
||||
if (!context.cachedGetWarnings) {
|
||||
const map = new WeakMap();
|
||||
context.cachedGetWarnings = compilation => {
|
||||
return (
|
||||
context.cachedGetWarnings = compilation =>
|
||||
map.get(compilation) ||
|
||||
(warnings => (map.set(compilation, warnings), warnings))(
|
||||
compilation.getWarnings()
|
||||
)
|
||||
);
|
||||
};
|
||||
}
|
||||
if (compilation.name) {
|
||||
object.name = compilation.name;
|
||||
|
@ -1626,17 +1619,15 @@ const SORTERS = {
|
|||
}
|
||||
};
|
||||
|
||||
const getItemSize = item => {
|
||||
const getItemSize = item =>
|
||||
// Each item takes 1 line
|
||||
// + the size of the children
|
||||
// + 1 extra line when it has children and filteredChildren
|
||||
return !item.children
|
||||
!item.children
|
||||
? 1
|
||||
: item.filteredChildren
|
||||
? 2 + getTotalSize(item.children)
|
||||
: 1 + getTotalSize(item.children);
|
||||
};
|
||||
|
||||
const getTotalSize = children => {
|
||||
let size = 0;
|
||||
for (const child of children) {
|
||||
|
@ -1896,17 +1887,13 @@ const ASSETS_GROUPERS = {
|
|||
_: (groupConfigs, context, options) => {
|
||||
const groupByFlag = (name, exclude) => {
|
||||
groupConfigs.push({
|
||||
getKeys: asset => {
|
||||
return asset[name] ? ["1"] : undefined;
|
||||
},
|
||||
getOptions: () => {
|
||||
return {
|
||||
getKeys: asset => (asset[name] ? ["1"] : undefined),
|
||||
getOptions: () => ({
|
||||
groupChildren: !exclude,
|
||||
force: exclude
|
||||
};
|
||||
},
|
||||
createGroup: (key, children, assets) => {
|
||||
return exclude
|
||||
}),
|
||||
createGroup: (key, children, assets) =>
|
||||
exclude
|
||||
? {
|
||||
type: "assets by status",
|
||||
[name]: Boolean(key),
|
||||
|
@ -1918,7 +1905,6 @@ const ASSETS_GROUPERS = {
|
|||
[name]: Boolean(key),
|
||||
children,
|
||||
...assetGroup(children, assets)
|
||||
};
|
||||
}
|
||||
});
|
||||
};
|
||||
|
@ -1962,33 +1948,27 @@ const ASSETS_GROUPERS = {
|
|||
}
|
||||
return keys;
|
||||
},
|
||||
createGroup: (key, children, assets) => {
|
||||
return {
|
||||
createGroup: (key, children, assets) => ({
|
||||
type: groupAssetsByPath ? "assets by path" : "assets by extension",
|
||||
name: key,
|
||||
children,
|
||||
...assetGroup(children, assets)
|
||||
};
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
},
|
||||
groupAssetsByInfo: (groupConfigs, context, options) => {
|
||||
const groupByAssetInfoFlag = name => {
|
||||
groupConfigs.push({
|
||||
getKeys: asset => {
|
||||
return asset.info && asset.info[name] ? ["1"] : undefined;
|
||||
},
|
||||
createGroup: (key, children, assets) => {
|
||||
return {
|
||||
getKeys: asset => (asset.info && asset.info[name] ? ["1"] : undefined),
|
||||
createGroup: (key, children, assets) => ({
|
||||
type: "assets by info",
|
||||
info: {
|
||||
[name]: Boolean(key)
|
||||
},
|
||||
children,
|
||||
...assetGroup(children, assets)
|
||||
};
|
||||
}
|
||||
})
|
||||
});
|
||||
};
|
||||
groupByAssetInfoFlag("immutable");
|
||||
|
@ -1998,17 +1978,13 @@ const ASSETS_GROUPERS = {
|
|||
groupAssetsByChunk: (groupConfigs, context, options) => {
|
||||
const groupByNames = name => {
|
||||
groupConfigs.push({
|
||||
getKeys: asset => {
|
||||
return asset[name];
|
||||
},
|
||||
createGroup: (key, children, assets) => {
|
||||
return {
|
||||
getKeys: asset => asset[name],
|
||||
createGroup: (key, children, assets) => ({
|
||||
type: "assets by chunk",
|
||||
[name]: [key],
|
||||
children,
|
||||
...assetGroup(children, assets)
|
||||
};
|
||||
}
|
||||
})
|
||||
});
|
||||
};
|
||||
groupByNames("chunkNames");
|
||||
|
@ -2041,23 +2017,17 @@ const MODULES_GROUPERS = type => ({
|
|||
_: (groupConfigs, context, options) => {
|
||||
const groupByFlag = (name, type, exclude) => {
|
||||
groupConfigs.push({
|
||||
getKeys: module => {
|
||||
return module[name] ? ["1"] : undefined;
|
||||
},
|
||||
getOptions: () => {
|
||||
return {
|
||||
getKeys: module => (module[name] ? ["1"] : undefined),
|
||||
getOptions: () => ({
|
||||
groupChildren: !exclude,
|
||||
force: exclude
|
||||
};
|
||||
},
|
||||
createGroup: (key, children, modules) => {
|
||||
return {
|
||||
}),
|
||||
createGroup: (key, children, modules) => ({
|
||||
type,
|
||||
[name]: Boolean(key),
|
||||
...(exclude ? { filteredChildren: modules.length } : { children }),
|
||||
...moduleGroup(children, modules)
|
||||
};
|
||||
}
|
||||
})
|
||||
});
|
||||
};
|
||||
const {
|
||||
|
@ -2120,17 +2090,13 @@ const MODULES_GROUPERS = type => ({
|
|||
}
|
||||
if (groupModulesByLayer) {
|
||||
groupConfigs.push({
|
||||
getKeys: module => {
|
||||
return [module.layer];
|
||||
},
|
||||
createGroup: (key, children, modules) => {
|
||||
return {
|
||||
getKeys: module => [module.layer],
|
||||
createGroup: (key, children, modules) => ({
|
||||
type: "modules by layer",
|
||||
layer: key,
|
||||
children,
|
||||
...moduleGroup(children, modules)
|
||||
};
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
if (groupModulesByPath || groupModulesByExtension) {
|
||||
|
@ -2212,17 +2178,13 @@ const RESULT_GROUPERS = {
|
|||
"module.reasons": {
|
||||
groupReasonsByOrigin: groupConfigs => {
|
||||
groupConfigs.push({
|
||||
getKeys: reason => {
|
||||
return [reason.module];
|
||||
},
|
||||
createGroup: (key, children, reasons) => {
|
||||
return {
|
||||
getKeys: reason => [reason.module],
|
||||
createGroup: (key, children, reasons) => ({
|
||||
type: "from origin",
|
||||
module: key,
|
||||
children,
|
||||
...reasonGroup(children, reasons)
|
||||
};
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -2461,9 +2423,7 @@ class DefaultStatsFactoryPlugin {
|
|||
);
|
||||
stats.hooks.getItemFactory
|
||||
.for("compilation.children[].compilation")
|
||||
.tap("DefaultStatsFactoryPlugin", () => {
|
||||
return childFactory;
|
||||
});
|
||||
.tap("DefaultStatsFactoryPlugin", () => childFactory);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -86,9 +86,7 @@ const mapLines = (str, fn) => str.split("\n").map(fn).join("\n");
|
|||
*/
|
||||
const twoDigit = n => (n >= 10 ? `${n}` : `0${n}`);
|
||||
|
||||
const isValidId = id => {
|
||||
return typeof id === "number" || id;
|
||||
};
|
||||
const isValidId = id => typeof id === "number" || id;
|
||||
|
||||
/**
|
||||
* @template T
|
||||
|
@ -96,9 +94,8 @@ const isValidId = id => {
|
|||
* @param {number} count number of items to show
|
||||
* @returns {string} string representation of list
|
||||
*/
|
||||
const moreCount = (list, count) => {
|
||||
return list && list.length > 0 ? `+ ${count}` : `${count}`;
|
||||
};
|
||||
const moreCount = (list, count) =>
|
||||
list && list.length > 0 ? `+ ${count}` : `${count}`;
|
||||
|
||||
/** @type {Record<string, (thing: any, context: StatsPrinterContext, printer: StatsPrinter) => string | void>} */
|
||||
const SIMPLE_PRINTERS = {
|
||||
|
@ -622,11 +619,10 @@ const SIMPLE_PRINTERS = {
|
|||
"error.chunkInitial": (chunkInitial, { formatFlag }) =>
|
||||
chunkInitial ? formatFlag("initial") : undefined,
|
||||
"error.file": (file, { bold }) => bold(file),
|
||||
"error.moduleName": (moduleName, { bold }) => {
|
||||
return moduleName.includes("!")
|
||||
"error.moduleName": (moduleName, { bold }) =>
|
||||
moduleName.includes("!")
|
||||
? `${bold(moduleName.replace(/^(\s|\S)*!/, ""))} (${moduleName})`
|
||||
: `${bold(moduleName)}`;
|
||||
},
|
||||
: `${bold(moduleName)}`,
|
||||
"error.loc": (loc, { green }) => green(loc),
|
||||
"error.message": (message, { bold, formatError }) =>
|
||||
message.includes("\u001b[") ? message : bold(formatError(message)),
|
||||
|
@ -1286,18 +1282,16 @@ const AVAILABLE_FORMATS = {
|
|||
}
|
||||
];
|
||||
for (const { regExp, format } of highlights) {
|
||||
message = message.replace(regExp, (match, content) => {
|
||||
return match.replace(content, format(content));
|
||||
});
|
||||
message = message.replace(regExp, (match, content) =>
|
||||
match.replace(content, format(content))
|
||||
);
|
||||
}
|
||||
return message;
|
||||
}
|
||||
};
|
||||
|
||||
const RESULT_MODIFIER = {
|
||||
"module.modules": result => {
|
||||
return indent(result, "| ");
|
||||
}
|
||||
"module.modules": result => indent(result, "| ")
|
||||
};
|
||||
|
||||
const createOrder = (array, preferredOrder) => {
|
||||
|
|
|
@ -33,8 +33,8 @@ module.exports.groupBy = (
|
|||
// eslint-disable-next-line default-param-last
|
||||
arr = [],
|
||||
fn
|
||||
) => {
|
||||
return arr.reduce(
|
||||
) =>
|
||||
arr.reduce(
|
||||
/**
|
||||
* @param {[Array<T>, Array<T>]} groups An accumulator storing already partitioned values returned from previous call.
|
||||
* @param {T} value The value of the current element
|
||||
|
@ -46,4 +46,3 @@ module.exports.groupBy = (
|
|||
},
|
||||
[[], []]
|
||||
);
|
||||
};
|
||||
|
|
|
@ -46,21 +46,16 @@ const createCachedParameterizedComparator = fn => {
|
|||
* @param {Chunk} b chunk
|
||||
* @returns {-1|0|1} compare result
|
||||
*/
|
||||
module.exports.compareChunksById = (a, b) => {
|
||||
return compareIds(
|
||||
/** @type {ChunkId} */ (a.id),
|
||||
/** @type {ChunkId} */ (b.id)
|
||||
);
|
||||
};
|
||||
module.exports.compareChunksById = (a, b) =>
|
||||
compareIds(/** @type {ChunkId} */ (a.id), /** @type {ChunkId} */ (b.id));
|
||||
|
||||
/**
|
||||
* @param {Module} a module
|
||||
* @param {Module} b module
|
||||
* @returns {-1|0|1} compare result
|
||||
*/
|
||||
module.exports.compareModulesByIdentifier = (a, b) => {
|
||||
return compareIds(a.identifier(), b.identifier());
|
||||
};
|
||||
module.exports.compareModulesByIdentifier = (a, b) =>
|
||||
compareIds(a.identifier(), b.identifier());
|
||||
|
||||
/**
|
||||
* @param {ChunkGraph} chunkGraph the chunk graph
|
||||
|
@ -68,9 +63,8 @@ module.exports.compareModulesByIdentifier = (a, b) => {
|
|||
* @param {Module} b module
|
||||
* @returns {-1|0|1} compare result
|
||||
*/
|
||||
const compareModulesById = (chunkGraph, a, b) => {
|
||||
return compareIds(chunkGraph.getModuleId(a), chunkGraph.getModuleId(b));
|
||||
};
|
||||
const compareModulesById = (chunkGraph, a, b) =>
|
||||
compareIds(chunkGraph.getModuleId(a), chunkGraph.getModuleId(b));
|
||||
/** @type {ParameterizedComparator<ChunkGraph, Module>} */
|
||||
module.exports.compareModulesById =
|
||||
createCachedParameterizedComparator(compareModulesById);
|
||||
|
@ -223,9 +217,7 @@ module.exports.compareModulesByIdOrIdentifier =
|
|||
* @param {Chunk} b chunk
|
||||
* @returns {-1|0|1} compare result
|
||||
*/
|
||||
const compareChunks = (chunkGraph, a, b) => {
|
||||
return chunkGraph.compareChunks(a, b);
|
||||
};
|
||||
const compareChunks = (chunkGraph, a, b) => chunkGraph.compareChunks(a, b);
|
||||
/** @type {ParameterizedComparator<ChunkGraph, Chunk>} */
|
||||
module.exports.compareChunks =
|
||||
createCachedParameterizedComparator(compareChunks);
|
||||
|
@ -264,12 +256,8 @@ module.exports.compareStrings = compareStrings;
|
|||
* @param {ChunkGroup} b second chunk group
|
||||
* @returns {-1|0|1} compare result
|
||||
*/
|
||||
const compareChunkGroupsByIndex = (a, b) => {
|
||||
return /** @type {number} */ (a.index) < /** @type {number} */ (b.index)
|
||||
? -1
|
||||
: 1;
|
||||
};
|
||||
|
||||
const compareChunkGroupsByIndex = (a, b) =>
|
||||
/** @type {number} */ (a.index) < /** @type {number} */ (b.index) ? -1 : 1;
|
||||
module.exports.compareChunkGroupsByIndex = compareChunkGroupsByIndex;
|
||||
|
||||
/**
|
||||
|
|
|
@ -9,9 +9,7 @@
|
|||
* @param {string} str string
|
||||
* @returns {string} quoted meta
|
||||
*/
|
||||
const quoteMeta = str => {
|
||||
return str.replace(/[-[\]\\/{}()*+?.^$|]/g, "\\$&");
|
||||
};
|
||||
const quoteMeta = str => str.replace(/[-[\]\\/{}()*+?.^$|]/g, "\\$&");
|
||||
|
||||
/**
|
||||
* @param {string} str string
|
||||
|
|
|
@ -50,11 +50,8 @@ module.exports.cssExportConvention = (input, convention) => {
|
|||
* @param {string} input input
|
||||
* @returns {string} result
|
||||
*/
|
||||
module.exports.dashesCamelCase = input => {
|
||||
return input.replace(/-+(\w)/g, (match, firstLetter) =>
|
||||
firstLetter.toUpperCase()
|
||||
);
|
||||
};
|
||||
module.exports.dashesCamelCase = input =>
|
||||
input.replace(/-+(\w)/g, (match, firstLetter) => firstLetter.toUpperCase());
|
||||
|
||||
// Copy from css-loader
|
||||
/**
|
||||
|
|
|
@ -534,12 +534,13 @@ module.exports = ({ maxSize, minSize, items, getSize, getKey }) => {
|
|||
}
|
||||
|
||||
// return the results
|
||||
return result.map(group => {
|
||||
return result.map(
|
||||
group =>
|
||||
/** @type {GroupedItems<T>} */
|
||||
return {
|
||||
({
|
||||
key: group.key,
|
||||
items: group.nodes.map(node => node.item),
|
||||
size: group.size
|
||||
};
|
||||
});
|
||||
})
|
||||
);
|
||||
};
|
||||
|
|
|
@ -250,12 +250,11 @@ const makeCacheableWithContext = fn => {
|
|||
* @param {string} identifier identifier for path
|
||||
* @returns {string} a converted relative path
|
||||
*/
|
||||
const _makePathsRelative = (context, identifier) => {
|
||||
return identifier
|
||||
const _makePathsRelative = (context, identifier) =>
|
||||
identifier
|
||||
.split(SEGMENTS_SPLIT_REGEXP)
|
||||
.map(str => absoluteToRequest(context, str))
|
||||
.join("");
|
||||
};
|
||||
|
||||
module.exports.makePathsRelative = makeCacheableWithContext(_makePathsRelative);
|
||||
|
||||
|
@ -264,12 +263,11 @@ module.exports.makePathsRelative = makeCacheableWithContext(_makePathsRelative);
|
|||
* @param {string} identifier identifier for path
|
||||
* @returns {string} a converted relative path
|
||||
*/
|
||||
const _makePathsAbsolute = (context, identifier) => {
|
||||
return identifier
|
||||
const _makePathsAbsolute = (context, identifier) =>
|
||||
identifier
|
||||
.split(SEGMENTS_SPLIT_REGEXP)
|
||||
.map(str => requestToAbsolute(context, str))
|
||||
.join("");
|
||||
};
|
||||
|
||||
module.exports.makePathsAbsolute = makeCacheableWithContext(_makePathsAbsolute);
|
||||
|
||||
|
@ -278,12 +276,11 @@ module.exports.makePathsAbsolute = makeCacheableWithContext(_makePathsAbsolute);
|
|||
* @param {string} request any request string may containing absolute paths, query string, etc.
|
||||
* @returns {string} a new request string avoiding absolute paths when possible
|
||||
*/
|
||||
const _contextify = (context, request) => {
|
||||
return request
|
||||
const _contextify = (context, request) =>
|
||||
request
|
||||
.split("!")
|
||||
.map(r => absoluteToRequest(context, r))
|
||||
.join("!");
|
||||
};
|
||||
|
||||
const contextify = makeCacheableWithContext(_contextify);
|
||||
module.exports.contextify = contextify;
|
||||
|
@ -293,12 +290,11 @@ module.exports.contextify = contextify;
|
|||
* @param {string} request any request string
|
||||
* @returns {string} a new request string using absolute paths when possible
|
||||
*/
|
||||
const _absolutify = (context, request) => {
|
||||
return request
|
||||
const _absolutify = (context, request) =>
|
||||
request
|
||||
.split("!")
|
||||
.map(r => requestToAbsolute(context, r))
|
||||
.join("!");
|
||||
};
|
||||
|
||||
const absolutify = makeCacheableWithContext(_absolutify);
|
||||
module.exports.absolutify = absolutify;
|
||||
|
|
|
@ -154,15 +154,15 @@ const generateImportObject = (
|
|||
importObject = [
|
||||
"return {",
|
||||
Template.indent([
|
||||
Array.from(propertiesByModule, ([module, list]) => {
|
||||
return Template.asString([
|
||||
Array.from(propertiesByModule, ([module, list]) =>
|
||||
Template.asString([
|
||||
`${JSON.stringify(module)}: {`,
|
||||
Template.indent([
|
||||
list.map(p => `${JSON.stringify(p.name)}: ${p.value}`).join(",\n")
|
||||
]),
|
||||
"}"
|
||||
]);
|
||||
}).join(",\n")
|
||||
])
|
||||
).join(",\n")
|
||||
]),
|
||||
"};"
|
||||
];
|
||||
|
@ -249,15 +249,15 @@ class WasmChunkLoadingRuntimeModule extends RuntimeModule {
|
|||
const { mangleImports } = this;
|
||||
/** @type {string[]} */
|
||||
const declarations = [];
|
||||
const importObjects = wasmModules.map(module => {
|
||||
return generateImportObject(
|
||||
const importObjects = wasmModules.map(module =>
|
||||
generateImportObject(
|
||||
chunkGraph,
|
||||
module,
|
||||
mangleImports,
|
||||
declarations,
|
||||
chunk.runtime
|
||||
)
|
||||
);
|
||||
});
|
||||
const chunkModuleIdMap = chunkGraph.getChunkModuleIdMap(chunk, m =>
|
||||
m.type.startsWith("webassembly")
|
||||
);
|
||||
|
|
|
@ -43,14 +43,11 @@ const WebAssemblyExportImportedDependency = require("../dependencies/WebAssembly
|
|||
* @param {((prev: ArrayBuffer) => ArrayBuffer)[]} fns transforms
|
||||
* @returns {Function} composed transform
|
||||
*/
|
||||
const compose = (...fns) => {
|
||||
return fns.reduce(
|
||||
(prevFn, nextFn) => {
|
||||
return value => nextFn(prevFn(value));
|
||||
},
|
||||
const compose = (...fns) =>
|
||||
fns.reduce(
|
||||
(prevFn, nextFn) => value => nextFn(prevFn(value)),
|
||||
value => value
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Removes the start instruction
|
||||
|
@ -58,13 +55,12 @@ const compose = (...fns) => {
|
|||
* @param {object} state.ast Module's ast
|
||||
* @returns {ArrayBufferTransform} transform
|
||||
*/
|
||||
const removeStartFunc = state => bin => {
|
||||
return editWithAST(state.ast, bin, {
|
||||
const removeStartFunc = state => bin =>
|
||||
editWithAST(state.ast, bin, {
|
||||
Start(path) {
|
||||
path.remove();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Get imported globals
|
||||
|
@ -250,8 +246,8 @@ const rewriteImportedGlobals = state => bin => {
|
|||
*/
|
||||
const rewriteExportNames =
|
||||
({ ast, moduleGraph, module, externalExports, runtime }) =>
|
||||
bin => {
|
||||
return editWithAST(ast, bin, {
|
||||
bin =>
|
||||
editWithAST(ast, bin, {
|
||||
/**
|
||||
* @param {NodePath<ModuleExport>} path path
|
||||
*/
|
||||
|
@ -271,7 +267,6 @@ const rewriteExportNames =
|
|||
path.node.name = /** @type {string} */ (usedName);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Mangle import names and modules
|
||||
|
@ -282,8 +277,8 @@ const rewriteExportNames =
|
|||
*/
|
||||
const rewriteImports =
|
||||
({ ast, usedDependencyMap }) =>
|
||||
bin => {
|
||||
return editWithAST(ast, bin, {
|
||||
bin =>
|
||||
editWithAST(ast, bin, {
|
||||
/**
|
||||
* @param {NodePath<ModuleImport>} path path
|
||||
*/
|
||||
|
@ -298,7 +293,6 @@ const rewriteImports =
|
|||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Add an init function.
|
||||
|
|
|
@ -9,8 +9,8 @@ const cacheDirectory = path.resolve(__dirname, "js/buildDepsCache");
|
|||
const outputDirectory = path.resolve(__dirname, "js/buildDeps");
|
||||
const inputDirectory = path.resolve(__dirname, "js/buildDepsInput");
|
||||
|
||||
const exec = (n, options = {}) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const exec = (n, options = {}) =>
|
||||
new Promise((resolve, reject) => {
|
||||
const webpack = require("../");
|
||||
const coverageEnabled = webpack.toString().includes("++");
|
||||
|
||||
|
@ -93,7 +93,6 @@ const exec = (n, options = {}) => {
|
|||
reject(err);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
const supportsEsm = Number(process.versions.modules) >= 83;
|
||||
|
||||
|
|
|
@ -18,15 +18,14 @@ const tempFolderPath = path.join(__dirname, "ChangesAndRemovalsTemp");
|
|||
const tempFilePath = path.join(tempFolderPath, "temp-file.js");
|
||||
const tempFile2Path = path.join(tempFolderPath, "temp-file2.js");
|
||||
|
||||
const createSingleCompiler = () => {
|
||||
return createCompiler({
|
||||
const createSingleCompiler = () =>
|
||||
createCompiler({
|
||||
entry: tempFilePath,
|
||||
output: {
|
||||
path: tempFolderPath,
|
||||
filename: "bundle.js"
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
const onceDone = (compiler, action) => {
|
||||
let initial = true;
|
||||
|
|
|
@ -337,8 +337,8 @@ describe("Compiler", () => {
|
|||
});
|
||||
it("should bubble up errors when wrapped in a promise and bail is true", async () => {
|
||||
try {
|
||||
const createCompiler = options => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const createCompiler = options =>
|
||||
new Promise((resolve, reject) => {
|
||||
const webpack = require("..");
|
||||
const c = webpack(options);
|
||||
c.run((err, stats) => {
|
||||
|
@ -352,7 +352,6 @@ describe("Compiler", () => {
|
|||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
compiler = await createCompiler({
|
||||
context: __dirname,
|
||||
mode: "production",
|
||||
|
@ -370,8 +369,8 @@ describe("Compiler", () => {
|
|||
}
|
||||
});
|
||||
it("should not emit compilation errors in async (watch)", async () => {
|
||||
const createStats = options => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const createStats = options =>
|
||||
new Promise((resolve, reject) => {
|
||||
const webpack = require("..");
|
||||
const c = webpack(options);
|
||||
c.outputFileSystem = createFsFromVolume(new Volume());
|
||||
|
@ -382,7 +381,6 @@ describe("Compiler", () => {
|
|||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
const stats = await createStats({
|
||||
context: __dirname,
|
||||
mode: "production",
|
||||
|
|
|
@ -20,18 +20,15 @@ const asModule = require("./helpers/asModule");
|
|||
const filterInfraStructureErrors = require("./helpers/infrastructureLogErrors");
|
||||
|
||||
const casesPath = path.join(__dirname, "configCases");
|
||||
const categories = fs.readdirSync(casesPath).map(cat => {
|
||||
return {
|
||||
const categories = fs.readdirSync(casesPath).map(cat => ({
|
||||
name: cat,
|
||||
tests: fs
|
||||
.readdirSync(path.join(casesPath, cat))
|
||||
.filter(folder => !folder.startsWith("_"))
|
||||
.sort()
|
||||
};
|
||||
});
|
||||
}));
|
||||
|
||||
const createLogger = appendTarget => {
|
||||
return {
|
||||
const createLogger = appendTarget => ({
|
||||
log: l => appendTarget.push(l),
|
||||
debug: l => appendTarget.push(l),
|
||||
trace: l => appendTarget.push(l),
|
||||
|
@ -46,8 +43,7 @@ const createLogger = appendTarget => {
|
|||
profileEnd: () => {},
|
||||
clear: () => {},
|
||||
status: () => {}
|
||||
};
|
||||
};
|
||||
});
|
||||
|
||||
const describeCases = config => {
|
||||
describe(config.name, () => {
|
||||
|
@ -493,9 +489,9 @@ const describeCases = config => {
|
|||
if (Array.isArray(module)) {
|
||||
p = path.join(currentDirectory, ".array-require.js");
|
||||
content = `module.exports = (${module
|
||||
.map(arg => {
|
||||
return `require(${JSON.stringify(`./${arg}`)})`;
|
||||
})
|
||||
.map(
|
||||
arg => `require(${JSON.stringify(`./${arg}`)})`
|
||||
)
|
||||
.join(", ")});`;
|
||||
} else {
|
||||
p = path.join(currentDirectory, module);
|
||||
|
@ -560,8 +556,8 @@ const describeCases = config => {
|
|||
return (async () => {
|
||||
if (esmMode === "unlinked") return esm;
|
||||
await esm.link(
|
||||
async (specifier, referencingModule) => {
|
||||
return await asModule(
|
||||
async (specifier, referencingModule) =>
|
||||
await asModule(
|
||||
await _require(
|
||||
path.dirname(
|
||||
referencingModule.identifier
|
||||
|
@ -577,8 +573,7 @@ const describeCases = config => {
|
|||
),
|
||||
referencingModule.context,
|
||||
true
|
||||
);
|
||||
}
|
||||
)
|
||||
);
|
||||
// node.js 10 needs instantiate
|
||||
if (esm.instantiate) esm.instantiate();
|
||||
|
|
|
@ -9,9 +9,7 @@ const stripAnsi = require("strip-ansi");
|
|||
* @param {string} str String to quote
|
||||
* @returns {string} Escaped string
|
||||
*/
|
||||
const quoteMeta = str => {
|
||||
return str.replace(/[-[\]\\/{}()*+?.^$|]/g, "\\$&");
|
||||
};
|
||||
const quoteMeta = str => str.replace(/[-[\]\\/{}()*+?.^$|]/g, "\\$&");
|
||||
|
||||
const cwd = process.cwd();
|
||||
const cwdRegExp = new RegExp(
|
||||
|
|
|
@ -13,14 +13,12 @@ const casesPath = path.join(__dirname, "hotCases");
|
|||
let categories = fs
|
||||
.readdirSync(casesPath)
|
||||
.filter(dir => fs.statSync(path.join(casesPath, dir)).isDirectory());
|
||||
categories = categories.map(cat => {
|
||||
return {
|
||||
categories = categories.map(cat => ({
|
||||
name: cat,
|
||||
tests: fs
|
||||
.readdirSync(path.join(casesPath, cat))
|
||||
.filter(folder => folder.indexOf("_") < 0)
|
||||
};
|
||||
});
|
||||
}));
|
||||
|
||||
const describeCases = config => {
|
||||
describe(config.name, () => {
|
||||
|
|
|
@ -45,11 +45,7 @@ describe("MultiItemCache", () => {
|
|||
for (let i = 0; i < howMany; ++i) {
|
||||
const name = `ItemCache${i}`;
|
||||
const tag = `ItemTag${i}`;
|
||||
const dataGen =
|
||||
dataGenerator ||
|
||||
(() => {
|
||||
return { name: tag };
|
||||
});
|
||||
const dataGen = dataGenerator || (() => ({ name: tag }));
|
||||
const cache = new Cache();
|
||||
cache.hooks.get.tapAsync(
|
||||
"DataReturner",
|
||||
|
|
|
@ -3,14 +3,12 @@
|
|||
const SyncHook = require("tapable").SyncHook;
|
||||
const MultiWatching = require("../lib/MultiWatching");
|
||||
|
||||
const createWatching = () => {
|
||||
return {
|
||||
const createWatching = () => ({
|
||||
invalidate: jest.fn(),
|
||||
suspend: jest.fn(),
|
||||
resume: jest.fn(),
|
||||
close: jest.fn()
|
||||
};
|
||||
};
|
||||
});
|
||||
|
||||
const createCompiler = () => {
|
||||
const compiler = {
|
||||
|
|
|
@ -60,8 +60,8 @@ describe("Persistent Caching", () => {
|
|||
}
|
||||
};
|
||||
|
||||
const compile = async (configAdditions = {}) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const compile = async (configAdditions = {}) =>
|
||||
new Promise((resolve, reject) => {
|
||||
const webpack = require("../");
|
||||
webpack(
|
||||
{
|
||||
|
@ -77,7 +77,6 @@ describe("Persistent Caching", () => {
|
|||
}
|
||||
);
|
||||
});
|
||||
};
|
||||
|
||||
const execute = () => {
|
||||
const cache = {};
|
||||
|
|
|
@ -4,8 +4,8 @@ require("./helpers/warmup-webpack");
|
|||
|
||||
const { createFsFromVolume, Volume } = require("memfs");
|
||||
|
||||
const compile = options => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const compile = options =>
|
||||
new Promise((resolve, reject) => {
|
||||
const webpack = require("..");
|
||||
const compiler = webpack(options);
|
||||
compiler.outputFileSystem = createFsFromVolume(new Volume());
|
||||
|
@ -17,7 +17,6 @@ const compile = options => {
|
|||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
describe("Stats", () => {
|
||||
it("should print env string in stats", async () => {
|
||||
|
|
|
@ -12,9 +12,7 @@ const webpack = require("..");
|
|||
* @param {string} str String to quote
|
||||
* @returns {string} Escaped string
|
||||
*/
|
||||
const quoteMeta = str => {
|
||||
return str.replace(/[-[\]\\/{}()*+?.^$|]/g, "\\$&");
|
||||
};
|
||||
const quoteMeta = str => str.replace(/[-[\]\\/{}()*+?.^$|]/g, "\\$&");
|
||||
|
||||
const base = path.join(__dirname, "statsCases");
|
||||
const outputBase = path.join(__dirname, "js", "stats");
|
||||
|
|
|
@ -15,17 +15,14 @@ const filterInfraStructureErrors = require("./helpers/infrastructureLogErrors");
|
|||
|
||||
const casesPath = path.join(__dirname, "cases");
|
||||
let categories = fs.readdirSync(casesPath);
|
||||
categories = categories.map(cat => {
|
||||
return {
|
||||
categories = categories.map(cat => ({
|
||||
name: cat,
|
||||
tests: fs
|
||||
.readdirSync(path.join(casesPath, cat))
|
||||
.filter(folder => folder.indexOf("_") < 0)
|
||||
};
|
||||
});
|
||||
}));
|
||||
|
||||
const createLogger = appendTarget => {
|
||||
return {
|
||||
const createLogger = appendTarget => ({
|
||||
log: l => appendTarget.push(l),
|
||||
debug: l => appendTarget.push(l),
|
||||
trace: l => appendTarget.push(l),
|
||||
|
@ -40,8 +37,7 @@ const createLogger = appendTarget => {
|
|||
profileEnd: () => {},
|
||||
clear: () => {},
|
||||
status: () => {}
|
||||
};
|
||||
};
|
||||
});
|
||||
|
||||
const describeCases = config => {
|
||||
describe(config.name, () => {
|
||||
|
@ -458,13 +454,14 @@ const describeCases = config => {
|
|||
}
|
||||
if (esmMode === "unlinked") return esm;
|
||||
return (async () => {
|
||||
await esm.link(async (specifier, module) => {
|
||||
return await asModule(
|
||||
await esm.link(
|
||||
async (specifier, module) =>
|
||||
await asModule(
|
||||
await _require(specifier, "unlinked"),
|
||||
module.context,
|
||||
true
|
||||
)
|
||||
);
|
||||
});
|
||||
// node.js 10 needs instantiate
|
||||
if (esm.instantiate) esm.instantiate();
|
||||
await esm.evaluate();
|
||||
|
|
|
@ -54,8 +54,7 @@ const describeCases = config => {
|
|||
const casesPath = path.join(__dirname, "watchCases");
|
||||
let categories = fs.readdirSync(casesPath);
|
||||
|
||||
categories = categories.map(cat => {
|
||||
return {
|
||||
categories = categories.map(cat => ({
|
||||
name: cat,
|
||||
tests: fs
|
||||
.readdirSync(path.join(casesPath, cat))
|
||||
|
@ -71,8 +70,7 @@ const describeCases = config => {
|
|||
return true;
|
||||
})
|
||||
.sort()
|
||||
};
|
||||
});
|
||||
}));
|
||||
beforeAll(() => {
|
||||
let dest = path.join(__dirname, "js");
|
||||
if (!fs.existsSync(dest)) fs.mkdirSync(dest);
|
||||
|
@ -103,11 +101,9 @@ const describeCases = config => {
|
|||
const runs = fs
|
||||
.readdirSync(testDirectory)
|
||||
.sort()
|
||||
.filter(name => {
|
||||
return fs
|
||||
.statSync(path.join(testDirectory, name))
|
||||
.isDirectory();
|
||||
})
|
||||
.filter(name =>
|
||||
fs.statSync(path.join(testDirectory, name)).isDirectory()
|
||||
)
|
||||
.map(name => ({ name }));
|
||||
|
||||
beforeAll(done => {
|
||||
|
|
|
@ -10,21 +10,19 @@ const createCompiler = config => {
|
|||
return compiler;
|
||||
};
|
||||
|
||||
const createSingleCompiler = () => {
|
||||
return createCompiler({
|
||||
const createSingleCompiler = () =>
|
||||
createCompiler({
|
||||
context: path.join(__dirname, "fixtures"),
|
||||
entry: "./a.js"
|
||||
});
|
||||
};
|
||||
|
||||
const createMultiCompiler = () => {
|
||||
return createCompiler([
|
||||
const createMultiCompiler = () =>
|
||||
createCompiler([
|
||||
{
|
||||
context: path.join(__dirname, "fixtures"),
|
||||
entry: "./a.js"
|
||||
}
|
||||
]);
|
||||
};
|
||||
|
||||
describe("WatcherEvents", () => {
|
||||
if (process.env.NO_WATCH_TESTS) {
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
const supportsRequireInModule = require("../../../helpers/supportsRequireInModule");
|
||||
|
||||
module.exports = config => {
|
||||
return !config.module || supportsRequireInModule();
|
||||
};
|
||||
module.exports = config => !config.module || supportsRequireInModule();
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
const supportsRequireInModule = require("../../../helpers/supportsRequireInModule");
|
||||
|
||||
module.exports = config => {
|
||||
return !config.module || supportsRequireInModule();
|
||||
};
|
||||
module.exports = config => !config.module || supportsRequireInModule();
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue