-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
42 changed files
with
735 additions
and
224 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
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 |
---|---|---|
|
@@ -12,3 +12,4 @@ rules: | |
curly: [2, "multi-line"] | ||
comma-dangle: [2, always-multiline] | ||
eqeqeq: [2, "allow-null"] | ||
no-shadow: 1 |
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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
# files | ||
src/ | ||
reports/ | ||
resolvers/ | ||
|
||
# config | ||
.eslintrc | ||
|
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
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 @@ | ||
--- | ||
env: | ||
es6: false |
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,26 @@ | ||
# eslint-import-resolver-node | ||
|
||
[![npm](https://img.shields.io/npm/v/eslint-import-resolver-node.svg)](https://www.npmjs.com/package/eslint-import-resolver-node) | ||
|
||
Default Node-style module resolution plugin for [`eslint-plugin-import`](https://www.npmjs.com/package/eslint-plugin-import). | ||
|
||
Published separately to allow pegging to a specific version in case of breaking | ||
changes. | ||
|
||
Config is passed directly through to [`resolve`](https://www.npmjs.com/package/resolve) as options: | ||
|
||
```yaml | ||
settings: | ||
import/resolver: | ||
node: | ||
moduleDirectory: | ||
- node_modules | ||
- src | ||
``` | ||
|
||
or to use the default options: | ||
|
||
```yaml | ||
settings: | ||
import/resolver: node | ||
``` |
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,17 @@ | ||
var resolve = require('resolve') | ||
, path = require('path') | ||
, assign = require('object-assign') | ||
|
||
exports.resolveImport = function resolveImport(source, file, config) { | ||
if (resolve.isCore(source)) return null | ||
|
||
return resolve.sync(source, opts(path.dirname(file), config)) | ||
} | ||
|
||
function opts(basedir, config) { | ||
return assign( {} | ||
, config | ||
, { basedir: basedir } | ||
) | ||
} | ||
|
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,30 @@ | ||
{ | ||
"name": "eslint-import-resolver-node", | ||
"version": "0.0.0", | ||
"description": "Node default behavior import resolution plugin for eslint-plugin-import.", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/benmosher/eslint-plugin-import" | ||
}, | ||
"keywords": [ | ||
"eslint", | ||
"eslintplugin", | ||
"esnext", | ||
"modules", | ||
"eslint-plugin-import" | ||
], | ||
"author": "Ben Mosher (me@benmosher.com)", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/benmosher/eslint-plugin-import/issues" | ||
}, | ||
"homepage": "https://github.com/benmosher/eslint-plugin-import", | ||
"dependencies": { | ||
"object-assign": "^4.0.1", | ||
"resolve": "^1.1.6" | ||
} | ||
} |
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 @@ | ||
{ "presets": ["es2015"] } |
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,2 @@ | ||
test/ | ||
.babelrc |
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,27 @@ | ||
# eslint-import-resolver-webpack | ||
|
||
[![npm](https://img.shields.io/npm/v/eslint-import-resolver-webpack.svg)](https://www.npmjs.com/package/eslint-import-resolver-webpack) | ||
|
||
Webpack-literate module resolution plugin for [`eslint-plugin-import`](https://www.npmjs.com/package/eslint-plugin-import). | ||
|
||
Published separately to allow pegging to a specific version in case of breaking | ||
changes. | ||
|
||
Will look for `webpack.config.js` as a sibling of the first ancestral `package.json`, | ||
or a `config` parameter may be provided with another filename/path relative to the | ||
`package.json`. | ||
|
||
```yaml | ||
--- | ||
settings: | ||
import/resolver: webpack # take all defaults | ||
``` | ||
|
||
or with explicit config file name: | ||
|
||
```yaml | ||
--- | ||
settings: | ||
import/resolver: | ||
webpack: { config: 'webpack.dev.config.js' } | ||
``` |
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,87 @@ | ||
var findRoot = require('find-root') | ||
, path = require('path') | ||
, resolve = require('resolve') | ||
, get = require('lodash.get') | ||
|
||
var resolveAlias = require('./resolve-alias') | ||
|
||
/** | ||
* Find the full path to 'source', given 'file' as a full reference path. | ||
* | ||
* resolveImport('./foo', '/Users/ben/bar.js') => '/Users/ben/foo.js' | ||
* @param {string} source - the module to resolve; i.e './some-module' | ||
* @param {string} file - the importing file's full path; i.e. '/usr/local/bin/file.js' | ||
* TODO: take options as a third param, with webpack config file name | ||
* @return {string?} the resolved path to source, undefined if not resolved, or null | ||
* if resolved to a non-FS resource (i.e. script tag at page load) | ||
*/ | ||
exports.resolveImport = function resolveImport(source, file, settings) { | ||
|
||
// strip loaders | ||
var finalBang = source.lastIndexOf('!') | ||
if (finalBang >= 0) { | ||
source = source.slice(finalBang + 1) | ||
} | ||
|
||
if (resolve.isCore(source)) return null | ||
|
||
var webpackConfig | ||
try { | ||
var packageDir = findRoot(file) | ||
if (!packageDir) throw new Error('package not found above ' + file) | ||
|
||
webpackConfig = require(path.join(packageDir, get(settings, 'config', 'webpack.config.js'))) | ||
} catch (err) { | ||
webpackConfig = {} | ||
} | ||
|
||
// externals | ||
if (findExternal(source, webpackConfig.externals)) return null | ||
|
||
// replace alias if needed | ||
source = resolveAlias(source, get(webpackConfig, ['resolve', 'alias'], {})) | ||
|
||
var paths = [] | ||
|
||
// root as first alternate path | ||
var rootPath = get(webpackConfig, ['resolve', 'root']) | ||
if (rootPath) paths.push(rootPath) | ||
|
||
// otherwise, resolve "normally" | ||
return resolve.sync(source, { | ||
basedir: path.dirname(file), | ||
|
||
// defined via http://webpack.github.io/docs/configuration.html#resolve-extensions | ||
extensions: get(webpackConfig, ['resolve', 'extensions']) | ||
|| ['', '.webpack.js', '.web.js', '.js'], | ||
|
||
// http://webpack.github.io/docs/configuration.html#resolve-modulesdirectories | ||
moduleDirectory: get(webpackConfig, ['resolve', 'modulesDirectories']) | ||
|| ['web_modules', 'node_modules'], | ||
|
||
paths: paths, | ||
}) | ||
} | ||
|
||
function findExternal(source, externals) { | ||
if (!externals) return false | ||
|
||
// string match | ||
if (typeof externals === 'string') return (source === externals) | ||
|
||
// array: recurse | ||
if (externals instanceof Array) { | ||
return externals.some(function (e) { return findExternal(source, e) }) | ||
} | ||
|
||
if (externals instanceof RegExp) { | ||
return externals.test(source) | ||
} | ||
|
||
if (typeof externals === 'function') { | ||
throw new Error('unable to handle function externals') | ||
} | ||
|
||
// else, vanilla object | ||
return Object.keys(externals).some(function (e) { return source === e }) | ||
} |
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,37 @@ | ||
{ | ||
"name": "eslint-import-resolver-webpack", | ||
"version": "0.0.0", | ||
"description": "Resolve paths to dependencies, given a webpack.config.js. Plugin for eslint-plugin-import.", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "mocha --compilers js:babel-core/register" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/benmosher/eslint-plugin-import.git" | ||
}, | ||
"keywords": [ | ||
"eslint-plugin-import", | ||
"eslint", | ||
"jsnext", | ||
"modules", | ||
"webpack" | ||
], | ||
"author": "Ben Mosher (me@benmosher.com)", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/benmosher/eslint-plugin-import/issues" | ||
}, | ||
"homepage": "https://github.com/benmosher/eslint-plugin-import#readme", | ||
"dependencies": { | ||
"find-root": "^0.1.1", | ||
"lodash.get": "^3.7.0", | ||
"resolve": "^1.1.6" | ||
}, | ||
"devDependencies": { | ||
"babel-core": "^6.1.21", | ||
"babel-preset-es2015": "^6.1.18", | ||
"chai": "^3.4.1", | ||
"mocha": "^2.3.3" | ||
} | ||
} |
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,36 @@ | ||
var path = require('path') | ||
|
||
// implements a rough version of | ||
// http://webpack.github.io/docs/configuration.html#resolve-alias | ||
module.exports = function resolveAlias(source, aliases) { | ||
|
||
for (var alias in aliases) { | ||
var match = matchAlias(source, alias, aliases[alias]) | ||
if (match) return match | ||
} | ||
|
||
// fail out | ||
return source | ||
} | ||
|
||
function matchAlias(source, alias, value) { | ||
var isExact = (alias[alias.length - 1] === '$') | ||
, isFile = (path.extname(value) !== '') | ||
, segments = source.split(path.sep) | ||
|
||
if (isExact) alias = alias.slice(0, -1) | ||
|
||
if (segments[0] === alias) { | ||
// always return exact match | ||
if (segments.length === 1) return value | ||
|
||
// prefix match on exact match for file is an error | ||
if (isFile && (isExact || !/^[./]/.test(value))) { | ||
throw new Error('can\'t match file with exact alias prefix') | ||
} | ||
|
||
// otherwise, prefix match is fine for non-file paths | ||
if (!isExact && !isFile) return [value].concat(segments.slice(1)).join(path.sep) | ||
} | ||
|
||
} |
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,5 @@ | ||
--- | ||
env: | ||
mocha: true | ||
rules: | ||
quotes: 0 |
Oops, something went wrong.