hsume2-browserify-rails 0.1.0 → 0.2.1
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/README.md +8 -17
- data/lib/browserify-rails.rb +5 -4
- data/lib/browserify-rails/browserify_error.rb +5 -0
- data/lib/browserify-rails/browserify_processor.rb +91 -0
- data/lib/browserify-rails/railtie.rb +3 -5
- data/lib/browserify-rails/version.rb +1 -1
- data/test/compilation_test.rb +54 -6
- data/test/dummy/app/assets/javascripts/foo.js.example +1 -0
- data/test/dummy/app/assets/javascripts/nested/index.js.example +1 -0
- data/test/dummy/package.json +2 -3
- data/test/fixtures/application.changed.out.js +12 -0
- data/test/fixtures/application.foo_changed.out.js +11 -0
- data/test/fixtures/application.out.js +11 -0
- data/test/fixtures/foo.out.js +9 -0
- metadata +14 -3
- data/lib/browserify-rails/directive_processor.rb +0 -70
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1cfe8c2634c87114f8c83d1d4b8ea1a9b690dbd0
|
4
|
+
data.tar.gz: 7c7170d2a116dec99bd786c71f9d22a4116a477b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d1b467af74253ecc9b46cb13fae112ec518c763755eced4ea2fa67a4a99ba48f6e5bdbed74c9d45f2645927439da1a780229e88e6b2576925a5ffaeb82df4733
|
7
|
+
data.tar.gz: 6c282412818608c37e746d380089de702ffb11fa244f7f877a274ab88b445965d20225bbe4d1f6ea5f406c7e3924eef839502f1ff8a7f2476cfd4d2970c47542
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -10,12 +10,13 @@ It let's you mix and match `//= require` directives and `require()` calls for i
|
|
10
10
|
2. Serve assets with Sprockets
|
11
11
|
3. Require modules with `require()` (without separate `//= require` directives)
|
12
12
|
4. Only build required modules
|
13
|
+
5. Require *npm modules* in your Rails assets
|
13
14
|
|
14
15
|
## Getting Started
|
15
16
|
|
16
17
|
Add this line to your application's Gemfile:
|
17
18
|
|
18
|
-
gem
|
19
|
+
gem "hsume2-browserify-rails", "~> 0.2.0", :require => "browserify-rails"
|
19
20
|
|
20
21
|
Create `package.json` in your Rails root:
|
21
22
|
|
@@ -23,8 +24,7 @@ Create `package.json` in your Rails root:
|
|
23
24
|
{
|
24
25
|
"name": "something",
|
25
26
|
"devDependencies" : {
|
26
|
-
"browserify": "
|
27
|
-
"module-deps": "1.7.x"
|
27
|
+
"browserify": "~> 3.33"
|
28
28
|
},
|
29
29
|
"license": "MIT",
|
30
30
|
"engines": {
|
@@ -50,20 +50,10 @@ console.log(foo(12));
|
|
50
50
|
```
|
51
51
|
|
52
52
|
## Coffeescript
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
"devDependencies" : {
|
58
|
-
"browserify": "2.13.x"
|
59
|
-
"coffeeify": "0.6.x"
|
60
|
-
},
|
61
|
-
"license": "MIT",
|
62
|
-
"engines": {
|
63
|
-
"node": ">= 0.6"
|
64
|
-
}
|
65
|
-
}
|
66
|
-
```
|
53
|
+
|
54
|
+
Coffeescript is handled seamlessly, if you name your files `*.js.coffee`. That
|
55
|
+
way the coffeescript compiler will already have done it's work, when we are
|
56
|
+
putting the javascript tools to work.
|
67
57
|
|
68
58
|
## Contributing
|
69
59
|
|
@@ -73,3 +63,4 @@ Pull requests appreciated.
|
|
73
63
|
|
74
64
|
* [Henry Hsu](https://github.com/hsume2)
|
75
65
|
* [Cássio Souza](https://github.com/cassiozen)
|
66
|
+
* [Marten Lienen](https://github.com/CQQL)
|
data/lib/browserify-rails.rb
CHANGED
@@ -1,8 +1,9 @@
|
|
1
|
-
require
|
1
|
+
require "sprockets"
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
3
|
+
require "browserify-rails/browserify_error"
|
4
|
+
require "browserify-rails/browserify_processor"
|
5
|
+
require "browserify-rails/railtie"
|
6
|
+
require "browserify-rails/version"
|
6
7
|
|
7
8
|
module BrowserifyRails
|
8
9
|
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
require "open3"
|
2
|
+
require "json"
|
3
|
+
|
4
|
+
module BrowserifyRails
|
5
|
+
class BrowserifyProcessor < Tilt::Template
|
6
|
+
BROWSERIFY_CMD = "./node_modules/.bin/browserify".freeze
|
7
|
+
|
8
|
+
def prepare
|
9
|
+
end
|
10
|
+
|
11
|
+
def evaluate(context, locals, &block)
|
12
|
+
if commonjs_module?
|
13
|
+
asset_dependencies(context.environment.paths).each do |path|
|
14
|
+
context.depend_on(path)
|
15
|
+
end
|
16
|
+
|
17
|
+
browserify
|
18
|
+
else
|
19
|
+
data
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def commonjs_module?
|
26
|
+
data.to_s.include?("module.exports") || data.to_s.include?("require")
|
27
|
+
end
|
28
|
+
|
29
|
+
# This primarily filters out required files from node modules
|
30
|
+
#
|
31
|
+
# @return [<String>] Paths of dependencies, that are in asset directories
|
32
|
+
def asset_dependencies(asset_paths)
|
33
|
+
dependencies.select do |path|
|
34
|
+
path.start_with?(*asset_paths)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# @return [<String>] Paths of files, that this file depends on
|
39
|
+
def dependencies
|
40
|
+
run_browserify("--list").lines.map(&:strip).select do |path|
|
41
|
+
# Filter the temp file, where browserify caches the input stream
|
42
|
+
File.exists?(path)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def browserify
|
47
|
+
# Only generate source maps in development
|
48
|
+
if Rails.env == "development"
|
49
|
+
options = "-d"
|
50
|
+
else
|
51
|
+
options = ""
|
52
|
+
end
|
53
|
+
|
54
|
+
run_browserify(options)
|
55
|
+
end
|
56
|
+
|
57
|
+
def browserify_cmd
|
58
|
+
cmd = File.join(Rails.root, BROWSERIFY_CMD)
|
59
|
+
|
60
|
+
if !File.exist?(cmd)
|
61
|
+
raise BrowserifyRails::BrowserifyError.new("browserify could not be found at #{cmd}. Please run npm install.")
|
62
|
+
end
|
63
|
+
|
64
|
+
cmd
|
65
|
+
end
|
66
|
+
|
67
|
+
# Run browserify with `data` on standard input.
|
68
|
+
#
|
69
|
+
# We are passing the data via stdin, so that earlier preprocessing steps are
|
70
|
+
# respected. If you had, say, an "application.js.coffee.erb", passing the
|
71
|
+
# filename would fail, because browserify would read the original file with
|
72
|
+
# ERB tags and fail. By passing the data via stdin, we get the expected
|
73
|
+
# behavior of success, because everything has been compiled to plain
|
74
|
+
# javascript at the time this processor is called.
|
75
|
+
#
|
76
|
+
# @raise [BrowserifyRails::BrowserifyError] if browserify does not succeed
|
77
|
+
# @param options [String] Options for browserify
|
78
|
+
# @return [String] Output on standard out
|
79
|
+
def run_browserify(options)
|
80
|
+
command = "#{browserify_cmd} #{options}"
|
81
|
+
directory = File.dirname(file)
|
82
|
+
stdout, stderr, status = Open3.capture3(command, stdin_data: data, chdir: directory)
|
83
|
+
|
84
|
+
if !status.success?
|
85
|
+
raise BrowserifyRails::BrowserifyError.new("Error while running `#{command}`:\n\n#{stderr}")
|
86
|
+
end
|
87
|
+
|
88
|
+
stdout
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
@@ -1,13 +1,11 @@
|
|
1
1
|
module BrowserifyRails
|
2
2
|
class Railtie < Rails::Engine
|
3
|
-
|
4
3
|
initializer :setup_browserify do |app|
|
5
|
-
app.assets.register_postprocessor
|
4
|
+
app.assets.register_postprocessor "application/javascript", BrowserifyRails::BrowserifyProcessor
|
6
5
|
end
|
7
6
|
|
8
7
|
rake_tasks do
|
9
|
-
Dir[File.join(File.dirname(__FILE__),
|
8
|
+
Dir[File.join(File.dirname(__FILE__), "tasks/*.rake")].each { |f| load f }
|
10
9
|
end
|
11
|
-
|
12
10
|
end
|
13
|
-
end
|
11
|
+
end
|
data/test/compilation_test.rb
CHANGED
@@ -3,36 +3,84 @@ require 'test_helper'
|
|
3
3
|
class BrowserifyTest < ActionController::IntegrationTest
|
4
4
|
|
5
5
|
setup do
|
6
|
-
|
7
|
-
|
6
|
+
Rails.application.assets.cache = nil
|
7
|
+
|
8
8
|
FileUtils.cp(File.join(Rails.root, 'app/assets/javascripts/application.js.example'), File.join(Rails.root, 'app/assets/javascripts/application.js'))
|
9
9
|
FileUtils.cp(File.join(Rails.root, 'app/assets/javascripts/foo.js.example'), File.join(Rails.root, 'app/assets/javascripts/foo.js'))
|
10
|
+
FileUtils.cp(File.join(Rails.root, 'app/assets/javascripts/nested/index.js.example'), File.join(Rails.root, 'app/assets/javascripts/nested/index.js'))
|
10
11
|
end
|
11
12
|
|
12
13
|
test "asset pipeline should serve application.js" do
|
14
|
+
expected_output = fixture("application.out.js")
|
15
|
+
|
13
16
|
get "/assets/application.js"
|
14
17
|
assert_response :success
|
15
|
-
|
18
|
+
assert_equal expected_output, @response.body.strip
|
16
19
|
end
|
17
20
|
|
18
21
|
test "asset pipeline should serve foo.js" do
|
22
|
+
expected_output = fixture("foo.out.js")
|
23
|
+
|
19
24
|
get "/assets/foo.js"
|
20
25
|
assert_response :success
|
21
|
-
|
26
|
+
assert_equal expected_output, @response.body.strip
|
22
27
|
end
|
23
28
|
|
24
29
|
test "asset pipeline should regenerate application.js when foo.js changes" do
|
30
|
+
expected_output = fixture("application.out.js")
|
31
|
+
|
25
32
|
get "/assets/application.js"
|
26
33
|
assert_response :success
|
27
|
-
|
34
|
+
assert_equal expected_output, @response.body.strip
|
35
|
+
|
36
|
+
# Ensure that Sprockets can detect the change to the file modification time
|
37
|
+
sleep 1
|
28
38
|
|
29
39
|
File.open(File.join(Rails.root, 'app/assets/javascripts/foo.js'), 'w+') do |f|
|
40
|
+
f.puts "require('./nested');"
|
30
41
|
f.puts "module.exports = function (n) { return n * 12 }"
|
31
42
|
end
|
32
43
|
|
44
|
+
expected_output = fixture("application.foo_changed.out.js")
|
45
|
+
|
46
|
+
get "/assets/application.js"
|
47
|
+
assert_response :success
|
48
|
+
assert_equal expected_output, @response.body.strip
|
49
|
+
end
|
50
|
+
|
51
|
+
test "asset pipeline should regenerate application.js when application.js changes" do
|
52
|
+
expected_output = fixture("application.out.js")
|
53
|
+
|
54
|
+
get "/assets/application.js"
|
55
|
+
assert_response :success
|
56
|
+
assert_equal expected_output, @response.body.strip
|
57
|
+
|
58
|
+
# Ensure that Sprockets can detect the change to the file modification time
|
59
|
+
sleep 1
|
60
|
+
|
61
|
+
File.open(File.join(Rails.root, 'app/assets/javascripts/application.js'), 'w+') do |f|
|
62
|
+
f.puts "var foo = require('./foo');"
|
63
|
+
f.puts "console.log(foo(11));"
|
64
|
+
end
|
65
|
+
|
66
|
+
expected_output = fixture("application.changed.out.js")
|
67
|
+
|
33
68
|
get "/assets/application.js"
|
34
69
|
assert_response :success
|
35
|
-
|
70
|
+
assert_equal expected_output, @response.body.strip
|
36
71
|
end
|
37
72
|
|
73
|
+
test "throws BrowserifyError if something went wrong while executing browserify" do
|
74
|
+
File.open(File.join(Rails.root, 'app/assets/javascripts/application.js'), 'w+') do |f|
|
75
|
+
f.puts "var foo = require('./foo');"
|
76
|
+
f.puts "var bar = require('./bar');"
|
77
|
+
end
|
78
|
+
|
79
|
+
get "/assets/application.js"
|
80
|
+
assert_match /BrowserifyRails::BrowserifyError/, @response.body
|
81
|
+
end
|
82
|
+
|
83
|
+
def fixture(filename)
|
84
|
+
File.open(File.join(File.dirname(__FILE__), "/fixtures/#{filename}")).read.strip
|
85
|
+
end
|
38
86
|
end
|
@@ -0,0 +1 @@
|
|
1
|
+
module.exports.NESTED = true;
|
data/test/dummy/package.json
CHANGED
@@ -3,11 +3,10 @@
|
|
3
3
|
"author": "Henry Hsu <hhsu@zendesk.com>",
|
4
4
|
"description": "a dummy Rails application",
|
5
5
|
"devDependencies" : {
|
6
|
-
"browserify": "
|
7
|
-
"module-deps": "1.7.x"
|
6
|
+
"browserify": "~> 3.33"
|
8
7
|
},
|
9
8
|
"license": "MIT",
|
10
9
|
"engines": {
|
11
|
-
"node": ">= 0.
|
10
|
+
"node": ">= 0.10"
|
12
11
|
}
|
13
12
|
}
|
@@ -0,0 +1,12 @@
|
|
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);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.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})({1:[function(require,module,exports){
|
2
|
+
var foo = require('./foo');
|
3
|
+
console.log(foo(11));
|
4
|
+
|
5
|
+
},{"./foo":2}],2:[function(require,module,exports){
|
6
|
+
require('./nested');
|
7
|
+
module.exports = function (n) { return n * 11 }
|
8
|
+
|
9
|
+
},{"./nested":3}],3:[function(require,module,exports){
|
10
|
+
module.exports.NESTED = true;
|
11
|
+
|
12
|
+
},{}]},{},[1])
|
@@ -0,0 +1,11 @@
|
|
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);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.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})({1:[function(require,module,exports){
|
2
|
+
var foo = require('./foo');
|
3
|
+
|
4
|
+
},{"./foo":2}],2:[function(require,module,exports){
|
5
|
+
require('./nested');
|
6
|
+
module.exports = function (n) { return n * 12 }
|
7
|
+
|
8
|
+
},{"./nested":3}],3:[function(require,module,exports){
|
9
|
+
module.exports.NESTED = true;
|
10
|
+
|
11
|
+
},{}]},{},[1])
|
@@ -0,0 +1,11 @@
|
|
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);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.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})({1:[function(require,module,exports){
|
2
|
+
var foo = require('./foo');
|
3
|
+
|
4
|
+
},{"./foo":2}],2:[function(require,module,exports){
|
5
|
+
require('./nested');
|
6
|
+
module.exports = function (n) { return n * 11 }
|
7
|
+
|
8
|
+
},{"./nested":3}],3:[function(require,module,exports){
|
9
|
+
module.exports.NESTED = true;
|
10
|
+
|
11
|
+
},{}]},{},[1])
|
@@ -0,0 +1,9 @@
|
|
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);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.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})({1:[function(require,module,exports){
|
2
|
+
require('./nested');
|
3
|
+
module.exports = function (n) { return n * 11 }
|
4
|
+
;
|
5
|
+
|
6
|
+
},{"./nested":2}],2:[function(require,module,exports){
|
7
|
+
module.exports.NESTED = true;
|
8
|
+
|
9
|
+
},{}]},{},[1])
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hsume2-browserify-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Henry Hsu
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-03-
|
11
|
+
date: 2014-03-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sprockets
|
@@ -81,7 +81,8 @@ files:
|
|
81
81
|
- Rakefile
|
82
82
|
- browserify-rails.gemspec
|
83
83
|
- lib/browserify-rails.rb
|
84
|
-
- lib/browserify-rails/
|
84
|
+
- lib/browserify-rails/browserify_error.rb
|
85
|
+
- lib/browserify-rails/browserify_processor.rb
|
85
86
|
- lib/browserify-rails/railtie.rb
|
86
87
|
- lib/browserify-rails/tasks/npm.rake
|
87
88
|
- lib/browserify-rails/version.rb
|
@@ -89,6 +90,7 @@ files:
|
|
89
90
|
- test/dummy/Rakefile
|
90
91
|
- test/dummy/app/assets/javascripts/application.js.example
|
91
92
|
- test/dummy/app/assets/javascripts/foo.js.example
|
93
|
+
- test/dummy/app/assets/javascripts/nested/index.js.example
|
92
94
|
- test/dummy/app/assets/stylesheets/application.css
|
93
95
|
- test/dummy/app/controllers/application_controller.rb
|
94
96
|
- test/dummy/app/controllers/home_controller.rb
|
@@ -120,6 +122,10 @@ files:
|
|
120
122
|
- test/dummy/public/500.html
|
121
123
|
- test/dummy/public/favicon.ico
|
122
124
|
- test/dummy/script/rails
|
125
|
+
- test/fixtures/application.changed.out.js
|
126
|
+
- test/fixtures/application.foo_changed.out.js
|
127
|
+
- test/fixtures/application.out.js
|
128
|
+
- test/fixtures/foo.out.js
|
123
129
|
- test/test_helper.rb
|
124
130
|
homepage: ''
|
125
131
|
licenses:
|
@@ -150,6 +156,7 @@ test_files:
|
|
150
156
|
- test/dummy/Rakefile
|
151
157
|
- test/dummy/app/assets/javascripts/application.js.example
|
152
158
|
- test/dummy/app/assets/javascripts/foo.js.example
|
159
|
+
- test/dummy/app/assets/javascripts/nested/index.js.example
|
153
160
|
- test/dummy/app/assets/stylesheets/application.css
|
154
161
|
- test/dummy/app/controllers/application_controller.rb
|
155
162
|
- test/dummy/app/controllers/home_controller.rb
|
@@ -181,4 +188,8 @@ test_files:
|
|
181
188
|
- test/dummy/public/500.html
|
182
189
|
- test/dummy/public/favicon.ico
|
183
190
|
- test/dummy/script/rails
|
191
|
+
- test/fixtures/application.changed.out.js
|
192
|
+
- test/fixtures/application.foo_changed.out.js
|
193
|
+
- test/fixtures/application.out.js
|
194
|
+
- test/fixtures/foo.out.js
|
184
195
|
- test/test_helper.rb
|
@@ -1,70 +0,0 @@
|
|
1
|
-
require 'open3'
|
2
|
-
require 'json'
|
3
|
-
|
4
|
-
module BrowserifyRails
|
5
|
-
class DirectiveProcessor < Sprockets::DirectiveProcessor
|
6
|
-
BROWSERIFY_CMD = './node_modules/.bin/browserify'.freeze
|
7
|
-
MODULE_DEPS_CMD = './node_modules/.bin/module-deps'.freeze
|
8
|
-
COFFEEIFY_PATH = './node_modules/coffeeify'.freeze
|
9
|
-
|
10
|
-
class BrowserifyError < RuntimeError
|
11
|
-
end
|
12
|
-
|
13
|
-
class ModuleDepsError < RuntimeError
|
14
|
-
end
|
15
|
-
|
16
|
-
def evaluate(context, locals, &block)
|
17
|
-
super
|
18
|
-
|
19
|
-
if commonjs_module?(data)
|
20
|
-
browserify_cmd = File.join(context.environment.root, BROWSERIFY_CMD)
|
21
|
-
module_deps_cmd = File.join(context.environment.root, MODULE_DEPS_CMD)
|
22
|
-
|
23
|
-
raise ArgumentError, "#{browserify_cmd} could not be found. Please run npm install." unless File.exist?(browserify_cmd)
|
24
|
-
raise ArgumentError, "#{module_deps_cmd} could not be found. Please run npm install." unless File.exist?(module_deps_cmd)
|
25
|
-
|
26
|
-
deps = JSON.parse(run_command("#{module_deps_cmd} #{pathname}"))
|
27
|
-
deps.each do |dep|
|
28
|
-
path = File.basename(dep['id'], context.environment.root)
|
29
|
-
next if path == File.basename(pathname)
|
30
|
-
|
31
|
-
if path =~ /<([^>]+)>/
|
32
|
-
path = $1
|
33
|
-
else
|
34
|
-
path = "./#{path}" unless relative?(path)
|
35
|
-
end
|
36
|
-
|
37
|
-
context.depend_on_asset(path)
|
38
|
-
end
|
39
|
-
|
40
|
-
params = "-d"
|
41
|
-
params += " -t coffeeify --extension='.coffee'" if File.directory?(COFFEEIFY_PATH)
|
42
|
-
|
43
|
-
run_command("#{browserify_cmd} #{params} #{pathname}")
|
44
|
-
else
|
45
|
-
data
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
def commonjs_module?(data)
|
50
|
-
data.to_s.include?('module.exports') || data.to_s.include?('require')
|
51
|
-
end
|
52
|
-
|
53
|
-
def run_command(command)
|
54
|
-
stdin, stdout, stderr = Open3.popen3("#{command}")
|
55
|
-
begin
|
56
|
-
result = stdout.read
|
57
|
-
result_error = stderr.read.strip
|
58
|
-
if result_error.empty?
|
59
|
-
result
|
60
|
-
else
|
61
|
-
raise ModuleDepsError, result_error
|
62
|
-
end
|
63
|
-
ensure
|
64
|
-
stdin.close
|
65
|
-
stdout.close
|
66
|
-
stderr.close
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|