MCPcopy Index your code
hub / github.com/freshframework/fresh / pathToSpec

Function pathToSpec

packages/fresh/src/utils.ts:247–277  ·  view source on GitHub ↗
(outDir: string, spec: string)

Source from the content-addressed store, hash-verified

245
246const PATH_TO_SPEC = /[\\/]+/g;
247export function pathToSpec(outDir: string, spec: string): string {
248 const outDirUrl = pathToFileUrl(outDir);
249
250 if (
251 spec.startsWith("http:") || spec.startsWith("https:") ||
252 spec.startsWith("jsr:")
253 ) {
254 return spec;
255 } else if (spec.startsWith("file://")) {
256 const fileUrl = pathToFileUrl(spec);
257 spec = relativeUrl(outDirUrl, fileUrl);
258 return maybeDot(spec);
259 }
260
261 spec = path.normalize(spec);
262 if (path.isAbsolute(spec)) {
263 const fileUrl = pathToFileUrl(spec);
264 spec = relativeUrl(outDirUrl, fileUrl);
265 return maybeDot(spec);
266 }
267
268 spec = spec.replaceAll(PATH_TO_SPEC, "/");
269 if (spec.startsWith("/")) {
270 const fileUrl = pathToFileUrl(spec);
271 spec = relativeUrl(outDirUrl, fileUrl);
272 return maybeDot(spec);
273 }
274
275 spec = maybeDot(spec);
276 return spec;
277}
278
279function maybeDot(spec: string): string {
280 return spec.startsWith(".") ? spec : `./${spec}`;

Callers 3

utils_test.tsFile · 0.90
flushMethod · 0.90
handlerFunction · 0.85

Calls 3

pathToFileUrlFunction · 0.90
relativeUrlFunction · 0.90
maybeDotFunction · 0.85

Tested by

no test coverage detected