update_npm_deps 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #!/bin/bash
  2. # Copyright 2017 The Chromium Authors. All rights reserved.
  3. # Use of this source code is governed by a BSD-style license that can be
  4. # found in the LICENSE file.
  5. # Script for updating WebUI's NPM deps.
  6. # 1) Update package.json file to point to the desired version.
  7. # 2) Run this script.
  8. # 3) Upload the compressed node_modules.tar.gz file to the Google Storage
  9. # bucket (commands to upload binaries are printed at step 2).
  10. # 4) Land a CL with the changes generated by this script.
  11. set -eu
  12. cd "$(dirname "$0")"
  13. rm -rf node_modules
  14. npm install --no-bin-links --only=prod
  15. # Apply local patch to polymer-bundler.
  16. patch -d node_modules/polymer-bundler/ -p1 < chromium_polymer_bundler.patch
  17. # Apply local patch to d3.
  18. patch -d node_modules/@types/d3/ -p1 < chromium_d3_types_index.patch
  19. # Apply local patch to html-minifier
  20. patch -d node_modules/html-minifier/ -p1 < html_minifier.patch
  21. rsync -c --delete -r -q --include-from="npm_include.txt" --exclude-from="npm_exclude.txt" \
  22. --prune-empty-dirs "node_modules/" "node_modules_filtered/"
  23. # `npm install` leaves a bunch of local paths in _where and _args.
  24. # This is undesired. See: https://github.com/npm/npm/issues/10393
  25. python clean_json_attrs.py --attr_pattern="^_" --file_pattern="^package\.json$" "node_modules_filtered/"
  26. echo -e "\n---------------------------------------------------------"
  27. echo "Before filtering:" size: $(du -h node_modules/ | tail -n1 | cut -f1) ", files: " $(find node_modules/ -type f | wc -l)
  28. rm -r node_modules
  29. mv node_modules_filtered node_modules
  30. echo "After filtering:" size: $(du -h node_modules/ | tail -n1 | cut -f1) ", files: " $(find node_modules/ -type f | wc -l)
  31. tar cfz node_modules.tar.gz node_modules
  32. echo "After compressing:" size: $(du -h node_modules.tar.gz | tail -n1 | cut -f1)
  33. sha1="$(sha1sum node_modules.tar.gz | cut -d ' ' -f1)"
  34. echo "${sha1}" > node_modules.tar.gz.sha1
  35. echo "Please run the following manually to update Google Storage bucket:"
  36. echo "> gsutil.py cp node_modules.tar.gz gs://chromium-nodejs/${sha1}"
  37. echo "DONE"
  38. echo -e "---------------------------------------------------------"