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

Commit

Permalink
Fix: Fix linting when using a root glob config (#38)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Now requires babel-plugin-module-resolver >= 2.5.0
  • Loading branch information
tleunen committed Feb 5, 2017
1 parent e775e16 commit 45a78be
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
},
"peerDependencies": {
"babel-core": "^6.0.0",
"babel-plugin-module-resolver": "^2.4.0"
"babel-plugin-module-resolver": "^2.5.0"
},
"scripts": {
"lint": "eslint src test",
Expand Down
9 changes: 6 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const path = require('path');
const resolve = require('resolve');
const pkgUp = require('pkg-up');
const targetPlugin = require('babel-plugin-module-resolver').default;
const mapModule = require('babel-plugin-module-resolver').mapModule;
const babelModuleResolver = require('babel-plugin-module-resolver');
const OptionManager = require('babel-core').OptionManager;

function getPlugins(file, target) {
Expand Down Expand Up @@ -62,10 +62,13 @@ exports.resolve = (source, file, options) => {
alias: Object.assign(config.alias, plugin[1] ? plugin[1].alias : {}),
}), { root: [], alias: {}, cwd: projectRootDir });

const src = mapModule(source, file, pluginOpts, path.resolve(pluginOpts.cwd)) || source;
const manipulatedOpts = babelModuleResolver.manipulatePluginOptions(pluginOpts);
const src = babelModuleResolver.mapModule(
source, file, manipulatedOpts, path.resolve(manipulatedOpts.cwd),
);
return {
found: true,
path: resolve.sync(src, opts(file, options)),
path: resolve.sync(src || source, opts(file, options)),
};
} catch (e) {
return { found: false };
Expand Down
1 change: 1 addition & 0 deletions test/.babelrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"plugins": [
["module-resolver", {
"root": ["./test/examples/**"],
"alias": {
"components": "./test/examples/components",
"underscore": "npm:lodash"
Expand Down
10 changes: 9 additions & 1 deletion test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ describe('eslint-import-resolver-module-resolver', () => {
});
});

it('should return `true` when the file is mapped through a glob root config', () => {
expect(resolverPlugin.resolve('c2', path.resolve('./test/examples/components/c1.js'), opts))
.toEqual({
found: true,
path: path.resolve(__dirname, './examples/components/sub/sub/c2.js'),
});
});

it('should return `true` when no mapping is required', () => {
expect(resolverPlugin.resolve('./sub/sub/c2', path.resolve('./test/examples/components/c1'), opts))
.toEqual({
Expand Down Expand Up @@ -111,7 +119,7 @@ describe('eslint-import-resolver-module-resolver', () => {
});
});

describe('when ony specific env is available', () => {
describe('when a specific env is available', () => {
it('should return `false` when the mapping doesn\'t exist in "env"', () => {
const oldEnv = process.env.NODE_ENV;
process.env.NODE_ENV = 'development';
Expand Down

0 comments on commit 45a78be

Please sign in to comment.