{"version":3,"file":"utils.mjs","names":[],"sources":["../src/utils.ts"],"sourcesContent":["import { fileURLToPath, pathToFileURL } from 'node:url';\n\nexport function local(file: string) {\n\treturn fileURLToPath(new URL(`../node_modules/.bin/${file}`, import.meta.url));\n}\n\n/** Error class for `bsh` failures. Carries a stable, greppable code. */\nexport class ToolsError extends Error {\n\tcode: string;\n\n\tconstructor(message: string, code: string) {\n\t\tsuper(message);\n\t\tthis.name = 'ToolsError';\n\t\tthis.code = code;\n\t}\n}\n\n/**\n * Compute a relative path from one directory URL to another, for APIs that\n * require a string path (e.g. `fs.symlink` targets). POSIX-style — forward\n * slashes are accepted by every platform Node supports for this purpose.\n */\nexport function relativeUrlPath(from: URL, to: URL): string {\n\tconst fromParts = from.pathname.split('/').filter(Boolean);\n\tconst toParts = to.pathname.split('/').filter(Boolean);\n\tlet common = 0;\n\twhile (\n\t\tcommon < fromParts.length &&\n\t\tcommon < toParts.length &&\n\t\tfromParts[common] === toParts[common]\n\t) {\n\t\tcommon++;\n\t}\n\tconst ups = fromParts.length - common;\n\tconst parts = [...Array<string>(ups).fill('..'), ...toParts.slice(common)];\n\treturn parts.map(decodeURIComponent).join('/');\n}\n\n/**\n * Resolve a symlink target (as returned by `fs.readlink`, which may be\n * relative to the link's directory) to an absolute URL.\n */\nexport function resolveLinkTarget(linkDir: URL, target: string): URL {\n\tif (target.startsWith('/') || /^[a-zA-Z]:[\\\\/]/.test(target)) {\n\t\treturn pathToFileURL(target);\n\t}\n\treturn new URL(target, linkDir);\n}\n"],"mappings":";;AAEA,SAAgB,MAAM,MAAc;CACnC,OAAO,cAAc,IAAI,IAAI,wBAAwB,QAAQ,OAAO,KAAK,GAAG,CAAC;AAC9E;;AAGA,IAAa,aAAb,cAAgC,MAAM;CACrC;CAEA,YAAY,SAAiB,MAAc;EAC1C,MAAM,OAAO;EACb,KAAK,OAAO;EACZ,KAAK,OAAO;CACb;AACD;;;;;;AAOA,SAAgB,gBAAgB,MAAW,IAAiB;CAC3D,MAAM,YAAY,KAAK,SAAS,MAAM,GAAG,CAAC,CAAC,OAAO,OAAO;CACzD,MAAM,UAAU,GAAG,SAAS,MAAM,GAAG,CAAC,CAAC,OAAO,OAAO;CACrD,IAAI,SAAS;CACb,OACC,SAAS,UAAU,UACnB,SAAS,QAAQ,UACjB,UAAU,YAAY,QAAQ,SAE9B;CAED,MAAM,MAAM,UAAU,SAAS;CAE/B,OAAO,CADQ,GAAG,MAAc,GAAG,CAAC,CAAC,KAAK,IAAI,GAAG,GAAG,QAAQ,MAAM,MAAM,CAC7D,CAAC,CAAC,IAAI,kBAAkB,CAAC,CAAC,KAAK,GAAG;AAC9C;;;;;AAMA,SAAgB,kBAAkB,SAAc,QAAqB;CACpE,IAAI,OAAO,WAAW,GAAG,KAAK,kBAAkB,KAAK,MAAM,GAC1D,OAAO,cAAc,MAAM;CAE5B,OAAO,IAAI,IAAI,QAAQ,OAAO;AAC/B"}