def run_browserify(logical_path=nil, extra_options=nil, force_browserifyinc=nil)
      command_options = "#{options} #{extra_options} #{granular_options(logical_path)}".strip

      # Browserifyinc uses a special cache file. We set up the path for it if
      # we're going to use browserifyinc.
      if uses_browserifyinc(force_browserifyinc)
        cache_file_path = rails_path(tmp_path, "browserifyinc-cache.json")
        command_options << " --cachefile=#{Shellwords.escape(cache_file_path)}"
      end

      # Create a temporary file for the output. Such file is necessary when
      # using browserifyinc, but we use it in all instances for consistency
      output_file = Tempfile.new("output", rails_path(tmp_path))
      command_options << " -o #{output_file.path.inspect}"

      # Compose the full command (using browserify or browserifyinc as necessary)
      command = "#{Shellwords.escape(browserify_command(force_browserifyinc))} #{command_options} -"

      # The directory the command will be executed from
      base_directory = File.dirname(file)

      Logger::log "Browserify: #{command}"

      # If we are on JRuby 1.x, capture3 does not support chdir option
      stdout, stderr, status = if RUBY_PLATFORM == "java" && JRUBY_VERSION =~ /^1/
        Dir.chdir(base_directory) {
          Open3.capture3(env, command, stdin_data: data)
        }
      else
        Open3.capture3(env, command, stdin_data: data, chdir: base_directory)
      end

      if !status.success?
        raise BrowserifyRails::BrowserifyError.new("Error while running `#{command}`:\n\n#{stderr}")
      end

      # If using exorcist, pipe output from browserify command into exorcist
      if uses_exorcist && logical_path
        if stdout.present?
          bfy_output = stdout
        else
          bfy_output = output_file.read
        end
        sourcemap_output_file = "#{File.dirname(file)}/#{logical_path.split('/')[-1]}.map"
        exorcist_command = "#{Shellwords.shellescape(exorcist_cmd)} #{Shellwords.shellescape(sourcemap_output_file)} #{exorcist_options}"
        Logger::log "Exorcist: #{exorcist_command}"
        exorcist_stdout, exorcist_stderr, exorcist_status = Open3.capture3(env,
                                                                           exorcist_command,
                                                                           stdin_data: bfy_output,
                                                                           chdir: base_directory)

        if !exorcist_status.success?
          raise BrowserifyRails::BrowserifyError.new("Error while running `#{exorcist_command}`:\n\n#{exorcist_stderr}")
        end
      end

      # Read the output that was stored in the temp file
      output_file.open
      output = output_file.read

      # Destroy the temp file (good practice)
      output_file.close
      output_file.unlink

      # Some command flags (such as --list) make the output go to stdout,
      # ignoring -o. If this happens, we give out stdout instead.
      # If we're using exorcist, then we directly use its output
      if uses_exorcist && exorcist_stdout.present?
        exorcist_stdout
      elsif stdout.present?
        stdout
      else
        output
      end
    end
def run_browserify(logical_path=nil, extra_options=nil, force_browserifyinc=nil)
      command_options = "#{options} #{extra_options} #{granular_options(logical_path)}".strip

      # Browserifyinc uses a special cache file. We set up the path for it if
      # we're going to use browserifyinc.
      if uses_browserifyinc(force_browserifyinc)
        cache_file_path = rails_path(tmp_path, "browserifyinc-cache.json")
        command_options << " --cachefile=#{Shellwords.escape(cache_file_path)}"
      end

      # Create a temporary file for the output. Such file is necessary when
      # using browserifyinc, but we use it in all instances for consistency
      output_file = Tempfile.new("output", rails_path(tmp_path))
      command_options << " -o #{output_file.path.inspect}"

      # Compose the full command (using browserify or browserifyinc as necessary)
      command = "#{Shellwords.escape(browserify_command(force_browserifyinc))} #{command_options} -"

      # The directory the command will be executed from
      base_directory = File.dirname(file)

      Logger::log "Browserify: #{command}"

      # If we are on JRuby 1.x, capture3 does not support chdir option
      stdout, stderr, status = if RUBY_PLATFORM == "java" && JRUBY_VERSION =~ /^1/
        Dir.chdir(base_directory) {
          Open3.capture3(env, command, stdin_data: data)
        }
      else
        Open3.capture3(env, command, stdin_data: data, chdir: base_directory)
      end

      if !status.success?
        raise BrowserifyRails::BrowserifyError.new("Error while running `#{command}`:\n\n#{stderr}")
      end

      # If using exorcist, pipe output from browserify command into exorcist
      if uses_exorcist && logical_path
        if stdout.present?
          bfy_output = stdout
        else
          bfy_output = output_file.read
        end
        sourcemap_output_file = "#{File.dirname(file)}/#{logical_path.split('/')[-1]}.map"
        exorcist_command = "#{Shellwords.shellescape(exorcist_cmd)} #{Shellwords.shellescape(sourcemap_output_file)} #{exorcist_options}"
        Logger::log "Exorcist: #{exorcist_command}"
        exorcist_stdout, exorcist_stderr, exorcist_status = Open3.capture3(env,
                                                                           exorcist_command,
                                                                           stdin_data: bfy_output,
                                                                           chdir: base_directory)

        if !exorcist_status.success?
          raise BrowserifyRails::BrowserifyError.new("Error while running `#{exorcist_command}`:\n\n#{exorcist_stderr}")
        end
      end

      # Read the output that was stored in the temp file
      output_file.open
      output = output_file.read

      # Destroy the temp file (good practice)
      output_file.close
      output_file.unlink

      # Some command flags (such as --list) make the output go to stdout,
      # ignoring -o. If this happens, we give out stdout instead.
      # If we're using exorcist, then we directly use its output
      if uses_exorcist && exorcist_stdout.present?
        exorcist_stdout
      elsif stdout.present?
        stdout
      else
        output
      end
    end
Run the requested version of browserify (browserify or browserifyinc)
 based on configuration or the use_browserifyinc parameter if present.

 We are passing the data via stdin, so that earlier preprocessing steps are
 respected. If you had, say, an "application.js.coffee.erb", passing the
 filename would fail, because browserify would read the original file with
 ERB tags and fail. By passing the data via stdin, we get the expected
 behavior of success, because everything has been compiled to plain
 javascript at the time this processor is called.

 @raise [BrowserifyRails::BrowserifyError] if browserify does not succeed
 @param logical_path [String] Sprockets's logical path for the file
 @param extra_options [String] Options to be included in the command
 @param force_browserifyinc [Boolean] Causes browserifyinc to be used if true
 @return [String] Output of the command