Last active
March 4, 2025 10:45
Revisions
-
danielweck revised this gist
Mar 30, 2022 . 2 changed files with 18 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,16 @@ module.exports = { settings: { // optionally, if TypeScript project: // 'import/parsers': { // '@typescript-eslint/parser': ['.ts', '.tsx'], // }, 'import/resolver': { // optionally, if TypeScript project: // https://github.com/alexgorbatchev/eslint-import-resolver-typescript // typescript: { // alwaysTryTypes: false, // project: ['./PATH/TO/tsconfig.json'], // }, [path.resolve('./eslint-plugin-import-resolver.js')]: { someConfig: 1 }, }, }, This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,12 +1,20 @@ const path = require('path'); const { resolve: resolveExports } = require('resolve.exports'); // optionally handle NodeJS built-ins just in case not handled by another ESLint module resolver in the chain const { builtinModules } = require('module'); const builtins = new Set(builtinModules); /** * @param {string} source source * @param {string} file file * @param {Object} _config config */ const resolve = (source, file, _config) => { if (builtins.has(source)) { // return { found: false }; // this also works? return { found: true, path: null }; } try { const moduleId = require.resolve(source, { paths: [path.dirname(file)] }); return { found: true, path: moduleId }; -
danielweck revised this gist
Feb 23, 2022 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,7 @@ module.exports = { settings: { 'import/resolver': { [path.resolve('./eslint-plugin-import-resolver.js')]: { someConfig: 1 }, }, }, }, -
danielweck revised this gist
Feb 23, 2022 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -5,6 +5,7 @@ Relies on NPM package `resolve.exports` https://github.com/lukeed/resolve.export See: * https://github.com/import-js/eslint-plugin-import/issues/1868 * https://github.com/import-js/eslint-plugin-import/issues/1810 * https://github.com/browserify/resolve/pull/224 * https://github.com/wooorm/import-meta-resolve/issues/2 * https://github.com/weiran-zsd/eslint-plugin-node/pull/4 -
danielweck revised this gist
Feb 23, 2022 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -10,4 +10,5 @@ See: * https://github.com/weiran-zsd/eslint-plugin-node/pull/4 * https://github.com/mysticatea/eslint-plugin-node/issues/255 * https://github.com/mysticatea/eslint-plugin-node/issues/244 * https://github.com/mysticatea/eslint-plugin-node/issues/258 * https://github.com/webpack/enhanced-resolve -
danielweck created this gist
Feb 23, 2022 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,7 @@ module.exports = { settings: { 'import/resolver': { [path.resolve('./eslint-plugin-import-resolver.cjs')]: { someConfig: 1 }, }, }, }, This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,13 @@ ESLint import resolver for ESM modules via package.json exports map. Relies on NPM package `resolve.exports` https://github.com/lukeed/resolve.exports See: * https://github.com/import-js/eslint-plugin-import/issues/1868 * https://github.com/browserify/resolve/pull/224 * https://github.com/wooorm/import-meta-resolve/issues/2 * https://github.com/weiran-zsd/eslint-plugin-node/pull/4 * https://github.com/mysticatea/eslint-plugin-node/issues/255 * https://github.com/mysticatea/eslint-plugin-node/issues/244 * https://github.com/mysticatea/eslint-plugin-node/issues/258 This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,27 @@ const path = require('path'); const { resolve: resolveExports } = require('resolve.exports'); /** * @param {string} source source * @param {string} file file * @param {Object} _config config */ const resolve = (source, file, _config) => { try { const moduleId = require.resolve(source, { paths: [path.dirname(file)] }); return { found: true, path: moduleId }; } catch (/** @type {any} */ err) { if (err.code === 'MODULE_NOT_FOUND' && err.path?.endsWith('/package.json')) { const { name, module, main, exports } = require(err.path); const resolved = resolveExports({ name, module, main, exports }, source); const moduleId = path.join(path.dirname(err.path), resolved); return { found: true, path: moduleId }; } return { found: false }; } }; module.exports = { interfaceVersion: 2, resolve, };