Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
emscripten-core
GitHub Repository: emscripten-core/emscripten
Path: blob/main/tools/maint/npm_update.py
4150 views
1
#!/usr/bin/env python3
2
# Copyright 2025 The Emscripten Authors. All rights reserved.
3
# Emscripten is available under two separate licenses, the MIT license and the
4
# University of Illinois/NCSA Open Source License. Both these licenses can be
5
# found in the LICENSE file.
6
7
"""Update npm dependencies using npm-check-updates
8
"""
9
10
import os
11
import subprocess
12
import sys
13
14
script_dir = os.path.dirname(os.path.abspath(__file__))
15
root_dir = os.path.dirname(os.path.dirname(script_dir))
16
17
18
def run(cmd, **args):
19
print('->', ' '.join(cmd))
20
return subprocess.check_output(cmd, text=True, cwd=root_dir, **args)
21
22
23
def main():
24
if run(['git', 'status', '-uno', '--porcelain']).strip():
25
print('tree is not clean')
26
return 1
27
28
output = run(['npx', 'npm-check-updates', '-u'], stderr=subprocess.STDOUT).strip()
29
30
if not run(['git', 'status', '-uno', '--porcelain']).strip():
31
print('no updates')
32
return 0
33
34
message = 'Automatic update of npm dependencies. NFC\n\n'
35
message += 'This change was automatically generated by tools/maint/npm_update.py\n\n'
36
lines = output.splitlines()
37
assert lines[0].startswith('Upgrading ')
38
assert lines[1] == ''
39
assert lines[-1].startswith('Run npm install to install new versions')
40
assert lines[-2] == ''
41
lines = lines[2:-2]
42
message += '\n'.join(lines) + '\n'
43
44
run(['npm', 'install'])
45
run(['git', 'checkout', '-b', 'npm_update'])
46
run(['git', 'add', '-u', 'package.json', 'package-lock.json'])
47
run(['git', 'commit', '-F', '-'], input=message)
48
49
50
if __name__ == '__main__':
51
sys.exit(main())
52
53