node_cache.py: Modify `generate_sha1sum_node_modules()`.

Modify `generate_sha1sum_node_modules()` such that it can calculate
the hash for a particular installation.

Tweaked by tabbott to use os.path.realpath in the setup_dir
calculation, to ensure it's consistent.
This commit is contained in:
Harshit Bansal 2017-08-19 09:06:45 +00:00 committed by Tim Abbott
parent 8aadbc258d
commit 8e41bbe2b0
1 changed files with 9 additions and 6 deletions

View File

@ -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,