isomorfeus-asset-manager 0.14.7 → 0.14.11

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: 85e22a9e188a1be0996db972e25710c16497826e71ddc17712af17c643716567
4
- data.tar.gz: 12d2fcbd96cb9df806aae43cb3960c93bee80df0b757aaa1a0f06a40c53ac6b2
3
+ metadata.gz: 78b774bc55cc59e8fee7021c0cad65221b01885e932f7881cf6f006e45898400
4
+ data.tar.gz: 76c7b73948ed055aeeca30847e307ef1e7ef7174075463abbfff04555e032df3
5
5
  SHA512:
6
- metadata.gz: f498c766bae93cf14772b0099d810d7cf6a9b5381fd658726bb10d54819b5163479708b024f660c047b1f19e3cd2c502f7bf39a8cfaa412910fd50963ae20449
7
- data.tar.gz: 5cc42ef75eaa113305e9a44a08d1d8eba25b0cfa9f882fae94e7ddf46109b315e39f237685c2d789a5d40add964f4892a0707378f361d90b7b9eb79917b7c2dd
6
+ metadata.gz: 9e05e0fdb8f88f717638ba1aece5332d737e7e7e16f0262519386eebb4e92b21af5e31176e76dabed2d19afed09a3b8652922c0365c49625cac3e4827e72f722
7
+ data.tar.gz: 8a67ce45a8dad7badc69a5e4cff9d617ff0f5bd9e9316d369fc335e190793110696f684ac2289dd31874eeaba25d06e63dcd9f1d543870b7197d61168d813b96
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](http://isomorfeus.com)
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,27 +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 hmr_ws = new WebSocket(ws_url);
112
- hmr_ws.onmessage = function(event) {
113
- let update = JSON.parse(event.data);
114
- if (typeof update.error !== 'undefined') { console.error(update.error); return; }
115
- let start_index = 'Opal.modules[\\"'.length;
116
- let end_index = update.javascript.indexOf('"', start_index);
117
- let opal_module_name = update.javascript.substr(start_index, end_index - start_index);
118
- console.log('Updating ', opal_module_name);
119
- if (typeof Opal !== 'undefined' && typeof Opal.require_table !== "undefined" && Opal.require_table['corelib/module']) {
120
- try {
121
- eval(update.javascript);
122
- if (Opal.require_table[opal_module_name]) { Opal.load.call(Opal, opal_module_name); }
123
- else { Opal.require.call(Opal, opal_module_name); }
124
- Opal.Isomorfeus.$force_render();
125
- } catch (e) { console.error(e); return; }
126
- }
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
+ };
127
169
  }
170
+ hmr_ws_fun()
128
171
  // Isomorfeus Asset Manager HMR code end
129
172
  JAVASCRIPT
130
173
  end
131
- js << "#{@ruby_imports.map(&:to_s).join("\n")}"
174
+ js << "#{@ruby_imports.map(&:to_s).join("\n")}" if Isomorfeus.production? || target == :node
132
175
  end
133
176
  js
134
177
  end
@@ -66,8 +66,8 @@ module Isomorfeus
66
66
 
67
67
  self.hmr_listener = nil
68
68
  self.asset_manager_hmr_channel = :isomorfeus_asset_manager_module_updates
69
- self.asset_manager_hmr_dirs = %w[channels components data operations policies]
70
- self.assets_websocket_path = '/_assets_websocket'
69
+ self.asset_manager_hmr_dirs = %w[channels components data locales operations policies]
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)
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
@@ -1,5 +1,5 @@
1
1
  module Isomorfeus
2
2
  class AssetManager
3
- VERSION = '0.14.7'
3
+ VERSION = '0.14.11'
4
4
  end
5
5
  end
@@ -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
- build_ruby_and_save(asset_key, asset)
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
- asset.css_map = bundled_css_map(asset_key) unless Isomorfeus.production?
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
- out_file = File.join(@imports_path, ruby_import.module_name + '.js')
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
- FileUtils.mkdir_p(File.join(*[@imports_path].concat(ruby_import.module_name.split('/')[0...-1]))) if ruby_import.module_name.include?('/')
105
- js = result.to_s
106
- unless Isomorfeus.production?
107
- js << "\n//# sourceMappingURL=file://#{js_map_path}\n"
108
- File.write(js_map_path, result.source_map)
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
- var esbuild_r;
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;
@@ -168,8 +180,14 @@ module Isomorfeus
168
180
  am_class.last_updated = (Time.now.to_f * (10 ** 9)).to_i
