minipack 0.3.1 → 0.3.6
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 +34 -0
- data/README.md +4 -5
- data/lib/minipack/configuration.rb +10 -0
- data/lib/minipack/helper.rb +27 -8
- data/lib/minipack/manifest.rb +58 -2
- data/lib/minipack/manifest_repository.rb +1 -1
- data/lib/minipack/version.rb +1 -1
- data/minipack.gemspec +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: be2ebfb0d6964abdaa84f7f95b525d69dfdc1a2c2229f5acb1f9d50951042358
|
4
|
+
data.tar.gz: f847d5b248c873b7d0897f46734a1ca6b2191fec5ed139b876a32fb012d6b111
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 28f87f19304affa8867ddb3a45afe4f8a273ab4156208ef87de626a2de23d671232d5ddf011149a5296bf52191a3e8dfe686dc4e337884623d9087cba0dfc323
|
7
|
+
data.tar.gz: f8a35530ba477d50ee25dde27761848447cada20f053730215af543291408519ff1420800c6081db039f9513ff9440505ad9ad7c96607c9b760a1c2017ee8f2f
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,37 @@
|
|
1
|
+
# 0.3.6 / 2020-08-21
|
2
|
+
|
3
|
+
## Bug fixes
|
4
|
+
|
5
|
+
* Fix duplicated shared chunks issue (#38) by @thiagobrandam
|
6
|
+
|
7
|
+
# 0.3.5 / 2020-03-21
|
8
|
+
|
9
|
+
## Bug fixes
|
10
|
+
|
11
|
+
* change name of method to fix conflict with ransack (#32) by @sadgb
|
12
|
+
|
13
|
+
# 0.3.4 / 2020-01-26
|
14
|
+
|
15
|
+
## Bug fixes
|
16
|
+
|
17
|
+
* Add support for integrity attribute when using experimental splitChunks (#27) by @Jukejc
|
18
|
+
|
19
|
+
# 0.3.3 / 2019-09-12
|
20
|
+
|
21
|
+
## Enhancements:
|
22
|
+
|
23
|
+
* Support manifest files that have integrity hashes in them (#24) by @HellRok
|
24
|
+
|
25
|
+
## Breaking changes(internal apis only)
|
26
|
+
|
27
|
+
* Return value of `Minipack::Manifest#lookup!` and `Minipack::Manifest#find`, now changed from String to `Minipack::Manifest::Entry`.
|
28
|
+
|
29
|
+
# 0.3.2 / 2019-07-22
|
30
|
+
|
31
|
+
## Enhancements:
|
32
|
+
|
33
|
+
* Add ability to instruct minipack if CSS will be in the manifest (#22) by @jmortlock
|
34
|
+
|
1
35
|
# 0.3.1 / 2019-06-06
|
2
36
|
|
3
37
|
## Bug fixes
|
data/README.md
CHANGED
@@ -4,7 +4,7 @@ Minipack, a gem for minimalists, which can integrates Rails with [webpack](https
|
|
4
4
|
|
5
5
|
Minipack provides view helpers through a manifest, which resolve paths of assets build by a webpack configured by you as you like.
|
6
6
|
|
7
|
-
**Note:** Before Minipack v0.3.0, it was called WebpackManifest. Please refer to [the migration guide](./docs/migrate_from_webpack_manifest.md
|
7
|
+
**Note:** Before Minipack v0.3.0, it was called WebpackManifest. Please refer to [the migration guide](./docs/migrate_from_webpack_manifest.md) from WebpackManifest.
|
8
8
|
|
9
9
|
## Features
|
10
10
|
|
@@ -48,6 +48,9 @@ Minipack.configuration do |c|
|
|
48
48
|
# Register a path to a manifest file here. Right now you have to specify an absolute path.
|
49
49
|
c.manifest = Rails.root.join('public', 'assets', 'manifest.json')
|
50
50
|
|
51
|
+
# If you are not extracting CSS in your webpack config you should set this flag to false
|
52
|
+
# c.extract_css = !Rails.env.development?
|
53
|
+
|
51
54
|
# The base directory for the frontend system. By default, it will be
|
52
55
|
# `Rails.root`.
|
53
56
|
# c.base_path = Rails.root
|
@@ -295,10 +298,6 @@ After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
|
295
298
|
|
296
299
|
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
297
300
|
|
298
|
-
**v0.2.x-trunk**
|
299
|
-
|
300
|
-
v0.2.x-trunk is made from the latest released version v0.2.4. I will not intend to actively maintain v0.2.x anymore, except security fixes or bug fixes.
|
301
|
-
|
302
301
|
## Contributing
|
303
302
|
|
304
303
|
Bug reports and pull requests are welcome on GitHub at https://github.com/nikushi/minipack.
|
@@ -79,6 +79,9 @@ module Minipack
|
|
79
79
|
# The command for installation of npm packages
|
80
80
|
config_attr :pkg_install_command, default: 'npm install'
|
81
81
|
|
82
|
+
# Disable if you're webpack configuration is not extracting CSS files
|
83
|
+
config_attr :extract_css, default: true
|
84
|
+
|
82
85
|
# Let me leave this line for remember the indea of post pkg install hooks
|
83
86
|
# config_attr :post_install_hooks, default: []
|
84
87
|
|
@@ -164,6 +167,13 @@ module Minipack
|
|
164
167
|
File.join(root_path, 'tmp', 'cache', 'minipack')
|
165
168
|
end
|
166
169
|
|
170
|
+
# CSS is extracted in the webpack build
|
171
|
+
#
|
172
|
+
# @return [Boolean]
|
173
|
+
def extract_css?
|
174
|
+
extract_css
|
175
|
+
end
|
176
|
+
|
167
177
|
private
|
168
178
|
|
169
179
|
def root?
|
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, **minipack_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.
|
@@ -39,7 +41,9 @@ module Minipack::Helper
|
|
39
41
|
# <%= javascript_bundles_with_chunks_tag 'calendar' %>
|
40
42
|
# <%= javascript_bundles_with_chunks_tag 'map' %>
|
41
43
|
def javascript_bundles_with_chunks_tag(*names, manifest: nil, **options)
|
42
|
-
|
44
|
+
sources_from_manifest_entrypoints(names, 'js', key: manifest).map { |entry|
|
45
|
+
javascript_include_tag(entry.path, **minipack_options_for(entry, options))
|
46
|
+
}.join("\n").html_safe
|
43
47
|
end
|
44
48
|
|
45
49
|
# Examples:
|
@@ -52,7 +56,11 @@ module Minipack::Helper
|
|
52
56
|
# <link rel="stylesheet" media="screen"
|
53
57
|
# href="/assets/web/pack/orders/style-1016838bab065ae1e122.css" />
|
54
58
|
def stylesheet_bundle_tag(*names, manifest: nil, **options)
|
55
|
-
|
59
|
+
if Minipack.configuration.extract_css?
|
60
|
+
entries_from_manifest(names, 'css', key: manifest).map { |entry|
|
61
|
+
stylesheet_link_tag(entry.path, **minipack_options_for(entry, options))
|
62
|
+
}.join("\n").html_safe
|
63
|
+
end
|
56
64
|
end
|
57
65
|
|
58
66
|
# Creates link tags that references the css chunks from entrypoints when using split chunks API.
|
@@ -69,7 +77,11 @@ module Minipack::Helper
|
|
69
77
|
# <%= stylesheet_bundles_with_chunks_tag 'calendar' %>
|
70
78
|
# <%= stylesheet_bundles_with_chunks_tag 'map' %>
|
71
79
|
def stylesheet_bundles_with_chunks_tag(*names, manifest: nil, **options)
|
72
|
-
|
80
|
+
if Minipack.configuration.extract_css?
|
81
|
+
sources_from_manifest_entrypoints(names, 'css', key: manifest).map { |entry|
|
82
|
+
stylesheet_link_tag(entry.path, **minipack_options_for(entry, options))
|
83
|
+
}.join("\n").html_safe
|
84
|
+
end
|
73
85
|
end
|
74
86
|
|
75
87
|
# Examples:
|
@@ -81,23 +93,30 @@ module Minipack::Helper
|
|
81
93
|
# <img src="/assets/pack/icon-1016838bab065ae1e314.png" width="16" height="10" alt="Edit Entry" />
|
82
94
|
def image_bundle_tag(name, manifest: nil, **options)
|
83
95
|
manifest = get_manifest_by_key(manifest)
|
84
|
-
image_tag(manifest.lookup!(name.to_s), **options)
|
96
|
+
image_tag(manifest.lookup!(name.to_s).path, **options)
|
85
97
|
end
|
86
98
|
|
87
99
|
private
|
88
100
|
|
89
|
-
def
|
101
|
+
def entries_from_manifest(names, ext, key: nil)
|
90
102
|
manifest = get_manifest_by_key(key)
|
91
103
|
names.map { |name| manifest.lookup!(name.to_s + '.' + ext) }
|
92
104
|
end
|
93
105
|
|
94
106
|
def sources_from_manifest_entrypoints(names, type, key: nil)
|
95
107
|
manifest = get_manifest_by_key(key)
|
96
|
-
names.map { |name| manifest.lookup_pack_with_chunks!(name, type: type) }.flatten.uniq
|
108
|
+
names.map { |name| manifest.lookup_pack_with_chunks!(name, type: type).entries }.flatten.uniq(&:path)
|
97
109
|
end
|
98
110
|
|
99
111
|
def get_manifest_by_key(key = nil)
|
100
112
|
repository = Minipack.configuration.manifests
|
101
113
|
key.nil? ? repository.default : repository.get(key)
|
102
114
|
end
|
115
|
+
|
116
|
+
# @param [Minipack::Manifest::Entry] entry
|
117
|
+
# @param [Hash] options
|
118
|
+
def minipack_options_for(entry, options)
|
119
|
+
return options unless entry.integrity
|
120
|
+
options.merge(integrity: entry.integrity)
|
121
|
+
end
|
103
122
|
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,30 @@ 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
|
+
|
55
|
+
entries = data['entrypoints']&.dig(manifest_pack_name, manifest_pack_type).map do |source|
|
56
|
+
entry_from_source(source) || handle_missing_entry(name)
|
57
|
+
end
|
58
|
+
|
59
|
+
ChunkGroup.new(entries)
|
24
60
|
end
|
25
61
|
|
26
62
|
def lookup!(name)
|
27
63
|
find(name) || handle_missing_entry(name)
|
28
64
|
end
|
29
65
|
|
66
|
+
# Find an entry by it's name
|
67
|
+
#
|
68
|
+
# @param [Symbol] name entry name
|
69
|
+
# @return [Minipack::Entry]
|
30
70
|
def find(name)
|
31
|
-
data[name.to_s]
|
71
|
+
path = data[name.to_s] || return
|
72
|
+
if path.is_a? Hash
|
73
|
+
integrity = path['integrity']
|
74
|
+
path = path['src']
|
75
|
+
end
|
76
|
+
Entry.new(path, integrity: integrity)
|
32
77
|
end
|
33
78
|
|
34
79
|
def assets
|
@@ -82,5 +127,16 @@ module Minipack
|
|
82
127
|
#{JSON.pretty_generate(@data)}
|
83
128
|
MSG
|
84
129
|
end
|
130
|
+
|
131
|
+
# Find an entry by its source
|
132
|
+
#
|
133
|
+
# @param [String] source
|
134
|
+
# @return [Minipack::Entry,nil]
|
135
|
+
def entry_from_source(source)
|
136
|
+
entry = assets.find { |entry| entry.is_a?(String) ? entry == source : entry['src'] == source }
|
137
|
+
return unless entry
|
138
|
+
entry.is_a?(String) ? Entry.new(entry) : Entry.new(entry['src'], integrity: entry['integrity'])
|
139
|
+
end
|
85
140
|
end
|
86
141
|
end
|
142
|
+
|
@@ -17,7 +17,7 @@ module Minipack
|
|
17
17
|
|
18
18
|
# @private
|
19
19
|
def add(key, path, **options)
|
20
|
-
manifest = Minipack::Manifest.new(path, options)
|
20
|
+
manifest = Minipack::Manifest.new(path, **options)
|
21
21
|
# Mark a first one as a default
|
22
22
|
@default = manifest if @manifests.empty?
|
23
23
|
@manifests[key.to_sym] = manifest
|
data/lib/minipack/version.rb
CHANGED
data/minipack.gemspec
CHANGED
@@ -27,6 +27,6 @@ Gem::Specification.new do |spec|
|
|
27
27
|
spec.add_dependency 'actionview'
|
28
28
|
spec.add_dependency "railties", ">= 4.2"
|
29
29
|
spec.add_development_dependency "bundler", "~> 2.0"
|
30
|
-
spec.add_development_dependency "rake", "
|
30
|
+
spec.add_development_dependency "rake", ">= 12.3.3"
|
31
31
|
spec.add_development_dependency "rspec", "~> 3.0"
|
32
32
|
end
|
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.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nobuhiro Nikushi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-08-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionview
|
@@ -56,16 +56,16 @@ dependencies:
|
|
56
56
|
name: rake
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
61
|
+
version: 12.3.3
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - "
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
68
|
+
version: 12.3.3
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rspec
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|