Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v1.9.0 bump #372

Merged
merged 2 commits into from
Jun 13, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ This project adheres to [Semantic Versioning](http://semver.org/).
This change log adheres to standards from [Keep a CHANGELOG](http://keepachangelog.com).

## [Unreleased]


## [1.9.0] - 2016-06-10
### Added
- Added support TomDoc comments to [`no-deprecated`]. ([#321], thanks [@josh])
- Added support for loading custom resolvers ([#314], thanks [@le0nik])
Expand Down Expand Up @@ -265,7 +268,8 @@ for info on changes for earlier releases.
[#119]: https://github.com/benmosher/eslint-plugin-import/issues/119
[#89]: https://github.com/benmosher/eslint-plugin-import/issues/89

[Unreleased]: https://github.com/benmosher/eslint-plugin-import/compare/v1.8.1...HEAD
[Unreleased]: https://github.com/benmosher/eslint-plugin-import/compare/v1.9.0...HEAD
[1.9.0]: https://github.com/benmosher/eslint-plugin-import/compare/v1.8.1...v1.9.0
[1.8.1]: https://github.com/benmosher/eslint-plugin-import/compare/v1.8.0...v1.8.1
[1.8.0]: https://github.com/benmosher/eslint-plugin-import/compare/v1.7.0...v1.8.0
[1.7.0]: https://github.com/benmosher/eslint-plugin-import/compare/v1.6.1...v1.7.0
Expand Down
48 changes: 15 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,41 +125,32 @@ resolvers are just npm packages, so [third party packages are supported](https:/

You can reference resolvers in several ways(in order of precedence):

- with an absolute path to resolver, used as a `computed property` name, which is supported since Node v4:
- as a conventional `eslint-import-resolver` name, like `eslint-import-resolver-foo`:

```js
// .eslintrc.js
module.exports = {
settings: {
'import/resolver': {
[path.resolve('../../../my-resolver')]: { someConfig: value }
}
}
}
```yaml
# .eslintrc.yml
settings:
# uses 'eslint-import-resolver-foo':
import/resolver: foo
```

- with a path relative to the closest `package.json` file:

```js
// .eslintrc.js
module.exports = {
settings: {
'import/resolver': {
'./my-resolver': { someConfig: value }
foo: { someConfig: value }
}
}
}
```

- with a full npm module name, like `my-awesome-npm-module`:

```yaml
# .eslintrc.yml
settings:
import/resolver: './my-resolver'
import/resolver: 'my-awesome-npm-module'
```

- with an npm module name, like `my-awesome-npm-module`:

```js
// .eslintrc.js
module.exports = {
Expand All @@ -171,32 +162,23 @@ module.exports = {
}
```


```yaml
# .eslintrc.yml
settings:
import/resolver: 'my-awesome-npm-module'
```

- as a conventional `eslint-import-resolver` name, like `eslint-import-resolver-foo`:

- with a filesystem path to resolver, defined in this example as a `computed property` name:

```js
// .eslintrc.js
module.exports = {
settings: {
'import/resolver': {
foo: { someConfig: value }
[path.resolve('../../../my-resolver')]: { someConfig: value }
}
}
}
```

`.eslintrc.yml`:
```yaml
settings:
import/resolver: foo
```
Relative paths will be resolved relative to the source's nearest `package.json` or
the process's current working directory if no `package.json` is found.



If you are interesting in writing a resolver, see the [spec](./resolvers/README.md) for more details.

Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "eslint-plugin-import",
"version": "1.8.1",
"version": "1.9.0",
"description": "Import with sanity.",
"main": "lib/index.js",
"directories": {
Expand Down Expand Up @@ -71,7 +71,6 @@
"es6-set": "^0.1.4",
"es6-symbol": "*",
"eslint-import-resolver-node": "^0.2.0",
"is-absolute": "^0.2.5",
"lodash.cond": "^4.3.0",
"lodash.endswith": "^4.0.1",
"lodash.find": "^4.3.0",
Expand Down
44 changes: 18 additions & 26 deletions src/core/resolve.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,11 @@ import Map from 'es6-map'
import Set from 'es6-set'
import assign from 'object-assign'
import pkgDir from 'pkg-dir'
import isAbsoluteFallback from 'is-absolute'

import fs from 'fs'
import { dirname, basename, join, isAbsolute as isAbsoluteNode } from 'path'
import * as path from 'path'

const isAbsolute = isAbsoluteNode || isAbsoluteFallback

export const CASE_SENSITIVE_FS = !fs.existsSync(join(__dirname, 'reSOLVE.js'))
export const CASE_SENSITIVE_FS = !fs.existsSync(path.join(__dirname, 'reSOLVE.js'))

const fileExistsCache = new Map()

Expand All @@ -36,7 +33,7 @@ function fileExistsWithCaseSync(filepath, cacheSettings) {
// null means it resolved to a builtin
if (filepath === null) return true

const dir = dirname(filepath)
const dir = path.dirname(filepath)

let result = checkCache(filepath, cacheSettings)
if (result != null) return result
Expand All @@ -46,7 +43,7 @@ function fileExistsWithCaseSync(filepath, cacheSettings) {
result = true
} else {
const filenames = fs.readdirSync(dir)
if (filenames.indexOf(basename(filepath)) === -1) {
if (filenames.indexOf(path.basename(filepath)) === -1) {
result = false
} else {
result = fileExistsWithCaseSync(dir, cacheSettings)
Expand All @@ -58,7 +55,7 @@ function fileExistsWithCaseSync(filepath, cacheSettings) {

export function relative(modulePath, sourceFile, settings) {

const sourceDir = dirname(sourceFile)
const sourceDir = path.dirname(sourceFile)
, cacheKey = sourceDir + hashObject(settings) + modulePath

const cacheSettings = assign({
Expand All @@ -73,18 +70,18 @@ export function relative(modulePath, sourceFile, settings) {
const cachedPath = checkCache(cacheKey, cacheSettings)
if (cachedPath !== undefined) return cachedPath

function cache(path) {
cachePath(cacheKey, path)
return path
function cache(resolvedPath) {
cachePath(cacheKey, resolvedPath)
return resolvedPath
}

function withResolver(resolver, config) {

function v1() {
try {
const path = resolver.resolveImport(modulePath, sourceFile, config)
if (path === undefined) return { found: false }
return { found: true, path }
const resolved = resolver.resolveImport(modulePath, sourceFile, config)
if (resolved === undefined) return { found: false }
return { found: true, path: resolved }
} catch (err) {
return { found: false }
}
Expand Down Expand Up @@ -148,27 +145,22 @@ function resolverReducer(resolvers, map) {
}

function requireResolver(name, sourceFile) {
// Try to resolve package with absolute path (/Volumes/....)
if (isAbsolute(name)) {
try {
return require(name)
} catch (err) { /* continue */ }
}

// Try to resolve package with path, relative to closest package.json
// Try to resolve package with conventional name
try {
const packageDir = pkgDir.sync(sourceFile)
return require(join(packageDir, name))
return require(`eslint-import-resolver-${name}`)
} catch (err) { /* continue */ }

// Try to resolve package with custom name (@myorg/resolver-name)
try {
return require(name)
} catch (err) { /* continue */ }

// Try to resolve package with conventional name
// Try to resolve package with path, relative to closest package.json
// or current working directory
try {
return require(`eslint-import-resolver-${name}`)
const baseDir = pkgDir.sync(sourceFile) || process.cwd()
// absolute paths ignore base, so this covers both
return require(path.resolve(baseDir, name))
} catch (err) { /* continue */ }

// all else failed
Expand Down