sprockets-commoner 0.2.2 → 0.2.3

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: 0e07853296174bca18616b5f0a8021b4830b33de
4
- data.tar.gz: f3a207b0a0b047889f21c1d75d5a3f1b2d491822
3
+ metadata.gz: a1b9fda2acf409f31fb052204e5319eecc1b9ed2
4
+ data.tar.gz: 8b5eee7b0be2cce4141b62388fd83fdf99b0c41d
5
5
  SHA512:
6
- metadata.gz: 081005224d924d04f646d027e6c618efc591bc157533f21b805ff48ec85ec7ccc199ffe4aaa4561d12fed8ab22ecaa067758b8f343d18ef75f864e4531a44a47
7
- data.tar.gz: 1d24a89e58c518190f34c6192c3a132d7f53235d533b518080afcbb02cef51afa1acf3a300c5f2964acbeddff95683d2d2ee37b8a2be0dd6a208cf632ba4e84d
6
+ metadata.gz: b77a61c55a9dcbf6c7f9f81a7bd48d926519f8b5e56fedcc07eace32841cc1e6e5ca31079faf4e0b91a1aac9797ee912e2dfd7c345a2f3b8d15e7920ab93fc13
7
+ data.tar.gz: 589434178aa3f2156952ec3aadf726bc1617cbe75a8ec3124940a7a4b973e04300bb9ced705a18ed6c498c00f55c4fcf4fb911495963505495da7bc627e086ca
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## v0.2.3
4
+
5
+ * Only avoid imports that won't be processed by Commoner if we actually use the module.
6
+
3
7
  ## v0.2.2
4
8
 
5
9
  * Don't cache Babel output as this can lead to bugs.
@@ -15,6 +19,10 @@
15
19
 
16
20
  * Add support for requiring JSON files.
17
21
 
22
+ ## v0.1.3
23
+
24
+ * Backport fixes from v0.2.3
25
+
18
26
  ## v0.1.2
19
27
 
20
28
  * Backport fixes from v0.2.2
@@ -116,7 +116,7 @@ module.exports = function (context) {
116
116
  return '__commoner_module__' + escapedPath;
117
117
  }
118
118
 
119
- function resolveTarget(file, path) {
119
+ function resolveTarget(file, path, ensureTargetIsProcessed) {
120
120
  var name = void 0;
121
121
  if (opts.globals != null && (name = opts.globals[path]) != null) {
122
122
  return name;
@@ -135,10 +135,13 @@ module.exports = function (context) {
135
135
  }
136
136
 
137
137
  if (/\.coffee$/.test(resolvedPath)) {
138
- // If it's a coffee script file, look for global variable assignments
138
+ // If it's a coffee script file, look for global variable assignments.
139
139
  return findDeclarationInCoffeeFile(resolvedPath);
140
140
  } else {
141
- // Otherwise we just look for the module by referencing its Special Identifier™
141
+ if (ensureTargetIsProcessed) {
142
+ file.metadata.targetsToProcess.push(resolvedPath);
143
+ }
144
+ // Otherwise we just look for the module by referencing its Special Identifier™.
142
145
  return pathToIdentifier(resolvedPath);
143
146
  }
144
147
  }
@@ -160,14 +163,14 @@ module.exports = function (context) {
160
163
  return;
161
164
  }
162
165
 
163
- var name = resolveTarget(state.file, target);
166
+ var name = resolveTarget(state.file, target, true);
164
167
  if (name === false) {
165
168
  path.get('init').replaceWith(t.objectExpression([]));
166
- return;
169
+ } else {
170
+ path.scope.rename(name);
171
+ path.scope.rename(path.node.id.name, name);
172
+ path.remove();
167
173
  }
168
- path.scope.rename(name);
169
- path.scope.rename(path.node.id.name, name);
170
- path.remove();
171
174
  },
172
175
  CallExpression: function CallExpression(path, state) {
173
176
  if (!isRequire(path)) {
@@ -179,14 +182,15 @@ module.exports = function (context) {
179
182
  return;
180
183
  }
181
184
 
182
- var replacement = resolveTarget(state.file, target);
183
185
  switch (path.parent.type) {
184
186
  case "ExpressionStatement":
185
- // We just need to know there's a dependency, we can remove it then
187
+ // We just need to know there's a dependency, we can remove the `require` call.
188
+ resolveTarget(state.file, target, false);
186
189
  path.remove();
187
190
  break;
188
191
  default:
189
- // Otherwise we just look for the module by referencing its Special Identifier
192
+ // Otherwise we just look for the module by referencing its Special Identifier™.
193
+ var replacement = resolveTarget(state.file, target, true);
190
194
  if (replacement === false) {
191
195
  path.replaceWith(t.objectExpression([]));
192
196
  } else {
@@ -202,6 +206,9 @@ module.exports = function (context) {
202
206
  if (file.metadata.required == null) {
203
207
  file.metadata.required = [];
204
208
  }
209
+ if (file.metadata.targetsToProcess == null) {
210
+ file.metadata.targetsToProcess = [];
211
+ }
205
212
  },
206
213
 
207
214
  visitor: {
@@ -11,7 +11,6 @@ module Sprockets
11
11
  PACKAGE_JSON = 'package.json'.freeze
12
12
  JS_PACKAGE_PATH = File.expand_path('../../../js', __dir__)
13
13
  ALLOWED_EXTENSIONS = /\.js(?:on)?(?:\.erb)?\z/
14
- COFFEE_EXTENSION = /\.coffee(:?\.erb)?\z/
15
14
 
16
15
  dependencies babel: 'babel-core', commoner: 'babel-plugin-sprockets-commoner-internal'
17
16
 
@@ -70,11 +69,16 @@ module Sprockets
70
69
 
71
70
  result = transform(input[:data], options(input), paths: @env.paths)
72
71
 
72
+ if result['metadata'].has_key?('targetsToProcess')
73
+ result['metadata']['targetsToProcess'].each do |t|
74
+ unless should_process?(t)
75
+ raise ExcludedFileError, "#{t} was imported from #{filename} but this file won't be processed by Sprockets::Commoner"
76
+ end
77
+ end
78
+ end
79
+
73
80
  if result['metadata'].has_key?('required')
74
81
  result['metadata']['required'].each do |r|
75
- unless COFFEE_EXTENSION =~ r || should_process?(r)
76
- raise ExcludedFileError, "#{r} was imported from #{filename} but this file won't be processed by Sprockets::Commoner"
77
- end
78
82
  asset = resolve(r, accept: input[:content_type], pipeline: :self)
79
83
  @required.insert(insertion_index, asset)
80
84
  end
@@ -1,5 +1,5 @@
1
1
  module Sprockets
2
2
  module Commoner
3
- VERSION = '0.2.2'
3
+ VERSION = '0.2.3'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sprockets-commoner
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bouke van der Bijl