Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: tleunen/babel-plugin-module-resolver
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v3.1.1
Choose a base ref
...
head repository: tleunen/babel-plugin-module-resolver
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v3.1.2
Choose a head ref
  • 8 commits
  • 14 files changed
  • 8 contributors

Commits on Jul 4, 2018

  1. chore: Fix AppVeyor config + drop support for node 4 (#304)

    It seems that the current AppVeyor config is broken because npm received an upgrade which breaks the build (and it shouldn't). The culprit is the line which installs the latest version of npm (while being used e.g. with node 4). It might be worth to make the config future-proof instead.
    fatfisz authored Jul 4, 2018

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    177e65b View commit details

Commits on Jul 31, 2018

  1. docs: Fix order of extensions for React Native (#302)

    Fixes #297
    kelset authored and tleunen committed Jul 31, 2018

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    d4f6054 View commit details

Commits on Aug 23, 2018

  1. Copy the full SHA
    4076423 View commit details
  2. fix: Escape key of alias to support using $ prefix (#313)

    Closes #312 
    
    (See #312 for detailed explanation)
    Telokis authored and fatfisz committed Aug 23, 2018
    Copy the full SHA
    4c56684 View commit details

Commits on Sep 27, 2018

  1. test: Replace Babel 6 with Babel 7 in tests (#324)

    This also preserve backwards compatibility and to align with Babel's documentation that says the `filename` option is optional, this plugin simulates Babel 6's behavior when the filename is undefined.
    ide authored and tleunen committed Sep 27, 2018
    Copy the full SHA
    7166c06 View commit details

Commits on Oct 29, 2018

  1. Copy the full SHA
    5afcd9d View commit details

Commits on Jan 16, 2019

  1. docs: adds .babelrc.js example (#337)

    atherdon authored and tleunen committed Jan 16, 2019
    Copy the full SHA
    b411888 View commit details
  2. chore(release): 3.1.2

    tleunen committed Jan 16, 2019
    Copy the full SHA
    5fce901 View commit details
Showing with 101 additions and 49 deletions.
  1. +2 −5 .babelrc
  2. +9 −9 .circleci/config.yml
  3. +10 −0 CHANGELOG.md
  4. +2 −1 DOCS.md
  5. +23 −1 README.md
  6. +1 −2 appveyor.yml
  7. +10 −10 package.json
  8. +6 −0 src/index.js
  9. +2 −1 src/normalizeOptions.js
  10. +4 −0 src/utils.js
  11. +1 −1 test/call.test.js
  12. +2 −2 test/dynamicImport.test.js
  13. +10 −8 test/import.test.js
  14. +19 −9 test/index.test.js
7 changes: 2 additions & 5 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
{
"presets": [
["env", {
["@babel/preset-env", {
"targets": {
"node": 4
},
"loose": true,
"useBuiltIns": true
"useBuiltIns": "usage"
}]
],
"plugins": [
"transform-object-rest-spread"
]
}
18 changes: 9 additions & 9 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
version: 2
jobs:
test_with_node_4:
test_with_node_6:
docker:
- image: circleci/node:4
- image: circleci/node:6
steps:
- checkout
- run:
@@ -11,9 +11,9 @@ jobs:
- run:
name: Test
command: npm test
test_with_node_6:
test_with_node_8:
docker:
- image: circleci/node:6
- image: circleci/node:8
steps:
- checkout
- run:
@@ -22,9 +22,9 @@ jobs:
- run:
name: Test
command: npm test
test_with_node_8:
test_with_node_9:
docker:
- image: circleci/node:8
- image: circleci/node:9
steps:
- checkout
- run:
@@ -33,9 +33,9 @@ jobs:
- run:
name: Test
command: npm test
test_with_node_9:
test_with_node_10:
docker:
- image: circleci/node:9
- image: circleci/node:10
steps:
- checkout
- run:
@@ -51,7 +51,7 @@ workflows:
version: 2
test_all:
jobs:
- test_with_node_4
- test_with_node_6
- test_with_node_8
- test_with_node_9
- test_with_node_10
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -2,6 +2,16 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

<a name="3.1.2"></a>
## [3.1.2](https://github.com/tleunen/babel-plugin-module-resolver/compare/v3.1.1...v3.1.2) (2019-01-16)


### Bug Fixes

* Escape key of alias to support using $ prefix ([#313](https://github.com/tleunen/babel-plugin-module-resolver/issues/313)) ([4c56684](https://github.com/tleunen/babel-plugin-module-resolver/commit/4c56684)), closes [#312](https://github.com/tleunen/babel-plugin-module-resolver/issues/312) [#312](https://github.com/tleunen/babel-plugin-module-resolver/issues/312)



<a name="3.1.1"></a>
## [3.1.1](https://github.com/tleunen/babel-plugin-module-resolver/compare/v3.1.0...v3.1.1) (2018-03-24)

3 changes: 2 additions & 1 deletion DOCS.md
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@
* [cwd](#cwd)
* [transformFunctions](#transformfunctions)
* [resolvePath](#resolvepath)
* [Usage with Create React App](#usage-with-create-react-app)
* [Usage with React Native](#usage-with-react-native)
* [Usage with Proxyquire](#usage-with-proxyquire)
* [Usage with Flow](#usage-with-flow)
@@ -237,7 +238,7 @@ To let the packager resolve the right module for each platform, you have to add
"module-resolver",
{
"root": ["./src"],
"extensions": [".js", ".ios.js", ".android.js"]
"extensions": [".ios.js", ".android.js", ".js", ".json"]
}
]
]
24 changes: 23 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -43,6 +43,28 @@ Specify the plugin in your `.babelrc` with the custom root or alias. Here's an e
}
```

**.babelrc.js version**
Specify the plugin in your `.babelrc.js` file with the custom root or alias. Here's an example:
```
const plugins = [
[
require.resolve('babel-plugin-module-resolver'),
{
root: ["./src/"],
alias: {
"test": "./test"
}
}
]
];
```
Good example: // https://gist.github.com/nodkz/41e189ff22325a27fe6a5ca81df2cb91


## Documentation

babel-plugin-module-resolver can be configured and controlled easily, check the [documentation](DOCS.md) for more details
@@ -51,7 +73,7 @@ Are you a plugin author (e.g. IDE integration)? We have [documented the exposed

## ESLint plugin

If you're using ESLint, you should use [eslint-plugin-import][eslint-plugin-import], and [eslint-import-resolver-babel-module][eslint-import-resolver-babel-module] to remove falsy unresolved modules.
If you're using ESLint, you should use [eslint-plugin-import][eslint-plugin-import], and [eslint-import-resolver-babel-module][eslint-import-resolver-babel-module] to remove falsy unresolved modules. If you want to have warnings when aliased modules are being imported by their relative paths, you can use [eslint-plugin-module-resolver](https://github.com/HeroProtagonist/eslint-plugin-module-resolver).

## Editors autocompletion

3 changes: 1 addition & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
environment:
matrix:
- nodejs_version: '4'
- nodejs_version: '6'
- nodejs_version: '8'
- nodejs_version: '9'
- nodejs_version: '10'
install:
- ps: Install-Product node $env:nodejs_version
- set CI=true
- npm -g install npm@latest
- set PATH=%APPDATA%\npm;%PATH%
- npm install
matrix:
20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"name": "babel-plugin-module-resolver",
"version": "3.1.1",
"version": "3.1.2",
"main": "lib/index.js",
"description": "Module resolver plugin for Babel",
"repository": {
"type": "git",
"url": "https://github.com/tleunen/babel-plugin-module-resolver.git"
},
"engines": {
"node": ">= 4.0.0"
"node": ">= 6.0.0"
},
"files": [
"lib"
@@ -40,20 +40,20 @@
"resolve": "^1.4.0"
},
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-core": "^6.26.0",
"babel-jest": "^22.4.1",
"babel-plugin-syntax-dynamic-import": "^6.18.0",
"babel-plugin-transform-es2015-modules-commonjs": "^6.26.0",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"babel-preset-env": "^1.6.0",
"@babel/cli": "^7.1.0",
"@babel/core": "^7.1.0",
"@babel/plugin-syntax-dynamic-import": "^7.0.0",
"@babel/plugin-transform-modules-commonjs": "^7.1.0",
"@babel/preset-env": "^7.1.0",
"babel-core": "^7.0.0-bridge.0",
"babel-jest": "^23.6.0",
"common-tags": "^1.4.0",
"eslint": "^4.19.0",
"eslint-config-airbnb-base": "^12.1.0",
"eslint-config-prettier": "^2.9.0",
"eslint-plugin-import": "^2.9.0",
"husky": "^0.14.3",
"jest": "^22.4.2",
"jest": "^23.6.0",
"lint-staged": "^7.0.0",
"prettier-eslint-cli": "^4.7.1",
"standard-version": "^4.2.0"
6 changes: 6 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -27,6 +27,12 @@ const visitor = {
export default ({ types }) => ({
name: 'module-resolver',

manipulateOptions(opts) {
if (opts.filename === undefined) {
opts.filename = 'unknown';
}
},

pre(file) {
this.types = types;

3 changes: 2 additions & 1 deletion src/normalizeOptions.js
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@ import findBabelConfig from 'find-babel-config';
import glob from 'glob';
import pkgUp from 'pkg-up';

import { escapeRegExp } from './utils';
import defaultResolvePath from './resolvePath';


@@ -79,7 +80,7 @@ function normalizeRoot(optsRoot, cwd) {
}

function getAliasTarget(key, isKeyRegExp) {
const regExpPattern = isKeyRegExp ? key : `^${key}(/.*|)$`;
const regExpPattern = isKeyRegExp ? key : `^${escapeRegExp(key)}(/.*|)$`;
return new RegExp(regExpPattern);
}

4 changes: 4 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
@@ -80,3 +80,7 @@ export function mapPathString(nodePath, state) {
export function isImportCall(types, calleePath) {
return types.isImport(calleePath.node.callee);
}

export function escapeRegExp(string) {
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
}
2 changes: 1 addition & 1 deletion test/call.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { transform } from 'babel-core';
import { transform } from '@babel/core';
import plugin from '../src';


4 changes: 2 additions & 2 deletions test/dynamicImport.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-env jest */
import { transform } from 'babel-core'; // eslint-disable-line import/no-extraneous-dependencies
import { transform } from '@babel/core'; // eslint-disable-line import/no-extraneous-dependencies
import plugin from '../src';

// According to https://github.com/tc39/proposal-dynamic-import
@@ -10,7 +10,7 @@ describe('import()', () => {
plugins: [
// We need to add the corresponding syntax plugin
// in order to parse the `import()`-calls
'syntax-dynamic-import',
'@babel/plugin-syntax-dynamic-import',
[plugin, {
root: [
'./test/testproject/src',
18 changes: 10 additions & 8 deletions test/import.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { transform } from 'babel-core';
import transformToCommonJsPlugin from 'babel-plugin-transform-es2015-modules-commonjs';
import { transform } from '@babel/core';
import transformToCommonJsPlugin from '@babel/plugin-transform-modules-commonjs';
import { stripIndent } from 'common-tags';
import plugin from '../src';

@@ -21,10 +21,10 @@ describe('import and export statement', () => {
});

it('with an export statement', () => {
const code = 'export { something };';
const code = 'let something; export { something }';
const result = transform(code, transformerOpts);

expect(result.code).toBe('export { something };');
expect(result.code).toBe('let something;\nexport { something };');
});
}

@@ -59,7 +59,7 @@ describe('import and export statement', () => {
});

it('with a transformed export statement', () => {
const code = 'export { something };';
const code = 'let something; export { something };';
const result = transform(code, transformerOptsWithCommonJs);

expect(result.code).toBe(stripIndent`
@@ -68,6 +68,8 @@ describe('import and export statement', () => {
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.something = void 0;
let something;
exports.something = something;
`);
});
@@ -85,7 +87,7 @@ describe('import and export statement', () => {
root: './test/testproject/src',
alias: {
test: './test/testproject/test',
'babel-core': 'babel-core/lib',
'@babel/core': '@babel/core/lib',
},
}],
],
@@ -126,8 +128,8 @@ describe('import and export statement', () => {
describe('should only apply the alias once', () => {
// If this test breaks, consider selecting another package used by the plugin
testImports(
'babel-core/store',
'babel-core/lib/store',
'@babel/core/transform',
'@babel/core/lib/transform',
transformerOpts,
);
});
Loading