eslint-import-resolver-node 0.3.5 → 0.3.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +25 -8
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -17,7 +17,8 @@ exports.resolve = function (source, file, config) {
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
try {
|
|
20
|
-
|
|
20
|
+
const cachedFilter = function (pkg, dir) { return packageFilter(pkg, dir, config); };
|
|
21
|
+
resolvedPath = resolve.sync(source, opts(file, config, cachedFilter));
|
|
21
22
|
log('Resolved to:', resolvedPath);
|
|
22
23
|
return { found: true, path: resolvedPath };
|
|
23
24
|
} catch (err) {
|
|
@@ -26,7 +27,7 @@ exports.resolve = function (source, file, config) {
|
|
|
26
27
|
}
|
|
27
28
|
};
|
|
28
29
|
|
|
29
|
-
function opts(file, config) {
|
|
30
|
+
function opts(file, config, packageFilter) {
|
|
30
31
|
return Object.assign({
|
|
31
32
|
// more closely matches Node (#333)
|
|
32
33
|
// plus 'mjs' for native modules! (#939)
|
|
@@ -36,16 +37,32 @@ function opts(file, config) {
|
|
|
36
37
|
{
|
|
37
38
|
// path.resolve will handle paths relative to CWD
|
|
38
39
|
basedir: path.dirname(path.resolve(file)),
|
|
39
|
-
packageFilter
|
|
40
|
-
|
|
40
|
+
packageFilter,
|
|
41
41
|
});
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
function
|
|
44
|
+
function identity(x) { return x; }
|
|
45
|
+
|
|
46
|
+
function packageFilter(pkg, dir, config) {
|
|
47
|
+
let found = false;
|
|
48
|
+
const file = path.join(dir, 'dummy.js');
|
|
45
49
|
if (pkg.module) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
50
|
+
try {
|
|
51
|
+
resolve.sync(String(pkg.module).replace(/^(?:\.\/)?/, './'), opts(file, config, identity));
|
|
52
|
+
pkg.main = pkg.module;
|
|
53
|
+
found = true;
|
|
54
|
+
} catch (err) {
|
|
55
|
+
log('resolve threw error trying to find pkg.module:', err);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
if (!found && pkg['jsnext:main']) {
|
|
59
|
+
try {
|
|
60
|
+
resolve.sync(String(pkg['jsnext:main']).replace(/^(?:\.\/)?/, './'), opts(file, config, identity));
|
|
61
|
+
pkg.main = pkg['jsnext:main'];
|
|
62
|
+
found = true;
|
|
63
|
+
} catch (err) {
|
|
64
|
+
log('resolve threw error trying to find pkg[\'jsnext:main\']:', err);
|
|
65
|
+
}
|
|
49
66
|
}
|
|
50
67
|
return pkg;
|
|
51
68
|
}
|