Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

eslint-import-resolver-custom-alias

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslint-import-resolver-custom-alias - npm Package Compare versions

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 @@ }

2

package.json
{
"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';
```
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc