mirror of
https://github.com/zulip/zulip.git
synced 2025-11-06 15:03:34 +00:00
provision: Use NVM to install node and npm.
NVM takes a specific node version and installs the node package and a corresponding compatible npm package. We use it in a somewhat hackish way to install node/npm globally with a pinned version, since that's how we actually want to consume node in our development environment. Other details: - Travis CI now is configured to use the version of node installed by provision; the easiest way to do this was to sabotage the existing node installation. - jsdom is upgraded to a current version, which both requires recent node and also is required for the tests to pass with recent node. This fixes running the node tests on Xenial. Fixes #1498. [tweaked by tabbott]
This commit is contained in:
@@ -25,10 +25,8 @@ SUPPORTED_PLATFORMS = {
|
||||
],
|
||||
}
|
||||
|
||||
NPM_VERSION = '3.9.3'
|
||||
PY2_VENV_PATH = "/srv/zulip-venv"
|
||||
PY3_VENV_PATH = "/srv/zulip-py3-venv"
|
||||
TRAVIS_NODE_PATH = os.path.join(os.environ['HOME'], 'node')
|
||||
VAR_DIR_PATH = os.path.join(ZULIP_PATH, 'var')
|
||||
LOG_DIR_PATH = os.path.join(VAR_DIR_PATH, 'log')
|
||||
UPLOAD_DIR_PATH = os.path.join(VAR_DIR_PATH, 'uploads')
|
||||
@@ -81,11 +79,9 @@ UBUNTU_COMMON_APT_DEPENDENCIES = [
|
||||
"rabbitmq-server",
|
||||
"redis-server",
|
||||
"hunspell-en-us",
|
||||
"nodejs",
|
||||
"nodejs-legacy",
|
||||
"supervisor",
|
||||
"git",
|
||||
"npm",
|
||||
"libssl-dev",
|
||||
"yui-compressor",
|
||||
"wget",
|
||||
"ca-certificates", # Explicit dependency in case e.g. wget is already installed
|
||||
@@ -120,29 +116,6 @@ REPO_STOPWORDS_PATH = os.path.join(
|
||||
|
||||
LOUD = dict(_out=sys.stdout, _err=sys.stderr)
|
||||
|
||||
def install_npm():
|
||||
# type: () -> None
|
||||
if not TRAVIS:
|
||||
if subprocess_text_output(['npm', '--version']) != NPM_VERSION:
|
||||
run(["sudo", "npm", "install", "-g", "npm@{}".format(NPM_VERSION)])
|
||||
|
||||
return
|
||||
|
||||
run(['mkdir', '-p', TRAVIS_NODE_PATH])
|
||||
|
||||
npm_exe = os.path.join(TRAVIS_NODE_PATH, 'bin', 'npm')
|
||||
travis_npm = subprocess_text_output(['which', 'npm'])
|
||||
if os.path.exists(npm_exe):
|
||||
run(['sudo', 'ln', '-sf', npm_exe, travis_npm])
|
||||
|
||||
version = subprocess_text_output(['npm', '--version'])
|
||||
if os.path.exists(npm_exe) and version == NPM_VERSION:
|
||||
print("Using cached npm")
|
||||
return
|
||||
|
||||
run(["npm", "install", "-g", "--prefix", TRAVIS_NODE_PATH, "npm@{}".format(NPM_VERSION)])
|
||||
run(['sudo', 'ln', '-sf', npm_exe, travis_npm])
|
||||
|
||||
|
||||
def main():
|
||||
# type: () -> int
|
||||
@@ -224,10 +197,12 @@ def main():
|
||||
run(["tools/setup/postgres-init-test-db"])
|
||||
run(["tools/do-destroy-rebuild-test-database"])
|
||||
run(["python", "./manage.py", "compilemessages"])
|
||||
# Install the pinned version of npm.
|
||||
install_npm()
|
||||
# Run npm install last because it can be flaky, and that way one
|
||||
# only needs to rerun `npm install` to fix the installation.
|
||||
|
||||
# Here we install nvm, node, and npm.
|
||||
run(["sudo", "tools/setup/install-node"])
|
||||
|
||||
# This is a wrapper around `npm install`, which we run last since
|
||||
# it can often fail due to network issues beyond our control.
|
||||
try:
|
||||
setup_node_modules()
|
||||
except subprocess.CalledProcessError:
|
||||
|
||||
Reference in New Issue
Block a user