From 5bdff367aa7d5d6a5935a09a8f38ff3922dd33f7 Mon Sep 17 00:00:00 2001 From: Tiago Costa Date: Thu, 21 Oct 2021 18:41:50 +0100 Subject: [PATCH] fix(NA): creation of multiple processes on production by splitting no_transpilation when setting up node env (#115246) * fix(NA): adds no_transpilation_dist to avoid preserve_symlinks on dist * chore(NA): setup node env correctly on functional tests * chore(NA): try to fix tests * chore(NA): correctly separate split * chore(NA): check ensure preserve symlinks need * chore(NA): investigate path resolve result * chore(NA): investigate path resolve result #2 * chore(NA): comment out preserve symlinks * chore(NA): apply fs.realpathSync into the calculated REPO_ROOT paths on babel_register_for_test_plugins * chore(NA): removes debug code * chore(NA): move array definition * chore(NA): correctly import fs * chore(NA): add debug code * chore(NA): some more debug statements * chore(NA): remove ensure symlinks * chore(NA): trying to solve double symlinking * chore(NA): test mappings * chore(NA): process path * chore(NA): test a second map * chore(NA): using a different mappings * chore(NA): more debug cases * chore(NA): more debug logic * chore(NA): more debug cases * chore(NA): more debug cases * chore(NA): more debug cases * chore(NA): try to add realpathSync into require * chore(NA): try to add realpathSync into require * fix(NA): jenkins and buildkite run * chore(NA): add debug logs * chore(NA): correct path * chore(NA): correct path * chore(NA): add more test maps * chore(NA): add more test maps * chore(NA): add some more test maps experiments * chore(NA): try to remove another test map dep * chore(NA): try to remove another test map dep * chore(NA): try to remove another test map dep * chore(NA): try to remove another test map dep * chore(NA): try to remove another test map dep * chore(NA): try to remove another test map dep * chore(NA): try to remove another test map dep * chore(NA): try to remove another test map dep * chore(NA): include all correct transpilations for each jenkins path * chore(NA): include all correct transpilations for each used asset path * chore(NA): include all correct transpilations for each used asset path * chore(NA): remove jenkins support Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> --- .../lib/babel_register_for_test_plugins.js | 27 ++++++++++++------- src/setup_node_env/dist.js | 2 +- src/setup_node_env/no_transpilation.js | 10 +------ src/setup_node_env/no_transpilation_dist.js | 16 +++++++++++ 4 files changed, 35 insertions(+), 20 deletions(-) create mode 100644 src/setup_node_env/no_transpilation_dist.js diff --git a/packages/kbn-test/src/functional_tests/lib/babel_register_for_test_plugins.js b/packages/kbn-test/src/functional_tests/lib/babel_register_for_test_plugins.js index 2ded0e509c253b..09ed81b62a09d6 100644 --- a/packages/kbn-test/src/functional_tests/lib/babel_register_for_test_plugins.js +++ b/packages/kbn-test/src/functional_tests/lib/babel_register_for_test_plugins.js @@ -6,23 +6,30 @@ * Side Public License, v 1. */ +const Fs = require('fs'); const Path = require('path'); -const { REPO_ROOT } = require('@kbn/dev-utils'); +const { REPO_ROOT: REPO_ROOT_FOLLOWING_SYMLINKS } = require('@kbn/dev-utils'); +const BASE_REPO_ROOT = Path.resolve( + Fs.realpathSync(Path.resolve(REPO_ROOT_FOLLOWING_SYMLINKS, 'package.json')), + '..' +); + +const transpileKbnPaths = [ + 'test', + 'x-pack/test', + 'examples', + 'x-pack/examples', + // TODO: should should probably remove this link back to the source + 'x-pack/plugins/task_manager/server/config.ts', + 'src/core/utils/default_app_categories.ts', +].map((path) => Path.resolve(BASE_REPO_ROOT, path)); // modifies all future calls to require() to automatically // compile the required source with babel require('@babel/register')({ ignore: [/[\/\\](node_modules|target|dist)[\/\\]/], - only: [ - Path.resolve(REPO_ROOT, 'test'), - Path.resolve(REPO_ROOT, 'x-pack/test'), - Path.resolve(REPO_ROOT, 'examples'), - Path.resolve(REPO_ROOT, 'x-pack/examples'), - // TODO: should should probably remove this link back to the source - Path.resolve(REPO_ROOT, 'x-pack/plugins/task_manager/server/config.ts'), - Path.resolve(REPO_ROOT, 'src/core/utils/default_app_categories.ts'), - ], + only: transpileKbnPaths, babelrc: false, presets: [require.resolve('@kbn/babel-preset/node_preset')], extensions: ['.js', '.ts', '.tsx'], diff --git a/src/setup_node_env/dist.js b/src/setup_node_env/dist.js index 1d901b9ef5f061..3628a27a7793fd 100644 --- a/src/setup_node_env/dist.js +++ b/src/setup_node_env/dist.js @@ -6,5 +6,5 @@ * Side Public License, v 1. */ -require('./no_transpilation'); +require('./no_transpilation_dist'); require('./polyfill'); diff --git a/src/setup_node_env/no_transpilation.js b/src/setup_node_env/no_transpilation.js index 1826f5bb0297d5..b9497734b40bc8 100644 --- a/src/setup_node_env/no_transpilation.js +++ b/src/setup_node_env/no_transpilation.js @@ -7,12 +7,4 @@ */ require('./ensure_node_preserve_symlinks'); - -// The following require statements MUST be executed before any others - BEGIN -require('./exit_on_warning'); -require('./harden'); -// The following require statements MUST be executed before any others - END - -require('symbol-observable'); -require('source-map-support/register'); -require('./node_version_validator'); +require('./no_transpilation_dist'); diff --git a/src/setup_node_env/no_transpilation_dist.js b/src/setup_node_env/no_transpilation_dist.js new file mode 100644 index 00000000000000..c52eba70f4ad3a --- /dev/null +++ b/src/setup_node_env/no_transpilation_dist.js @@ -0,0 +1,16 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +// The following require statements MUST be executed before any others - BEGIN +require('./exit_on_warning'); +require('./harden'); +// The following require statements MUST be executed before any others - END + +require('symbol-observable'); +require('source-map-support/register'); +require('./node_version_validator');