| 761 | * @returns {void} |
| 762 | */ |
| 763 | const emitFiles = (err) => { |
| 764 | if (err) return callback(err); |
| 765 | |
| 766 | const assets = compilation.getAssets(); |
| 767 | compilation.assets = { ...compilation.assets }; |
| 768 | /** @type {Map<string, SimilarEntry>} */ |
| 769 | const caseInsensitiveMap = new Map(); |
| 770 | /** @type {Set<string>} */ |
| 771 | const allTargetPaths = new Set(); |
| 772 | asyncLib.forEachLimit( |
| 773 | assets, |
| 774 | 15, |
| 775 | ({ name: file, source, info }, callback) => { |
| 776 | let targetFile = file; |
| 777 | let immutable = info.immutable; |
| 778 | const queryOrHashStringIdx = targetFile.search(/[?#]/); |
| 779 | if (queryOrHashStringIdx >= 0) { |
| 780 | targetFile = targetFile.slice(0, queryOrHashStringIdx); |
| 781 | // We may remove the hash, which is in the query string |
| 782 | // So we recheck if the file is immutable |
| 783 | // This doesn't cover all cases, but immutable is only a performance optimization anyway |
| 784 | immutable = |
| 785 | immutable && |
| 786 | (includesHash(targetFile, info.contenthash) || |
| 787 | includesHash(targetFile, info.chunkhash) || |
| 788 | includesHash(targetFile, info.modulehash) || |
| 789 | includesHash(targetFile, info.fullhash)); |
| 790 | } |
| 791 | |
| 792 | const fs = /** @type {OutputFileSystem} */ (this.outputFileSystem); |
| 793 | // A Windows drive-absolute targetFile is written as-is; joining it onto |
| 794 | // outputPath would produce an invalid path (e.g. C:\out\D:\file). A |
| 795 | // leading "/" stays relative to outputPath (e.g. entry name "/dir/x"). |
| 796 | const targetPath = WINDOWS_ABS_PATH_REGEXP.test(targetFile) |
| 797 | ? targetFile |
| 798 | : join(fs, outputPath, targetFile); |
| 799 | |
| 800 | /** |
| 801 | * Processes the provided err. |
| 802 | * @param {Error=} err error |
| 803 | * @returns {void} |
| 804 | */ |
| 805 | const writeOut = (err) => { |
| 806 | if (err) return callback(err); |
| 807 | allTargetPaths.add(targetPath); |
| 808 | |
| 809 | // check if the target file has already been written by this Compiler |
| 810 | const targetFileGeneration = |
| 811 | this._assetEmittingWrittenFiles.get(targetPath); |
| 812 | |
| 813 | // create an cache entry for this Source if not already existing |
| 814 | let cacheEntry = this._assetEmittingSourceCache.get(source); |
| 815 | if (cacheEntry === undefined) { |
| 816 | cacheEntry = { |
| 817 | sizeOnlySource: undefined, |
| 818 | /** @type {CacheEntry["writtenTo"]} */ |
| 819 | writtenTo: new Map() |
| 820 | }; |