node cache: Don't shell out to yarn to get the version.

This can easily be done by just reading the package.json file and
extracting the version value, just like we now do in install-node.
This commit is contained in:
Tim Abbott 2018-12-07 14:43:52 -08:00
parent 630968b632
commit 9423f8e31c
1 changed files with 5 additions and 1 deletions

View File

@ -1,6 +1,7 @@
import os import os
import hashlib import hashlib
import json
if False: if False:
from typing import Optional, List, IO, Tuple, Any from typing import Optional, List, IO, Tuple, Any
@ -17,6 +18,7 @@ if 'TRAVIS' in os.environ:
NODE_MODULES_CACHE_PATH = os.path.join(ZULIP_SRV_PATH, 'zulip-npm-cache') NODE_MODULES_CACHE_PATH = os.path.join(ZULIP_SRV_PATH, 'zulip-npm-cache')
YARN_BIN = os.path.join(ZULIP_SRV_PATH, 'zulip-yarn/bin/yarn') YARN_BIN = os.path.join(ZULIP_SRV_PATH, 'zulip-yarn/bin/yarn')
YARN_PACKAGE_JSON = os.path.join(ZULIP_SRV_PATH, 'zulip-yarn/package.json')
DEFAULT_PRODUCTION = False DEFAULT_PRODUCTION = False
@ -39,7 +41,9 @@ def generate_sha1sum_node_modules(setup_dir=None, production=DEFAULT_PRODUCTION)
if os.path.exists(YARN_LOCK_FILE_PATH): if os.path.exists(YARN_LOCK_FILE_PATH):
# For backwards compatibility, we can't assume yarn.lock exists # For backwards compatibility, we can't assume yarn.lock exists
sha1sum.update(subprocess_text_output(['cat', YARN_LOCK_FILE_PATH]).encode('utf8')) sha1sum.update(subprocess_text_output(['cat', YARN_LOCK_FILE_PATH]).encode('utf8'))
sha1sum.update(subprocess_text_output([YARN_BIN, '--version']).encode('utf8')) with open(YARN_PACKAGE_JSON, "r") as f:
yarn_version = json.loads(f.read())['version']
sha1sum.update(yarn_version.encode("utf8"))
sha1sum.update(subprocess_text_output(['node', '--version']).encode('utf8')) sha1sum.update(subprocess_text_output(['node', '--version']).encode('utf8'))
yarn_args = get_yarn_args(production=production) yarn_args = get_yarn_args(production=production)
sha1sum.update(''.join(sorted(yarn_args)).encode('utf8')) sha1sum.update(''.join(sorted(yarn_args)).encode('utf8'))