isomorfeus-asset-manager 0.12.1 → 0.12.2

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: 4322f1c6ad8dff9d4df265bc44715ed4bb057e031ac81d9d3a13e8f7eef885f7
4
- data.tar.gz: 3fb59bd726d4c25cd9f214b511d44759aea3e4af056e298ccd6afd70971c7ccf
3
+ metadata.gz: 169aeadc71daafe7fa04cdb85aea6c6c00e4827624c1a85a89bc7c0555a063c3
4
+ data.tar.gz: 622b5c1979563fb4d5bb7a1d064bc8cebbdb41be5626cc8d7a234e15f21bbd24
5
5
  SHA512:
6
- metadata.gz: 9c73e59b221e26ff3d9e90920d02b6c6f47400e3808e36099d43d0f838090ba31d8231dbec1af43c5adddad62974a10be5b3560ed1a6e29c9adff6d38b6efda2
7
- data.tar.gz: bfbef83aa44a0763209e1cedab3cc754e066e630309feea7252ff7b81e7922c7ad274e1aa00e6b628554fb38519bc644898cb5e9d740b42479b5691c8424b3cf
6
+ metadata.gz: 59b5412998db5107f023cde6368ca9137f328f54fda0b8e0b10b8871a2db0936371e422ee86ee35fb55c99b15fa86a0a6db3fd2f99a65d488c4dce73df25242d
7
+ data.tar.gz: 741c7cab68752ff9c7fb13dc4a3dfa924a9e884bb94f587b1a237ad9dbdb0239174f43b94bb8bbabd73e15e7529bd739973bff9b3640c55351f464a0658f7cfd
@@ -6,11 +6,14 @@ module Isomorfeus
6
6
  attr_reader :bundle_map
7
7
  attr_reader :bundle_map_gz
8
8
  attr_reader :mtime, :ruby_imports, :target
9
+ attr_reader :mutex
9
10
 
10
11
  def initialize(target = :browser)
12
+ @mutex = Mutex.new
11
13
  raise "Unknown asset target!" unless %i[browser node].include?(target)
12
14
  @target = target
13
15
  @bundled = false
16
+ @ruby_compiled = false
14
17
  @js_imports = []
15
18
  @ruby_imports = []
16
19
  end
@@ -31,7 +34,6 @@ module Isomorfeus
31
34
  @bundle_gz = Zlib::gzip(b, level: Zlib::BEST_COMPRESSION)
32
35
  @bundle_gz_size = @bundle_gz.size
33
36
  end
34
- @mtime = Time.now
35
37
  @bundle
36
38
  end
37
39
 
@@ -39,7 +41,6 @@ module Isomorfeus
39
41
  @bundled = true
40
42
  @bundle_map = m
41
43
  @bundle_map_gz = Zlib::gzip(m, level: Zlib::BEST_COMPRESSION) unless @target == :node
42
- @mtime = Time.now unless @mtime
43
44
  @bundle_map
44
45
  end
45
46
 
@@ -51,6 +52,10 @@ module Isomorfeus
51
52
  @ruby_imports.map(&:module_name)
52
53
  end
53
54
 
55
+ def touch
56
+ @mtime = Time.now
57
+ end
58
+
54
59
  def to_s
55
60
  js = @target == :node ? '' : "if (typeof globalThis !== 'undefined' && typeof global === 'undefined') { globalThis.global = globalThis; }\n"
56
61
  unless @js_imports.empty?
@@ -10,6 +10,7 @@ module Isomorfeus
10
10
  attr_accessor :root
11
11
  attr_accessor :app_root
12
12
  attr_accessor :assets_path
13
+ attr_accessor :asset_manager_tmpdir
13
14
  attr_accessor :node_paths
14
15
  attr_accessor :assets
15
16
 
@@ -66,4 +67,6 @@ module Isomorfeus
66
67
  'web.js' => Isomorfeus::AssetManager::Asset.new(:browser),
67
68
  'ssr.js' => Isomorfeus::AssetManager::Asset.new(:node)
68
69
  }