169
181
  next if file.start_with?(@server_path)
170
182
  begin
171
- update = compile_ruby(file)
172
- update_json = Oj.dump(update, mode: :strict)
183
+ if file.end_with?('.rb')
184
+ update = compile_ruby(file)
185
+ update_json = Oj.dump(update, mode: :strict)
186
+ elsif file.end_with?('.yml') || file.end_with?('.mo') || file.end_with?('.po')
187
+ update_json = Oj.dump({ locale: file }, mode: :strict)
188
+ else
189
+ update_json = Oj.dump({ error: "Don't know how to update #{file}!" }, mode: :strict)
190
+ end
173
191
  Iodine.publish(Isomorfeus.asset_manager_hmr_channel, update_json)
174
192
  rescue Exception => e
175
193
  message = "IsomorfeusAssetManager during hot module update:\n#{e.class}\n#{e.message}\n#{e.backtrace.join("\n")}"
@@ -184,7 +202,6 @@ module Isomorfeus
184
202
  # possible future improvement
185
203
  # loader: {
186
204
  # '.png': 'dataurl',
187
- # '.svg': 'text',
188
205
  # },
189
206
  def run_esbuild(asset_key, asset, analyze = false)
190
207
  resolve_paths = ENV['NODE_PATH'].split(Gem.win_platform? ? ';' : ':')
@@ -199,7 +216,7 @@ module Isomorfeus
199
216
  format: '#{asset.target == :node ? 'cjs' : 'iife'}',
200
217
  legalComments: 'linked',
201
218
  loader: { '.svg': 'text' },
202
- metafile: true,
219
+ metafile: #{analyze ? 'true' : 'false'},
203
220
  minify: #{Isomorfeus.production? ? 'true' : 'false'},
204
221
  nodePaths: #{resolve_paths},
205
222
  outdir: global.output_path,
@@ -4,14 +4,14 @@
4
4
  "requires": true,
5
5
  "packages": {
6
6
  "node_modules/esbuild-wasm": {
7
- "version": "0.14.14",
8
- "resolved": "https://registry.npmjs.org/esbuild-wasm/-/esbuild-wasm-0.14.14.tgz",
9
- "integrity": "sha512-qTjK4MWnYtQHCMGg2qDUqeFYXfVvYq5qJkQTIsOV4VZCknoYePVaDTG9ygEB9Ct0kc0DWs7IrS6Ja+GjY62Kzw==",
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
  },
13
13
  "engines": {
14
- "node": ">=8"
14
+ "node": ">=12"
15
15
  }
16
16
  }
17
17
  }
