-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Ability to resolve npm specifier imports in bundlers made for npm #17043
Comments
Replying here from the thread in #15427
Errr, yeah I mean rollup. It's only CLI and we want to keep it that way. I suggest to just leave all the resolution to Deno without meddling with package.json yourself - it should be more reliable that way (avoiding discrepancies how Deno discovers dependencies and how your code would do it).
Yes, let's move the discussion on this particular topic to that issue.
I discussed it with @dsherret yesterday, and indeed the cache path is only specified in non-JSON output, we will most likely add path to the cached sources to the JSON output. Have you started any work on the plugin already? |
Hi! Ok so looking at deno info a bit more it might work pretty well.
That has the information I need to find the module (as for npm it will just be {npmpath}/{name}@{version}. I was surprised at the output difference of
I'm currently playing around with something locally to get it working. When I have an initial pass I'll put something on Github/deno_x. Is there any documentation or code references for how Deno currently resolves npm specifiers (with dependencies). |
Will Few things to figure out for getting a bundler plugin working:
I noticed you've tried writing a rollup plugin, how did you go? #16089 (comment) |
I'm not sure why there's a difference. @dsherret could you explain it? That said we should add complete path to cached module in the JSON output.
No, there's no such documentation and I strongly feel it should remain a black box - otherwise if we need to change or fix something the plugins relying on this will break, whilst if they shell out to
Unclear at the moment -
That's already handled by various subcommands (like
I think plugins should only use
That's reasonable - with latest version
When I was working on it we didn't have support for npm specifier in Let me know when you get something published, I can give you a hand smoothing out problematic parts. |
One of the difficult parts I'm having right now is resolving nested entry points. Atm I'm getting the Deno cache absolute location of a npm pkg and then calling this.resolve to get the node resolver to do the heavy lifting. It works, until I encounter a nested entry point, and then I'm at a loss for how to make it work without reimplementing node resolver, specifically the pkg json exports logic. When you were writing your plugin did you do anything special to handle this? Basically I'd love the Deno plugin to only care about two things:
But (2) I'm finding difficult. |
@itsdouges could you give an example of such entry point? Maybe I'm missing something here. Also it feels I should start a new repository for a rollup plugin and we could work from there? |
Ones such as @babel/runtime/helpers/AsyncGenerator. It's easy enough to find the location of @babel/runtime folder in the Deno cache and pass it as an absolute path to the node resolver plugin via this.resolve, but when it's a nested entry point like above I'm at a loss if it's still possible to pass an absolute path... |
So doing |
Sweet thank you mate, that would provide a way forward 😊 |
@bartlomieju is there any issue I can follow for successfully resolving the cache location of npm dependencies?
And so on. |
Opened: #17168 |
This is now fixed because |
Hi! As mentioned in #15960 I'm opening a new issue to talk about this issue I'm having.
Thanks to #15427 and npm: specifiers hitting stable you can run Vite in Deno which works. One issue is that for any dependencies in the frontend graph that aren't executed in Deno they don't ever get their dependencies resolved/cached.
Because of this you have to rely on importing them in any file that is executed in Deno, e.g. in the React example here https://deno.land/manual@v1.28.2/node/how_to_with_npm/react#add-a-router you show importing the dependencies used in the frontend app in the config file.
This will then "install" the dependencies on run, and then make them available in node_modules for Vite (and any other bundler). This unblocks usage but causes a few problems:
react
instead ofnpm:react
)react
instead ofnpm:react
) they aren't type checked (because Deno doesn't know about the module). So you need to resort to creating aimport_map.json
, example below:react
it will add to the source file thereact/jsx-runtime
import... but of course that isn't a real dependency for Deno so it's another entry to add to the import_mapDoing all of the above at the very least gets it into a usable state but it's not ideal. If we could resolve Deno npm specifier imports (and during resolution it installs/caches them) I can imagine a plugin being written for bundlers to make use of it so it has better interop.
I will say the interop between a natively installed npm package (via npm, and hopefully other package managers) and Deno npm:specifiers worked suprisingly well and the two seem to work together with each other, very great stuff.
Let me know if you need more info 😄.
The text was updated successfully, but these errors were encountered: