Skip to content

Commit

Permalink
fix(NA): support inspect flags on ensure_node_preserve_symlinks script (
Browse files Browse the repository at this point in the history
#95344)

* fix(NA): support inspect flags on ensure_node_preserve_symlinks script

* chore(NA): fix wording on function test runner schema file

* chore(NA): update execargv array in case of --inspect port
  • Loading branch information
mistic authored Mar 25, 2021
1 parent 49078c8 commit a7ac120
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import Joi from 'joi';
// valid pattern for ID
// enforced camel-case identifiers for consistency
const ID_PATTERN = /^[a-zA-Z0-9_]+$/;
const INSPECTING =
process.execArgv.includes('--inspect') || process.execArgv.includes('--inspect-brk');
// it will search both --inspect and --inspect-brk
const INSPECTING = !!process.execArgv.find((arg) => arg.includes('--inspect'));

const urlPartsSchema = () =>
Joi.object()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,11 @@ function collectCliArgs(config, { installDir, extraKbnOpts }) {
const buildArgs = config.get('kbnTestServer.buildArgs') || [];
const sourceArgs = config.get('kbnTestServer.sourceArgs') || [];
const serverArgs = config.get('kbnTestServer.serverArgs') || [];
const execArgv = process.execArgv || [];

return pipe(
serverArgs,
(args) => (installDir ? args.filter((a) => a !== '--oss') : args),
(args) =>
installDir
? [...buildArgs, ...args]
: [...execArgv, KIBANA_EXEC_PATH, ...sourceArgs, ...args],
(args) => (installDir ? [...buildArgs, ...args] : [KIBANA_EXEC_PATH, ...sourceArgs, ...args]),
(args) => args.concat(extraKbnOpts || [])
);
}
Expand Down
43 changes: 42 additions & 1 deletion src/setup_node_env/ensure_node_preserve_symlinks.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,51 @@
(function () {
var cp = require('child_process');

var calculateInspectPortOnExecArgv = function (processExecArgv) {
var execArgv = [].concat(processExecArgv);

if (execArgv.length === 0) {
return execArgv;
}

var inspectFlagIndex = execArgv.reverse().findIndex(function (flag) {
return flag.startsWith('--inspect');
});

if (inspectFlagIndex !== -1) {
var inspectFlag;
var inspectPortCounter = 9230;
var argv = execArgv[inspectFlagIndex];

if (argv.includes('=')) {
// --inspect=port
var argvSplit = argv.split('=');
var flag = argvSplit[0];
var port = argvSplit[1];
inspectFlag = flag;
inspectPortCounter = Number.parseInt(port, 10) + 1;
} else {
// --inspect
inspectFlag = argv;

// is number?
if (String(execArgv[inspectFlagIndex + 1]).match(/^[0-9]+$/)) {
// --inspect port
inspectPortCounter = Number.parseInt(execArgv[inspectFlagIndex + 1], 10) + 1;
execArgv.slice(inspectFlagIndex + 1, 1);
}
}

execArgv[inspectFlagIndex] = inspectFlag + '=' + inspectPortCounter;
}

return execArgv;
};

var preserveSymlinksOption = '--preserve-symlinks';
var preserveSymlinksMainOption = '--preserve-symlinks-main';
var nodeOptions = (process && process.env && process.env.NODE_OPTIONS) || [];
var nodeExecArgv = (process && process.execArgv) || [];
var nodeExecArgv = calculateInspectPortOnExecArgv((process && process.execArgv) || []);

var isPreserveSymlinksPresent =
nodeOptions.includes(preserveSymlinksOption) || nodeExecArgv.includes(preserveSymlinksOption);
Expand Down

0 comments on commit a7ac120

Please sign in to comment.