Skip to content

Commit

Permalink
Merge pull request #34492 from dimagi/jls/build_requirejs-reosurce-ve…
Browse files Browse the repository at this point in the history
…rsion-fix

Updated build_requirejs to always update bundle resource hashes
  • Loading branch information
orangejenny authored Apr 23, 2024
2 parents b42b689 + 5831dd0 commit 7e6e095
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions corehq/apps/hqwebapp/management/commands/build_requirejs.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,29 +254,28 @@ def _copy_modules_back_into_corehq(self, config, local_js_dirs):
else:
logger.warning("Could not copy {} to {}".format(os.path.relpath(src), os.path.relpath(dest)))

def _update_resource_hash(self, name, filename):
file_hash = self.get_hash(filename)
def _update_resource_hash(self, name, filename, file_hash=None):
if file_hash is None:
file_hash = self.get_hash(filename)
self.resource_versions[name] = file_hash
return file_hash

# Overwrite source map references. Source maps are accessed on the CDN, so they need the version hash
def _update_source_maps(self, config):
if not self.optimize:
return

logger.info("Updating resource_versions with hashes from newly minified bundles")

for module in config['modules']:
filename = self._staticfiles_path(module['name'] + ".js")
with open(filename, 'r') as fin:
lines = fin.readlines()
with open(filename, 'w') as fout:
for line in lines:
match = re.search(BUNDLE_SOURCE_MAP_PATTERN, line)
if match:
file_hash = self._update_resource_hash(module['name'] + ".js", filename)
line += f'?version={file_hash}'
fout.write(line)
file_hash = self.get_hash(filename)
if self.optimize:
with open(filename, 'r') as fin:
lines = fin.readlines()
with open(filename, 'w') as fout:
for line in lines:
match = re.search(BUNDLE_SOURCE_MAP_PATTERN, line)
if match:
line += f'?version={file_hash}'
fout.write(line)
self._update_resource_hash(module['name'] + ".js", filename, file_hash=file_hash)

def _write_resource_versions(self):
logger.info("Writing out resource_versions.js")
Expand Down

0 comments on commit 7e6e095

Please sign in to comment.