denoland / deno

A modern runtime for JavaScript and TypeScript.
https://deno.com
MIT License
98.01k stars 5.39k forks source link

bug: `deno install -g` fails to install local files if they are not prefixed with `./` if npm or jsr pkg exists with same name #26969

Closed KnorpelSenf closed 21 hours ago

KnorpelSenf commented 1 day ago

https://github.com/denoland/deno/pull/26629 caused a regression in 2.1.0 that prevents deno install -g from handling local files correctly.

Repro

echo 'console.log("hi");' > cli.ts
deno install -g --name my-cli cli.ts

Expected Result

The program is installed correctly and I can use cli.ts as a globally installed CLI.

Actual Result

error: cli.ts is missing a prefix. Did you mean `deno install -g npm:cli.ts`?

With Deno 2.0.6, everything works as expected. However, since Deno 2.1.0, the above error is thrown.

Ideally, I would like the previous functionality to keep on working. Bare filenames are supported everywhere else and it is just bad DX not to do it here.

On the other hand, if you want to enfore a prefix even for local files for some reason, then this still has to be fixed. The error is nonsense. It should not suggest an import from npm but rather suggest me to prefix the path with ./.

But I believe that the whole point of prefixing jsr/npm imports was to be able to support local files cleanly, so I assume that the behaviour from 2.0.6 can just be restored.

dsherret commented 22 hours ago

This occurs because https://www.npmjs.com/package/cli.ts exists

KnorpelSenf commented 22 hours ago

Are you saying that the Deno CLI first contacts the npm registry before even checking for the file on disk? 🫠

bartlomieju commented 22 hours ago

Yes, it's a regression that I didn't catch in code review.

mbrdg commented 22 hours ago

I'm already rolling a change to fix this.

dsherret commented 22 hours ago

@mbrdg there's a fix https://github.com/denoland/deno/pull/26975

KnorpelSenf commented 20 hours ago

Thanks for the super fast turnaround time!