Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deno install -g doesn't auto-discover config file in local directory #27499

Open
johndeighan opened this issue Dec 30, 2024 · 3 comments
Open

Comments

@johndeighan
Copy link

Version: Deno 2.1.4
Using Windows 11

I've posted a question on stackoverflow, at https://stackoverflow.com/questions/79317608/deno-2-configuration-file-not-detected-when-using-compile-command that may explain further

But, here's the jist. If I run deno install -fgA src/bin/compile.js with the current directory set to my project directory (~/vllu below), the files added to my ~/.deno/bin folder include the --no-config option, even though my project root contains a deno.jsonc file. FYI, my directory structure is:

~
   vllu
      deno.jsonc
      src
         lib
            llutils.js
         bin
            compile.js

And I ALWAYS leave the current directory at my project root (i.e. ~/vllu)

The docs I see when running deno compile --help clearly state that the config file should be automatically detected and used. But that's not all. Since there is a --config option for specifying the config file to use, I tried using

deno install -fgA --config ./deno.jsonc src/bin/compile.js

which resulted in this odd behavior:

  1. my config file was copied to the ~/.deno/bin directory, which is odd because the script being installed is NOT copied, but used directly, i.e. if I make changes to compile.js, the command would use those changes, but if I make changes to my deno.jsonc file, those wouldn't be used because the file is copied.

  2. the copied file has the file extension .json even though my config file is named deno.jsonc. It is, in fact, not a valid JSON file since it contains comments and trailing commas. Attempts to load the file as a true JSON file is bound to fail.

Then, after executing the above install command, I found files compile and compile.cmd in my ~/.deno/bin folder:

#!/bin/sh
# generated by deno install
deno "run" "--allow-all" "--config" "C:\Users\johnd\.deno\bin\.compile.deno.json" "file:///C:/Users/johnd/vllu/src/bin/compile.js" "$@"

% generated by deno install %
@deno "run" "--allow-all" "--config" "C:\Users\johnd\.deno\bin\.compile.deno.json" "file:///C:/Users/johnd/vllu/src/bin/compile.js" %*

I'm not sure why I need both, but anyway... when I try to run the command compile llutils (my compile script automatically finds the location of the src/lib/llutils.js file), I get the error:

$ compile llutils
error: Module not found "file:///C:/Users/johnd/.deno/bin/src/lib/llutils.js".
at file:///C:/Users/johnd/vllu/src/bin/compile.js:7:9

The file path it's looking for is entirely wrong. It seems to be looking for src/lib/llutils.js in my ~/.deno/bin folder. FYI, the compile.js script is importing from '@jdeighan/vllu/llutils.js' and the config file contains:

"@jdeighan/vllu/": "./src/lib/",
in the imports section. I'm guessing that Deno changes the current directory, which would, I think, cause the bad file path. If Deno is going to change the working directory, it should modify the relative paths used in the config file.

Also, I tried changing the copied config file extension to .jsonc, and also changing that file extension in both the files compile and compile.cmd, but that made no difference. Perhaps deno loads it as a .jsonc file, even if the extension is .json, which I find very confusing.

@dsherret
Copy link
Member

dsherret commented Dec 30, 2024

I think this is #17855 ?

@dsherret dsherret changed the title deno install command bugs deno install -g doesn't auto-discover config file in local directory Dec 30, 2024
@dsherret
Copy link
Member

Or #17572 ?

@johndeighan
Copy link
Author

I think those issues are related, but I notice that their justification for not using a config file for globally installed commands mention things like TypeScript config, linting and formatting. My main issue has to do with using the 'imports' section of my config since my libraries don't normally use relative paths, but instead use the same syntax that users of my libraries would use, i.e. something more like @jdeighan/vllu/utils.js - where the @jdeighan/vllu is my repo name and an entry in the 'imports' section takes care of mapping the file to my src/lib folder. A technique I learned from NodeJS, really like, and was glad to find in Deno 2. Sadly, that technique doesn't work with installed commands and results in the error message "relative path doesn't start with ., ./ or ../" when it's clearly not a relative path. It took me quite some time to figure out that this was related to running installed commands, especially since I often run those from deno tasks.

I also wonder whether installed commands shouldn't result in files being copied to my ~/.deno/bin folder rather than just being referred to. It would definitely result in more disk space being used, but would allow me to remove the project folder entirely while still allowing the installed command to continue functioning.

And then there's the fact that if I include the config option when installing a command, it copies my deno.jsonc file, but names it something ending with .json - that's just really odd.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants