sprockets-commoner 0.6.3 → 0.6.4

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: 9ff180d659ed6740f08d3ea240c4c839134bd40a
4
- data.tar.gz: 707b8cbd232bb7feb41abc8f4e95b64fae3088d8
3
+ metadata.gz: 4b1327821fb74f7b7ad9a60cef8d479982d1b87e
4
+ data.tar.gz: 4b4b0f98e15ddf7b753de081de21fa9d38cf2bef
5
5
  SHA512:
6
- metadata.gz: a29bdeff52324bb60dfd150ca2037853e62b942541d0cb191bd69fef86c8cf1bca186674926a74637e4d020b8d40b87a91cbc9bb0ea9a1d3649228216e6bc3fc
7
- data.tar.gz: ba509adca807ef8b90d02ffee2f798a4244af127698c18dff86313bcebf33f010d86d52be7d784c66f30400ee0ea480368ff85250ff6c7ecf6a9dbcdc6cbed30
6
+ metadata.gz: 1a2f95fc8ab129da96a52f21f4229f050a1b1b65b6ecfbdafdb994e9a80835b298c9a116168f037d009cd1d1e9422d655984238589aa7ba8cec4865294f0f46f
7
+ data.tar.gz: 1af98e196a45aac1d2b8410d58f7351088e9224fde68c54ff95c1318c6a04c80115b2026b2bc501e11cfdfece8c9a22a63a7d16485b2790cbec6f38da4db7c1b
data/.gitignore CHANGED
@@ -9,3 +9,4 @@
9
9
  /tmp/
10
10
  node_modules
11
11
  npm-debug.log
12
+ yarn.lock
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## v0.6.4
4
+
5
+ * Add support for ExecJS.
6
+
3
7
  ## v0.6.2
4
8
 
5
9
  * Add support for Sprockets 4
data/Gemfile CHANGED
@@ -1,3 +1,13 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
+ group :development, :test do
4
+ gem 'sprockets', github: 'rails/sprockets'
5
+ end
6
+
7
+ group :development do
8
+ gem 'pry'
9
+ gem 'pry-rescue'
10
+ gem 'pry-stack_explorer'
11
+ end
12
+
3
13
  gemspec
data/README.md CHANGED
@@ -17,7 +17,7 @@
17
17
  ### Requirements
18
18
 
19
19
  1. Ruby v2+.
20
- 2. Rails/Any other application that uses Sprockets.
20
+ 2. Rails 4+/Any other application that uses Sprockets 3+.
21
21
  2. NPM v3+. We only support version 3 because commoner doesn't do any sort of deduplication of dependencies, so you could end up with a huge bundle if you don't want out. We only test against version 3, so you will definitely run into issues when running version 2.
22
22
  3. We recommend and support version 4+ of Node.js.
23
23
 
@@ -37,7 +37,7 @@ console.log(_.map([1, 2, 3], function(n) { return n * 3; }));
37
37
  ### Enabling Babel transforms
38
38
 
39
39
  1. Install any Babel plugins or presets you want to use. We'll use the default ES2015 preset; `npm install babel-preset-es2015`.
40
- 1. Add a `.babelrc` with you required configuration. We just need to do `echo '{presets: ["es2015"]}' > .babelrc`.
40
+ 1. Add a `.babelrc` with you required configuration. We just need to do `echo '{"presets": ["es2015"]}' > .babelrc`.
41
41
  1. Use any feature you want! For example, let's use `import` and arrow functions in our `application.js`:
42
42
 
