esm.sh icon indicating copy to clipboard operation
esm.sh copied to clipboard

API that provides all the urls of packages that are being imported by an package

Open renhiyama opened this issue 2 years ago • 4 comments

How does it help? Lets us download all the dependencies of the packages instead of executing the whole package before. This lets us bundle/vendor dependencies without running them. Whats my usecase? Currently working on URL Imports in Nodejs, and it works pretty fine, with some tweaks and polyfills. You can read source code at https://github.com/rovelstars/reejs/blob/master/project/import.js and it uses Nodejs' vm modules to sandbox the downloaded code and run it. Example that my code works incase you think its a bad idea:

But now my project installs deps only during it starts the application, so I would like to basically crawl and download before the application starts (preferrably for those installation and build scripts in heroku/railway). This will also allow me to have a uninstaller too, that doesnt executes the whole code again before crawling for all the links and then uninstalling...

renhiyama avatar Aug 05 '22 03:08 renhiyama

You might be interested in the deno info CLI, that can report the dependency graph of a module file/URL:

https://deno.land/manual/tools/dependency_inspector

It has a --json option if you want to use the dependency graph information programatically.

Deno also has commands for caching and vendoring, but they might not be helpful to you if you are using Node.js at runtime.

jaydenseric avatar Aug 10 '22 05:08 jaydenseric

As you figured out I am using nodejs as runtime, deno info won't help me too lol. This api feature would help pre-downloading required packages instead of downloadingthem at runtime :clap:

renhiyama avatar Aug 10 '22 09:08 renhiyama

Also it looks like Deno downloads the code in order to crawl the links.

renhiyama avatar Aug 10 '22 11:08 renhiyama

If esm.sh could provide an api for all the urls used, it would make it easier to download files in parallel since the code doesnt run and crawl one by one file.

renhiyama avatar Aug 10 '22 11:08 renhiyama

esm.sh has now support for preloading of js files. Consider this issue as resolved.

renhiyama avatar Oct 05 '23 13:10 renhiyama