-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
309 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,8 +2,8 @@ sudo: false | |
language: node_js | ||
node_js: | ||
- "4" | ||
- "5" | ||
- "6" | ||
- "8" | ||
- "node" | ||
script: | ||
- "npm run cov" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
const fs = require('fs'); | ||
const adjustMD = require('adjust-md-for-publish'); | ||
|
||
function copyFile(filename) { | ||
fs.writeFileSync(`dist/${filename}`, fs.readFileSync(filename)); | ||
} | ||
|
||
adjustMD({ | ||
filename: 'README.md', | ||
destname: 'dist/README.md', | ||
filterSection: [ | ||
'CHANGELOG', | ||
'References' | ||
] | ||
}); | ||
|
||
[ | ||
'core.js', | ||
'index.js', | ||
'package.json' | ||
].forEach(copyFile); | ||
|
||
console.log('\n release is ready !!!'); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
NOTE.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# NOTE | ||
|
||
The `dist` folder contains the standalone build for guideline, however files here are not checked-in whenever there are changes in the source code. If you are on the `dev` branch, files here are **NOT** up to date. Only the `master` branch contains the built files for the latest stable version. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# eslint-import-resolver-alias | ||
|
||
[![Version npm][version]](http://browsenpm.org/package/eslint-import-resolver-alias) | ||
[![Build Status][build]](https://travis-ci.org/johvin/eslint-import-resolver-alias) | ||
[![Download][download]](https://www.npmjs.com/package/eslint-import-resolver-alias) | ||
[![Dependencies][david]](https://david-dm.org/johvin/eslint-import-resolver-alias) | ||
[![Coverage Status][cover]](https://coveralls.io/github/johvin/eslint-import-resolver-alias?branch=master) | ||
[![Known Vulnerabilities][vulnerabilities]](https://snyk.io/test/npm/eslint-import-resolver-alias) | ||
[![License][license]](https://opensource.org/licenses/MIT) | ||
|
||
[version]: http://img.shields.io/npm/v/eslint-import-resolver-alias.svg?style=flat-square | ||
[build]: http://img.shields.io/travis/johvin/eslint-import-resolver-alias/master.svg?style=flat-square | ||
[download]: https://img.shields.io/npm/dm/eslint-import-resolver-alias.svg?style=flat-square | ||
[david]: https://img.shields.io/david/johvin/eslint-import-resolver-alias.svg?style=flat-square | ||
[cover]: http://img.shields.io/coveralls/johvin/eslint-import-resolver-alias/master.svg?style=flat-square | ||
[vulnerabilities]: https://snyk.io/test/npm/eslint-import-resolver-alias/badge.svg?style=flat-square | ||
[license]: https://img.shields.io/badge/License-MIT-brightgreen.svg?style=flat-square | ||
|
||
|
||
This is a simple Node.js module import resolution plugin for [`eslint-plugin-import`](https://www.npmjs.com/package/eslint-plugin-import), which supports module alias and native Node.js module import. | ||
|
||
|
||
## Installation | ||
|
||
Prerequisites: Node.js >=4.x and corresponding version of npm. | ||
|
||
```shell | ||
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`. | ||
|
||
```js | ||
// .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'] | ||
], | ||
// node: true | ||
} | ||
} | ||
}; | ||
``` | ||
|
||
Note: | ||
|
||
- The items of alias config array is also array 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 os module name | ||
- The config item `['helper', './utils/helper']` means that the module `helper/*` will be resolved to `./utils/helper/*`. See [#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 | ||
- when the config is an empty array or not an array, the resolver falls back to native Node.js module import |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
'use strict'; | ||
/** | ||
* this resolver is used as a plugin of eslint-plugin-import | ||
* to solve npm package mapping problem | ||
* | ||
*/ | ||
const path = require('path'); | ||
const coreModules = {}; | ||
|
||
require('./core').forEach(function (m) { | ||
this[m] = true | ||
}, coreModules); | ||
|
||
exports.interfaceVersion = 2; | ||
|
||
const Module = module.constructor; | ||
const toString = Object.prototype.toString; | ||
|
||
exports.resolve = (modulePath, sourceFile, config) => { | ||
const isRelativePath = modulePath[0] === '.'; | ||
if (!isRelativePath && coreModules[modulePath]) { | ||
return { found: true, path: null }; | ||
} | ||
|
||
const sourceDir = path.dirname(sourceFile); | ||
let findPath; | ||
|
||
if (isRelativePath) { | ||
findPath = path.resolve(sourceDir, modulePath); | ||
return findModulePath(findPath, []); | ||
} | ||
|
||
/* istanbul ignore else */ | ||
if (toString.call(config) === '[object Array]') { | ||
for (let i = 0, len = config.length; i < len; i++) { | ||
const re = new RegExp(`(^|/)${config[i][0]}($|/)`); | ||
const match = modulePath.match(re); | ||
if (match) { | ||
findPath = modulePath.replace(match[0], `${match[1]}${config[i][1]}${match[2]}`); | ||
break; | ||
} | ||
} | ||
} | ||
|
||
if (!findPath) { | ||
findPath = modulePath; | ||
} | ||
|
||
const paths = resolveLookupPaths(sourceDir); | ||
return findModulePath(findPath, paths); | ||
}; | ||
|
||
function findModulePath(request, paths) { | ||
const filename = Module._findPath(request, paths); | ||
return { | ||
found: !!filename, | ||
path: filename || null | ||
}; | ||
} | ||
|
||
function resolveLookupPaths(absoluteSourceDir) { | ||
const paths = []; | ||
let curDir; | ||
let nextDir = absoluteSourceDir; | ||
do { | ||
// not append node_modules to a path already ending with node_modules | ||
while(nextDir.indexOf('node_modules', nextDir.length - 12) !== -1) { | ||
nextDir = path.resolve(nextDir, '..'); | ||
} | ||
curDir = nextDir; | ||
paths.push(path.resolve(curDir, 'node_modules')); | ||
nextDir = path.resolve(curDir, '..'); | ||
} while(nextDir !== curDir); | ||
|
||
paths.push.apply(paths, Module.globalPaths); | ||
return paths; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
{ | ||
"name": "eslint-import-resolver-alias", | ||
"version": "1.0.3", | ||
"description": "a simple Node behavior import resolution plugin for eslint-plugin-import, supporting module alias.", | ||
"main": "index.js", | ||
"scripts": { | ||
"release": "node build/release.js", | ||
"test": "mocha test/test.js --require test/setup.js", | ||
"cov": "istanbul cover node_modules/mocha/bin/_mocha -i index.js -- test/test.js --require test/setup.js" | ||
}, | ||
"keywords": [ | ||
"eslint", | ||
"eslintplugin", | ||
"modules", | ||
"alias", | ||
"eslint-plugin-import", | ||
"import-resolver" | ||
], | ||
"engines": { | ||
"node": ">= 4" | ||
}, | ||
"author": "johvin", | ||
"license": "MIT", | ||
"devDependencies": { | ||
"adjust-md-for-publish": "^1.0.0", | ||
"builtin-modules": "^2.0.0", | ||
"istanbul": "^1.0.0-alpha.2", | ||
"mocha": "^3.2.0" | ||
}, | ||
"peerDependencies": { | ||
"eslint-plugin-import": ">=1.4.0" | ||
}, | ||
"directories": { | ||
"test": "test" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/johvin/eslint-import-resolver-alias.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/johvin/eslint-import-resolver-alias/issues" | ||
}, | ||
"homepage": "https://github.com/johvin/eslint-import-resolver-alias#readme" | ||
} |
Oops, something went wrong.