sprockets-commoner 0.1.2 → 0.1.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: e7413c6a1d1cd9cd4e4d2a3edf3c2d0482672cce
4
- data.tar.gz: c9504e240f43982f261bb8aa23cc20b961f246af
3
+ metadata.gz: c0f64fc540ae4a4e9d1e7113bebd91a5453598e7
4
+ data.tar.gz: 10254542506d4e61dc2f055b43951781c1601b15
5
5
  SHA512:
6
- metadata.gz: 695aaa8c418489ab2f6a4fcca64b0e858c77ad1cd1ec3718e9f8a4a6e496c65f40fefa7b6c304144f3eb935c9e9f1c7c73380f021516e567bbf44cb8e49a5913
7
- data.tar.gz: 86378f61500f8a7de324dc441dee9ff7a46c824425fe68cfa946e41166eb68f908a7fdb439b728bfe98f5207db7390dfd5e6a03aa03efc014196bde013a1649b
6
+ metadata.gz: d52f46af8d4abb7b4b9241556217505a2ba5acc9f072ca09a0cb0a2f722fcace33a78e9531b7210e652d277669c877e384c797fb66a7ba3befef924f6a7cc066
7
+ data.tar.gz: 6dfd607e5b3593bd3c04d3d1e834a7d02e0611f6821f03af59a51db743ec42dd2b4554fb5bd4897d3e37a556a4d8e8777ce975ff68c698b3a30899c4f79ff4a3
@@ -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: {
@@ -70,11 +70,16 @@ module Sprockets
70
70
 
71
71
  result = transform(input[:data], options(input), paths: @env.paths)
72
72
 
73
+ if result['metadata'].has_key?('targetsToProcess')
74
+ result['metadata']['targetsToProcess'].each do |t|
75
+ unless should_process?(t)
76
+ raise ExcludedFileError, "#{t} was imported from #{filename} but this file won't be processed by Sprockets::Commoner"
77
+ end
78
+ end
79
+ end
80
+
73
81
  if result['metadata'].has_key?('required')
74
82
  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
83
  asset = resolve(r, accept: input[:content_type], pipeline: :self)
79
84
  @required.insert(insertion_index, asset)
80
85
  end
@@ -1,5 +1,5 @@
1
1
  module Sprockets
2
2
  module Commoner
3
- VERSION = '0.1.2'
3
+ VERSION = '0.1.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.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bouke van der Bijl