diff --git a/scripts/lib/node_cache.py b/scripts/lib/node_cache.py index 3c189940c6..b58fb80a75 100644 --- a/scripts/lib/node_cache.py +++ b/scripts/lib/node_cache.py @@ -5,7 +5,7 @@ import hashlib from os.path import dirname, abspath if False: - from typing import Optional, List, IO, Tuple, Any + from typing import Optional, List, IO, Text, Tuple, Any from scripts.lib.zulip_tools import subprocess_text_output, run @@ -30,16 +30,19 @@ def get_yarn_args(production): yarn_args = [] return yarn_args -def generate_sha1sum_node_modules(production=DEFAULT_PRODUCTION): - # type: (bool) -> str +def generate_sha1sum_node_modules(setup_dir=None, production=DEFAULT_PRODUCTION): + # type: (Optional[Text], bool) -> str + if setup_dir is None: + setup_dir = os.path.realpath(os.getcwd()) + PACKAGE_JSON_FILE_PATH = os.path.join(setup_dir, 'package.json') + YARN_LOCK_FILE_PATH = os.path.join(setup_dir, 'yarn.lock') sha1sum = hashlib.sha1() - sha1sum.update(subprocess_text_output(['cat', 'package.json']).encode('utf8')) - sha1sum.update(subprocess_text_output(['cat', 'yarn.lock']).encode('utf8')) + sha1sum.update(subprocess_text_output(['cat', PACKAGE_JSON_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')) sha1sum.update(subprocess_text_output(['node', '--version']).encode('utf8')) yarn_args = get_yarn_args(production=production) sha1sum.update(''.join(sorted(yarn_args)).encode('utf8')) - return sha1sum.hexdigest() def setup_node_modules(production=DEFAULT_PRODUCTION, stdout=None, stderr=None, copy_modules=False,