From 422a65179efb30c55cb7b489b632fd13d8c6c6d9 Mon Sep 17 00:00:00 2001 From: ppisljar Date: Mon, 19 Nov 2018 09:40:05 +0100 Subject: [PATCH] review feedback --- .../server/get_plugin_paths.js | 29 ++++++++++----- packages/kbn-interpreter/server/index.js | 22 ------------ .../kbn-interpreter/tasks/webpack.plugins.js | 36 +++++++------------ 3 files changed, 32 insertions(+), 55 deletions(-) delete mode 100644 packages/kbn-interpreter/server/index.js diff --git a/packages/kbn-interpreter/server/get_plugin_paths.js b/packages/kbn-interpreter/server/get_plugin_paths.js index c1c9d15284fab24..f6520563c912ffb 100644 --- a/packages/kbn-interpreter/server/get_plugin_paths.js +++ b/packages/kbn-interpreter/server/get_plugin_paths.js @@ -23,22 +23,33 @@ import { promisify } from 'util'; import { flatten } from 'lodash'; import { pathsRegistry } from '../common/lib/paths_registry'; +const lstat = promisify(fs.lstat); const readdir = promisify(fs.readdir); +const isDirectory = path => + lstat(path) + .then(stat => stat.isDirectory()) + .catch(() => false); + export const getPluginPaths = type => { const typePaths = pathsRegistry.get(type); if (!typePaths) { throw new Error(`Unknown type: ${type}`); } - return Promise.all(typePaths.map(path => { - - // Get the full path of all files in the directory - return readdir(path).then(files => files.map(file => { - if (!file.endsWith('.js')) { - return; - } - return resolve(path, file); - }).filter(path => path)).catch(); + return Promise.all(typePaths.map(async path => { + const isDir = await isDirectory(path); + if (!isDir) { + return; + } + // Get the full path of all js files in the directory + return readdir(path).then(files => { + return files.reduce((acc, file) => { + if (file.endsWith('.js')) { + acc.push(resolve(path, file)); + } + return acc; + }, []); + }).catch(); })).then(flatten); }; diff --git a/packages/kbn-interpreter/server/index.js b/packages/kbn-interpreter/server/index.js deleted file mode 100644 index bf7ff13e3ac0f61..000000000000000 --- a/packages/kbn-interpreter/server/index.js +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Licensed to Elasticsearch B.V. under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch B.V. licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import { populateServerRegistries, getServerRegistries } from './server_registries'; - -export { populateServerRegistries, getServerRegistries }; diff --git a/packages/kbn-interpreter/tasks/webpack.plugins.js b/packages/kbn-interpreter/tasks/webpack.plugins.js index d20442bb063fa01..8b16edc5ad46222 100644 --- a/packages/kbn-interpreter/tasks/webpack.plugins.js +++ b/packages/kbn-interpreter/tasks/webpack.plugins.js @@ -37,6 +37,7 @@ module.exports = { resolve: { extensions: ['.js', '.json'], + mainFields: ['browser', 'main'], }, plugins: [ @@ -51,12 +52,15 @@ module.exports = { }); this.plugin('done', function (stats) { - if (stats.compilation.errors && stats.compilation.errors.length) { - if (isWatch) { - console.error(stats.compilation.errors[0]); - } else { - throw stats.compilation.errors[0]; - } + if (!stats.hasErrors()) { + return; + } + const errorMessage = stats.toString('errors-only'); + if (isWatch) { + console.error(errorMessage); + } + else { + throw new Error(errorMessage); } }); }, @@ -66,28 +70,12 @@ module.exports = { rules: [ { test: /\.js$/, + exclude: [/node_modules/], loaders: 'babel-loader', options: { babelrc: false, - plugins: [ - 'transform-object-rest-spread', - 'transform-async-to-generator', - 'transform-class-properties', - ], - presets: [ - 'es2015', - 'react', - [ - 'env', - { - targets: { - node: 'current', - }, - }, - ], - ], + presets: [require.resolve('@kbn/babel-preset/webpack_preset')], }, - exclude: [/node_modules/], }, { test: /\.(png|jpg|gif|jpeg|svg)$/,