isomorfeus-asset-manager 0.13.3 → 0.13.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
  SHA256:
3
- metadata.gz: aca011238408ac3f1a13c4aeae9a32a7897eda12c1680d54773cf8c48b501302
4
- data.tar.gz: 8fdd2a8f8ffe4d2ee2e2544db17a33b42f83df77498c53898356c5563ae859f1
3
+ metadata.gz: 57c6e9cbf3cca3ff51230dc1d5d138d41d0c52c22a3dac313ef74d0103e2021c
4
+ data.tar.gz: 0f2aecd3cced8363965e0514bd8e64dcfa82df116e9ade38bb340d873b70bc27
5
5
  SHA512:
6
- metadata.gz: fc65d991ab1aa2ddb8da5118cb9d29cb505d9a51f5ec864fb667ec62e288541b1d26898ee549d4d0336bdbb21a67005630bd2220b3d0c6a502dca635645b100c
7
- data.tar.gz: fd042923175fe0e57bb8bbe455ca3c7d98e3d781a89728f40a91a8eaa1f6d87c4cab0d2450283021403e3ae1642eebe2a81e7afb1b1bfef9c0eb75127c92dba6
6
+ metadata.gz: '079db8abd836f1d0a720ffa0b6905d31cb7c22e78ca4b8be079d4b58762dd4fa4c70438831bd3bb312acc678dfcda0fcd1c4033126f8df52aff38bfec66e9327'
7
+ data.tar.gz: bf2092bd1ca8f2d19b150ada7eb6efb054fda1d9dcf295866146b9e9ea19e24ab223f8f49110cb6b388fce819a262d737ac110aded218966c1592abcd4635b26
@@ -3,8 +3,12 @@ module Isomorfeus
3
3
  class Asset
4
4
  attr_reader :bundle, :bundle_size
5
5
  attr_reader :bundle_gz, :bundle_gz_size
6
- attr_reader :bundle_map
7
- attr_reader :bundle_map_gz
6
+ attr_reader :bundle_map, :bundle_map_size
7
+ attr_reader :bundle_map_gz, :bundle_map_gz_size
8
+ attr_reader :css, :css_size
9
+ attr_reader :css_gz, :css_gz_size
10
+ attr_reader :css_map, :css_map_size
11
+ attr_reader :css_map_gz, :css_map_gz_size
8
12
  attr_reader :mtime, :ruby_imports, :target
9
13
  attr_reader :mutex
10
14
 
@@ -13,6 +17,7 @@ module Isomorfeus
13
17
  raise "Unknown asset target!" unless %i[browser node].include?(target)
14
18
  @target = target
15
19
  @bundled = false
20
+ @css_bundled = false
16
21
  @ruby_compiled = false
17
22
  @js_imports = []
18
23
  @ruby_imports = []
@@ -26,21 +31,24 @@ module Isomorfeus
26
31
  @ruby_imports << Isomorfeus::AssetManager::RubyImport.new(*args)
27
32
  end
28
33
 
29
- def bundle=(b)
34
+ def bundle=(b)
30
35
  @bundled = true
31
36
  @bundle = b
32
37
  @bundle_size = @bundle.size
33
38
  unless @target == :node
34
- @bundle_gz = Zlib::gzip(b, level: Zlib::BEST_COMPRESSION)
39
+ @bundle_gz = Zlib::gzip(b, level: Zlib::BEST_COMPRESSION)
35
40
  @bundle_gz_size = @bundle_gz.size
36
41
  end
37
42
  @bundle
38
43
  end
39
44
 
40
- def bundle_map=(m)
45
+ def bundle_map=(m)
41
46
  @bundled = true
42
47
  @bundle_map = m
43
- @bundle_map_gz = Zlib::gzip(m, level: Zlib::BEST_COMPRESSION) unless @target == :node
48
+ unless @target == :node
49
+ @bundle_map_gz = Zlib::gzip(m, level: Zlib::BEST_COMPRESSION)
50
+ @bundle_map_gz_size = @bundle_map_gz.size
51
+ end
44
52
  @bundle_map
45
53
  end
46
54
 
@@ -48,6 +56,38 @@ module Isomorfeus
48
56
  @bundled
49
57
  end
50
58
 
59
+ def css=(b)
60
+ @bundled = true
61
+ if b
62
+ @has_css = true
63
+ @css = b
64
+ @css_size = @css.size
65
+ unless @target == :node
66
+ @css_gz = Zlib::gzip(b, level: Zlib::BEST_COMPRESSION)
67
+ @css_gz_size = @bundle_gz.size
68
+ end
69
+ end
70
+ @css
71
+ end
72
+
73
+ def css_map=(m)
74
+ @bundled = true
75
+ if m
76
+ @has_css = true
77
+ @css_map = m
78
+ @css_map_size = @css_map.size
79
+ unless @target == :node
80
+ @css_map_gz = Zlib::gzip(m, level: Zlib::BEST_COMPRESSION)
81
+ @css_map_gz_size = @css_map_gz.size
82
+ end
83
+ end
84
+ @css_map
85
+ end
86
+
87
+ def has_css?
88
+ @has_css
89
+ end
90
+
51
91
  def ruby_modules
