MCPcopy
hub / github.com/webpack/webpack / applyDiff

Function applyDiff

lib/CleanPlugin.js:175–336  ·  view source on GitHub ↗
(fs, outputPath, dry, logger, diff, isKept, callback)

Source from the content-addressed store, hash-verified

173 * @returns {void}
174 */
175const applyDiff = (fs, outputPath, dry, logger, diff, isKept, callback) => {
176 /**
177 * Processes the provided msg.
178 * @param {string} msg message
179 */
180 const log = (msg) => {
181 if (dry) {
182 logger.info(msg);
183 } else {
184 logger.log(msg);
185 }
186 };
187 /** @typedef {{ type: "check" | "unlink" | "rmdir", filename: string, parent: { remaining: number, job: Job } | undefined }} Job */
188 /** @type {Job[]} */
189 const jobs = Array.from(diff.keys(), (filename) => ({
190 type: "check",
191 filename,
192 parent: undefined
193 }));
194 /** @type {Assets} */
195 const keptAssets = new Map();
196 processAsyncTree(
197 jobs,
198 10,
199 ({ type, filename, parent }, push, callback) => {
200 const path = join(fs, outputPath, filename);
201 /**
202 * Describes how this handle error operation behaves.
203 * @param {Error & { code?: string }} err error
204 * @returns {void}
205 */
206 const handleError = (err) => {
207 const isAlreadyRemoved = () =>
208 new Promise((resolve) => {
209 if (err.code === "ENOENT") {
210 resolve(true);
211 } else if (err.code === "EPERM") {
212 // https://github.com/isaacs/rimraf/blob/main/src/fix-eperm.ts#L37
213 // fs.existsSync(path) === false https://github.com/webpack/webpack/actions/runs/15493412975/job/43624272783?pr=19586
214 doStat(fs, path, (err) => {
215 if (err) {
216 resolve(err.code === "ENOENT");
217 } else {
218 resolve(false);
219 }
220 });
221 } else {
222 resolve(false);
223 }
224 });
225
226 isAlreadyRemoved().then((isRemoved) => {
227 if (isRemoved) {
228 log(`${filename} was removed during cleaning by something else`);
229 handleParent();
230 return callback();
231 }
232 return callback(err);

Callers 1

diffCallbackMethod · 0.85

Calls 11

processAsyncTreeFunction · 0.85
joinFunction · 0.85
handleParentFunction · 0.85
warnMethod · 0.80
logFunction · 0.70
doStatFunction · 0.70
handleErrorFunction · 0.70
keysMethod · 0.65
pushFunction · 0.50
callbackFunction · 0.50
setMethod · 0.45

Tested by

no test coverage detected