-
-
Notifications
You must be signed in to change notification settings - Fork 86
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
Update package.json to exports itself #243
Conversation
Pull Request Test Coverage Report for Build 331e3533a24f2ead6c2d9986b725ca42cbeefafc-PR-243Warning: This coverage report may be inaccurate.This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.
Details
💛 - Coveralls |
Why would you like to import Stylis' |
Oh, gotcha. I don't think this is a scalable solution though - they should switch to |
Btw. from what I remember Svelte's compiler is Rollup-based and it seems that |
You're right this should work with the |
Is this specific to svelte only? Because stylis doesn't export a svelte pkg.json field making this issue moot? |
Stylis don't need to modify its |
@thysultan the problem is only that Svelte's compiler is trying to require the |
I'd imagine many other packages would have this same issue, @Graphmaxer can you file this issue with the svelte compiler. Thanks. |
@thysultan any other package using “exports” but not explicitly including package.json does have this issue, and the fix in this PR is the only solution available. The svelte compiler has no reliable way to do this otherwise. |
@ljharb Why using FS APIs is not a possible solution for the Svelte compiler? |
It’s impossible to reliably know where package.json lives on the filesystem. That plugin is using heuristics to figure out the package name, which does not reliably locate the proper package.json in every case. As a member of the node modules team and the maintainer of https://npmjs.com/resolve, i can assure you that the only fix (prior to node itself adding an api for locating a package directory) is for every individual package using “exports” to also add package.json to it. |
I know about your involvement in those projects but I would also like to understand the issue at hand (so for example I could explain it to others in the future). I fail to see when this heuristic could fail. According to the https://nodejs.org/api/esm.html#esm_resolver_algorithm and the PACKAGE_RESOLVE algorithm
But I can't find anything beyond that and this statement doesn't seem to tell me on its own how this is resolved. Also, the call to READ_PACKAGE_JSON looks like this: READ_PACKAGE_JSON(packageURL) (step 10.4) so either way this is resolved from the "root" of the package so how this could return anything beyond |
The issue is exactly that - when an exports dot points to a file in a dir, that in turn has a package.json. Certainly tools could reimplement node’s own require algorithm, as resolve itself has, but this is far more complicated than packages adding a single line to their own exports object. |
I don't follow. Could you illustrate this with a simple example?
Well, at least if tools do this then this complexity lies just in a couple of tools whereas if the community will be forced to add |
The longer term solution is to add an api to node itself to expose the package dir, which tools can then use. That solution is not yet ready, and in the interim, a package’s choices are “don’t use exports”, or “add package.json”, or “screw over users by breaking the majority of tools that don’t yet use fs APIs or resolve”. |
I find it hard to blame package authors for "screwing over users" if this has not been accounted for by the node team... If anything I feel like this should be prioritized there so we wouldn't have to do anything for a short period of time in which this stays "bugged" on the node's side. That being said I still have no idea how a package can be structured right now that would be incorrectly handled by the |
That is a reasonable reaction, and i don’t dispute it - but that doesn’t change the reality now. I’d have to take a look at its logic to locate bugs, but i don’t pay much attention to the rollup ecosystem, so I’m not sure when I’d find time. |
@thysultan Thanks for reopening this. I just merged master to resolve conflicts. |
This change is needed to access the package.json for external bundlers as documented here and discussed here. I also did the same for another npm package here.