Replies: 1 comment
-
|
Careful, import.meta.url won't give you the install directory. When you deno install a script from a remote URL, the generated shim still points at that remote URL, so at runtime import.meta.url is something like https://.../mod.ts, not a local path. new URL(".", import.meta.url).pathname just gives you the remote path portion, and import.meta.filename / import.meta.dirname are only set for local file:// modules, so they're undefined for a remotely installed script. For parameterizing the CLI, the runtime-native ways are:
const [configPath] = Deno.args;
const dir = Deno.env.get("MYTOOL_HOME") ?? "";
Any of those is stable regardless of where the tool is installed. The import.meta.url route only works when you run the script directly from a local file, not through deno install. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi guys,
I'm trying to do something that I'm not sure is supported in Deno and I am wondering if I missed a feature or if there is a possible improvement to Deno.
What
I'm trying to write a CLI tool that's supposed to have access to a single folder on the user's machine. The idea:
So, for example, if a user wants to install my tool in
/home/me/forge, I'd like them to be able to install it withdeno install --allow-read=/home/me/forgeAND I'd like my script to know where that folder is.How
I have tried the options below:
allow-env, breaks#1, two-step installationdeno installcurrently can't do that, I'd have to write a wrapping installation script. Seems convoluted and does not inspire trustFrom my perspective, this looks like a use-case others might run into and it would be nice to have it supported by Deno It would probably best be solved at installation (new capabilities in
deno install?).WDYT? Any solution I missed?
Beta Was this translation helpful? Give feedback.
All reactions