webpack
Advanced tools
Comparing version 5.64.4 to 5.65.0
@@ -231,3 +231,3 @@ /* | ||
); | ||
let publicPath; | ||
let assetPath; | ||
if (this.publicPath !== undefined) { | ||
@@ -245,7 +245,10 @@ const { path, info } = | ||
); | ||
publicPath = JSON.stringify(path); | ||
assetInfo = mergeAssetInfo(assetInfo, info); | ||
assetPath = JSON.stringify(path + filename); | ||
} else { | ||
publicPath = RuntimeGlobals.publicPath; | ||
runtimeRequirements.add(RuntimeGlobals.publicPath); // add __webpack_require__.p | ||
assetPath = runtimeTemplate.concatenation( | ||
{ expr: RuntimeGlobals.publicPath }, | ||
filename | ||
); | ||
} | ||
@@ -269,5 +272,3 @@ assetInfo = { | ||
return new RawSource( | ||
`${ | ||
RuntimeGlobals.module | ||
}.exports = ${publicPath} + ${JSON.stringify(filename)};` | ||
`${RuntimeGlobals.module}.exports = ${assetPath};` | ||
); | ||
@@ -274,0 +275,0 @@ } |
@@ -277,3 +277,40 @@ /* | ||
}), | ||
optionalChaining: rawChecker({ | ||
chrome: 80, | ||
and_chr: 80, | ||
edge: 80, | ||
firefox: 74, | ||
and_ff: 79, | ||
// ie: Not supported, | ||
opera: 67, | ||
op_mob: 64, | ||
safari: [13, 1], | ||
ios_saf: [13, 4], | ||
samsung: 13, | ||
android: 80, | ||
// and_qq: Not supported | ||
// baidu: Not supported | ||
// and_uc: Not supported | ||
// kaios: Not supported | ||
node: 14 | ||
}), | ||
templateLiteral: rawChecker({ | ||
chrome: 41, | ||
and_chr: 41, | ||
edge: 13, | ||
firefox: 34, | ||
and_ff: 34, | ||
// ie: Not supported, | ||
opera: 29, | ||
op_mob: 64, | ||
safari: [9, 1], | ||
ios_saf: 9, | ||
samsung: 4, | ||
android: 41, | ||
and_qq: [10, 4], | ||
baidu: [7, 12], | ||
and_uc: [12, 12], | ||
kaios: [2, 5], | ||
node: 4 | ||
}), | ||
browser: browserProperty, | ||
@@ -280,0 +317,0 @@ electron: false, |
@@ -835,3 +835,3 @@ /* | ||
D(output, "hashDigest", "hex"); | ||
D(output, "hashDigestLength", 20); | ||
D(output, "hashDigestLength", futureDefaults ? 16 : 20); | ||
D(output, "strictModuleExceptionHandling", false); | ||
@@ -838,0 +838,0 @@ |
@@ -62,2 +62,4 @@ /* | ||
* @property {boolean | null} module ESM syntax is available (when in module) | ||
* @property {boolean | null} optionalChaining optional chaining is available | ||
* @property {boolean | null} templateLiteral template literal is available | ||
*/ | ||
@@ -171,2 +173,4 @@ | ||
const: v(6), | ||
templateLiteral: v(4), | ||
optionalChaining: v(14), | ||
arrowFunction: v(6), | ||
@@ -211,2 +215,4 @@ forOf: v(5), | ||
const: v(1, 1), | ||
templateLiteral: v(1, 1), | ||
optionalChaining: v(8), | ||
arrowFunction: v(1, 1), | ||
@@ -247,2 +253,4 @@ forOf: v(0, 36), | ||
const: v(0, 15), | ||
templateLiteral: v(0, 13), | ||
optionalChaining: v(0, 44), | ||
arrowFunction: v(0, 15), | ||
@@ -267,2 +275,4 @@ forOf: v(0, 13), | ||
const: v >= 2015, | ||
templateLiteral: v >= 2015, | ||
optionalChaining: v >= 2020, | ||
arrowFunction: v >= 2015, | ||
@@ -269,0 +279,0 @@ forOf: v >= 2015, |
@@ -223,6 +223,4 @@ /* | ||
`if (!${RuntimeGlobals.shareScopeMap}) return;`, | ||
`var oldScope = ${RuntimeGlobals.shareScopeMap}[${JSON.stringify( | ||
this._shareScope | ||
)}];`, | ||
`var name = ${JSON.stringify(this._shareScope)}`, | ||
`var oldScope = ${RuntimeGlobals.shareScopeMap}[name];`, | ||
`if(oldScope && oldScope !== shareScope) throw new Error("Container initialization failed as it has already been initialized with a different share scope");`, | ||
@@ -229,0 +227,0 @@ `${RuntimeGlobals.shareScopeMap}[name] = shareScope;`, |
@@ -539,3 +539,3 @@ /* | ||
request, | ||
runtimeTemplate.outputOptions.globalObject | ||
runtimeTemplate.globalObject | ||
); | ||
@@ -542,0 +542,0 @@ case "commonjs": |
@@ -22,2 +22,3 @@ /* | ||
/** @typedef {import("../declarations/WebpackOptions").RuleSetUseItem} RuleSetUseItem */ | ||
/** @typedef {import("../declarations/WebpackOptions").StatsOptions} StatsOptions */ | ||
/** @typedef {import("../declarations/WebpackOptions").WebpackOptions} Configuration */ | ||
@@ -31,2 +32,4 @@ /** @typedef {import("../declarations/WebpackOptions").WebpackOptionsNormalized} WebpackOptionsNormalized */ | ||
/** @typedef {import("./Parser").ParserState} ParserState */ | ||
/** @typedef {import("./ResolverFactory").ResolvePluginInstance} ResolvePluginInstance */ | ||
/** @typedef {import("./ResolverFactory").Resolver} Resolver */ | ||
/** @typedef {import("./Watching")} Watching */ | ||
@@ -33,0 +36,0 @@ /** @typedef {import("./stats/DefaultStatsFactoryPlugin").StatsAsset} StatsAsset */ |
@@ -48,3 +48,3 @@ /* | ||
chunk instanceof HotUpdateChunk ? chunk : null; | ||
const globalObject = runtimeTemplate.outputOptions.globalObject; | ||
const globalObject = runtimeTemplate.globalObject; | ||
const source = new ConcatSource(); | ||
@@ -142,3 +142,3 @@ const runtimeModules = | ||
hash.update( | ||
`ArrayPushCallbackChunkFormatPlugin1${runtimeTemplate.outputOptions.chunkLoadingGlobal}${runtimeTemplate.outputOptions.hotUpdateGlobal}${runtimeTemplate.outputOptions.globalObject}` | ||
`ArrayPushCallbackChunkFormatPlugin1${runtimeTemplate.outputOptions.chunkLoadingGlobal}${runtimeTemplate.outputOptions.hotUpdateGlobal}${runtimeTemplate.globalObject}` | ||
); | ||
@@ -145,0 +145,0 @@ const entries = Array.from( |
@@ -177,3 +177,3 @@ /* | ||
return this.prefix === "global" | ||
? [compilation.outputOptions.globalObject] | ||
? [compilation.runtimeTemplate.globalObject] | ||
: this.prefix; | ||
@@ -329,11 +329,6 @@ } | ||
hash.update("AssignLibraryPlugin"); | ||
const prefix = | ||
this.prefix === "global" | ||
? [compilation.outputOptions.globalObject] | ||
: this.prefix; | ||
const fullName = options.name ? prefix.concat(options.name) : prefix; | ||
const fullNameResolved = fullName.map(n => | ||
compilation.getPath(n, { | ||
chunk | ||
}) | ||
const fullNameResolved = this._getResolvedFullName( | ||
options, | ||
chunk, | ||
compilation | ||
); | ||
@@ -340,0 +335,0 @@ if (options.name ? this.named === "copy" : this.unnamed === "copy") { |
@@ -53,2 +53,23 @@ /* | ||
/** | ||
* @param {string|undefined} definition global object definition | ||
* @returns {string} save to use global object | ||
*/ | ||
function getGlobalObject(definition) { | ||
if (!definition) return definition; | ||
const trimmed = definition.trim(); | ||
if ( | ||
// identifier, we do not need real identifier regarding ECMAScript/Unicode | ||
trimmed.match(/^[_\p{L}][_0-9\p{L}]*$/iu) || | ||
// iife | ||
// call expression | ||
// expression in parentheses | ||
trimmed.match(/^([_\p{L}][_0-9\p{L}]*)?\(.*\)$/iu) | ||
) | ||
return trimmed; | ||
return `Object(${trimmed})`; | ||
} | ||
class RuntimeTemplate { | ||
@@ -64,2 +85,3 @@ /** | ||
this.requestShortener = requestShortener; | ||
this.globalObject = getGlobalObject(outputOptions.globalObject); | ||
} | ||
@@ -83,2 +105,6 @@ | ||
supportsOptionalChaining() { | ||
return this.outputOptions.environment.optionalChaining; | ||
} | ||
supportsForOf() { | ||
@@ -105,4 +131,3 @@ return this.outputOptions.environment.forOf; | ||
supportTemplateLiteral() { | ||
// TODO | ||
return false; | ||
return this.outputOptions.environment.templateLiteral; | ||
} | ||
@@ -122,2 +147,67 @@ | ||
/** | ||
* @param {Array<string|{expr: string}>} args args | ||
* @returns {string} result expression | ||
*/ | ||
concatenation(...args) { | ||
const len = args.length; | ||
if (len === 2) return this._es5Concatenation(args); | ||
if (len === 0) return '""'; | ||
if (len === 1) { | ||
return typeof args[0] === "string" | ||
? JSON.stringify(args[0]) | ||
: `"" + ${args[0].expr}`; | ||
} | ||
if (!this.supportTemplateLiteral()) return this._es5Concatenation(args); | ||
// cost comparison between template literal and concatenation: | ||
// both need equal surroundings: `xxx` vs "xxx" | ||
// template literal has constant cost of 3 chars for each expression | ||
// es5 concatenation has cost of 3 + n chars for n expressions in row | ||
// when a es5 concatenation ends with an expression it reduces cost by 3 | ||
// when a es5 concatenation starts with an single expression it reduces cost by 3 | ||
// e. g. `${a}${b}${c}` (3*3 = 9) is longer than ""+a+b+c ((3+3)-3 = 3) | ||
// e. g. `x${a}x${b}x${c}x` (3*3 = 9) is shorter than "x"+a+"x"+b+"x"+c+"x" (4+4+4 = 12) | ||
let templateCost = 0; | ||
let concatenationCost = 0; | ||
let lastWasExpr = false; | ||
for (const arg of args) { | ||
const isExpr = typeof arg !== "string"; | ||
if (isExpr) { | ||
templateCost += 3; | ||
concatenationCost += lastWasExpr ? 1 : 4; | ||
} | ||
lastWasExpr = isExpr; | ||
} | ||
if (lastWasExpr) concatenationCost -= 3; | ||
if (typeof args[0] !== "string" && typeof args[1] === "string") | ||
concatenationCost -= 3; | ||
if (concatenationCost <= templateCost) return this._es5Concatenation(args); | ||
return `\`${args | ||
.map(arg => (typeof arg === "string" ? arg : `\${${arg.expr}}`)) | ||
.join("")}\``; | ||
} | ||
/** | ||
* @param {Array<string|{expr: string}>} args args (len >= 2) | ||
* @returns {string} result expression | ||
* @private | ||
*/ | ||
_es5Concatenation(args) { | ||
const str = args | ||
.map(arg => (typeof arg === "string" ? JSON.stringify(arg) : arg.expr)) | ||
.join(" + "); | ||
// when the first two args are expression, we need to prepend "" + to force string | ||
// concatenation instead of number addition. | ||
return typeof args[0] !== "string" && typeof args[1] !== "string" | ||
? `"" + ${str}` | ||
: str; | ||
} | ||
expressionFunction(expression, args = "") { | ||
@@ -124,0 +214,0 @@ return this.supportsArrowFunction() |
@@ -213,2 +213,6 @@ /* | ||
fn += "VersionCheck"; | ||
} else { | ||
if (singleton) { | ||
fn += "Singleton"; | ||
} | ||
} | ||
@@ -215,0 +219,0 @@ if (fallbackCode) { |
@@ -111,2 +111,9 @@ /* | ||
)};`, | ||
`var getSingleton = ${runtimeTemplate.basicFunction( | ||
"scope, scopeName, key, requiredVersion", | ||
[ | ||
"var version = findSingletonVersionKey(scope, key);", | ||
"return get(scope[key][version]);" | ||
] | ||
)};`, | ||
`var getSingletonVersion = ${runtimeTemplate.basicFunction( | ||
@@ -206,2 +213,9 @@ "scope, scopeName, key, requiredVersion", | ||
)});`, | ||
`var loadSingleton = /*#__PURE__*/ init(${runtimeTemplate.basicFunction( | ||
"scopeName, scope, key", | ||
[ | ||
"ensureExistence(scopeName, key);", | ||
"return getSingleton(scope, scopeName, key);" | ||
] | ||
)});`, | ||
`var loadSingletonVersionCheck = /*#__PURE__*/ init(${runtimeTemplate.basicFunction( | ||
@@ -235,2 +249,9 @@ "scopeName, scope, key, version", | ||
)});`, | ||
`var loadSingletonFallback = /*#__PURE__*/ init(${runtimeTemplate.basicFunction( | ||
"scopeName, scope, key, fallback", | ||
[ | ||
`if(!scope || !${RuntimeGlobals.hasOwnProperty}(scope, key)) return fallback();`, | ||
"return getSingleton(scope, scopeName, key);" | ||
] | ||
)});`, | ||
`var loadSingletonVersionCheckFallback = /*#__PURE__*/ init(${runtimeTemplate.basicFunction( | ||
@@ -237,0 +258,0 @@ "scopeName, scope, key, version, fallback", |
@@ -1163,3 +1163,3 @@ /* | ||
{ regExp: /\(possible exports: (.+)\)/g, format: green }, | ||
{ regExp: /\s*([^\s].* doesn't exist)/g, format: red }, | ||
{ regExp: /(?:^|\n)(.* doesn't exist)/g, format: red }, | ||
{ regExp: /('\w+' option has not been set)/g, format: red }, | ||
@@ -1166,0 +1166,0 @@ { |
@@ -14,3 +14,6 @@ /* | ||
const index = urlAndGlobal.indexOf("@"); | ||
if (index <= 0 || index === urlAndGlobal.length - 1) { | ||
throw new Error(`Invalid request "${urlAndGlobal}"`); | ||
} | ||
return [urlAndGlobal.substring(index + 1), urlAndGlobal.substring(0, index)]; | ||
}; |
@@ -62,3 +62,2 @@ /* | ||
outputOptions: { | ||
globalObject, | ||
chunkLoadingGlobal, | ||
@@ -70,2 +69,3 @@ hotUpdateGlobal, | ||
} = compilation; | ||
const globalObject = runtimeTemplate.globalObject; | ||
const { linkPreload, linkPrefetch } = | ||
@@ -72,0 +72,0 @@ JsonpChunkLoadingRuntimeModule.getCompilationHooks(compilation); |
@@ -34,6 +34,7 @@ /* | ||
runtimeTemplate, | ||
outputOptions: { globalObject, chunkLoadingGlobal, hotUpdateGlobal } | ||
outputOptions: { chunkLoadingGlobal, hotUpdateGlobal } | ||
}, | ||
_withCreateScriptUrl: withCreateScriptUrl | ||
} = this; | ||
const globalObject = runtimeTemplate.globalObject; | ||
const fn = RuntimeGlobals.ensureChunkHandlers; | ||
@@ -40,0 +41,0 @@ const withBaseURI = this.runtimeRequirements.has(RuntimeGlobals.baseURI); |
{ | ||
"name": "webpack", | ||
"version": "5.64.4", | ||
"version": "5.65.0", | ||
"author": "Tobias Koppers @sokra", | ||
@@ -30,3 +30,3 @@ "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.", | ||
"terser-webpack-plugin": "^5.1.3", | ||
"watchpack": "^2.3.0", | ||
"watchpack": "^2.3.1", | ||
"webpack-sources": "^3.2.2" | ||
@@ -33,0 +33,0 @@ }, |
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
4188551
121354
Updatedwatchpack@^2.3.1