diff --git a/.babelrc b/.babelrc index 7902914..170d677 100644 --- a/.babelrc +++ b/.babelrc @@ -2,7 +2,7 @@ "presets": [ ["env", { "targets": { - "node": 4 + "node": 6 }, "loose": true, "useBuiltIns": true diff --git a/.npmrc b/.npmrc new file mode 100644 index 0000000..43c97e7 --- /dev/null +++ b/.npmrc @@ -0,0 +1 @@ +package-lock=false diff --git a/circle.yml b/circle.yml index cf37790..c86d7d7 100644 --- a/circle.yml +++ b/circle.yml @@ -5,7 +5,7 @@ dependencies: cache_directories: - ~/.cache/yarn pre: - - case $CIRCLE_NODE_INDEX in 0) NODE_VERSION=4 ;; 1) NODE_VERSION=6 ;; 2) NODE_VERSION=7 ;; esac; nvm install $NODE_VERSION && nvm alias default $NODE_VERSION + - case $CIRCLE_NODE_INDEX in 0) NODE_VERSION=6 ;; 1) NODE_VERSION=7 ;; 2) NODE_VERSION=8 ;; esac; nvm install $NODE_VERSION && nvm alias default $NODE_VERSION override: - yarn --no-lockfile test: diff --git a/package.json b/package.json index 4570bd5..d9fbe1a 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,9 @@ "type": "git", "url": "https://github.com/tleunen/eslint-import-resolver-babel-module.git" }, + "engines": { + "node": ">=6.0.0" + }, "files": [ "lib" ], @@ -30,25 +33,25 @@ ], "dependencies": { "pkg-up": "^2.0.0", - "resolve": "^1.3.3" + "resolve": "^1.4.0" }, "devDependencies": { - "babel-cli": "^6.24.1", - "babel-core": "^6.24.1", - "babel-jest": "^20.0.3", + "babel-cli": "^6.26.0", + "babel-core": "^6.26.0", + "babel-jest": "^21.2.0", "babel-plugin-module-resolver": "^3.0.0-beta.0", - "babel-plugin-transform-object-rest-spread": "^6.23.0", - "babel-preset-env": "^1.4.0", - "eslint": "^3.19.0", - "eslint-config-airbnb-base": "^11.1.3", - "eslint-plugin-import": "^2.2.0", - "jest": "^20.0.3", + "babel-plugin-transform-object-rest-spread": "^6.26.0", + "babel-preset-env": "^1.6.0", + "eslint": "^4.8.0", + "eslint-config-airbnb-base": "^12.0.2", + "eslint-plugin-import": "^2.7.0", + "jest": "^21.2.1", "lodash": "^4.17.4", - "standard-version": "^4.0.0" + "standard-version": "^4.2.0" }, "peerDependencies": { "babel-core": "^6.0.0", - "babel-plugin-module-resolver": ">3.0.0-beta" + "babel-plugin-module-resolver": "^3.0.0-beta" }, "scripts": { "lint": "eslint src test", @@ -57,7 +60,7 @@ "test": "jest --coverage", "test:suite": "jest", "test:watch": "jest --watch", - "prepublish": "npm run compile", + "prepare": "npm run compile", "release": "standard-version" }, "jest": { diff --git a/src/index.js b/src/index.js index 46ffe7e..15f0732 100644 --- a/src/index.js +++ b/src/index.js @@ -2,8 +2,8 @@ const path = require('path'); const resolve = require('resolve'); const pkgUp = require('pkg-up'); const targetPlugin = require('babel-plugin-module-resolver').default; -const resolvePath = require('babel-plugin-module-resolver').resolvePath; -const OptionManager = require('babel-core').OptionManager; +const { resolvePath } = require('babel-plugin-module-resolver'); +const { OptionManager } = require('babel-core'); function getPlugins(file, target) { try { @@ -73,7 +73,21 @@ exports.resolve = (source, file, opts) => { alias: Object.assign(config.alias, plugin[1] ? plugin[1].alias : {}), extensions: plugin[1] && plugin[1].extensions ? plugin[1].extensions : config.extensions, }), - { root: [], alias: {}, cwd: projectRootDir }, + { + // if .babelrc doesn't exist, try to get the configuration information from `options`, + // which gets defined by the eslint configuration file. + // e.g. in .eslintrc file + // "import/resolver": { + // "babel-module": { + // "root": ["./src"], + // "extensions": [".js", ".jsx"] + // } + // } + cwd: options.cwd || projectRootDir, + root: options.root || [], + alias: options.alias || {}, + extensions: options.extensions || ['.js', '.jsx', '.es', '.es6', '.mjs'], + }, ); const finalSource = stripWebpack(source); diff --git a/test/index.test.js b/test/index.test.js index 4db8db3..4ce50e7 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -4,7 +4,7 @@ 'use strict'; const path = require('path'); -const OptionManager = require('babel-core').OptionManager; +const { OptionManager } = require('babel-core'); const resolverPlugin = require('../src/index'); const opts = {}; @@ -185,6 +185,7 @@ describe('eslint-import-resolver-module-resolver', () => { beforeEach(() => { oldInit = OptionManager.prototype.init; + // eslint-disable-next-line prefer-destructuring error = console.error; }); afterEach(() => {