Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(NA): support inspect flags on ensure_node_preserve_symlinks script #95344

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
spalger marked this conversation as resolved.
Show resolved Hide resolved
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