MCPcopy
hub / github.com/webpack/webpack / getUndoPath

Function getUndoPath

lib/util/identifier.js:460–485  ·  view source on GitHub ↗
(filename, outputPath, enforceRelative)

Source from the content-addressed store, hash-verified

458 * @returns {string} repeated ../ to leave the directory of the provided filename to be back on output dir
459 */
460const getUndoPath = (filename, outputPath, enforceRelative) => {
461 let depth = -1;
462 let append = "";
463 outputPath = outputPath.replace(/[\\/]$/, "");
464 for (const part of filename.split(/[/\\]+/)) {
465 if (part === "..") {
466 if (depth > -1) {
467 depth--;
468 } else {
469 const i = outputPath.lastIndexOf("/");
470 const j = outputPath.lastIndexOf("\\");
471 const pos = i < 0 ? j : j < 0 ? i : Math.max(i, j);
472 if (pos < 0) return `${outputPath}/`;
473 append = `${outputPath.slice(pos + 1)}/${append}`;
474 outputPath = outputPath.slice(0, pos);
475 }
476 } else if (part !== ".") {
477 depth++;
478 }
479 }
480 return depth > 0
481 ? `${"../".repeat(depth)}${append}`
482 : enforceRelative
483 ? `./${append}`
484 : append;
485};
486
487const HASH_REGEXP = /(?<!\0)#/g;
488

Callers 9

generateMethod · 0.85
getRelativePathFunction · 0.85
_generateBaseUriMethod · 0.85
applyMethod · 0.85
applyMethod · 0.85
applyMethod · 0.85
generateMethod · 0.85
generateMethod · 0.85
generateMethod · 0.85

Calls 3

splitMethod · 0.80
sliceMethod · 0.80
replaceMethod · 0.45

Tested by

no test coverage detected