52
92
  @ruby_imports.map(&:module_name)
53
93
  end
@@ -79,7 +119,7 @@ module Isomorfeus
79
119
  if (typeof Opal !== 'undefined' && typeof Opal.require_table !== "undefined" && Opal.require_table['corelib/module']) {
80
120
  try {
81
121
  eval(update.javascript);
82
- if (Opal.require_table[opal_module_name]) { Opal.load.call(Opal, opal_module_name); }
122
+ if (Opal.require_table[opal_module_name]) { Opal.load.call(Opal, opal_module_name); }
83
123
  else { Opal.require.call(Opal, opal_module_name); }
84
124
  Opal.Isomorfeus.$force_render();
85
125
  } catch (e) { console.error(e); return; }
@@ -9,7 +9,7 @@ module Isomorfeus
9
9
  def initialize(app)
10
10
  @app = app
11
11
  @asset_manager = Isomorfeus::AssetManager.new
12
- @compressible_types = %w[application/javascript text/javascript]
12
+ @compressible_types = %w[application/javascript text/javascript text/css]
13
13
  if Isomorfeus.assets_path.end_with?('/')
14
14
  @assets_path = Isomorfeus.assets_path
15
15
  @assets_path_size = @assets_path.size
@@ -24,45 +24,87 @@ module Isomorfeus
24
24
  def call(env)
25
25
  path_info = env['PATH_INFO']
26
26
  if path_info.start_with?(@assets_path)
27
- asset_key = path_info[@assets_path_size..-1]
28
27
 
29
- # get js
30
- if Isomorfeus.assets.key?(asset_key)
28
+ if path_info.end_with?('.js')
29
+ # get js
30
+ asset_key = path_info[@assets_path_size..-1]
31
+ if Isomorfeus.assets.key?(asset_key)
32
+ asset = Isomorfeus.assets[asset_key]
33
+ if asset && asset.target != :node
34
+ asset_manager.transition(asset_key, asset)
35
+ headers = {}
36
+ headers['Last-Modified'] = asset.mtime
37
+ headers[Rack::CONTENT_TYPE] = 'application/javascript'
38
+ if should_gzip?(env)
39
+ headers['Content-Encoding'] = "gzip"
40
+ headers[Rack::CONTENT_LENGTH] = asset.bundle_gz_size
41
+ return [200, headers, asset.bundle_gz]
42
+ else
43
+ headers[Rack::CONTENT_LENGTH] = asset.bundle_size
44
+ return [200, {}, asset.bundle]
45
+ end
46
+ end
47
+ end
48
+
49
+ elsif path_info.end_with?('.js.map')
50
+ # get js source map
51
+ asset_key = path_info[@assets_path_size..-5]
52
+ asset = Isomorfeus.assets[asset_key]
53
+ if asset && asset.target != :node
54
+ asset_manager.transition(asset_key, asset)
55
+ headers = {}
56
+ headers['Last-Modified'] = asset.mtime
57
+ headers[Rack::CONTENT_TYPE] = 'application/json'
58
+ if should_gzip?(env)
59
+ headers['Content-Encoding'] = "gzip"
60
+ headers[Rack::CONTENT_LENGTH] = asset.bundle_map_gz_size
61
+ return [200, headers, asset.bundle_map_gz]
62
+ else
63
+ headers[Rack::CONTENT_LENGTH] = asset.bundle_map_size
64
+ return [200, {}, asset.bundle_map]
65
+ end
66
+ end
67
+
68
+ elsif path_info.end_with?('.css')
69
+ # get css
70
+ asset_key = path_info[@assets_path_size..-5] + '.js'
31
71
  asset = Isomorfeus.assets[asset_key]
32
72
  if asset && asset.target != :node
33
73
  asset_manager.transition(asset_key, asset)
34
74
  headers = {}
35
75
  headers['Last-Modified'] = asset.mtime
36
- headers[Rack::CONTENT_TYPE] = 'application/javascript'
76
+ headers[Rack::CONTENT_TYPE] = 'text/css'
37
77
  if should_gzip?(env)
38
78
  headers['Content-Encoding'] = "gzip"
39
- headers[Rack::CONTENT_LENGTH] = asset.bundle_gz_size
40
- return [200, headers, asset.bundle_gz]
79
+ headers[Rack::CONTENT_LENGTH] = asset.css_gz_size
80
+ return [200, headers, asset.css_gz]
41
81
  else
42
- headers[Rack::CONTENT_LENGTH] = asset.bundle_size
43
- return [200, {}, asset.bundle]
44
- end
82
+ headers[Rack::CONTENT_LENGTH] = asset.css_size
83
+ return [200, {}, asset.css]
84
+ end
45
85
  end
46
-
47
- # get source map
48
- elsif asset_key.end_with?('.js.map')
49
- asset = Isomorfeus.assets[asset_key[0..-5]]
86
+
87
+ elsif path_info.end_with?('.css.map')
88
+ # get css source map
89
+ asset_key = path_info[@assets_path_size..-9] + '.js'
90
+ asset = Isomorfeus.assets[asset_key]
50
91
  if asset && asset.target != :node
51
- asset_manager.transition(asset_key, asset) unless asset.bundled?
92
+ asset_manager.transition(asset_key, asset)
52
93
  headers = {}
53
94
  headers['Last-Modified'] = asset.mtime
54
95
  headers[Rack::CONTENT_TYPE] = 'application/json'
55
96
  if should_gzip?(env)
56
97
  headers['Content-Encoding'] = "gzip"
57
- headers[Rack::CONTENT_LENGTH] = asset.bundle_map_gz.size
58
- return [200, headers, asset.bundle_map_gz]
98
+ headers[Rack::CONTENT_LENGTH] = asset.css_map_gz_size
99
+ return [200, headers, asset.css_map_gz]
59
100
  else
60
- headers[Rack::CONTENT_LENGTH] = asset.bundle_map.size
61
- return [200, {}, asset.bundle_map]
62
- end
101
+ headers[Rack::CONTENT_LENGTH] = asset.css_map_size
102
+ return [200, {}, asset.css_map]
103
+ end
63
104
  end
64
105
  end
65
106
 
107
+ return [404, {}, 'not found']
66
108
  # hot reloading subscription
67
109
  elsif Isomorfeus.development? && path_info == Isomorfeus.assets_websocket_path
68
110
  if env['rack.upgrade?'] == :websocket
@@ -1,5 +1,5 @@
1
1
  module Isomorfeus
2
2
  class AssetManager
3
- VERSION = '0.13.3'
3
+ VERSION = '0.13.4'
4
4
  end
5
5
  end
@@ -4,6 +4,10 @@ module Isomorfeus
4
4
  def script_tag(path)
5
5
  "<script type=\"application/javascript\" src=\"#{Isomorfeus.assets_path}/#{path}\"></script>"
6
6
  end
7
+
8
+ def stylesheet_tag(path)
9
+ "<link rel=\"stylesheet\" type=\"text/css\" href=\"#{Isomorfeus.assets_path}/#{path}\">"
10
+ end
7
11
  end
8
12
  end
9
13
  end
@@ -24,7 +24,7 @@ module Isomorfeus
24
24
 
25
25
  init_hmr_listener if Isomorfeus.development? && !Isomorfeus.hmr_listener
26
26
  end
27
-
27
+
28
28
  def transition(asset_key, asset, analyze: false)
29
29
  return if !Isomorfeus.development? && asset.bundled?
30
30
  asset.mutex.synchronize do
@@ -35,6 +35,8 @@ module Isomorfeus
35
35
  run_esbuild(asset_key, asset, analyze)
36
36
  asset.bundle = bundled_asset(asset_key)
37
37
  asset.bundle_map = bundled_asset_map(asset_key) unless Isomorfeus.production?
38
+ asset.css = bundled_css(asset_key)
39
+ asset.css_map = bundled_css_map(asset_key) unless Isomorfeus.production?
38
40
  end
39
41
  end
40
42
 
@@ -48,6 +50,16 @@ module Isomorfeus
48
50
  File.read(File.join(@output_path, asset_key + '.map'))
49
51
  end
50
52
 
53
+ def bundled_css(asset_key)
54
+ filename = File.join(@output_path, asset_key[0..-4] + '.css')
55
+ File.read(filename) if File.exist?(filename)
56
+ end
57
+
58
+ def bundled_css_map(asset_key)
59
+ filename = File.join(@output_path, asset_key[0..-4] + '.css.map')
60
+ File.read(filename) if File.exist?(filename)
61
+ end
62
+
51
63
  def save_imports(asset_key, asset)
52
64
  File.write(File.join(@imports_path, asset_key), asset.to_s)
53
65
  end
@@ -91,7 +103,7 @@ module Isomorfeus
91
103
  end
92
104
  end
93
105
  end
94
- raise "Asset Manager: error bundling '#{asset_key}'"
106
+ raise "Asset Manager: error bundling '#{asset_key}'"
95
107
  end
96
108
  end
97
109
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: isomorfeus-asset-manager
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.3
4
+ version: 0.13.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Biedermann
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-11-10 00:00:00.000000000 Z
11
+ date: 2021-11-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: isomorfeus-iodine
@@ -72,14 +72,14 @@ dependencies:
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: 1.3.0
75
+ version: 1.3.2
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: 1.3.0
82
+ version: 1.3.2
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: rack
85
85
  requirement: !ruby/object:Gem::Requirement