@supernovaio/cli
Version:
Supernova.io Command Line Interface
23 lines (21 loc) • 1.1 kB
JavaScript
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="2dabe1ff-5512-5ef7-813f-572f6a4a2409")}catch(e){}}();
import path from "node:path";
const slashRegex = /[\\/]/g;
export function trimFileName(fileName, cwd = process.cwd(), platform) {
const pathLib = platform ? path[platform] : path;
const originalSep = fileName.match(slashRegex)?.[0] || pathLib.sep;
const normalizedFileName = pathLib.normalize(fileName);
const { root } = pathLib.parse(cwd);
let parent = cwd;
do {
if (normalizedFileName.startsWith(parent)) {
return (pathLib
.relative(pathLib.dirname(parent), normalizedFileName)
.replaceAll(slashRegex, originalSep));
}
parent = pathLib.dirname(parent);
} while (parent !== root);
return fileName;
}
//# sourceMappingURL=trim-file-name.js.map
//# debugId=2dabe1ff-5512-5ef7-813f-572f6a4a2409