eslint-import-resolver-custom-alias
Advanced tools
Comparing version 1.2.0 to 1.3.0
14
index.js
@@ -30,2 +30,7 @@ const path = require('path'); | ||
const parent = path.resolve(process.cwd(), globParent(pkg)); | ||
try { | ||
if (!fs.statSync(parent).isDirectory()) return []; | ||
} catch (e) { | ||
return []; | ||
} | ||
const dir = fs.readdirSync(parent) | ||
@@ -40,6 +45,11 @@ .map(name => path.resolve(parent, name)) | ||
let ret = currentSource; | ||
if (currentSource.indexOf(prefix) === 0 && currentSource[prefix.length] === '/') { | ||
// case alias(prefix) = '', currentSource = 'utils/helper.js' | ||
const isMatchEmptyString = prefix === '' && ['.', '/'].indexOf(currentSource[0]) < 0; | ||
// case: alias(prefix) = 'src', currentSource = 'src/utils/helper.js' | ||
const isMatchPrefix = currentSource.indexOf(prefix) === 0 && currentSource[prefix.length] === '/'; | ||
if (isMatchPrefix || isMatchEmptyString) { | ||
const prefixPath = getPath(config.alias[prefix], file, packages); | ||
ret = `${prefixPath}${currentSource.substr(prefix.length)}`; | ||
ret = path.join(prefixPath, currentSource.substr(prefix.length)); | ||
} else if (currentSource === prefix) { | ||
// case: alias(prefix) = 'src', currentSource = 'src' | ||
ret = getPath(config.alias[prefix], file, packages); | ||
@@ -46,0 +56,0 @@ } |
{ | ||
"name": "eslint-import-resolver-custom-alias", | ||
"version": "1.2.0", | ||
"version": "1.3.0", | ||
"description": "Plugin for eslint-plugin-import to use custom alias.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -95,1 +95,28 @@ [![Build Status](https://travis-ci.org/laysent/eslint-import-resolver-custom-alias.svg?branch=master)](https://travis-ci.org/laysent/eslint-import-resolver-custom-alias) | ||
Resolver will try to find it at `./packages/subfolder/src/utils` folder instead. | ||
One special alias is empty string `""`. If configured, the resolver will try to | ||
add prefix in front of the path before resolving. For example, with following configuration | ||
```json | ||
{ | ||
"settings": { | ||
"import/resolver": { | ||
"eslint-import-resolver-custom-alias": { | ||
"alias": { | ||
"": "./src" | ||
}, | ||
"extensions": [".js", ".jsx"], | ||
"packages": [ | ||
"packages/*" | ||
] | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
The resolver will try to find the following import at path `./packages/subfolder/src/utils/helper`. | ||
```jsx | ||
import * as helper from 'utils/helper'; | ||
``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
121
1
7560
5
59