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

What is the recommended user agent for getting nodejs targetted builds?

Open renhiyama opened this issue 1 year ago • 6 comments

As far as I know, esm.sh checks whether the user agent is deno or not, and then automatically uses the deno target, same for browsers, so what about nodejs? Also anything about bun? (If a third party library can consume URL imports in nodejs, bun can consume too.)

renhiyama avatar Mar 07 '23 04:03 renhiyama

does nodejs/bun support U'rl imports now?

ije avatar Mar 07 '23 04:03 ije

They dont, but if you consider third party implementations, they technically can still consume url imports (if the third party works by downloading the scripts and importing them to nodejs/bun, similar to what you can see in deno.) Nextjs has URL imports in testing (https://esm.vercel.app/) And I'm working on @reejs/imports (& reejs pkg's cli based url imports downloader) npm package to achieve the same thing that deno does. So I thought it would be cool if there's a standard user agent we could use for stability usage with esm.sh so based on what runtime user is using, we could easily send it to esm.sh servers and get the required build ;) without using ?target query.

renhiyama avatar Mar 09 '23 17:03 renhiyama

maybe just similar to deno: Node/16, what do you think?

ije avatar Mar 09 '23 19:03 ije

I was not sure whether this implemented by esm.sh. hopefully it is Bun/x for bun

renhiyama avatar Mar 10 '23 17:03 renhiyama

currently the server use es2022 as the build target for deno, it's good for bun too?

ije avatar Mar 11 '23 13:03 ije

It would be better to use the node target for bun ;p bun tries to work with nodejs, and not like deno where you need to rewrite your whole nodejs project to make it compatible with deno's url imports and security flags that only deno has. Deno also has browser like environment, so most of the code that are made for nodejs has some more polyfills added for deno. it would make more sense to use nodejs' native modules instead of those for more efficiency. Not to mention, you can maybe go forward and instead of not using nodejs as target, add a new target as bun; there are some Bun specific APIs and features that are only available in Bun and have huge performance improvements over Node implementations. You might still need to have node:path and other native node module support for Bun target though.

renhiyama avatar Mar 13 '23 06:03 renhiyama