eslint-import-resolver-node
Advanced tools
Comparing version 0.3.5 to 0.3.6
33
index.js
@@ -20,3 +20,4 @@ 'use strict'; | ||
try { | ||
resolvedPath = resolve.sync(source, opts(file, config)); | ||
const cachedFilter = function (pkg, dir) { return packageFilter(pkg, dir, config); }; | ||
resolvedPath = resolve.sync(source, opts(file, config, cachedFilter)); | ||
log('Resolved to:', resolvedPath); | ||
@@ -30,3 +31,3 @@ return { found: true, path: resolvedPath }; | ||
function opts(file, config) { | ||
function opts(file, config, packageFilter) { | ||
return Object.assign({ | ||
@@ -41,14 +42,30 @@ // more closely matches Node (#333) | ||
basedir: path.dirname(path.resolve(file)), | ||
packageFilter: packageFilter, | ||
packageFilter, | ||
}); | ||
} | ||
function packageFilter(pkg) { | ||
function identity(x) { return x; } | ||
function packageFilter(pkg, dir, config) { | ||
let found = false; | ||
const file = path.join(dir, 'dummy.js'); | ||
if (pkg.module) { | ||
pkg.main = pkg.module; | ||
} else if (pkg['jsnext:main']) { | ||
pkg.main = pkg['jsnext:main']; | ||
try { | ||
resolve.sync(String(pkg.module).replace(/^(?:\.\/)?/, './'), opts(file, config, identity)); | ||
pkg.main = pkg.module; | ||
found = true; | ||
} catch (err) { | ||
log('resolve threw error trying to find pkg.module:', err); | ||
} | ||
} | ||
if (!found && pkg['jsnext:main']) { | ||
try { | ||
resolve.sync(String(pkg['jsnext:main']).replace(/^(?:\.\/)?/, './'), opts(file, config, identity)); | ||
pkg.main = pkg['jsnext:main']; | ||
found = true; | ||
} catch (err) { | ||
log('resolve threw error trying to find pkg[\'jsnext:main\']:', err); | ||
} | ||
} | ||
return pkg; | ||
} |
{ | ||
"name": "eslint-import-resolver-node", | ||
"version": "0.3.5", | ||
"version": "0.3.6", | ||
"description": "Node default behavior import resolution plugin for eslint-plugin-import.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5373
59