mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
[eslint] unify resolver configs (#19102)
* [eslint] unify resolver configs Our eslint resolver settings currently rely on the fact that we define our resolver with a string globally, and an object in the overrides. This causes the override value to completely override/replace the global setting, which is desired, but when the global setting is converted to an object they are merged, causing both resolvers to run. This is a problem because some dependencies in the UI side of things will resolve with the node resolver, but will resolve incorrectly because they are intended to use some webpack specific override. While trying to add TypeScript I needed to pass argument to the node resolver which uncovered this issue. The change here moves us away from using the node resolver directly and instead uses the kibana resolver with `forceNode: true` set when linting server code and `forceNode: false` when resolving imports that will be handled by webpack. * [import-resolver] use object spread operator
This commit is contained in:
parent
f24a725144
commit
0b03166d2d
2 changed files with 20 additions and 9 deletions
|
@ -9,7 +9,12 @@ module.exports = {
|
|||
],
|
||||
|
||||
settings: {
|
||||
'import/resolver': 'eslint-import-resolver-node',
|
||||
'import/resolver': {
|
||||
'@kbn/eslint-import-resolver-kibana': {
|
||||
forceNode: true,
|
||||
},
|
||||
},
|
||||
|
||||
react: {
|
||||
version: '16.3',
|
||||
},
|
||||
|
@ -73,6 +78,7 @@ module.exports = {
|
|||
|
||||
'import/resolver': {
|
||||
'@kbn/eslint-import-resolver-kibana': {
|
||||
forceNode: false,
|
||||
rootPackageName: 'kibana',
|
||||
kibanaPath: '.',
|
||||
pluginMap: readdirSync(resolve(__dirname, 'x-pack/plugins')).reduce(
|
||||
|
|
|
@ -33,9 +33,21 @@ function initContext(file, config) {
|
|||
return context;
|
||||
}
|
||||
|
||||
function tryNodeResolver(importRequest, file, config) {
|
||||
return nodeResolver.resolve(importRequest, file, {
|
||||
...config,
|
||||
extensions: ['.js', '.json'],
|
||||
isFile,
|
||||
});
|
||||
}
|
||||
|
||||
exports.resolve = function resolveKibanaPath(importRequest, file, config) {
|
||||
config = config || {};
|
||||
|
||||
if (config.forceNode) {
|
||||
return tryNodeResolver(importRequest, file, config);
|
||||
}
|
||||
|
||||
// these modules are simulated by webpack, so there is no
|
||||
// path to resolve to and no reason to do any more work
|
||||
if (importRequest.startsWith('uiExports/')) {
|
||||
|
@ -79,14 +91,7 @@ exports.resolve = function resolveKibanaPath(importRequest, file, config) {
|
|||
// to the node_modules directory by the node resolver, but we want
|
||||
// them to resolve to the actual shim
|
||||
if (isPathRequest || !isProbablyWebpackShim(importRequest, file)) {
|
||||
const nodeResult = nodeResolver.resolve(
|
||||
importRequest,
|
||||
file,
|
||||
Object.assign({}, config, {
|
||||
isFile,
|
||||
})
|
||||
);
|
||||
|
||||
const nodeResult = tryNodeResolver(importRequest, file, config);
|
||||
if (nodeResult && nodeResult.found) {
|
||||
return nodeResult;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue