Bug NODE: call webpack directly and handle multiple inputs draft
authorDan Mosedale <dmose@meer.net>
Tue, 15 May 2018 17:53:22 -0700
changeset 795818 1e5c2f551e0c34d4e323d8777e367a7adabcdee4
parent 795817 8da66ded52a8701cb8d76a67fb2a0d46ec83f5a5
child 795819 36a2e8e9d816b8d626105c1ba130a1b7010c5685
push id110091
push userbmo:dmose@mozilla.org
push dateWed, 16 May 2018 16:58:05 +0000
milestone62.0a1
Bug NODE: call webpack directly and handle multiple inputs The idea here is that the .build file invokes node.py with some arbitrary number of inputs followed by -- followed by all the arguments that will be passed to node.
python/mozbuild/mozbuild/action/node.py
--- a/python/mozbuild/mozbuild/action/node.py
+++ b/python/mozbuild/mozbuild/action/node.py
@@ -15,31 +15,34 @@ import sys
 
 
 def main(output, config, *flags):
     # XXX once we switch to multiple inputs, we may need a better way
     # to get this
     cwd = os.path.dirname(os.path.abspath(config))
 
     try:
-        args = flags
+        if(flags.count('--') != 1):
+            raise ValueError('Exactly one -- delimiter must be given to separate inputs from node arguments')
+
+        delimiterIndex = flags.index('--')
 
-        cmd = ' '.join(pipes.quote(arg) for arg in args)
+        # XXX Do we even need to do anything with the inputs?  If so, they're
+        # here:
+        # inputs = flags[:delimiterIndex]
+
+        nodeArgs = ['node']
+        nodeArgs += flags[delimiterIndex + 1:]
+
+        cmd = ' '.join(pipes.quote(arg) for arg in nodeArgs)
         print('"{}" in {}'.format(cmd, cwd), file=sys.stderr)
         sys.stderr.flush()
 
         env = dict(os.environ)
 
-        # TODO: explain how this enables bare `webpack` in scripts.
-        path = mozpath.join(buildconfig.topsrcdir, 'node_modules', '.bin')
-        if os.path.exists(path) and os.path.isdir(path):
-            if 'PATH' in env:
-                path += os.pathsep + env['PATH']
-            env['PATH'] = path
-
-        subprocess.check_call(args, cwd=cwd, env=env)
+        subprocess.check_call(nodeArgs, cwd=cwd, env=env)
 
         return 0
     except subprocess.CalledProcessError as err:
         # XXX OSError: [Errno 13] Permission denied may mean "not installed".
         # Figure out way to display more clearly.
         print('Failed with %s.' % str(err))
         return 1