condenser 0.1 → 0.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 78e391e2e34c47daeb8d0489f2ba3567d24ba9a2fecee0c8457c65276bbb6886
4
- data.tar.gz: 354fd3b42f9eb4636a94babb725f87c0c4ea037c0943fa82380eb6f35a169338
3
+ metadata.gz: bce2f9e63c85791fe398be271a8384c0c1ee1bebda8b6cb4576d797c73fd2095
4
+ data.tar.gz: ac1375ba4585e172d2fa8eca13e381773e5c76651ec871b23306fd435f5c026d
5
5
  SHA512:
6
- metadata.gz: a0bf3d990b15d7b225b8d0af09da4359e95e4add21222bbace313ac8a7b6833a40ee17257498e5f2a65a8fa13f47a6467bb9eae910c6acdbd2ddf7ab64b45ac2
7
- data.tar.gz: cff15370f99605a8f87c1e313afbb65efc169acf4df4877c44acbe6b0ea36a2a772ecb98641e5c093fb1d658d35b2d562968d890a5ee328d764d3e8229a6c9aa
6
+ metadata.gz: 10b483f5a68484ec0841c6fde493100f1a13a1037b02b9f3ad4ebc38112711ad9deef64335f51dd1afdd15bf043d6db308171424daad54a3b58f34b5f3d2feed
7
+ data.tar.gz: a7e759c7f7e887560d21f497155d4eb57bbdc1dc2e76902f159abc20b6d1c4244576473b080b8906080bc0f2f17a30d1cda4f6d036f65c468d5bb9cfb533bf70
@@ -71,7 +71,7 @@ class Condenser
71
71
  process
72
72
  @process_dependencies
73
73
  end
74
-
74
+
75
75
  d = []
76
76
  deps.each do |i|
77
77
  i = [i, nil] if i.is_a?(String)
@@ -147,6 +147,9 @@ class Condenser
147
147
  Digest::SHA1.base64digest(JSON.generate([
148
148
  Condenser::VERSION,
149
149
  @source_file,
150
+ stat.ino,
151
+ stat.mtime.to_f,
152
+ stat.size,
150
153
  @content_types_digest
151
154
  ]))
152
155
  end
@@ -154,7 +157,7 @@ class Condenser
154
157
  def process_cache_version
155
158
  return @pcv if @pcv
156
159
 
157
- f = [stat.ino, stat.mtime.to_f, stat.size]
160
+ f = []
158
161
  all_dependenies(process_dependencies, [], :process_dependencies) do |dep|
159
162
  f << [dep.source_file, dep.stat.ino, dep.stat.mtime.to_f, dep.stat.size]
160
163
  end
@@ -165,7 +168,7 @@ class Condenser
165
168
  def export_cache_version
166
169
  return @ecv if @ecv
167
170
 
168
- f = [stat.ino, stat.mtime.to_f, stat.size]
171
+ f = []
169
172
  all_dependenies(export_dependencies, [], :export_dependencies) do |dep|
170
173
  f << [dep.source_file, dep.stat.ino, dep.stat.mtime.to_f, dep.stat.size]
171
174
  end
@@ -37,29 +37,47 @@ class Condenser
37
37
  globs << file.match(/([^\.]+)(\.|$)/).to_a[1]
38
38
  if path_match = @path.find { |p| file.start_with?(p) }
39
39
  a = file.delete_prefix(path_match).match(/([^\.]+)(\.|$)/).to_a[1]
40
- b = (File.dirname(a) + "/*")
40
+ b = File.join(File.dirname(a), "*")
41
41
 
42
42
  globs << a << a.delete_prefix('/')
43
- globs << a << b.delete_prefix('/')
43
+ globs << b << b.delete_prefix('/')
44
44
  end
45
45
  end
46
-
46
+
47
+ others = []
47
48
  @map_cache&.delete_if do |k,v|
48
49
  if globs.any?{ |a| k.starts_with?(a) }
50
+ @export_dependencies[v.source_file]&.each do |a|
51
+ others << "/#{a.filename}".delete_suffix(File.extname(a.filename))
52
+ end
49
53
  true
50
54
  else
51
55
  false
52
56
  end
53
57
  end
54
-
58
+ @map_cache&.delete_if do |k,v|
59
+ others.any?{ |a| k.starts_with?(a) || k.starts_with?("/" + a) }
60
+ end
61
+
62
+ others = []
55
63
  @lookup_cache.delete_if do |key, value|
56
64
  if globs.any?{ |a| key.starts_with?(a) }
65
+ value.each do |v|
66
+ @export_dependencies[v.source_file]&.each do |a|
67
+ others << "/#{a.filename}".delete_suffix(File.extname(a.filename))
68
+ end
69
+ end
57
70
  value.each do |asset|
58
71
  modified << asset.source_file
59
72
  end
60
73
  true
61
74
  end
62
75
  end
76
+ @lookup_cache&.delete_if do |k,v|
77
+ others.any?{ |a| k.starts_with?(a) || k.starts_with?("/" + a) }
78
+ end
79
+
80
+
63
81
 
64
82
  removed.each do |file|
65
83
  @process_dependencies[file]&.delete_if do |asset|
