-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Rule proposal: no-dir-import #1624
Comments
You don't actually have to have full paths (ie, relative paths with index/extensions) inside imports - you can also use "exports" and the package name and define your own API. You can already make extensions required for |
@laysent Thanks for the quick reply 👍
I can't since the main goal is to allow So we can't use "exports" since it's purely Node.js feature and ignored both by the browser and by Deno.
We are migrating from Flow to TS so we can't use So the simplest solution is to add babel plugin add |
imo it's unrealistic to expect a node package to be compatible out of the box with browsers or with deno, and also imo unrealistic to ever have no build process in web dev; either way you should have different files for use in different platforms. You can use |
@ljharb If a library has zero dependencies (or you bundle them during build) and doesn't use anything beyond core JS than it's possible.
I can't since Node 10 is still in LTS and AFAIK it doesn't support |
That's a lot of caveats and inconvenience to make something that's not even objectively desirable, possible. That's true, at the moment only node v13.2+ supports it. Why can't you use |
@ljharb TS forbids you to have extensions at all:
|
Seems like something TS will have to change, to account for node's experimental but native ESM module system. |
AFAIK, the are no way to specify `rulesdir` inside '.eslintrc' config because of that IDE can't run ESLint with default CLI options
We plan to support ESM modules for the next release of
graphql-js
and as part of this effort, we need to have full paths inside imports.I tried to switch to full paths and enable
extensions
rule, but this created a lot of problems with different tooling, so our current approach is to have full paths but without extensions.It means we need to add
/index
to all directory imports see this PR for more details:graphql/graphql-js#2368
Additionally, I wrote custom ESLint rule to enforce this approach:
https://github.com/graphql/graphql-js/blob/master/resources/eslint-rules/no-dir-import.js
I think other maintainers will have similar challenges trying to release ESM build, so do you think it something that should be included in this plugin?
P.S. At the moment I don't have time to polish this rule (add docs and tests), so if anyone wants to work on PR, please feel free to reuse code that I wrote for
graphql-js
:https://github.com/graphql/graphql-js/blob/master/resources/eslint-rules/no-dir-import.js
The text was updated successfully, but these errors were encountered: