-
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
Support package.json auto-discovery and bare specifiers #17491
Comments
I expect the cwd-only discovery will need to be revisited, as enterprising Node users will have grown used to the recursive search and will expect that to work the same in Deno as well.
Won't this bring sloppy mode support into Deno as well? A CJS Node project without
This is of course just an example but why would something like this exist?
Definitely support this being an external script. It's a one-time-only script so its performance is not super critical, so whether this is written in well-optimised TypeScript or well-optimised Rust should make no practical difference. |
Can you outline the reasoning behind this suggestion? It seems to me like migrating a Node project to Deno already is fairly easy since we got |
@aapoalas Most likely. I personally am thinking we shouldn't auto-discover package.json recursively because it would probably add too much of a performance hit in cases that one wasn't used. I think we might want to only support a package.json if it's explicitly specified (ex. specified in a deno.json or explicitly provided on the command line).
There's certain features we just won't support and we don't expect everything to work. IMO, code relying on sloppy mode would be an example code that wouldn't work in Deno.
This already works in package.json files (npm package aliasing). I'll remove that from the example because it's confusing and not many people know about that feature. It was added to show off something else that didn't make the cut.
I also think it should be an external script. It would be easier to maintain it and add a bunch of "nice to have" features that way, which would otherwise be hard to get merged into the CLI.
@KnorpelSenf Bartek will be able to explain better than me. cc @bartlomieju |
That's partially true - eg. for Vite projects currently you need to put imports for all your dependencies in Additionally copy-pasting another answer from other thread:
Some frameworks/build tools from npm still produce CommonJS output (eg. NextJS). We are still evaluating if this is needed, but with our current knowledge it is - it would be silly to support developing projects using these frameworks but not allowing to actually deploy/run the project. No one's happy about it, but it's an escape hatch (we're consider adding a warning about running CommonJS modules). |
I understand. How about limiting the auto-discovery of |
Specifying via |
One thing that came to mind: What's the long term view of this feature related to authoring libraries/ modules, NPM and other registries, and Deno as that authoring tool? And the Deno ecosystem in general? Currently dnt offers a way to author modules bound for NPM using Deno, but that is obviously not good enough since this issue is raised. Deno's NPM support makes an NPM first stance possible, in which case supporting package.json near fully makes sense. If the aim is to only enable transitioning from Node authoring to Deno authoring easily then a conversion script makes sense, which would then relegate package.json to only an NPM metadata file. A hybrid strategy where package.json is near fully supported (dependencies, scripts, scope?, ...) AND a conversion script is provided AND /x/ registry tries to take on a more NPM-like form isn't really pushing for projects to move into the Deno ecosystem, and sort of reduces reasons to use the Deno ecosystem since it is becoming more like a small NPM. As a hardliner I would of course prefer that a conversion script would be provided but no auto-discovery would be implemented. Then again, it may be a better idea in the long term to simply go quite all-in on NPM and adopt package.json completely. |
With #17864 landed, this is now done. |
Moved out from #17475
import express from "express"
)deno.json
take precedence overpackage.json
(bare specifiers first are resolved indeno.json
and then fall back topackage.json
)These changes will allow most projects written for Node.js to work out-of-the-box in Deno.
Future support for
{ "type": "commonjs" }
for running legacy code.Example. Suppose you have a
package.json
file like this:Then
main.ts
file that looks like this, will work out of the box:Side note: Maybe in the future:
deno from-node
subcommands, createsdeno.json
frompackage.json
(doesn’t necessarily need to be built-in, e.g.deno run deno:from-node
) writes adeno.json
, also fixes your node global imports, and node build-in imports.The text was updated successfully, but these errors were encountered: