Skip to content

Commit

Permalink
[resolvers] [*] [refactor] avoid hoisting
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Mar 13, 2024
1 parent 51185dd commit 2d38b33
Show file tree
Hide file tree
Showing 2 changed files with 314 additions and 314 deletions.
40 changes: 20 additions & 20 deletions resolvers/node/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,6 @@ const log = require('debug')('eslint-plugin-import:resolver:node');

exports.interfaceVersion = 2;

exports.resolve = function (source, file, config) {
log('Resolving:', source, 'from:', file);
let resolvedPath;

if (isCoreModule(source)) {
log('resolved to core');
return { found: true, path: null };
}

try {
const cachedFilter = function (pkg, dir) { return packageFilter(pkg, dir, config); };
resolvedPath = resolve(source, opts(file, config, cachedFilter));
log('Resolved to:', resolvedPath);
return { found: true, path: resolvedPath };
} catch (err) {
log('resolve threw error:', err);
return { found: false };
}
};

function opts(file, config, packageFilter) {
return Object.assign({ // more closely matches Node (#333)
// plus 'mjs' for native modules! (#939)
Expand Down Expand Up @@ -64,3 +44,23 @@ function packageFilter(pkg, dir, config) {
}
return pkg;
}

exports.resolve = function (source, file, config) {
log('Resolving:', source, 'from:', file);
let resolvedPath;

if (isCoreModule(source)) {
log('resolved to core');
return { found: true, path: null };
}

try {
const cachedFilter = function (pkg, dir) { return packageFilter(pkg, dir, config); };
resolvedPath = resolve(source, opts(file, config, cachedFilter));
log('Resolved to:', resolvedPath);
return { found: true, path: resolvedPath };
} catch (err) {
log('resolve threw error:', err);
return { found: false };
}
};
Loading

0 comments on commit 2d38b33

Please sign in to comment.