eslint-import-resolver-node 0.3.2 → 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 (4) hide show
  1. package/LICENSE +22 -0
  2. package/index.js +51 -30
  3. package/package.json +12 -8
  4. package/CHANGELOG.md +0 -52
package/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Ben Mosher
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
package/index.js CHANGED
@@ -1,47 +1,68 @@
1
- var resolve = require('resolve')
2
- , path = require('path')
1
+ 'use strict';
3
2
 
4
- var log = require('debug')('eslint-plugin-import:resolver:node')
3
+ const resolve = require('resolve');
4
+ const path = require('path');
5
5
 
6
- exports.interfaceVersion = 2
6
+ const log = require('debug')('eslint-plugin-import:resolver:node');
7
+
8
+ exports.interfaceVersion = 2;
7
9
 
8
10
  exports.resolve = function (source, file, config) {
9
- log('Resolving:', source, 'from:', file)
10
- var resolvedPath
11
+ log('Resolving:', source, 'from:', file);
12
+ let resolvedPath;
11
13
 
12
14
  if (resolve.isCore(source)) {
13
- log('resolved to core')
14
- return { found: true, path: null }
15
+ log('resolved to core');
16
+ return { found: true, path: null };
15
17
  }
16
18
 
17
19
  try {
18
- resolvedPath = resolve.sync(source, opts(file, config))
19
- log('Resolved to:', resolvedPath)
20
- return { found: true, path: resolvedPath }
20
+ const cachedFilter = function (pkg, dir) { return packageFilter(pkg, dir, config); };
21
+ resolvedPath = resolve.sync(source, opts(file, config, cachedFilter));
22
+ log('Resolved to:', resolvedPath);
23
+ return { found: true, path: resolvedPath };
21
24
  } catch (err) {
22
- log('resolve threw error:', err)
23
- return { found: false }
25
+ log('resolve threw error:', err);
26
+ return { found: false };
24
27
  }
25
- }
28
+ };
26
29
 
27
- function opts(file, config) {
30
+ function opts(file, config, packageFilter) {
28
31
  return Object.assign({
29
- // more closely matches Node (#333)
30
- // plus 'mjs' for native modules! (#939)
31
- extensions: ['.mjs', '.js', '.json'],
32
- },
33
- config,
34
- {
35
- // path.resolve will handle paths relative to CWD
36
- basedir: path.dirname(path.resolve(file)),
37
- packageFilter: packageFilter,
38
-
39
- })
32
+ // more closely matches Node (#333)
33
+ // plus 'mjs' for native modules! (#939)
34
+ extensions: ['.mjs', '.js', '.json', '.node'],
35
+ },
36
+ config,
37
+ {
38
+ // path.resolve will handle paths relative to CWD
39
+ basedir: path.dirname(path.resolve(file)),
40
+ packageFilter,
41
+ });
40
42
  }
41
43
 
42
- function packageFilter(pkg) {
43
- if (pkg['jsnext:main']) {
44
- pkg['main'] = pkg['jsnext:main']
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');
49
+ if (pkg.module) {
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
+ }
45
66
  }
46
- return pkg
67
+ return pkg;
47
68
  }
package/package.json CHANGED
@@ -1,17 +1,20 @@
1
1
  {
2
2
  "name": "eslint-import-resolver-node",
3
- "version": "0.3.2",
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": [
7
7
  "index.js"
8
8
  ],
9
9
  "scripts": {
10
- "test": "nyc mocha"
10
+ "prepublishOnly": "cp ../../{LICENSE,.npmrc} ./",
11
+ "tests-only": "nyc mocha",
12
+ "test": "npm run tests-only",
13
+ "coveralls": "nyc report --reporter lcovonly && cd ../.. && coveralls < ./resolvers/node/coverage/lcov.info"
11
14
  },
12
15
  "repository": {
13
16
  "type": "git",
14
- "url": "https://github.com/benmosher/eslint-plugin-import"
17
+ "url": "https://github.com/import-js/eslint-plugin-import"
15
18
  },
16
19
  "keywords": [
17
20
  "eslint",
@@ -23,16 +26,17 @@
23
26
  "author": "Ben Mosher (me@benmosher.com)",
24
27
  "license": "MIT",
25
28
  "bugs": {
26
- "url": "https://github.com/benmosher/eslint-plugin-import/issues"
29
+ "url": "https://github.com/import-js/eslint-plugin-import/issues"
27
30
  },
28
- "homepage": "https://github.com/benmosher/eslint-plugin-import",
31
+ "homepage": "https://github.com/import-js/eslint-plugin-import",
29
32
  "dependencies": {
30
- "debug": "^2.6.9",
31
- "resolve": "^1.5.0"
33
+ "debug": "^3.2.7",
34
+ "resolve": "^1.20.0"
32
35
  },
33
36
  "devDependencies": {
34
37
  "chai": "^3.5.0",
38
+ "coveralls": "^3.1.0",
35
39
  "mocha": "^3.5.3",
36
- "nyc": "^10.3.2"
40
+ "nyc": "^11.9.0"
37
41
  }
38
42
  }
package/CHANGELOG.md DELETED
@@ -1,52 +0,0 @@
1
- # Change Log
2
- All notable changes to this resolver will be documented in this file.
3
- This project adheres to [Semantic Versioning](http://semver.org/).
4
- This change log adheres to standards from [Keep a CHANGELOG](http://keepachangelog.com).
5
-
6
- ## Unreleased
7
-
8
- ## v0.3.2 - 2018-01-05
9
- ### Added
10
- - `.mjs` extension detected by default to support `experimental-modules` (#939)
11
-
12
- ### Deps
13
- - update `debug`, `resolve`
14
-
15
- ## v0.3.1 - 2017-06-23
16
- ### Changed
17
- - bumped `debug` dep to match other packages
18
-
19
- ## v0.3.0 - 2016-12-15
20
- ### Changed
21
- - bumped `resolve` to fix issues with Node builtins (thanks [@SkeLLLa] and [@ljharb])
22
-
23
- ### Fixed
24
- - use `files` in `package.json` to ship only `index.js` ([#531], thanks for noticing [@lukeapage])
25
-
26
- ## v0.2.3 - 2016-08-20
27
- ### Added
28
- - debug logging (use `DEBUG=eslint-plugin-import:resolver:node eslint [...]`)
29
-
30
- ## v0.2.2 - 2016-07-14
31
- ### Fixed
32
- - Node resolver no longer declares the import plugin as a `peerDependency`. See [#437]
33
- for a well-articulated and thoughtful expression of why this doesn't make sense.
34
- Thanks [@jasonkarns] for the issue and the PR to fix it ([#438]).
35
-
36
- Also, apologies to the others who expressed this before, but I never understood
37
- what the problem was.😅
38
-
39
- ## v0.2.1
40
- ### Fixed
41
- - find files with `.json` extensions (#333, thanks for noticing @jfmengels)
42
-
43
- [#438]: https://github.com/benmosher/eslint-plugin-import/pull/438
44
-
45
- [#939]: https://github.com/benmosher/eslint-plugin-import/issues/939
46
- [#531]: https://github.com/benmosher/eslint-plugin-import/issues/531
47
- [#437]: https://github.com/benmosher/eslint-plugin-import/issues/437
48
-
49
- [@jasonkarns]: https://github.com/jasonkarns
50
- [@lukeapage]: https://github.com/lukeapage
51
- [@SkeLLLa]: https://github.com/SkeLLLa
52
- [@ljharb]: https://github.com/ljharb