UNPKG

@intlayer/chokidar

Version:

Scans and builds Intlayer declaration files into dictionaries based on Intlayer configuration.

1 lines 2.19 kB
{"version":3,"file":"resolveRelativePath.cjs","names":[],"sources":["../../../src/utils/resolveRelativePath.ts"],"sourcesContent":["import { dirname, isAbsolute, normalize, resolve } from 'node:path';\n\nexport const resolveRelativePath = (\n path: string,\n sourcePath: string,\n baseDir: string\n) => {\n // Handle absolute paths\n if (isAbsolute(path)) {\n const normalizedResult = normalize(path);\n const normalizedBaseDir = normalize(baseDir);\n\n // Check if it's relative to baseDir (starts with /)\n // but not a system path (like /usr/local)\n if (\n path.startsWith('/') &&\n !normalizedResult.startsWith(normalizedBaseDir)\n ) {\n // Try to resolve it relative to baseDir first\n const relativeToBase = resolve(baseDir, path.substring(1));\n\n // If the path doesn't exist in common system directories, treat as relative to baseDir\n if (\n !path.startsWith('/usr/') &&\n !path.startsWith('/etc/') &&\n !path.startsWith('/var/') &&\n !path.startsWith('/home/') &&\n !path.startsWith('/Users/') &&\n !path.startsWith('/tmp/') &&\n !path.startsWith('/private/') &&\n !path.startsWith('/opt/')\n ) {\n return relativeToBase;\n }\n }\n\n // It's a true system absolute path\n return normalizedResult;\n }\n\n // Handle relative paths (starting with ./ or ../)\n if (path.startsWith('./') || path.startsWith('../')) {\n const fileDir = dirname(sourcePath);\n return resolve(fileDir, path);\n }\n\n // Default case: treat as relative to baseDir\n return resolve(baseDir, path);\n};\n"],"mappings":";;;;;AAEA,MAAa,uBACX,MACA,YACA,YACG;AAEH,+BAAe,KAAK,EAAE;EACpB,MAAM,4CAA6B,KAAK;EACxC,MAAM,6CAA8B,QAAQ;AAI5C,MACE,KAAK,WAAW,IAAI,IACpB,CAAC,iBAAiB,WAAW,kBAAkB,EAC/C;GAEA,MAAM,wCAAyB,SAAS,KAAK,UAAU,EAAE,CAAC;AAG1D,OACE,CAAC,KAAK,WAAW,QAAQ,IACzB,CAAC,KAAK,WAAW,QAAQ,IACzB,CAAC,KAAK,WAAW,QAAQ,IACzB,CAAC,KAAK,WAAW,SAAS,IAC1B,CAAC,KAAK,WAAW,UAAU,IAC3B,CAAC,KAAK,WAAW,QAAQ,IACzB,CAAC,KAAK,WAAW,YAAY,IAC7B,CAAC,KAAK,WAAW,QAAQ,CAEzB,QAAO;;AAKX,SAAO;;AAIT,KAAI,KAAK,WAAW,KAAK,IAAI,KAAK,WAAW,MAAM,CAEjD,sDADwB,WACF,EAAE,KAAK;AAI/B,+BAAe,SAAS,KAAK"}