Skip to content

Commit 98acd6a

Browse files
authored
fix #939 by adding .mjs to stock Node resolver (#955)
1 parent 1e3f842 commit 98acd6a

File tree

6 files changed

+37
-5
lines changed

6 files changed

+37
-5
lines changed

Diff for: resolvers/node/CHANGELOG.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
44
This change log adheres to standards from [Keep a CHANGELOG](http://keepachangelog.com).
55

66
## Unreleased
7-
7+
### Added
8+
- `.mjs` extension detected by default to support `experimental-modules` (#939)
89

910
## v0.3.1 - 2017-06-23
1011
### Changed
@@ -36,6 +37,7 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
3637

3738
[#438]: https://github.com/benmosher/eslint-plugin-import/pull/438
3839

40+
[#939]: https://github.com/benmosher/eslint-plugin-import/issues/939
3941
[#531]: https://github.com/benmosher/eslint-plugin-import/issues/531
4042
[#437]: https://github.com/benmosher/eslint-plugin-import/issues/437
4143

Diff for: resolvers/node/index.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ exports.resolve = function (source, file, config) {
2727
function opts(file, config) {
2828
return Object.assign({
2929
// more closely matches Node (#333)
30-
extensions: ['.js', '.json'],
30+
// plus 'mjs' for native modules! (#939)
31+
extensions: ['.mjs', '.js', '.json'],
3132
},
3233
config,
3334
{

Diff for: resolvers/node/package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
"version": "0.3.1",
44
"description": "Node default behavior import resolution plugin for eslint-plugin-import.",
55
"main": "index.js",
6-
"files": ["index.js"],
6+
"files": [
7+
"index.js"
8+
],
79
"scripts": {
810
"test": "nyc mocha"
911
},

Diff for: resolvers/node/test/native.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
exports.natively = function () { return "but where do we feature?" }

Diff for: resolvers/node/test/native.mjs

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export function natively() { return "a shining new era is tiptoeing nearer" }

Diff for: resolvers/node/test/paths.js

+27-2
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,39 @@ describe("paths", function () {
1111
})
1212
})
1313

14+
15+
describe("core", function () {
16+
it("returns found, but null path, for core Node modules", function () {
17+
var resolved = node.resolve('fs', "./test/file.js")
18+
expect(resolved).has.property("found", true)
19+
expect(resolved).has.property("path", null)
20+
})
21+
})
22+
23+
1424
describe("default options", function () {
25+
1526
it("finds .json files", function () {
16-
expect(node.resolve('./data', './test/file.js'))
27+
expect(node.resolve('./data', './test/file.js'))
1728
.to.have.property('path')
1829
.equal(path.resolve(__dirname, './data.json'))
1930
})
31+
2032
it("ignores .json files if 'extensions' is redefined", function () {
21-
expect(node.resolve('./data', './test/file.js', { extensions: ['.js'] }))
33+
expect(node.resolve('./data', './test/file.js', { extensions: ['.js'] }))
2234
.to.have.property('found', false)
2335
})
36+
37+
it("finds mjs modules, with precedence over .js", function () {
38+
expect(node.resolve('./native', './test/file.js'))
39+
.to.have.property('path')
40+
.equal(path.resolve(__dirname, './native.mjs'))
41+
})
42+
43+
it("still finds .js if explicit", function () {
44+
expect(node.resolve('./native.js', './test/file.js'))
45+
.to.have.property('path')
46+
.equal(path.resolve(__dirname, './native.js'))
47+
})
48+
2449
})

0 commit comments

Comments
 (0)