forked from import-js/eslint-plugin-import
-
-
Notifications
You must be signed in to change notification settings - Fork 26
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
feat: implement a resolver that supports exports
#209
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
🦋 Changeset detectedLatest commit: e836192 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. |
f6df50e
to
96721df
Compare
96721df
to
e836192
Compare
renovate bot
added a commit
to mmkal/eslint-plugin-mmkal
that referenced
this pull request
Dec 19, 2024
##### [v4.6.0](https://github.com/un-ts/eslint-plugin-import-x/blob/HEAD/CHANGELOG.md#460) ##### Minor Changes - [#209](un-ts/eslint-plugin-import-x#209) [`46d2360`](un-ts/eslint-plugin-import-x@46d2360) Thanks [@SukkaW](https://github.com/SukkaW)! - When `eslint-plugin-import-x` was forked from `eslint-plugin-import`, we copied over the default resolver (which is `eslint-import-resolver-node`) as well. However, this resolver doesn't supports `exports` in the `package.json` file, and the current maintainer of the `eslint-import-resolver-node` (ljharb) doesn't have the time implementing this feature and he locked the issue import-js/eslint-plugin-import#1810. So we decided to implement our own resolver that "just works". The new resolver is built upon the [`enhanced-resolve`](https://www.npmjs.com/package/enhanced-resolve) that implements the full Node.js [Resolver Algorithm](https://nodejs.org/dist/v14.21.3/docs/api/esm.html#esm_resolver_algorithm). The new resolver only implements the import resolver interface v3, which means you can only use it with ESLint Flat config. For more details about the import resolver interface v3, please check out [#192](un-ts/eslint-plugin-import-x#192). In the next major version of `eslint-plugin-import-x`, we will remove the `eslint-import-resolver-node` and use this new resolver by default. In the meantime, you can try out this new resolver by setting the `import-x/resolver-next` option in your `eslint.config.js` file: ```js // eslint.config.js const eslintPluginImportX = require('eslint-plugin-import-x'); const { createNodeResolver } = eslintPluginImportX; module.exports = { plugins: { 'import-x': eslintPluginImportX, }, settings: { 'import-x/resolver-next': [ // This is the new resolver we are introducing createNodeResolver({ /** * The allowed extensions the resolver will attempt to find when resolving a module * By default it uses a relaxed extension list to search for both ESM and CJS modules * You can customize this list to fit your needs * * @default ['.mjs', '.cjs', '.js', '.json', '.node'] */ extensions?: string[]; /** * Optional, the import conditions the resolver will used when reading the exports map from "package.json" * By default it uses a relaxed condition list to search for both ESM and CJS modules * You can customize this list to fit your needs * * @default ['default', 'module', 'import', 'require'] */ conditions: ['default', 'module', 'import', 'require'], // You can pass more options here, see the enhanced-resolve documentation for more details // https://github.com/webpack/enhanced-resolve/tree/v5.17.1?tab=readme-ov-file#resolver-options }), // you can add more resolvers down below require('eslint-import-resolver-typescript').createTypeScriptImportResolver( /** options of eslint-import-resolver-typescript */ ) ], }, }; ``` We do not plan to implement reading `baseUrl` and `paths` from the `tsconfig.json` file in this resolver. If you need this feature, please checkout [eslint-import-resolver-typescript](https://www.npmjs.com/package/eslint-import-resolver-typescript) (also powered by `enhanced-resolve`), [eslint-import-resolver-oxc](https://www.npmjs.com/package/eslint-import-resolver-oxc) (powered by `oxc-resolver`), [eslint-import-resolver-next](https://www.npmjs.com/package/eslint-import-resolver-next) (also powered by `oxc-resolver`), or other similar resolvers. ##### Patch Changes - [#206](un-ts/eslint-plugin-import-x#206) [`449738f`](un-ts/eslint-plugin-import-x@449738f) Thanks [@privatenumber](https://github.com/privatenumber)! - insert type prefix without new line
renovate bot
added a commit
to mmkal/eslint-plugin-mmkal
that referenced
this pull request
Dec 19, 2024
##### [v4.6.1](https://github.com/un-ts/eslint-plugin-import-x/blob/HEAD/CHANGELOG.md#461) ##### Patch Changes - [#211](un-ts/eslint-plugin-import-x#211) [`be9c3e8`](un-ts/eslint-plugin-import-x@be9c3e8) Thanks [@mrginglymus](https://github.com/mrginglymus)! - Fix enhanced-resolve dependency ##### [v4.6.0](https://github.com/un-ts/eslint-plugin-import-x/blob/HEAD/CHANGELOG.md#460) ##### Minor Changes - [#209](un-ts/eslint-plugin-import-x#209) [`46d2360`](un-ts/eslint-plugin-import-x@46d2360) Thanks [@SukkaW](https://github.com/SukkaW)! - When `eslint-plugin-import-x` was forked from `eslint-plugin-import`, we copied over the default resolver (which is `eslint-import-resolver-node`) as well. However, this resolver doesn't supports `exports` in the `package.json` file, and the current maintainer of the `eslint-import-resolver-node` (ljharb) doesn't have the time implementing this feature and he locked the issue import-js/eslint-plugin-import#1810. So we decided to implement our own resolver that "just works". The new resolver is built upon the [`enhanced-resolve`](https://www.npmjs.com/package/enhanced-resolve) that implements the full Node.js [Resolver Algorithm](https://nodejs.org/dist/v14.21.3/docs/api/esm.html#esm_resolver_algorithm). The new resolver only implements the import resolver interface v3, which means you can only use it with ESLint Flat config. For more details about the import resolver interface v3, please check out [#192](un-ts/eslint-plugin-import-x#192). In the next major version of `eslint-plugin-import-x`, we will remove the `eslint-import-resolver-node` and use this new resolver by default. In the meantime, you can try out this new resolver by setting the `import-x/resolver-next` option in your `eslint.config.js` file: ```js // eslint.config.js const eslintPluginImportX = require('eslint-plugin-import-x'); const { createNodeResolver } = eslintPluginImportX; module.exports = { plugins: { 'import-x': eslintPluginImportX, }, settings: { 'import-x/resolver-next': [ // This is the new resolver we are introducing createNodeResolver({ /** * The allowed extensions the resolver will attempt to find when resolving a module * By default it uses a relaxed extension list to search for both ESM and CJS modules * You can customize this list to fit your needs * * @default ['.mjs', '.cjs', '.js', '.json', '.node'] */ extensions?: string[]; /** * Optional, the import conditions the resolver will used when reading the exports map from "package.json" * By default it uses a relaxed condition list to search for both ESM and CJS modules * You can customize this list to fit your needs * * @default ['default', 'module', 'import', 'require'] */ conditions: ['default', 'module', 'import', 'require'], // You can pass more options here, see the enhanced-resolve documentation for more details // https://github.com/webpack/enhanced-resolve/tree/v5.17.1?tab=readme-ov-file#resolver-options }), // you can add more resolvers down below require('eslint-import-resolver-typescript').createTypeScriptImportResolver( /** options of eslint-import-resolver-typescript */ ) ], }, }; ``` We do not plan to implement reading `baseUrl` and `paths` from the `tsconfig.json` file in this resolver. If you need this feature, please checkout [eslint-import-resolver-typescript](https://www.npmjs.com/package/eslint-import-resolver-typescript) (also powered by `enhanced-resolve`), [eslint-import-resolver-oxc](https://www.npmjs.com/package/eslint-import-resolver-oxc) (powered by `oxc-resolver`), [eslint-import-resolver-next](https://www.npmjs.com/package/eslint-import-resolver-next) (also powered by `oxc-resolver`), or other similar resolvers. ##### Patch Changes - [#206](un-ts/eslint-plugin-import-x#206) [`449738f`](un-ts/eslint-plugin-import-x@449738f) Thanks [@privatenumber](https://github.com/privatenumber)! - insert type prefix without new line
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The PR implements a default resolver that supports
exports
frompackage.json
.More details can be found at #208.
Fixes #208.