mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
* [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
5e697f0074
commit
f6399b4d4c
2 changed files with 20 additions and 9 deletions
|
@ -9,7 +9,11 @@ module.exports = {
|
|||
],
|
||||
|
||||
settings: {
|
||||
'import/resolver': 'eslint-import-resolver-node',
|
||||
'import/resolver': {
|
||||
'@kbn/eslint-import-resolver-kibana': {
|
||||
forceNode: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
overrides: [
|
||||
|
@ -65,6 +69,7 @@ module.exports = {
|
|||
|
||||
'import/resolver': {
|
||||
'@kbn/eslint-import-resolver-kibana': {
|
||||
forceNode: false,
|
||||
rootPackageName: 'kibana',
|
||||
kibanaPath: '.',
|
||||
pluginMap: readdirSync(resolve(__dirname, 'x-pack/plugins')).reduce(
|
||||
|
|
|
@ -33,8 +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);
|
||||
}
|
||||
|
||||
const { webpackConfig, aliasEntries } = initContext(file, config);
|
||||
let isPathRequest = getIsPathRequest(importRequest);
|
||||
|
||||
|
@ -69,14 +82,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