MCPcopy
hub / github.com/webpack/webpack / writeOut

Method writeOut

lib/Compiler.js:805–1069  ·  lib/Compiler.js::Compiler.writeOut
(err)

Source from the content-addressed store, hash-verified

803 * @returns {void}
804 */
805 const writeOut = (err) => {
806 if (err) return callback(err);
807 allTargetPaths.add(targetPath);
808
809 class="cm">// check if the target file has already been written by this Compiler
810 const targetFileGeneration =
811 this._assetEmittingWrittenFiles.get(targetPath);
812
813 class="cm">// 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[class="st">"writtenTo"]} */
819 writtenTo: new Map()
820 };
821 this._assetEmittingSourceCache.set(source, cacheEntry);
822 }
823
824 /** @type {SimilarEntry | undefined} */
825 let similarEntry;
826
827 const checkSimilarFile = () => {
828 const caseInsensitiveTargetPath = targetPath.toLowerCase();
829 similarEntry = caseInsensitiveMap.get(caseInsensitiveTargetPath);
830 if (similarEntry !== undefined) {
831 const { path: other, source: otherSource } = similarEntry;
832 if (isSourceEqual(otherSource, source)) {
833 class="cm">// Size may or may not be available at this point.
834 class="cm">// If it's not available add to class="st">"waiting" list and it will be updated once available
835 if (similarEntry.size !== undefined) {
836 updateWithReplacementSource(similarEntry.size);
837 } else {
838 if (!similarEntry.waiting) similarEntry.waiting = [];
839 similarEntry.waiting.push({ file, cacheEntry });
840 }
841 alreadyWritten();
842 } else {
843 const err =
844 new WebpackError(`Prevent writing to file that only differs in casing or query string from already written file.
845This will lead to a race-condition and corrupted files on case-insensitive file systems.
846${targetPath}
847${other}`);
848 err.file = file;
849 callback(err);
850 }
851 return true;
852 }
853 caseInsensitiveMap.set(
854 caseInsensitiveTargetPath,
855 (similarEntry = /** @type {SimilarEntry} */ ({
856 path: targetPath,
857 source,
858 size: undefined,
859 waiting: undefined
860 }))
861 );
862 return false;

Callers

nothing calls this directly

Calls 7

updateAssetMethod · 0.80
callbackFunction · 0.50
addMethod · 0.45
getMethod · 0.45
setMethod · 0.45
hasMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected