| #!/usr/bin/env python3 | |
| # Copyright 2019 The Chromium OS Authors. All rights reserved. | |
| # Use of this source code is governed by a BSD-style license that can be | |
| # found in the LICENSE file. | |
| """Update our node_modules bundle.""" | |
| import logging | |
| import os | |
| import sys | |
| import libdot | |
| def get_parser(): | |
| """Get a command line parser.""" | |
| parser = libdot.ArgumentParser(description=__doc__) | |
| return parser | |
| def main(argv): | |
| """The main func!""" | |
| parser = get_parser() | |
| _opts = parser.parse_args(argv) | |
| libdot.node_and_npm_setup() | |
| tar = libdot.LIBAPPS_DIR / 'node_modules.tar.xz' | |
| os.chdir(libdot.LIBAPPS_DIR) | |
| libdot.unlink('package-lock.json') | |
| logging.info('Removing modules not listed in package.json') | |
| libdot.npm.run(['prune']) | |
| logging.info('Updating modules from package.json') | |
| libdot.npm.run(['upgrade', '--no-save']) | |
| libdot.pack(tar, ['node_modules'], exclude=[ | |
| 'node_modules/.hash', | |
| 'node_modules/.node/*', | |
| 'node_modules/.bin/node', | |
| 'node_modules/.bin/npm', | |
| 'node_modules/puppeteer/.local-chromium', | |
| ]) | |
| new_hash = libdot.sha256(tar) | |
| final_tar = f'node_modules-{new_hash}.tar.xz' | |
| tar.rename(final_tar) | |
| logging.info( | |
| 'To update the hash, run:\n' | |
| "sed -i \"/^NODE_MODULES_HASH *=/s:=.*:= '%s':\" '%s/node'", | |
| new_hash, libdot.BIN_DIR) | |
| logging.info('To upload the new modules:\ngsutil cp -a public-read %s %s/', | |
| final_tar, libdot.node.NODE_MODULES_GS_URI) | |
| if __name__ == '__main__': | |
| sys.exit(main(sys.argv[1:])) |