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 +4 -4
- data/.gitignore +1 -0
- data/CHANGELOG.md +4 -0
- data/README.md +2 -0
- data/lib/browserify-rails/browserify_processor.rb +49 -10
- data/lib/browserify-rails/version.rb +1 -1
- data/test/browserify_processor_test.rb +7 -4
- data/test/compilation_test.rb +23 -0
- data/test/dummy/package.json +1 -0
- data/test/fixtures/js-with-sourcemap-url.out.js +16 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7f9e37a33cb04145996240865debf9ea327d1feb
|
4
|
+
data.tar.gz: bcee606ba1195f4147ee10d698063cb3d926c919
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aaa4a37b369a164fd6db990c0a57b1ae8e39cbaddf182f19b42551dee0a9a6b18f8acb9aeba457ef325a22c4efbb584519300cecf29ece3368fecf66f8f92128
|
7
|
+
data.tar.gz: 5a198d7ea6c81f0f053c039929a88db67522c0816943701016538e7b7466485e46db96fc6ed5d69fe436c1d69fe3552d0b7973a28ad420e8e2a4056220c05b5c
|
data/.gitignore
CHANGED
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
|
+
[](https://gitter.im/browserify-rails/browserify-rails?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
2
4
|
[](https://travis-ci.org/browserify-rails/browserify-rails)
|
3
5
|
[](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
|
-
|
124
|
-
|
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
|
-
|
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
|
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
|
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
|
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
|
|
@@ -2,8 +2,11 @@ require 'test_helper'
|
|
2
2
|
|
3
3
|
class BrowserifyProcessorTest < ActiveSupport::TestCase
|
4
4
|
setup do
|
5
|
-
|
6
|
-
@
|
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}
|
38
|
-
assert_equal "-d -i
|
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
|
data/test/compilation_test.rb
CHANGED
@@ -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');"
|
data/test/dummy/package.json
CHANGED
@@ -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.
|
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-
|
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
|