Comparing version
@@ -17,8 +17,16 @@ /* | ||
if (!updatedModules) { | ||
log("warning", "[HMR] Cannot find update. Need to do a full reload!"); | ||
log( | ||
"warning", | ||
"[HMR] Cannot find update. " + | ||
(typeof window !== "undefined" | ||
? "Need to do a full reload!" | ||
: "Please reload manually!") | ||
); | ||
log( | ||
"warning", | ||
"[HMR] (Probably because of restarting the webpack-dev-server)" | ||
); | ||
window.location.reload(); | ||
if (typeof window !== "undefined") { | ||
window.location.reload(); | ||
} | ||
return; | ||
@@ -42,6 +50,11 @@ } | ||
"warning", | ||
"[HMR] Cannot apply update. Need to do a full reload!" | ||
"[HMR] Cannot apply update. " + | ||
(typeof window !== "undefined" | ||
? "Need to do a full reload!" | ||
: "Please reload manually!") | ||
); | ||
log("warning", "[HMR] " + log.formatError(err)); | ||
window.location.reload(); | ||
if (typeof window !== "undefined") { | ||
window.location.reload(); | ||
} | ||
} else { | ||
@@ -48,0 +61,0 @@ log("warning", "[HMR] Update failed: " + log.formatError(err)); |
@@ -36,3 +36,3 @@ /* | ||
.replace(/\s+\n/g, "\n") | ||
.trimRight()}\n */`; | ||
.trimEnd()}\n */`; | ||
}; | ||
@@ -39,0 +39,0 @@ |
@@ -511,4 +511,5 @@ /* | ||
c = chunkGroup; | ||
} else { | ||
c.addOptions(b.groupOptions); | ||
} | ||
c.addOptions(b.groupOptions); | ||
c.addOrigin(module, b.loc, b.request); | ||
@@ -515,0 +516,0 @@ } |
@@ -193,3 +193,4 @@ /* | ||
css: options.experiments.css, | ||
futureDefaults | ||
futureDefaults, | ||
isNode: targetProperties && targetProperties.node === true | ||
}); | ||
@@ -455,2 +456,3 @@ | ||
* @param {boolean} options.futureDefaults is future defaults enabled | ||
* @param {boolean} options.isNode is node target platform | ||
* @returns {void} | ||
@@ -460,3 +462,3 @@ */ | ||
parserOptions, | ||
{ futureDefaults } | ||
{ futureDefaults, isNode } | ||
) => { | ||
@@ -476,2 +478,6 @@ D(parserOptions, "unknownContextRequest", "."); | ||
D(parserOptions, "importMeta", true); | ||
D(parserOptions, "dynamicImportMode", "lazy"); | ||
D(parserOptions, "dynamicImportPrefetch", false); | ||
D(parserOptions, "dynamicImportPreload", false); | ||
D(parserOptions, "createRequire", isNode); | ||
if (futureDefaults) D(parserOptions, "exportsPresence", "error"); | ||
@@ -486,4 +492,5 @@ }; | ||
* @param {boolean} options.asyncWebAssembly is asyncWebAssembly enabled | ||
* @param {CssExperimentOptions} options.css is css enabled | ||
* @param {CssExperimentOptions|false} options.css is css enabled | ||
* @param {boolean} options.futureDefaults is future defaults enabled | ||
* @param {boolean} options.isNode is node target platform | ||
* @returns {void} | ||
@@ -493,3 +500,3 @@ */ | ||
module, | ||
{ cache, syncWebAssembly, asyncWebAssembly, css, futureDefaults } | ||
{ cache, syncWebAssembly, asyncWebAssembly, css, futureDefaults, isNode } | ||
) => { | ||
@@ -513,3 +520,4 @@ if (cache) { | ||
applyJavascriptParserOptionsDefaults(module.parser.javascript, { | ||
futureDefaults | ||
futureDefaults, | ||
isNode | ||
}); | ||
@@ -1124,3 +1132,3 @@ | ||
* @param {boolean} options.development is development | ||
* @param {CssExperimentOptions} options.css is css enabled | ||
* @param {CssExperimentOptions|false} options.css is css enabled | ||
* @param {boolean} options.records using records | ||
@@ -1127,0 +1135,0 @@ * @returns {void} |
@@ -181,7 +181,6 @@ /* | ||
experiments.lazyCompilation, | ||
options => | ||
options === true ? {} : options === false ? undefined : options | ||
options => (options === true ? {} : options) | ||
), | ||
css: optionalNestedConfig(experiments.css, options => | ||
options === true ? {} : options === false ? undefined : options | ||
options === true ? {} : options | ||
) | ||
@@ -188,0 +187,0 @@ })), |
@@ -68,2 +68,3 @@ /* | ||
runtime: options.runtime, | ||
shareScope: options.shareScope, | ||
exposes: options.exposes | ||
@@ -80,2 +81,3 @@ }).apply(compiler); | ||
remoteType, | ||
shareScope: options.shareScope, | ||
remotes: options.remotes | ||
@@ -82,0 +84,0 @@ }).apply(compiler); |
@@ -111,9 +111,11 @@ /* | ||
crossOriginLoading | ||
? Template.asString([ | ||
"if (link.src.indexOf(window.location.origin + '/') !== 0) {", | ||
Template.indent( | ||
`link.crossOrigin = ${JSON.stringify(crossOriginLoading)};` | ||
), | ||
"}" | ||
]) | ||
? crossOriginLoading === "use-credentials" | ||
? 'link.crossOrigin = "use-credentials";' | ||
: Template.asString([ | ||
"if (link.src.indexOf(window.location.origin + '/') !== 0) {", | ||
Template.indent( | ||
`link.crossOrigin = ${JSON.stringify(crossOriginLoading)};` | ||
), | ||
"}" | ||
]) | ||
: "" | ||
@@ -120,0 +122,0 @@ ]); |
@@ -199,3 +199,3 @@ /* | ||
} | ||
return [pos, text.trimRight()]; | ||
return [pos, text.trimEnd()]; | ||
}; | ||
@@ -202,0 +202,0 @@ const eatExportName = eatUntil(":};/"); |
@@ -8,5 +8,8 @@ /* | ||
const { fileURLToPath } = require("url"); | ||
const CommentCompilationWarning = require("../CommentCompilationWarning"); | ||
const RuntimeGlobals = require("../RuntimeGlobals"); | ||
const UnsupportedFeatureWarning = require("../UnsupportedFeatureWarning"); | ||
const WebpackError = require("../WebpackError"); | ||
const BasicEvaluatedExpression = require("../javascript/BasicEvaluatedExpression"); | ||
const { | ||
@@ -30,4 +33,8 @@ evaluateToIdentifier, | ||
/** @typedef {import("estree").CallExpression} CallExpressionNode */ | ||
/** @typedef {import("../../declarations/WebpackOptions").JavascriptParserOptions} JavascriptParserOptions */ | ||
const createRequireSpecifierTag = Symbol("createRequire"); | ||
const createdRequireIdentifierTag = Symbol("createRequire()"); | ||
class CommonJsImportsParserPlugin { | ||
@@ -44,3 +51,10 @@ /** | ||
// metadata // | ||
const getContext = () => { | ||
if (parser.currentTagData) { | ||
const { context } = parser.currentTagData; | ||
return context; | ||
} | ||
}; | ||
//#region metadata | ||
const tapRequireExpression = (expression, getMembers) => { | ||
@@ -50,3 +64,3 @@ parser.hooks.typeof | ||
.tap( | ||
"CommonJsPlugin", | ||
"CommonJsImportsParserPlugin", | ||
toConstantDependency(parser, JSON.stringify("function")) | ||
@@ -56,31 +70,45 @@ ); | ||
.for(expression) | ||
.tap("CommonJsPlugin", evaluateToString("function")); | ||
.tap("CommonJsImportsParserPlugin", evaluateToString("function")); | ||
parser.hooks.evaluateIdentifier | ||
.for(expression) | ||
.tap( | ||
"CommonJsPlugin", | ||
"CommonJsImportsParserPlugin", | ||
evaluateToIdentifier(expression, "require", getMembers, true) | ||
); | ||
}; | ||
const tapRequireExpressionTag = tag => { | ||
parser.hooks.typeof | ||
.for(tag) | ||
.tap( | ||
"CommonJsImportsParserPlugin", | ||
toConstantDependency(parser, JSON.stringify("function")) | ||
); | ||
parser.hooks.evaluateTypeof | ||
.for(tag) | ||
.tap("CommonJsImportsParserPlugin", evaluateToString("function")); | ||
}; | ||
tapRequireExpression("require", () => []); | ||
tapRequireExpression("require.resolve", () => ["resolve"]); | ||
tapRequireExpression("require.resolveWeak", () => ["resolveWeak"]); | ||
//#endregion | ||
// Weird stuff // | ||
parser.hooks.assign.for("require").tap("CommonJsPlugin", expr => { | ||
// to not leak to global "require", we need to define a local require here. | ||
const dep = new ConstDependency("var require;", 0); | ||
dep.loc = expr.loc; | ||
parser.state.module.addPresentationalDependency(dep); | ||
return true; | ||
}); | ||
parser.hooks.assign | ||
.for("require") | ||
.tap("CommonJsImportsParserPlugin", expr => { | ||
// to not leak to global "require", we need to define a local require here. | ||
const dep = new ConstDependency("var require;", 0); | ||
dep.loc = expr.loc; | ||
parser.state.module.addPresentationalDependency(dep); | ||
return true; | ||
}); | ||
// Unsupported // | ||
//#region Unsupported | ||
parser.hooks.expression | ||
.for("require.main.require") | ||
.for("require.main") | ||
.tap( | ||
"CommonJsPlugin", | ||
"CommonJsImportsParserPlugin", | ||
expressionIsUnsupported( | ||
parser, | ||
"require.main.require is not supported by webpack." | ||
"require.main is not supported by webpack." | ||
) | ||
@@ -91,3 +119,3 @@ ); | ||
.tap( | ||
"CommonJsPlugin", | ||
"CommonJsImportsParserPlugin", | ||
expressionIsUnsupported( | ||
@@ -101,3 +129,3 @@ parser, | ||
.tap( | ||
"CommonJsPlugin", | ||
"CommonJsImportsParserPlugin", | ||
expressionIsUnsupported( | ||
@@ -111,3 +139,3 @@ parser, | ||
.tap( | ||
"CommonJsPlugin", | ||
"CommonJsImportsParserPlugin", | ||
expressionIsUnsupported( | ||
@@ -118,6 +146,6 @@ parser, | ||
); | ||
//#endregion | ||
// renaming // | ||
parser.hooks.canRename.for("require").tap("CommonJsPlugin", () => true); | ||
parser.hooks.rename.for("require").tap("CommonJsPlugin", expr => { | ||
//#region Renaming | ||
const defineUndefined = expr => { | ||
// To avoid "not defined" error, replace the value with undefined | ||
@@ -128,44 +156,62 @@ const dep = new ConstDependency("undefined", expr.range); | ||
return false; | ||
}); | ||
}; | ||
parser.hooks.canRename | ||
.for("require") | ||
.tap("CommonJsImportsParserPlugin", () => true); | ||
parser.hooks.rename | ||
.for("require") | ||
.tap("CommonJsImportsParserPlugin", defineUndefined); | ||
//#endregion | ||
// inspection // | ||
//#region Inspection | ||
const requireCache = toConstantDependency( | ||
parser, | ||
RuntimeGlobals.moduleCache, | ||
[ | ||
RuntimeGlobals.moduleCache, | ||
RuntimeGlobals.moduleId, | ||
RuntimeGlobals.moduleLoaded | ||
] | ||
); | ||
parser.hooks.expression | ||
.for("require.cache") | ||
.tap( | ||
"CommonJsImportsParserPlugin", | ||
toConstantDependency(parser, RuntimeGlobals.moduleCache, [ | ||
RuntimeGlobals.moduleCache, | ||
RuntimeGlobals.moduleId, | ||
RuntimeGlobals.moduleLoaded | ||
]) | ||
.tap("CommonJsImportsParserPlugin", requireCache); | ||
//#endregion | ||
//#region Require as expression | ||
const requireAsExpressionHandler = expr => { | ||
const dep = new CommonJsRequireContextDependency( | ||
{ | ||
request: options.unknownContextRequest, | ||
recursive: options.unknownContextRecursive, | ||
regExp: options.unknownContextRegExp, | ||
mode: "sync" | ||
}, | ||
expr.range, | ||
undefined, | ||
parser.scope.inShorthand, | ||
getContext() | ||
); | ||
// require as expression // | ||
dep.critical = | ||
options.unknownContextCritical && | ||
"require function is used in a way in which dependencies cannot be statically extracted"; | ||
dep.loc = expr.loc; | ||
dep.optional = !!parser.scope.inTry; | ||
parser.state.current.addDependency(dep); | ||
return true; | ||
}; | ||
parser.hooks.expression | ||
.for("require") | ||
.tap("CommonJsImportsParserPlugin", expr => { | ||
const dep = new CommonJsRequireContextDependency( | ||
{ | ||
request: options.unknownContextRequest, | ||
recursive: options.unknownContextRecursive, | ||
regExp: options.unknownContextRegExp, | ||
mode: "sync" | ||
}, | ||
expr.range, | ||
undefined, | ||
parser.scope.inShorthand | ||
); | ||
dep.critical = | ||
options.unknownContextCritical && | ||
"require function is used in a way in which dependencies cannot be statically extracted"; | ||
dep.loc = expr.loc; | ||
dep.optional = !!parser.scope.inTry; | ||
parser.state.current.addDependency(dep); | ||
return true; | ||
}); | ||
.tap("CommonJsImportsParserPlugin", requireAsExpressionHandler); | ||
//#endregion | ||
// require // | ||
//#region Require | ||
const processRequireItem = (expr, param) => { | ||
if (param.isString()) { | ||
const dep = new CommonJsRequireDependency(param.string, param.range); | ||
const dep = new CommonJsRequireDependency( | ||
param.string, | ||
param.range, | ||
getContext() | ||
); | ||
dep.loc = expr.loc; | ||
@@ -187,3 +233,5 @@ dep.optional = !!parser.scope.inTry; | ||
}, | ||
parser | ||
parser, | ||
undefined, | ||
getContext() | ||
); | ||
@@ -282,4 +330,5 @@ if (!dep) return; | ||
.tap("CommonJsImportsParserPlugin", createRequireHandler(true)); | ||
//#endregion | ||
// require with property access // | ||
//#region Require with property access | ||
const chainHandler = (expr, calleeMembers, callExpr, members) => { | ||
@@ -331,4 +380,5 @@ if (callExpr.arguments.length !== 1) return; | ||
.tap("CommonJsImportsParserPlugin", callChainHandler); | ||
//#endregion | ||
// require.resolve // | ||
//#region Require.resolve | ||
const processResolve = (expr, weak) => { | ||
@@ -361,3 +411,7 @@ if (expr.arguments.length !== 1) return; | ||
if (param.isString()) { | ||
const dep = new RequireResolveDependency(param.string, param.range); | ||
const dep = new RequireResolveDependency( | ||
param.string, | ||
param.range, | ||
getContext() | ||
); | ||
dep.loc = expr.loc; | ||
@@ -381,3 +435,4 @@ dep.optional = !!parser.scope.inTry; | ||
}, | ||
parser | ||
parser, | ||
getContext() | ||
); | ||
@@ -393,3 +448,3 @@ if (!dep) return; | ||
.for("require.resolve") | ||
.tap("RequireResolveDependencyParserPlugin", expr => { | ||
.tap("CommonJsImportsParserPlugin", expr => { | ||
return processResolve(expr, false); | ||
@@ -399,7 +454,233 @@ }); | ||
.for("require.resolveWeak") | ||
.tap("RequireResolveDependencyParserPlugin", expr => { | ||
.tap("CommonJsImportsParserPlugin", expr => { | ||
return processResolve(expr, true); | ||
}); | ||
//#endregion | ||
//#region Create require | ||
if (!options.createRequire) return; | ||
let moduleName; | ||
let specifierName; | ||
if (options.createRequire === true) { | ||
moduleName = "module"; | ||
specifierName = "createRequire"; | ||
} else { | ||
const match = /^(.*) from (.*)$/.exec(options.createRequire); | ||
if (match) { | ||
[, specifierName, moduleName] = match; | ||
} | ||
if (!specifierName || !moduleName) { | ||
const err = new WebpackError( | ||
`Parsing javascript parser option "createRequire" failed, got ${JSON.stringify( | ||
options.createRequire | ||
)}` | ||
); | ||
err.details = | ||
'Expected string in format "createRequire from module", where "createRequire" is specifier name and "module" name of the module'; | ||
throw err; | ||
} | ||
} | ||
tapRequireExpressionTag(createdRequireIdentifierTag); | ||
tapRequireExpressionTag(createRequireSpecifierTag); | ||
parser.hooks.evaluateCallExpression | ||
.for(createRequireSpecifierTag) | ||
.tap("CommonJsImportsParserPlugin", expr => { | ||
const context = parseCreateRequireArguments(expr); | ||
if (context === undefined) return; | ||
const ident = parser.evaluatedVariable({ | ||
tag: createdRequireIdentifierTag, | ||
data: { context }, | ||
next: undefined | ||
}); | ||
return new BasicEvaluatedExpression() | ||
.setIdentifier(ident, ident, () => []) | ||
.setSideEffects(false) | ||
.setRange(expr.range); | ||
}); | ||
parser.hooks.unhandledExpressionMemberChain | ||
.for(createdRequireIdentifierTag) | ||
.tap("CommonJsImportsParserPlugin", (expr, members) => { | ||
return expressionIsUnsupported( | ||
parser, | ||
`createRequire().${members.join(".")} is not supported by webpack.` | ||
)(expr); | ||
}); | ||
parser.hooks.canRename | ||
.for(createdRequireIdentifierTag) | ||
.tap("CommonJsImportsParserPlugin", () => true); | ||
parser.hooks.canRename | ||
.for(createRequireSpecifierTag) | ||
.tap("CommonJsImportsParserPlugin", () => true); | ||
parser.hooks.rename | ||
.for(createRequireSpecifierTag) | ||
.tap("CommonJsImportsParserPlugin", defineUndefined); | ||
parser.hooks.expression | ||
.for(createdRequireIdentifierTag) | ||
.tap("CommonJsImportsParserPlugin", requireAsExpressionHandler); | ||
parser.hooks.call | ||
.for(createdRequireIdentifierTag) | ||
.tap("CommonJsImportsParserPlugin", createRequireHandler(false)); | ||
/** | ||
* @param {CallExpressionNode} expr call expression | ||
* @returns {string} context | ||
*/ | ||
const parseCreateRequireArguments = expr => { | ||
const args = expr.arguments; | ||
if (args.length !== 1) { | ||
const err = new WebpackError( | ||
"module.createRequire supports only one argument." | ||
); | ||
err.loc = expr.loc; | ||
parser.state.module.addWarning(err); | ||
return; | ||
} | ||
const arg = args[0]; | ||
const evaluated = parser.evaluateExpression(arg); | ||
if (!evaluated.isString()) { | ||
const err = new WebpackError( | ||
"module.createRequire failed parsing argument." | ||
); | ||
err.loc = arg.loc; | ||
parser.state.module.addWarning(err); | ||
return; | ||
} | ||
const ctx = evaluated.string.startsWith("file://") | ||
? fileURLToPath(evaluated.string) | ||
: evaluated.string; | ||
// argument always should be a filename | ||
return ctx.slice(0, ctx.lastIndexOf(ctx.startsWith("/") ? "/" : "\\")); | ||
}; | ||
parser.hooks.import.tap( | ||
{ | ||
name: "CommonJsImportsParserPlugin", | ||
stage: -10 | ||
}, | ||
(statement, source) => { | ||
if ( | ||
source !== moduleName || | ||
statement.specifiers.length !== 1 || | ||
statement.specifiers[0].type !== "ImportSpecifier" || | ||
statement.specifiers[0].imported.type !== "Identifier" || | ||
statement.specifiers[0].imported.name !== specifierName | ||
) | ||
return; | ||
// clear for 'import { createRequire as x } from "module"' | ||
// if any other specifier was used import module | ||
const clearDep = new ConstDependency( | ||
parser.isAsiPosition(statement.range[0]) ? ";" : "", | ||
statement.range | ||
); | ||
clearDep.loc = statement.loc; | ||
parser.state.module.addPresentationalDependency(clearDep); | ||
parser.unsetAsiPosition(statement.range[1]); | ||
return true; | ||
} | ||
); | ||
parser.hooks.importSpecifier.tap( | ||
{ | ||
name: "CommonJsImportsParserPlugin", | ||
stage: -10 | ||
}, | ||
(statement, source, id, name) => { | ||
if (source !== moduleName || id !== specifierName) return; | ||
parser.tagVariable(name, createRequireSpecifierTag); | ||
return true; | ||
} | ||
); | ||
parser.hooks.preDeclarator.tap( | ||
"CommonJsImportsParserPlugin", | ||
declarator => { | ||
if ( | ||
declarator.id.type !== "Identifier" || | ||
!declarator.init || | ||
declarator.init.type !== "CallExpression" || | ||
declarator.init.callee.type !== "Identifier" | ||
) | ||
return; | ||
const variableInfo = parser.getVariableInfo( | ||
declarator.init.callee.name | ||
); | ||
if ( | ||
variableInfo && | ||
variableInfo.tagInfo && | ||
variableInfo.tagInfo.tag === createRequireSpecifierTag | ||
) { | ||
const context = parseCreateRequireArguments(declarator.init); | ||
if (context === undefined) return; | ||
parser.tagVariable(declarator.id.name, createdRequireIdentifierTag, { | ||
name: declarator.id.name, | ||
context | ||
}); | ||
return true; | ||
} | ||
} | ||
); | ||
parser.hooks.memberChainOfCallMemberChain | ||
.for(createRequireSpecifierTag) | ||
.tap( | ||
"CommonJsImportsParserPlugin", | ||
(expr, calleeMembers, callExpr, members) => { | ||
if ( | ||
calleeMembers.length !== 0 || | ||
members.length !== 1 || | ||
members[0] !== "cache" | ||
) | ||
return; | ||
// createRequire().cache | ||
const context = parseCreateRequireArguments(callExpr); | ||
if (context === undefined) return; | ||
return requireCache(expr); | ||
} | ||
); | ||
parser.hooks.callMemberChainOfCallMemberChain | ||
.for(createRequireSpecifierTag) | ||
.tap( | ||
"CommonJsImportsParserPlugin", | ||
(expr, calleeMembers, innerCallExpression, members) => { | ||
if ( | ||
calleeMembers.length !== 0 || | ||
members.length !== 1 || | ||
members[0] !== "resolve" | ||
) | ||
return; | ||
// createRequire().resolve() | ||
return processResolve(expr, false); | ||
} | ||
); | ||
parser.hooks.expressionMemberChain | ||
.for(createdRequireIdentifierTag) | ||
.tap("CommonJsImportsParserPlugin", (expr, members) => { | ||
// require.cache | ||
if (members.length === 1 && members[0] === "cache") { | ||
return requireCache(expr); | ||
} | ||
}); | ||
parser.hooks.callMemberChain | ||
.for(createdRequireIdentifierTag) | ||
.tap("CommonJsImportsParserPlugin", (expr, members) => { | ||
// require.resolve() | ||
if (members.length === 1 && members[0] === "resolve") { | ||
return processResolve(expr, false); | ||
} | ||
}); | ||
parser.hooks.call | ||
.for(createRequireSpecifierTag) | ||
.tap("CommonJsImportsParserPlugin", expr => { | ||
const clearDep = new ConstDependency( | ||
"/* createRequire() */ undefined", | ||
expr.range | ||
); | ||
clearDep.loc = expr.loc; | ||
parser.state.module.addPresentationalDependency(clearDep); | ||
return true; | ||
}); | ||
//#endregion | ||
} | ||
} | ||
module.exports = CommonJsImportsParserPlugin; |
@@ -13,4 +13,4 @@ /* | ||
class CommonJsRequireContextDependency extends ContextDependency { | ||
constructor(options, range, valueRange, inShorthand) { | ||
super(options); | ||
constructor(options, range, valueRange, inShorthand, context) { | ||
super(options, context); | ||
@@ -17,0 +17,0 @@ this.range = range; |
@@ -13,5 +13,6 @@ /* | ||
class CommonJsRequireDependency extends ModuleDependency { | ||
constructor(request, range) { | ||
constructor(request, range, context) { | ||
super(request); | ||
this.range = range; | ||
this._context = context; | ||
} | ||
@@ -18,0 +19,0 @@ |
@@ -29,4 +29,5 @@ /* | ||
* @param {ContextDependencyOptions} options options for the context module | ||
* @param {string=} context request context | ||
*/ | ||
constructor(options) { | ||
constructor(options, context) { | ||
super(); | ||
@@ -54,4 +55,12 @@ | ||
this.replaces = undefined; | ||
this._requestContext = context; | ||
} | ||
/** | ||
* @returns {string | undefined} a request context | ||
*/ | ||
getContext() { | ||
return this._requestContext; | ||
} | ||
get category() { | ||
@@ -73,3 +82,5 @@ return "commonjs"; | ||
return ( | ||
`context${this.options.request} ${this.options.recursive} ` + | ||
`context${this._requestContext || ""}|ctx request${ | ||
this.options.request | ||
} ${this.options.recursive} ` + | ||
`${regExpToString(this.options.regExp)} ${regExpToString( | ||
@@ -118,2 +129,3 @@ this.options.include | ||
write(this.request); | ||
write(this._requestContext); | ||
write(this.range); | ||
@@ -135,2 +147,3 @@ write(this.valueRange); | ||
this.request = read(); | ||
this._requestContext = read(); | ||
this.range = read(); | ||
@@ -137,0 +150,0 @@ this.valueRange = read(); |
@@ -42,3 +42,3 @@ /* | ||
/** @typedef {{ new(options: ContextDependencyOptions, range: [number, number], valueRange: [number, number]): ContextDependency }} ContextDependencyConstructor */ | ||
/** @typedef {{ new(options: ContextDependencyOptions, range: [number, number], valueRange: [number, number], ...args: any[]): ContextDependency }} ContextDependencyConstructor */ | ||
@@ -53,5 +53,15 @@ /** | ||
* @param {JavascriptParser} parser the parser | ||
* @param {...any} depArgs depArgs | ||
* @returns {ContextDependency} the created Dependency | ||
*/ | ||
exports.create = (Dep, range, param, expr, options, contextOptions, parser) => { | ||
exports.create = ( | ||
Dep, | ||
range, | ||
param, | ||
expr, | ||
options, | ||
contextOptions, | ||
parser, | ||
...depArgs | ||
) => { | ||
if (param.isTemplateString()) { | ||
@@ -102,3 +112,4 @@ let prefixRaw = param.quasis[0].string; | ||
range, | ||
valueRange | ||
valueRange, | ||
...depArgs | ||
); | ||
@@ -186,3 +197,4 @@ dep.loc = expr.loc; | ||
range, | ||
valueRange | ||
valueRange, | ||
...depArgs | ||
); | ||
@@ -225,3 +237,4 @@ dep.loc = expr.loc; | ||
range, | ||
param.range | ||
param.range, | ||
...depArgs | ||
); | ||
@@ -228,0 +241,0 @@ dep.loc = expr.loc; |
@@ -52,16 +52,2 @@ /* | ||
/** | ||
* @returns {string | undefined} a request context | ||
*/ | ||
getContext() { | ||
return this._context; | ||
} | ||
/** | ||
* @returns {string | null} an identifier to merge equal requests | ||
*/ | ||
getResourceIdentifier() { | ||
return `context${this._context || ""}|${super.getResourceIdentifier()}`; | ||
} | ||
get category() { | ||
@@ -90,3 +76,2 @@ return this._category; | ||
write(this._category); | ||
write(this._context); | ||
write(this.referencedExports); | ||
@@ -100,3 +85,2 @@ super.serialize(context); | ||
this._category = read(); | ||
this._context = read(); | ||
this.referencedExports = read(); | ||
@@ -103,0 +87,0 @@ super.deserialize(context); |
@@ -106,3 +106,3 @@ /* | ||
if (typeof value === "boolean") { | ||
source.replace(dep.range[0], dep.range[1] - 1, `${value}`); | ||
source.replace(dep.range[0], dep.range[1] - 1, ` ${value}`); | ||
} else { | ||
@@ -109,0 +109,0 @@ const usedName = exportsInfo.getUsedName(ids, runtime); |
@@ -41,3 +41,3 @@ /* | ||
.for("import.meta.webpackContext") | ||
.tap("HotModuleReplacementPlugin", expr => { | ||
.tap("ImportMetaContextDependencyParserPlugin", expr => { | ||
return evaluateToIdentifier( | ||
@@ -44,0 +44,0 @@ "import.meta.webpackContext", |
@@ -17,2 +17,3 @@ /* | ||
/** @typedef {import("../../declarations/WebpackOptions").JavascriptParserOptions} JavascriptParserOptions */ | ||
/** @typedef {import("../ChunkGroup").RawChunkGroupOptions} RawChunkGroupOptions */ | ||
@@ -22,2 +23,5 @@ /** @typedef {import("../ContextModule").ContextMode} ContextMode */ | ||
class ImportParserPlugin { | ||
/** | ||
* @param {JavascriptParserOptions} options options | ||
*/ | ||
constructor(options) { | ||
@@ -33,3 +37,3 @@ this.options = options; | ||
/** @type {ContextMode} */ | ||
let mode = "lazy"; | ||
let mode = this.options.dynamicImportMode; | ||
let include = null; | ||
@@ -42,2 +46,13 @@ let exclude = null; | ||
const { dynamicImportPreload, dynamicImportPrefetch } = this.options; | ||
if (dynamicImportPreload !== undefined && dynamicImportPreload !== false) | ||
groupOptions.preloadOrder = | ||
dynamicImportPreload === true ? 0 : dynamicImportPreload; | ||
if ( | ||
dynamicImportPrefetch !== undefined && | ||
dynamicImportPrefetch !== false | ||
) | ||
groupOptions.prefetchOrder = | ||
dynamicImportPrefetch === true ? 0 : dynamicImportPrefetch; | ||
const { options: importOptions, errors: commentErrors } = | ||
@@ -129,3 +144,3 @@ parser.parseCommentOptions(expr.range); | ||
!importOptions.webpackInclude || | ||
importOptions.webpackInclude.constructor.name !== "RegExp" | ||
!(importOptions.webpackInclude instanceof RegExp) | ||
) { | ||
@@ -139,3 +154,3 @@ parser.state.module.addWarning( | ||
} else { | ||
include = new RegExp(importOptions.webpackInclude); | ||
include = importOptions.webpackInclude; | ||
} | ||
@@ -146,3 +161,3 @@ } | ||
!importOptions.webpackExclude || | ||
importOptions.webpackExclude.constructor.name !== "RegExp" | ||
!(importOptions.webpackExclude instanceof RegExp) | ||
) { | ||
@@ -156,3 +171,3 @@ parser.state.module.addWarning( | ||
} else { | ||
exclude = new RegExp(importOptions.webpackExclude); | ||
exclude = importOptions.webpackExclude; | ||
} | ||
@@ -186,12 +201,18 @@ } | ||
if ( | ||
mode !== "lazy" && | ||
mode !== "lazy-once" && | ||
mode !== "eager" && | ||
mode !== "weak" | ||
) { | ||
parser.state.module.addWarning( | ||
new UnsupportedFeatureWarning( | ||
`\`webpackMode\` expected 'lazy', 'lazy-once', 'eager' or 'weak', but received: ${mode}.`, | ||
expr.loc | ||
) | ||
); | ||
mode = "lazy"; | ||
} | ||
if (param.isString()) { | ||
if (mode !== "lazy" && mode !== "eager" && mode !== "weak") { | ||
parser.state.module.addWarning( | ||
new UnsupportedFeatureWarning( | ||
`\`webpackMode\` expected 'lazy', 'eager' or 'weak', but received: ${mode}.`, | ||
expr.loc | ||
) | ||
); | ||
} | ||
if (mode === "eager") { | ||
@@ -227,17 +248,2 @@ const dep = new ImportEagerDependency( | ||
} else { | ||
if ( | ||
mode !== "lazy" && | ||
mode !== "lazy-once" && | ||
mode !== "eager" && | ||
mode !== "weak" | ||
) { | ||
parser.state.module.addWarning( | ||
new UnsupportedFeatureWarning( | ||
`\`webpackMode\` expected 'lazy', 'lazy-once', 'eager' or 'weak', but received: ${mode}.`, | ||
expr.loc | ||
) | ||
); | ||
mode = "lazy"; | ||
} | ||
if (mode === "weak") { | ||
@@ -244,0 +250,0 @@ mode = "async-weak"; |
@@ -16,2 +16,3 @@ /* | ||
/** @typedef {import("../ModuleGraph")} ModuleGraph */ | ||
/** @typedef {import("../json/JsonData")} JsonData */ | ||
/** @typedef {import("../util/Hash")} Hash */ | ||
@@ -22,9 +23,11 @@ | ||
if (Array.isArray(data)) { | ||
return data.map((item, idx) => { | ||
return { | ||
name: `${idx}`, | ||
canMangle: true, | ||
exports: getExportsFromData(item) | ||
}; | ||
}); | ||
return data.length < 100 | ||
? data.map((item, idx) => { | ||
return { | ||
name: `${idx}`, | ||
canMangle: true, | ||
exports: getExportsFromData(item) | ||
}; | ||
}) | ||
: undefined; | ||
} else { | ||
@@ -47,8 +50,7 @@ const exports = []; | ||
/** | ||
* @param {(string | ExportSpec)[]} exports json exports | ||
* @param {JsonData=} data json data | ||
*/ | ||
constructor(exports) { | ||
constructor(data) { | ||
super(); | ||
this.exports = exports; | ||
this._hashUpdate = undefined; | ||
this.data = data; | ||
} | ||
@@ -67,3 +69,3 @@ | ||
return { | ||
exports: this.exports, | ||
exports: getExportsFromData(this.data && this.data.get()), | ||
dependencies: undefined | ||
@@ -80,8 +82,3 @@ }; | ||
updateHash(hash, context) { | ||
if (this._hashUpdate === undefined) { | ||
this._hashUpdate = this.exports | ||
? JSON.stringify(this.exports) | ||
: "undefined"; | ||
} | ||
hash.update(this._hashUpdate); | ||
this.data.updateHash(hash); | ||
} | ||
@@ -91,3 +88,3 @@ | ||
const { write } = context; | ||
write(this.exports); | ||
write(this.data); | ||
super.serialize(context); | ||
@@ -98,3 +95,3 @@ } | ||
const { read } = context; | ||
this.exports = read(); | ||
this.data = read(); | ||
super.deserialize(context); | ||
@@ -110,2 +107,1 @@ } | ||
module.exports = JsonExportsDependency; | ||
module.exports.getExportsFromData = getExportsFromData; |
@@ -29,9 +29,17 @@ /* | ||
this.assertions = undefined; | ||
this._context = undefined; | ||
} | ||
/** | ||
* @returns {string | undefined} a request context | ||
*/ | ||
getContext() { | ||
return this._context; | ||
} | ||
/** | ||
* @returns {string | null} an identifier to merge equal requests | ||
*/ | ||
getResourceIdentifier() { | ||
let str = `module${this.request}`; | ||
let str = `context${this._context || ""}|module${this.request}`; | ||
if (this.assertions !== undefined) { | ||
@@ -67,2 +75,3 @@ str += JSON.stringify(this.assertions); | ||
write(this.userRequest); | ||
write(this._context); | ||
write(this.range); | ||
@@ -76,2 +85,3 @@ super.serialize(context); | ||
this.userRequest = read(); | ||
this._context = read(); | ||
this.range = read(); | ||
@@ -78,0 +88,0 @@ super.deserialize(context); |
@@ -8,2 +8,3 @@ /* | ||
const Dependency = require("../Dependency"); | ||
const InitFragment = require("../InitFragment"); | ||
@@ -15,3 +16,3 @@ const makeSerializable = require("../util/makeSerializable"); | ||
/** @typedef {import("../ChunkGraph")} ChunkGraph */ | ||
/** @typedef {import("../Dependency")} Dependency */ | ||
/** @typedef {import("../Dependency").ReferencedExport} ReferencedExport */ | ||
/** @typedef {import("../Dependency").UpdateHashContext} UpdateHashContext */ | ||
@@ -23,2 +24,3 @@ /** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */ | ||
/** @typedef {import("../util/Hash")} Hash */ | ||
/** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */ | ||
@@ -35,6 +37,12 @@ /** | ||
class ProvidedDependency extends ModuleDependency { | ||
constructor(request, identifier, path, range) { | ||
/** | ||
* @param {string} request request | ||
* @param {string} identifier identifier | ||
* @param {string[]} ids ids | ||
* @param {[number, number]} range range | ||
*/ | ||
constructor(request, identifier, ids, range) { | ||
super(request); | ||
this.identifier = identifier; | ||
this.path = path; | ||
this.ids = ids; | ||
this.range = range; | ||
@@ -53,2 +61,14 @@ this._hashUpdate = undefined; | ||
/** | ||
* Returns list of exports referenced by this dependency | ||
* @param {ModuleGraph} moduleGraph module graph | ||
* @param {RuntimeSpec} runtime the runtime for which the module is analysed | ||
* @returns {(string[] | ReferencedExport)[]} referenced exports | ||
*/ | ||
getReferencedExports(moduleGraph, runtime) { | ||
let ids = this.ids; | ||
if (ids.length === 0) return Dependency.EXPORTS_OBJECT_REFERENCED; | ||
return [ids]; | ||
} | ||
/** | ||
* Update the hash | ||
@@ -61,4 +81,3 @@ * @param {Hash} hash hash to be updated | ||
if (this._hashUpdate === undefined) { | ||
this._hashUpdate = | ||
this.identifier + (this.path ? this.path.join(",") : "null"); | ||
this._hashUpdate = this.identifier + (this.ids ? this.ids.join(",") : ""); | ||
} | ||
@@ -71,3 +90,3 @@ hash.update(this._hashUpdate); | ||
write(this.identifier); | ||
write(this.path); | ||
write(this.ids); | ||
super.serialize(context); | ||
@@ -79,3 +98,3 @@ } | ||
this.identifier = read(); | ||
this.path = read(); | ||
this.ids = read(); | ||
super.deserialize(context); | ||
@@ -101,2 +120,3 @@ } | ||
{ | ||
runtime, | ||
runtimeTemplate, | ||
@@ -110,2 +130,5 @@ moduleGraph, | ||
const dep = /** @type {ProvidedDependency} */ (dependency); | ||
const connection = moduleGraph.getConnection(dep); | ||
const exportsInfo = moduleGraph.getExportsInfo(connection.module); | ||
const usedName = exportsInfo.getUsedName(dep.ids, runtime); | ||
initFragments.push( | ||
@@ -120,3 +143,3 @@ new InitFragment( | ||
runtimeRequirements | ||
})}${pathToString(dep.path)};\n`, | ||
})}${pathToString(/** @type {string[]} */ (usedName))};\n`, | ||
InitFragment.STAGE_PROVIDES, | ||
@@ -123,0 +146,0 @@ 1, |
@@ -13,4 +13,4 @@ /* | ||
class RequireResolveContextDependency extends ContextDependency { | ||
constructor(options, range, valueRange) { | ||
super(options); | ||
constructor(options, range, valueRange, context) { | ||
super(options, context); | ||
@@ -17,0 +17,0 @@ this.range = range; |
@@ -18,6 +18,7 @@ /* | ||
class RequireResolveDependency extends ModuleDependency { | ||
constructor(request, range) { | ||
constructor(request, range, context) { | ||
super(request); | ||
this.range = range; | ||
this._context = context; | ||
} | ||
@@ -24,0 +25,0 @@ |
@@ -8,2 +8,4 @@ /* | ||
const { pathToFileURL } = require("url"); | ||
const BasicEvaluatedExpression = require("../javascript/BasicEvaluatedExpression"); | ||
const { approve } = require("../javascript/JavascriptParserHelpers"); | ||
@@ -15,2 +17,3 @@ const InnerGraph = require("../optimize/InnerGraph"); | ||
/** @typedef {import("../Compiler")} Compiler */ | ||
/** @typedef {import("../NormalModule")} NormalModule */ | ||
/** @typedef {import("../javascript/JavascriptParser")} JavascriptParser */ | ||
@@ -33,2 +36,9 @@ | ||
/** | ||
* @param {NormalModule} module module | ||
* @returns {URL} file url | ||
*/ | ||
const getUrl = module => { | ||
return pathToFileURL(module.resource); | ||
}; | ||
/** | ||
* @param {JavascriptParser} parser parser | ||
@@ -73,2 +83,13 @@ * @param {object} parserOptions options | ||
parser.hooks.canRename.for("URL").tap("URLPlugin", approve); | ||
parser.hooks.evaluateNewExpression | ||
.for("URL") | ||
.tap("URLPlugin", expr => { | ||
const request = getUrlRequest(expr); | ||
if (!request) return; | ||
const url = new URL(request, getUrl(parser.state.module)); | ||
return new BasicEvaluatedExpression() | ||
.setString(url.toString()) | ||
.setRange(expr.range); | ||
}); | ||
parser.hooks.new.for("URL").tap("URLPlugin", _expr => { | ||
@@ -75,0 +96,0 @@ const expr = /** @type {NewExpressionNode} */ (_expr); |
@@ -193,4 +193,6 @@ /* | ||
: { | ||
/** @type {Record<string, Expression | Pattern>} */ | ||
expressions: {}, | ||
otherElements: [], | ||
/** @type {Record<string, any>} */ | ||
values: {}, | ||
@@ -197,0 +199,0 @@ spread: false, |
@@ -21,2 +21,3 @@ /* | ||
/** @typedef {import("./Compiler")} Compiler */ | ||
/** @typedef {import("./NormalModule").SourceMap} SourceMap */ | ||
@@ -109,3 +110,3 @@ /** @type {WeakMap<Source, Source>} */ | ||
/** @type {{ [key: string]: TODO; }} */ | ||
/** @type {SourceMap} */ | ||
let sourceMap; | ||
@@ -115,6 +116,6 @@ let content; | ||
const sourceAndMap = source.sourceAndMap(options); | ||
sourceMap = sourceAndMap.map; | ||
sourceMap = /** @type {SourceMap} */ (sourceAndMap.map); | ||
content = sourceAndMap.source; | ||
} else { | ||
sourceMap = source.map(options); | ||
sourceMap = /** @type {SourceMap} */ (source.map(options)); | ||
content = source.source(); | ||
@@ -158,2 +159,5 @@ } | ||
sourceMap.sources = moduleFilenames; | ||
if (options.noSources) { | ||
sourceMap.sourcesContent = undefined; | ||
} | ||
sourceMap.sourceRoot = options.sourceRoot || ""; | ||
@@ -160,0 +164,0 @@ const moduleId = chunkGraph.getModuleId(m); |
@@ -390,3 +390,3 @@ /* | ||
const optimalRange = Math.min( | ||
Math.ceil(items.length * 20) + extraSpace, | ||
items.length * 20 + extraSpace, | ||
Number.MAX_SAFE_INTEGER | ||
@@ -393,0 +393,0 @@ ); |
@@ -31,2 +31,3 @@ /* | ||
/** @typedef {import("./Compilation").EntryOptions} EntryOptions */ | ||
/** @typedef {import("./Compilation").PathData} PathData */ | ||
/** @typedef {import("./Compiler").AssetEmittedInfo} AssetEmittedInfo */ | ||
@@ -345,2 +346,5 @@ /** @typedef {import("./MultiStats")} MultiStats */ | ||
}, | ||
get HarmonyImportDependency() { | ||
return require("./dependencies/HarmonyImportDependency"); | ||
}, | ||
get ConstDependency() { | ||
@@ -496,2 +500,5 @@ return require("./dependencies/ConstDependency"); | ||
return require("./wasm-async/AsyncWebAssemblyModulesPlugin"); | ||
}, | ||
get EnableWasmLoadingPlugin() { | ||
return require("./wasm/EnableWasmLoadingPlugin"); | ||
} | ||
@@ -498,0 +505,0 @@ }, |
@@ -27,2 +27,10 @@ /* | ||
} | ||
updateHash(hash) { | ||
if (this._buffer === undefined && this._data !== undefined) { | ||
this._buffer = Buffer.from(JSON.stringify(this._data)); | ||
} | ||
if (this._buffer) return hash.update(this._buffer); | ||
} | ||
} | ||
@@ -29,0 +37,0 @@ |
@@ -44,4 +44,4 @@ /* | ||
: parseFn(source[0] === "\ufeff" ? source.slice(1) : source); | ||
state.module.buildInfo.jsonData = new JsonData(data); | ||
const jsonData = new JsonData(data); | ||
state.module.buildInfo.jsonData = jsonData; | ||
state.module.buildInfo.strict = true; | ||
@@ -51,5 +51,3 @@ state.module.buildMeta.exportsType = "default"; | ||
typeof data === "object" ? "redirect-warn" : false; | ||
state.module.addDependency( | ||
new JsonExportsDependency(JsonExportsDependency.getExportsFromData(data)) | ||
); | ||
state.module.addDependency(new JsonExportsDependency(jsonData)); | ||
return state; | ||
@@ -56,0 +54,0 @@ } |
@@ -67,3 +67,3 @@ /* | ||
"global", | ||
"The global namespace object is Node.js feature and doesn't present in browser." | ||
"The global namespace object is a Node.js feature and isn't available in browsers." | ||
) | ||
@@ -121,3 +121,3 @@ ); | ||
"/index.js", | ||
"The __filename is Node.js feature and doesn't present in browser." | ||
"__filename is a Node.js feature and isn't available in browsers." | ||
); | ||
@@ -149,3 +149,3 @@ break; | ||
"/", | ||
"The __dirname is Node.js feature and doesn't present in browser." | ||
"__dirname is a Node.js feature and isn't available in browsers." | ||
); | ||
@@ -152,0 +152,0 @@ break; |
@@ -333,2 +333,4 @@ /* | ||
this._addedSideEffectsBailout = undefined; | ||
/** @type {Map<string, any>} */ | ||
this._codeGeneratorData = new Map(); | ||
} | ||
@@ -1192,7 +1194,5 @@ | ||
/** @type {Map<string, any>} */ | ||
let data; | ||
/** @type {function(): Map<string, any>} */ | ||
const getData = () => { | ||
if (data === undefined) data = new Map(); | ||
return data; | ||
return this._codeGeneratorData; | ||
}; | ||
@@ -1228,3 +1228,3 @@ | ||
runtimeRequirements, | ||
data | ||
data: this._codeGeneratorData | ||
}; | ||
@@ -1377,2 +1377,3 @@ return resultEntry; | ||
write(this._forceBuild); | ||
write(this._codeGeneratorData); | ||
super.serialize(context); | ||
@@ -1410,2 +1411,3 @@ } | ||
this._forceBuild = read(); | ||
this._codeGeneratorData = read(); | ||
super.deserialize(context); | ||
@@ -1412,0 +1414,0 @@ } |
@@ -24,3 +24,3 @@ /* | ||
const LazySet = require("../util/LazySet"); | ||
const { concatComparators, keepOriginalOrder } = require("../util/comparators"); | ||
const { concatComparators } = require("../util/comparators"); | ||
const createHash = require("../util/createHash"); | ||
@@ -189,15 +189,15 @@ const { makePathsRelative } = require("../util/identifier"); | ||
const bySourceOrder = (a, b) => { | ||
const aOrder = a.sourceOrder; | ||
const bOrder = b.sourceOrder; | ||
if (isNaN(aOrder)) { | ||
if (!isNaN(bOrder)) { | ||
const createComparator = (property, comparator) => (a, b) => | ||
comparator(a[property], b[property]); | ||
const compareNumbers = (a, b) => { | ||
if (isNaN(a)) { | ||
if (!isNaN(b)) { | ||
return 1; | ||
} | ||
} else { | ||
if (isNaN(bOrder)) { | ||
if (isNaN(b)) { | ||
return -1; | ||
} | ||
if (aOrder !== bOrder) { | ||
return aOrder < bOrder ? -1 : 1; | ||
if (a !== b) { | ||
return a < b ? -1 : 1; | ||
} | ||
@@ -207,2 +207,4 @@ } | ||
}; | ||
const bySourceOrder = createComparator("sourceOrder", compareNumbers); | ||
const byRangeStart = createComparator("rangeStart", compareNumbers); | ||
@@ -891,2 +893,5 @@ const joinIterableWithComma = iterable => { | ||
} | ||
/** | ||
* @type {Array<{ connection: ModuleGraphConnection, sourceOrder: number, rangeStart: number }>} | ||
*/ | ||
const references = connections | ||
@@ -903,11 +908,29 @@ .filter(connection => { | ||
}) | ||
.map(connection => ({ | ||
connection, | ||
sourceOrder: /** @type {HarmonyImportDependency} */ ( | ||
.map(connection => { | ||
const dep = /** @type {HarmonyImportDependency} */ ( | ||
connection.dependency | ||
).sourceOrder | ||
})); | ||
references.sort( | ||
concatComparators(bySourceOrder, keepOriginalOrder(references)) | ||
); | ||
); | ||
return { | ||
connection, | ||
sourceOrder: dep.sourceOrder, | ||
rangeStart: dep.range && dep.range[0] | ||
}; | ||
}); | ||
/** | ||
* bySourceOrder | ||
* @example | ||
* import a from "a"; // sourceOrder=1 | ||
* import b from "b"; // sourceOrder=2 | ||
* | ||
* byRangeStart | ||
* @example | ||
* import {a, b} from "a"; // sourceOrder=1 | ||
* a.a(); // first range | ||
* b.b(); // second range | ||
* | ||
* If there is no reexport, we have the same source. | ||
* If there is reexport, but module has side effects, this will lead to reexport module only. | ||
* If there is side-effects-free reexport, we can get simple deterministic result with range start comparison. | ||
*/ | ||
references.sort(concatComparators(bySourceOrder, byRangeStart)); | ||
/** @type {Map<Module, { connection: ModuleGraphConnection, runtimeCondition: RuntimeSpec | true }>} */ | ||
@@ -914,0 +937,0 @@ const referencesMap = new Map(); |
@@ -181,6 +181,39 @@ /* | ||
if (hashToAssets.size === 0) return; | ||
const hashRegExp = new RegExp( | ||
Array.from(hashToAssets.keys(), quoteMeta).join("|"), | ||
"g" | ||
const hashRegExps = Array.from(hashToAssets.keys(), quoteMeta).map( | ||
hash => new RegExp(hash, "g") | ||
); | ||
/** | ||
* @param {string} str string to be matched against all hashRegExps | ||
* @returns {string[] | null} matches found | ||
*/ | ||
const hashMatch = str => { | ||
/** @type {string[]} */ | ||
const results = []; | ||
for (const hashRegExp of hashRegExps) { | ||
const matches = str.match(hashRegExp); | ||
if (matches) { | ||
matches.forEach(match => results.push(match)); | ||
} | ||
} | ||
if (results.length) { | ||
return results; | ||
} else { | ||
return null; | ||
} | ||
}; | ||
/** | ||
* @param {string} str string to be replaced with all hashRegExps | ||
* @param {function(string): string} fn replacement function to use when a hash is found | ||
* @returns {string} replaced content | ||
*/ | ||
const hashReplace = (str, fn) => { | ||
let result = str; | ||
for (const hashRegExp of hashRegExps) { | ||
result = result.replace(hashRegExp, fn); | ||
} | ||
return result; | ||
}; | ||
await Promise.all( | ||
@@ -202,3 +235,3 @@ assetsWithInfo.map(async asset => { | ||
let ownHashes = new Set(); | ||
const inContent = content.match(hashRegExp); | ||
const inContent = hashMatch(content); | ||
if (inContent) { | ||
@@ -303,3 +336,3 @@ for (const hash of inContent) { | ||
() => { | ||
const newContent = asset.content.replace(hashRegExp, hash => | ||
const newContent = hashReplace(asset.content, hash => | ||
hashToNewHash.get(hash) | ||
@@ -329,11 +362,8 @@ ); | ||
() => { | ||
const newContent = asset.content.replace( | ||
hashRegExp, | ||
hash => { | ||
if (asset.ownHashes.has(hash)) { | ||
return ""; | ||
} | ||
return hashToNewHash.get(hash); | ||
const newContent = hashReplace(asset.content, hash => { | ||
if (asset.ownHashes.has(hash)) { | ||
return ""; | ||
} | ||
); | ||
return hashToNewHash.get(hash); | ||
}); | ||
return new RawSource(newContent); | ||
@@ -349,3 +379,2 @@ } | ||
assets.sort(comparator); | ||
const hash = createHash(this._hashFunction); | ||
await Promise.all( | ||
@@ -371,2 +400,3 @@ assets.map(asset => | ||
if (!newHash) { | ||
const hash = createHash(this._hashFunction); | ||
for (const content of assetsContent) { | ||
@@ -383,3 +413,3 @@ hash.update(content); | ||
await computeNewContent(asset); | ||
const newName = asset.name.replace(hashRegExp, hash => | ||
const newName = hashReplace(asset.name, hash => | ||
hashToNewHash.get(hash) | ||
@@ -386,0 +416,0 @@ ); |
@@ -23,8 +23,9 @@ /* | ||
return Template.asString([ | ||
'var webpackThen = typeof Symbol === "function" ? Symbol("webpack then") : "__webpack_then__";', | ||
'var webpackQueues = typeof Symbol === "function" ? Symbol("webpack queues") : "__webpack_queues__";', | ||
'var webpackExports = typeof Symbol === "function" ? Symbol("webpack exports") : "__webpack_exports__";', | ||
'var webpackError = typeof Symbol === "function" ? Symbol("webpack error") : "__webpack_error__";', | ||
`var completeQueue = ${runtimeTemplate.basicFunction("queue", [ | ||
"if(queue) {", | ||
`var resolveQueue = ${runtimeTemplate.basicFunction("queue", [ | ||
"if(queue && !queue.d) {", | ||
Template.indent([ | ||
"queue.d = 1;", | ||
`queue.forEach(${runtimeTemplate.expressionFunction( | ||
@@ -41,10 +42,2 @@ "fn.r--", | ||
])}`, | ||
`var completeFunction = ${runtimeTemplate.expressionFunction( | ||
"!--fn.r && fn()", | ||
"fn" | ||
)};`, | ||
`var queueFunction = ${runtimeTemplate.expressionFunction( | ||
"queue ? queue.push(fn) : completeFunction(fn)", | ||
"queue, fn" | ||
)};`, | ||
`var wrapDeps = ${runtimeTemplate.returningFunction( | ||
@@ -54,19 +47,18 @@ `deps.map(${runtimeTemplate.basicFunction("dep", [ | ||
Template.indent([ | ||
"if(dep[webpackThen]) return dep;", | ||
"if(dep[webpackQueues]) return dep;", | ||
"if(dep.then) {", | ||
Template.indent([ | ||
"var queue = [];", | ||
"queue.d = 0;", | ||
`dep.then(${runtimeTemplate.basicFunction("r", [ | ||
"obj[webpackExports] = r;", | ||
"completeQueue(queue);", | ||
"queue = 0;" | ||
"resolveQueue(queue);" | ||
])}, ${runtimeTemplate.basicFunction("e", [ | ||
"obj[webpackError] = e;", | ||
"completeQueue(queue);", | ||
"queue = 0;" | ||
"resolveQueue(queue);" | ||
])});`, | ||
"var obj = {};", | ||
`obj[webpackThen] = ${runtimeTemplate.expressionFunction( | ||
"queueFunction(queue, fn), dep['catch'](reject)", | ||
"fn, reject" | ||
`obj[webpackQueues] = ${runtimeTemplate.expressionFunction( | ||
`fn(queue)`, | ||
"fn" | ||
)};`, | ||
@@ -79,6 +71,3 @@ "return obj;" | ||
"var ret = {};", | ||
`ret[webpackThen] = ${runtimeTemplate.expressionFunction( | ||
"completeFunction(fn)", | ||
"fn" | ||
)};`, | ||
`ret[webpackQueues] = ${runtimeTemplate.emptyFunction()};`, | ||
"ret[webpackExports] = dep;", | ||
@@ -90,3 +79,5 @@ "return ret;" | ||
`${fn} = ${runtimeTemplate.basicFunction("module, body, hasAwait", [ | ||
"var queue = hasAwait && [];", | ||
"var queue;", | ||
"hasAwait && ((queue = []).d = 1);", | ||
"var depQueues = new Set();", | ||
"var exports = module.exports;", | ||
@@ -96,35 +87,10 @@ "var currentDeps;", | ||
"var reject;", | ||
"var isEvaluating = true;", | ||
"var nested = false;", | ||
`var whenAll = ${runtimeTemplate.basicFunction( | ||
"deps, onResolve, onReject", | ||
[ | ||
"if (nested) return;", | ||
"nested = true;", | ||
"onResolve.r += deps.length;", | ||
`deps.map(${runtimeTemplate.expressionFunction( | ||
"dep[webpackThen](onResolve, onReject)", | ||
"dep, i" | ||
)});`, | ||
"nested = false;" | ||
] | ||
)};`, | ||
`var promise = new Promise(${runtimeTemplate.basicFunction( | ||
"resolve, rej", | ||
[ | ||
"reject = rej;", | ||
`outerResolve = ${runtimeTemplate.expressionFunction( | ||
"resolve(exports), completeQueue(queue), queue = 0" | ||
)};` | ||
] | ||
["reject = rej;", "outerResolve = resolve;"] | ||
)});`, | ||
"promise[webpackExports] = exports;", | ||
`promise[webpackThen] = ${runtimeTemplate.basicFunction( | ||
"fn, rejectFn", | ||
[ | ||
"if (isEvaluating) { return completeFunction(fn); }", | ||
"if (currentDeps) whenAll(currentDeps, fn, rejectFn);", | ||
"queueFunction(queue, fn);", | ||
"promise['catch'](rejectFn);" | ||
] | ||
`promise[webpackQueues] = ${runtimeTemplate.expressionFunction( | ||
`queue && fn(queue), depQueues.forEach(fn), promise["catch"](${runtimeTemplate.emptyFunction()})`, | ||
"fn" | ||
)};`, | ||
@@ -142,9 +108,17 @@ "module.exports = promise;", | ||
`var promise = new Promise(${runtimeTemplate.basicFunction( | ||
"resolve, reject", | ||
"resolve", | ||
[ | ||
`fn = ${runtimeTemplate.expressionFunction( | ||
"resolve(getResult)" | ||
"resolve(getResult)", | ||
"" | ||
)};`, | ||
"fn.r = 0;", | ||
"whenAll(currentDeps, fn, reject);" | ||
`var fnQueue = ${runtimeTemplate.expressionFunction( | ||
"q !== queue && !depQueues.has(q) && (depQueues.add(q), q && !q.d && (fn.r++, q.push(fn)))", | ||
"q" | ||
)};`, | ||
`currentDeps.map(${runtimeTemplate.expressionFunction( | ||
"dep[webpackQueues](fnQueue)", | ||
"dep" | ||
)});` | ||
] | ||
@@ -154,6 +128,6 @@ )});`, | ||
])}, ${runtimeTemplate.expressionFunction( | ||
"err && reject(promise[webpackError] = err), outerResolve()", | ||
"(err ? reject(promise[webpackError] = err) : outerResolve(exports)), resolveQueue(queue)", | ||
"err" | ||
)});`, | ||
"isEvaluating = false;" | ||
"queue && (queue.d = 0);" | ||
])};` | ||
@@ -160,0 +134,0 @@ ]); |
@@ -90,9 +90,11 @@ /* | ||
crossOriginLoading | ||
? Template.asString([ | ||
"if (script.src.indexOf(window.location.origin + '/') !== 0) {", | ||
Template.indent( | ||
`script.crossOrigin = ${JSON.stringify(crossOriginLoading)};` | ||
), | ||
"}" | ||
]) | ||
? crossOriginLoading === "use-credentials" | ||
? 'script.crossOrigin = "use-credentials";' | ||
: Template.asString([ | ||
"if (script.src.indexOf(window.location.origin + '/') !== 0) {", | ||
Template.indent( | ||
`script.crossOrigin = ${JSON.stringify(crossOriginLoading)};` | ||
), | ||
"}" | ||
]) | ||
: "" | ||
@@ -148,4 +150,4 @@ ]); | ||
]) | ||
), | ||
";", | ||
) + | ||
";", | ||
`var timeout = setTimeout(onScriptComplete.bind(null, undefined, { type: 'timeout', target: script }), ${loadTimeout});`, | ||
@@ -152,0 +154,0 @@ "script.onerror = onScriptComplete.bind(null, script.onerror);", |
@@ -132,4 +132,3 @@ /* | ||
} else if (!descriptionFileData.version) { | ||
details = | ||
"No version in description file (usually package.json). Add version to description file, or manually specify version in shared config."; | ||
details = `No version in description file (usually package.json). Add version to description file ${resourceResolveData.descriptionFilePath}, or manually specify version in shared config.`; | ||
} else { | ||
@@ -136,0 +135,0 @@ version = descriptionFileData.version; |
@@ -1156,3 +1156,3 @@ /* | ||
"warnings[].error": joinError(false), | ||
loggingGroup: items => joinExplicitNewLine(items, "").trimRight(), | ||
loggingGroup: items => joinExplicitNewLine(items, "").trimEnd(), | ||
moduleTraceItem: items => " @ " + joinOneLine(items), | ||
@@ -1159,0 +1159,0 @@ moduleTraceDependency: joinOneLine |
@@ -220,3 +220,3 @@ /* | ||
} else { | ||
const str = s.trimRight(); | ||
const str = s.trimEnd(); | ||
if (!str) return ""; | ||
@@ -223,0 +223,0 @@ const ind = str[0] === "\n" ? "" : "\t"; |
@@ -20,3 +20,3 @@ /* | ||
const JS_COMPAT_TYPES = new Set(["i32", "f32", "f64"]); | ||
const JS_COMPAT_TYPES = new Set(["i32", "i64", "f32", "f64"]); | ||
@@ -23,0 +23,0 @@ /** |
@@ -266,11 +266,13 @@ /* | ||
crossOriginLoading | ||
? Template.asString([ | ||
"if (link.href.indexOf(window.location.origin + '/') !== 0) {", | ||
Template.indent( | ||
`link.crossOrigin = ${JSON.stringify( | ||
crossOriginLoading | ||
)};` | ||
), | ||
"}" | ||
]) | ||
? crossOriginLoading === "use-credentials" | ||
? 'link.crossOrigin = "use-credentials";' | ||
: Template.asString([ | ||
"if (link.href.indexOf(window.location.origin + '/') !== 0) {", | ||
Template.indent( | ||
`link.crossOrigin = ${JSON.stringify( | ||
crossOriginLoading | ||
)};` | ||
), | ||
"}" | ||
]) | ||
: "" | ||
@@ -277,0 +279,0 @@ ]), |
@@ -163,2 +163,24 @@ /* | ||
).apply(compiler); | ||
} else if (options.externalsPresets.node) { | ||
if (options.experiments.css) { | ||
//@ts-expect-error https://github.com/microsoft/TypeScript/issues/41697 | ||
const ExternalsPlugin = require("./ExternalsPlugin"); | ||
new ExternalsPlugin( | ||
"module", | ||
({ request, dependencyType }, callback) => { | ||
if (dependencyType === "url") { | ||
if (/^(\/\/|https?:\/\/)/.test(request)) | ||
return callback(null, `asset ${request}`); | ||
} else if (dependencyType === "css-import") { | ||
if (/^(\/\/|https?:\/\/)/.test(request)) | ||
return callback(null, `css-import ${request}`); | ||
} else if (/^(\/\/|https?:\/\/|std:)/.test(request)) { | ||
if (/^\.css(\?|$)/.test(request)) | ||
return callback(null, `css-import ${request}`); | ||
return callback(null, `module ${request}`); | ||
} | ||
callback(); | ||
} | ||
).apply(compiler); | ||
} | ||
} | ||
@@ -165,0 +187,0 @@ |
{ | ||
"name": "webpack", | ||
"version": "5.72.1", | ||
"version": "5.76.0", | ||
"author": "Tobias Koppers @sokra", | ||
@@ -13,7 +13,7 @@ "description": "Packs CommonJs/AMD modules for the browser. Allows to split your codebase into multiple bundles, which can be loaded on demand. Support loaders to preprocess files, i.e. json, jsx, es7, css, less, ... and your custom stuff.", | ||
"@webassemblyjs/wasm-parser": "1.11.1", | ||
"acorn": "^8.4.1", | ||
"acorn": "^8.7.1", | ||
"acorn-import-assertions": "^1.7.6", | ||
"browserslist": "^4.14.5", | ||
"chrome-trace-event": "^1.0.2", | ||
"enhanced-resolve": "^5.9.3", | ||
"enhanced-resolve": "^5.10.0", | ||
"es-module-lexer": "^0.9.0", | ||
@@ -31,3 +31,3 @@ "eslint-scope": "5.1.1", | ||
"terser-webpack-plugin": "^5.1.3", | ||
"watchpack": "^2.3.1", | ||
"watchpack": "^2.4.0", | ||
"webpack-sources": "^3.2.3" | ||
@@ -81,3 +81,3 @@ }, | ||
"lint-staged": "^11.0.0", | ||
"loader-utils": "^2.0.0", | ||
"loader-utils": "^2.0.3", | ||
"lodash": "^4.17.19", | ||
@@ -90,3 +90,3 @@ "lodash-es": "^4.17.15", | ||
"open-cli": "^6.0.1", | ||
"prettier": "^2.2.0", | ||
"prettier": "^2.7.1", | ||
"pretty-format": "^27.0.2", | ||
@@ -105,5 +105,5 @@ "pug": "^3.0.0", | ||
"toml": "^3.0.0", | ||
"tooling": "webpack/tooling#v1.21.0", | ||
"tooling": "webpack/tooling#v1.22.0", | ||
"ts-loader": "^8.0.2", | ||
"typescript": "^4.5.5", | ||
"typescript": "^4.8.4", | ||
"url-loader": "^4.1.0", | ||
@@ -129,2 +129,3 @@ "wast-loader": "^1.11.0", | ||
"homepage": "https://github.com/webpack/webpack", | ||
"bugs": "https://github.com/webpack/webpack/issues", | ||
"main": "lib/index.js", | ||
@@ -131,0 +132,0 @@ "bin": { |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
4408207
0.6%127922
0.52%716
0.56%9
12.5%+ Added
- Removed
Updated
Updated
Updated