Skip to content

Commit

Permalink
fix #939 by adding .mjs to stock Node resolver (#955)
Browse files Browse the repository at this point in the history
  • Loading branch information
benmosher authored Oct 20, 2017
1 parent 1e3f842 commit 98acd6a
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 5 deletions.
4 changes: 3 additions & 1 deletion resolvers/node/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
This change log adheres to standards from [Keep a CHANGELOG](http://keepachangelog.com).

## Unreleased

### Added
- `.mjs` extension detected by default to support `experimental-modules` (#939)

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

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

[#939]: https://github.com/benmosher/eslint-plugin-import/issues/939
[#531]: https://github.com/benmosher/eslint-plugin-import/issues/531
[#437]: https://github.com/benmosher/eslint-plugin-import/issues/437

Expand Down
3 changes: 2 additions & 1 deletion resolvers/node/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ exports.resolve = function (source, file, config) {
function opts(file, config) {
return Object.assign({
// more closely matches Node (#333)
extensions: ['.js', '.json'],
// plus 'mjs' for native modules! (#939)
extensions: ['.mjs', '.js', '.json'],
},
config,
{
Expand Down
4 changes: 3 additions & 1 deletion resolvers/node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
"version": "0.3.1",
"description": "Node default behavior import resolution plugin for eslint-plugin-import.",
"main": "index.js",
"files": ["index.js"],
"files": [
"index.js"
],
"scripts": {
"test": "nyc mocha"
},
Expand Down
1 change: 1 addition & 0 deletions resolvers/node/test/native.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
exports.natively = function () { return "but where do we feature?" }
1 change: 1 addition & 0 deletions resolvers/node/test/native.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export function natively() { return "a shining new era is tiptoeing nearer" }
29 changes: 27 additions & 2 deletions resolvers/node/test/paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,39 @@ describe("paths", function () {
})
})


describe("core", function () {
it("returns found, but null path, for core Node modules", function () {
var resolved = node.resolve('fs', "./test/file.js")
expect(resolved).has.property("found", true)
expect(resolved).has.property("path", null)
})
})


describe("default options", function () {

it("finds .json files", function () {
expect(node.resolve('./data', './test/file.js'))
expect(node.resolve('./data', './test/file.js'))
.to.have.property('path')
.equal(path.resolve(__dirname, './data.json'))
})

it("ignores .json files if 'extensions' is redefined", function () {
expect(node.resolve('./data', './test/file.js', { extensions: ['.js'] }))
expect(node.resolve('./data', './test/file.js', { extensions: ['.js'] }))
.to.have.property('found', false)
})

it("finds mjs modules, with precedence over .js", function () {
expect(node.resolve('./native', './test/file.js'))
.to.have.property('path')
.equal(path.resolve(__dirname, './native.mjs'))
})

it("still finds .js if explicit", function () {
expect(node.resolve('./native.js', './test/file.js'))
.to.have.property('path')
.equal(path.resolve(__dirname, './native.js'))
})

})

0 comments on commit 98acd6a

Please sign in to comment.