From 9f139c2417e0253abcfe26ef4a1098d3d9c8e9dc Mon Sep 17 00:00:00 2001 From: Nathan Vander Wilt Date: Tue, 10 Jan 2017 14:55:22 -0800 Subject: [PATCH 1/2] simplify (and fix) default browserify binary so that it will work with new simple_execute helper and hopefully on Windows fixing #17 too --- README.rst | 7 +++++++ pipeline_browserify/compiler.py | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/README.rst b/README.rst index b3b7789..5f393e5 100755 --- a/README.rst +++ b/README.rst @@ -38,6 +38,13 @@ To set environment varaibles specific to the browserify command:: (Note that for an actual production build, this example is not sufficient. You'll probably want to use a transform like loose-envify so the minifier can optimize out debug statements. Browserify doesn't usually pass environment variables like that shown above into the compiled code; but it may effect the runtime behavior of browserify itself.) +To use a local install of the browserify command line utility (or if it is not in your PATH for some other reason), you can override the command used:: + + PIPELINE['BROWSERIFY_BINARY'] = "/custom/path/to/browserify" + + # ...or perhaps something like this: + PIPELINE['BROWSERIFY_BINARY'] = os.path.join(REPO_ROOT, "node_modules/.bin", "browserify"), + **Important:** give your entry-point file a `.browserify.js` extension:: diff --git a/pipeline_browserify/compiler.py b/pipeline_browserify/compiler.py index 4a7889f..14825fe 100755 --- a/pipeline_browserify/compiler.py +++ b/pipeline_browserify/compiler.py @@ -26,7 +26,7 @@ def simple_execute_command(self, cmd, **kwargs): def _get_cmd_parts(self): pipeline_settings = getattr(settings, 'PIPELINE', {}) - tool = pipeline_settings.get('BROWSERIFY_BINARY', "/usr/bin/env browserify") + tool = pipeline_settings.get('BROWSERIFY_BINARY', "browserify") old_args = pipeline_settings.get('BROWSERIFY_ARGUMENTS', '') if old_args: From a2c808517930152101b69b3639f18a69021440bc Mon Sep 17 00:00:00 2001 From: Nathan Vander Wilt Date: Tue, 10 Jan 2017 15:11:28 -0800 Subject: [PATCH 2/2] make messaging a little nicer when BROWSERIFY_BINARY is misconfigured, showing a compiler error instead of a somewhat cryptic 500 --- pipeline_browserify/compiler.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pipeline_browserify/compiler.py b/pipeline_browserify/compiler.py index 14825fe..8fb800b 100755 --- a/pipeline_browserify/compiler.py +++ b/pipeline_browserify/compiler.py @@ -15,7 +15,10 @@ def match_file(self, path): # similar to old removed in https://github.com/jazzband/django-pipeline/commit/1f6b48ae74026a12f955f2f15f9f08823d744515 def simple_execute_command(self, cmd, **kwargs): import subprocess - pipe = subprocess.Popen(cmd, stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.PIPE, **kwargs) + try: + pipe = subprocess.Popen(cmd, stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.PIPE, **kwargs) + except OSError as e: + raise CompilerError("Compiler failed to execute. (%s)" % e, command=cmd, error_output="Executing the compiler resulted in an %s from the system.\n\nThis is most likely due to the `browserify` executable not being found in your PATH (if it is installed globally), or a misconfigured BROWSERIFY_BINARY setting (if you are using a non-global install)." % repr(e)) stdout, stderr = pipe.communicate() if self.verbose: print stdout