MCPcopy
hub / github.com/webpack/webpack / deleteAsset

Method deleteAsset

lib/Compilation.js:5410–5465  ·  lib/Compilation.js::Compilation.deleteAsset

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

(file)

Source from the content-addressed store, hash-verified

5408 * @param {string} file file name
5409 */
5410 deleteAsset(file) {
5411 if (!this.assets[file]) {
5412 return;
5413 }
5414 delete this.assets[file];
5415 const assetInfo = this.assetsInfo.get(file);
5416 this._setAssetInfo(file, undefined, assetInfo);
5417 const related = assetInfo && assetInfo.related;
5418 if (related) {
5419 for (const key of Object.keys(related)) {
5420 /**
5421 * Checks used and delete.
5422 * @param {string} file file
5423 */
5424 const checkUsedAndDelete = (file) => {
5425 if (!this._assetsRelatedIn.has(file)) {
5426 this.deleteAsset(file);
5427 }
5428 };
5429 const items = related[key];
5430 if (Array.isArray(items)) {
5431 for (const file of items) {
5432 checkUsedAndDelete(file);
5433 }
5434 } else if (items) {
5435 checkUsedAndDelete(items);
5436 }
5437 }
5438 }
5439 this._buildAssetToChunkIndex();
5440 const index = /** @type {Map<string, Set<Chunk>>} */ (
5441 this._assetToChunkIndex
5442 );
5443 const auxiliaryIndex = /** @type {Map<string, Set<Chunk>>} */ (
5444 this._assetToChunkAuxiliaryIndex
5445 );
5446 const chunks = index.get(file);
5447 const auxiliaryChunks = auxiliaryIndex.get(file);
5448 if (chunks === undefined && auxiliaryChunks === undefined) {
5449 class="cm">// Not tracked in either index: chunk sets may have been mutated
5450 class="cm">// directly (bypassing emitAsset), so scan all chunks to stay correct.
5451 for (const chunk of this.chunks) {
5452 chunk.files.delete(file);
5453 chunk.auxiliaryFiles.delete(file);
5454 }
5455 return;
5456 }
5457 if (chunks !== undefined) {
5458 for (const chunk of chunks) chunk.files.delete(file);
5459 index.delete(file);
5460 }
5461 if (auxiliaryChunks !== undefined) {
5462 for (const chunk of auxiliaryChunks) chunk.auxiliaryFiles.delete(file);
5463 auxiliaryIndex.delete(file);
5464 }
5465 }
5466
5467 getAssets() {

Callers 6

checkUsedAndDeleteMethod · 0.95
loader.jsFile · 0.80
webpack.config.jsFile · 0.80
webpack.config.jsFile · 0.80
webpack.config.jsFile · 0.80

Calls 6

_setAssetInfoMethod · 0.95
isArrayMethod · 0.80
keysMethod · 0.65
getMethod · 0.45
deleteMethod · 0.45

Tested by

no test coverage detected