MCPcopy
hub / github.com/webpack/webpack / getDiffToFs

Function getDiffToFs

lib/CleanPlugin.js:92–129  ·  lib/CleanPlugin.js::getDiffToFs
(fs, outputPath, currentAssets, callback)

Source from the content-addressed store, hash-verified

90 * @returns {void}
91 */
92const getDiffToFs = (fs, outputPath, currentAssets, callback) => {
93 const directories = getDirectories(currentAssets);
94 /** @type {Diff} */
95 const diff = new Set();
96 asyncLib.forEachLimit(
97 directories,
98 10,
99 (directory, callback) => {
100 /** @type {NonNullable<OutputFileSystem[class="st">"readdir"]>} */
101 (fs.readdir)(join(fs, outputPath, directory), (err, entries) => {
102 if (err) {
103 if (err.code === class="st">"ENOENT") return callback();
104 if (err.code === class="st">"ENOTDIR") {
105 diff.add(directory);
106 return callback();
107 }
108 return callback(err);
109 }
110 for (const entry of /** @type {string[]} */ (entries)) {
111 const file = entry;
112 class="cm">// Since path.normalize(class="st">"./file") === path.normalize(class="st">"file"),
113 class="cm">// return file directly when directory === class="st">"."
114 const filename =
115 directory && directory !== class="st">"." ? `${directory}/${file}` : file;
116 if (!directories.has(filename) && !currentAssets.has(filename)) {
117 diff.add(filename);
118 }
119 }
120 callback();
121 });
122 },
123 (err) => {
124 if (err) return callback(err);
125
126 callback(null, diff);
127 }
128 );
129};
130
131/**
132 * Gets diff to old assets.

Callers 1

applyMethod · 0.85

Calls 5

getDirectoriesFunction · 0.85
joinFunction · 0.85
callbackFunction · 0.50
addMethod · 0.45
hasMethod · 0.45

Tested by

no test coverage detected