MCPcopy
hub / github.com/webpack/webpack / renameAsset

Method renameAsset

lib/Compilation.js:5267–5357  ·  lib/Compilation.js::Compilation.renameAsset

* Processes the provided file. * @param {string} file file name * @param {string} newFile the new name of file

(file, newFile)

Source from the content-addressed store, hash-verified

5265 * @param {string} newFile the new name of file
5266 */
5267 renameAsset(file, newFile) {
5268 const source = this.assets[file];
5269 if (!source) {
5270 throw new Error(
5271 `Called Compilation.renameAsset for not existing filename ${file}`
5272 );
5273 }
5274 if (this.assets[newFile] && !isSourceEqual(this.assets[file], source)) {
5275 this.errors.push(
5276 new WebpackError(
5277 `Conflict: Called Compilation.renameAsset for already existing filename ${newFile} with different content`
5278 )
5279 );
5280 }
5281 const assetInfo = this.assetsInfo.get(file);
5282 class="cm">// Update related in all other assets
5283 const relatedInInfo = this._assetsRelatedIn.get(file);
5284 if (relatedInInfo) {
5285 for (const [key, assets] of relatedInInfo) {
5286 for (const name of assets) {
5287 const info = this.assetsInfo.get(name);
5288 if (!info) continue;
5289 const related = info.related;
5290 if (!related) continue;
5291 const entry = related[key];
5292 /** @type {string | string[]} */
5293 let newEntry;
5294 if (Array.isArray(entry)) {
5295 newEntry = entry.map((x) => (x === file ? newFile : x));
5296 } else if (entry === file) {
5297 newEntry = newFile;
5298 } else {
5299 continue;
5300 }
5301 this.assetsInfo.set(name, {
5302 ...info,
5303 related: {
5304 ...related,
5305 [key]: newEntry
5306 }
5307 });
5308 }
5309 }
5310 }
5311 this._setAssetInfo(file, undefined, assetInfo);
5312 this._setAssetInfo(newFile, assetInfo);
5313 delete this.assets[file];
5314 this.assets[newFile] = source;
5315 this._buildAssetToChunkIndex();
5316 const index = /** @type {Map<string, Set<Chunk>>} */ (
5317 this._assetToChunkIndex
5318 );
5319 const auxiliaryIndex = /** @type {Map<string, Set<Chunk>>} */ (
5320 this._assetToChunkAuxiliaryIndex
5321 );
5322 const chunks = index.get(file);
5323 const auxiliaryChunks = auxiliaryIndex.get(file);
5324 if (chunks === undefined && auxiliaryChunks === undefined) {

Callers 2

applyMethod · 0.80

Calls 9

_setAssetInfoMethod · 0.95
_renameAssetInChunkMethod · 0.95
isSourceEqualFunction · 0.85
isArrayMethod · 0.80
pushMethod · 0.45
getMethod · 0.45
setMethod · 0.45
deleteMethod · 0.45

Tested by

no test coverage detected