Skip to content

Commit

Permalink
Merge dbfc372 into dfcd007
Browse files Browse the repository at this point in the history
  • Loading branch information
johvin committed Dec 8, 2018
2 parents dfcd007 + dbfc372 commit 0d4f28c
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 10 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Expand Up @@ -4,6 +4,7 @@ node_js:
- "4"
- "6"
- "8"
- "10"
- "node"
script:
- "npm run cov"
Expand Down
13 changes: 12 additions & 1 deletion CHANGELOG.md
Expand Up @@ -4,6 +4,16 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [1.1.2] - 2018-12-08
### Fixed
- fix the bug to not resolve `path/to/file` to `path/from/file` with the config `['to', 'from']`. see [#7][issue7]

### Changed
- update test case
- update changelog
- update usage to readme


## [1.1.1] - 2018-07-30
### Fixed
- fix the bug that the module mapped to a relative path can not be resolved. see [#5][issue5]
Expand Down Expand Up @@ -64,4 +74,5 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- support resolve relative path modules

<!-- references -->
[issue5]: https://github.com/johvin/eslint-import-resolver-alias/issues/5
[issue5]: https://github.com/johvin/eslint-import-resolver-alias/issues/5
[issue7]: https://github.com/johvin/eslint-import-resolver-alias/issues/7
8 changes: 4 additions & 4 deletions README.md
Expand Up @@ -60,11 +60,11 @@ Note:

- The alias config object contains two properties, `map` and `extensions`, both of which are array types
- The item of `map` array is also array type which contains 2 string
+ The first string represents the mapped module name or path
+ The second string represents the module alias, the actual module path or name
- The `map` item `['helper', './utils/helper']` means that the modules which matches `helper` or `helper/*` will be resolved to `./utils/helper` or `./utils/helper/*` which is located relative to the `process current working directory` (almost the project root directory). See [#3](https://github.com/johvin/eslint-import-resolver-alias/issues/3)
+ The first string represents the alias of module name or path
+ The second string represents the actual module name or path
- The `map` item `['helper', './utils/helper']` means that the modules which match `helper` or `helper/*` will be resolved to `./utils/helper` or `./utils/helper/*` which are located relative to the `process current working directory` (almost the project root directory). If you just want to resolve `helper` to `./utils/helper`, use `['^helper$', './utils/helper']` instead. See [issue #3](https://github.com/johvin/eslint-import-resolver-alias/issues/3)
- The order of 'material-ui/DatePicker' and 'material-ui' cannot be reversed, otherwise the alias rule 'material-ui/DatePicker' does not work
- The default value of `extensions` property is `['.js', '.json', '.node']` if it is assigned to an empty array or not specified.
- The default value of `extensions` property is `['.js', '.json', '.node']` if it is assigned to an empty array or not specified

*If the `extensions` property is not specified, the config object can be simplified to the `map` array.*

Expand Down
6 changes: 2 additions & 4 deletions index.js
Expand Up @@ -55,17 +55,15 @@ exports.resolve = (modulePath, sourceFile, config) => {

if (Array.isArray(map)) {
for (let i = 0, len = map.length; i < len; i++) {
const re = new RegExp(`(^|/)${map[i][0]}($|/)`);
const re = new RegExp(`^${map[i][0]}($|/)`);
const match = modulePath.match(re);
if (match) {
resolvePath = modulePath.replace(match[0], `${match[1]}${map[i][1]}${match[2]}`);
resolvePath = modulePath.replace(match[0], `${map[i][1]}${match[1]}`);
break;
}
}
}



// there is a relative path mapping in alias.map,
// the relative path is relative to the project root directory
if (resolvePath[0] === '.') {
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "eslint-import-resolver-alias",
"version": "1.1.1",
"version": "1.1.2",
"description": "a simple Node behavior import resolution plugin for eslint-plugin-import, supporting module alias.",
"main": "index.js",
"scripts": {
Expand Down
1 change: 1 addition & 0 deletions test/test.js
Expand Up @@ -11,6 +11,7 @@ describe('resolver-alias/index.js', () => {
['module3/heihei', 'module2/smile'],
['^core$', './dist/core'],
['core', 'module2/styles'],
['red', './nothing'], // should not impact the paths which contain red and not starts with red
['module3', 'module2'],
['srcCore', './core'],
['relativeSetup', './test/setup']
Expand Down

0 comments on commit 0d4f28c

Please sign in to comment.