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:
Joe Fleming 2019-01-04 16:21:57 -07:00 committed by GitHub
parent 0a1b86ad3c
commit 82d05f5667
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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 }));
});
};