Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

eslint-import-resolver-alias

johvin3.1mMIT1.1.2

a simple Node behavior import resolution plugin for eslint-plugin-import, supporting module alias.

eslint, eslintplugin, eslint-plugin-import, eslint-import-resolver, import-resolver, resolver, resolve, resolution, alias, mapping, rewrite, rename, webpack, module, node-native, module-resolver, import, require

readme

eslint-import-resolver-alias

Version npm Version node Build Status Download Dependencies peerDependencies Coverage Status Known Vulnerabilities License

This is a simple Node.js module import resolution plugin for eslint-plugin-import, which supports native Node.js module resolution, module alias/mapping and custom file extensions.

Installation

Prerequisites: Node.js >=4.x and corresponding version of npm.

npm install eslint-plugin-import eslint-import-resolver-alias --save-dev

Usage

Pass this resolver and its parameters to eslint-plugin-import using your eslint config file, .eslintrc or .eslintrc.js.

// .eslintrc.js
module.exports = {
  settings: {
    'import/resolver': {
      alias: {
        map: [
          ['babel-polyfill', 'babel-polyfill/dist/polyfill.min.js'],
          ['helper', './utils/helper'],
          ['material-ui/DatePicker', '../custom/DatePicker'],
          ['material-ui', 'material-ui-ie10']
        ],
        extensions: ['.ts', '.js', '.jsx', '.json']
      }
    }
  }
};

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 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
  • 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

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

// .eslintrc.js
module.exports = {
  settings: {
    'import/resolver': {
      alias: [
        ['babel-polyfill', 'babel-polyfill/dist/polyfill.min.js'],
        ['helper', './utils/helper'],
        ['material-ui/DatePicker', '../custom/DatePicker'],
        ['material-ui', 'material-ui-ie10']
      ]
    }
  }
};

When the config is not a valid object (such as true), the resolver falls back to native Node.js module resolution.

// .eslintrc.js
module.exports = {
  settings: {
    'import/resolver': {
      alias: true
    }
  }
};

changelog

Change Log

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog and this project adheres to Semantic Versioning.

[1.1.2] - 2018-12-08

Fixed

  • fix a bug in order to not resolve path/to/file to path/from/file with the config ['to', 'from']. see #7

Changed

  • update test case
  • update coverage for node 10 & 11
  • 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

Changed

  • update test case
  • update changelog
  • update usage to readme
  • add more package keywords

[1.1.0] - 2018-05-06

Added

  • support custom file extensions

Changed

  • update test case
  • update changelog
  • update usage to readme

[1.0.4] - 2018-04-25

Added

  • add builtin modules resolve test case and relevant dependencies

Fixed

  • fix the bug that inner function resolveLookupPaths resolve /node_modules as //node_modules
  • update core modules for Node.js 8/9/...

Changed

  • add peerDependencies, repository, bugs, homepage config items to package.json
  • update readme
  • update changelog
  • update travis config
  • add release script to complete preparation before publish

[1.0.3] - 2017-01-12

Fixed

  • fix the bug that the path like /path/to/node_modules/node_modules is excluded from the lookup paths

[1.0.2] - 2017-01-05

Changed

  • fix the bug that it's unable to resolve non-relative path modules when current working directory is subdirectory of the project root directory.

[1.0.1] - 2016-12-29

Changed

  • remove package resolve to fix the bug caused by format changing of the internal file core.json of resolve 1.1.7
  • add bug description and solution to README.md

[1.0.0] - 2016-12-23

Added

  • support resolve node modules with alias config
  • support resolve normal node modules, including Node.js core modules and other third party modules
  • support resolve relative path modules