@@ -1,6 +1,7 @@
1
1
  # Basic Condenser error classes
2
2
  class Condenser
3
- class Error < StandardError; end
3
+ class Error < StandardError; end
4
+ class SyntaxError < ::SyntaxError; end
4
5
  class CommandNotFoundError < Error; end
5
6
  # class ArgumentError < Error; end
6
7
  class ContentTypeMismatch < Error; end
@@ -3,9 +3,6 @@ require File.expand_path('../node_processor', __FILE__)
3
3
 
4
4
  class Condenser::BabelProcessor < Condenser::NodeProcessor
5
5
 
6
- class Error < StandardError
7
- end
8
-
9
6
  # npm install @babel/core @babel/runtime-corejs3 @babel/plugin-transform-runtime @babel/preset-env rollup rollup-plugin-commonjs rollup-plugin-node-resolve @babel/plugin-proposal-class-properties babel-plugin-transform-class-extended-hook
10
7
 
11
8
  def self.call(environment, input)
@@ -90,7 +87,11 @@ class Condenser::BabelProcessor < Condenser::NodeProcessor
90
87
  JS
91
88
 
92
89
  if result['error']
93
- raise exec_runtime_error(result['error'][0] + ': ' + result['error'][1])
90
+ if result['error'][0] == 'SyntaxError'
91
+ raise exec_syntax_error(result['error'][1], "/assets/#{input[:filename]}")
92
+ else
93
+ raise exec_runtime_error(result['error'][0] + ': ' + result['error'][1])
94
+ end
94
95
  else
95
96
  input[:source] = result['code']
96
97
  input[:map] = result['map']
@@ -38,6 +38,15 @@ class Condenser
38
38
  end
39
39
  end
40
40
 
41
+ def exec_syntax_error(output, source_file)
42
+ error = Condenser::SyntaxError.new(output)
43
+ lines = output.split("\n")
44
+ lineno = lines[0][/\((\d+):\d+\)$/, 1] if lines[0]
45
+ lineno ||= 1
46
+ error.set_backtrace(["#{source_file}:#{lineno}"] + caller)
47
+ error
48
+ end
49
+
41
50
  def exec_runtime_error(output)
42
51
  error = RuntimeError.new(output)
43
52
  lines = output.split("\n")
@@ -19,6 +19,7 @@ class Condenser
19
19
  accept = Array(accept)
20
20
 
21
21
  cache_key = [dirname, basename].flatten.join('/')
22
+ cache_key = "/#{cache_key}" if !cache_key.starts_with?('/')
22
23
  cache_key << "@#{accept.join(',')}" if accept
23
24
  build_cache.fetch(cache_key) do
24
25
  build do
@@ -86,7 +87,7 @@ class Condenser
86
87
  end
87
88
 
88
89
  results = results.keys.sort.reduce([]) do |c, key|
89
- c += results[key].sort_by(&:filename)
90
+ c += results[key].sort_by(&:filename).uniq { |f| f.filename }
90
91
  end
91
92
 
92
93
  results.sort_by!(&:filename)
@@ -1,3 +1,3 @@
1
1
  class Condenser
2
- VERSION = '0.1'
2
+ VERSION = '0.2'
3
3
  end
@@ -171,6 +171,14 @@ class CacheTest < ActiveSupport::TestCase
171
171
  assert_exported_file 'a.js', 'application/javascript', <<~JS
172
172
  !function(){"use strict";console.log(10)}();
173
173
  JS
174
+
175
+ file 'a/deps/dep.js', <<-JS
176
+ console.log( 20 );
177
+ JS
178
+
179
+ assert_exported_file 'a.js', 'application/javascript', <<~JS
180
+ !function(){"use strict";console.log(20)}();
181
+ JS
174
182
  end
175
183
 
176
184
  test 'a new dependency for a glob call is reflected in the next call' do
@@ -24,6 +24,27 @@ class CondenserBabelTest < ActiveSupport::TestCase
24
24
  JS
25
25
  end
26
26
 
27
+ test "error" do
28
+ file 'error.js', <<~JS
29
+ console.log('this file has an error');
30
+
31
+ var error = {;
32
+ JS
33
+
34
+ e = assert_raises Condenser::SyntaxError do
35
+ assert_file 'error.js', 'application/javascript'
36
+ end
37
+ assert_equal <<~ERROR.rstrip, e.message.rstrip
38
+ /assets/error.js: Unexpected token (3:13)
39
+
40
+ 1 | console.log('this file has an error');
41
+ 2 |
42
+ > 3 | var error = {;
43
+ | ^
44
+ 4 |
45
+ ERROR
46
+ end
47
+
27
48
  test 'not duplicating babel-helpers' do
28
49
  file 'a.js', <<-JS
29
50
  export default class {
@@ -14,6 +14,7 @@ require 'condenser'
14
14
  require 'condenser/server'
15
15
  require 'condenser/cache/memory_store'
16
16
 
17
+ require 'byebug'
17
18
  require "active_support"
18
19
  require "active_support/testing/autorun"
19
20
  require 'mocha/minitest'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: condenser
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.1'
4
+ version: '0.2'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jon Bracy
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-01-17 00:00:00.000000000 Z
11
+ date: 2020-01-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: erubi