70
+ self.asset_manager_tmpdir = Dir.mktmpdir
71
+ Kernel.at_exit { FileUtils.rm_rf(Isomorfeus.asset_manager_tmpdir) if Dir.exist?(Isomorfeus.asset_manager_tmpdir) }
69
72
  end
@@ -1,5 +1,5 @@
1
1
  module Isomorfeus
2
2
  class AssetManager
3
- VERSION = '0.12.1'
3
+ VERSION = '0.12.2'
4
4
  end
5
5
  end
@@ -7,7 +7,7 @@ module Isomorfeus
7
7
  def initialize
8
8
  Isomorfeus.set_node_paths
9
9
 
10
- @tmpdir = Dir.mktmpdir
10
+ @tmpdir = Isomorfeus.asset_manager_tmpdir
11
11
  @imports_path = File.join(@tmpdir, 'imports')
12
12
  @output_path = File.join(@tmpdir, 'output')
13
13
  FileUtils.mkdir_p(@imports_path)
@@ -30,12 +30,14 @@ module Isomorfeus
30
30
 
31
31
  def transition(asset_key, asset)
32
32
  return if !Isomorfeus.development? && asset.bundled?
33
- compile_ruby_and_save(asset_key, asset)
34
- save_imports(asset_key, asset)
35
- run_esbuild(asset_key, asset)
36
- asset.bundle = bundled_asset(asset_key)
37
- if !Isomorfeus.production? && asset.target != :node
38
- asset.bundle_map = bundled_asset_map(asset_key)
33
+ asset.mutex.synchronize do
34
+ return if !Isomorfeus.development? && asset.bundled?
35
+ asset.touch
36
+ compile_ruby_and_save(asset_key, asset)
37
+ save_imports(asset_key, asset)
38
+ run_esbuild(asset_key, asset)
39
+ asset.bundle = bundled_asset(asset_key)
40
+ asset.bundle_map = bundled_asset_map(asset_key) unless Isomorfeus.production?
39
41
  end
40
42
  end
41
43
 
@@ -55,15 +57,17 @@ module Isomorfeus
55
57
 
56
58
  def compile_ruby_and_save(asset_key, asset)
57
59
  asset.ruby_imports.each do |ruby_import|
60
+ out_file = File.join(@imports_path, ruby_import.module_name + '.js')
61
+ next if !Isomorfeus.development? && File.exist?(out_file)
62
+ js_map_path = File.join(@imports_path, ruby_import.module_name + '.js.map')
58
63
  result = Opal::Builder.build(ruby_import.resolved_path, { es6_wrap: true })
59
64
  FileUtils.mkdir_p(File.join(*[@imports_path].concat(ruby_import.module_name.split('/')[0...-1]))) if ruby_import.module_name.include?('/')
60
65
  js = result.to_s
61
- if !Isomorfeus.production? && asset.target != :node
62
- js_map_path = File.join(@imports_path, ruby_import.module_name + '.js.map')
66
+ unless Isomorfeus.production?
63
67
  js << "\n//# sourceMappingURL=file://#{js_map_path}\n"
64
68
  File.write(js_map_path, result.source_map)
65
69
  end
66
- File.write(File.join(@imports_path, ruby_import.module_name + '.js'), js)
70
+ File.write(out_file, js)
67
71
  end
68
72
  end
69
73
 
@@ -133,7 +137,7 @@ module Isomorfeus
133
137
  outdir: global.output_path,
134
138
  platform: '#{asset.target}',
135
139
  publicPath: '/assets',
136
- sourcemap: #{(!Isomorfeus.production? && asset.target != :node) ? 'true' : 'false'},
140
+ sourcemap: #{!Isomorfeus.production? ? 'true' : 'false'},
137
141
  splitting: false,
138
142
  target: 'es6',
139
143
  write: true
@@ -1,4 +1,5 @@
1
1
  require 'fileutils'
2
+ require 'thread'
2
3
  require 'tmpdir'
3
4
  require 'zlib'
4
5
  require 'opal'
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.12.1
4
+ version: 0.12.2
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-09-06 00:00:00.000000000 Z
11
+ date: 2021-09-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: isomorfeus-speednode