Skip to content

Commit

Permalink
chore: use XTRANSIT_NODE_EXE to get exe (#55)
Browse files Browse the repository at this point in the history
* chore: use XTRANSIT_NODE_EXE to get exe
  • Loading branch information
killagu authored Sep 21, 2024
1 parent 987c7b5 commit 3f3b246
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 10 deletions.
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

0 comments on commit 3f3b246

Please sign in to comment.