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

chore: use XTRANSIT_NODE_EXE to get exe #55

Merged
merged 2 commits into from
Sep 21, 2024
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
2 changes: 1 addition & 1 deletion commands/check_process_status.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ async function checkInstalled(nodeExe, cwd) {
}

async function checkStatus() {
const nodeExe = process.env.XTRANSIT_NODE_EXE || await getNodeExe(pid);
const nodeExe = await getNodeExe(pid);
status.nodeVersion = await execute(`${nodeExe} -v`);
status.alinodeVersion = await execute(`${nodeExe} -V`);

Expand Down
2 changes: 1 addition & 1 deletion commands/xprofctl.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ async function takeAction() {
// hanle coredump
if (command === 'generate_coredump') {
data.type = 'core';
const nodepath = process.env.XTRANSIT_NODE_EXE || await realpath(await getNodeExe(process.pid, false));
const nodepath = await realpath(await getNodeExe(process.pid, false));
data.executable_path = nodepath;
data.node_version = process.versions.node;
data.alinode_version = process.versions.alinode;
Expand Down
3 changes: 3 additions & 0 deletions common/exe.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ const utils = require('../common/utils');
const platform = os.platform();

module.exports = async (pid, stringify = true) => {
if (process.env.XTRANSIT_NODE_EXE) {
return process.env.XTRANSIT_NODE_EXE;
}
let nodeExe = 'node';

/* istanbul ignore next */
Expand Down
3 changes: 3 additions & 0 deletions lib/agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ class XtransitAgent extends EventEmitter {
this.filterProcessEnvName = config.filterProcessEnvName;
this.customXprofilerLogs = config.customXprofilerLogs;
this.nodeExe = config.nodeExe;
if (this.nodeExe) {
process.env.XTRANSIT_NODE_EXE = this.nodeExe;
}

// global var
this.conn = null;
Expand Down
8 changes: 1 addition & 7 deletions lib/handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,7 @@ module.exports = async function(message, options) {
};

// exec command
let nodeExe;
if (this.config && this.config.nodeExe) {
nodeExe = this.config.nodeExe;
execOptions.env.XTRANSIT_NODE_EXE = this.config.nodeExe;
} else {
nodeExe = await getNodeExe(process.pid, false);
}
const nodeExe = await getNodeExe(process.pid, false);
this.logger.debug(`[execute command] ${nodeExe} ${args.join(' ')}`);
const aExecFile = options && options.execFile || execFile;
const { stdout, stderr: error } = await aExecFile(nodeExe, args, execOptions);
Expand Down
5 changes: 4 additions & 1 deletion test/config.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ function getError(config) {
}

describe('get config', function() {
afterEach(mm.restore);
afterEach(() => {
mm.restore();
delete process.env.XTRANSIT_NODE_EXE;
});

it('should throw error', function() {
expect(getError({})).to.be('config.server must be passed in!');
Expand Down
Loading