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

[Backport 2.x] Allow selecting the Node.js binary OSD uses #3637

Merged
merged 2 commits into from
Mar 23, 2023
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- Introduce @opensearch-project/opensearch@^2.1.0, aliased as @opensearch-project/opensearch-next ([#3469](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/3469))
- Relax the Node.js requirement to `^14.20.1` ([3463](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/3463))
- Bump the version of Node.js installed by `nvm` to `14.21.3` ([3463](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/3463))
- Allow selecting the Node.js binary using `NODE_HOME` and `OSD_NODE_HOME` ([3508](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/3508))

### 🪛 Refactoring

Expand Down
64 changes: 32 additions & 32 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,42 +37,42 @@
},
"author": "opensearch-project",
"scripts": {
"preinstall": "node ./preinstall_check",
"osd": "node scripts/osd",
"opensearch": "node scripts/opensearch",
"preinstall": "scripts/use_node ./preinstall_check",
"osd": "scripts/use_node scripts/osd",
"opensearch": "scripts/use_node scripts/opensearch",
"test": "grunt test",
"test:bwc": "./scripts/bwctest_osd.sh",
"test:jest": "node scripts/jest",
"test:jest:coverage": "node scripts/jest --coverage",
"test:jest:ci": "node scripts/jest --ci --colors --runInBand",
"test:jest:ci:coverage": "node scripts/jest --ci --colors --runInBand --coverage",
"test:jest_integration": "node scripts/jest_integration",
"test:jest_integration:ci": "node scripts/jest_integration --ci --colors --max-old-space-size=5120",
"test:mocha": "node scripts/mocha",
"test:mocha:coverage": "yarn nyc --reporter=text-summary --reporter=lcov --report-dir=./target/opensearch-dashboards-coverage/mocha node scripts/mocha",
"test:ftr": "node scripts/functional_tests",
"test:ftr:server": "node scripts/functional_tests_server",
"test:ftr:runner": "node scripts/functional_test_runner",
"checkLicenses": "node scripts/check_licenses --dev",
"notice:validate": "node scripts/notice --validate",
"notice:generate": "node scripts/notice",
"build-platform": "node scripts/build",
"build": "node scripts/build --all-platforms",
"start": "node scripts/opensearch_dashboards --dev",
"start:docker": "node scripts/opensearch_dashboards --dev --opensearch.hosts=$OPENSEARCH_HOSTS --opensearch.ignoreVersionMismatch=true --server.host=$SERVER_HOST",
"debug": "node --nolazy --inspect scripts/opensearch_dashboards --dev",
"debug-break": "node --nolazy --inspect-brk scripts/opensearch_dashboards --dev",
"test:jest": "scripts/use_node scripts/jest",
"test:jest:coverage": "scripts/use_node scripts/jest --coverage",
"test:jest:ci": "scripts/use_node scripts/jest --ci --colors --runInBand",
"test:jest:ci:coverage": "scripts/use_node scripts/jest --ci --colors --runInBand --coverage",
"test:jest_integration": "scripts/use_node scripts/jest_integration",
"test:jest_integration:ci": "scripts/use_node scripts/jest_integration --ci --colors --max-old-space-size=5120",
"test:mocha": "scripts/use_node scripts/mocha",
"test:mocha:coverage": "yarn nyc --reporter=text-summary --reporter=lcov --report-dir=./target/opensearch-dashboards-coverage/mocha scripts/use_node scripts/mocha",
"test:ftr": "scripts/use_node scripts/functional_tests",
"test:ftr:server": "scripts/use_node scripts/functional_tests_server",
"test:ftr:runner": "scripts/use_node scripts/functional_test_runner",
"checkLicenses": "scripts/use_node scripts/check_licenses --dev",
"notice:validate": "scripts/use_node scripts/notice --validate",
"notice:generate": "scripts/use_node scripts/notice",
"build-platform": "scripts/use_node scripts/build",
"build": "scripts/use_node scripts/build --all-platforms",
"start": "scripts/use_node scripts/opensearch_dashboards --dev",
"start:docker": "scripts/use_node scripts/opensearch_dashboards --dev --opensearch.hosts=$OPENSEARCH_HOSTS --opensearch.ignoreVersionMismatch=true --server.host=$SERVER_HOST",
"debug": "scripts/use_node --nolazy --inspect scripts/opensearch_dashboards --dev",
"debug-break": "scripts/use_node --nolazy --inspect-brk scripts/opensearch_dashboards --dev",
"lint": "yarn run lint:es && yarn run lint:style",
"lint:es": "node scripts/eslint",
"lint:style": "node scripts/stylelint",
"makelogs": "node scripts/makelogs",
"lint:es": "scripts/use_node scripts/eslint",
"lint:style": "scripts/use_node scripts/stylelint",
"makelogs": "scripts/use_node scripts/makelogs",
"uiFramework:compileCss": "cd packages/osd-ui-framework && yarn compileCss",
"osd:watch": "node scripts/opensearch_dashboards --dev --logging.json=false",
"build:types": "node scripts/remove.js ./target/types && tsc --p tsconfig.types.json",
"docs:acceptApiChanges": "node --max-old-space-size=6144 scripts/check_published_api_changes.js --accept",
"osd:bootstrap": "node scripts/build_ts_refs && node scripts/register_git_hook",
"spec_to_console": "node scripts/spec_to_console",
"pkg-version": "node -e \"console.log(require('./package.json').version)\""
"osd:watch": "scripts/use_node scripts/opensearch_dashboards --dev --logging.json=false",
"build:types": "scripts/use_node scripts/remove.js ./target/types && tsc --p tsconfig.types.json",
"docs:acceptApiChanges": "scripts/use_node --max-old-space-size=6144 scripts/check_published_api_changes.js --accept",
"osd:bootstrap": "scripts/use_node scripts/build_ts_refs && scripts/use_node scripts/register_git_hook",
"spec_to_console": "scripts/use_node scripts/spec_to_console",
"pkg-version": "scripts/use_node -e \"console.log(require('./package.json').version)\""
},
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion packages/osd-ace/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "./target/index.js",
"license": "Apache-2.0",
"scripts": {
"build": "node ./scripts/build.js",
"build": "../../scripts/use_node ./scripts/build.js",
"osd:bootstrap": "yarn build --dev"
},
"dependencies": {
Expand Down
6 changes: 3 additions & 3 deletions packages/osd-analytics/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
"author": "Ahmad Bamieh <ahmadbamieh@gmail.com>",
"license": "Apache-2.0",
"scripts": {
"build": "node scripts/build",
"osd:bootstrap": "node scripts/build --source-maps",
"osd:watch": "node scripts/build --source-maps --watch"
"build": "../../scripts/use_node scripts/build",
"osd:bootstrap": "../../scripts/use_node scripts/build --source-maps",
"osd:watch": "../../scripts/use_node scripts/build --source-maps --watch"
},
"devDependencies": {
"@babel/cli": "^7.16.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/osd-dev-utils/src/precommit_hook/script_source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ set -euo pipefail
trap "exit 130" INT

has_node() {
command -v node >/dev/null 2>&1
command -v scripts/use_node >/dev/null 2>&1
}

has_nvm() {
Expand Down Expand Up @@ -109,7 +109,7 @@ has_node || {
}

execute_precommit_hook() {
node scripts/precommit_hook || return 1
scripts/use_node scripts/precommit_hook || return 1

PRECOMMIT_FILE="./.git/hooks/pre-commit.local"
if [ -x "\${PRECOMMIT_FILE}" ]; then
Expand Down
6 changes: 3 additions & 3 deletions packages/osd-i18n/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
"license": "Apache-2.0",
"private": true,
"scripts": {
"build": "node scripts/build",
"osd:bootstrap": "node scripts/build --source-maps",
"osd:watch": "node scripts/build --watch --source-maps"
"build": "../../scripts/use_node scripts/build",
"osd:bootstrap": "../../scripts/use_node scripts/build --source-maps",
"osd:watch": "../../scripts/use_node scripts/build --watch --source-maps"
},
"devDependencies": {
"@babel/cli": "^7.16.0",
Expand Down
6 changes: 3 additions & 3 deletions packages/osd-interpreter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
"license": "Apache-2.0",
"scripts": {
"interpreter:peg": "pegjs src/common/lib/grammar.peg",
"build": "node scripts/build",
"osd:bootstrap": "node scripts/build --dev",
"osd:watch": "node scripts/build --dev --watch"
"build": "../../scripts/use_node scripts/build",
"osd:bootstrap": "../../scripts/use_node scripts/build --dev",
"osd:watch": "../../scripts/use_node scripts/build --dev --watch"
},
"dependencies": {
"@babel/runtime": "^7.16.5",
Expand Down
2 changes: 1 addition & 1 deletion packages/osd-monaco/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "./target/index.js",
"license": "Apache-2.0",
"scripts": {
"build": "node ./scripts/build.js",
"build": "../../scripts/use_node ./scripts/build.js",
"osd:bootstrap": "yarn build --dev"
},
"dependencies": {
Expand Down
4 changes: 2 additions & 2 deletions packages/osd-opensearch-archiver/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
"devOnly": true
},
"scripts": {
"osd:bootstrap": "node ../../scripts/remove.js target && tsc",
"osd:watch": "node ../../scripts/remove.js target && tsc --watch"
"osd:bootstrap": "../../scripts/use_node ../../scripts/remove.js target && tsc",
"osd:watch": "../../scripts/use_node ../../scripts/remove.js target && tsc --watch"
},
"dependencies": {
"@osd/dev-utils": "1.0.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/osd-opensearch/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"devOnly": true
},
"scripts": {
"osd:bootstrap": "node scripts/build",
"osd:watch": "node scripts/build --watch"
"osd:bootstrap": "../../scripts/use_node scripts/build",
"osd:watch": "../../scripts/use_node scripts/build --watch"
},
"dependencies": {
"@opensearch-project/opensearch": "^1.1.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/osd-plugin-generator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"license": "Apache-2.0",
"main": "target/index.js",
"scripts": {
"osd:bootstrap": "node scripts/build",
"osd:watch": "node scripts/build --watch"
"osd:bootstrap": "../../scripts/use_node scripts/build",
"osd:watch": "../../scripts/use_node scripts/build --watch"
},
"dependencies": {
"@osd/cross-platform": "1.0.0",
Expand Down
6 changes: 3 additions & 3 deletions packages/osd-plugin-generator/template/package.json.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"private": true,
"scripts": {
"build": "yarn plugin-helpers build",
"plugin-helpers": "node ../../scripts/plugin_helpers",
"osd": "node ../../scripts/osd"
"plugin-helpers": "../../scripts/use_node ../../scripts/plugin_helpers",
"osd": "../../scripts/use_node ../../scripts/osd"
}
}
}
2 changes: 1 addition & 1 deletion packages/osd-plugin-helpers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"plugin-helpers": "bin/plugin-helpers.js"
},
"scripts": {
"osd:bootstrap": "node ../../scripts/remove.js target && tsc",
"osd:bootstrap": "../../scripts/use_node ../../scripts/remove.js target && tsc",
"osd:watch": "tsc --watch"
},
"dependencies": {
Expand Down
6 changes: 3 additions & 3 deletions packages/osd-ui-shared-deps/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
"private": true,
"license": "Apache-2.0",
"scripts": {
"build": "node scripts/build",
"osd:bootstrap": "node scripts/build --dev",
"osd:watch": "node scripts/build --dev --watch"
"build": "../../scripts/use_node scripts/build",
"osd:bootstrap": "../../scripts/use_node scripts/build --dev",
"osd:watch": "../../scripts/use_node scripts/build --dev --watch"
},
"dependencies": {
"@elastic/charts": "31.1.0",
Expand Down
97 changes: 97 additions & 0 deletions scripts/use_node
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
#!/bin/sh

#
# SPDX-License-Identifier: Apache-2.0
#
# The OpenSearch Contributors require contributions made to
# this file be licensed under the Apache-2.0 license or a
# compatible open source license.
#
# Any modifications Copyright OpenSearch Contributors. See
# GitHub history for details.
#

# This script will find the appropriate Node.js runtime binary and execute it with any
# parameters passed in.
#
# Set a variable named OSD_USE_NODE_JS_FILE_PATH to have it prefixed with OSD_HOME and executed
# Example: SET OSD_USE_NODE_JS_FILE_PATH=\src\cli\dist
#
# NODE_OPTIONS is built using config/node.options and overridden by any previously set NODE_OPTIONS.
# To pass in any specific defaults that can be overridden by both of them, use OSD_NODE_OPTS_PREFIX.

SCRIPT="$0"

UNAME=$(uname -s)
if [ $UNAME = "FreeBSD" ]; then
OS="freebsd"
elif [ $UNAME = "Darwin" ]; then
OS="darwin"
else
OS="other"
fi

# SCRIPT may be an arbitrarily deep series of symlinks. Loop until we have the concrete path.
while [ -h "$SCRIPT" ] ; do
loc=$(ls -ld "$SCRIPT")
# Drop everything prior to ->
link=$(expr "$loc" : '.*-> \(.*\)$')
if expr "$link" : '/.*' > /dev/null; then
SCRIPT="$link"
else
SCRIPT=$(dirname "$SCRIPT")/"$link"
fi
done

# Get an absolute path for OSD_HOME
OSD_HOME="$(cd "$(dirname "${SCRIPT}")/.."; pwd)"
CONFIG_DIR=${OSD_PATH_CONF:-"OSD_HOME/config"}

# Places to look for the Node.js binary in order: OSD_NODE_HOME > NODE_HOME > bundled with OSD > system-wide
if [ ! -z "$OSD_NODE_HOME" ]; then
NODE="$OSD_NODE_HOME/bin/node"
NODE_ERROR_MSG="in OSD_NODE_HOME"
NODE_ERROR_SHOW=true
elif [ ! -z "$NODE_HOME" ]; then
NODE="$NODE_HOME/bin/node"
NODE_ERROR_MSG="in NODE_HOME"
NODE_ERROR_SHOW=true
else
NODE="$OSD_HOME/node/bin/node"
NODE_ERROR_MSG="bundled with OpenSearch Dashboards"
# A bin folder at the root is only present in release builds that have a bundled Node.js binary
if [ -x "OSD_HOME/bin" ]; then
NODE_ERROR_SHOW=true
fi
fi

if [ -x "$NODE" ]; then
# Node.js binary was found where it was expected; no need to show an error
NODE_ERROR_SHOW=
elif [ $OS = "freebsd" ]; then
NODE="${LOCALBASE}/bin/node"
else
NODE="$(command -v node)"
fi

if [ ! -x "$NODE" ]; then
# Irrespective of NODE_ERROR_SHOW, show the error
echo "Could not find a Node.js runtime binary $NODE_ERROR_MSG or on the system" >&2
exit 1
fi

# Node.js binary was found but not where it was told to be, so show a warning
if [ ! -z "$NODE_ERROR_SHOW" ]; then
echo "Could not find a Node.js runtime binary $NODE_ERROR_MSG but found one at $NODE" >&2
fi

if [ -f "${CONFIG_DIR}/node.options" ]; then
OSD_NODE_OPTS="$(grep -v ^# < ${CONFIG_DIR}/node.options | xargs)"
fi

# If a file path was provided for execution, prefix with OSD_HOME; use relative paths to avoid the need for this.
if [ ! -z "$OSD_USE_NODE_JS_FILE_PATH" ]; then
NODE_OPTIONS="$OSD_NODE_OPTS_PREFIX $OSD_NODE_OPTS $NODE_OPTIONS" "${NODE}" "${OSD_HOME}${OSD_USE_NODE_JS_FILE_PATH}" "${@}"
elif [ $# -ne 0 ]; then
NODE_OPTIONS="$OSD_NODE_OPTS_PREFIX $OSD_NODE_OPTS $NODE_OPTIONS" "${NODE}" "${@}"
fi
Loading