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

Commit

Permalink
fix: Fix lib to support babel plugin v3 (#54)
Browse files Browse the repository at this point in the history
Breaking change: Not compatible with babel-plugin-module-resolver v2.x
  • Loading branch information
tleunen committed Apr 23, 2017
1 parent 91029b8 commit 731ab8c
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 20 deletions.
9 changes: 9 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
{
"presets": [
["env", {
"targets": {
"node": 4
},
"loose": true,
"useBuiltIns": true
}]
],
"plugins": [
["transform-object-rest-spread", { "useBuiltIns": true }]
]
Expand Down
19 changes: 10 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,19 @@
],
"dependencies": {
"pkg-up": "^1.0.0",
"resolve": "^1.2.0"
"resolve": "^1.3.3"
},
"devDependencies": {
"babel-cli": "^6.22.2",
"babel-core": "^6.22.1",
"babel-jest": "^18.0.0",
"babel-plugin-module-resolver": "^2.5.0",
"babel-plugin-transform-object-rest-spread": "^6.22.0",
"eslint": "^3.15.0",
"eslint-config-airbnb-base": "^11.0.1",
"babel-cli": "^6.24.1",
"babel-core": "^6.24.1",
"babel-jest": "^19.0.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": "^18.1.0",
"jest": "^19.0.2",
"lodash": "^4.17.4",
"standard-version": "^4.0.0"
},
Expand Down
22 changes: 14 additions & 8 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ const path = require('path');
const resolve = require('resolve');
const pkgUp = require('pkg-up');
const targetPlugin = require('babel-plugin-module-resolver').default;
const babelModuleResolver = require('babel-plugin-module-resolver');
const normalizeOptions = require('babel-plugin-module-resolver/lib/normalizeOptions').default;
const getRealPath = require('babel-plugin-module-resolver/lib/getRealPath').default;
const OptionManager = require('babel-core').OptionManager;

function getPlugins(file, target) {
Expand Down Expand Up @@ -57,15 +58,20 @@ exports.resolve = (source, file, opts) => {
extensions: plugin[1] && plugin[1].extensions ? plugin[1].extensions : config.extensions,
}), { root: [], alias: {}, cwd: projectRootDir });

const manipulatedOpts = babelModuleResolver.manipulatePluginOptions(pluginOpts);

const src = babelModuleResolver.mapModule(
source, file, manipulatedOpts, path.resolve(manipulatedOpts.cwd),
);
normalizeOptions(pluginOpts, file);

const extensions = options.extensions ||
manipulatedOpts.extensions ||
babelModuleResolver.defaultExtensions;
const babelState = {
file: {
opts: {
filename: file,
},
},
opts: pluginOpts,
};
const src = getRealPath(source, babelState);

const extensions = options.extensions || pluginOpts.extensions;

return {
found: true,
Expand Down
2 changes: 1 addition & 1 deletion test/.babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"root": ["./test/examples/**"],
"alias": {
"components": "./test/examples/components",
"underscore": "npm:lodash"
"old-bcore": "babel-core"
},
"extensions": [".js", ".customExt"]
}]
Expand Down
4 changes: 2 additions & 2 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ describe('eslint-import-resolver-module-resolver', () => {
});

it('should return `true` when mapped to a npm module', () => {
expect(resolverPlugin.resolve('underscore', path.resolve('./test/examples/file1'), opts))
expect(resolverPlugin.resolve('old-bcore', path.resolve('./test/examples/file1'), opts))
.toEqual({
found: true,
path: path.resolve(__dirname, '../node_modules/lodash/lodash.js'),
path: path.resolve(__dirname, '../node_modules/babel-core/index.js'),
});
});

Expand Down

0 comments on commit 731ab8c

Please sign in to comment.