denoland / deno

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

deno.json imports not used when deno run https://xyz/main.ts - feature or bug ? #25994

Open oscar6echo opened 5 days ago

oscar6echo commented 5 days ago

Observation

I noticed that when doing deno run path/to/main.ts the imports field in deno.json is used - as expected.
However when running the same script from remote deno run https:///abc/xyz/main.ts this is not the case.

So if I need distribute a "package" ie a collection of interdependent .ts files then I cannot use the convenience of deno.json/imports.

Question

Is it a feature or a bug ?
If it is a feature, to you plan to allow the use of deno.json in remote runs ?
Or is there a good reason not to ?

Context

I am in a corp env and the best/only way to share such package is via a github enterprise repo.

Repo

To reproduce: https://github.com/oscar6echo/sample-deno-pkg

Screenshots: image

image

image


deno --version                                                                                            
deno 2.0.0-rc.9 (release candidate, release, x86_64-unknown-linux-gnu)
v8 12.9.202.13-rusty
typescript 5.6.2
marvinhagemeister commented 5 days ago

This is expected behaviour and the primary reason we built JSR. With http specifiers there is no concept of a "package". From Deno's point of view these are just a bunch of random files with no relation to each other, apart from the import statements. There is no concept of where a package boundary starts or ends.

This is different when using JSR. There every package can have their own imports mapping and it will be respected as expected.

oscar6echo commented 5 days ago

Thx for the swift reply :+1: Ok very clear ! Does make sense.

In a corp context, where publishing packages anywhere outside incl. JSR is not an option, what would be in your view the best way to share packages ? (I appreciate this is a bit off topic, be grateful for just hints/directions).

bartlomieju commented 5 days ago

@oscar6echo I think there might be a small misunderstanding. You can still use the config file you have there, from a URL - but you will have to specify it explicitly using --config flag.

oscar6echo commented 5 days ago

@bartlomieju Thx for the tip :+1:
After some trial and error I reached the following conclusion with --config.

Indeed if a corresponding deno.json is available on disk it does work.
But if it is remote it does not: --config expects a path, quite reasonably.
If it could also accept a url then It would be possible to run a remote package in one deno run command.
(even if not on JSR - again corp use case)

Would it make sense to allow this ?

image

repo sample-deno-pkg updated.

oscar6echo commented 4 days ago

Still thinking about it :thinking:

It seems the best way to make package available via https is to put all dependencies with full qualified urls in a deps.ts.
Thus:

While it works, is it the recommended way ?