browserify-rails 0.9.1 → 0.9.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 753653fe9ebcc36fcbfe9ebcb4a44050ecc8e382
4
- data.tar.gz: 8f7f954f0c7b9f4d254e4e5e7cb0324f9a06a266
3
+ metadata.gz: 7f9e37a33cb04145996240865debf9ea327d1feb
4
+ data.tar.gz: bcee606ba1195f4147ee10d698063cb3d926c919
5
5
  SHA512:
6
- metadata.gz: 78bfe52c9f4c44658b35ea15116a5b5c26328b5c990b8c70d30bba305bbd0378c6d9e15901f5c8d7a828e122b40903c6b3f5f6301ce39b21a61a49085c2fa1b9
7
- data.tar.gz: 970bfab72485509afa047b616c40f78623352c3f052816b44bcdd56ae61914534e3de54d46e903340a39a980f15385cf0fc6a9d5284d92f682b0b6f6a31888e2
6
+ metadata.gz: aaa4a37b369a164fd6db990c0a57b1ae8e39cbaddf182f19b42551dee0a9a6b18f8acb9aeba457ef325a22c4efbb584519300cecf29ece3368fecf66f8f92128
7
+ data.tar.gz: 5a198d7ea6c81f0f053c039929a88db67522c0816943701016538e7b7466485e46db96fc6ed5d69fe436c1d69fe3552d0b7973a28ad420e8e2a4056220c05b5c
data/.gitignore CHANGED
@@ -25,5 +25,6 @@ tmp
25
25
  test/dummy/app/assets/javascripts/*.js
26
26
  test/dummy/app/assets/javascripts/**/*.js
27
27
  test/dummy/app/assets/javascripts/**/*.js.coffee
28
+ test/dummy/app/assets/javascripts/**/*.map
28
29
  /.ruby-*
