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

Bugfix for issue #667 - devon npm setup ignores a given version #668

Merged
merged 4 commits into from
Jan 25, 2022
Merged
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
49 changes: 42 additions & 7 deletions scripts/src/main/resources/scripts/command/npm
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Comment on lines +38 to +57
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of removing and copying, I would prefer to create symlinks but due to windows limitations this does not seem to be an option. So I think there is no better solution than yours here that should always work (KISS).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the record: the current approach could fail on Windows if a npm.cmd is currently running in parallel due to file locking.

fi
}

function doGetProjectVersion() {
Expand Down Expand Up @@ -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
Expand Down