sewing_kit 0.8.0 → 0.27.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/lib/sewing_kit/version.rb +1 -1
- data/lib/sewing_kit/webpack/helper.rb +31 -41
- data/lib/sewing_kit/webpack/manifest.rb +5 -3
- data/lib/sewing_kit/webpack/manifest/base.rb +4 -4
- data/lib/sewing_kit/webpack/manifest/development.rb +6 -0
- data/lib/sewing_kit/webpack/manifest/production.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 767dcb5c1f9643937e519b07940c286ef42c1c6a
|
4
|
+
data.tar.gz: 3744a04508c81a91b90bdf72d5d0f43eb5ee17e8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: deaefac1ed2b3d39f233bdfbaa6d23c7fa32f8a8d827878d1b416e26782f5f5d42fde18487a733653d570d4f293a3747230a90c28601f9c2602e0a43c0885534
|
7
|
+
data.tar.gz: c1b7e41ef24ba24aff7d0812b3da10b879c4618e991266d8c58674ec67cf039058339f9dc0a2149a89f7f9d2d74d011fb57eb5f76db19c642775f5ee0dc9c832
|
data/README.md
CHANGED
@@ -28,8 +28,8 @@ sewing_kit looks for JavaScript in `app/ui/index.js`. The code in `index.js` (a
|
|
28
28
|
The `main` bundle is imported into `erb` files using Rails helpers:
|
29
29
|
|
30
30
|
```erb
|
31
|
-
<%= sewing_kit_link_tag *
|
32
|
-
<%= sewing_kit_script_tag *
|
31
|
+
<%= sewing_kit_link_tag *sewing_kit_assets('main') %>
|
32
|
+
<%= sewing_kit_script_tag *sewing_kit_assets('main') %>
|
33
33
|
```
|
34
34
|
|
35
35
|
**Note:** CSS `<link>` tags appear only in production; in development, CSS is embedded within the `main.js` bundle.
|
data/lib/sewing_kit/version.rb
CHANGED
@@ -11,35 +11,38 @@ module SewingKit
|
|
11
11
|
class UnknownJavaScriptAssetError < StandardError
|
12
12
|
end
|
13
13
|
|
14
|
-
|
14
|
+
Asset = Struct.new(:path, :integrity)
|
15
|
+
|
16
|
+
def sewing_kit_assets(entrypoint_name, extension: 'js')
|
15
17
|
return '' unless entrypoint_name.present?
|
16
18
|
|
17
|
-
|
18
|
-
return
|
19
|
+
assets = SewingKit::Webpack::Manifest.asset_dependencies(entrypoint_name)
|
20
|
+
return [] unless assets && assets[extension]
|
19
21
|
|
20
|
-
|
21
|
-
|
22
|
-
|
22
|
+
dependencies = assets[extension]
|
23
|
+
dependencies.unshift(dll_asset) if serve_development_assets? && extension == 'js'
|
24
|
+
dependencies.map do |raw_asset|
|
25
|
+
Asset.new(raw_asset['path'], raw_asset['integrity'])
|
26
|
+
end
|
23
27
|
end
|
24
28
|
|
25
|
-
def sewing_kit_link_tag(*
|
26
|
-
options =
|
29
|
+
def sewing_kit_link_tag(*assets)
|
30
|
+
options = assets.extract_options!
|
27
31
|
|
28
|
-
tags =
|
29
|
-
next '' if path == ''
|
30
|
-
create_asset_tag(:link,
|
32
|
+
tags = assets.uniq.map do |asset|
|
33
|
+
next '' if asset.path == ''
|
34
|
+
create_asset_tag(:link, asset, options)
|
31
35
|
end
|
32
36
|
|
33
37
|
safe_join(tags, "\n")
|
34
38
|
end
|
35
39
|
|
36
|
-
def sewing_kit_script_tag(*
|
37
|
-
options =
|
38
|
-
|
39
|
-
|
40
|
-
next '' if path == ''
|
40
|
+
def sewing_kit_script_tag(*assets)
|
41
|
+
options = assets.extract_options!
|
42
|
+
tags = assets.map do |asset|
|
43
|
+
next '' if asset.path == ''
|
41
44
|
|
42
|
-
create_asset_tag(:script,
|
45
|
+
create_asset_tag(:script, asset, options)
|
43
46
|
end
|
44
47
|
|
45
48
|
safe_join(tags, "\n")
|
@@ -47,46 +50,33 @@ module SewingKit
|
|
47
50
|
|
48
51
|
private
|
49
52
|
|
50
|
-
def create_asset_tag(tag_type,
|
53
|
+
def create_asset_tag(tag_type, asset, tag_options)
|
51
54
|
raise ArgumentError, "Invalid tag type: #{tag_type}" unless [:script, :link].include? tag_type
|
52
55
|
|
53
56
|
options = tag_options.clone
|
54
57
|
|
55
|
-
if tag_options[:integrity]
|
56
|
-
|
57
|
-
|
58
|
+
if tag_options[:integrity] && asset.integrity
|
59
|
+
options[:integrity] = asset.integrity
|
60
|
+
else
|
61
|
+
options.delete(:integrity)
|
58
62
|
end
|
59
63
|
|
60
64
|
case tag_type
|
61
65
|
when :script
|
62
|
-
content_tag(:script, '', options.reverse_merge(src: path))
|
66
|
+
content_tag(:script, '', options.reverse_merge(src: asset.path))
|
63
67
|
when :link
|
64
|
-
tag(:link, options.reverse_merge(href: path, rel: 'stylesheet'))
|
68
|
+
tag(:link, options.reverse_merge(href: asset.path, rel: 'stylesheet'))
|
65
69
|
end
|
66
70
|
end
|
67
71
|
|
68
|
-
def maybe_integrity(file_hash)
|
69
|
-
return nil unless file_hash
|
70
|
-
encode_hash(file_hash)
|
71
|
-
end
|
72
|
-
|
73
|
-
def encode_hash(hash)
|
74
|
-
# sewing-kit's default config places a sha256 hash in the filename. Browsers expect integrity
|
75
|
-
# to be the Base64 encoded version of the binary hash prefixed with the hashing algorithm
|
76
|
-
binary_hash = Array(hash).pack('H*')
|
77
|
-
"sha256-#{Base64.strict_encode64(binary_hash)}"
|
78
|
-
end
|
79
|
-
|
80
|
-
def extract_hash(path)
|
81
|
-
# Consumes sewing-kit's [name]-[chunkhash].[ext] format
|
82
|
-
return unless path =~ /.*-[A-Za-z0-9]{64}\.(js|css)/
|
83
|
-
path.rpartition('-').last.split('.').first
|
84
|
-
end
|
85
|
-
|
86
72
|
def serve_development_assets?
|
87
73
|
return false if ENV['SK_SIMULATE_PRODUCTION'] == '1'
|
88
74
|
Rails.env.development?
|
89
75
|
end
|
76
|
+
|
77
|
+
def dll_asset
|
78
|
+
Asset.new('/webpack/assets/dll/vendor.js')
|
79
|
+
end
|
90
80
|
end
|
91
81
|
end
|
92
82
|
end
|
@@ -47,8 +47,8 @@ module SewingKit
|
|
47
47
|
|
48
48
|
class << self
|
49
49
|
# :nodoc:
|
50
|
-
def
|
51
|
-
instance.
|
50
|
+
def asset_dependencies(entrypoint_name)
|
51
|
+
instance.asset_dependencies(entrypoint_name)
|
52
52
|
end
|
53
53
|
|
54
54
|
def clear_cache!
|
@@ -61,7 +61,9 @@ module SewingKit
|
|
61
61
|
|
62
62
|
def instance
|
63
63
|
return @instance if @instance
|
64
|
-
|
64
|
+
|
65
|
+
mode = ENV['NODE_ENV'] || Rails.env.to_s
|
66
|
+
@instance = if mode == 'development' && ENV['SK_SIMULATE_PRODUCTION'] != '1'
|
65
67
|
Development.new
|
66
68
|
else
|
67
69
|
Production.new
|
@@ -8,7 +8,7 @@ module SewingKit
|
|
8
8
|
end
|
9
9
|
|
10
10
|
# :nodoc:
|
11
|
-
def
|
11
|
+
def asset_dependencies(entrypoint_name)
|
12
12
|
metadata['entrypoints'][entrypoint_name]
|
13
13
|
end
|
14
14
|
|
@@ -22,7 +22,7 @@ module SewingKit
|
|
22
22
|
|
23
23
|
def load_metadata_from_node
|
24
24
|
begin
|
25
|
-
stdout, * = Open3.capture3('node_modules/.bin/sewing-kit', 'manifest', "--
|
25
|
+
stdout, * = Open3.capture3('node_modules/.bin/sewing-kit', 'manifest', "--mode=#{mode}")
|
26
26
|
rescue => e
|
27
27
|
raise NodeSewingKitNotRunnable.new(mode, e)
|
28
28
|
end
|
@@ -34,10 +34,10 @@ module SewingKit
|
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
|
-
|
37
|
+
protected
|
38
38
|
|
39
39
|
def mode
|
40
|
-
Rails.env.to_s || 'production'
|
40
|
+
ENV['NODE_ENV'] || Rails.env.to_s || 'production'
|
41
41
|
end
|
42
42
|
end
|
43
43
|
end
|