isomorfeus-asset-manager 0.14.8 → 0.14.12
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 +4 -4
- data/README.md +1 -1
- data/lib/isomorfeus/asset_manager/asset.rb +60 -23
- data/lib/isomorfeus/asset_manager/config.rb +1 -1
- data/lib/isomorfeus/asset_manager/rack_middleware.rb +86 -39
- data/lib/isomorfeus/asset_manager/ruby_import.rb +5 -1
- data/lib/isomorfeus/asset_manager/version.rb +1 -1
- data/lib/isomorfeus/asset_manager.rb +30 -19
- data/node_modules/.package-lock.json +3 -3
- data/node_modules/esbuild-wasm/esbuild.wasm +0 -0
- data/node_modules/esbuild-wasm/esm/browser.d.ts +6 -0
- data/node_modules/esbuild-wasm/esm/browser.js +47 -9
- data/node_modules/esbuild-wasm/esm/browser.min.js +6 -6
- data/node_modules/esbuild-wasm/lib/browser.d.ts +6 -0
- data/node_modules/esbuild-wasm/lib/browser.js +47 -9
- data/node_modules/esbuild-wasm/lib/browser.min.js +6 -6
- data/node_modules/esbuild-wasm/lib/main.d.ts +6 -0
- data/node_modules/esbuild-wasm/lib/main.js +51 -12
- data/node_modules/esbuild-wasm/package.json +1 -1
- data/package.json +1 -1
- metadata +8 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0d50c569569e02ba08898b07c244ad40c2be45d190e98635383f53932391d725
|
4
|
+
data.tar.gz: 5c662d03177f4ab834d3667b34e44f20e485822a5474143be29171e63755c5d6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c186995284e3e0bffddcf3aee7c7af958ba68af4d2f724c725d030a0098a9ebaa7c02e7fd5df43c61192e4784b78c6aa65e01ac372266dca0ed3ae3916da68b0
|
7
|
+
data.tar.gz: f92d390b1703c40b1141197dd0ee34445951139f4535bae6491e47d784045c60b673f42deeb21504a3f4de2c3c43bdbf324f9f30f4471a1c44bdada62d3a364d
|
data/README.md
CHANGED
@@ -12,4 +12,4 @@ No need to install esbuild separately, everything bundled ready to go.
|
|
12
12
|
However, if within the project the 'esbuild' npm package is installed in node_modules, that version will be used instead.
|
13
13
|
|
14
14
|
### Community and Support
|
15
|
-
At the [Isomorfeus Framework Project](
|
15
|
+
At the [Isomorfeus Framework Project](https://isomorfeus.com)
|
@@ -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
|
@@ -108,33 +135,43 @@ module Isomorfeus
|
|
108
135
|
// Isomorfeus Asset Manager HMR code begin
|
109
136
|
let ws_protocol = (window.location.protocol == 'https:') ? 'wss:' : 'ws:';
|
110
137
|
let ws_url = ws_protocol + '//' + window.location.host + "#{Isomorfeus.assets_websocket_path}";
|
111
|
-
let
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
138
|
+
let hmr_ws_fun = function() {
|
139
|
+
let hmr_ws = new WebSocket(ws_url);
|
140
|
+
hmr_ws.onopen = function(event) { console.log("Isomorfeus Asset Manager HMR socket connected"); }
|
141
|
+
hmr_ws.onmessage = function(event) {
|
142
|
+
let update = JSON.parse(event.data);
|
143
|
+
if (typeof update.error !== 'undefined') { console.error(update.error); return; }
|
144
|
+
if (typeof update.locale !== 'undefined') {
|
145
|
+
console.log('Isomorfeus Asset Manager updating locale ', update.locale);
|
146
|
+
try { Opal.Isomorfeus.I18n.Init.$reload_from_server(); }
|
147
|
+
catch { console.log('Isomorfeus Asset Manager could not update locale ', update.locale) }
|
148
|
+
return;
|
149
|
+
}
|
150
|
+
let start_index = 'Opal.modules[\\"'.length;
|
151
|
+
let end_index = update.javascript.indexOf('"', start_index);
|
152
|
+
let opal_module_name = update.javascript.substr(start_index, end_index - start_index);
|
153
|
+
console.log('Isomorfeus Asset Manager updating ', opal_module_name);
|
154
|
+
if (typeof Opal !== 'undefined' && typeof Opal.require_table !== "undefined" && Opal.require_table['corelib/module']) {
|
155
|
+
try {
|
156
|
+
eval(update.javascript);
|
157
|
+
if (Opal.require_table[opal_module_name]) { Opal.load.call(Opal, opal_module_name); }
|
158
|
+
else { Opal.require.call(Opal, opal_module_name); }
|
159
|
+
Opal.Isomorfeus.$force_render();
|
160
|
+
} catch (e) { console.error(e); return; }
|
161
|
+
}
|
162
|
+
};
|
163
|
+
hmr_ws.onclose = function(event) {
|
164
|
+
setTimeout(function() {
|
165
|
+
console.log("Isomorfeus Asset Manager reconnecting HMR socket");
|
166
|
+
hmr_ws_fun();
|
167
|
+
}, 2000);
|
168
|
+
};
|
133
169
|
}
|
170
|
+
hmr_ws_fun()
|
134
171
|
// Isomorfeus Asset Manager HMR code end
|
135
172
|
JAVASCRIPT
|
136
173
|
end
|
137
|
-
js << "#{@ruby_imports.map(&:to_s).join("\n")}"
|
174
|
+
js << "#{@ruby_imports.map(&:to_s).join("\n")}" if Isomorfeus.production? || target == :node
|
138
175
|
end
|
139
176
|
js
|
140
177
|
end
|
@@ -67,7 +67,7 @@ module Isomorfeus
|
|
67
67
|
self.hmr_listener = nil
|
68
68
|
self.asset_manager_hmr_channel = :isomorfeus_asset_manager_module_updates
|
69
69
|
self.asset_manager_hmr_dirs = %w[channels components data locales operations policies]
|
70
|
-
self.assets_websocket_path = '/
|
70
|
+
self.assets_websocket_path = '/_asset_manager_hmr_websocket'
|
71
71
|
self.assets_path = '/assets'
|
72
72
|
self.assets = {
|
73
73
|
'web.js' => Isomorfeus::AssetManager::Asset.new(:browser),
|
@@ -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) unless asset.bundled?
|
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
|
-
|
101
|
-
|
102
|
-
|
109
|
+
module_name = ruby_import.module_name
|
110
|
+
out_file = File.join(@imports_path, module_name + '.rb.js')
|
111
|
+
next if Isomorfeus.production? && File.exist?(out_file)
|
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 if Isomorfeus.production?
|
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,
|
@@ -4,9 +4,9 @@
|
|
4
4
|
"requires": true,
|
5
5
|
"packages": {
|
6
6
|
"node_modules/esbuild-wasm": {
|
7
|
-
"version": "0.14.
|
8
|
-
"resolved": "https://registry.npmjs.org/esbuild-wasm/-/esbuild-wasm-0.14.
|
9
|
-
"integrity": "sha512-
|
7
|
+
"version": "0.14.21",
|
8
|
+
"resolved": "https://registry.npmjs.org/esbuild-wasm/-/esbuild-wasm-0.14.21.tgz",
|
9
|
+
"integrity": "sha512-sPMyljBiKxXjW1wLd5dQnrUJR1PAt8ybSidXoZWJnMuB1mpdLju57LtstDWWkCgcaE+TGJJ6NqP/OtGyeDdEAA==",
|
10
10
|
"bin": {
|
11
11
|
"esbuild": "bin/esbuild"
|
12
12
|
},
|
Binary file
|
@@ -26,6 +26,8 @@ interface CommonOptions {
|
|
26
26
|
mangleProps?: RegExp;
|
27
27
|
/** Documentation: https://esbuild.github.io/api/#mangle-props */
|
28
28
|
reserveProps?: RegExp;
|
29
|
+
/** Documentation: https://esbuild.github.io/api/#mangle-props */
|
30
|
+
mangleCache?: Record<string, string | false>;
|
29
31
|
/** Documentation: https://esbuild.github.io/api/#drop */
|
30
32
|
drop?: Drop[];
|
31
33
|
/** Documentation: https://esbuild.github.io/api/#minify */
|
@@ -200,6 +202,8 @@ export interface BuildResult {
|
|
200
202
|
stop?: () => void;
|
201
203
|
/** Only when "metafile: true" */
|
202
204
|
metafile?: Metafile;
|
205
|
+
/** Only when "mangleCache" is present */
|
206
|
+
mangleCache?: Record<string, string | false>;
|
203
207
|
}
|
204
208
|
|
205
209
|
export interface BuildFailure extends Error {
|
@@ -253,6 +257,8 @@ export interface TransformResult {
|
|
253
257
|
code: string;
|
254
258
|
map: string;
|
255
259
|
warnings: Message[];
|
260
|
+
/** Only when "mangleCache" is present */
|
261
|
+
mangleCache?: Record<string, string | false>;
|
256
262
|
}
|
257
263
|
|
258
264
|
export interface TransformFailure extends Error {
|
@@ -251,6 +251,21 @@ function validateInitializeOptions(options) {
|
|
251
251
|
worker
|
252
252
|
};
|
253
253
|
}
|
254
|
+
function validateMangleCache(mangleCache) {
|
255
|
+
let validated;
|
256
|
+
if (mangleCache !== void 0) {
|
257
|
+
validated = /* @__PURE__ */ Object.create(null);
|
258
|
+
for (let key of Object.keys(mangleCache)) {
|
259
|
+
let value = mangleCache[key];
|
260
|
+
if (typeof value === "string" || value === false) {
|
261
|
+
validated[key] = value;
|
262
|
+
} else {
|
263
|
+
throw new Error(`Expected ${JSON.stringify(key)} in mangle cache to map to either a string or false`);
|
264
|
+
}
|
265
|
+
}
|
266
|
+
}
|
267
|
+
return validated;
|
268
|
+
}
|
254
269
|
function pushLogFlags(flags, options, keys, isTTY, logLevelDefault) {
|
255
270
|
let color = getFlag(options, keys, "color", mustBeBoolean);
|
256
271
|
let logLevel = getFlag(options, keys, "logLevel", mustBeString);
|
@@ -382,6 +397,7 @@ function flagsForBuildOptions(callName, options, isTTY, logLevelDefault, writeDe
|
|
382
397
|
let write = (_a = getFlag(options, keys, "write", mustBeBoolean)) != null ? _a : writeDefault;
|
383
398
|
let allowOverwrite = getFlag(options, keys, "allowOverwrite", mustBeBoolean);
|
384
399
|
let incremental = getFlag(options, keys, "incremental", mustBeBoolean) === true;
|
400
|
+
let mangleCache = getFlag(options, keys, "mangleCache", mustBeObject);
|
385
401
|
keys.plugins = true;
|
386
402
|
checkForInvalidFlags(options, keys, `in ${callName}() call`);
|
387
403
|
if (sourcemap)
|
@@ -531,7 +547,8 @@ function flagsForBuildOptions(callName, options, isTTY, logLevelDefault, writeDe
|
|
531
547
|
absWorkingDir,
|
532
548
|
incremental,
|
533
549
|
nodePaths,
|
534
|
-
watch: watchMode
|
550
|
+
watch: watchMode,
|
551
|
+
mangleCache: validateMangleCache(mangleCache)
|
535
552
|
};
|
536
553
|
}
|
537
554
|
function flagsForTransformOptions(callName, options, isTTY, logLevelDefault) {
|
@@ -545,6 +562,7 @@ function flagsForTransformOptions(callName, options, isTTY, logLevelDefault) {
|
|
545
562
|
let loader = getFlag(options, keys, "loader", mustBeString);
|
546
563
|
let banner = getFlag(options, keys, "banner", mustBeString);
|
547
564
|
let footer = getFlag(options, keys, "footer", mustBeString);
|
565
|
+
let mangleCache = getFlag(options, keys, "mangleCache", mustBeObject);
|
548
566
|
checkForInvalidFlags(options, keys, `in ${callName}() call`);
|
549
567
|
if (sourcemap)
|
550
568
|
flags.push(`--sourcemap=${sourcemap === true ? "external" : sourcemap}`);
|
@@ -558,7 +576,10 @@ function flagsForTransformOptions(callName, options, isTTY, logLevelDefault) {
|
|
558
576
|
flags.push(`--banner=${banner}`);
|
559
577
|
if (footer)
|
560
578
|
flags.push(`--footer=${footer}`);
|
561
|
-
return
|
579
|
+
return {
|
580
|
+
flags,
|
581
|
+
mangleCache: validateMangleCache(mangleCache)
|
582
|
+
};
|
562
583
|
}
|
563
584
|
function createChannel(streamIn) {
|
564
585
|
let responseCallbacks = /* @__PURE__ */ new Map();
|
@@ -702,8 +723,8 @@ function createChannel(streamIn) {
|
|
702
723
|
if (isFirstPacket) {
|
703
724
|
isFirstPacket = false;
|
704
725
|
let binaryVersion = String.fromCharCode(...bytes);
|
705
|
-
if (binaryVersion !== "0.14.
|
706
|
-
throw new Error(`Cannot start service: Host version "${"0.14.
|
726
|
+
if (binaryVersion !== "0.14.21") {
|
727
|
+
throw new Error(`Cannot start service: Host version "${"0.14.21"}" does not match binary version ${JSON.stringify(binaryVersion)}`);
|
707
728
|
}
|
708
729
|
return;
|
709
730
|
}
|
@@ -1162,7 +1183,8 @@ function createChannel(streamIn) {
|
|
1162
1183
|
absWorkingDir,
|
1163
1184
|
incremental,
|
1164
1185
|
nodePaths,
|
1165
|
-
watch
|
1186
|
+
watch,
|
1187
|
+
mangleCache
|
1166
1188
|
} = flagsForBuildOptions(callName, options, isTTY, buildLogLevelDefault, writeDefault);
|
1167
1189
|
let request = {
|
1168
1190
|
command: "build",
|
@@ -1178,6 +1200,8 @@ function createChannel(streamIn) {
|
|
1178
1200
|
};
|
1179
1201
|
if (requestPlugins)
|
1180
1202
|
request.plugins = requestPlugins;
|
1203
|
+
if (mangleCache)
|
1204
|
+
request.mangleCache = mangleCache;
|
1181
1205
|
let serve2 = serveOptions && buildServeData(refs, serveOptions, request, key);
|
1182
1206
|
let rebuild;
|
1183
1207
|
let stop;
|
@@ -1186,6 +1210,8 @@ function createChannel(streamIn) {
|
|
1186
1210
|
result.outputFiles = response.outputFiles.map(convertOutputFiles);
|
1187
1211
|
if (response.metafile)
|
1188
1212
|
result.metafile = JSON.parse(response.metafile);
|
1213
|
+
if (response.mangleCache)
|
1214
|
+
result.mangleCache = response.mangleCache;
|
1189
1215
|
if (response.writeToStdout !== void 0)
|
1190
1216
|
console.log(decodeUTF8(response.writeToStdout).replace(/\n$/, ""));
|
1191
1217
|
};
|
@@ -1313,20 +1339,32 @@ function createChannel(streamIn) {
|
|
1313
1339
|
try {
|
1314
1340
|
if (typeof input !== "string")
|
1315
1341
|
throw new Error('The input to "transform" must be a string');
|
1316
|
-
let
|
1342
|
+
let {
|
1343
|
+
flags,
|
1344
|
+
mangleCache
|
1345
|
+
} = flagsForTransformOptions(callName, options, isTTY, transformLogLevelDefault);
|
1317
1346
|
let request = {
|
1318
1347
|
command: "transform",
|
1319
1348
|
flags,
|
1320
1349
|
inputFS: inputPath !== null,
|
1321
1350
|
input: inputPath !== null ? inputPath : input
|
1322
1351
|
};
|
1352
|
+
if (mangleCache)
|
1353
|
+
request.mangleCache = mangleCache;
|
1323
1354
|
sendRequest(refs, request, (error, response) => {
|
1324
1355
|
if (error)
|
1325
1356
|
return callback(new Error(error), null);
|
1326
1357
|
let errors = replaceDetailsInMessages(response.errors, details);
|
1327
1358
|
let warnings = replaceDetailsInMessages(response.warnings, details);
|
1328
1359
|
let outstanding = 1;
|
1329
|
-
let next = () =>
|
1360
|
+
let next = () => {
|
1361
|
+
if (--outstanding === 0) {
|
1362
|
+
let result = { warnings, code: response.code, map: response.map };
|
1363
|
+
if (response.mangleCache)
|
1364
|
+
result.mangleCache = response == null ? void 0 : response.mangleCache;
|
1365
|
+
callback(null, result);
|
1366
|
+
}
|
1367
|
+
};
|
1330
1368
|
if (errors.length > 0)
|
1331
1369
|
return callback(failureErrorWithLog("Transform failed", errors, warnings), null);
|
1332
1370
|
if (response.codeFS) {
|
@@ -1631,7 +1669,7 @@ function convertOutputFiles({ path, contents }) {
|
|
1631
1669
|
}
|
1632
1670
|
|
1633
1671
|
// lib/npm/browser.ts
|
1634
|
-
var version = "0.14.
|
1672
|
+
var version = "0.14.21";
|
1635
1673
|
var build = (options) => ensureServiceIsRunning().build(options);
|
1636
1674
|
var serve = () => {
|
1637
1675
|
throw new Error(`The "serve" API only works in node`);
|
@@ -2388,7 +2426,7 @@ onmessage = ({ data: wasm }) => {
|
|
2388
2426
|
callback(null, count);
|
2389
2427
|
};
|
2390
2428
|
let go = new global.Go();
|
2391
|
-
go.argv = ["", \`--service=\${"0.14.
|
2429
|
+
go.argv = ["", \`--service=\${"0.14.21"}\`];
|
2392
2430
|
WebAssembly.instantiate(wasm, go.importObject).then(({ instance }) => go.run(instance));
|
2393
2431
|
};}`;
|
2394
2432
|
let worker;
|