Skip to content

Commit

Permalink
Adding Support for OSD_NODE_HOME
Browse files Browse the repository at this point in the history
Signed-off-by: AbhishekReddy1127 <[email protected]>
  • Loading branch information
AbhishekReddy1127 committed Aug 29, 2022
1 parent 730a75a commit 75b3ca8
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 36 deletions.
12 changes: 8 additions & 4 deletions src/dev/build/tasks/bin/scripts/opensearch-dashboards
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,14 @@ done
DIR="$(dirname "${SCRIPT}")/.."
CONFIG_DIR=${OSD_PATH_CONF:-"$DIR/config"}

if [ -x "${DIR}/node/bin/node" ]; then
NODE="${DIR}/node/bin/node"
else
NODE="$(which node)"
NODE="$OSD_NODE_HOME"

if [ -z "$NODE" ]; then
if [ -x "${DIR}/node/bin/node" ]; then
NODE="${DIR}/node/bin/node"
else
NODE="$(which node)"
fi
fi

if [ ! -x "$NODE" ]; then
Expand Down
19 changes: 12 additions & 7 deletions src/setup_node_env/node_version_validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,16 @@ var isVersionValid =

// Validates current the NodeJS version compatibility when OpenSearch Dashboards starts.
if (!isVersionValid) {
var errorMessage =
`OpenSearch Dashboards was built with ${requiredVersion} and does not support the current Node.js version ${currentVersion}. ` +
`Please use Node.js ${requiredVersion} or a higher patch version.`;

// Actions to apply when validation fails: error report + exit.
console.error(errorMessage);
process.exit(1);
var errorMessage = `OpenSearch Dashboards was built with ${requiredVersion} and does not support the current Node.js version ${currentVersion}. `;
if (!process.env.OSD_NODE_HOME) {
// Actions to apply when validation fails: error report + exit.
errorMessage += `Please use Node.js ${requiredVersion} or a higher patch version.`;
console.error(errorMessage);
process.exit(1);
} else {
errorMessage +=
'\nOpenSearch Dashboards is running as OSD_NODE_HOME environment variable is set, ' +
'Ignoring any incpatibilities in node version.';
console.warn(errorMessage);
}
}
52 changes: 27 additions & 25 deletions src/setup_node_env/node_version_validator.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,31 +51,33 @@ describe('NodeVersionValidator', function () {
);
});

it('should run the script WITH error if the major version is higher', function (done) {
testValidateNodeVersion(done, requiredNodeVersionWithDiff(+1, 0, 0), true);
});

it('should run the script WITH error if the major version is lower', function (done) {
var lowerMajorVersion = requiredNodeVersionWithDiff(-1, 0, 0);
testValidateNodeVersion(
done,
lowerMajorVersion,
REQUIRED_NODE_JS_VERSION !== lowerMajorVersion
);
});

it('should run the script WITH error if the minor version is higher', function (done) {
testValidateNodeVersion(done, requiredNodeVersionWithDiff(0, +1, 0), true);
});

it('should run the script WITH error if the minor version is lower', function (done) {
var lowerMinorVersion = requiredNodeVersionWithDiff(0, -1, 0);
testValidateNodeVersion(
done,
lowerMinorVersion,
REQUIRED_NODE_JS_VERSION !== lowerMinorVersion
);
});
if (!process.env.OSD_NODE_HOME) {
it('should run the script WITH error if the major version is higher', function (done) {
testValidateNodeVersion(done, requiredNodeVersionWithDiff(+1, 0, 0), true);
});

it('should run the script WITH error if the major version is lower', function (done) {
var lowerMajorVersion = requiredNodeVersionWithDiff(-1, 0, 0);
testValidateNodeVersion(
done,
lowerMajorVersion,
REQUIRED_NODE_JS_VERSION !== lowerMajorVersion
);
});

it('should run the script WITH error if the minor version is higher', function (done) {
testValidateNodeVersion(done, requiredNodeVersionWithDiff(0, +1, 0), true);
});

it('should run the script WITH error if the minor version is lower', function (done) {
var lowerMinorVersion = requiredNodeVersionWithDiff(0, -1, 0);
testValidateNodeVersion(
done,
lowerMinorVersion,
REQUIRED_NODE_JS_VERSION !== lowerMinorVersion
);
});
}
});

function requiredNodeVersionWithDiff(majorDiff, minorDiff, patchDiff) {
Expand Down

0 comments on commit 75b3ca8

Please sign in to comment.