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.
Files changed (2) hide show
  1. package/index.js +25 -8
  2. 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
- resolvedPath = resolve.sync(source, opts(file, config));
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: packageFilter,
40
-
40
+ packageFilter,
41
41
  });
42
42
  }
43
43
 
44
- function packageFilter(pkg) {
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
- pkg.main = pkg.module;
47
- } else if (pkg['jsnext:main']) {
48
- pkg.main = pkg['jsnext:main'];
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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-import-resolver-node",
3
- "version": "0.3.5",
3
+ "version": "0.3.6",
4
4
  "description": "Node default behavior import resolution plugin for eslint-plugin-import.",
5
5
  "main": "index.js",
6
6
  "files": [