Binary file
@@ -22,6 +22,13 @@ interface CommonOptions {
22
22
  /** Documentation: https://esbuild.github.io/api/#target */
23
23
  target?: string | string[];
24
24
 
25
+ /** Documentation: https://esbuild.github.io/api/#mangle-props */
26
+ mangleProps?: RegExp;
27
+ /** Documentation: https://esbuild.github.io/api/#mangle-props */
28
+ reserveProps?: RegExp;
29
+ /** Documentation: https://esbuild.github.io/api/#mangle-props */
30
+ mangleCache?: Record<string, string | false>;
31
+ /** Documentation: https://esbuild.github.io/api/#drop */
25
32
  drop?: Drop[];
26
33
  /** Documentation: https://esbuild.github.io/api/#minify */
27
34
  minify?: boolean;
@@ -195,6 +202,8 @@ export interface BuildResult {
195
202
  stop?: () => void;
196
203
  /** Only when "metafile: true" */
197
204
  metafile?: Metafile;
205
+ /** Only when "mangleCache" is present */
206
+ mangleCache?: Record<string, string | false>;
198
207
  }
199
208
 
200
209
  export interface BuildFailure extends Error {
@@ -248,6 +257,8 @@ export interface TransformResult {
248
257
  code: string;
249
258
  map: string;
250
259
  warnings: Message[];
260
+ /** Only when "mangleCache" is present */
261
+ mangleCache?: Record<string, string | false>;
251
262
  }
252
263
 
253
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);
@@ -269,6 +284,8 @@ function pushCommonFlags(flags, options, keys) {
269
284
  let target = getFlag(options, keys, "target", mustBeStringOrArray);
270
285
  let format = getFlag(options, keys, "format", mustBeString);
271
286
  let globalName = getFlag(options, keys, "globalName", mustBeString);
287
+ let mangleProps = getFlag(options, keys, "mangleProps", mustBeRegExp);
288
+ let reserveProps = getFlag(options, keys, "reserveProps", mustBeRegExp);
272
289
  let minify = getFlag(options, keys, "minify", mustBeBoolean);
273
290
  let minifySyntax = getFlag(options, keys, "minifySyntax", mustBeBoolean);
274
291
  let minifyWhitespace = getFlag(options, keys, "minifyWhitespace", mustBeBoolean);
@@ -316,6 +333,10 @@ function pushCommonFlags(flags, options, keys) {
316
333
  if (drop)
317
334
  for (let what of drop)
318
335
  flags.push(`--drop:${what}`);
336
+ if (mangleProps)
337
+ flags.push(`--mangle-props=${mangleProps.source}`);
338
+ if (reserveProps)
339
+ flags.push(`--reserve-props=${reserveProps.source}`);
319
340
  if (jsx)
320
341
  flags.push(`--jsx=${jsx}`);
321
342
  if (jsxFactory)
@@ -376,6 +397,7 @@ function flagsForBuildOptions(callName, options, isTTY, logLevelDefault, writeDe
376
397
  let write = (_a = getFlag(options, keys, "write", mustBeBoolean)) != null ? _a : writeDefault;
377
398
  let allowOverwrite = getFlag(options, keys, "allowOverwrite", mustBeBoolean);
378
399
  let incremental = getFlag(options, keys, "incremental", mustBeBoolean) === true;
400
+ let mangleCache = getFlag(options, keys, "mangleCache", mustBeObject);
379
401
  keys.plugins = true;
380
402
  checkForInvalidFlags(options, keys, `in ${callName}() call`);
381
403
  if (sourcemap)
@@ -525,7 +547,8 @@ function flagsForBuildOptions(callName, options, isTTY, logLevelDefault, writeDe
525
547
  absWorkingDir,
526
548
  incremental,
527
549
  nodePaths,
528
- watch: watchMode
550
+ watch: watchMode,
551
+ mangleCache: validateMangleCache(mangleCache)
529
552
  };
530
553
  }
531
554
  function flagsForTransformOptions(callName, options, isTTY, logLevelDefault) {
@@ -539,6 +562,7 @@ function flagsForTransformOptions(callName, options, isTTY, logLevelDefault) {
539
562
  let loader = getFlag(options, keys, "loader", mustBeString);
540
563
  let banner = getFlag(options, keys, "banner", mustBeString);
541
564
  let footer = getFlag(options, keys, "footer", mustBeString);
565
+ let mangleCache = getFlag(options, keys, "mangleCache", mustBeObject);
542
566
  checkForInvalidFlags(options, keys, `in ${callName}() call`);
543
567
  if (sourcemap)
544
568
  flags.push(`--sourcemap=${sourcemap === true ? "external" : sourcemap}`);
@@ -552,7 +576,10 @@ function flagsForTransformOptions(callName, options, isTTY, logLevelDefault) {
552
576
  flags.push(`--banner=${banner}`);
553
577
  if (footer)
554
578
  flags.push(`--footer=${footer}`);
555
- return flags;
579
+ return {
580
+ flags,
581
+ mangleCache: validateMangleCache(mangleCache)
582
+ };
556
583
  }
557
584
  function createChannel(streamIn) {
558
585
  let responseCallbacks = /* @__PURE__ */ new Map();
@@ -696,8 +723,8 @@ function createChannel(streamIn) {
696
723
  if (isFirstPacket) {
697
724
  isFirstPacket = false;
698
725
  let binaryVersion = String.fromCharCode(...bytes);
699
- if (binaryVersion !== "0.14.14") {
700
- throw new Error(`Cannot start service: Host version "${"0.14.14"}" does not match binary version ${JSON.stringify(binaryVersion)}`);
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)}`);
701
728
  }
702
729
  return;
703
730
  }
@@ -1156,7 +1183,8 @@ function createChannel(streamIn) {
1156
1183
  absWorkingDir,
1157
1184
  incremental,
1158
1185
  nodePaths,
1159
- watch
1186
+ watch,
1187
+ mangleCache
1160
1188
  } = flagsForBuildOptions(callName, options, isTTY, buildLogLevelDefault, writeDefault);
1161
1189
  let request = {
1162
1190
  command: "build",
@@ -1172,6 +1200,8 @@ function createChannel(streamIn) {
1172
1200
  };
1173
1201
  if (requestPlugins)
1174
1202
  request.plugins = requestPlugins;
1203
+ if (mangleCache)
1204
+ request.mangleCache = mangleCache;
1175
1205
  let serve2 = serveOptions && buildServeData(refs, serveOptions, request, key);
1176
1206
  let rebuild;
1177
1207
  let stop;
@@ -1180,6 +1210,8 @@ function createChannel(streamIn) {
1180
1210
  result.outputFiles = response.outputFiles.map(convertOutputFiles);
1181
1211
  if (response.metafile)
1182
1212
  result.metafile = JSON.parse(response.metafile);
1213
+ if (response.mangleCache)
1214
+ result.mangleCache = response.mangleCache;
1183
1215
  if (response.writeToStdout !== void 0)
1184
1216
  console.log(decodeUTF8(response.writeToStdout).replace(/\n$/, ""));
1185
1217
  };
@@ -1307,20 +1339,32 @@ function createChannel(streamIn) {
1307
1339
  try {
1308
1340
  if (typeof input !== "string")
1309
1341
  throw new Error('The input to "transform" must be a string');
1310
- let flags = flagsForTransformOptions(callName, options, isTTY, transformLogLevelDefault);
1342
+ let {
1343
+ flags,
1344
+ mangleCache
1345
+ } = flagsForTransformOptions(callName, options, isTTY, transformLogLevelDefault);
1311
1346
  let request = {
1312
1347
  command: "transform",
1313
1348
  flags,
1314
1349
  inputFS: inputPath !== null,
1315
1350
  input: inputPath !== null ? inputPath : input
1316
1351
  };
1352
+ if (mangleCache)
1353
+ request.mangleCache = mangleCache;
1317
1354
  sendRequest(refs, request, (error, response) => {
1318
1355
  if (error)
1319
1356
  return callback(new Error(error), null);
1320
1357
  let errors = replaceDetailsInMessages(response.errors, details);
1321
1358
  let warnings = replaceDetailsInMessages(response.warnings, details);
1322
1359
  let outstanding = 1;
1323
- let next = () => --outstanding === 0 && callback(null, { warnings, code: response.code, map: response.map });
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
+ };
1324
1368
  if (errors.length > 0)
1325
1369
  return callback(failureErrorWithLog("Transform failed", errors, warnings), null);
1326
1370
  if (response.codeFS) {
@@ -1625,7 +1669,7 @@ function convertOutputFiles({ path, contents }) {
1625
1669
  }
1626
1670
 
1627
1671
  // lib/npm/browser.ts
1628
- var version = "0.14.14";
1672
+ var version = "0.14.21";
1629
1673
  var build = (options) => ensureServiceIsRunning().build(options);
1630
1674
  var serve = () => {
1631
1675
  throw new Error(`The "serve" API only works in node`);
@@ -2382,7 +2426,7 @@ onmessage = ({ data: wasm }) => {
2382
2426
  callback(null, count);
2383
2427
  };
2384
2428
  let go = new global.Go();
2385
- go.argv = ["", \`--service=\${"0.14.14"}\`];
2429
+ go.argv = ["", \`--service=\${"0.14.21"}\`];
2386
2430
  WebAssembly.instantiate(wasm, go.importObject).then(({ instance }) => go.run(instance));
2387
2431
  };}`;
2388
2432
  let worker;