jekyll-minibundle 1.6.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/LICENSE.txt +1 -1
- data/README.md +16 -12
- data/jekyll-minibundle.gemspec +2 -2
- data/lib/jekyll/minibundle/asset_bundle.rb +19 -10
- data/lib/jekyll/minibundle/asset_file_operations.rb +4 -0
- data/lib/jekyll/minibundle/asset_file_registry.rb +74 -17
- data/lib/jekyll/minibundle/bundle_file.rb +7 -0
- data/lib/jekyll/minibundle/development_file_collection.rb +4 -0
- data/lib/jekyll/minibundle/exceptions.rb +3 -0
- data/lib/jekyll/minibundle/log.rb +15 -0
- data/lib/jekyll/minibundle/mini_bundle_block.rb +1 -2
- data/lib/jekyll/minibundle/version.rb +1 -1
- data/lib/jekyll/minibundle.rb +4 -0
- data/test/integration/minibundle_development_mode_test.rb +56 -12
- data/test/integration/minibundle_production_mode_test.rb +98 -8
- data/test/integration/ministamp_development_mode_test.rb +41 -1
- data/test/integration/ministamp_production_mode_test.rb +41 -1
- data/test/support/test_case.rb +1 -1
- data/test/unit/asset_file_registry_test.rb +67 -19
- data/test/unit/mini_bundle_block_test.rb +1 -1
- data/test/unit/mini_stamp_tag_test.rb +1 -1
- metadata +6 -7
- data/lib/jekyll/minibundle/compatibility.rb +0 -37
- data/test/integration/known_caveats_test.rb +0 -89
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7b98e5563a50d5892a424e3be6ba49fe3d899810
|
4
|
+
data.tar.gz: 38648384d0bce35475e6a8f0787c5d607fbfae80
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 96700c73cdaada8a240ef9009f13e8433e149670bee218cea457ada7e17a21e8781dc4291766bab54144d3527d9b02d9870f2fc8a9abee7c13ab37abb03bc480
|
7
|
+
data.tar.gz: 8c0d2048c10c7e07c1d4d5a59abf0acd0517ca3545febf09451d98b9f957c2bed9e8d22b966cdf6ec8d0370723982955d6aea13d6435bd45cf15322b25733546
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
# 2.0.0 / 2016-04-01
|
2
|
+
|
3
|
+
* Drop support for Jekyll versions below 3
|
4
|
+
* Remove unused asset cache entries and temporary files when Jekyll
|
5
|
+
rebuilds the site
|
6
|
+
* Document a known caveat: the plugin doesn't work with Jekyll's
|
7
|
+
incremental rebuild feature.
|
8
|
+
|
1
9
|
# 1.6.0 / 2016-03-26
|
2
10
|
|
3
11
|
* Log the last 2000 bytes of minifier's STDOUT output if the minifier
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -8,14 +8,17 @@ for cache busting.
|
|
8
8
|
There are no runtime dependencies, except for the minification tool
|
9
9
|
used for bundling (fingerprinting has no dependencies).
|
10
10
|
|
11
|
-
|
11
|
+
The plugin requires Jekyll version 3.x. It is tested with Ruby MRI
|
12
|
+
2.x. Ruby 1.8 and 1.9 are *not* supported.
|
12
13
|
|
13
|
-
The plugin works with Jekyll's watch (auto-regeneration
|
14
|
+
The plugin works with Jekyll's watch mode (auto-regeneration, Jekyll
|
15
|
+
option `--watch`), but not with incremental feature enabled (Jekyll
|
16
|
+
option `--incremental`).
|
14
17
|
|
15
18
|
[![Gem version](https://badge.fury.io/rb/jekyll-minibundle.svg)][MinibundleGem]
|
16
19
|
[![Build status](https://secure.travis-ci.org/tkareine/jekyll-minibundle.svg)][MinibundleBuild]
|
17
20
|
|
18
|
-
|
21
|
+
## Features
|
19
22
|
|
20
23
|
There are two features: asset fingerprinting with MD5 digest over the
|
21
24
|
contents of the asset, and asset bundling combined with the first
|
@@ -40,7 +43,7 @@ backend upon page load. The minification of stylesheets and JavaScript
|
|
40
43
|
sources makes asset sizes smaller and thus faster to load over
|
41
44
|
network.
|
42
45
|
|
43
|
-
|
46
|
+
## Usage
|
44
47
|
|
45
48
|
The plugin ships as a [RubyGem][MinibundleGem]. To install:
|
46
49
|
|
@@ -69,7 +72,7 @@ require 'jekyll/minibundle'
|
|
69
72
|
You must allow Jekyll to use custom plugins. That is, do not enable
|
70
73
|
Jekyll's `safe` setting.
|
71
74
|
|
72
|
-
|
75
|
+
### Asset fingerprinting
|
73
76
|
|
74
77
|
If you just want to have a fingerprint in your asset's path, use
|
75
78
|
`ministamp` tag:
|
@@ -97,7 +100,7 @@ fingerprint to Jekyll's output directory:
|
|
97
100
|
<link href="{{ site.baseurl }}{% ministamp _tmp/site.css assets/site.css %}" rel="stylesheet">
|
98
101
|
```
|
99
102
|
|
100
|
-
|
103
|
+
### Asset bundling
|
101
104
|
|
102
105
|
This is a straightforward way to bundle assets with any minification
|
103
106
|
tool that supports reading input from STDIN and writing the output to
|
@@ -210,7 +213,7 @@ specific one wins. For example, the `minifier_cmd` setting inside
|
|
210
213
|
`minibundle js` block overrides the setting in
|
211
214
|
`$JEKYLL_MINIBUNDLE_CMD_JS` environment variable.
|
212
215
|
|
213
|
-
|
216
|
+
### Recommended directory layout
|
214
217
|
|
215
218
|
It's recommended that you exclude the files you use as asset sources
|
216
219
|
from Jekyll itself. Otherwise, you end up with duplicate files in the
|
@@ -242,7 +245,7 @@ character (`_`), consider using the following directory layout:
|
|
242
245
|
See [Jekyll configuration][JekyllConf] for more about excluding files
|
243
246
|
and directories.
|
244
247
|
|
245
|
-
|
248
|
+
### Development mode
|
246
249
|
|
247
250
|
The plugin has one more trick in its sleeves. If you set
|
248
251
|
`$JEKYLL_MINIBUNDLE_MODE` environment variable to `development`, then
|
@@ -266,15 +269,16 @@ minibundle:
|
|
266
269
|
Should both be defined, the setting from the environment variable
|
267
270
|
wins.
|
268
271
|
|
269
|
-
|
272
|
+
## Example site
|
270
273
|
|
271
274
|
See the contents of `test/fixture/site` directory.
|
272
275
|
|
273
|
-
|
276
|
+
## Known caveats
|
274
277
|
|
275
|
-
|
278
|
+
The plugin does not work with Jekyll's incremental rebuild feature (Jekyll
|
279
|
+
option `--incremental`).
|
276
280
|
|
277
|
-
|
281
|
+
## License
|
278
282
|
|
279
283
|
MIT. See `LICENSE.txt`.
|
280
284
|
|
data/jekyll-minibundle.gemspec
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
require_relative 'lib/jekyll/minibundle/version'
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = 'jekyll-minibundle'
|
@@ -27,7 +27,7 @@ minification tool (not even other gems).
|
|
27
27
|
|
28
28
|
s.test_files = `git ls-files -- test`.split("\n")
|
29
29
|
|
30
|
-
s.add_development_dependency 'jekyll', '~> 3.
|
30
|
+
s.add_development_dependency 'jekyll', '~> 3.0.0'
|
31
31
|
s.add_development_dependency 'minitest', '~> 5.8'
|
32
32
|
s.add_development_dependency 'nokogiri', '~> 1.6'
|
33
33
|
s.add_development_dependency 'rake', '~> 11.1'
|
@@ -1,9 +1,12 @@
|
|
1
1
|
require 'tempfile'
|
2
|
-
require 'jekyll/minibundle/
|
2
|
+
require 'jekyll/minibundle/exceptions'
|
3
3
|
require 'jekyll/minibundle/files'
|
4
|
+
require 'jekyll/minibundle/log'
|
4
5
|
|
5
6
|
module Jekyll::Minibundle
|
6
7
|
class AssetBundle
|
8
|
+
TEMPFILE_PREFIX = 'jekyll-minibundle-'.freeze
|
9
|
+
|
7
10
|
def initialize(config)
|
8
11
|
@type = config.fetch(:type)
|
9
12
|
@asset_paths = config.fetch(:asset_paths)
|
@@ -19,20 +22,26 @@ Missing minification command for bundling #{@type} assets. Specify it in
|
|
19
22
|
END
|
20
23
|
end
|
21
24
|
|
22
|
-
@
|
23
|
-
|
25
|
+
@tempfile = Tempfile.new([TEMPFILE_PREFIX, ".#{@type}"])
|
26
|
+
end
|
27
|
+
|
28
|
+
def close
|
29
|
+
@tempfile.close!
|
30
|
+
@tempfile = nil
|
24
31
|
end
|
25
32
|
|
26
33
|
def path
|
27
|
-
@
|
34
|
+
raise IllegalStateError, 'Cannot get path of closed AssetBundle' unless @tempfile
|
35
|
+
@tempfile.path
|
28
36
|
end
|
29
37
|
|
30
38
|
def make_bundle
|
39
|
+
raise IllegalStateError, 'Cannot make bundle with closed AssetBundle' unless @tempfile
|
31
40
|
exit_status = spawn_minifier(@minifier_cmd) do |input|
|
32
41
|
$stdout.puts # place newline after "(Re)generating..." log messages
|
33
|
-
|
42
|
+
Log.info("Bundling #{@type} assets:")
|
34
43
|
@asset_paths.each do |asset|
|
35
|
-
|
44
|
+
Log.info(relative_path_from(asset, @site_dir))
|
36
45
|
IO.foreach(asset) { |line| input.write(line) }
|
37
46
|
input.puts(';') if @type == :js
|
38
47
|
end
|
@@ -55,7 +64,7 @@ Missing minification command for bundling #{@type} assets. Specify it in
|
|
55
64
|
pid = nil
|
56
65
|
rd, wr = IO.pipe
|
57
66
|
Dir.chdir(@site_dir) do
|
58
|
-
pid = spawn(cmd, out: [@
|
67
|
+
pid = spawn(cmd, out: [@tempfile.path, 'w'], in: rd)
|
59
68
|
end
|
60
69
|
rd.close
|
61
70
|
yield wr
|
@@ -69,16 +78,16 @@ Missing minification command for bundling #{@type} assets. Specify it in
|
|
69
78
|
end
|
70
79
|
|
71
80
|
def log_minifier_error(message)
|
72
|
-
last_bytes = Files.read_last(@
|
81
|
+
last_bytes = Files.read_last(@tempfile.path, 2000)
|
73
82
|
|
74
83
|
return if last_bytes.empty?
|
75
84
|
|
76
|
-
|
85
|
+
Log.error("#{message}, last #{last_bytes.size} bytes of minifier output:")
|
77
86
|
|
78
87
|
last_bytes
|
79
88
|
.gsub(/[^[:print:]\t\n]/) { |ch| '\x' + ch.unpack('H2').first }
|
80
89
|
.split("\n")
|
81
|
-
.each { |line|
|
90
|
+
.each { |line| Log.error(line) }
|
82
91
|
end
|
83
92
|
end
|
84
93
|
end
|
@@ -2,6 +2,10 @@ require 'fileutils'
|
|
2
2
|
|
3
3
|
module Jekyll::Minibundle
|
4
4
|
module AssetFileOperations
|
5
|
+
def cleanup
|
6
|
+
# defaults to no-op
|
7
|
+
end
|
8
|
+
|
5
9
|
def write_destination(site_destination_dir)
|
6
10
|
destination_path = destination(site_destination_dir)
|
7
11
|
FileUtils.mkdir_p(File.dirname(destination_path))
|
@@ -7,10 +7,23 @@ require 'jekyll/minibundle/stamp_file'
|
|
7
7
|
module Jekyll::Minibundle
|
8
8
|
module AssetFileRegistry
|
9
9
|
class << self
|
10
|
-
def
|
10
|
+
def clear_all
|
11
11
|
@_files = {}
|
12
12
|
end
|
13
13
|
|
14
|
+
def clear_unused
|
15
|
+
@_files
|
16
|
+
.select { |_, cached| !cached.fetch(:is_used) }
|
17
|
+
.each do |asset_destination_path, cached|
|
18
|
+
cached.fetch(:file).cleanup
|
19
|
+
@_files.delete(asset_destination_path)
|
20
|
+
end
|
21
|
+
|
22
|
+
@_files.each_value do |cached|
|
23
|
+
cached[:is_used] = false
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
14
27
|
def register_bundle_file(site, bundle_config)
|
15
28
|
register_file_for_bundle_block(BundleFile, site, bundle_config) { |file| [file] }
|
16
29
|
end
|
@@ -35,23 +48,40 @@ module Jekyll::Minibundle
|
|
35
48
|
cached = @_files[asset_destination_path]
|
36
49
|
|
37
50
|
if cached
|
38
|
-
|
51
|
+
if cached.fetch(:type) != :bundle
|
52
|
+
raise "minibundle block has the same destination path as a ministamp tag: '#{asset_destination_path}'"
|
53
|
+
end
|
39
54
|
|
40
55
|
cached_file = cached.fetch(:file)
|
56
|
+
cached_config = cached.fetch(:config)
|
57
|
+
cached_is_used = cached.fetch(:is_used)
|
41
58
|
|
42
|
-
if bundle_config ==
|
43
|
-
|
44
|
-
|
59
|
+
if bundle_config == cached_config
|
60
|
+
unless cached_is_used
|
61
|
+
cached[:is_used] = true
|
62
|
+
add_as_static_files_to_site(site, get_files.call(cached_file))
|
45
63
|
end
|
64
|
+
|
46
65
|
return cached_file
|
47
|
-
else
|
48
|
-
get_files.call(cached_file).each { |file| site.static_files.delete(file) }
|
49
66
|
end
|
67
|
+
|
68
|
+
if cached_is_used
|
69
|
+
raise <<-END
|
70
|
+
Two or more minibundle blocks with the same destination path '#{asset_destination_path}', but having different asset configuration: #{bundle_config.inspect} vs. #{cached_config.inspect}
|
71
|
+
END
|
72
|
+
end
|
73
|
+
|
74
|
+
cached_file.cleanup
|
50
75
|
end
|
51
76
|
|
52
77
|
new_file = file_class.new(site, bundle_config)
|
53
|
-
@_files[asset_destination_path] = {
|
54
|
-
|
78
|
+
@_files[asset_destination_path] = {
|
79
|
+
type: :bundle,
|
80
|
+
file: new_file,
|
81
|
+
config: bundle_config,
|
82
|
+
is_used: true
|
83
|
+
}
|
84
|
+
add_as_static_files_to_site(site, get_files.call(new_file))
|
55
85
|
new_file
|
56
86
|
end
|
57
87
|
|
@@ -59,25 +89,52 @@ module Jekyll::Minibundle
|
|
59
89
|
cached = @_files[asset_destination_path]
|
60
90
|
|
61
91
|
if cached
|
62
|
-
|
92
|
+
if cached.fetch(:type) != :stamp
|
93
|
+
raise "ministamp tag has the same destination path as a minibundle block: '#{asset_destination_path}'"
|
94
|
+
end
|
63
95
|
|
64
96
|
cached_file = cached.fetch(:file)
|
97
|
+
cached_config = cached.fetch(:config)
|
98
|
+
cached_is_used = cached.fetch(:is_used)
|
99
|
+
|
100
|
+
if asset_source_path == cached_config
|
101
|
+
unless cached_is_used
|
102
|
+
cached[:is_used] = true
|
103
|
+
add_as_static_files_to_site(site, [cached_file])
|
104
|
+
end
|
65
105
|
|
66
|
-
if asset_source_path == cached.fetch(:config)
|
67
|
-
site.static_files << cached_file unless site.static_files.include?(cached_file)
|
68
106
|
return cached_file
|
69
|
-
else
|
70
|
-
site.static_files.delete(cached_file)
|
71
107
|
end
|
108
|
+
|
109
|
+
if cached_is_used
|
110
|
+
raise <<-END
|
111
|
+
Two or more ministamp tags with the same destination path '#{asset_destination_path}', but different asset source paths: '#{asset_source_path}' vs. '#{cached_config}'
|
112
|
+
END
|
113
|
+
end
|
114
|
+
|
115
|
+
cached_file.cleanup
|
72
116
|
end
|
73
117
|
|
74
118
|
new_file = file_class.new(site, asset_source_path, asset_destination_path)
|
75
|
-
@_files[asset_destination_path] = {
|
76
|
-
|
119
|
+
@_files[asset_destination_path] = {
|
120
|
+
type: :stamp,
|
121
|
+
file: new_file,
|
122
|
+
config: asset_source_path,
|
123
|
+
is_used: true
|
124
|
+
}
|
125
|
+
add_as_static_files_to_site(site, [new_file])
|
77
126
|
new_file
|
78
127
|
end
|
128
|
+
|
129
|
+
def add_as_static_files_to_site(site, files)
|
130
|
+
files.each { |file| site.static_files << file }
|
131
|
+
end
|
79
132
|
end
|
80
133
|
|
81
|
-
|
134
|
+
clear_all
|
82
135
|
end
|
83
136
|
end
|
137
|
+
|
138
|
+
::Jekyll::Hooks.register(:site, :post_write) do
|
139
|
+
::Jekyll::Minibundle::AssetFileRegistry.clear_unused
|
140
|
+
end
|
@@ -19,6 +19,13 @@ module Jekyll::Minibundle
|
|
19
19
|
@minifier_cmd = config.fetch('minifier_cmd')
|
20
20
|
@stamped_at = nil
|
21
21
|
@is_modified = false
|
22
|
+
@_asset_bundle = nil
|
23
|
+
end
|
24
|
+
|
25
|
+
def cleanup
|
26
|
+
return unless @_asset_bundle
|
27
|
+
@_asset_bundle.close
|
28
|
+
@_asset_bundle = nil
|
22
29
|
end
|
23
30
|
|
24
31
|
def destination_path_for_markup
|
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'jekyll/minibundle/hashes'
|
2
|
-
require 'jekyll/minibundle/compatibility'
|
3
2
|
require 'jekyll/minibundle/environment'
|
4
3
|
require 'jekyll/minibundle/asset_file_registry'
|
5
4
|
require 'jekyll/minibundle/asset_tag_markup'
|
@@ -14,7 +13,7 @@ module Jekyll::Minibundle
|
|
14
13
|
|
15
14
|
def render(context)
|
16
15
|
site = context.registers.fetch(:site)
|
17
|
-
bundle_config = get_current_bundle_config(
|
16
|
+
bundle_config = get_current_bundle_config(::SafeYAML.load(super), site)
|
18
17
|
baseurl = bundle_config.fetch('baseurl')
|
19
18
|
attributes = bundle_config.fetch('attributes')
|
20
19
|
|
data/lib/jekyll/minibundle.rb
CHANGED
@@ -2,7 +2,7 @@ require 'support/test_case'
|
|
2
2
|
require 'support/fixture_config'
|
3
3
|
|
4
4
|
module Jekyll::Minibundle::Test
|
5
|
-
class
|
5
|
+
class MinibundleDevelopmentModeTest < TestCase
|
6
6
|
include FixtureConfig
|
7
7
|
|
8
8
|
CSS_ASSET_DESTINATION_PATHS = %w{reset common}.map { |f| File.join(CSS_BUNDLE_DESTINATION_PATH, "#{f}.css") }
|
@@ -136,25 +136,53 @@ module Jekyll::Minibundle::Test
|
|
136
136
|
assert File.exist?(destination_path(JS_BUNDLE_DESTINATION_PATH, 'dependency.js'))
|
137
137
|
assert File.exist?(destination_path(JS_BUNDLE_DESTINATION_PATH, 'app.js'))
|
138
138
|
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
destination_path: assets/site
|
143
|
-
END
|
139
|
+
ensure_file_mtime_changes do
|
140
|
+
change_destination_path_in_minibundle_block('assets/site', 'assets/site2')
|
141
|
+
end
|
144
142
|
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
143
|
+
generate_site(:development, clear_cache: false)
|
144
|
+
|
145
|
+
refute File.exist?(destination_path(JS_BUNDLE_DESTINATION_PATH, 'dependency.js'))
|
146
|
+
refute File.exist?(destination_path(JS_BUNDLE_DESTINATION_PATH, 'app.js'))
|
147
|
+
|
148
|
+
assert_equal ['assets/site2/dependency.js', 'assets/site2/app.js'], find_js_paths_from_index
|
149
|
+
assert File.exist?(destination_path('assets/site2/dependency.js'))
|
150
|
+
assert File.exist?(destination_path('assets/site2/app.js'))
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
def test_changing_asset_destination_path_to_new_value_and_back_to_original_rewrites_destination
|
155
|
+
with_site_dir do
|
156
|
+
generate_site(:development)
|
157
|
+
|
158
|
+
assert File.exist?(destination_path(JS_BUNDLE_DESTINATION_PATH, 'dependency.js'))
|
159
|
+
assert File.exist?(destination_path(JS_BUNDLE_DESTINATION_PATH, 'app.js'))
|
150
160
|
|
151
|
-
|
161
|
+
ensure_file_mtime_changes do
|
162
|
+
change_destination_path_in_minibundle_block('assets/site', 'assets/site2')
|
163
|
+
end
|
152
164
|
|
153
165
|
generate_site(:development, clear_cache: false)
|
154
166
|
|
167
|
+
refute File.exist?(destination_path(JS_BUNDLE_DESTINATION_PATH, 'dependency.js'))
|
168
|
+
refute File.exist?(destination_path(JS_BUNDLE_DESTINATION_PATH, 'app.js'))
|
169
|
+
|
155
170
|
assert_equal ['assets/site2/dependency.js', 'assets/site2/app.js'], find_js_paths_from_index
|
156
171
|
assert File.exist?(destination_path('assets/site2/dependency.js'))
|
157
172
|
assert File.exist?(destination_path('assets/site2/app.js'))
|
173
|
+
|
174
|
+
ensure_file_mtime_changes do
|
175
|
+
change_destination_path_in_minibundle_block('assets/site2', 'assets/site')
|
176
|
+
end
|
177
|
+
|
178
|
+
generate_site(:development, clear_cache: false)
|
179
|
+
|
180
|
+
refute File.exist?(destination_path('assets/site2/dependency.js'))
|
181
|
+
refute File.exist?(destination_path('assets/site2/app.js'))
|
182
|
+
|
183
|
+
assert_equal ['assets/site/dependency.js', 'assets/site/app.js'], find_js_paths_from_index
|
184
|
+
assert File.exist?(destination_path(JS_BUNDLE_DESTINATION_PATH, 'dependency.js'))
|
185
|
+
assert File.exist?(destination_path(JS_BUNDLE_DESTINATION_PATH, 'app.js'))
|
158
186
|
end
|
159
187
|
end
|
160
188
|
|
@@ -320,5 +348,21 @@ module Jekyll::Minibundle::Test
|
|
320
348
|
assert File.exist?(actual)
|
321
349
|
assert_equal File.read(expected), File.read(actual)
|
322
350
|
end
|
351
|
+
|
352
|
+
def change_destination_path_in_minibundle_block(from, to)
|
353
|
+
match_snippet = <<-END
|
354
|
+
{% minibundle js %}
|
355
|
+
source_dir: _assets/scripts
|
356
|
+
destination_path: #{from}
|
357
|
+
END
|
358
|
+
|
359
|
+
replacement_snippet = <<-END
|
360
|
+
{% minibundle js %}
|
361
|
+
source_dir: _assets/scripts
|
362
|
+
destination_path: #{to}
|
363
|
+
END
|
364
|
+
|
365
|
+
find_and_gsub_in_file(source_path('_layouts/default.html'), match_snippet, replacement_snippet)
|
366
|
+
end
|
323
367
|
end
|
324
368
|
end
|
@@ -2,7 +2,7 @@ require 'support/test_case'
|
|
2
2
|
require 'support/fixture_config'
|
3
3
|
|
4
4
|
module Jekyll::Minibundle::Test
|
5
|
-
class
|
5
|
+
class MinibundleProductionModeTest < TestCase
|
6
6
|
include FixtureConfig
|
7
7
|
|
8
8
|
def test_css_asset_bundle_has_stamp
|
@@ -174,36 +174,106 @@ module Jekyll::Minibundle::Test
|
|
174
174
|
end
|
175
175
|
end
|
176
176
|
|
177
|
-
def
|
177
|
+
def test_changing_asset_source_list_removes_old_temporary_bundle_file
|
178
178
|
with_site_dir do
|
179
179
|
generate_site(:production)
|
180
180
|
|
181
181
|
assert File.exist?(destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH))
|
182
182
|
|
183
183
|
match_snippet = <<-END
|
184
|
-
|
185
|
-
|
186
|
-
|
184
|
+
assets:
|
185
|
+
- dependency
|
186
|
+
- app
|
187
187
|
END
|
188
188
|
|
189
189
|
replacement_snippet = <<-END
|
190
|
-
|
191
|
-
|
192
|
-
destination_path: assets/site2
|
190
|
+
assets:
|
191
|
+
- dependency
|
193
192
|
END
|
194
193
|
|
194
|
+
org_tempfiles = find_tempfiles
|
195
|
+
|
195
196
|
ensure_file_mtime_changes do
|
196
197
|
find_and_gsub_in_file(source_path('_layouts/default.html'), match_snippet, replacement_snippet)
|
197
198
|
end
|
198
199
|
|
199
200
|
generate_site(:production, clear_cache: false)
|
200
201
|
|
202
|
+
refute File.exist?(destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH))
|
203
|
+
assert File.exist?(destination_path('assets/site-71042d0b7c86c04e015fde694dd9f409.js'))
|
204
|
+
assert_equal 1, (org_tempfiles - find_tempfiles).size
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
def test_changing_asset_destination_path_rewrites_destination
|
209
|
+
with_site_dir do
|
210
|
+
generate_site(:production)
|
211
|
+
|
212
|
+
assert File.exist?(destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH))
|
213
|
+
|
214
|
+
ensure_file_mtime_changes do
|
215
|
+
change_destination_path_in_minibundle_block('assets/site', 'assets/site2')
|
216
|
+
end
|
217
|
+
|
218
|
+
generate_site(:production, clear_cache: false)
|
219
|
+
|
220
|
+
refute File.exist?(destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH))
|
221
|
+
|
222
|
+
new_destination = "assets/site2-#{JS_BUNDLE_FINGERPRINT}.js"
|
223
|
+
|
224
|
+
assert_equal new_destination, find_js_path_from_index
|
225
|
+
assert File.exist?(destination_path(new_destination))
|
226
|
+
end
|
227
|
+
end
|
228
|
+
|
229
|
+
def test_changing_asset_destination_path_removes_old_temporary_bundle_file
|
230
|
+
with_site_dir do
|
231
|
+
generate_site(:production)
|
232
|
+
|
233
|
+
assert File.exist?(destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH))
|
234
|
+
|
235
|
+
org_tempfiles = find_tempfiles
|
236
|
+
|
237
|
+
ensure_file_mtime_changes do
|
238
|
+
change_destination_path_in_minibundle_block('assets/site', 'assets/site2')
|
239
|
+
end
|
240
|
+
|
241
|
+
generate_site(:production, clear_cache: false)
|
242
|
+
|
243
|
+
refute File.exist?(destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH))
|
244
|
+
assert File.exist?(destination_path("assets/site2-#{JS_BUNDLE_FINGERPRINT}.js"))
|
245
|
+
assert_equal 1, (org_tempfiles - find_tempfiles).size
|
246
|
+
end
|
247
|
+
end
|
248
|
+
|
249
|
+
def test_changing_asset_destination_path_to_new_value_and_back_to_original_rewrites_destination
|
250
|
+
with_site_dir do
|
251
|
+
generate_site(:production)
|
252
|
+
|
253
|
+
assert File.exist?(destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH))
|
254
|
+
|
255
|
+
ensure_file_mtime_changes do
|
256
|
+
change_destination_path_in_minibundle_block('assets/site', 'assets/site2')
|
257
|
+
end
|
258
|
+
|
259
|
+
generate_site(:production, clear_cache: false)
|
260
|
+
|
201
261
|
refute File.exist?(destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH))
|
202
262
|
|
203
263
|
new_destination = "assets/site2-#{JS_BUNDLE_FINGERPRINT}.js"
|
204
264
|
|
205
265
|
assert_equal new_destination, find_js_path_from_index
|
206
266
|
assert File.exist?(destination_path(new_destination))
|
267
|
+
|
268
|
+
ensure_file_mtime_changes do
|
269
|
+
change_destination_path_in_minibundle_block('assets/site2', 'assets/site')
|
270
|
+
end
|
271
|
+
|
272
|
+
generate_site(:production, clear_cache: false)
|
273
|
+
|
274
|
+
refute File.exist?(destination_path(new_destination))
|
275
|
+
assert_equal JS_BUNDLE_DESTINATION_FINGERPRINT_PATH, find_js_path_from_index
|
276
|
+
assert File.exist?(destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH))
|
207
277
|
end
|
208
278
|
end
|
209
279
|
|
@@ -472,5 +542,25 @@ title: Test
|
|
472
542
|
.join('')
|
473
543
|
.size
|
474
544
|
end
|
545
|
+
|
546
|
+
def change_destination_path_in_minibundle_block(from, to)
|
547
|
+
match_snippet = <<-END
|
548
|
+
{% minibundle js %}
|
549
|
+
source_dir: _assets/scripts
|
550
|
+
destination_path: #{from}
|
551
|
+
END
|
552
|
+
|
553
|
+
replacement_snippet = <<-END
|
554
|
+
{% minibundle js %}
|
555
|
+
source_dir: _assets/scripts
|
556
|
+
destination_path: #{to}
|
557
|
+
END
|
558
|
+
|
559
|
+
find_and_gsub_in_file(source_path('_layouts/default.html'), match_snippet, replacement_snippet)
|
560
|
+
end
|
561
|
+
|
562
|
+
def find_tempfiles
|
563
|
+
Dir[File.join(Dir.tmpdir, AssetBundle::TEMPFILE_PREFIX + '*')]
|
564
|
+
end
|
475
565
|
end
|
476
566
|
end
|
@@ -2,7 +2,7 @@ require 'support/test_case'
|
|
2
2
|
require 'support/fixture_config'
|
3
3
|
|
4
4
|
module Jekyll::Minibundle::Test
|
5
|
-
class
|
5
|
+
class MinistampDevelopmentModeTest < TestCase
|
6
6
|
include FixtureConfig
|
7
7
|
|
8
8
|
def test_asset_destination_path_has_no_stamp
|
@@ -97,6 +97,46 @@ module Jekyll::Minibundle::Test
|
|
97
97
|
end
|
98
98
|
end
|
99
99
|
|
100
|
+
def test_changing_asset_destination_path_to_new_value_and_back_to_original_rewrites_destination
|
101
|
+
with_site_dir do
|
102
|
+
generate_site(:development)
|
103
|
+
|
104
|
+
assert File.exist?(destination_path(STAMP_DESTINATION_PATH))
|
105
|
+
|
106
|
+
ensure_file_mtime_changes do
|
107
|
+
find_and_gsub_in_file(
|
108
|
+
source_path('_layouts/default.html'),
|
109
|
+
'{% ministamp _tmp/site.css assets/screen.css',
|
110
|
+
'{% ministamp _tmp/site.css assets/screen2.css'
|
111
|
+
)
|
112
|
+
end
|
113
|
+
|
114
|
+
generate_site(:development, clear_cache: false)
|
115
|
+
|
116
|
+
refute File.exist?(destination_path(STAMP_DESTINATION_PATH))
|
117
|
+
|
118
|
+
new_destination = 'assets/screen2.css'
|
119
|
+
|
120
|
+
assert_equal new_destination, find_css_path_from_index
|
121
|
+
assert File.exist?(destination_path(new_destination))
|
122
|
+
|
123
|
+
ensure_file_mtime_changes do
|
124
|
+
find_and_gsub_in_file(
|
125
|
+
source_path('_layouts/default.html'),
|
126
|
+
'{% ministamp _tmp/site.css assets/screen2.css',
|
127
|
+
'{% ministamp _tmp/site.css assets/screen.css'
|
128
|
+
)
|
129
|
+
end
|
130
|
+
|
131
|
+
generate_site(:development, clear_cache: false)
|
132
|
+
|
133
|
+
refute File.exist?(destination_path(new_destination))
|
134
|
+
|
135
|
+
assert_equal STAMP_DESTINATION_PATH, find_css_path_from_index
|
136
|
+
assert File.exist?(destination_path(STAMP_DESTINATION_PATH))
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
100
140
|
def test_supports_relative_and_absolute_destination_paths
|
101
141
|
with_site_dir do
|
102
142
|
generate_site(:development)
|
@@ -2,7 +2,7 @@ require 'support/test_case'
|
|
2
2
|
require 'support/fixture_config'
|
3
3
|
|
4
4
|
module Jekyll::Minibundle::Test
|
5
|
-
class
|
5
|
+
class MinistampProductionModeTest < TestCase
|
6
6
|
include FixtureConfig
|
7
7
|
|
8
8
|
def test_asset_destination_path_has_stamp
|
@@ -101,6 +101,46 @@ module Jekyll::Minibundle::Test
|
|
101
101
|
end
|
102
102
|
end
|
103
103
|
|
104
|
+
def test_changing_asset_destination_path_to_new_value_and_back_to_original_rewrites_destination
|
105
|
+
with_site_dir do
|
106
|
+
generate_site(:production)
|
107
|
+
|
108
|
+
assert File.exist?(destination_path(STAMP_DESTINATION_FINGERPRINT_PATH))
|
109
|
+
|
110
|
+
ensure_file_mtime_changes do
|
111
|
+
find_and_gsub_in_file(
|
112
|
+
source_path('_layouts/default.html'),
|
113
|
+
'{% ministamp _tmp/site.css assets/screen.css',
|
114
|
+
'{% ministamp _tmp/site.css assets/screen2.css'
|
115
|
+
)
|
116
|
+
end
|
117
|
+
|
118
|
+
generate_site(:production, clear_cache: false)
|
119
|
+
|
120
|
+
refute File.exist?(destination_path(STAMP_DESTINATION_FINGERPRINT_PATH))
|
121
|
+
|
122
|
+
new_destination = "assets/screen2-#{STAMP_FINGERPRINT}.css"
|
123
|
+
|
124
|
+
assert_equal new_destination, find_css_path_from_index
|
125
|
+
assert File.exist?(destination_path(new_destination))
|
126
|
+
|
127
|
+
ensure_file_mtime_changes do
|
128
|
+
find_and_gsub_in_file(
|
129
|
+
source_path('_layouts/default.html'),
|
130
|
+
'{% ministamp _tmp/site.css assets/screen2.css',
|
131
|
+
'{% ministamp _tmp/site.css assets/screen.css'
|
132
|
+
)
|
133
|
+
end
|
134
|
+
|
135
|
+
generate_site(:production, clear_cache: false)
|
136
|
+
|
137
|
+
refute File.exist?(destination_path(new_destination))
|
138
|
+
|
139
|
+
assert_equal STAMP_DESTINATION_FINGERPRINT_PATH, find_css_path_from_index
|
140
|
+
assert File.exist?(destination_path(STAMP_DESTINATION_FINGERPRINT_PATH))
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
104
144
|
def test_supports_relative_and_absolute_destination_paths
|
105
145
|
with_site_dir do
|
106
146
|
generate_site(:production)
|
data/test/support/test_case.rb
CHANGED
@@ -146,7 +146,7 @@ module Jekyll::Minibundle::Test
|
|
146
146
|
end
|
147
147
|
|
148
148
|
def _generate_site(test_options)
|
149
|
-
AssetFileRegistry.
|
149
|
+
AssetFileRegistry.clear_all if test_options.fetch(:clear_cache, true)
|
150
150
|
site = new_real_site
|
151
151
|
capture_io { site.process }
|
152
152
|
end
|
@@ -4,11 +4,11 @@ require 'jekyll/minibundle/asset_file_registry'
|
|
4
4
|
module Jekyll::Minibundle::Test
|
5
5
|
class AssetFileRegistryTest < TestCase
|
6
6
|
def setup
|
7
|
-
AssetFileRegistry.
|
7
|
+
AssetFileRegistry.clear_all
|
8
8
|
@site = new_site
|
9
9
|
end
|
10
10
|
|
11
|
-
def
|
11
|
+
def test_register_returns_same_bundle_file_for_same_bundle_config
|
12
12
|
first = AssetFileRegistry.register_bundle_file(@site, bundle_config)
|
13
13
|
second = AssetFileRegistry.register_bundle_file(@site, bundle_config)
|
14
14
|
assert_same first, second
|
@@ -16,7 +16,7 @@ module Jekyll::Minibundle::Test
|
|
16
16
|
assert_contains_only @site.static_files, [first]
|
17
17
|
end
|
18
18
|
|
19
|
-
def
|
19
|
+
def test_register_returns_same_development_file_collection_for_same_bundle_config
|
20
20
|
first = AssetFileRegistry.register_development_file_collection(@site, bundle_config)
|
21
21
|
second = AssetFileRegistry.register_development_file_collection(@site, bundle_config)
|
22
22
|
assert_same first, second
|
@@ -60,12 +60,18 @@ module Jekyll::Minibundle::Test
|
|
60
60
|
{description: 'assets', config_diff: {'assets' => %w{b1 b2}}},
|
61
61
|
{description: 'source_directory', config_diff: {'source_dir' => '_assets/src2'}}
|
62
62
|
].each do |spec|
|
63
|
-
define_method :"
|
64
|
-
|
65
|
-
|
66
|
-
|
63
|
+
define_method :"test_raise_exception_if_registering_bundle_file_with_same_destination_path_but_with_different_#{spec.fetch(:description)}" do
|
64
|
+
first_config = bundle_config
|
65
|
+
first_file = AssetFileRegistry.register_bundle_file(@site, first_config)
|
66
|
+
second_config = bundle_config.merge(spec[:config_diff])
|
67
|
+
err = assert_raises(RuntimeError) do
|
68
|
+
AssetFileRegistry.register_bundle_file(@site, second_config)
|
69
|
+
end
|
70
|
+
assert_equal <<-END, err.to_s
|
71
|
+
Two or more minibundle blocks with the same destination path 'assets/dest.css', but having different asset configuration: #{second_config.inspect} vs. #{first_config.inspect}
|
72
|
+
END
|
67
73
|
assert_equal 1, asset_file_registry_size
|
68
|
-
assert_contains_only @site.static_files, [
|
74
|
+
assert_contains_only @site.static_files, [first_file]
|
69
75
|
end
|
70
76
|
end
|
71
77
|
|
@@ -73,12 +79,18 @@ module Jekyll::Minibundle::Test
|
|
73
79
|
{description: 'assets', config_diff: {'assets' => %w{b1 b2}}},
|
74
80
|
{description: 'source_directory', config_diff: {'source_dir' => '_assets/src2'}}
|
75
81
|
].each do |spec|
|
76
|
-
define_method :"
|
77
|
-
|
78
|
-
|
79
|
-
|
82
|
+
define_method :"test_raise_exception_if_registering_development_file_collection_with_same_destination_path_but_with_different_#{spec.fetch(:description)}" do
|
83
|
+
first_config = bundle_config
|
84
|
+
first_file = AssetFileRegistry.register_development_file_collection(@site, first_config)
|
85
|
+
second_config = bundle_config.merge(spec[:config_diff])
|
86
|
+
err = assert_raises(RuntimeError) do
|
87
|
+
AssetFileRegistry.register_development_file_collection(@site, second_config)
|
88
|
+
end
|
89
|
+
assert_equal <<-END, err.to_s
|
90
|
+
Two or more minibundle blocks with the same destination path 'assets/dest.css', but having different asset configuration: #{second_config.inspect} vs. #{first_config.inspect}
|
91
|
+
END
|
80
92
|
assert_equal 1, asset_file_registry_size
|
81
|
-
assert_contains_only @site.static_files,
|
93
|
+
assert_contains_only @site.static_files, first_file.files
|
82
94
|
end
|
83
95
|
end
|
84
96
|
|
@@ -102,12 +114,16 @@ module Jekyll::Minibundle::Test
|
|
102
114
|
assert_contains_only @site.static_files, [first, second]
|
103
115
|
end
|
104
116
|
|
105
|
-
define_method :"
|
117
|
+
define_method :"test_raise_exception_if_registering_#{spec.fetch(:description)}s_with_different_source_and_same_destination_paths" do
|
106
118
|
first = AssetFileRegistry.send(spec.fetch(:method), @site, '_assets/src1.css', 'assets/dest1.css')
|
107
|
-
|
108
|
-
|
119
|
+
err = assert_raises(RuntimeError) do
|
120
|
+
AssetFileRegistry.send(spec.fetch(:method), @site, '_assets/src2.css', 'assets/dest1.css')
|
121
|
+
end
|
122
|
+
assert_equal <<-END, err.to_s
|
123
|
+
Two or more ministamp tags with the same destination path 'assets/dest1.css', but different asset source paths: '_assets/src2.css' vs. '_assets/src1.css'
|
124
|
+
END
|
109
125
|
assert_equal 1, asset_file_registry_size
|
110
|
-
assert_contains_only @site.static_files, [
|
126
|
+
assert_contains_only @site.static_files, [first]
|
111
127
|
end
|
112
128
|
end
|
113
129
|
|
@@ -116,7 +132,7 @@ module Jekyll::Minibundle::Test
|
|
116
132
|
err = assert_raises(RuntimeError) do
|
117
133
|
AssetFileRegistry.register_stamp_file(@site, '_assets/src1.css', 'assets/dest.css')
|
118
134
|
end
|
119
|
-
assert_equal
|
135
|
+
assert_equal "ministamp tag has the same destination path as a minibundle block: 'assets/dest.css'", err.to_s
|
120
136
|
assert_equal 1, asset_file_registry_size
|
121
137
|
assert_contains_only @site.static_files, [file]
|
122
138
|
end
|
@@ -126,11 +142,43 @@ module Jekyll::Minibundle::Test
|
|
126
142
|
err = assert_raises(RuntimeError) do
|
127
143
|
AssetFileRegistry.register_bundle_file(@site, bundle_config.merge('type' => :css, 'destination_path' => 'assets/dest'))
|
128
144
|
end
|
129
|
-
assert_equal
|
145
|
+
assert_equal "minibundle block has the same destination path as a ministamp tag: 'assets/dest.css'", err.to_s
|
130
146
|
assert_equal 1, asset_file_registry_size
|
131
147
|
assert_contains_only @site.static_files, [file]
|
132
148
|
end
|
133
149
|
|
150
|
+
[
|
151
|
+
{description: 'bundle_file', method: :register_bundle_file},
|
152
|
+
{description: 'development_file_collection', method: :register_development_file_collection}
|
153
|
+
].each do |spec|
|
154
|
+
define_method :"test_remove_unused_#{spec.fetch(:description)}" do
|
155
|
+
AssetFileRegistry.send(spec.fetch(:method), @site, bundle_config)
|
156
|
+
AssetFileRegistry.clear_unused
|
157
|
+
|
158
|
+
assert_equal 1, asset_file_registry_size
|
159
|
+
|
160
|
+
AssetFileRegistry.clear_unused
|
161
|
+
|
162
|
+
assert_equal 0, asset_file_registry_size
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
[
|
167
|
+
{description: 'stamp_file', method: :register_stamp_file},
|
168
|
+
{description: 'development_file', method: :register_development_file}
|
169
|
+
].each do |spec|
|
170
|
+
define_method :"test_remove_unused_#{spec.fetch(:description)}" do
|
171
|
+
AssetFileRegistry.send(spec.fetch(:method), @site, '_assets/src.css', 'assets/dest.css')
|
172
|
+
AssetFileRegistry.clear_unused
|
173
|
+
|
174
|
+
assert_equal 1, asset_file_registry_size
|
175
|
+
|
176
|
+
AssetFileRegistry.clear_unused
|
177
|
+
|
178
|
+
assert_equal 0, asset_file_registry_size
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
134
182
|
private
|
135
183
|
|
136
184
|
def bundle_config
|
@@ -41,7 +41,7 @@ module Jekyll::Minibundle::Test
|
|
41
41
|
}
|
42
42
|
].each do |spec|
|
43
43
|
define_method :"test_normalizing_baseurl_with_#{spec.fetch(:description)}" do
|
44
|
-
AssetFileRegistry.
|
44
|
+
AssetFileRegistry.clear_all
|
45
45
|
|
46
46
|
template = Liquid::Template.parse(<<-END)
|
47
47
|
{% minibundle css %}
|
@@ -21,7 +21,7 @@ module Jekyll::Minibundle::Test
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def test_ignore_rest_arguments
|
24
|
-
AssetFileRegistry.
|
24
|
+
AssetFileRegistry.clear_all
|
25
25
|
output = Liquid::Template
|
26
26
|
.parse("{% ministamp #{STAMP_SOURCE_PATH} #{STAMP_DESTINATION_PATH} rest %}")
|
27
27
|
.render({}, registers: {site: new_fake_site(site_fixture_path)})
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-minibundle
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tuomas Kareinen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-03-
|
11
|
+
date: 2016-03-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 3.0.0
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 3.0.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: minitest
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -104,12 +104,13 @@ files:
|
|
104
104
|
- lib/jekyll/minibundle/asset_stamp.rb
|
105
105
|
- lib/jekyll/minibundle/asset_tag_markup.rb
|
106
106
|
- lib/jekyll/minibundle/bundle_file.rb
|
107
|
-
- lib/jekyll/minibundle/compatibility.rb
|
108
107
|
- lib/jekyll/minibundle/development_file.rb
|
109
108
|
- lib/jekyll/minibundle/development_file_collection.rb
|
110
109
|
- lib/jekyll/minibundle/environment.rb
|
110
|
+
- lib/jekyll/minibundle/exceptions.rb
|
111
111
|
- lib/jekyll/minibundle/files.rb
|
112
112
|
- lib/jekyll/minibundle/hashes.rb
|
113
|
+
- lib/jekyll/minibundle/log.rb
|
113
114
|
- lib/jekyll/minibundle/mini_bundle_block.rb
|
114
115
|
- lib/jekyll/minibundle/mini_stamp_tag.rb
|
115
116
|
- lib/jekyll/minibundle/stamp_file.rb
|
@@ -126,7 +127,6 @@ files:
|
|
126
127
|
- test/fixture/site/about.html
|
127
128
|
- test/fixture/site/assets/site.css
|
128
129
|
- test/fixture/site/index.html
|
129
|
-
- test/integration/known_caveats_test.rb
|
130
130
|
- test/integration/minibundle_development_mode_test.rb
|
131
131
|
- test/integration/minibundle_production_mode_test.rb
|
132
132
|
- test/integration/ministamp_development_mode_test.rb
|
@@ -192,7 +192,6 @@ test_files:
|
|
192
192
|
- test/fixture/site/about.html
|
193
193
|
- test/fixture/site/assets/site.css
|
194
194
|
- test/fixture/site/index.html
|
195
|
-
- test/integration/known_caveats_test.rb
|
196
195
|
- test/integration/minibundle_development_mode_test.rb
|
197
196
|
- test/integration/minibundle_production_mode_test.rb
|
198
197
|
- test/integration/ministamp_development_mode_test.rb
|
@@ -1,37 +0,0 @@
|
|
1
|
-
module Jekyll::Minibundle
|
2
|
-
module Compatibility
|
3
|
-
LOG_TOPIC = 'Minibundle:'.freeze
|
4
|
-
|
5
|
-
class << self
|
6
|
-
# SafeYAML.load is introduced in Jekyll 2.0.0
|
7
|
-
if defined?(::SafeYAML) && ::SafeYAML.respond_to?(:load)
|
8
|
-
def load_yaml(*args)
|
9
|
-
::SafeYAML.load(*args)
|
10
|
-
end
|
11
|
-
else
|
12
|
-
def load_yaml(*args)
|
13
|
-
::YAML.load(*args)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
# Jekyll.logger is introduced in Jekyll 1.0.3
|
18
|
-
if ::Jekyll.respond_to?(:logger)
|
19
|
-
def log_error(msg)
|
20
|
-
::Jekyll.logger.error(LOG_TOPIC, msg)
|
21
|
-
end
|
22
|
-
|
23
|
-
def log_info(msg)
|
24
|
-
::Jekyll.logger.info(LOG_TOPIC, msg)
|
25
|
-
end
|
26
|
-
else
|
27
|
-
def log_error(msg)
|
28
|
-
$stderr.puts(msg)
|
29
|
-
end
|
30
|
-
|
31
|
-
def log_info(msg)
|
32
|
-
$stdout.puts(msg)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
@@ -1,89 +0,0 @@
|
|
1
|
-
require 'support/test_case'
|
2
|
-
require 'support/fixture_config'
|
3
|
-
|
4
|
-
module Jekyll::Minibundle::Test
|
5
|
-
# Known software caveats that won't be fixed in the current design
|
6
|
-
# of the software.
|
7
|
-
class KnownCaveatsTest < TestCase
|
8
|
-
include FixtureConfig
|
9
|
-
|
10
|
-
# In Jekyll's watch (auto-regeneration) mode, changing asset
|
11
|
-
# destination path to a new value triggers the plugin to rebundle
|
12
|
-
# the assets and writing the bundle file to site output
|
13
|
-
# directory. After that, changing the destination path back to the
|
14
|
-
# original value should cause the plugin to write the original
|
15
|
-
# bundle file to site output directory again. This should happen
|
16
|
-
# without rebundling the assets, because the plugin stores the
|
17
|
-
# original bundle in a temporary file.
|
18
|
-
#
|
19
|
-
# The plugin cannot rewrite the original bundle file to site
|
20
|
-
# output directory, because it does not get a trigger for doing
|
21
|
-
# so. The plugin has a non-expiring cumulative cache for
|
22
|
-
# assets. This allows the plugin to avoid rebundling assets in
|
23
|
-
# site regeneration if the assets themselves are unchanged. This
|
24
|
-
# same mechanism is the cause for this caveat.
|
25
|
-
#
|
26
|
-
# As a workaround, touching or changing one of the assets in the
|
27
|
-
# bundle triggers rebundling and rewriting the bundle file to site
|
28
|
-
# output directory.
|
29
|
-
#
|
30
|
-
# For now, we have decided that the caveat is a minor drawback
|
31
|
-
# compared to the benefit of avoiding unnecessary rebundling in
|
32
|
-
# site regeneration.
|
33
|
-
def test_changing_asset_destination_path_to_new_value_and_back_to_original_does_not_rewrite_destination
|
34
|
-
with_site_dir do
|
35
|
-
generate_site(:production)
|
36
|
-
|
37
|
-
assert File.exist?(destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH))
|
38
|
-
|
39
|
-
ensure_file_mtime_changes do
|
40
|
-
change_destination_path('assets/site', 'assets/site2')
|
41
|
-
end
|
42
|
-
|
43
|
-
generate_site(:production, clear_cache: false)
|
44
|
-
|
45
|
-
refute File.exist?(destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH))
|
46
|
-
|
47
|
-
new_destination = "assets/site2-#{JS_BUNDLE_FINGERPRINT}.js"
|
48
|
-
|
49
|
-
assert_equal new_destination, find_js_path_from_index
|
50
|
-
assert File.exist?(destination_path(new_destination))
|
51
|
-
|
52
|
-
ensure_file_mtime_changes do
|
53
|
-
change_destination_path('assets/site2', 'assets/site')
|
54
|
-
|
55
|
-
# CAVEAT: This should not be needed.
|
56
|
-
FileUtils.touch(source_path('_assets/scripts/dependency.js'))
|
57
|
-
end
|
58
|
-
|
59
|
-
generate_site(:production, clear_cache: false)
|
60
|
-
|
61
|
-
assert_equal JS_BUNDLE_DESTINATION_FINGERPRINT_PATH, find_js_path_from_index
|
62
|
-
refute File.exist?(destination_path(new_destination))
|
63
|
-
assert File.exist?(destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH))
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
private
|
68
|
-
|
69
|
-
def change_destination_path(from, to)
|
70
|
-
match_snippet = <<-END
|
71
|
-
{% minibundle js %}
|
72
|
-
source_dir: _assets/scripts
|
73
|
-
destination_path: #{from}
|
74
|
-
END
|
75
|
-
|
76
|
-
replacement_snippet = <<-END
|
77
|
-
{% minibundle js %}
|
78
|
-
source_dir: _assets/scripts
|
79
|
-
destination_path: #{to}
|
80
|
-
END
|
81
|
-
|
82
|
-
find_and_gsub_in_file(source_path('_layouts/default.html'), match_snippet, replacement_snippet)
|
83
|
-
end
|
84
|
-
|
85
|
-
def find_js_path_from_index
|
86
|
-
find_html_element(File.read(destination_path('index.html')), 'body script').first['src']
|
87
|
-
end
|
88
|
-
end
|
89
|
-
end
|