isomorfeus-asset-manager 0.14.10 → 0.14.11
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 78b774bc55cc59e8fee7021c0cad65221b01885e932f7881cf6f006e45898400
|
4
|
+
data.tar.gz: 76c7b73948ed055aeeca30847e307ef1e7ef7174075463abbfff04555e032df3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9e05e0fdb8f88f717638ba1aece5332d737e7e7e16f0262519386eebb4e92b21af5e31176e76dabed2d19afed09a3b8652922c0365c49625cac3e4827e72f722
|
7
|
+
data.tar.gz: 8a67ce45a8dad7badc69a5e4cff9d617ff0f5bd9e9316d369fc335e190793110696f684ac2289dd31874eeaba25d06e63dcd9f1d543870b7197d61168d813b96
|
@@ -5,6 +5,7 @@ module Isomorfeus
|
|
5
5
|
attr_reader :bundle_gz, :bundle_gz_size
|
6
6
|
attr_reader :bundle_map, :bundle_map_size
|
7
7
|
attr_reader :bundle_map_gz, :bundle_map_gz_size
|
8
|
+
attr_reader :bundle_ruby_modules
|
8
9
|
attr_reader :css, :css_size
|
9
10
|
attr_reader :css_gz, :css_gz_size
|
10
11
|
attr_reader :css_map, :css_map_size
|
@@ -52,6 +53,22 @@ module Isomorfeus
|
|
52
53
|
@bundle_map
|
53
54
|
end
|
54
55
|
|
56
|
+
def bundle_ruby_modules=(m)
|
57
|
+
@bundled = true
|
58
|
+
@bundle_ruby_modules = m
|
59
|
+
if !Isomorfeus.production? && @target != :node
|
60
|
+
@bundle_ruby_modules.each do |key, mod_hash|
|
61
|
+
mod_hash[:js_size] = mod_hash[:js].size
|
62
|
+
mod_hash[:js_gz] = Zlib::gzip(mod_hash[:js], level: Zlib::BEST_COMPRESSION)
|
63
|
+
mod_hash[:js_gz_size] = mod_hash[:js_gz].size
|
64
|
+
mod_hash[:map_size] = mod_hash[:map].size
|
65
|
+
mod_hash[:map_gz] = Zlib::gzip(mod_hash[:map], level: Zlib::BEST_COMPRESSION)
|
66
|
+
mod_hash[:map_gz_size] = mod_hash[:map_gz].size
|
67
|
+
end
|
68
|
+
end
|
69
|
+
@bundle_ruby_modules
|
70
|
+
end
|
71
|
+
|
55
72
|
def bundled?
|
56
73
|
@bundled
|
57
74
|
end
|
@@ -92,6 +109,16 @@ module Isomorfeus
|
|
92
109
|
@ruby_imports.map(&:module_name)
|
93
110
|
end
|
94
111
|
|
112
|
+
def ruby_imports_to_s(asset_name)
|
113
|
+
s = @ruby_imports.size - 1
|
114
|
+
return '' if s < 0
|
115
|
+
js = "async function iam_load_ruby_modules() {\n"
|
116
|
+
@ruby_imports.each do |import|
|
117
|
+
js << ' await ' << import.to_dev_s(asset_name)
|
118
|
+
end
|
119
|
+
js << "}\niam_load_ruby_modules();\n"
|
120
|
+
end
|
121
|
+
|
95
122
|
def touch
|
96
123
|
@mtime = (Time.now.to_f * (10 ** 9)).to_i
|
97
124
|
end
|
@@ -144,7 +171,7 @@ module Isomorfeus
|
|
144
171
|
// Isomorfeus Asset Manager HMR code end
|
145
172
|
JAVASCRIPT
|
146
173
|
end
|
147
|
-
js << "#{@ruby_imports.map(&:to_s).join("\n")}"
|
174
|
+
js << "#{@ruby_imports.map(&:to_s).join("\n")}" if Isomorfeus.production? || target == :node
|
148
175
|
end
|
149
176
|
js
|
150
177
|
end
|
@@ -25,8 +25,93 @@ module Isomorfeus
|
|
25
25
|
path_info = env['PATH_INFO']
|
26
26
|
if path_info.start_with?(@assets_path)
|
27
27
|
|
28
|
+
if !Isomorfeus.production?
|
29
|
+
if path_info.end_with?('.rb.js')
|
30
|
+
asset_key_module_name = path_info[@assets_path_size..-7]
|
31
|
+
asset_key, module_name = asset_key_module_name.split('/')
|
32
|
+
asset_key += '.js'
|
33
|
+
if Isomorfeus.assets.key?(asset_key)
|
34
|
+
asset = Isomorfeus.assets[asset_key]
|
35
|
+
if asset && asset.target != :node
|
36
|
+
asset_manager.transition(asset_key, asset)
|
37
|
+
if asset.bundle_ruby_modules.key?(module_name)
|
38
|
+
headers = {}
|
39
|
+
headers['Last-Modified'] = asset.mtime
|
40
|
+
headers[Rack::CONTENT_TYPE] = 'application/javascript'
|
41
|
+
if should_gzip?(env)
|
42
|
+
headers['Content-Encoding'] = "gzip"
|
43
|
+
headers[Rack::CONTENT_LENGTH] = asset.bundle_ruby_modules[module_name][:js_gz_size]
|
44
|
+
return [200, headers, asset.bundle_ruby_modules[module_name][:js_gz]]
|
45
|
+
else
|
46
|
+
headers[Rack::CONTENT_LENGTH] = asset.bundle_ruby_modules[module_name][:js_size]
|
47
|
+
return [200, headers, asset.bundle_ruby_modules[module_name][:js]]
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
elsif path_info.end_with?('.rb.js.map')
|
54
|
+
asset_key_module_name = path_info[@assets_path_size..-11]
|
55
|
+
asset_key, module_name = asset_key_module_name.split('/')
|
56
|
+
asset_key += '.js'
|
57
|
+
asset = Isomorfeus.assets[asset_key]
|
58
|
+
if asset && asset.target != :node
|
59
|
+
asset_manager.transition(asset_key, asset) unless asset.bundled?
|
60
|
+
if asset.bundle_ruby_modules.key?(module_name)
|
61
|
+
headers = {}
|
62
|
+
headers['Last-Modified'] = asset.mtime
|
63
|
+
headers[Rack::CONTENT_TYPE] = 'application/json'
|
64
|
+
if should_gzip?(env)
|
65
|
+
headers['Content-Encoding'] = "gzip"
|
66
|
+
headers[Rack::CONTENT_LENGTH] = asset.bundle_ruby_modules[module_name][:map_gz_size]
|
67
|
+
return [200, headers, asset.bundle_ruby_modules[module_name][:map_gz]]
|
68
|
+
else
|
69
|
+
headers[Rack::CONTENT_LENGTH] = asset.bundle_ruby_modules[module_name][:map_size]
|
70
|
+
return [200, headers, asset.bundle_ruby_modules[module_name][:map]]
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
elsif path_info.end_with?('.js.map')
|
76
|
+
asset_key = path_info[@assets_path_size..-5]
|
77
|
+
asset = Isomorfeus.assets[asset_key]
|
78
|
+
if asset && asset.target != :node
|
79
|
+
asset_manager.transition(asset_key, asset) unless asset.bundled?
|
80
|
+
headers = {}
|
81
|
+
headers['Last-Modified'] = asset.mtime
|
82
|
+
headers[Rack::CONTENT_TYPE] = 'application/json'
|
83
|
+
if should_gzip?(env)
|
84
|
+
headers['Content-Encoding'] = "gzip"
|
85
|
+
headers[Rack::CONTENT_LENGTH] = asset.bundle_map_gz_size
|
86
|
+
return [200, headers, asset.bundle_map_gz]
|
87
|
+
else
|
88
|
+
headers[Rack::CONTENT_LENGTH] = asset.bundle_map_size
|
89
|
+
return [200, headers, asset.bundle_map]
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
elsif path_info.end_with?('.css.map')
|
94
|
+
# get css source map
|
95
|
+
asset_key = path_info[@assets_path_size..-9] + '.js'
|
96
|
+
asset = Isomorfeus.assets[asset_key]
|
97
|
+
if asset && asset.target != :node
|
98
|
+
asset_manager.transition(asset_key, asset) unless asset.bundled?
|
99
|
+
headers = {}
|
100
|
+
headers['Last-Modified'] = asset.mtime
|
101
|
+
headers[Rack::CONTENT_TYPE] = 'application/json'
|
102
|
+
if should_gzip?(env)
|
103
|
+
headers['Content-Encoding'] = "gzip"
|
104
|
+
headers[Rack::CONTENT_LENGTH] = asset.css_map_gz_size
|
105
|
+
return [200, headers, asset.css_map_gz]
|
106
|
+
else
|
107
|
+
headers[Rack::CONTENT_LENGTH] = asset.css_map_size
|
108
|
+
return [200, headers, asset.css_map]
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
28
114
|
if path_info.end_with?('.js')
|
29
|
-
# get js
|
30
115
|
asset_key = path_info[@assets_path_size..-1]
|
31
116
|
if Isomorfeus.assets.key?(asset_key)
|
32
117
|
asset = Isomorfeus.assets[asset_key]
|
@@ -46,25 +131,6 @@ module Isomorfeus
|
|
46
131
|
end
|
47
132
|
end
|
48
133
|
|
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) unless asset.bundled?
|
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, headers, asset.bundle_map]
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
134
|
elsif path_info.end_with?('.css')
|
69
135
|
# get css
|
70
136
|
asset_key = path_info[@assets_path_size..-5] + '.js'
|
@@ -83,25 +149,6 @@ module Isomorfeus
|
|
83
149
|
return [200, headers, asset.css]
|
84
150
|
end
|
85
151
|
end
|
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]
|
91
|
-
if asset && asset.target != :node
|
92
|
-
asset_manager.transition(asset_key, asset) unless asset.bundled?
|
93
|
-
headers = {}
|
94
|
-
headers['Last-Modified'] = asset.mtime
|
95
|
-
headers[Rack::CONTENT_TYPE] = 'application/json'
|
96
|
-
if should_gzip?(env)
|
97
|
-
headers['Content-Encoding'] = "gzip"
|
98
|
-
headers[Rack::CONTENT_LENGTH] = asset.css_map_gz_size
|
99
|
-
return [200, headers, asset.css_map_gz]
|
100
|
-
else
|
101
|
-
headers[Rack::CONTENT_LENGTH] = asset.css_map_size
|
102
|
-
return [200, headers, asset.css_map]
|
103
|
-
end
|
104
|
-
end
|
105
152
|
end
|
106
153
|
|
107
154
|
return [404, {}, 'not found']
|
@@ -14,7 +14,11 @@ module Isomorfeus
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def to_s
|
17
|
-
"import(\"./#{@module_name}.js\");\n"
|
17
|
+
"import(\"./#{@module_name}.rb.js\");\n"
|
18
|
+
end
|
19
|
+
|
20
|
+
def to_dev_s(asset_name)
|
21
|
+
"import(\"#{Isomorfeus.assets_path}/#{asset_name}/#{@module_name}.rb.js\");\n"
|
18
22
|
end
|
19
23
|
|
20
24
|
private
|
@@ -60,21 +60,29 @@ module Isomorfeus
|
|
60
60
|
asset.mutex.synchronize do
|
61
61
|
return if !Isomorfeus.development? && asset.bundled?
|
62
62
|
return if Isomorfeus.development? && asset.bundled? && (self.class.last_updated.nil? || (asset.mtime > self.class.last_updated))
|
63
|
+
start = Time.now
|
64
|
+
puts "Isomorfeus Asset Manager bundling #{asset_key} ..."
|
63
65
|
asset.touch
|
64
|
-
|
66
|
+
asset_name = asset_key[0..-4]
|
67
|
+
asset.bundle_ruby_modules = build_ruby_and_save(asset_key, asset_name, asset)
|
65
68
|
save_imports(asset_key, asset)
|
66
69
|
run_esbuild(asset_key, asset, analyze)
|
67
|
-
asset.bundle = bundled_asset(asset_key)
|
68
|
-
asset.bundle_map = bundled_asset_map(asset_key) unless Isomorfeus.production?
|
70
|
+
asset.bundle = bundled_asset(asset_key, asset_name, asset)
|
69
71
|
asset.css = bundled_css(asset_key)
|
70
|
-
|
72
|
+
unless Isomorfeus.production?
|
73
|
+
asset.bundle_map = bundled_asset_map(asset_key)
|
74
|
+
asset.css_map = bundled_css_map(asset_key)
|
75
|
+
end
|
76
|
+
puts "Isomorfeus Asset Manager bundling #{asset_key} took #{Time.now - start}s"
|
71
77
|
end
|
72
78
|
end
|
73
79
|
|
74
80
|
private
|
75
81
|
|
76
|
-
def bundled_asset(asset_key)
|
77
|
-
File.read(File.join(@output_path, asset_key))
|
82
|
+
def bundled_asset(asset_key, asset_name, asset)
|
83
|
+
res = File.read(File.join(@output_path, asset_key))
|
84
|
+
res << asset.ruby_imports_to_s(asset_name) if !Isomorfeus.production? && asset.target != :node
|
85
|
+
res
|
78
86
|
end
|
79
87
|
|
80
88
|
def bundled_asset_map(asset_key)
|
@@ -95,20 +103,24 @@ module Isomorfeus
|
|
95
103
|
File.write(File.join(@imports_path, asset_key), asset.to_s)
|
96
104
|
end
|
97
105
|
|
98
|
-
def build_ruby_and_save(asset_key, asset)
|
106
|
+
def build_ruby_and_save(asset_key, asset_name, asset)
|
107
|
+
rb = {}
|
99
108
|
asset.ruby_imports.each do |ruby_import|
|
100
|
-
|
109
|
+
module_name = ruby_import.module_name
|
110
|
+
out_file = File.join(@imports_path, module_name + '.rb.js')
|
101
111
|
next if !Isomorfeus.development? && File.exist?(out_file)
|
102
|
-
js_map_path = File.join(@imports_path, ruby_import.module_name + '.js.map')
|
103
112
|
result = Opal::Builder.build(ruby_import.resolved_path, { esm: true })
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
113
|
+
rb[module_name] = { js: result.to_s }
|
114
|
+
if !Isomorfeus.production? && asset.target != :node
|
115
|
+
rb[module_name][:js] << "\n//# sourceMappingURL=#{Isomorfeus.assets_path}/#{asset_name}/#{module_name}.rb.js.map\n"
|
116
|
+
rb[module_name][:map] = Oj.dump(result.source_map.as_json, mode: :strict)
|
117
|
+
else
|
118
|
+
FileUtils.mkdir_p(File.join(*[@imports_path].concat(module_name.split('/')[0...-1]))) if module_name.include?('/')
|
119
|
+
File.write(out_file, rb[module_name][:js])
|
120
|
+
rb[module_name][:js] = nil
|
109
121
|
end
|
110
|
-
File.write(out_file, js)
|
111
122
|
end
|
123
|
+
rb
|
112
124
|
end
|
113
125
|
|
114
126
|
def compile_ruby(file)
|
@@ -142,7 +154,7 @@ module Isomorfeus
|
|
142
154
|
<<~JAVASCRIPT
|
143
155
|
'use strict';
|
144
156
|
const path = require('path');
|
145
|
-
|
157
|
+
let esbuild_r;
|
146
158
|
try { esbuild_r = require('esbuild'); }
|
147
159
|
catch { esbuild_r = require('esbuild-wasm'); }
|
148
160
|
const esbuild = esbuild_r;
|
@@ -190,7 +202,6 @@ module Isomorfeus
|
|
190
202
|
# possible future improvement
|
191
203
|
# loader: {
|
192
204
|
# '.png': 'dataurl',
|
193
|
-
# '.svg': 'text',
|
194
205
|
# },
|
195
206
|
def run_esbuild(asset_key, asset, analyze = false)
|
196
207
|
resolve_paths = ENV['NODE_PATH'].split(Gem.win_platform? ? ';' : ':')
|
@@ -205,7 +216,7 @@ module Isomorfeus
|
|
205
216
|
format: '#{asset.target == :node ? 'cjs' : 'iife'}',
|
206
217
|
legalComments: 'linked',
|
207
218
|
loader: { '.svg': 'text' },
|
208
|
-
metafile: true,
|
219
|
+
metafile: #{analyze ? 'true' : 'false'},
|
209
220
|
minify: #{Isomorfeus.production? ? 'true' : 'false'},
|
210
221
|
nodePaths: #{resolve_paths},
|
211
222
|
outdir: global.output_path,
|
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.14.
|
4
|
+
version: 0.14.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jan Biedermann
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-02-
|
11
|
+
date: 2022-02-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: isomorfeus-iodine
|