-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathnode_modules_create_bundle
executable file
·67 lines (51 loc) · 1.57 KB
/
node_modules_create_bundle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env python3
# Copyright 2019 The ChromiumOS Authors
# 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/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 *=/,+1{/"/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:]))