Skip to content
This repository has been archived by the owner on Jun 8, 2023. It is now read-only.

Commit

Permalink
feat: Allow the resolver options to be set in the eslint file (#68)
Browse files Browse the repository at this point in the history
  • Loading branch information
tleunen committed Oct 9, 2017
1 parent b4a64f1 commit 8ee7c08
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"presets": [
["env", {
"targets": {
"node": 4
"node": 6
},
"loose": true,
"useBuiltIns": true
Expand Down
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock=false
2 changes: 1 addition & 1 deletion circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
29 changes: 16 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
"type": "git",
"url": "https://github.com/tleunen/eslint-import-resolver-babel-module.git"
},
"engines": {
"node": ">=6.0.0"
},
"files": [
"lib"
],
Expand All @@ -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",
Expand All @@ -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": {
Expand Down
20 changes: 17 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};
Expand Down Expand Up @@ -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(() => {
Expand Down

0 comments on commit 8ee7c08

Please sign in to comment.