Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates for 2.0.3: Fix caching of manifest #14

Merged
merged 1 commit into from
May 30, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ Contributors: please follow the recommendations outlined at [keepachangelog.com]
## [Unreleased]
*Please add entries here for your pull requests.*

## [2.0.3] - 2017-05-29
### Fixed
* Fixed caching of manifest.json for tests. [#14](https://github.com/shakacode/webpacker_lite/pull/14) by [justin808](https://github.com/justin808).

## [2.0.2] - 2017-05-26
### Fixed
* Fixed rake assets:clobber. [#11](https://github.com/shakacode/webpacker_lite/pull/11) by [dpuscher](https://github.com/dpuscher).
Expand All @@ -30,7 +34,8 @@ All in [#9](https://github.com/shakacode/webpacker_lite/pull/9) by [justin808](h
## [1.0.0] - 2017-05-03
Initial release

[Unreleased]: https://github.com/shakacode/webpacker_lite/compare/2.0.2...master
[Unreleased]: https://github.com/shakacode/webpacker_lite/compare/2.0.3...master
[2.0.3]: https://github.com/shakacode/react_on_rails/compare/2.0.2...2.0.3
[2.0.2]: https://github.com/shakacode/react_on_rails/compare/2.0.1...2.0.2
[2.0.1]: https://github.com/shakacode/react_on_rails/compare/2.0.0...2.0.1
[2.0.0]: https://github.com/shakacode/react_on_rails/compare/1.0.0...2.0.0
Expand Down
8 changes: 6 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ or to autofix:
bundle exec rubocop -a
```

### Debugging

Enable pry by setting an ENV value for `USE_PRY`. When you use pry, you may get a useless warning about circular references.

### All ci

```sh
Expand All @@ -69,12 +73,12 @@ What do project maintainers do? What sort of work is involved? [sstephenson](htt

Using [gem-release](https://github.com/svenfuchs/gem-release).

If the version to bump is `2.0.1`
If the version to bump is `2.0.3`

```
git checkout master
git pull --rebase
gem bump --version 2.0.1
gem bump --version 2.0.3
bundle
git commit -m "Update Gemfile.lock"
gem release --tag --push
Expand Down
9 changes: 9 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,13 @@ gem "rubocop", ">= 0.47", require: false

group :test do
gem "minitest", "~> 5.10", "!= 5.10.2"

if ENV["USE_PRY"]
gem "pry"
gem "pry-byebug"
gem "pry-doc"
gem "pry-rails"
gem "pry-rescue"
gem "pry-stack_explorer"
end
end
104 changes: 69 additions & 35 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9,51 +9,57 @@ PATH
GEM
remote: https://rubygems.org/
specs:
actioncable (5.1.0)
actionpack (= 5.1.0)
actioncable (5.1.1)
actionpack (= 5.1.1)
nio4r (~> 2.0)
websocket-driver (~> 0.6.1)
actionmailer (5.1.0)
actionpack (= 5.1.0)
actionview (= 5.1.0)
activejob (= 5.1.0)
actionmailer (5.1.1)
actionpack (= 5.1.1)
actionview (= 5.1.1)
activejob (= 5.1.1)
mail (~> 2.5, >= 2.5.4)
rails-dom-testing (~> 2.0)
actionpack (5.1.0)
actionview (= 5.1.0)
activesupport (= 5.1.0)
actionpack (5.1.1)
actionview (= 5.1.1)
activesupport (= 5.1.1)
rack (~> 2.0)
rack-test (~> 0.6.3)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.0.2)
actionview (5.1.0)
activesupport (= 5.1.0)
actionview (5.1.1)
activesupport (= 5.1.1)
builder (~> 3.1)
erubi (~> 1.4)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.0.3)
activejob (5.1.0)
activesupport (= 5.1.0)
activejob (5.1.1)
activesupport (= 5.1.1)
globalid (>= 0.3.6)
activemodel (5.1.0)
activesupport (= 5.1.0)
activerecord (5.1.0)
activemodel (= 5.1.0)
activesupport (= 5.1.0)
activemodel (5.1.1)
activesupport (= 5.1.1)
activerecord (5.1.1)
activemodel (= 5.1.1)
activesupport (= 5.1.1)
arel (~> 8.0)
activesupport (5.1.0)
activesupport (5.1.1)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (~> 0.7)
minitest (~> 5.1)
tzinfo (~> 1.1)
arel (8.0.0)
ast (2.3.0)
binding_of_caller (0.7.2)
debug_inspector (>= 0.0.1)
builder (3.2.3)
byebug (9.0.6)
coderay (1.1.1)
concurrent-ruby (1.0.5)
debug_inspector (0.0.3)
erubi (1.6.0)
globalid (0.4.0)
activesupport (>= 4.2.0)
i18n (0.8.1)
interception (0.5)
loofah (2.0.3)
nokogiri (>= 1.5.9)
mail (2.6.5)
Expand All @@ -65,48 +71,69 @@ GEM
mini_portile2 (2.1.0)
minitest (5.10.1)
multi_json (1.12.1)
nio4r (2.0.0)
nio4r (2.1.0)
nokogiri (1.7.2)
mini_portile2 (~> 2.1.0)
parallel (1.11.2)
parser (2.4.0.0)
ast (~> 2.2)
powerpack (0.1.1)
rack (2.0.2)
pry (0.10.4)
coderay (~> 1.1.0)
method_source (~> 0.8.1)
slop (~> 3.4)
pry-byebug (3.4.2)
byebug (~> 9.0)
pry (~> 0.10)
pry-doc (0.10.0)
pry (~> 0.9)
yard (~> 0.9)
pry-rails (0.3.6)
pry (>= 0.10.4)
pry-rescue (1.4.5)
interception (>= 0.5)
pry
pry-stack_explorer (0.4.9.2)
binding_of_caller (>= 0.7)
pry (>= 0.9.11)
rack (2.0.3)
rack-test (0.6.3)
rack (>= 1.0)
rails (5.1.0)
actioncable (= 5.1.0)
actionmailer (= 5.1.0)
actionpack (= 5.1.0)
actionview (= 5.1.0)
activejob (= 5.1.0)
activemodel (= 5.1.0)
activerecord (= 5.1.0)
activesupport (= 5.1.0)
rails (5.1.1)
actioncable (= 5.1.1)
actionmailer (= 5.1.1)
actionpack (= 5.1.1)
actionview (= 5.1.1)
activejob (= 5.1.1)
activemodel (= 5.1.1)
activerecord (= 5.1.1)
activesupport (= 5.1.1)
bundler (>= 1.3.0, < 2.0)
railties (= 5.1.0)
railties (= 5.1.1)
sprockets-rails (>= 2.0.0)
rails-dom-testing (2.0.3)
activesupport (>= 4.2.0)
nokogiri (>= 1.6)
rails-html-sanitizer (1.0.3)
loofah (~> 2.0)
railties (5.1.0)
actionpack (= 5.1.0)
activesupport (= 5.1.0)
railties (5.1.1)
actionpack (= 5.1.1)
activesupport (= 5.1.1)
method_source
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
rainbow (2.2.2)
rake
rake (12.0.0)
rubocop (0.48.1)
rubocop (0.49.1)
parallel (~> 1.10)
parser (>= 2.3.3.1, < 3.0)
powerpack (~> 0.1)
rainbow (>= 1.99.1, < 3.0)
ruby-progressbar (~> 1.7)
unicode-display_width (~> 1.0, >= 1.0.1)
ruby-progressbar (1.8.1)
slop (3.6.0)
sprockets (3.7.1)
concurrent-ruby (~> 1.0)
rack (> 1, < 3)
Expand All @@ -122,13 +149,20 @@ GEM
websocket-driver (0.6.5)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.2)
yard (0.9.9)

PLATFORMS
ruby

DEPENDENCIES
bundler (~> 1.12)
minitest (~> 5.10, != 5.10.2)
pry
pry-byebug
pry-doc
pry-rails
pry-rescue
pry-stack_explorer
rails
rake (>= 11.1)
rubocop (>= 0.47)
Expand Down
2 changes: 1 addition & 1 deletion lib/webpacker_lite/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def base_url
end

def configuration
load_instance if WebpackerLite::Env.development?
load_instance
raise WebpackerLite::FileLoader::FileLoaderError.new("WebpackerLite::Configuration.load_instance must be called first") unless instance
instance.data
end
Expand Down
4 changes: 0 additions & 4 deletions lib/webpacker_lite/env.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ def current
instance.data
end

def development?
current == "development"
end

def hot_loading?
(ENV["HOT_RELOADING"].present? && (
ENV["HOT_RELOADING"].upcase == "YES" ||
Expand Down
15 changes: 14 additions & 1 deletion lib/webpacker_lite/file_loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,34 @@ class NotFoundError < StandardError; end
class FileLoaderError < StandardError; end

class_attribute :instance
attr_accessor :data
attr_accessor :data, :mtime

class << self
def load_instance(path = file_path)
# Assume production is 100% cached
return if self.instance && # if we have a singleton
(env == "production" || # skip if production bc always cached
self.instance.mtime == File.mtime(path)) # skip if mtime not changed

self.instance = new(path)
end

def file_path
raise FileLoaderError.new("Subclass of WebpackerLite::FileLoader should override this method")
end

private

# Prefer the NODE_ENV to the rails env.
def env
ENV["NODE_ENV"].presence || Rails.env
end
end

private
def initialize(path)
@path = path
@mtime = File.mtime(path)
@data = load_data
end

Expand Down
2 changes: 1 addition & 1 deletion lib/webpacker_lite/manifest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def lookup!(name)
def lookup(name)
instance.confirm_manifest_exists

load_instance if WebpackerLite::Env.development? || instance.data.empty?
load_instance
raise WebpackerLite::FileLoader::FileLoaderError.new("WebpackerLite::Manifest.load must be called first") unless instance
instance.data[name.to_s]
end
Expand Down
8 changes: 4 additions & 4 deletions test/configuration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

class ConfigurationTest < Minitest::Test
def test_manifest_path
manifest_path = File.join(File.dirname(__FILE__), "test_app/public/webpack", "manifest.json").to_s
assert_equal WebpackerLite::Configuration.manifest_path.to_s, manifest_path
manifest_path = File.join(File.dirname(__FILE__), "test_app/public/webpack/test", "manifest.json").to_s
assert_equal manifest_path, WebpackerLite::Configuration.manifest_path.to_s
end

def test_output_path
output_path = File.join(File.dirname(__FILE__), "test_app/public/webpack").to_s
assert_equal WebpackerLite::Configuration.webpack_public_output_dir.to_s, output_path
output_path = File.join(File.dirname(__FILE__), "test_app/public/webpack/test").to_s
assert_equal output_path, WebpackerLite::Configuration.webpack_public_output_dir.to_s
end
end
6 changes: 3 additions & 3 deletions test/env_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

class EnvTest < Minitest::Test
def test_current_env
assert_equal WebpackerLite::Env.current, "production"
assert_equal Rails.env, WebpackerLite::Env.current
end

def test_file_path
correct_path = File.join(File.dirname(__FILE__), "test_app/config", "webpacker_lite.yml").to_s
assert_equal WebpackerLite::Env.file_path.to_s, correct_path
correct_path = File.join(File.dirname(__FILE__), "test_app", "config", "webpacker_lite.yml").to_s
assert_equal correct_path, WebpackerLite::Env.file_path.to_s
end
end
8 changes: 4 additions & 4 deletions test/helper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ def setup
end

def test_asset_pack_path
assert_equal @view.asset_pack_path("bootstrap.js"), "/webpack/bootstrap-300631c4f0e0f9c865bc.js"
assert_equal @view.asset_pack_path("bootstrap.css"), "/webpack/bootstrap-c38deda30895059837cf.css"
assert_equal @view.asset_pack_path("bootstrap.js"), "/webpack/test/bootstrap-300631c4f0e0f9c865bc.js"
assert_equal @view.asset_pack_path("bootstrap.css"), "/webpack/test/bootstrap-c38deda30895059837cf.css"
end

def test_javascript_pack_tag
script = %(<script src="/webpack/bootstrap-300631c4f0e0f9c865bc.js"></script>)
script = %(<script src="/webpack/test/bootstrap-300631c4f0e0f9c865bc.js"></script>)
assert_equal @view.javascript_pack_tag("bootstrap.js"), script
end

def test_stylesheet_pack_tag
expected_style = %(<link rel="stylesheet" media="screen" href="/webpack/bootstrap-c38deda30895059837cf.css" />)
expected_style = %(<link rel="stylesheet" media="screen" href="/webpack/test/bootstrap-c38deda30895059837cf.css" />)
assert_equal @view.stylesheet_pack_tag("bootstrap.css"), expected_style
end
end
4 changes: 2 additions & 2 deletions test/manifest_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

class ManifestTest < Minitest::Test
def test_file_path
file_path = File.join(File.dirname(__FILE__), "test_app/public/webpack", "manifest.json").to_s
file_path = File.join(File.dirname(__FILE__), "test_app/public/webpack/test", "manifest.json").to_s
assert_equal WebpackerLite::Manifest.file_path.to_s, file_path
end

def test_lookup_exception
manifest_path = File.join(File.dirname(__FILE__), "test_app/public/webpack", "manifest.json").to_s
manifest_path = File.join(File.dirname(__FILE__), "test_app/public/webpack/test", "manifest.json").to_s
asset_file = "calendar.js"
msg = <<-MSG
WebpackerLite can't find #{asset_file} in your manifest #{manifest_path}. Possible causes:
Expand Down
Loading