From 07d9407f9b508095eb5b8d00eee9ceafc684d117 Mon Sep 17 00:00:00 2001 From: fdcg Date: Tue, 25 Jan 2022 10:44:59 +0100 Subject: [PATCH] #667: devon npm setup ignores a given version (#668) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Bugfix or issue #667 - devon npm setup ignores a given version * constructive review changes * Adaptation to new download process Co-authored-by: fdcg Co-authored-by: Jörg Hohwiller --- .../src/main/resources/scripts/command/npm | 49 ++++++++++++++++--- 1 file changed, 42 insertions(+), 7 deletions(-) diff --git a/scripts/src/main/resources/scripts/command/npm b/scripts/src/main/resources/scripts/command/npm index 180a699ba..450f23bec 100755 --- a/scripts/src/main/resources/scripts/command/npm +++ b/scripts/src/main/resources/scripts/command/npm @@ -16,17 +16,46 @@ source "$(dirname "${0}")"/../functions # $1: optional setup function doSetup() { - if [ ! -x "${NPM_CMD}" ] + local software_version=${NPM_VERSION} + local installed_version + if [ -x "${NPM_CMD}" ] then + installed_version=$(${NPM_CMD} -version) + else doDevonCommand node setup silent - elif [ "${1}" != "silent" ] - then - doEcho "npm is already installed at ${NPM_CMD}" + installed_version=$(${NPM_CMD} -version) fi - if [ -n "${NPM_VERSION}" ] + + if [ -z "${software_version}" ] || [ "${installed_version}" == "${software_version}" ] then - doDevonCommand npm install -g "npm@${NPM_VERSION}" - fi + if [ "${1}" != "silent" ] + then + doEcho "Version ${installed_version} of npm is already installed at ${NPM_CMD}" + fi + else + local software_dir="${NODE_HOME}/node_modules/npm" + doInstall "-" "${software_dir}" "npm" "${software_version}" + if [ -f "${NODE_HOME}/npm" ] + then + rm "${NODE_HOME}/npm" + fi + if [ -f "${NODE_HOME}/npm.cmd" ] + then + rm "${NODE_HOME}/npm.cmd" + fi + if [ -f "${NODE_HOME}/npx" ] + then + rm "${NODE_HOME}/npx" + fi + if [ -f "${NODE_HOME}/npx.cmd" ] + then + rm "${NODE_HOME}/npx.cmd" + fi + cp "${software_dir}/bin/npm" "${NODE_HOME}" + cp "${software_dir}/bin/npm.cmd" "${NODE_HOME}" + cp "${software_dir}/bin/npx" "${NODE_HOME}" + cp "${software_dir}/bin/npx.cmd" "${NODE_HOME}" + fi } function doGetProjectVersion() { @@ -96,6 +125,12 @@ then echo "Options:" exit fi + +if [ -z "${NODE_HOME}" ] +then + NODE_HOME="${DEVON_IDE_HOME}/software/node" +fi + NPM_CMD="${DEVON_IDE_HOME}/software/node/npm" if [ ! -x "${NPM_CMD}" ] then