hsume2-browserify-rails 0.1.0 → 0.2.1

This diff has not been reviewed by any users.
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 469695df5508ae4f129ba905b0735f0926e54056
4
- data.tar.gz: 507fde818f2e615d2eaa38b4175d7496aa177368
3
+ metadata.gz: 1cfe8c2634c87114f8c83d1d4b8ea1a9b690dbd0
4
+ data.tar.gz: 7c7170d2a116dec99bd786c71f9d22a4116a477b
5
5
  SHA512:
6
- metadata.gz: 6d78c3dcb29c3882b5eccb993401b643945fbe9c94c82288ca5a3fbdbb7659382f1f832643b9ec9e87ad76cafd5a94294ce89451db43b9ef3cb33d817e638c61
7
- data.tar.gz: 0c3406fb50d87677e2d623a8a418a6163fce0cd62279a42e66a6ea5ff86737208359d11f2d1da170817719d82077dc0d4d7e5f5f292ee08c8063aaeb9a012ffd
6
+ metadata.gz: d1b467af74253ecc9b46cb13fae112ec518c763755eced4ea2fa67a4a99ba48f6e5bdbed74c9d45f2645927439da1a780229e88e6b2576925a5ffaeb82df4733
7
+ data.tar.gz: 6c282412818608c37e746d380089de702ffb11fa244f7f877a274ab88b445965d20225bbe4d1f6ea5f406c7e3924eef839502f1ff8a7f2476cfd4d2970c47542
data/.gitignore CHANGED
@@ -23,3 +23,4 @@ test/dummy/public/system
23
23
  test/dummy/db/schema.rb
24
24
  tmp
25
25
  test/dummy/app/assets/javascripts/*.js
26
+ test/dummy/app/assets/javascripts/**/*.js
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 'hsume2-browserify-rails'
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": "2.13.x",
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
- If you want to use coffeescript files, add coffeeify as a dependency on `package.json`:
54
- ```js
55
- {
56
- "name": "something",
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)
@@ -1,8 +1,9 @@
1
- require 'sprockets'
1
+ require "sprockets"
2
2
 
3
- require 'browserify-rails/directive_processor'
4
- require 'browserify-rails/railtie'
5
- require 'browserify-rails/version'
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,5 @@
1
+ module BrowserifyRails
2
+ # Something went wrong while executing browserify
3
+ class BrowserifyError < RuntimeError
4
+ end
5
+ 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 'application/javascript', BrowserifyRails::DirectiveProcessor
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__),'tasks/*.rake')].each { |f| load f }
8
+ Dir[File.join(File.dirname(__FILE__), "tasks/*.rake")].each { |f| load f }
10
9
  end
11
-
12
10
  end
13
- end
11
+ end
@@ -1,3 +1,3 @@
1
1
  module BrowserifyRails
2
- VERSION = '0.1.0'
2
+ VERSION = "0.2.1"
3
3
  end
@@ -3,36 +3,84 @@ require 'test_helper'
3
3
  class BrowserifyTest < ActionController::IntegrationTest
4
4
 
5
5
  setup do
6
- FileUtils.rm_rf(File.join(Rails.root, 'tmp/cache'))
7
- FileUtils.mkdir_p(File.join(Rails.root, 'tmp'))
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
- assert @response.body.include? ";(function(e,t,n){function i(n,s){if(!t[n]){if(!e[n]){var o=typeof require==\"function\"&&require;if(!s&&o)return o(n,!0);if(r)return r(n,!0);throw new Error(\"Cannot find module '\"+n+\"'\")}var u=t[n]={exports:{}};e[n][0].call(u.exports,function(t){var r=e[n][1][t];return i(r?r:t)},u,u.exports)}return t[n].exports}var r=typeof require==\"function\"&&require;for(var s=0;s<n.length;s++)i(n[s]);return i})({1:[function(require,module,exports){\nvar foo = require('./foo');\n\n},{\"./foo\":2}],2:[function(require,module,exports){\nmodule.exports = function (n) { return n * 11 }\n\n},{}]},{},[1])\n"
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
- assert @response.body.include? ";(function(e,t,n){function i(n,s){if(!t[n]){if(!e[n]){var o=typeof require==\"function\"&&require;if(!s&&o)return o(n,!0);if(r)return r(n,!0);throw new Error(\"Cannot find module '\"+n+\"'\")}var u=t[n]={exports:{}};e[n][0].call(u.exports,function(t){var r=e[n][1][t];return i(r?r:t)},u,u.exports)}return t[n].exports}var r=typeof require==\"function\"&&require;for(var s=0;s<n.length;s++)i(n[s]);return i})({1:[function(require,module,exports){\nmodule.exports = function (n) { return n * 11 }\n\n},{}]},{},[1])\n"
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
- assert @response.body.include? ";(function(e,t,n){function i(n,s){if(!t[n]){if(!e[n]){var o=typeof require==\"function\"&&require;if(!s&&o)return o(n,!0);if(r)return r(n,!0);throw new Error(\"Cannot find module '\"+n+\"'\")}var u=t[n]={exports:{}};e[n][0].call(u.exports,function(t){var r=e[n][1][t];return i(r?r:t)},u,u.exports)}return t[n].exports}var r=typeof require==\"function\"&&require;for(var s=0;s<n.length;s++)i(n[s]);return i})({1:[function(require,module,exports){\nvar foo = require('./foo');\n\n},{\"./foo\":2}],2:[function(require,module,exports){\nmodule.exports = function (n) { return n * 11 }\n\n},{}]},{},[1])\n"
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
- assert @response.body.include? ";(function(e,t,n){function i(n,s){if(!t[n]){if(!e[n]){var o=typeof require==\"function\"&&require;if(!s&&o)return o(n,!0);if(r)return r(n,!0);throw new Error(\"Cannot find module '\"+n+\"'\")}var u=t[n]={exports:{}};e[n][0].call(u.exports,function(t){var r=e[n][1][t];return i(r?r:t)},u,u.exports)}return t[n].exports}var r=typeof require==\"function\"&&require;for(var s=0;s<n.length;s++)i(n[s]);return i})({1:[function(require,module,exports){\nvar foo = require('./foo');\n\n},{\"./foo\":2}],2:[function(require,module,exports){\nmodule.exports = function (n) { return n * 12 }\n\n},{}]},{},[1])\n"
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
@@ -1 +1,2 @@
1
+ require('./nested');
1
2
  module.exports = function (n) { return n * 11 }
@@ -0,0 +1 @@
1
+ module.exports.NESTED = true;
@@ -3,11 +3,10 @@
3
3
  "author": "Henry Hsu <hhsu@zendesk.com>",
4
4
  "description": "a dummy Rails application",
5
5
  "devDependencies" : {
6
- "browserify": "2.13.x",
7
- "module-deps": "1.7.x"
6
+ "browserify": "~> 3.33"
8
7
  },
9
8
  "license": "MIT",
10
9
  "engines": {
11
- "node": ">= 0.6"
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.0
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-24 00:00:00.000000000 Z
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/directive_processor.rb
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