Skip to content

Commit

Permalink
[resolvers/node] [Refactor] use is-core-module directly
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Nov 29, 2022
1 parent 4e83dcb commit f4f305b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
11 changes: 6 additions & 5 deletions resolvers/README.md
Expand Up @@ -68,16 +68,17 @@ If the resolver cannot resolve `source` relative to `file`, it should just retur
Here is most of the [Node resolver] at the time of this writing. It is just a wrapper around substack/Browserify's synchronous [`resolve`]:

```js
var resolve = require('resolve')
var resolve = require('resolve');
var isCoreModule = require('is-core-module');

exports.resolve = function (source, file, config) {
if (resolve.isCore(source)) return { found: true, path: null }
if (isCoreModule(source)) return { found: true, path: null };
try {
return { found: true, path: resolve.sync(source, opts(file, config)) }
return { found: true, path: resolve.sync(source, opts(file, config)) };
} catch (err) {
return { found: false }
return { found: false };
}
}
};
```

[Node resolver]: ./node/index.js
Expand Down
3 changes: 2 additions & 1 deletion resolvers/node/index.js
@@ -1,6 +1,7 @@
'use strict';

const resolve = require('resolve');
const isCoreModule = require('is-core-module');
const path = require('path');

const log = require('debug')('eslint-plugin-import:resolver:node');
Expand All @@ -11,7 +12,7 @@ exports.resolve = function (source, file, config) {
log('Resolving:', source, 'from:', file);
let resolvedPath;

if (resolve.isCore(source)) {
if (isCoreModule(source)) {
log('resolved to core');
return { found: true, path: null };
}
Expand Down
1 change: 1 addition & 0 deletions resolvers/node/package.json
Expand Up @@ -30,6 +30,7 @@
"homepage": "https://github.com/import-js/eslint-plugin-import",
"dependencies": {
"debug": "^3.2.7",
"is-core-module": "^2.11.0",
"resolve": "^1.22.1"
},
"devDependencies": {
Expand Down

0 comments on commit f4f305b

Please sign in to comment.