29
30
  vendor/*
data/CHANGELOG.md CHANGED
@@ -1,6 +1,10 @@
1
1
  # Change Log
2
2
  All notable changes to this project will be documented in this file going forward.
3
3
 
4
+ ## [0.9.3] - 2015-06-03
5
+ - allow parentheses in path names
6
+ - support for piping output through Exorcist to extract sourcemaps
7
+
4
8
  ## [0.9.1] - 2015-04-20
5
9
  - options can be set to a proc
6
10
 
data/README.md CHANGED
@@ -1,4 +1,6 @@
1
1
  # browserify-rails
2
+
3
+ [![Join the chat at https://gitter.im/browserify-rails/browserify-rails](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/browserify-rails/browserify-rails?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
2
4
  [![Build Status](https://travis-ci.org/browserify-rails/browserify-rails.svg?branch=master)](https://travis-ci.org/browserify-rails/browserify-rails)
3
5
  [![Gem Version](https://badge.fury.io/rb/browserify-rails.svg)](http://badge.fury.io/rb/browserify-rails)
4
6
 
@@ -1,6 +1,7 @@
1
1
  require "open3"
2
2
  require "fileutils"
3
3
  require "tempfile"
4
+ require "shellwords"
4
5
 
5
6
  module BrowserifyRails
6
7
  class BrowserifyProcessor < Tilt::Template
@@ -39,6 +40,10 @@ module BrowserifyRails
39
40
  @browserifyinc_cmd ||= File.join(config.node_bin, "browserifyinc").freeze
40
41
  end
41
42
 
43
+ def exorcist_cmd
44
+ @exorcist_cmd ||= rails_path(File.join(config.node_bin, "exorcist").freeze)
45
+ end
46
+
42
47
  def ensure_tmp_dir_exists!
43
48
  FileUtils.mkdir_p(rails_path(tmp_path))
44
49
  end
@@ -119,10 +124,10 @@ module BrowserifyRails
119
124
  # NODE_ENV is set to the Rails.env. This is used by some modules to determine
120
125
  # how to build. Example: https://facebook.github.io/react/downloads.html#npm
121
126
  def env
122
- {
123
- "NODE_PATH" => asset_paths,
124
- "NODE_ENV" => config.node_env || Rails.env
125
- }
127
+ env_hash = {}
128
+ env_hash["NODE_PATH"] = asset_paths unless uses_exorcist
129
+ env_hash["NODE_ENV"] = config.node_env || Rails.env
130
+ env_hash
126
131
  end
127
132
 
128
133
  # Run the requested version of browserify (browserify or browserifyinc)
@@ -147,7 +152,7 @@ module BrowserifyRails
147
152
  # we're going to use browserifyinc.
148
153
  if uses_browserifyinc(force_browserifyinc)
149
154
  cache_file_path = rails_path(tmp_path, "browserifyinc-cache.json")
150
- command_options << " --cachefile=#{cache_file_path.inspect}"
155
+ command_options << " --cachefile=#{Shellwords.escape(cache_file_path.inspect)}"
151
156
  end
152
157
 
153
158
  # Create a temporary file for the output. Such file is necessary when
@@ -156,7 +161,7 @@ module BrowserifyRails
156
161
  command_options << " -o #{output_file.path.inspect}"
157
162
 
158
163
  # Compose the full command (using browserify or browserifyinc as necessary)
159
- command = "#{browserify_command(force_browserifyinc)} #{command_options} -"
164
+ command = "#{Shellwords.escape(browserify_command(force_browserifyinc))} #{command_options} -"
160
165
 
161
166
  # The directory the command will be executed from
162
167
  base_directory = File.dirname(file)
@@ -168,6 +173,26 @@ module BrowserifyRails
168
173
  raise BrowserifyRails::BrowserifyError.new("Error while running `#{command}`:\n\n#{stderr}")
169
174
  end
170
175
 
176
+ # If using exorcist, pipe output from browserify command into exorcist
177
+ if uses_exorcist && logical_path
178
+ if stdout.present?
179
+ bfy_output = stdout
180
+ else
181
+ bfy_output = output_file.read
182
+ end
183
+ sourcemap_output_file = "#{File.dirname(file)}/#{logical_path.split('/')[-1]}.map"
184
+ exorcist_command = "#{exorcist_cmd} #{sourcemap_output_file} #{exorcist_options}"
185
+ Logger::log "Exorcist: #{exorcist_command}"
186
+ exorcist_stdout, exorcist_stderr, exorcist_status = Open3.capture3(env,
187
+ exorcist_command,
188
+ stdin_data: bfy_output,
189
+ chdir: base_directory)
190
+
191
+ if !exorcist_status.success?
192
+ raise BrowserifyRails::BrowserifyError.new("Error while running `#{exorcist_command}`:\n\n#{exorcist_stderr}")
193
+ end
194
+ end
195
+
171
196
  # Read the output that was stored in the temp file
172
197
  output = output_file.read
173
198
 
@@ -177,7 +202,10 @@ module BrowserifyRails
177
202
 
178
203
  # Some command flags (such as --list) make the output go to stdout,
179
204
  # ignoring -o. If this happens, we give out stdout instead.
180
- if stdout.present?
205
+ # If we're using exorcist, then we directly use its output
206
+ if uses_exorcist && exorcist_stdout.present?
207
+ exorcist_stdout
208
+ elsif stdout.present?
181
209
  stdout
182
210
  else
183
211
  output
@@ -188,11 +216,15 @@ module BrowserifyRails
188
216
  !force.nil? ? force : config.use_browserifyinc
189
217
  end
190
218
 
219
+ def uses_exorcist
220
+ config.use_exorcist
221
+ end
222
+
191
223
  def browserify_command(force=nil)
192
224
  rails_path(uses_browserifyinc(force) ? browserifyinc_cmd : browserify_cmd)
193
225
  end
194
226
 
195
- def options_to_array(options, file)
227
+ def options_to_array(options)
196
228
  if options.respond_to? :call
197
229
  options.call(file)
198
230
  else
@@ -200,16 +232,23 @@ module BrowserifyRails
200
232
  end
201
233
  end
202
234
 
203
- def options(file = file)
235
+ def options
204
236
  options = []
205
237
 
206
238
  options.push("-d") if config.source_map_environments.include?(Rails.env)
207
239
 
208
- options += options_to_array(config.commandline_options, file) if config.commandline_options.present?
240
+ options += options_to_array(config.commandline_options) if config.commandline_options.present?
209
241
 
210
242
  options.uniq.join(" ")
211
243
  end
212
244
 
245
+ def exorcist_options
246
+ exorcist_options = []
247
+ exorcist_base_path = config.exorcist_base_path || config.root
248
+ exorcist_options.push("-b #{exorcist_base_path}")
249
+ exorcist_options.join(" ")
250
+ end
251
+
213
252
  def get_granular_config(logical_path)
214
253
  granular_config = config.granular["javascript"]
215
254
 
@@ -1,3 +1,3 @@
1
1
  module BrowserifyRails
2
- VERSION = "0.9.1"
2
+ VERSION = "0.9.3"
3
3
  end
@@ -2,8 +2,11 @@ require 'test_helper'
2
2
 
3
3
  class BrowserifyProcessorTest < ActiveSupport::TestCase
4
4
  setup do
5
- @empty_module = fixture("empty_module.js")
6
- @processor = BrowserifyRails::BrowserifyProcessor.new { |p| @empty_module }
5
+ template = "empty_module.js"
6
+ @empty_module = fixture(template)
7
+ @processor = BrowserifyRails::BrowserifyProcessor.new(template) do |p|
8
+ @empty_module
9
+ end
7
10
  end
8
11
 
9
12
  test "should run command without options if none provided" do
@@ -34,8 +37,8 @@ class BrowserifyProcessorTest < ActiveSupport::TestCase
34
37
  end
35
38
 
36
39
  test "should allow command line options to be a function" do
37
- stub_engine_config :commandline_options, -> file { ["-d", "-i #{file}.js"] }
38
- assert_equal "-d -i foo.js", @processor.send(:options, "foo")
40
+ stub_engine_config :commandline_options, -> file { ["-d", "-i #{file}"] }
41
+ assert_equal "-d -i empty_module.js", @processor.send(:options)
39
42
  end
40
43
 
41
44
  test "should add -d option if current env is in source_maps_env list" do
@@ -184,6 +184,29 @@ class BrowserifyTest < ActionController::IntegrationTest
184
184
  assert_equal expected_output, @response.body.strip
185
185
  end
186
186
 
187
+ test "generates sourcemap and writes to file if --use-exorcist" do
188
+ [:set_base_path, :default_base_path].each do |mode|
189
+ processor = BrowserifyRails::BrowserifyProcessor.new { |p| fixture("plain.js") }
190
+ processor.send(:config).stubs(:commandline_options).returns(["-d"])
191
+ Dummy::Application.config.browserify_rails.use_exorcist = true
192
+ if mode == :set_base_path
193
+ Dummy::Application.config.browserify_rails.exorcist_base_path = File.join(File.dirname(File.expand_path(__FILE__))).to_s
194
+ else
195
+ Dummy::Application.config.browserify_rails.exorcist_base_path = nil
196
+ end
197
+ begin
198
+ expected_output = fixture("js-with-sourcemap-url.out.js")
199
+
200
+ get "/assets/application.js"
201
+
202
+ assert_response :success
203
+ assert_equal expected_output, @response.body.strip
204
+ ensure
205
+ Dummy::Application.config.browserify_rails.use_exorcist = false
206
+ end
207
+ end
208
+ end
209
+
187
210
  test "throws BrowserifyError if something went wrong while executing browserify" do
188
211
  File.open(File.join(Rails.root, "app/assets/javascripts/application.js"), "w+") do |f|
189
212
  f.puts "var foo = require('./foo');"
@@ -6,6 +6,7 @@
6
6
  "browserify": "~> 6.2",
7
7
  "browserify-incremental": "^1.4.0",
8
8
  "coffeeify": "~> 0.6",
9
+ "exorcist": "~> 0.3.0",
9
10
  "node-test-package": "~> 0.0.2"
10
11
  },
11
12
  "license": "MIT",
@@ -0,0 +1,16 @@
1
+ (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({"__RAILS_ROOT__/app/assets/javascripts/_stream_0.js":[function(require,module,exports){
2
+ var foo = require('./foo');
3
+ var nodeTestPackage = require('node-test-package');
4
+
5
+ },{"./foo":"__RAILS_ROOT__/app/assets/javascripts/foo.js","node-test-package":"__RAILS_ROOT__/node_modules/node-test-package/index.js"}],"__RAILS_ROOT__/app/assets/javascripts/foo.js":[function(require,module,exports){
6
+ require('./nested');
7
+ module.exports = function (n) { return n * 11 }
8
+
9
+ },{"./nested":"__RAILS_ROOT__/app/assets/javascripts/nested/index.js"}],"__RAILS_ROOT__/app/assets/javascripts/nested/index.js":[function(require,module,exports){
10
+ module.exports.NESTED = true;
11
+
12
+ },{}],"__RAILS_ROOT__/node_modules/node-test-package/index.js":[function(require,module,exports){
13
+ module.exports = console.log("hello friend");
14
+
15
+ },{}]},{},["__RAILS_ROOT__/app/assets/javascripts/_stream_0.js"])
16
+ //# sourceMappingURL=application.map
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: browserify-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.1
4
+ version: 0.9.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henry Hsu, Cymen Vig
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-20 00:00:00.000000000 Z
11
+ date: 2015-06-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sprockets
@@ -202,6 +202,7 @@ files:
202
202
  - test/fixtures/browserified.out.js
203
203
  - test/fixtures/empty_module.js
204
204
  - test/fixtures/foo.out.js
205
+ - test/fixtures/js-with-sourcemap-url.out.js
205
206
  - test/fixtures/main.out.js
206
207
  - test/fixtures/mocha.js
207
208
  - test/fixtures/node_path_based_require.out.js
@@ -293,6 +294,7 @@ test_files:
293
294
  - test/fixtures/browserified.out.js
294
295
  - test/fixtures/empty_module.js
295
296
  - test/fixtures/foo.out.js
297
+ - test/fixtures/js-with-sourcemap-url.out.js
296
298
  - test/fixtures/main.out.js
297
299
  - test/fixtures/mocha.js
298
300
  - test/fixtures/node_path_based_require.out.js