minipack 0.3.2 → 0.3.3
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/CHANGELOG.md +10 -0
- data/lib/minipack/helper.rb +17 -6
- data/lib/minipack/manifest.rb +42 -2
- data/lib/minipack/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: bc8eca1d1f23c89720efbc82ceaa6afe4b914295e42be8edd661a22bdedafe43
|
|
4
|
+
data.tar.gz: b8fa5684228e7d29882f98c1cff298414f48cb8df94929ee215560b081e355a3
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ccd21785cac03e000600d35917f51f5a263b01c356ad07cb74ed6c26a9fc8fdee2620856416769405560308c3b8a5f4d501827399ebde570b0444c71868fe642
|
|
7
|
+
data.tar.gz: 90f9e18cdf3b56ce4d102ad7603579799398cbd44496e673950a717c7af5d7fa5db0211df571bb09edf44da3dbfe4d4fa13db6ba0a3b9ce203e1fe67aebf282a
|
data/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
# 0.3.3 / 2019-09-12
|
|
2
|
+
|
|
3
|
+
## Enhancements:
|
|
4
|
+
|
|
5
|
+
* Support manifest files that have integrity hashes in them (#24) by @HellRok
|
|
6
|
+
|
|
7
|
+
## Breaking changes(internal apis only)
|
|
8
|
+
|
|
9
|
+
* Return value of `Minipack::Manifest#lookup!` and `Minipack::Manifest#find`, now changed from String to `Minipack::Manifest::Entry`.
|
|
10
|
+
|
|
1
11
|
# 0.3.2 / 2019-07-22
|
|
2
12
|
|
|
3
13
|
## Enhancements:
|
data/lib/minipack/helper.rb
CHANGED
|
@@ -9,7 +9,7 @@ module Minipack::Helper
|
|
|
9
9
|
# <%= asset_bundle_path 'icon/favicon.ico' %> # => "/assets/web/pack/icon/favicon-1016838bab065ae1e122.ico"
|
|
10
10
|
def asset_bundle_path(name, manifest: nil, **options)
|
|
11
11
|
manifest = get_manifest_by_key(manifest)
|
|
12
|
-
asset_path(manifest.lookup!(name.to_s), **options)
|
|
12
|
+
asset_path(manifest.lookup!(name.to_s).path, **options)
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
# Example:
|
|
@@ -20,7 +20,9 @@ module Minipack::Helper
|
|
|
20
20
|
# <%= javascript_bundle_tag 'orders/app' %> # =>
|
|
21
21
|
# <script src="/assets/web/pack/orders/app-1016838bab065ae1e314.js"></script>
|
|
22
22
|
def javascript_bundle_tag(*names, manifest: nil, **options)
|
|
23
|
-
|
|
23
|
+
entries_from_manifest(names, 'js', key: manifest).map { |entry|
|
|
24
|
+
javascript_include_tag(entry.path, **options_for(entry, options))
|
|
25
|
+
}.join("\n").html_safe
|
|
24
26
|
end
|
|
25
27
|
|
|
26
28
|
# Creates script tags that references the js chunks from entrypoints when using split chunks API.
|
|
@@ -53,7 +55,9 @@ module Minipack::Helper
|
|
|
53
55
|
# href="/assets/web/pack/orders/style-1016838bab065ae1e122.css" />
|
|
54
56
|
def stylesheet_bundle_tag(*names, manifest: nil, **options)
|
|
55
57
|
if Minipack.configuration.extract_css?
|
|
56
|
-
|
|
58
|
+
entries_from_manifest(names, 'css', key: manifest).map { |entry|
|
|
59
|
+
stylesheet_link_tag(entry.path, **options_for(entry, options))
|
|
60
|
+
}.join("\n").html_safe
|
|
57
61
|
end
|
|
58
62
|
end
|
|
59
63
|
|
|
@@ -85,23 +89,30 @@ module Minipack::Helper
|
|
|
85
89
|
# <img src="/assets/pack/icon-1016838bab065ae1e314.png" width="16" height="10" alt="Edit Entry" />
|
|
86
90
|
def image_bundle_tag(name, manifest: nil, **options)
|
|
87
91
|
manifest = get_manifest_by_key(manifest)
|
|
88
|
-
image_tag(manifest.lookup!(name.to_s), **options)
|
|
92
|
+
image_tag(manifest.lookup!(name.to_s).path, **options)
|
|
89
93
|
end
|
|
90
94
|
|
|
91
95
|
private
|
|
92
96
|
|
|
93
|
-
def
|
|
97
|
+
def entries_from_manifest(names, ext, key: nil)
|
|
94
98
|
manifest = get_manifest_by_key(key)
|
|
95
99
|
names.map { |name| manifest.lookup!(name.to_s + '.' + ext) }
|
|
96
100
|
end
|
|
97
101
|
|
|
98
102
|
def sources_from_manifest_entrypoints(names, type, key: nil)
|
|
99
103
|
manifest = get_manifest_by_key(key)
|
|
100
|
-
names.map { |name| manifest.lookup_pack_with_chunks!(name, type: type) }.flatten.uniq
|
|
104
|
+
names.map { |name| manifest.lookup_pack_with_chunks!(name, type: type).entries.map(&:path) }.flatten.uniq
|
|
101
105
|
end
|
|
102
106
|
|
|
103
107
|
def get_manifest_by_key(key = nil)
|
|
104
108
|
repository = Minipack.configuration.manifests
|
|
105
109
|
key.nil? ? repository.default : repository.get(key)
|
|
106
110
|
end
|
|
111
|
+
|
|
112
|
+
# @param [Minipack::Manifest::Entry] entry
|
|
113
|
+
# @param [Hash] options
|
|
114
|
+
def options_for(entry, options)
|
|
115
|
+
return options unless entry.integrity
|
|
116
|
+
options.merge(integrity: entry.integrity)
|
|
117
|
+
end
|
|
107
118
|
end
|
data/lib/minipack/manifest.rb
CHANGED
|
@@ -6,6 +6,36 @@ require 'uri'
|
|
|
6
6
|
|
|
7
7
|
module Minipack
|
|
8
8
|
class Manifest
|
|
9
|
+
# A class that represents a single entry in a manifest
|
|
10
|
+
class Entry
|
|
11
|
+
attr_reader :path, :integrity
|
|
12
|
+
|
|
13
|
+
# @param [String] path single path of a single entry
|
|
14
|
+
# @param [String,nil] integrity optional value for subresource integrity of script tags
|
|
15
|
+
def initialize(path, integrity: nil)
|
|
16
|
+
@path = path
|
|
17
|
+
@integrity = integrity
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def ==(other)
|
|
21
|
+
@path == other.path && @integrity == other.integrity
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# A class that represents a group of chunked entries in a manifest
|
|
26
|
+
class ChunkGroup
|
|
27
|
+
attr_reader :entries
|
|
28
|
+
|
|
29
|
+
# @param [Array<Minipack::Manifest::Entry>] entries paths of chunked group
|
|
30
|
+
def initialize(entries)
|
|
31
|
+
@entries = Array(entries).map { |entry| entry.is_a?(String) ? Entry.new(entry) : entry }
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def ==(other)
|
|
35
|
+
@entries == other.entries
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
9
39
|
class MissingEntryError < StandardError; end
|
|
10
40
|
class FileNotFoundError < StandardError; end
|
|
11
41
|
|
|
@@ -20,15 +50,25 @@ module Minipack
|
|
|
20
50
|
def lookup_pack_with_chunks!(name, type: nil)
|
|
21
51
|
manifest_pack_type = manifest_type(name, type)
|
|
22
52
|
manifest_pack_name = manifest_name(name, manifest_pack_type)
|
|
23
|
-
|
|
53
|
+
paths = data['entrypoints']&.dig(manifest_pack_name, manifest_pack_type) || handle_missing_entry(name)
|
|
54
|
+
ChunkGroup.new(paths)
|
|
24
55
|
end
|
|
25
56
|
|
|
26
57
|
def lookup!(name)
|
|
27
58
|
find(name) || handle_missing_entry(name)
|
|
28
59
|
end
|
|
29
60
|
|
|
61
|
+
# Find an entry by it's name
|
|
62
|
+
#
|
|
63
|
+
# @param [Symbol] name entry name
|
|
64
|
+
# @return [Minipack::Entry]
|
|
30
65
|
def find(name)
|
|
31
|
-
data[name.to_s]
|
|
66
|
+
path = data[name.to_s] || return
|
|
67
|
+
if path.is_a? Hash
|
|
68
|
+
integrity = path['integrity']
|
|
69
|
+
path = path['src']
|
|
70
|
+
end
|
|
71
|
+
Entry.new(path, integrity: integrity)
|
|
32
72
|
end
|
|
33
73
|
|
|
34
74
|
def assets
|
data/lib/minipack/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: minipack
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.3.
|
|
4
|
+
version: 0.3.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Nobuhiro Nikushi
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2019-
|
|
11
|
+
date: 2019-09-12 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: actionview
|