-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ESLint: Use custom module resolver for ESLint
This custom resolver inspects the file's path to decide which off-the-shelf resolver would be appropriate. For files from the client folder, this resolver uses Webpack's resolver. For other files, this resolver uses Node's resolver.
- Loading branch information
Showing
2 changed files
with
61 additions
and
11 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 |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
const assign = require ( 'lodash/assign' ); | ||
const debugFactory = require( 'debug' ); | ||
const nodeResolver = require( 'eslint-import-resolver-node' ); | ||
const path = require( 'path' ); | ||
const webpackResolver = require( 'eslint-import-resolver-webpack' ); | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
const webpackResolveConfig = require( './webpack.config.resolve' ); | ||
|
||
/** | ||
* Module variables | ||
*/ | ||
const log = debugFactory('eslint-plugin-import:resolver:wp-calypso-resolver'); | ||
|
||
const nodeResolverConfig = { | ||
extensions: [ | ||
'.js', | ||
'.jsx', | ||
], | ||
moduleDirectory: [ | ||
'node_modules', | ||
'server' | ||
], | ||
paths: [ | ||
path.join( __dirname, 'test' ), | ||
path.join( __dirname, 'server' ), | ||
path.join( __dirname, 'client' ), | ||
] | ||
}; | ||
|
||
const webpackResolverConfig = { | ||
config: { | ||
resolve: webpackResolveConfig, | ||
}, | ||
}; | ||
|
||
exports.interfaceVersion = 2 | ||
|
||
exports.resolve = function (source, file, config) { | ||
log('Resolving', source, 'from:', file); | ||
// If the file is from the client folder, use Webpack for resolution. | ||
// Otherwise, use Node's resolver. | ||
if (file.indexOf('/client/') > 0) { | ||
log('Client file detected, resolving with Webpack'); | ||
return webpackResolver.resolve( source, file, webpackResolverConfig ); | ||
} else { | ||
log('Resolving with Node resolver'); | ||
return nodeResolver.resolve( source, file, nodeResolverConfig ); | ||
} | ||
} |
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