From 3859c5699becc15eab1526cf1dde37dfe5e9e370 Mon Sep 17 00:00:00 2001 From: Tiago Costa Date: Thu, 14 Oct 2021 03:00:14 +0100 Subject: [PATCH 01/12] fix(NA): adds no_transpilation_dist to avoid preserve_symlinks on dist --- src/setup_node_env/dist.js | 2 +- src/setup_node_env/no_transpilation.js | 10 +--------- src/setup_node_env/no_transpilation_dist.js | 16 ++++++++++++++++ 3 files changed, 18 insertions(+), 10 deletions(-) create mode 100644 src/setup_node_env/no_transpilation_dist.js 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'); From 5728f666f4cdc7aae65bfde5c4732fbaf1cf0ea7 Mon Sep 17 00:00:00 2001 From: Tiago Costa Date: Thu, 14 Oct 2021 16:15:37 +0100 Subject: [PATCH 02/12] chore(NA): setup node env correctly on functional tests --- scripts/functional_tests.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/functional_tests.js b/scripts/functional_tests.js index 89f20121867dc7..d591752a701c80 100644 --- a/scripts/functional_tests.js +++ b/scripts/functional_tests.js @@ -6,6 +6,8 @@ * Side Public License, v 1. */ +require('../src/setup_node_env'); + // eslint-disable-next-line no-restricted-syntax const alwaysImportedTests = [ require.resolve('../test/functional/config.js'), @@ -20,7 +22,6 @@ const onlyNotInCoverageTests = [ require.resolve('../test/examples/config.js'), ]; -require('../src/setup_node_env'); require('@kbn/test').runTestsCli([ // eslint-disable-next-line no-restricted-syntax ...alwaysImportedTests, From e447bae5bbf146eafee1af126f2ef82dc589fd37 Mon Sep 17 00:00:00 2001 From: Tiago Costa Date: Thu, 14 Oct 2021 16:54:47 +0100 Subject: [PATCH 03/12] chore(NA): try to fix tests --- scripts/functional_tests.js | 3 +-- src/setup_node_env/dist.js | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/scripts/functional_tests.js b/scripts/functional_tests.js index d591752a701c80..89f20121867dc7 100644 --- a/scripts/functional_tests.js +++ b/scripts/functional_tests.js @@ -6,8 +6,6 @@ * Side Public License, v 1. */ -require('../src/setup_node_env'); - // eslint-disable-next-line no-restricted-syntax const alwaysImportedTests = [ require.resolve('../test/functional/config.js'), @@ -22,6 +20,7 @@ const onlyNotInCoverageTests = [ require.resolve('../test/examples/config.js'), ]; +require('../src/setup_node_env'); require('@kbn/test').runTestsCli([ // eslint-disable-next-line no-restricted-syntax ...alwaysImportedTests, diff --git a/src/setup_node_env/dist.js b/src/setup_node_env/dist.js index 3628a27a7793fd..1d901b9ef5f061 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_dist'); +require('./no_transpilation'); require('./polyfill'); From ae9860ae1a4f0a045e2d1e57426328ae49d98fe0 Mon Sep 17 00:00:00 2001 From: Tiago Costa Date: Thu, 14 Oct 2021 16:59:28 +0100 Subject: [PATCH 04/12] chore(NA): correctly separate split --- src/setup_node_env/dist.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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'); From 0d533cf0a13287fe207acd967e9f080eaa158b05 Mon Sep 17 00:00:00 2001 From: Tiago Costa Date: Thu, 14 Oct 2021 21:05:17 +0100 Subject: [PATCH 05/12] chore(NA): check ensure preserve symlinks need --- src/setup_node_env/dist.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/setup_node_env/dist.js b/src/setup_node_env/dist.js index 3628a27a7793fd..391ba4a2a9e58a 100644 --- a/src/setup_node_env/dist.js +++ b/src/setup_node_env/dist.js @@ -6,5 +6,6 @@ * Side Public License, v 1. */ +require('./ensure_node_preserve_symlinks'); require('./no_transpilation_dist'); require('./polyfill'); From eea42f9426221ab555f1f3b8ac7a06f67b98b676 Mon Sep 17 00:00:00 2001 From: Tiago Costa Date: Thu, 14 Oct 2021 21:51:19 +0100 Subject: [PATCH 06/12] chore(NA): investigate path resolve result --- .../functional_tests/lib/babel_register_for_test_plugins.js | 4 ++++ 1 file changed, 4 insertions(+) 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..13b23901525ab5 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 @@ -10,6 +10,10 @@ const Path = require('path'); const { REPO_ROOT } = require('@kbn/dev-utils'); +console.log(Path.resolve(REPO_ROOT, 'test')); +console.log(require('fs').realpathSync(Path.resolve(REPO_ROOT, 'test'))); +throw new Error('FAIL CI'); + // modifies all future calls to require() to automatically // compile the required source with babel require('@babel/register')({ From 988f5ba5f15d0772236870c675ed687e046f6987 Mon Sep 17 00:00:00 2001 From: Tiago Costa Date: Thu, 14 Oct 2021 21:57:50 +0100 Subject: [PATCH 07/12] chore(NA): investigate path resolve result #2 --- .../functional_tests/lib/babel_register_for_test_plugins.js | 3 +++ 1 file changed, 3 insertions(+) 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 13b23901525ab5..554e923602a600 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 @@ -10,8 +10,11 @@ const Path = require('path'); const { REPO_ROOT } = require('@kbn/dev-utils'); +const KIBANA_ROOT = Path.resolve(__dirname, '../../../../../'); + console.log(Path.resolve(REPO_ROOT, 'test')); console.log(require('fs').realpathSync(Path.resolve(REPO_ROOT, 'test'))); +console.log(Path.resolve(KIBANA_ROOT, 'test')); throw new Error('FAIL CI'); // modifies all future calls to require() to automatically From 3e4ba6dcb86f83af74f43b4a79ef4ef77f2a228e Mon Sep 17 00:00:00 2001 From: Tiago Costa Date: Thu, 14 Oct 2021 22:28:33 +0100 Subject: [PATCH 08/12] chore(NA): comment out preserve symlinks --- src/setup_node_env/dist.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/setup_node_env/dist.js b/src/setup_node_env/dist.js index 391ba4a2a9e58a..7de5d3a4fb1c53 100644 --- a/src/setup_node_env/dist.js +++ b/src/setup_node_env/dist.js @@ -6,6 +6,6 @@ * Side Public License, v 1. */ -require('./ensure_node_preserve_symlinks'); +// require('./ensure_node_preserve_symlinks'); require('./no_transpilation_dist'); require('./polyfill'); From 9f6aa9f69726ea5b8c34883527a03824f7f48311 Mon Sep 17 00:00:00 2001 From: Tiago Costa Date: Fri, 15 Oct 2021 02:39:09 +0100 Subject: [PATCH 09/12] chore(NA): apply fs.realpathSync into the calculated REPO_ROOT paths on babel_register_for_test_plugins --- .../lib/babel_register_for_test_plugins.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) 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 554e923602a600..7305b56a222b90 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,16 +6,17 @@ * Side Public License, v 1. */ +const Fs = require('path'); const Path = require('path'); const { REPO_ROOT } = require('@kbn/dev-utils'); -const KIBANA_ROOT = Path.resolve(__dirname, '../../../../../'); +// const KIBANA_ROOT = Path.resolve(__dirname, '../../../../../'); -console.log(Path.resolve(REPO_ROOT, 'test')); -console.log(require('fs').realpathSync(Path.resolve(REPO_ROOT, 'test'))); -console.log(Path.resolve(KIBANA_ROOT, 'test')); -throw new Error('FAIL CI'); +// console.log(Path.resolve(REPO_ROOT, 'test')); +// console.log(require('fs').realpathSync(Path.resolve(REPO_ROOT, 'test'))); +// console.log(Path.resolve(KIBANA_ROOT, 'test')); +// throw new Error('FAIL CI'); // modifies all future calls to require() to automatically // compile the required source with babel @@ -29,7 +30,7 @@ require('@babel/register')({ // 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'), - ], + ].map((path) => Fs.realpathSync(path)), babelrc: false, presets: [require.resolve('@kbn/babel-preset/node_preset')], extensions: ['.js', '.ts', '.tsx'], From 5a372055086451bd630734cf9f1fb4db70ce4827 Mon Sep 17 00:00:00 2001 From: Tiago Costa Date: Fri, 15 Oct 2021 02:42:26 +0100 Subject: [PATCH 10/12] chore(NA): removes debug code --- .../lib/babel_register_for_test_plugins.js | 7 ------- src/setup_node_env/dist.js | 1 - 2 files changed, 8 deletions(-) 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 7305b56a222b90..f2d8460e14d8de 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 @@ -11,13 +11,6 @@ const Path = require('path'); const { REPO_ROOT } = require('@kbn/dev-utils'); -// const KIBANA_ROOT = Path.resolve(__dirname, '../../../../../'); - -// console.log(Path.resolve(REPO_ROOT, 'test')); -// console.log(require('fs').realpathSync(Path.resolve(REPO_ROOT, 'test'))); -// console.log(Path.resolve(KIBANA_ROOT, 'test')); -// throw new Error('FAIL CI'); - // modifies all future calls to require() to automatically // compile the required source with babel require('@babel/register')({ diff --git a/src/setup_node_env/dist.js b/src/setup_node_env/dist.js index 7de5d3a4fb1c53..3628a27a7793fd 100644 --- a/src/setup_node_env/dist.js +++ b/src/setup_node_env/dist.js @@ -6,6 +6,5 @@ * Side Public License, v 1. */ -// require('./ensure_node_preserve_symlinks'); require('./no_transpilation_dist'); require('./polyfill'); From 783bdee175a3e54236825a20d8c1fca956d2a53a Mon Sep 17 00:00:00 2001 From: Tiago Costa Date: Fri, 15 Oct 2021 03:19:52 +0100 Subject: [PATCH 11/12] chore(NA): move array definition --- .../lib/babel_register_for_test_plugins.js | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) 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 f2d8460e14d8de..3af38d0a6abc9c 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 @@ -11,19 +11,21 @@ const Path = require('path'); const { REPO_ROOT } = require('@kbn/dev-utils'); +const babelRegisterPaths = [ + 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'), +].map((path) => Fs.realpathSync(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'), - ].map((path) => Fs.realpathSync(path)), + only: babelRegisterPaths, babelrc: false, presets: [require.resolve('@kbn/babel-preset/node_preset')], extensions: ['.js', '.ts', '.tsx'], From 02be1a39b0b3217e931bd9c0a0c9e67208fdc34c Mon Sep 17 00:00:00 2001 From: Tiago Costa Date: Fri, 15 Oct 2021 03:21:52 +0100 Subject: [PATCH 12/12] chore(NA): correctly import fs --- .../lib/babel_register_for_test_plugins.js | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 deletions(-) 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 3af38d0a6abc9c..fcc2b0b0e3ca92 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,26 +6,24 @@ * Side Public License, v 1. */ -const Fs = require('path'); +const Fs = require('fs'); const Path = require('path'); const { REPO_ROOT } = require('@kbn/dev-utils'); -const babelRegisterPaths = [ - 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'), -].map((path) => Fs.realpathSync(path)); - // modifies all future calls to require() to automatically // compile the required source with babel require('@babel/register')({ ignore: [/[\/\\](node_modules|target|dist)[\/\\]/], - only: babelRegisterPaths, + 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'), + ].map((path) => Fs.realpathSync(path)), babelrc: false, presets: [require.resolve('@kbn/babel-preset/node_preset')], extensions: ['.js', '.ts', '.tsx'],