NestarZ
NestarZ3mo ago

Like import.meta.resolve("./bla/bla") but so that it return me the relative cwd path

How using Deno to do something like import.meta.resolve("./bla/bla") but so that it return me the relative path relative to the current working directory ?
3 Replies
Deno AI Helper
Deno AI Helper3mo ago
I wasn't able to find the answer to your question in the official Deno documentation. However, based on your message, it seems like you're looking for a way to resolve a path relative to the current working directory (CWD) in Deno. In Deno, you can use Deno.cwd() to get the current working directory and then use the path module from Deno's standard library to resolve or join paths. Here's an example of how you might achieve this:
import { join } from "https://deno.land/std@0.145.0/path/mod.ts";

const relativePath = join(Deno.cwd(), "./bla/bla");
console.log(relativePath);
import { join } from "https://deno.land/std@0.145.0/path/mod.ts";

const relativePath = join(Deno.cwd(), "./bla/bla");
console.log(relativePath);
This will give you an absolute path, not a relative one. If you need a relative path, you could potentially calculate it by comparing the absolute path to the CWD, but this functionality is not directly provided by Deno's standard library. Please note that this advice is not based on the Deno documentation, and I would advise you to double-check the accuracy of this advice and test it to ensure it meets your requirements.
lcasdev
lcasdev3mo ago
@NestarZ you can call import.meta.resolve() to get the full path, then use relative() from @std/path to make it relative to Deno.cwd()
NestarZ
NestarZ3mo ago
thank you @lucacasonato