43
43
  ```javascript
@@ -57,11 +57,11 @@ By default, commoner will process any file under the application root directory.
57
57
  Rails.application.config.assets.configure do |env|
58
58
  Sprockets::Commoner::Processor.configure(env,
59
59
  # include, exclude, and babel_exclude patterns can be path prefixes or regexes.
60
- # Explicitely list paths to include. The default is `[env.root]`
60
+ # Explicitly list paths to include. The default is `[env.root]`
61
61
  include: ['app/assets/javascripts/subdirectory'],
62
62
  # List files to ignore and not process require calls or apply any Babel transforms to. Default is ['vendor/bundle'].
63
63
  exclude: ['vendor/bundle', /ignored/],
64
- # Anything listed in babel_exclude has its require calls resolved, but no transforms listed in .babelrcs applied.
64
+ # Anything listed in babel_exclude has its require calls resolved, but no transforms listed in .babelrc applied.
65
65
  # Default is [/node_modules/]
66
66
  babel_exclude: [/node_modules/]
67
67
  )
data/bin/setup CHANGED
@@ -4,12 +4,15 @@ set -euo pipefail
4
4
  gem install bundler --version '1.11.2'
5
5
  bundle check || bundle install -j 4
6
6
 
7
- for path in "./test/fixtures" "./test/fixtures/vendor-stub" "./js/babel-plugin-sprockets-commoner-internal" "./test/fixtures/root-node-modules" "./test/demo"; do
7
+ for path in "./test/fixtures" "./test/fixtures/vendor-stub" "./test/fixtures/root-node-modules" "./test/demo"; do
8
8
  pushd "$path" >/dev/null
9
- npm install
9
+ yarn install
10
10
  popd >/dev/null
11
11
  done
12
+ pushd "./js/babel-plugin-sprockets-commoner-internal"
13
+ npm install
14
+ popd>/dev/null
12
15
 
13
16
  pushd "./test/demo"
14
17
  bundle check || bundle install -j 4
15
- popd
18
+ popd>/dev/null
data/circle.yml CHANGED
@@ -6,7 +6,12 @@ machine:
6
6
 
7
7
  dependencies:
8
8
  override:
9
+ - curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
10
+ - echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
11
+ - sudo apt-get update && sudo apt-get install yarn
9
12
  - bin/setup
13
+ cache_directories:
14
+ - ~/.cache/yarn
10
15
 
11
16
  test:
12
17
  override:
@@ -5,6 +5,9 @@ require 'sprockets/commoner/bundle'
5
5
 
6
6
  module Sprockets
7
7
  module Commoner
8
+ def self.sprockets4?
9
+ @@sprockets4 ||= Gem::Version.new(Sprockets::VERSION) >= Gem::Version.new('4.0.0.beta')
10
+ end
8
11
  end
9
12
 
10
13
  register_postprocessor 'application/javascript', ::Sprockets::Commoner::Processor
@@ -29,17 +29,16 @@ function(helpers, globalIdentifiers) {
29
29
  JS
30
30
 
31
31
  PRELUDE = <<-JS.freeze
32
- !function() {
32
+ !function(global) {
33
33
  var __commoner_initialize_module__ = function(f) {
34
34
  var module = {exports: {}};
35
35
  f.call(module.exports, module, module.exports);
36
36
  return module.exports;
37
37
  };
38
- var global = window;
39
38
  JS
40
39
 
41
40
  OUTRO = <<-JS.freeze
42
- }();
41
+ }(typeof global != 'undefined' ? global : typeof window != 'undefined' ? window : this);
43
42
  JS
44
43
  def initialize(root)
45
44
  super(root, 'NODE_PATH' => JS_PACKAGE_PATH)
@@ -63,10 +62,10 @@ JS
63
62
  assets_missing = input[:metadata][:commoner_required] - assets_in_bundle
64
63
 
65
64
  global_identifiers = assets_missing.map do |filename|
66
- uri, _ = if Sprockets::VERSION < '4'
67
- env.resolve(filename, accept: input[:content_type], pipeline: :self, compat: false)
68
- else
65
+ uri, _ = if Commoner.sprockets4?
69
66
  env.resolve(filename, accept: input[:content_type], pipeline: :self)
67
+ else
68
+ env.resolve(filename, accept: input[:content_type], pipeline: :self, compat: false)
70
69
  end
71
70
  asset = env.load(uri)
72
71
  # Retrieve the global variable the file is exposed through
@@ -78,9 +77,26 @@ JS
78
77
  used_helpers = input[:metadata][:commoner_used_helpers].to_a
79
78
  header_code = generate_header(used_helpers, global_identifiers)
80
79
  {
81
- data: "#{PRELUDE}#{header_code}\n#{input[:data]}#{OUTRO}"
80
+ data: "#{PRELUDE}#{header_code}\n#{input[:data]}#{OUTRO}",
81
+ map: shift_map(input[:metadata][:map], PRELUDE.lines.count + header_code.lines.count),
82
82
  }
83
83
  end
84
+
85
+ private
86
+
87
+ def shift_map(map, offset)
88
+ return unless map && Commoner.sprockets4?
89
+ index_map = Sprockets::SourceMapUtils.make_index_map(map)
90
+ index_map.merge({
91
+ "sections" => index_map["sections"].map { |section|
92
+ section.merge({
93
+ "offset" => section["offset"].merge({
94
+ "line" => section["offset"]["line"] + offset
95
+ })
96
+ })
97
+ }
98
+ })
99
+ end
84
100
  end
85
101
  end
86
102
  end
@@ -104,10 +104,13 @@ module Sprockets
104
104
  @dependencies << "commoner-environment-variable:#{env}"
105
105
  end
106
106
 
107
+ map = process_map(input[:metadata][:map], result['map'], input)
108
+
107
109
  {
108
110
  data: result['code'],
109
111
  dependencies: @dependencies,
110
112
  required: Set.new(@required),
113
+ map: map,
111
114
 
112
115
  commoner_global_identifier: result['metadata']['globalIdentifier'],
113
116
  commoner_required: commoner_required,
@@ -117,6 +120,13 @@ module Sprockets
117
120
  end
118
121
 
119
122
  private
123
+ def process_map(oldmap, map, input)
124
+ if Commoner.sprockets4?
125
+ formatted_map = Sprockets::SourceMapUtils.format_source_map(map, input)
126
+ Sprockets::SourceMapUtils.combine_source_maps(oldmap, formatted_map)
127
+ end
128
+ end
129
+
120
130
  def compute_cache_key
121
131
  package_file = File.join(@root, 'node_modules', 'babel-core', 'package.json')
122
132
  raise Schmooze::DependencyError, 'Cannot determine babel version as babel-core has not been installed' unless File.exist?(package_file)
@@ -197,7 +207,6 @@ module Sprockets
197
207
  end
198
208
 
199
209
  def options(input)
200
- # TODO(bouk): Fix sourcemaps. Sourcemaps are only available in Sprockets v4
201
210
  {
202
211
  'ast' => false,
203
212
  'babelrc' => !match_any?(self.babel_exclude, input[:filename]),
@@ -205,6 +214,7 @@ module Sprockets
205
214
  'filenameRelative' => PathUtils.split_subpath(input[:load_path], input[:filename]),
206
215
  'moduleRoot' => nil,
207
216
  'sourceRoot' => @env.root,
217
+ 'sourceMaps' => Commoner.sprockets4?,
208
218
  }
209
219
  end
210
220
 
@@ -3,7 +3,8 @@ module Sprockets
3
3
  class Railtie < ::Rails::Railtie
4
4
  initializer 'sprockets-commoner' do
5
5
  # We need to disable debugging because otherwise Rails will include each file individually, while we need everything to be bundled up together into a single file.
6
- config.assets.debug = false
6
+ # ^ Not applicable to sprockets 4+
7
+ config.assets.debug = false unless Commoner.sprockets4?
7
8
  config.assets.paths << 'node_modules'
8
9
  end
9
10
  end
@@ -1,5 +1,5 @@
1
1
  module Sprockets
2
2
  module Commoner
3
- VERSION = '0.6.3'
3
+ VERSION = '0.6.4'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sprockets-commoner
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.3
4
+ version: 0.6.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bouke van der Bijl
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-09-29 00:00:00.000000000 Z
11
+ date: 2017-03-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sprockets
@@ -182,7 +182,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
182
182
  version: '0'
183
183
  requirements: []
184
184
  rubyforge_project:
185
- rubygems_version: 2.5.1
185
+ rubygems_version: 2.6.10
186
186
  signing_key:
187
187
  specification_version: 4
188
188
  summary: Use Babel in Sprockets to compile modules for the browser