mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 09:19:04 -04:00
Fix: Interpreter plugin dir loading (#27638)
* chore: refactor directory filtering * fix: filter out directories the intention was to only load files at the root anyway, not direcories
This commit is contained in:
parent
0a1b86ad3c
commit
82d05f5667
1 changed files with 11 additions and 9 deletions
|
@ -31,10 +31,16 @@ const canvasPluginDirectoryName = 'canvas_plugin';
|
|||
const isDirectory = path =>
|
||||
lstat(path)
|
||||
.then(stat => stat.isDirectory())
|
||||
.catch(() => false);
|
||||
.catch(() => false); // if lstat fails, it doesn't exist and is not a directory
|
||||
|
||||
const isDirname = (p, name) => path.basename(p) === name;
|
||||
|
||||
const filterDirectories = (paths, { exclude = false } = {}) => {
|
||||
return Promise.all(paths.map(p => isDirectory(p))).then(directories => {
|
||||
return paths.filter((p, i) => (exclude ? !directories[i] : directories[i]));
|
||||
});
|
||||
};
|
||||
|
||||
const getPackagePluginPath = () => {
|
||||
let basePluginPath = path.resolve(__dirname, '..');
|
||||
|
||||
|
@ -90,19 +96,15 @@ export const getPluginPaths = type => {
|
|||
return list.concat(dir);
|
||||
}, [])
|
||||
)
|
||||
.then(possibleCanvasPlugins => {
|
||||
// Check how many are directories. If lstat fails it doesn't exist anyway.
|
||||
return Promise.all(
|
||||
// An array
|
||||
possibleCanvasPlugins.map(pluginPath => isDirectory(pluginPath))
|
||||
).then(isDirectory => possibleCanvasPlugins.filter((pluginPath, i) => isDirectory[i]));
|
||||
})
|
||||
.then(possibleCanvasPlugins => filterDirectories(possibleCanvasPlugins, { exclude: false }))
|
||||
.then(canvasPluginDirectories => {
|
||||
return Promise.all(
|
||||
canvasPluginDirectories.map(dir =>
|
||||
// Get the full path of all files in the directory
|
||||
readdir(dir).then(files => files.map(file => path.resolve(dir, file)))
|
||||
)
|
||||
).then(flatten);
|
||||
)
|
||||
.then(flatten)
|
||||
.then(files => filterDirectories(files, { exclude: true }));
|
||||
});
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue