MCPcopy
hub / github.com/webpack/webpack / updateAsset

Method updateAsset

lib/Compilation.js:5234–5260  ·  lib/Compilation.js::Compilation.updateAsset

* Updates asset using the provided file. * @param {string} file file name * @param {Source | ((source: Source) => Source)} newSourceOrFunction new asset source or function converting old to new * @param {(AssetInfo | ((assetInfo?: AssetInfo) => AssetInfo | undefined)) | undefined} assetInfoUpd

(
		file,
		newSourceOrFunction,
		assetInfoUpdateOrFunction = undefined
	)

Source from the content-addressed store, hash-verified

5232 * @param {(AssetInfo | ((assetInfo?: AssetInfo) => AssetInfo | undefined)) | undefined} assetInfoUpdateOrFunction new asset info or function converting old to new
5233 */
5234 updateAsset(
5235 file,
5236 newSourceOrFunction,
5237 assetInfoUpdateOrFunction = undefined
5238 ) {
5239 if (!this.assets[file]) {
5240 throw new Error(
5241 `Called Compilation.updateAsset for not existing filename ${file}`
5242 );
5243 }
5244 this.assets[file] =
5245 typeof newSourceOrFunction === class="st">"function"
5246 ? newSourceOrFunction(this.assets[file])
5247 : newSourceOrFunction;
5248 if (assetInfoUpdateOrFunction !== undefined) {
5249 const oldInfo = this.assetsInfo.get(file) || EMPTY_ASSET_INFO;
5250 if (typeof assetInfoUpdateOrFunction === class="st">"function") {
5251 this._setAssetInfo(file, assetInfoUpdateOrFunction(oldInfo), oldInfo);
5252 } else {
5253 this._setAssetInfo(
5254 file,
5255 cachedCleverMerge(oldInfo, assetInfoUpdateOrFunction),
5256 oldInfo
5257 );
5258 }
5259 }
5260 }
5261
5262 /**
5263 * Processes the provided file.

Callers 15

applyMethod · 0.80
writeOutMethod · 0.80
applyMethod · 0.80
applyMethod · 0.80
webpack.config.jsFile · 0.80
webpack.config.jsFile · 0.80
applyFunction · 0.80
applyFunction · 0.80
webpack.config.jsFile · 0.80
toScriptTagMethod · 0.80
applyMethod · 0.80

Calls 3

_setAssetInfoMethod · 0.95
cachedCleverMergeFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected