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