From ae8b84bb180a5c61ca55361c0547df01119c3f46 Mon Sep 17 00:00:00 2001 From: Spencer Date: Thu, 22 Nov 2018 18:14:14 -0800 Subject: [PATCH] [babel-register] ignore packages directory when running from source (#26098) When running the Kibana distributable packages are excluded from `babel-register` because they are installed in the node_modules directory. When running from source they are not ignored, which means that babel-register is doing more work than necessary because these files need to already be built. To fix this I've added an ignore rule that excludes all packages when we are running from source. --- src/setup_node_env/babel_register/register.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/setup_node_env/babel_register/register.js b/src/setup_node_env/babel_register/register.js index 2d909636a02a83..1cc90fb507e185 100644 --- a/src/setup_node_env/babel_register/register.js +++ b/src/setup_node_env/babel_register/register.js @@ -38,8 +38,8 @@ var ignore = [ // https://github.com/elastic/kibana/issues/14800#issuecomment-366130268 // ignore paths matching `/node_modules/{a}/{b}`, unless `a` - // is `x-pack` and `b` is not `node_modules` - /\/node_modules\/(?!x-pack\/(?!node_modules)([^\/]+))([^\/]+\/[^\/]+)/ + // is `x-pack` or `b` is not `node_modules` + /\/node_modules\/(?!x-pack\/(?!node_modules)([^\/]+))([^\/]+\/[^\/]+)/, ]; if (global.__BUILT_WITH_BABEL__) { @@ -52,6 +52,13 @@ if (global.__BUILT_WITH_BABEL__) { // building their server code at require-time since version 4.2 // TODO: the plugin install process could transpile plugin server code... ignore.push(resolve(__dirname, '../../../src')); +} else { + ignore.push( + // ignore any path in the packages, unless it is in the package's + // root `src` directory, in any test or __tests__ directory, or it + // ends with .test.js, .test.ts, or .test.tsx + /\/packages\/(eslint-|kbn-)[^\/]+\/(?!src\/.*|(.+\/)?(test|__tests__)\/.+|.+\.test\.(js|ts|tsx)$)(.+$)/ + ); } // modifies all future calls to require() to automatically