1- import sys , json , os , shutil
1+ import json
2+ import os
3+ import shutil
4+ import sys
5+
26
37def glob (path ):
48 return [os .path .join (path , filename ) for filename in os .listdir (path )]
59
10+
611def remove (* paths ):
712 for path in paths :
813 path = os .path .abspath (path )
@@ -14,50 +19,57 @@ def remove(*paths):
1419 except OSError as error :
1520 print (error )
1621
22+
1723def rewrite_package_json (path ):
18- package = open (path ,"rb+" )
24+ package = open (path , "rb+" )
1925 settings = json .load (package )
2026 settings ["devDependencies" ] = {}
2127 package .seek (0 )
2228 package .truncate ()
2329 json .dump (settings , package , indent = 4 )
2430 package .close ()
2531
32+
2633emsdk_path = sys .argv [1 ]
2734emscripten_path = os .path .join (emsdk_path , "upstream" , "emscripten" )
2835node_root = os .path .join (emsdk_path , "node" )
2936node_paths = glob (node_root )
30- upgrade = False
37+ upgrade = True
3138
32- npm = os . path . join ( node_paths [ 0 ], " bin" , "npm" )
33- if not os . path . exists ( npm ):
34- npm = "npm"
39+ # Add the local node bin directory to the path so that
40+ # npm can find it when doing the updating or pruning
41+ os . environ [ "PATH" ] += os . pathsep + os . path . join ( node_paths [ 0 ], "bin" )
3542
3643def update_npm (path ):
3744 try :
3845 os .chdir (os .path .join (path , "lib" ))
39- os .system (npm + " install npm@latest" )
46+ os .system ("npm install npm@latest" )
47+ os .system ("npm install npm@latest" )
4048 prune ()
4149 except OSError as error :
4250 print ("npm update failed" )
4351 print (error )
4452
53+
4554def remove_npm (path ):
4655 os .chdir (path )
4756 remove ("bin/npx" , "bin/npm" , "include" , "lib" , "share" )
4857
58+
4959def prune ():
5060 try :
51- os .system (npm + " prune --production" )
61+ os .system ("npm prune --production" )
5262 except OSError as error :
5363 print ("npm prune failed" )
5464 print (error )
5565
66+
5667os .chdir (emscripten_path )
5768rewrite_package_json ("package.json" )
58- prune ()
5969
60- remove ("tests" ,
70+
71+ remove (
72+ "tests" ,
6173 "node_modules/google-closure-compiler" ,
6274 "node_modules/google-closure-compiler-java" ,
6375 "node_modules/google-closure-compiler-osx" ,
@@ -67,7 +79,10 @@ def prune():
6779 "third_party/jni" ,
6880 "third_party/ply" ,
6981 "third_party/uglify-js" ,
70- "third_party/websockify" )
82+ "third_party/websockify" ,
83+ )
84+
85+ prune ()
7186
7287for path in node_paths :
7388 if upgrade :
0 commit comments