From 27df49d1b53d6843b63dfa68ef88555b990210f9 Mon Sep 17 00:00:00 2001 From: Michael Misshore Date: Mon, 18 Apr 2016 17:57:21 -0500 Subject: [PATCH 01/81] Update loadcss example to use the latest syntax --- README.md | 3 ++- lib/critical_path_css/rails/version.rb | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 836567d..58c1311 100644 --- a/README.md +++ b/README.md @@ -74,8 +74,9 @@ A simple example using loadcss-rails looks like: + ``` diff --git a/lib/critical_path_css/rails/version.rb b/lib/critical_path_css/rails/version.rb index 7115eaa..c7a8caa 100644 --- a/lib/critical_path_css/rails/version.rb +++ b/lib/critical_path_css/rails/version.rb @@ -1,6 +1,6 @@ module CriticalPathCSS module Rails - VERSION = '0.2.2' + VERSION = '0.2.3' PENTHOUSE_VERSION = '0.3.4' end end From 1cda58adb5c0c22e207cbbe4f16cd4e54a6a6457 Mon Sep 17 00:00:00 2001 From: Michael Misshore Date: Tue, 4 Oct 2016 17:36:31 -0500 Subject: [PATCH 02/81] Set expires_in to nil --- lib/critical-path-css-rails.rb | 2 +- lib/critical_path_css/rails/version.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/critical-path-css-rails.rb b/lib/critical-path-css-rails.rb index 4e8bbaf..4c6b0fc 100644 --- a/lib/critical-path-css-rails.rb +++ b/lib/critical-path-css-rails.rb @@ -5,7 +5,7 @@ module CriticalPathCss def self.generate CssFetcher.new.fetch.each do |route, css| - Rails.cache.write(route, css, namespace: CACHE_NAMESPACE) + Rails.cache.write(route, css, namespace: CACHE_NAMESPACE, expires_in: nil) end end diff --git a/lib/critical_path_css/rails/version.rb b/lib/critical_path_css/rails/version.rb index c7a8caa..e9c58ab 100644 --- a/lib/critical_path_css/rails/version.rb +++ b/lib/critical_path_css/rails/version.rb @@ -1,6 +1,6 @@ module CriticalPathCSS module Rails - VERSION = '0.2.3' + VERSION = '0.2.4' PENTHOUSE_VERSION = '0.3.4' end end From ca1823d6e3bdb7f6b35f5ba18025fb964d82577a Mon Sep 17 00:00:00 2001 From: Tom Aranda Date: Sat, 1 Oct 2016 13:51:28 -0500 Subject: [PATCH 03/81] Add methods to allow generation of critical CSS for a specific route and to allow removal of specific routes from the CSS cache. --- README.md | 53 ++++++++++++++++++++++---- lib/critical-path-css-rails.rb | 18 ++++++++- lib/critical_path_css/css_fetcher.rb | 6 ++- lib/critical_path_css/rails/version.rb | 2 +- lib/tasks/critical_path_css.rake | 6 ++- 5 files changed, 74 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 836567d..0feafb8 100644 --- a/README.md +++ b/README.md @@ -8,13 +8,16 @@ This gem assumes that you'll load the rest of the CSS asyncronously. At the mome This gem uses [PhantomJS](https://github.com/colszowka/phantomjs-gem) and [Penthouse](https://github.com/pocketjoso/penthouse) to generate the critical CSS. +## Update + +Version 0.3.0 is not compatible with previous versions. Please read the Upgrading from Previous Versions section below for more information. ## Installation Add `critical-path-css-rails` to your Gemfile: ``` -gem 'critical-path-css-rails', '~> 0.2.0' +gem 'critical-path-css-rails', '~> 0.3.0' ``` Download and install by running: @@ -65,20 +68,56 @@ To load the generated critical CSS into your layout, in the head tag, insert: ``` -A simple example using loadcss-rails looks like: +A simple example using [loadcss-rails](https://github.com/michael-misshore/loadcss-rails) looks like: ```HTML+ERB - +<%= tag :link, as: 'style', href: stylesheet_path('application'), onload: raw("this.rel='stylesheet'"), rel: 'preload' %> ``` +### Route-level Control of CSS Generation and Removal + +CriticalPathCss exposes some methods to give the user more control over the generation of Critical CSS and managment of the CSS cache: + +``` ruby +CriticalPathCss.generate route # Generates the critical path CSS for the given route (relative path) + +CriticalPathCss.generate_all # Generates critical CSS for all routes in critical_path_css.yml + +CriticalPathCss.clear route # Removes the CSS for the given route from the cache + +CriticalPathCss.clear_matched routes # Removes the CSS for the matched routes from the cache + +CriticalPathCss.clear_all # Clears all CSS from the cache +``` + +In addition to the `critical_path_css:generate` rake task described above, you also have access to task which clears the CSS cache: + +``` +rake critical_path_css:clear_all +``` + +Careful use of these methods allows the developer to generate critical path CSS dynamically within the app. The user should strongly consider using a [background job](http://edgeguides.rubyonrails.org/active_job_basics.html) when generating CSS in order to avoid tying up a rails thread. The `generate` method will send a GET request to your server which could cause infinite recursion if the developer is not careful. + +A user can use these methods to [dynamically generate critical path CSS](https://gist.github.com/taranda/1597e97ccf24c978b59aef9249666c77) without using the `rake critical_path_css:generate` rake task and without hardcoding the application's routes into `config/critical_path_css.yml`. See [this Gist](https://gist.github.com/taranda/1597e97ccf24c978b59aef9249666c77) for an example of such an implementation. + +## Upgrading from Previous Versions + +The latest version of Critcal Path CSS Rails changes the functionality of the `generate` method. In past versions, +`generate` would produce CSS for all of the routes listed in `config/critical_path_css.yml`. This functionality has been replaced by the `generate_all` method, and `generate` will only produce CSS for one route. + +Developers upgrading from versions prior to 0.3.0 will need to replace `CriticalPathCss:generate` with `CriticalPathCss:generate_all` throughout their codebase. One file that will need updating is `lib/tasks/critical_path_css.rake`. Users can upgrade this file automatically by running: + +``` prompt +rails generate critical_path_css:install +``` + +Answer 'Y' when prompted to overwrite `critical_path_css.rake`. However, overwriting `critical_path_css.yml` is not necessary and not recommended. ## Versions diff --git a/lib/critical-path-css-rails.rb b/lib/critical-path-css-rails.rb index 4e8bbaf..a6c62d7 100644 --- a/lib/critical-path-css-rails.rb +++ b/lib/critical-path-css-rails.rb @@ -3,12 +3,28 @@ module CriticalPathCss CACHE_NAMESPACE = 'critical-path-css' - def self.generate + def self.generate(route) + Rails.cache.write(route, CssFetcher.new.fetch_route(route), namespace: CACHE_NAMESPACE) + end + + def self.generate_all CssFetcher.new.fetch.each do |route, css| Rails.cache.write(route, css, namespace: CACHE_NAMESPACE) end end + def self.clear(route) + Rails.cache.delete(route, namespace: CACHE_NAMESPACE) + end + + def self.clear_matched(routes) + Rails.cache.delete_matched(routes,namespace: CACHE_NAMESPACE) + end + + def self.clear_all + self.clear_matched('*') + end + def self.fetch(route) Rails.cache.read(route, namespace: CACHE_NAMESPACE) || '' end diff --git a/lib/critical_path_css/css_fetcher.rb b/lib/critical_path_css/css_fetcher.rb index 3397819..9892ec7 100644 --- a/lib/critical_path_css/css_fetcher.rb +++ b/lib/critical_path_css/css_fetcher.rb @@ -13,7 +13,11 @@ def fetch @config.routes.map { |route| [route, css_for_route(route)] }.to_h end - private + def fetch_route(route) + css_for_route route + end + + protected def css_for_route(route) Phantomjs.run(PENTHOUSE_PATH, @config.base_url + route, @config.css_path) diff --git a/lib/critical_path_css/rails/version.rb b/lib/critical_path_css/rails/version.rb index c7a8caa..f48757d 100644 --- a/lib/critical_path_css/rails/version.rb +++ b/lib/critical_path_css/rails/version.rb @@ -1,6 +1,6 @@ module CriticalPathCSS module Rails - VERSION = '0.2.3' + VERSION = '0.3.0' PENTHOUSE_VERSION = '0.3.4' end end diff --git a/lib/tasks/critical_path_css.rake b/lib/tasks/critical_path_css.rake index 30016fb..ee66a9f 100644 --- a/lib/tasks/critical_path_css.rake +++ b/lib/tasks/critical_path_css.rake @@ -3,7 +3,11 @@ require 'critical-path-css-rails' namespace :critical_path_css do desc 'Generate critical CSS for the routes defined' task generate: :environment do - CriticalPathCss.generate + CriticalPathCss.generate_all + end + desc 'Clear all critical CSS from the cache' + task clear_all: :environment do + CriticalPathCss.clear_all end end From 136ba143fe99365c61cb5e6044a52f42e4e4e16c Mon Sep 17 00:00:00 2001 From: Tom Aranda Date: Fri, 28 Oct 2016 15:03:55 -0500 Subject: [PATCH 04/81] Set critical CSS cache entries to never expire. --- README.md | 2 ++ lib/critical-path-css-rails.rb | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 0b747d0..a71a470 100644 --- a/README.md +++ b/README.md @@ -105,6 +105,8 @@ In addition to the `critical_path_css:generate` rake task described above, you a rake critical_path_css:clear_all ``` +NOTE: The `clear_all` and `clear_matched` methods will not work with Memcached due to the latter's incompatibility with Rails' `delete_matched` method. We recommend using an alternative cache such as [Redis](https://github.com/redis-store/redis-rails). + Careful use of these methods allows the developer to generate critical path CSS dynamically within the app. The user should strongly consider using a [background job](http://edgeguides.rubyonrails.org/active_job_basics.html) when generating CSS in order to avoid tying up a rails thread. The `generate` method will send a GET request to your server which could cause infinite recursion if the developer is not careful. A user can use these methods to [dynamically generate critical path CSS](https://gist.github.com/taranda/1597e97ccf24c978b59aef9249666c77) without using the `rake critical_path_css:generate` rake task and without hardcoding the application's routes into `config/critical_path_css.yml`. See [this Gist](https://gist.github.com/taranda/1597e97ccf24c978b59aef9249666c77) for an example of such an implementation. diff --git a/lib/critical-path-css-rails.rb b/lib/critical-path-css-rails.rb index f635a1a..b027d6a 100644 --- a/lib/critical-path-css-rails.rb +++ b/lib/critical-path-css-rails.rb @@ -4,7 +4,8 @@ module CriticalPathCss CACHE_NAMESPACE = 'critical-path-css' def self.generate(route) - Rails.cache.write(route, CssFetcher.new.fetch_route(route), namespace: CACHE_NAMESPACE) + Rails.cache.write(route, CssFetcher.new.fetch_route(route), + namespace: CACHE_NAMESPACE, expires_in: nil) end def self.generate_all From 7a301e53c8d138c353838c21b12de37a5611dbad Mon Sep 17 00:00:00 2001 From: Tom Aranda Date: Fri, 4 Nov 2016 14:49:46 -0500 Subject: [PATCH 05/81] Remove clear_all method and add comments to clear_all rake task --- README.md | 7 +++---- lib/critical-path-css-rails.rb | 4 ---- lib/tasks/critical_path_css.rake | 5 ++++- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index a71a470..d63579d 100644 --- a/README.md +++ b/README.md @@ -95,17 +95,16 @@ CriticalPathCss.generate_all # Generates critical CSS for all routes i CriticalPathCss.clear route # Removes the CSS for the given route from the cache CriticalPathCss.clear_matched routes # Removes the CSS for the matched routes from the cache - -CriticalPathCss.clear_all # Clears all CSS from the cache ``` +NOTE: The `clear_matched` method will not work with Memcached due to the latter's incompatibility with Rails' `delete_matched` method. We recommend using an alternative cache such as [Redis](https://github.com/redis-store/redis-rails). + In addition to the `critical_path_css:generate` rake task described above, you also have access to task which clears the CSS cache: ``` rake critical_path_css:clear_all ``` - -NOTE: The `clear_all` and `clear_matched` methods will not work with Memcached due to the latter's incompatibility with Rails' `delete_matched` method. We recommend using an alternative cache such as [Redis](https://github.com/redis-store/redis-rails). +NOTE: The `critical_path_css:clear_all` rake task may need to be customized to suit your particular cache implementation. Careful use of these methods allows the developer to generate critical path CSS dynamically within the app. The user should strongly consider using a [background job](http://edgeguides.rubyonrails.org/active_job_basics.html) when generating CSS in order to avoid tying up a rails thread. The `generate` method will send a GET request to your server which could cause infinite recursion if the developer is not careful. diff --git a/lib/critical-path-css-rails.rb b/lib/critical-path-css-rails.rb index b027d6a..1e9d12b 100644 --- a/lib/critical-path-css-rails.rb +++ b/lib/critical-path-css-rails.rb @@ -22,10 +22,6 @@ def self.clear_matched(routes) Rails.cache.delete_matched(routes,namespace: CACHE_NAMESPACE) end - def self.clear_all - self.clear_matched('*') - end - def self.fetch(route) Rails.cache.read(route, namespace: CACHE_NAMESPACE) || '' end diff --git a/lib/tasks/critical_path_css.rake b/lib/tasks/critical_path_css.rake index ee66a9f..4e32f54 100644 --- a/lib/tasks/critical_path_css.rake +++ b/lib/tasks/critical_path_css.rake @@ -7,7 +7,10 @@ namespace :critical_path_css do end desc 'Clear all critical CSS from the cache' task clear_all: :environment do - CriticalPathCss.clear_all + # Use the following for Redis cache implmentations + CriticalPathCss.clear_matched('*') + # Some other cache implementations may require the following syntax instead + # CriticalPathCss.clear_matched(/.*/) end end From 53b359fbda66f69ded000f258697aeca54d1e90c Mon Sep 17 00:00:00 2001 From: Michael Misshore Date: Tue, 17 Jan 2017 21:03:12 -0600 Subject: [PATCH 06/81] Update Readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d63579d..c11bc1b 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ rails generate critical_path_css:install The generator adds the following files: -* `config/critical_path_css.yml` +* `config/critical_path_css.yml` **Note:** This file supports ERB. * `lib/tasks/critical_path_css.rake` From 25a6866eae79593ccef99741eb74b0bf3e7bc6f7 Mon Sep 17 00:00:00 2001 From: Michael Misshore Date: Tue, 17 Jan 2017 21:03:33 -0600 Subject: [PATCH 07/81] Add arguments to allow for SSL --- lib/critical_path_css/css_fetcher.rb | 10 +++++++++- lib/critical_path_css/rails/version.rb | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/critical_path_css/css_fetcher.rb b/lib/critical_path_css/css_fetcher.rb index 9892ec7..2fccdc9 100644 --- a/lib/critical_path_css/css_fetcher.rb +++ b/lib/critical_path_css/css_fetcher.rb @@ -20,7 +20,15 @@ def fetch_route(route) protected def css_for_route(route) - Phantomjs.run(PENTHOUSE_PATH, @config.base_url + route, @config.css_path) + url = @config.base_url + route + + Phantomjs.run( + '--ignore-ssl-errors=true', + '--ssl-protocol=tlsv1', + PENTHOUSE_PATH, + url, + @config.css_path + ) end end end diff --git a/lib/critical_path_css/rails/version.rb b/lib/critical_path_css/rails/version.rb index f48757d..0bffe92 100644 --- a/lib/critical_path_css/rails/version.rb +++ b/lib/critical_path_css/rails/version.rb @@ -1,6 +1,6 @@ module CriticalPathCSS module Rails - VERSION = '0.3.0' + VERSION = '0.3.1' PENTHOUSE_VERSION = '0.3.4' end end From 404048b733e8ba8c3403a289f1c05eccce7ff4ce Mon Sep 17 00:00:00 2001 From: Michael Misshore Date: Tue, 17 Jan 2017 21:56:42 -0600 Subject: [PATCH 08/81] Satisfy rubocop Conflicts: lib/critical_path_css/css_fetcher.rb --- lib/critical-path-css-rails.rb | 10 +++++++--- lib/critical_path_css/css_fetcher.rb | 2 +- lib/tasks/critical_path_css.rake | 9 +++++---- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/lib/critical-path-css-rails.rb b/lib/critical-path-css-rails.rb index 1e9d12b..be64a3c 100644 --- a/lib/critical-path-css-rails.rb +++ b/lib/critical-path-css-rails.rb @@ -4,8 +4,12 @@ module CriticalPathCss CACHE_NAMESPACE = 'critical-path-css' def self.generate(route) - Rails.cache.write(route, CssFetcher.new.fetch_route(route), - namespace: CACHE_NAMESPACE, expires_in: nil) + Rails.cache.write( + route, + CssFetcher.new.fetch_route(route), + namespace: CACHE_NAMESPACE, + expires_in: nil + ) end def self.generate_all @@ -19,7 +23,7 @@ def self.clear(route) end def self.clear_matched(routes) - Rails.cache.delete_matched(routes,namespace: CACHE_NAMESPACE) + Rails.cache.delete_matched(routes, namespace: CACHE_NAMESPACE) end def self.fetch(route) diff --git a/lib/critical_path_css/css_fetcher.rb b/lib/critical_path_css/css_fetcher.rb index 2fccdc9..90fbb2f 100644 --- a/lib/critical_path_css/css_fetcher.rb +++ b/lib/critical_path_css/css_fetcher.rb @@ -17,7 +17,7 @@ def fetch_route(route) css_for_route route end - protected + protected def css_for_route(route) url = @config.base_url + route diff --git a/lib/tasks/critical_path_css.rake b/lib/tasks/critical_path_css.rake index 4e32f54..7038ceb 100644 --- a/lib/tasks/critical_path_css.rake +++ b/lib/tasks/critical_path_css.rake @@ -5,12 +5,13 @@ namespace :critical_path_css do task generate: :environment do CriticalPathCss.generate_all end + desc 'Clear all critical CSS from the cache' task clear_all: :environment do - # Use the following for Redis cache implmentations - CriticalPathCss.clear_matched('*') - # Some other cache implementations may require the following syntax instead - # CriticalPathCss.clear_matched(/.*/) + # Use the following for Redis cache implmentations + CriticalPathCss.clear_matched('*') + # Some other cache implementations may require the following syntax instead + # CriticalPathCss.clear_matched(/.*/) end end From 677bed0230473a5b39d54fcac3d975d901e431d6 Mon Sep 17 00:00:00 2001 From: frozenfung Date: Thu, 2 Mar 2017 16:25:27 +0800 Subject: [PATCH 09/81] Upgrade phantomjs --- critical-path-css-rails.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/critical-path-css-rails.gemspec b/critical-path-css-rails.gemspec index 60dfa4d..68ac81c 100644 --- a/critical-path-css-rails.gemspec +++ b/critical-path-css-rails.gemspec @@ -10,7 +10,7 @@ Gem::Specification.new do |s| s.description = 'Only load the CSS you need for the initial viewport in Rails!' s.license = 'MIT' - s.add_runtime_dependency 'phantomjs', ['~> 1.9'] + s.add_runtime_dependency 'phantomjs', ['~> 2.1.1'] s.files = `git ls-files`.split("\n") s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) } From 2a940bf0f839358821e126c82b6d08753a4574f4 Mon Sep 17 00:00:00 2001 From: Michael Misshore Date: Fri, 3 Mar 2017 20:04:35 -0600 Subject: [PATCH 10/81] Increment version to 0.4.0 --- README.md | 4 ++-- lib/critical_path_css/rails/version.rb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index c11bc1b..183485d 100644 --- a/README.md +++ b/README.md @@ -10,14 +10,14 @@ This gem uses [PhantomJS](https://github.com/colszowka/phantomjs-gem) and [Penth ## Update -Version 0.3.0 is not compatible with previous versions. Please read the Upgrading from Previous Versions section below for more information. +Versions below 0.3.0 are not compatible with this version. Please read the Upgrading from Previous Versions section below for more information. ## Installation Add `critical-path-css-rails` to your Gemfile: ``` -gem 'critical-path-css-rails', '~> 0.3.0' +gem 'critical-path-css-rails', '~> 0.4.0' ``` Download and install by running: diff --git a/lib/critical_path_css/rails/version.rb b/lib/critical_path_css/rails/version.rb index 0bffe92..dad8e18 100644 --- a/lib/critical_path_css/rails/version.rb +++ b/lib/critical_path_css/rails/version.rb @@ -1,6 +1,6 @@ module CriticalPathCSS module Rails - VERSION = '0.3.1' + VERSION = '0.4.0' PENTHOUSE_VERSION = '0.3.4' end end From 47d7896d563dd08729d88f053af26889192cccfe Mon Sep 17 00:00:00 2001 From: Michael Misshore Date: Fri, 3 Mar 2017 20:09:20 -0600 Subject: [PATCH 11/81] Allow for the phantomjs version to be less strict --- critical-path-css-rails.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/critical-path-css-rails.gemspec b/critical-path-css-rails.gemspec index 68ac81c..404e650 100644 --- a/critical-path-css-rails.gemspec +++ b/critical-path-css-rails.gemspec @@ -10,7 +10,7 @@ Gem::Specification.new do |s| s.description = 'Only load the CSS you need for the initial viewport in Rails!' s.license = 'MIT' - s.add_runtime_dependency 'phantomjs', ['~> 2.1.1'] + s.add_runtime_dependency 'phantomjs', ['~> 2.1'] s.files = `git ls-files`.split("\n") s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) } From 71e70176db65e36ac3fe9986ca62cce8490e29e3 Mon Sep 17 00:00:00 2001 From: Gleb Mazovetskiy Date: Sat, 3 Jun 2017 20:14:01 +0100 Subject: [PATCH 12/81] Use penthouse from npm 1. Install npm dependencies on Gem.pre_install. 2. Use a penthouse wrapper script. 3. Remove phantomjs ruby dependency and the vendored version of penthouse. 4. Add a basic test. Refs #5 --- .codeclimate.yml | 2 - .gitignore | 2 + Gemfile | 19 +- critical-path-css-rails.gemspec | 6 +- ext/npm/extconf.rb | 3 + ext/npm/install.rb | 4 + lib/critical-path-css-rails.rb | 14 +- lib/critical_path_css/configuration.rb | 26 +- lib/critical_path_css/css_fetcher.rb | 65 +- lib/critical_path_css/rails/config_loader.rb | 24 + lib/critical_path_css/rails/version.rb | 1 - lib/fetch-css.js | 14 + lib/npm_commands.rb | 56 ++ lib/penthouse/penthouse.js | 601 ------------------- package-lock.json | 595 ++++++++++++++++++ package.json | 13 + spec/css_fetcher_spec.rb | 25 + spec/fixtures/static/test.css | 3 + spec/fixtures/static/test.html | 7 + spec/spec_helper.rb | 18 + spec/support/static_file_server.rb | 45 ++ 21 files changed, 897 insertions(+), 646 deletions(-) create mode 100644 ext/npm/extconf.rb create mode 100644 ext/npm/install.rb create mode 100644 lib/critical_path_css/rails/config_loader.rb create mode 100644 lib/fetch-css.js create mode 100644 lib/npm_commands.rb delete mode 100644 lib/penthouse/penthouse.js create mode 100644 package-lock.json create mode 100644 package.json create mode 100644 spec/css_fetcher_spec.rb create mode 100644 spec/fixtures/static/test.css create mode 100644 spec/fixtures/static/test.html create mode 100644 spec/spec_helper.rb create mode 100644 spec/support/static_file_server.rb diff --git a/.codeclimate.yml b/.codeclimate.yml index df67882..7561b07 100644 --- a/.codeclimate.yml +++ b/.codeclimate.yml @@ -1,4 +1,2 @@ languages: Ruby: true -exclude_paths: - - lib/penthouse/penthouse.js \ No newline at end of file diff --git a/.gitignore b/.gitignore index b36aa3d..1df918d 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,5 @@ test/version_tmp tmp .DS_Store +/node_modules/ +.rspec_status diff --git a/Gemfile b/Gemfile index 07d2b13..1cfb04f 100644 --- a/Gemfile +++ b/Gemfile @@ -1,4 +1,17 @@ -# A sample Gemfile -source "https://rubygems.org" +source 'https://rubygems.org' -gem 'rubocop', require: false \ No newline at end of file +gemspec + +group :development, :test do + gem 'byebug', platform: [:ruby], require: false + gem 'rubocop', require: false +end + +# HACK: npm install on bundle +unless $npm_commands_hook_installed # rubocop:disable Style/GlobalVars + Gem.pre_install do |installer| + next true unless installer.spec.name == 'critical-path-css-rails' + require_relative './ext/npm/install' + end + $npm_commands_hook_installed = true # rubocop:disable Style/GlobalVars +end diff --git a/critical-path-css-rails.gemspec b/critical-path-css-rails.gemspec index 404e650..ce7d39b 100644 --- a/critical-path-css-rails.gemspec +++ b/critical-path-css-rails.gemspec @@ -10,9 +10,11 @@ Gem::Specification.new do |s| s.description = 'Only load the CSS you need for the initial viewport in Rails!' s.license = 'MIT' - s.add_runtime_dependency 'phantomjs', ['~> 2.1'] - s.files = `git ls-files`.split("\n") s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) } s.require_path = 'lib' + + s.add_development_dependency 'rspec', '~> 3.6' + + s.extensions = ['ext/npm/extconf.rb'] end diff --git a/ext/npm/extconf.rb b/ext/npm/extconf.rb new file mode 100644 index 0000000..7dce95c --- /dev/null +++ b/ext/npm/extconf.rb @@ -0,0 +1,3 @@ +File.write 'Makefile', + "make:\n\t\ninstall:\n\truby install.rb\nclean:\n\t\n" + diff --git a/ext/npm/install.rb b/ext/npm/install.rb new file mode 100644 index 0000000..793ac21 --- /dev/null +++ b/ext/npm/install.rb @@ -0,0 +1,4 @@ +require_relative '../../lib/npm_commands' + +NpmCommands.new.install('--production', '.') || + raise('Error while installing npm dependencies') diff --git a/lib/critical-path-css-rails.rb b/lib/critical-path-css-rails.rb index be64a3c..78150b3 100644 --- a/lib/critical-path-css-rails.rb +++ b/lib/critical-path-css-rails.rb @@ -1,19 +1,21 @@ -module CriticalPathCss - require 'critical_path_css/css_fetcher' +require 'critical_path_css/configuration' +require 'critical_path_css/css_fetcher' +require 'critical_path_css/rails/config_loader' +module CriticalPathCss CACHE_NAMESPACE = 'critical-path-css' def self.generate(route) Rails.cache.write( route, - CssFetcher.new.fetch_route(route), + CssFetcher.new(config).fetch_route(route), namespace: CACHE_NAMESPACE, expires_in: nil ) end def self.generate_all - CssFetcher.new.fetch.each do |route, css| + CssFetcher.new(config).fetch.each do |route, css| Rails.cache.write(route, css, namespace: CACHE_NAMESPACE, expires_in: nil) end end @@ -29,4 +31,8 @@ def self.clear_matched(routes) def self.fetch(route) Rails.cache.read(route, namespace: CACHE_NAMESPACE) || '' end + + def self.config + @config ||= Configuration.new(CriticalPathCss::Rails::ConfigLoader.new.load) + end end diff --git a/lib/critical_path_css/configuration.rb b/lib/critical_path_css/configuration.rb index 737a5f3..2e4b794 100644 --- a/lib/critical_path_css/configuration.rb +++ b/lib/critical_path_css/configuration.rb @@ -1,39 +1,29 @@ require 'erb' module CriticalPathCss class Configuration - CONFIGURATION_FILENAME = 'critical_path_css.yml' - def initialize - @configurations = YAML.load(ERB.new(File.read(configuration_file_path)).result)[Rails.env] + def initialize(config) + @config = config end def base_url - @configurations['base_url'] + @config['base_url'] end def css_path - @css_path ||= begin - relative_path = @configurations['css_path'] || manifest_path - "#{Rails.root}/public#{relative_path}" - end + @config['css_path'] end def manifest_name - @configurations['manifest_name'] + @config['manifest_name'] end def routes - @configurations['routes'] + @config['routes'] end - private - - def configuration_file_path - @configuration_file_path ||= Rails.root.join('config', CONFIGURATION_FILENAME) - end - - def manifest_path - @manifest_path ||= ActionController::Base.helpers.stylesheet_path(manifest_name, host: '') + def penthouse_options + @config['penthouse_options'] || {} end end end diff --git a/lib/critical_path_css/css_fetcher.rb b/lib/critical_path_css/css_fetcher.rb index 90fbb2f..bda7314 100644 --- a/lib/critical_path_css/css_fetcher.rb +++ b/lib/critical_path_css/css_fetcher.rb @@ -1,12 +1,12 @@ +require 'json' +require 'open3' + module CriticalPathCss class CssFetcher - require 'phantomjs' - require 'critical_path_css/configuration' - - PENTHOUSE_PATH = "#{File.dirname(__FILE__)}/../penthouse/penthouse.js" + GEM_ROOT = File.expand_path(File.join('..', '..'), File.dirname(__FILE__)) - def initialize - @config = Configuration.new + def initialize(config) + @config = config end def fetch @@ -20,15 +20,50 @@ def fetch_route(route) protected def css_for_route(route) - url = @config.base_url + route - - Phantomjs.run( - '--ignore-ssl-errors=true', - '--ssl-protocol=tlsv1', - PENTHOUSE_PATH, - url, - @config.css_path - ) + options = { + 'url' => @config.base_url + route, + 'css' => @config.css_path, + ## optional params + # viewport dimensions + 'width' => 1300, + 'height' => 900, + # CSS selectors to always include, e.g.: + 'forceInclude' => [ + # '.keepMeEvenIfNotSeenInDom', + # '^\.regexWorksToo' + ], + # ms; abort critical CSS generation after this timeout + 'timeout' => 30000, + # set to true to throw on CSS errors (will run faster if no errors) + 'strict' => false, + # characters; strip out inline base64 encoded resources larger than this + 'maxEmbeddedBase64Length' => 1000, + # specify which user agent string when loading the page + 'userAgent' => 'Penthouse Critical Path CSS Generator', + # ms; render wait timeout before CSS processing starts (default: 100) + 'renderWaitTime' => 100, + # set to false to load (external) JS (default: true) + 'blockJSRequests' => true, + # see `phantomjs --help` for the list of all available options + 'phantomJsOptions' => { + 'ignore-ssl-errors' => true, + 'ssl-protocol' => 'tlsv1' + }, + 'customPageHeaders' => { + # use if getting compression errors like 'Data corrupted': + 'Accept-Encoding' => 'identity' + } + }.merge(@config.penthouse_options) + out, err, st = Dir.chdir(GEM_ROOT) do + Open3.capture3('node', 'lib/fetch-css.js', JSON.dump(options)) + end + if !st.exitstatus.zero? || out.empty? && !err.empty? + STDOUT.puts out + STDERR.puts err + raise "Failed to get CSS for route #{route}\n" \ + " with options=#{options.inspect}" + end + out end end end diff --git a/lib/critical_path_css/rails/config_loader.rb b/lib/critical_path_css/rails/config_loader.rb new file mode 100644 index 0000000..887ef2e --- /dev/null +++ b/lib/critical_path_css/rails/config_loader.rb @@ -0,0 +1,24 @@ +module CriticalPathCss + module Rails + module ConfigLoader + CONFIGURATION_FILENAME = 'critical_path_css.yml' + + def load + config = YAML.load(ERB.new(File.read(configuration_file_path)).result)[Rails.env] + config['css_path'] = "#{Rails.root}/public" + ( + config['css_path'] || + ActionController::Base.helpers.stylesheet_path( + config['manifest_name'], host: '' + ) + ) + config + end + + private + + def configuration_file_path + @configuration_file_path ||= Rails.root.join('config', CONFIGURATION_FILENAME) + end + end + end +end diff --git a/lib/critical_path_css/rails/version.rb b/lib/critical_path_css/rails/version.rb index dad8e18..f31dfb1 100644 --- a/lib/critical_path_css/rails/version.rb +++ b/lib/critical_path_css/rails/version.rb @@ -1,6 +1,5 @@ module CriticalPathCSS module Rails VERSION = '0.4.0' - PENTHOUSE_VERSION = '0.3.4' end end diff --git a/lib/fetch-css.js b/lib/fetch-css.js new file mode 100644 index 0000000..6f1db63 --- /dev/null +++ b/lib/fetch-css.js @@ -0,0 +1,14 @@ +const penthouse = require('penthouse'); +const fs = require('fs'); + +const penthouseOptions = JSON.parse(process.argv[2]); + +const STDOUT_FD = 1; +const STDERR_FD = 2; + +penthouse(penthouseOptions).then(function(criticalCss) { + fs.writeSync(STDOUT_FD, criticalCss); +}).catch(function(err) { + fs.writeSync(STDERR_FD, err); + process.exit(1); +}); diff --git a/lib/npm_commands.rb b/lib/npm_commands.rb new file mode 100644 index 0000000..5f50095 --- /dev/null +++ b/lib/npm_commands.rb @@ -0,0 +1,56 @@ +# frozen_string_literal: true + +# NPM wrapper with helpful error messages +class NpmCommands + + # @return [Boolean] whether the installation succeeded + def install(*args) # rubocop:disable Metrics/MethodLength + return false unless check_nodejs_installed + STDERR.puts 'Installing npm dependencies...' + install_status = Dir.chdir File.expand_path('..', File.dirname(__FILE__)) do + system('npm', 'install', *args) + end + STDERR.puts( + *if install_status + ['npm dependencies installed'] + else + ['-' * 60, + 'Error: npm dependencies installation failed', + '-' * 60] + end + ) + install_status + end + + private + + def check_nodejs_installed # rubocop:disable Metrics/MethodLength + return true if executable?('node') + STDERR.puts( + '-' * 60, + 'Error: critical-path-css-rails requires NodeJS and NPM.', + *if executable?('brew') + [' To install NodeJS and NPM, run:', + ' brew install node'] + elsif Gem.win_platform? + [' To install NodeJS and NPM, we recommend:', + ' https://github.com/coreybutler/nvm-windows/releases'] + else + [' To install NodeJS and NPM, we recommend:', + ' https://github.com/creationix/nvm'] + end, + '-' * 60 + ) + end + + def executable?(cmd) + exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : [''] + ENV['PATH'].split(File::PATH_SEPARATOR).each do |path| + exts.each do |ext| + exe = File.join(path, "#{cmd}#{ext}") + return exe if File.executable?(exe) && !File.directory?(exe) + end + end + nil + end +end diff --git a/lib/penthouse/penthouse.js b/lib/penthouse/penthouse.js deleted file mode 100644 index ff585dd..0000000 --- a/lib/penthouse/penthouse.js +++ /dev/null @@ -1,601 +0,0 @@ -/* -Penthouse CSS Critical Path Generator -https://github.com/pocketjoso/penthouse -Author: Jonas Ohlsson -License: MIT -Version: 0.3.4 - -USAGE: - phantomjs penthouse.js [options] - Options: - --width The viewport width in pixels. Defaults to 1300 - --height The viewport height in pixels. Defaults to 900 - - to run on HTTPS sites two flags must be passed in, directly after phantomjs in the call: - --ignore-ssl-errors=true --ssl-protocol=tlsv1 - -DEPENDENCIES - + "phantomjs" : "~1.9.7" - -*/ - - -(function() { "use strict"; -/* - * parser for the script - can be used both for the standalone node binary and the phantomjs script - */ - -/*jshint unused:false*/ - -var usageString = '[--width ] [--height ] '; - -function buildError(msg, problemToken, args) { - var error = new Error(msg + problemToken); - error.token = problemToken; - error.args = args; - throw error; -} - -// Parses the arguments passed in -// @returns { width, height, url, css } -// throws an error on wrong options or parsing error -function parseOptions(argsOriginal) { - var args = argsOriginal.slice(0), - validOptions = ['--width', '--height'], - parsed = {}, - val, - len = args.length, - optIndex, - option; - - if (len < 2) buildError('Not enough arguments, ', args); - - while (args.length > 2 && args[0].match(/^(--width|--height)$/)) { - optIndex = validOptions.indexOf(args[0]); - if (optIndex === -1) buildError('Logic/Parsing error ', args[0], args); - - // lose the dashes - option = validOptions[optIndex].slice(2); - val = args[1]; - - parsed[option] = parseInt(val, 10); - if (isNaN(parsed[option])) buildError('Parsing error when parsing ', val, args); - - // remove the two parsed arguments from the list - args = args.slice(2); - } - parsed.url = args[0]; - parsed.css = args[1]; - - if (!parsed.url) { - buildError('Missing url/path to html file', '', args); - } - - if (!parsed.css) { - buildError('Missing css file', '', args); - } - - - return parsed; -} - -if (typeof module !== 'undefined') { - module.exports = exports = { - parse: parseOptions, - usage: usageString - }; -} -/* -module for removing unused fontface rules - can be used both for the standalone node binary and the phantomjs script -*/ -/*jshint unused:false*/ - -function unusedFontfaceRemover (css){ - var toDeleteSections = []; - - //extract full @font-face rules - var fontFaceRegex = /(@font-face[ \s\S]*?\{([\s\S]*?)\})/gm, - ff; - - while ((ff = fontFaceRegex.exec(css)) !== null) { - - //grab the font name declared in the @font-face rule - //(can still be in quotes, f.e. 'Lato Web' - var t = /font-family[^:]*?:[ ]*([^;]*)/.exec(ff[1]); - if (typeof t[1] === 'undefined') - continue; //no font-family in @fontface rule! - - //rm quotes - var fontName = t[1].replace(/['"]/gm, ''); - - // does this fontname appear as a font-family or font (shorthand) value? - var fontNameRegex = new RegExp('([^{}]*?){[^}]*?font(-family)?[^:]*?:[^;]*' + fontName + '[^,;]*[,;]', 'gmi'); - - - var fontFound = false, - m; - - while ((m = fontNameRegex.exec(css)) !== null) { - if (m[1].indexOf('@font-face') === -1) { - //log('FOUND, keep rule'); - fontFound = true; - break; - } - } - if (!fontFound) { - //NOT FOUND, rm! - - //can't remove rule here as it will screw up ongoing while (exec ...) loop. - //instead: save indices and delete AFTER for loop - var closeRuleIndex = css.indexOf('}', ff.index); - //unshift - add to beginning of array - we need to remove rules in reverse order, - //otherwise indeces will become incorrect again. - toDeleteSections.unshift({ - start: ff.index, - end: closeRuleIndex + 1 - }); - } - } - //now delete the @fontface rules we registed as having no matches in the css - for (var i = 0; i < toDeleteSections.length; i++) { - var start = toDeleteSections[i].start, - end = toDeleteSections[i].end; - css = css.substring(0, start) + css.substring(end); - } - - return css; -}; - - - -if(typeof module !== 'undefined') { - module.exports = unusedFontfaceRemover; -} -/*jshint unused:false*/ - -/* === preFormatCSS === - * preformats the css to ensure we won't run into and problems in our parsing - * removes comments (actually would be anough to remove/replace {} chars.. TODO - * replaces } char inside content: '' properties. - */ - -function cssPreformatter (css){ - //remove comments from css (including multi-line coments) - css = css.replace(/\/\*[\s\S]*?\*\//g, ''); - - //replace Windows \r\n with \n, - //otherwise final output might get converted into /r/r/n - css = css.replace(/\r\n/gm, '\n'); - - //we also need to replace eventual close curly bracket characters inside content: '' property declarations, replace them with their ASCI code equivalent - //\7d (same as: '\' + '}'.charCodeAt(0).toString(16) ); - - var m, - regexP = /(content\s*:\s*['"][^'"]*)}([^'"]*['"])/gm, - matchedData = []; - - //for each content: '' rule that contains at least one end bracket ('}') - while ((m = regexP.exec(css)) !== null) { - //we need to replace ALL end brackets in the rule - //we can't do it in here, because it will mess up ongoing exec, store data and do after - - //unshift - add to beginning of array - we need to remove rules in reverse order, - //otherwise indeces will become incorrect. - matchedData.unshift({ - start: m.index, - end: m.index + m[0].length, - replaceStr: m[0].replace(/\}/gm, '\\7d') - }); - } - - for (var i = 0; i < matchedData.length; i++) { - var item = matchedData[0]; - css = css.substring(0, item.start) + item.replaceStr + css.substring(item.end); - } - - return css; -}; - -if(typeof module !== 'undefined') { - module.exports = cssPreformatter; -} -var standaloneMode = true; -'use strict'; -var standaloneMode = standaloneMode || false; - -var page = require('webpage').create(), - fs = require('fs'), - system = require('system'), - DEBUG = false, - stdout = system.stdout; // for using this as a file - -var combineArgsString = function(argsArr) { - return [].join.call(argsArr, ' ') + '\n'; -}; - -// monkey patch for directing errors to stderr -// https://github.com/ariya/phantomjs/issues/10150#issuecomment-28707859 -var errorlog = function() { - system.stderr.write(combineArgsString(arguments)); -}; - -var debug = function() { - if (DEBUG) errorlog('DEBUG: ' + combineArgsString(arguments)); -}; - -// discard stdout from phantom exit; -var phantomExit = function(code) { - if (page) { - page.close(); - } - setTimeout(function() { - phantom.exit(code); - }, 0); -}; - -//don't confuse analytics more than necessary when visiting websites -page.settings.userAgent = 'Penthouse Critical Path CSS Generator'; - -/* prevent page JS errors from being output to final CSS */ -page.onError = function(msg, trace) { - //do nothing -}; - -page.onResourceError = function(resourceError) { - page.reason = resourceError.errorString; - page.reason_url = resourceError.url; -}; - -var main = function(options) { - debug('main(): ', JSON.stringify(options)); -//final cleanup -//remove all empty rules, and remove leading/trailing whitespace - try { - var f = fs.open(options.css, 'r'); - - //preformat css - var cssPreformat; - if (standaloneMode) { - cssPreformat = cssPreformatter; - } else { - cssPreformat = require('./css-preformatter.js'); - } - options.css = cssPreformat(f.read()); - } catch (e) { - errorlog(e); - phantomExit(1); - } - - // start the critical path CSS generation - getCriticalPathCss(options); -}; - -function cleanup(css) { - //remove all animation rules, as keyframes have already been removed - css = css.replace(/(-webkit-|-moz-|-ms-|-o-)?animation[ ]?:[^;{}]*;/gm, ''); - //remove all empty rules, and remove leading/trailing whitespace - return css.replace(/[^{}]*\{\s*\}/gm, '').trim(); -} - -/* Final function - * Get's called from getCriticalPathCss when CSS extraction from page is done*/ -page.onCallback = function(css) { - debug('phantom.onCallback'); - - try { - if (css) { - // we are done - clean up the final css - var finalCss = cleanup(css); - - // remove unused @fontface rules - var ffRemover; - if (standaloneMode) { - ffRemover = unusedFontfaceRemover; - } else { - ffRemover = require('./unused-fontface-remover.js'); - } - finalCss = ffRemover(finalCss); - - if(finalCss.trim().length === 0){ - errorlog('Note: Generated critical css was empty for URL: ' + options.url); - } - - // return the critical css! - stdout.write(finalCss); - phantomExit(0); - } else { - // No css. This is not an error on our part - // but still safer to warn the end user, in case they made a mistake - errorlog('Note: Generated critical css was empty for URL: ' + options.url); - // for consisteny, still generate output (will be empty) - stdout.write(css); - phantomExit(0); - } - - } catch (ex) { - debug('phantom.onCallback -> error', ex); - errorlog('error: ' + ex); - phantomExit(1); - } -}; - -/* - * Tests each selector in css file at specified resolution, - * to see if any such elements appears above the fold on the page - * modifies CSS - removes selectors that don't appear, and empty rules - * - * @param options.url the url as a string - * @param options.css the css as a string - * @param options.width the width of viewport - * @param options.height the height of viewport - ---------------------------------------------------------*/ -function getCriticalPathCss(options) { - debug('getCriticalPathCss():', JSON.stringify(options)); - - page.viewportSize = { - width: options.width, - height: options.height - }; - - page.open(options.url, function(status) { - if (status !== 'success') { - errorlog('Error opening url \'' + page.reason_url + '\': ' + page.reason); - phantomExit(1); - } else { - - debug('Starting sandboxed evaluation of CSS\n', options.css); - // sandboxed environments - no outside references - // arguments and return value must be primitives - // @see http://phantomjs.org/api/webpage/method/evaluate.html - page.evaluate(function sandboxed(css) { - var h = window.innerHeight, - renderWaitTime = 100, //ms TODO: user specifiable through options object - finished = false, - currIndex = 0, - forceRemoveNestedRule = false; - - //split CSS so we can value the (selector) rules separately. - //but first, handle stylesheet initial non nested @-rules. - //they don't come with any associated rules, and should all be kept, - //so just keep them in critical css, but don't include them in split - var splitCSS = css.replace(/@(import|charset|namespace)[^;]*;/g, ''); - var split = splitCSS.split(/[{}]/g); - - var getNewValidCssSelector = function(i) { - var newSel = split[i]; - /* HANDLE Nested @-rules */ - - /*Case 1: @-rule with CSS properties inside [REMAIN] - Can't remove @font-face rules here, don't know if used or not. - Another check at end for this purpose. - */ - if (/@(font-face)/gi.test(newSel)) { - //skip over this rule - currIndex = css.indexOf('}', currIndex) + 1; - return getNewValidCssSelector(i + 2); - } - /*Case 2: @-rule with CSS properties inside [REMOVE] - @page - This case doesn't need any special handling, - as this "selector" won't match anything on the page, - and will therefor be removed, together with it's css props - */ - - /*Case 4: @-rule with full CSS (rules) inside [REMOVE] - @media print|speech|aural, @keyframes - Delete this rule and all its contents - doesn't belong in critical path CSS - */ - else if (/@(media (print|speech|aural)|(([a-z\-])*keyframes))/gi.test(newSel)) { - //force delete on child css rules - forceRemoveNestedRule = true; - return getNewValidCssSelector(i + 1); - } - - /*Case 3: @-rule with full CSS (rules) inside [REMAIN] - This test is executed AFTER Case 4, - since we here match every remaining @media, - after @media print has been removed by Case 4 rule) - - just skip this particular line (i.e. keep), and continue checking the CSS inside as normal - */ - else if (/@(media|(-moz-)?document|supports)/gi.test(newSel)) { - return getNewValidCssSelector(i + 1); - } - /* - Resume normal execution after end of @-media rule with inside CSS rules (Case 3) - Also identify abrupt file end. - */ - else if (newSel.trim().length === 0) { - //abrupt file end - if (i + 1 >= split.length) { - //end of file - finished = true; - return false; - } - //end of @-rule (Case 3) - forceRemoveNestedRule = false; - return getNewValidCssSelector(i + 1); - } - return i; - }; - - var removeSelector = function(sel, selectorsKept) { - var selPos = css.indexOf(sel, currIndex); - - //check what comes next: { or , - var nextComma = css.indexOf(',', selPos); - var nextOpenBracket = css.indexOf('{', selPos); - - if (selectorsKept > 0 || (nextComma > 0 && nextComma < nextOpenBracket)) { - //we already kept selectors from this rule, so rule will stay - - //more selectors in selectorList, cut until (and including) next comma - if (nextComma > 0 && nextComma < nextOpenBracket) { - css = css.substring(0, selPos) + css.substring(nextComma + 1); - } - //final selector, cut until open bracket. Also remove previous comma, as the (new) last selector should not be followed by a comma. - else { - var prevComma = css.lastIndexOf(',', selPos); - css = css.substring(0, prevComma) + css.substring(nextOpenBracket); - } - } else { - //no part of selector (list) matched elements above fold on page - remove whole rule CSS rule - var endRuleBracket = css.indexOf('}', nextOpenBracket); - - css = css.substring(0, selPos) + css.substring(endRuleBracket + 1); - } - }; - - - var processCssRules = function() { - for (var i = 0; i < split.length; i = i + 2) { - //step over non DOM CSS selectors (@-rules) - i = getNewValidCssSelector(i); - - //reach end of CSS - if (finished) { - //call final function to exit outside of phantom evaluate scope - window.callPhantom(css); - } - - var fullSel = split[i]; - //fullSel can contain combined selectors - //,f.e. body, html {} - //split and check one such selector at the time. - var selSplit = fullSel.split(','); - //keep track - if we remove all selectors, we also want to remove the whole rule. - var selectorsKept = 0; - var aboveFold; - - for (var j = 0; j < selSplit.length; j++) { - var sel = selSplit[j]; - - //some selectors can't be matched on page. - //In these cases we test a slightly modified selectors instead, temp. - var temp = sel; - - if (sel.indexOf(':') > -1) { - //handle special case selectors, the ones that contain a semi colon (:) - //many of these selectors can't be matched to anything on page via JS, - //but that still might affect the above the fold styling - - //these psuedo selectors depend on an element, - //so test element instead (would do the same for f.e. :hover, :focus, :active IF we wanted to keep them for critical path css, but we don't) - temp = temp.replace(/(:?:before|:?:after)*/g, ''); - - //if selector is purely psuedo (f.e. ::-moz-placeholder), just keep as is. - //we can't match it to anything on page, but it can impact above the fold styles - if (temp.replace(/:[:]?([a-zA-Z0-9\-\_])*/g, '').trim().length === 0) { - currIndex = css.indexOf(sel, currIndex) + sel.length; - selectorsKept++; - continue; - } - - //handle browser specific psuedo selectors bound to elements, - //Example, button::-moz-focus-inner, input[type=number]::-webkit-inner-spin-button - //remove browser specific pseudo and test for element - temp = temp.replace(/:?:-[a-z-]*/g, ''); - } - - if (!forceRemoveNestedRule) { - //now we have a selector to test, first grab any matching elements - var el; - try { - el = document.querySelectorAll(temp); - } catch (e) { - //not a valid selector, remove it. - removeSelector(sel, 0); - continue; - } - - //check if selector matched element(s) on page.. - aboveFold = false; - - for (var k = 0; k < el.length; k++) { - var testEl = el[k]; - //temporarily force clear none in order to catch elements that clear previous content themselves and who w/o their styles could show up unstyled in above the fold content (if they rely on f.e. 'clear:both;' to clear some main content) - testEl.style.clear = 'none'; - - //check to see if any matched element is above the fold on current page - //(in current viewport size) - if (testEl.getBoundingClientRect().top < h) { - //then we will save this selector - aboveFold = true; - selectorsKept++; - - //update currIndex so we only search from this point from here on. - currIndex = css.indexOf(sel, currIndex); - - //set clear style back to what it was - testEl.style.clear = ''; - //break, because matching 1 element is enough - break; - } - //set clear style back to what it was - testEl.style.clear = ''; - } - } else { - aboveFold = false; - } //force removal of selector - - //if selector didn't match any elements above fold - delete selector from CSS - if (aboveFold === false) { - //update currIndex so we only search from this point from here on. - currIndex = css.indexOf(sel, currIndex); - //remove seletor (also removes rule, if nnothing left) - removeSelector(sel, selectorsKept); - } - } - //if rule stayed, move our cursor forward for matching new selectors - if (selectorsKept > 0) { - currIndex = css.indexOf('}', currIndex) + 1; - } - } - - //we're done - call final function to exit outside of phantom evaluate scope - window.callPhantom(css); - }; - - //give some time (renderWaitTime) for sites like facebook that build their page dynamically, - //otherwise we can miss some selectors (and therefor rules) - //--tradeoff here: if site is too slow with dynamic content, - // it doesn't deserve to be in critical path. - setTimeout(processCssRules, renderWaitTime); - - }, options.css); - } - }); -} - -var parser, parse, usage, options; - -// test to see if we are running as a standalone script -// or as part of the node module -if (standaloneMode) { - parse = parseOptions; - usage = usageString; -} else { - parser = require('../options-parser'); - parse = parser.parse; - usage = parser.usage; -} - -try { - options = parse(system.args.slice(1)); -} catch (ex) { - - errorlog('Caught error parsing arguments: ' + ex.message); - - // the usage string does not make sense to show if running via Node - if(standaloneMode) { - errorlog('\nUsage: phantomjs penthouse.js ' + usage); - } - - phantomExit(1); -} - -// set defaults -if (!options.width) options.width = 1300; -if (!options.height) options.height = 900; - -main(options); -})(); \ No newline at end of file diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..f2a0244 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,595 @@ +{ + "name": "critical-path-css-rails", + "version": "1.0.0", + "lockfileVersion": 1, + "dependencies": { + "amdefine": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/amdefine/-/amdefine-1.0.1.tgz", + "integrity": "sha1-SlKCrBZHKek2Gbz9OtFR+BfOkfU=" + }, + "ansi-regex": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz", + "integrity": "sha1-w7M6te42DYbg5ijwRorn7yfWVN8=" + }, + "ansi-styles": { + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-2.2.1.tgz", + "integrity": "sha1-tDLdM1i2NM914eRmQ2gkBTPB3b4=" + }, + "apartment": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/apartment/-/apartment-1.1.1.tgz", + "integrity": "sha1-/ZQGzcyodTWULxWzYKGrWkqpfiY=" + }, + "asn1": { + "version": "0.2.3", + "resolved": "https://registry.npmjs.org/asn1/-/asn1-0.2.3.tgz", + "integrity": "sha1-2sh4dxPJlmhJ/IGAd36+nB3fO4Y=" + }, + "assert-plus": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/assert-plus/-/assert-plus-0.2.0.tgz", + "integrity": "sha1-104bh+ev/A24qttwIfP+SBAasjQ=" + }, + "asynckit": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", + "integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k=" + }, + "atob": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/atob/-/atob-1.1.3.tgz", + "integrity": "sha1-lfE2KbEsOlGl0hWr3OKqnzL4B3M=" + }, + "aws-sign2": { + "version": "0.6.0", + "resolved": "https://registry.npmjs.org/aws-sign2/-/aws-sign2-0.6.0.tgz", + "integrity": "sha1-FDQt0428yU0OW4fXY81jYSwOeU8=" + }, + "aws4": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/aws4/-/aws4-1.6.0.tgz", + "integrity": "sha1-g+9cqGCysy5KDe7e6MdxudtXRx4=" + }, + "babel-polyfill": { + "version": "6.23.0", + "resolved": "https://registry.npmjs.org/babel-polyfill/-/babel-polyfill-6.23.0.tgz", + "integrity": "sha1-g2TKYt+Or7gwSZ9pkXdGbDsDSZ0=" + }, + "babel-runtime": { + "version": "6.23.0", + "resolved": "https://registry.npmjs.org/babel-runtime/-/babel-runtime-6.23.0.tgz", + "integrity": "sha1-CpSJ8UTecO+zzkMArM2zKeL8VDs=" + }, + "bcrypt-pbkdf": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/bcrypt-pbkdf/-/bcrypt-pbkdf-1.0.1.tgz", + "integrity": "sha1-Y7xdy2EzG5K8Bf1SiVPDNGKgb40=", + "optional": true + }, + "boom": { + "version": "2.10.1", + "resolved": "https://registry.npmjs.org/boom/-/boom-2.10.1.tgz", + "integrity": "sha1-OciRjO/1eZ+D+UkqhI9iWt0Mdm8=" + }, + "caseless": { + "version": "0.11.0", + "resolved": "https://registry.npmjs.org/caseless/-/caseless-0.11.0.tgz", + "integrity": "sha1-cVuW6phBWTzDMGeSP17GDr2k99c=" + }, + "chalk": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz", + "integrity": "sha1-qBFcVeSnAv5NFQq9OHKCKn4J/Jg=" + }, + "combined-stream": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.5.tgz", + "integrity": "sha1-k4NwpXtKUd6ix3wV1cX9+JUWQAk=" + }, + "commander": { + "version": "2.9.0", + "resolved": "https://registry.npmjs.org/commander/-/commander-2.9.0.tgz", + "integrity": "sha1-nJkJQXbhIkDLItbFFGCYQA/g99Q=" + }, + "concat-stream": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/concat-stream/-/concat-stream-1.5.0.tgz", + "integrity": "sha1-U/fUPFHF5D+ByP3QMyHGMb5o1hE=" + }, + "core-js": { + "version": "2.4.1", + "resolved": "https://registry.npmjs.org/core-js/-/core-js-2.4.1.tgz", + "integrity": "sha1-TekR5mew6ukSTjQlS1OupvxhjT4=" + }, + "core-util-is": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz", + "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=" + }, + "cryptiles": { + "version": "2.0.5", + "resolved": "https://registry.npmjs.org/cryptiles/-/cryptiles-2.0.5.tgz", + "integrity": "sha1-O9/s3GCBR8HGcgL6KR59ylnqo7g=" + }, + "css": { + "version": "git+https://github.com/pocketjoso/css.git#8ddea7e3cbc0a183ecf694a7a5fbc84326893893" + }, + "css-mediaquery": { + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/css-mediaquery/-/css-mediaquery-0.1.2.tgz", + "integrity": "sha1-aiw3NEkoYYYxxUvTPO3TAdoYvqA=" + }, + "dashdash": { + "version": "1.14.1", + "resolved": "https://registry.npmjs.org/dashdash/-/dashdash-1.14.1.tgz", + "integrity": "sha1-hTz6D3y+L+1d4gMmuN1YEDX24vA=", + "dependencies": { + "assert-plus": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/assert-plus/-/assert-plus-1.0.0.tgz", + "integrity": "sha1-8S4PPF13sLHN2RRpQuTpbB5N1SU=" + } + } + }, + "debug": { + "version": "0.7.4", + "resolved": "https://registry.npmjs.org/debug/-/debug-0.7.4.tgz", + "integrity": "sha1-BuHqgILCyxTjmAbiLi9vdX+Srzk=" + }, + "delayed-stream": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", + "integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk=" + }, + "ecc-jsbn": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/ecc-jsbn/-/ecc-jsbn-0.1.1.tgz", + "integrity": "sha1-D8c6ntXw1Tw4GTOYUj735UN3dQU=", + "optional": true + }, + "es6-promise": { + "version": "4.0.5", + "resolved": "https://registry.npmjs.org/es6-promise/-/es6-promise-4.0.5.tgz", + "integrity": "sha1-eILzCt3lskDM+n99eMVIMwlRrkI=" + }, + "escape-string-regexp": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", + "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=" + }, + "extend": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/extend/-/extend-3.0.1.tgz", + "integrity": "sha1-p1Xqe8Gt/MWjHOfnYtuq3F5jZEQ=" + }, + "extract-zip": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/extract-zip/-/extract-zip-1.5.0.tgz", + "integrity": "sha1-ksz22B73Cp+kwXRxFMzvbYaIpsQ=" + }, + "extsprintf": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/extsprintf/-/extsprintf-1.0.2.tgz", + "integrity": "sha1-4QgOBljjALBilJkMxw4VAiNf1VA=" + }, + "fd-slicer": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/fd-slicer/-/fd-slicer-1.0.1.tgz", + "integrity": "sha1-i1vL2ewyfFBBv5qwI/1nUPEXfmU=" + }, + "forever-agent": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/forever-agent/-/forever-agent-0.6.1.tgz", + "integrity": "sha1-+8cfDEGt6zf5bFd60e1C2P2sypE=" + }, + "form-data": { + "version": "2.1.4", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-2.1.4.tgz", + "integrity": "sha1-M8GDrPGTJ27KqYFDpp6Uv+4XUNE=" + }, + "fs-extra": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-1.0.0.tgz", + "integrity": "sha1-zTzl9+fLYUWIP8rjGR6Yd/hYeVA=" + }, + "generate-function": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/generate-function/-/generate-function-2.0.0.tgz", + "integrity": "sha1-aFj+fAlpt9TpCTM3ZHrHn2DfvnQ=" + }, + "generate-object-property": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/generate-object-property/-/generate-object-property-1.2.0.tgz", + "integrity": "sha1-nA4cQDCM6AT0eDYYuTf6iPmdUNA=" + }, + "get-stdin": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/get-stdin/-/get-stdin-5.0.1.tgz", + "integrity": "sha1-Ei4WFZHiH/TFJTAwVpPyDmOTo5g=" + }, + "getpass": { + "version": "0.1.7", + "resolved": "https://registry.npmjs.org/getpass/-/getpass-0.1.7.tgz", + "integrity": "sha1-Xv+OPmhNVprkyysSgmBOi6YhSfo=", + "dependencies": { + "assert-plus": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/assert-plus/-/assert-plus-1.0.0.tgz", + "integrity": "sha1-8S4PPF13sLHN2RRpQuTpbB5N1SU=" + } + } + }, + "graceful-fs": { + "version": "4.1.11", + "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.1.11.tgz", + "integrity": "sha1-Dovf5NHduIVNZOBOp8AOKgJuVlg=" + }, + "graceful-readlink": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/graceful-readlink/-/graceful-readlink-1.0.1.tgz", + "integrity": "sha1-TK+tdrxi8C+gObL5Tpo906ORpyU=" + }, + "har-validator": { + "version": "2.0.6", + "resolved": "https://registry.npmjs.org/har-validator/-/har-validator-2.0.6.tgz", + "integrity": "sha1-zcvAgYgmWtEZtqWnyKtw7s+10n0=" + }, + "has-ansi": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/has-ansi/-/has-ansi-2.0.0.tgz", + "integrity": "sha1-NPUEnOHs3ysGSa8+8k5F7TVBbZE=" + }, + "hasha": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/hasha/-/hasha-2.2.0.tgz", + "integrity": "sha1-eNfL/B5tZjA/55g3NlmEUXsvbuE=" + }, + "hawk": { + "version": "3.1.3", + "resolved": "https://registry.npmjs.org/hawk/-/hawk-3.1.3.tgz", + "integrity": "sha1-B4REvXwWQLD+VA0sm3PVlnjo4cQ=" + }, + "hoek": { + "version": "2.16.3", + "resolved": "https://registry.npmjs.org/hoek/-/hoek-2.16.3.tgz", + "integrity": "sha1-ILt0A9POo5jpHcRxCo/xuCdKJe0=" + }, + "http-signature": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/http-signature/-/http-signature-1.1.1.tgz", + "integrity": "sha1-33LiZwZs0Kxn+3at+OE0qPvPkb8=" + }, + "inherits": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", + "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=" + }, + "is-my-json-valid": { + "version": "2.16.0", + "resolved": "https://registry.npmjs.org/is-my-json-valid/-/is-my-json-valid-2.16.0.tgz", + "integrity": "sha1-8Hndm/2uZe4gOKrorLyGqxCeNpM=" + }, + "is-property": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/is-property/-/is-property-1.0.2.tgz", + "integrity": "sha1-V/4cTkhHTt1lsJkR8msc1Ald2oQ=" + }, + "is-stream": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-1.1.0.tgz", + "integrity": "sha1-EtSj3U5o4Lec6428hBc66A2RykQ=" + }, + "is-typedarray": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/is-typedarray/-/is-typedarray-1.0.0.tgz", + "integrity": "sha1-5HnICFjfDBsR3dppQPlgEfzaSpo=" + }, + "isarray": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", + "integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=" + }, + "isexe": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", + "integrity": "sha1-6PvzdNxVb/iUehDcsFctYz8s+hA=" + }, + "isstream": { + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/isstream/-/isstream-0.1.2.tgz", + "integrity": "sha1-R+Y/evVa+m+S4VAOaQ64uFKcCZo=" + }, + "jodid25519": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/jodid25519/-/jodid25519-1.0.2.tgz", + "integrity": "sha1-BtSRIlUJNBlHfUJWM2BuDpB4KWc=", + "optional": true + }, + "jsbn": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/jsbn/-/jsbn-0.1.1.tgz", + "integrity": "sha1-peZUwuWi3rXyAdls77yoDA7y9RM=", + "optional": true + }, + "jsesc": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/jsesc/-/jsesc-1.3.0.tgz", + "integrity": "sha1-RsP+yMGJKxKwgz25vHYiF226s0s=" + }, + "json-schema": { + "version": "0.2.3", + "resolved": "https://registry.npmjs.org/json-schema/-/json-schema-0.2.3.tgz", + "integrity": "sha1-tIDIkuWaLwWVTOcnvT8qTogvnhM=" + }, + "json-stringify-safe": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz", + "integrity": "sha1-Epai1Y/UXxmg9s4B1lcB4sc1tus=" + }, + "jsonfile": { + "version": "2.4.0", + "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-2.4.0.tgz", + "integrity": "sha1-NzaitCi4e72gzIO1P6PWM6NcKug=" + }, + "jsonpointer": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/jsonpointer/-/jsonpointer-4.0.1.tgz", + "integrity": "sha1-T9kss04OnbPInIYi7PUfm5eMbLk=" + }, + "jsprim": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/jsprim/-/jsprim-1.4.0.tgz", + "integrity": "sha1-o7h+QCmNjDgFUtjMdiigu5WiKRg=", + "dependencies": { + "assert-plus": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/assert-plus/-/assert-plus-1.0.0.tgz", + "integrity": "sha1-8S4PPF13sLHN2RRpQuTpbB5N1SU=" + } + } + }, + "kew": { + "version": "0.7.0", + "resolved": "https://registry.npmjs.org/kew/-/kew-0.7.0.tgz", + "integrity": "sha1-edk9LTM2PW/dKXCzNdkUGtWR15s=" + }, + "klaw": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/klaw/-/klaw-1.3.1.tgz", + "integrity": "sha1-QIhDO0azsbolnXh4XY6W9zugJDk=" + }, + "lodash": { + "version": "3.10.1", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-3.10.1.tgz", + "integrity": "sha1-W/Rejkm6QYnhfUgnid/RW9FAt7Y=" + }, + "mime-db": { + "version": "1.27.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.27.0.tgz", + "integrity": "sha1-gg9XIpa70g7CXtVeW13oaeVDbrE=" + }, + "mime-types": { + "version": "2.1.15", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.15.tgz", + "integrity": "sha1-pOv1BkCUVpI3uM9wBGd20J/JKu0=" + }, + "minimist": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz", + "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=" + }, + "mkdirp": { + "version": "0.5.0", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.0.tgz", + "integrity": "sha1-HXMHam35hs2TROFecfzAWkyavxI=", + "dependencies": { + "minimist": { + "version": "0.0.8", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", + "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=" + } + } + }, + "oauth-sign": { + "version": "0.8.2", + "resolved": "https://registry.npmjs.org/oauth-sign/-/oauth-sign-0.8.2.tgz", + "integrity": "sha1-Rqarfwrq2N6unsBWV4C31O/rnUM=" + }, + "os-tmpdir": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/os-tmpdir/-/os-tmpdir-1.0.2.tgz", + "integrity": "sha1-u+Z0BseaqFxc/sdm/lc0VV36EnQ=" + }, + "pend": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/pend/-/pend-1.2.0.tgz", + "integrity": "sha1-elfrVQpng/kRUzH89GY9XI4AelA=" + }, + "penthouse": { + "version": "0.11.3", + "resolved": "https://registry.npmjs.org/penthouse/-/penthouse-0.11.3.tgz", + "integrity": "sha1-XxyUB2toau7L01x8Fzpfer+WuA8=" + }, + "phantomjs-prebuilt": { + "version": "2.1.14", + "resolved": "https://registry.npmjs.org/phantomjs-prebuilt/-/phantomjs-prebuilt-2.1.14.tgz", + "integrity": "sha1-1T0xH8+30dCN2yQBRVjxGIxRbaA=" + }, + "pinkie": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/pinkie/-/pinkie-2.0.4.tgz", + "integrity": "sha1-clVrgM+g1IqXToDnckjoDtT3+HA=" + }, + "pinkie-promise": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/pinkie-promise/-/pinkie-promise-2.0.1.tgz", + "integrity": "sha1-ITXW36ejWMBprJsXh3YogihFD/o=" + }, + "process-nextick-args": { + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-1.0.7.tgz", + "integrity": "sha1-FQ4gt1ZZCtP5EJPyWk8q2L/zC6M=" + }, + "progress": { + "version": "1.1.8", + "resolved": "https://registry.npmjs.org/progress/-/progress-1.1.8.tgz", + "integrity": "sha1-4mDHj2Fhzdmw5WzD4Khd4Xx6V74=" + }, + "punycode": { + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/punycode/-/punycode-1.4.1.tgz", + "integrity": "sha1-wNWmOycYgArY4esPpSachN1BhF4=" + }, + "qs": { + "version": "6.3.2", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.3.2.tgz", + "integrity": "sha1-51vV9uJoEioqDgvaYwslUMFmUCw=" + }, + "readable-stream": { + "version": "2.0.6", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.0.6.tgz", + "integrity": "sha1-j5A0HmilPMySh4jaz80Rs265t44=" + }, + "regenerator-runtime": { + "version": "0.10.5", + "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.10.5.tgz", + "integrity": "sha1-M2w+/BIgrc7dosn6tntaeVWjNlg=" + }, + "request": { + "version": "2.79.0", + "resolved": "https://registry.npmjs.org/request/-/request-2.79.0.tgz", + "integrity": "sha1-Tf5b9r6LjNw3/Pk+BLZVd3InEN4=" + }, + "request-progress": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/request-progress/-/request-progress-2.0.1.tgz", + "integrity": "sha1-XTa7V5YcZzqlt4jbyBQf3yO0Tgg=" + }, + "resolve-url": { + "version": "0.2.1", + "resolved": "https://registry.npmjs.org/resolve-url/-/resolve-url-0.2.1.tgz", + "integrity": "sha1-LGN/53yJOv0qZj/iGqkIAGjiBSo=" + }, + "sntp": { + "version": "1.0.9", + "resolved": "https://registry.npmjs.org/sntp/-/sntp-1.0.9.tgz", + "integrity": "sha1-ZUEYTMkK7qbG57NeJlkIJEPGYZg=" + }, + "source-map": { + "version": "0.1.43", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.1.43.tgz", + "integrity": "sha1-wkvBRspRfBRx9drL4lcbK3+eM0Y=" + }, + "source-map-resolve": { + "version": "0.3.1", + "resolved": "https://registry.npmjs.org/source-map-resolve/-/source-map-resolve-0.3.1.tgz", + "integrity": "sha1-YQ9hIqRFuN1RU1oqcbeD38Ekh2E=" + }, + "source-map-url": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/source-map-url/-/source-map-url-0.3.0.tgz", + "integrity": "sha1-fsrxO1e80J2opAxdJp2zN5nUqvk=" + }, + "sshpk": { + "version": "1.13.0", + "resolved": "https://registry.npmjs.org/sshpk/-/sshpk-1.13.0.tgz", + "integrity": "sha1-/yo+T9BEl1Vf7Zezmg/YL6+zozw=", + "dependencies": { + "assert-plus": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/assert-plus/-/assert-plus-1.0.0.tgz", + "integrity": "sha1-8S4PPF13sLHN2RRpQuTpbB5N1SU=" + } + } + }, + "string_decoder": { + "version": "0.10.31", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz", + "integrity": "sha1-YuIDvEF2bGwoyfyEMB2rHFMQ+pQ=" + }, + "stringstream": { + "version": "0.0.5", + "resolved": "https://registry.npmjs.org/stringstream/-/stringstream-0.0.5.tgz", + "integrity": "sha1-TkhM1N5aC7vuGORjB3EKioFiGHg=" + }, + "strip-ansi": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz", + "integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=" + }, + "supports-color": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-2.0.0.tgz", + "integrity": "sha1-U10EXOa2Nj+kARcIRimZXp3zJMc=" + }, + "throttleit": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/throttleit/-/throttleit-1.0.0.tgz", + "integrity": "sha1-nnhYNtr0Z0MUWlmEtiaNgoUorGw=" + }, + "tmp": { + "version": "0.0.31", + "resolved": "https://registry.npmjs.org/tmp/-/tmp-0.0.31.tgz", + "integrity": "sha1-jzirlDjhcxXl29izZX6L+yd65Kc=" + }, + "tough-cookie": { + "version": "2.3.2", + "resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-2.3.2.tgz", + "integrity": "sha1-8IH3bkyFcg5sN6X6ztc3FQ2EByo=" + }, + "tunnel-agent": { + "version": "0.4.3", + "resolved": "https://registry.npmjs.org/tunnel-agent/-/tunnel-agent-0.4.3.tgz", + "integrity": "sha1-Y3PbdpCf5XDgjXNYM2Xtgop07us=" + }, + "tweetnacl": { + "version": "0.14.5", + "resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-0.14.5.tgz", + "integrity": "sha1-WuaBd/GS1EViadEIr6k/+HQ/T2Q=", + "optional": true + }, + "typedarray": { + "version": "0.0.6", + "resolved": "https://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz", + "integrity": "sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=" + }, + "urix": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/urix/-/urix-0.1.0.tgz", + "integrity": "sha1-2pN/emLiH+wf0Y1Js1wpNQZ6bHI=" + }, + "util-deprecate": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", + "integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=" + }, + "uuid": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-3.0.1.tgz", + "integrity": "sha1-ZUS7ot/ajBzxfmKaOjBeK7H+5sE=" + }, + "verror": { + "version": "1.3.6", + "resolved": "https://registry.npmjs.org/verror/-/verror-1.3.6.tgz", + "integrity": "sha1-z/XfEpRtKX0rqu+qJoniW+AcAFw=" + }, + "which": { + "version": "1.2.14", + "resolved": "https://registry.npmjs.org/which/-/which-1.2.14.tgz", + "integrity": "sha1-mofEN48D6CfOyvGs31bHNsAcFOU=" + }, + "xtend": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.1.tgz", + "integrity": "sha1-pcbVMr5lbiPbgg77lDofBJmNY68=" + }, + "yauzl": { + "version": "2.4.1", + "resolved": "https://registry.npmjs.org/yauzl/-/yauzl-2.4.1.tgz", + "integrity": "sha1-lSj0QtqxsihOWLQ3m7GU4i4MQAU=" + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..266a315 --- /dev/null +++ b/package.json @@ -0,0 +1,13 @@ +{ + "name": "critical-path-css-rails", + "version": "1.0.0", + "description": "NPM dependencies of critical-path-css-rails", + "private": true, + "directories": { + "lib": "lib" + }, + "dependencies": { + "penthouse": "=0.11.3" + }, + "license": "MIT" +} diff --git a/spec/css_fetcher_spec.rb b/spec/css_fetcher_spec.rb new file mode 100644 index 0000000..0475c9a --- /dev/null +++ b/spec/css_fetcher_spec.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe 'CssFetcher' do + before :all do + StaticFileServer.start + end + + after :all do + StaticFileServer.stop + end + + it 'fetches css' do + config = CriticalPathCss::Configuration.new( + 'base_url' => StaticFileServer.url, + 'css_path' => 'spec/fixtures/static/test.css', + 'routes' => ['/test.html'] + ) + fetcher = CriticalPathCss::CssFetcher.new(config) + expect(fetcher.fetch).to( + eq('/test.html' => "p {\n color: red;\n}\n") + ) + end +end diff --git a/spec/fixtures/static/test.css b/spec/fixtures/static/test.css new file mode 100644 index 0000000..3d9a2b2 --- /dev/null +++ b/spec/fixtures/static/test.css @@ -0,0 +1,3 @@ +p { + color: red; +} diff --git a/spec/fixtures/static/test.html b/spec/fixtures/static/test.html new file mode 100644 index 0000000..a16a45d --- /dev/null +++ b/spec/fixtures/static/test.html @@ -0,0 +1,7 @@ + + + + + +

Hello world

+ diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..7b07287 --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +require 'bundler/setup' +require 'critical-path-css-rails' + +require 'support/static_file_server' + +RSpec.configure do |config| + # Enable flags like --only-failures and --next-failure + config.example_status_persistence_file_path = '.rspec_status' + + # Disable RSpec exposing methods globally on `Module` and `main` + config.disable_monkey_patching! + + config.expect_with :rspec do |c| + c.syntax = :expect + end +end diff --git a/spec/support/static_file_server.rb b/spec/support/static_file_server.rb new file mode 100644 index 0000000..345baa9 --- /dev/null +++ b/spec/support/static_file_server.rb @@ -0,0 +1,45 @@ +require 'socket' + +module StaticFileServer + class << self + def start # rubocop:disable Metrics/MethodLength,Metrics/AbcSize + @port = get_free_port + rd, wt = IO.pipe + @pid = fork do + require 'webrick' + rd.close + server = WEBrick::HTTPServer.new( + DocumentRoot: File.expand_path('spec/fixtures/static'), + Port: @port, + BindAddress: '127.0.0.1', + StartCallback: lambda do + # write "1", signal a server start message + wt.write(1) + wt.close + end + ) + trap('INT') { server.shutdown } + server.start + end + wt.close + # read a byte for the server start signal + rd.read(1) + rd.close + end + + def stop + Process.kill('INT', @pid) + end + + def url + "http://localhost:#{@port}" + end + + def get_free_port + server = TCPServer.new('127.0.0.1', 0) + port = server.addr[1] + server.close + port + end + end +end From 5a627d8a07ec4d2ba3e1678b85c815b90e27f5bf Mon Sep 17 00:00:00 2001 From: Michael Misshore Date: Wed, 2 Aug 2017 09:50:40 -0500 Subject: [PATCH 13/81] Fix namespacing --- lib/critical-path-css-rails.rb | 10 +++++----- lib/critical_path_css/rails/config_loader.rb | 8 ++++---- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/critical-path-css-rails.rb b/lib/critical-path-css-rails.rb index 78150b3..f4c431f 100644 --- a/lib/critical-path-css-rails.rb +++ b/lib/critical-path-css-rails.rb @@ -6,7 +6,7 @@ module CriticalPathCss CACHE_NAMESPACE = 'critical-path-css' def self.generate(route) - Rails.cache.write( + ::Rails.cache.write( route, CssFetcher.new(config).fetch_route(route), namespace: CACHE_NAMESPACE, @@ -16,20 +16,20 @@ def self.generate(route) def self.generate_all CssFetcher.new(config).fetch.each do |route, css| - Rails.cache.write(route, css, namespace: CACHE_NAMESPACE, expires_in: nil) + ::Rails.cache.write(route, css, namespace: CACHE_NAMESPACE, expires_in: nil) end end def self.clear(route) - Rails.cache.delete(route, namespace: CACHE_NAMESPACE) + ::Rails.cache.delete(route, namespace: CACHE_NAMESPACE) end def self.clear_matched(routes) - Rails.cache.delete_matched(routes, namespace: CACHE_NAMESPACE) + ::Rails.cache.delete_matched(routes, namespace: CACHE_NAMESPACE) end def self.fetch(route) - Rails.cache.read(route, namespace: CACHE_NAMESPACE) || '' + ::Rails.cache.read(route, namespace: CACHE_NAMESPACE) || '' end def self.config diff --git a/lib/critical_path_css/rails/config_loader.rb b/lib/critical_path_css/rails/config_loader.rb index 887ef2e..c9a6add 100644 --- a/lib/critical_path_css/rails/config_loader.rb +++ b/lib/critical_path_css/rails/config_loader.rb @@ -1,11 +1,11 @@ module CriticalPathCss module Rails - module ConfigLoader + class ConfigLoader CONFIGURATION_FILENAME = 'critical_path_css.yml' def load - config = YAML.load(ERB.new(File.read(configuration_file_path)).result)[Rails.env] - config['css_path'] = "#{Rails.root}/public" + ( + config = YAML.load(ERB.new(File.read(configuration_file_path)).result)[::Rails.env] + config['css_path'] = "#{::Rails.root}/public" + ( config['css_path'] || ActionController::Base.helpers.stylesheet_path( config['manifest_name'], host: '' @@ -17,7 +17,7 @@ def load private def configuration_file_path - @configuration_file_path ||= Rails.root.join('config', CONFIGURATION_FILENAME) + @configuration_file_path ||= ::Rails.root.join('config', CONFIGURATION_FILENAME) end end end From abf24e1f94199e32910466081ee55d605bca9586 Mon Sep 17 00:00:00 2001 From: Michael Misshore Date: Wed, 2 Aug 2017 09:51:09 -0500 Subject: [PATCH 14/81] Ignore NPM debug log --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 1df918d..dde38a7 100644 --- a/.gitignore +++ b/.gitignore @@ -19,3 +19,4 @@ tmp .DS_Store /node_modules/ .rspec_status +/npm-debug.log From 13883df25e4411f39ebb366339fc0430ba0bc0e7 Mon Sep 17 00:00:00 2001 From: Michael Misshore Date: Wed, 2 Aug 2017 09:56:43 -0500 Subject: [PATCH 15/81] Update penthouse to 0.11.5 --- package-lock.json | 347 +++++++++++++++++++++++++++++++++++----------- package.json | 2 +- 2 files changed, 268 insertions(+), 81 deletions(-) diff --git a/package-lock.json b/package-lock.json index f2a0244..93145c6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2,6 +2,7 @@ "name": "critical-path-css-rails", "version": "1.0.0", "lockfileVersion": 1, + "requires": true, "dependencies": { "amdefine": { "version": "1.0.1", @@ -21,7 +22,13 @@ "apartment": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/apartment/-/apartment-1.1.1.tgz", - "integrity": "sha1-/ZQGzcyodTWULxWzYKGrWkqpfiY=" + "integrity": "sha1-/ZQGzcyodTWULxWzYKGrWkqpfiY=", + "requires": { + "css": "git+https://github.com/pocketjoso/css.git#8ddea7e3cbc0a183ecf694a7a5fbc84326893893", + "get-stdin": "5.0.1", + "lodash": "3.10.1", + "minimist": "1.2.0" + } }, "asn1": { "version": "0.2.3", @@ -53,26 +60,22 @@ "resolved": "https://registry.npmjs.org/aws4/-/aws4-1.6.0.tgz", "integrity": "sha1-g+9cqGCysy5KDe7e6MdxudtXRx4=" }, - "babel-polyfill": { - "version": "6.23.0", - "resolved": "https://registry.npmjs.org/babel-polyfill/-/babel-polyfill-6.23.0.tgz", - "integrity": "sha1-g2TKYt+Or7gwSZ9pkXdGbDsDSZ0=" - }, - "babel-runtime": { - "version": "6.23.0", - "resolved": "https://registry.npmjs.org/babel-runtime/-/babel-runtime-6.23.0.tgz", - "integrity": "sha1-CpSJ8UTecO+zzkMArM2zKeL8VDs=" - }, "bcrypt-pbkdf": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/bcrypt-pbkdf/-/bcrypt-pbkdf-1.0.1.tgz", "integrity": "sha1-Y7xdy2EzG5K8Bf1SiVPDNGKgb40=", - "optional": true + "optional": true, + "requires": { + "tweetnacl": "0.14.5" + } }, "boom": { "version": "2.10.1", "resolved": "https://registry.npmjs.org/boom/-/boom-2.10.1.tgz", - "integrity": "sha1-OciRjO/1eZ+D+UkqhI9iWt0Mdm8=" + "integrity": "sha1-OciRjO/1eZ+D+UkqhI9iWt0Mdm8=", + "requires": { + "hoek": "2.16.3" + } }, "caseless": { "version": "0.11.0", @@ -82,27 +85,37 @@ "chalk": { "version": "1.1.3", "resolved": "https://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz", - "integrity": "sha1-qBFcVeSnAv5NFQq9OHKCKn4J/Jg=" + "integrity": "sha1-qBFcVeSnAv5NFQq9OHKCKn4J/Jg=", + "requires": { + "ansi-styles": "2.2.1", + "escape-string-regexp": "1.0.5", + "has-ansi": "2.0.0", + "strip-ansi": "3.0.1", + "supports-color": "2.0.0" + } }, "combined-stream": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.5.tgz", - "integrity": "sha1-k4NwpXtKUd6ix3wV1cX9+JUWQAk=" + "integrity": "sha1-k4NwpXtKUd6ix3wV1cX9+JUWQAk=", + "requires": { + "delayed-stream": "1.0.0" + } }, "commander": { - "version": "2.9.0", - "resolved": "https://registry.npmjs.org/commander/-/commander-2.9.0.tgz", - "integrity": "sha1-nJkJQXbhIkDLItbFFGCYQA/g99Q=" + "version": "2.11.0", + "resolved": "https://registry.npmjs.org/commander/-/commander-2.11.0.tgz", + "integrity": "sha512-b0553uYA5YAEGgyYIGYROzKQ7X5RAqedkfjiZxwi0kL1g3bOaBNNZfYkzt/CL0umgD5wc9Jec2FbB98CjkMRvQ==" }, "concat-stream": { "version": "1.5.0", "resolved": "https://registry.npmjs.org/concat-stream/-/concat-stream-1.5.0.tgz", - "integrity": "sha1-U/fUPFHF5D+ByP3QMyHGMb5o1hE=" - }, - "core-js": { - "version": "2.4.1", - "resolved": "https://registry.npmjs.org/core-js/-/core-js-2.4.1.tgz", - "integrity": "sha1-TekR5mew6ukSTjQlS1OupvxhjT4=" + "integrity": "sha1-U/fUPFHF5D+ByP3QMyHGMb5o1hE=", + "requires": { + "inherits": "2.0.3", + "readable-stream": "2.0.6", + "typedarray": "0.0.6" + } }, "core-util-is": { "version": "1.0.2", @@ -112,10 +125,19 @@ "cryptiles": { "version": "2.0.5", "resolved": "https://registry.npmjs.org/cryptiles/-/cryptiles-2.0.5.tgz", - "integrity": "sha1-O9/s3GCBR8HGcgL6KR59ylnqo7g=" + "integrity": "sha1-O9/s3GCBR8HGcgL6KR59ylnqo7g=", + "requires": { + "boom": "2.10.1" + } }, "css": { - "version": "git+https://github.com/pocketjoso/css.git#8ddea7e3cbc0a183ecf694a7a5fbc84326893893" + "version": "git+https://github.com/pocketjoso/css.git#8ddea7e3cbc0a183ecf694a7a5fbc84326893893", + "requires": { + "inherits": "2.0.3", + "source-map": "0.1.43", + "source-map-resolve": "0.3.1", + "urix": "0.1.0" + } }, "css-mediaquery": { "version": "0.1.2", @@ -126,6 +148,9 @@ "version": "1.14.1", "resolved": "https://registry.npmjs.org/dashdash/-/dashdash-1.14.1.tgz", "integrity": "sha1-hTz6D3y+L+1d4gMmuN1YEDX24vA=", + "requires": { + "assert-plus": "1.0.0" + }, "dependencies": { "assert-plus": { "version": "1.0.0", @@ -148,7 +173,10 @@ "version": "0.1.1", "resolved": "https://registry.npmjs.org/ecc-jsbn/-/ecc-jsbn-0.1.1.tgz", "integrity": "sha1-D8c6ntXw1Tw4GTOYUj735UN3dQU=", - "optional": true + "optional": true, + "requires": { + "jsbn": "0.1.1" + } }, "es6-promise": { "version": "4.0.5", @@ -168,7 +196,13 @@ "extract-zip": { "version": "1.5.0", "resolved": "https://registry.npmjs.org/extract-zip/-/extract-zip-1.5.0.tgz", - "integrity": "sha1-ksz22B73Cp+kwXRxFMzvbYaIpsQ=" + "integrity": "sha1-ksz22B73Cp+kwXRxFMzvbYaIpsQ=", + "requires": { + "concat-stream": "1.5.0", + "debug": "0.7.4", + "mkdirp": "0.5.0", + "yauzl": "2.4.1" + } }, "extsprintf": { "version": "1.0.2", @@ -178,7 +212,10 @@ "fd-slicer": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/fd-slicer/-/fd-slicer-1.0.1.tgz", - "integrity": "sha1-i1vL2ewyfFBBv5qwI/1nUPEXfmU=" + "integrity": "sha1-i1vL2ewyfFBBv5qwI/1nUPEXfmU=", + "requires": { + "pend": "1.2.0" + } }, "forever-agent": { "version": "0.6.1", @@ -188,12 +225,22 @@ "form-data": { "version": "2.1.4", "resolved": "https://registry.npmjs.org/form-data/-/form-data-2.1.4.tgz", - "integrity": "sha1-M8GDrPGTJ27KqYFDpp6Uv+4XUNE=" + "integrity": "sha1-M8GDrPGTJ27KqYFDpp6Uv+4XUNE=", + "requires": { + "asynckit": "0.4.0", + "combined-stream": "1.0.5", + "mime-types": "2.1.16" + } }, "fs-extra": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-1.0.0.tgz", - "integrity": "sha1-zTzl9+fLYUWIP8rjGR6Yd/hYeVA=" + "integrity": "sha1-zTzl9+fLYUWIP8rjGR6Yd/hYeVA=", + "requires": { + "graceful-fs": "4.1.11", + "jsonfile": "2.4.0", + "klaw": "1.3.1" + } }, "generate-function": { "version": "2.0.0", @@ -203,7 +250,10 @@ "generate-object-property": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/generate-object-property/-/generate-object-property-1.2.0.tgz", - "integrity": "sha1-nA4cQDCM6AT0eDYYuTf6iPmdUNA=" + "integrity": "sha1-nA4cQDCM6AT0eDYYuTf6iPmdUNA=", + "requires": { + "is-property": "1.0.2" + } }, "get-stdin": { "version": "5.0.1", @@ -214,6 +264,9 @@ "version": "0.1.7", "resolved": "https://registry.npmjs.org/getpass/-/getpass-0.1.7.tgz", "integrity": "sha1-Xv+OPmhNVprkyysSgmBOi6YhSfo=", + "requires": { + "assert-plus": "1.0.0" + }, "dependencies": { "assert-plus": { "version": "1.0.0", @@ -227,30 +280,44 @@ "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.1.11.tgz", "integrity": "sha1-Dovf5NHduIVNZOBOp8AOKgJuVlg=" }, - "graceful-readlink": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/graceful-readlink/-/graceful-readlink-1.0.1.tgz", - "integrity": "sha1-TK+tdrxi8C+gObL5Tpo906ORpyU=" - }, "har-validator": { "version": "2.0.6", "resolved": "https://registry.npmjs.org/har-validator/-/har-validator-2.0.6.tgz", - "integrity": "sha1-zcvAgYgmWtEZtqWnyKtw7s+10n0=" + "integrity": "sha1-zcvAgYgmWtEZtqWnyKtw7s+10n0=", + "requires": { + "chalk": "1.1.3", + "commander": "2.11.0", + "is-my-json-valid": "2.16.0", + "pinkie-promise": "2.0.1" + } }, "has-ansi": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/has-ansi/-/has-ansi-2.0.0.tgz", - "integrity": "sha1-NPUEnOHs3ysGSa8+8k5F7TVBbZE=" + "integrity": "sha1-NPUEnOHs3ysGSa8+8k5F7TVBbZE=", + "requires": { + "ansi-regex": "2.1.1" + } }, "hasha": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/hasha/-/hasha-2.2.0.tgz", - "integrity": "sha1-eNfL/B5tZjA/55g3NlmEUXsvbuE=" + "integrity": "sha1-eNfL/B5tZjA/55g3NlmEUXsvbuE=", + "requires": { + "is-stream": "1.1.0", + "pinkie-promise": "2.0.1" + } }, "hawk": { "version": "3.1.3", "resolved": "https://registry.npmjs.org/hawk/-/hawk-3.1.3.tgz", - "integrity": "sha1-B4REvXwWQLD+VA0sm3PVlnjo4cQ=" + "integrity": "sha1-B4REvXwWQLD+VA0sm3PVlnjo4cQ=", + "requires": { + "boom": "2.10.1", + "cryptiles": "2.0.5", + "hoek": "2.16.3", + "sntp": "1.0.9" + } }, "hoek": { "version": "2.16.3", @@ -260,7 +327,12 @@ "http-signature": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/http-signature/-/http-signature-1.1.1.tgz", - "integrity": "sha1-33LiZwZs0Kxn+3at+OE0qPvPkb8=" + "integrity": "sha1-33LiZwZs0Kxn+3at+OE0qPvPkb8=", + "requires": { + "assert-plus": "0.2.0", + "jsprim": "1.4.0", + "sshpk": "1.13.1" + } }, "inherits": { "version": "2.0.3", @@ -270,7 +342,13 @@ "is-my-json-valid": { "version": "2.16.0", "resolved": "https://registry.npmjs.org/is-my-json-valid/-/is-my-json-valid-2.16.0.tgz", - "integrity": "sha1-8Hndm/2uZe4gOKrorLyGqxCeNpM=" + "integrity": "sha1-8Hndm/2uZe4gOKrorLyGqxCeNpM=", + "requires": { + "generate-function": "2.0.0", + "generate-object-property": "1.2.0", + "jsonpointer": "4.0.1", + "xtend": "4.0.1" + } }, "is-property": { "version": "1.0.2", @@ -302,12 +380,6 @@ "resolved": "https://registry.npmjs.org/isstream/-/isstream-0.1.2.tgz", "integrity": "sha1-R+Y/evVa+m+S4VAOaQ64uFKcCZo=" }, - "jodid25519": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/jodid25519/-/jodid25519-1.0.2.tgz", - "integrity": "sha1-BtSRIlUJNBlHfUJWM2BuDpB4KWc=", - "optional": true - }, "jsbn": { "version": "0.1.1", "resolved": "https://registry.npmjs.org/jsbn/-/jsbn-0.1.1.tgz", @@ -332,7 +404,10 @@ "jsonfile": { "version": "2.4.0", "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-2.4.0.tgz", - "integrity": "sha1-NzaitCi4e72gzIO1P6PWM6NcKug=" + "integrity": "sha1-NzaitCi4e72gzIO1P6PWM6NcKug=", + "requires": { + "graceful-fs": "4.1.11" + } }, "jsonpointer": { "version": "4.0.1", @@ -343,6 +418,12 @@ "version": "1.4.0", "resolved": "https://registry.npmjs.org/jsprim/-/jsprim-1.4.0.tgz", "integrity": "sha1-o7h+QCmNjDgFUtjMdiigu5WiKRg=", + "requires": { + "assert-plus": "1.0.0", + "extsprintf": "1.0.2", + "json-schema": "0.2.3", + "verror": "1.3.6" + }, "dependencies": { "assert-plus": { "version": "1.0.0", @@ -359,7 +440,10 @@ "klaw": { "version": "1.3.1", "resolved": "https://registry.npmjs.org/klaw/-/klaw-1.3.1.tgz", - "integrity": "sha1-QIhDO0azsbolnXh4XY6W9zugJDk=" + "integrity": "sha1-QIhDO0azsbolnXh4XY6W9zugJDk=", + "requires": { + "graceful-fs": "4.1.11" + } }, "lodash": { "version": "3.10.1", @@ -367,14 +451,17 @@ "integrity": "sha1-W/Rejkm6QYnhfUgnid/RW9FAt7Y=" }, "mime-db": { - "version": "1.27.0", - "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.27.0.tgz", - "integrity": "sha1-gg9XIpa70g7CXtVeW13oaeVDbrE=" + "version": "1.29.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.29.0.tgz", + "integrity": "sha1-SNJtI1WJZRcErFkWygYAGRQmaHg=" }, "mime-types": { - "version": "2.1.15", - "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.15.tgz", - "integrity": "sha1-pOv1BkCUVpI3uM9wBGd20J/JKu0=" + "version": "2.1.16", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.16.tgz", + "integrity": "sha1-K4WKUuXs1RbbiXrCvodIeDBpjiM=", + "requires": { + "mime-db": "1.29.0" + } }, "minimist": { "version": "1.2.0", @@ -385,6 +472,9 @@ "version": "0.5.0", "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.0.tgz", "integrity": "sha1-HXMHam35hs2TROFecfzAWkyavxI=", + "requires": { + "minimist": "0.0.8" + }, "dependencies": { "minimist": { "version": "0.0.8", @@ -409,14 +499,35 @@ "integrity": "sha1-elfrVQpng/kRUzH89GY9XI4AelA=" }, "penthouse": { - "version": "0.11.3", - "resolved": "https://registry.npmjs.org/penthouse/-/penthouse-0.11.3.tgz", - "integrity": "sha1-XxyUB2toau7L01x8Fzpfer+WuA8=" + "version": "0.11.5", + "resolved": "https://registry.npmjs.org/penthouse/-/penthouse-0.11.5.tgz", + "integrity": "sha1-/+y0LwrsYkhYWC8nLqLcIYGHyVI=", + "requires": { + "apartment": "1.1.1", + "css": "git+https://github.com/pocketjoso/css.git#8ddea7e3cbc0a183ecf694a7a5fbc84326893893", + "css-mediaquery": "0.1.2", + "jsesc": "1.3.0", + "os-tmpdir": "1.0.2", + "phantomjs-prebuilt": "2.1.14", + "regenerator-runtime": "0.10.5", + "tmp": "0.0.31" + } }, "phantomjs-prebuilt": { "version": "2.1.14", "resolved": "https://registry.npmjs.org/phantomjs-prebuilt/-/phantomjs-prebuilt-2.1.14.tgz", - "integrity": "sha1-1T0xH8+30dCN2yQBRVjxGIxRbaA=" + "integrity": "sha1-1T0xH8+30dCN2yQBRVjxGIxRbaA=", + "requires": { + "es6-promise": "4.0.5", + "extract-zip": "1.5.0", + "fs-extra": "1.0.0", + "hasha": "2.2.0", + "kew": "0.7.0", + "progress": "1.1.8", + "request": "2.79.0", + "request-progress": "2.0.1", + "which": "1.2.14" + } }, "pinkie": { "version": "2.0.4", @@ -426,7 +537,10 @@ "pinkie-promise": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/pinkie-promise/-/pinkie-promise-2.0.1.tgz", - "integrity": "sha1-ITXW36ejWMBprJsXh3YogihFD/o=" + "integrity": "sha1-ITXW36ejWMBprJsXh3YogihFD/o=", + "requires": { + "pinkie": "2.0.4" + } }, "process-nextick-args": { "version": "1.0.7", @@ -451,7 +565,15 @@ "readable-stream": { "version": "2.0.6", "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.0.6.tgz", - "integrity": "sha1-j5A0HmilPMySh4jaz80Rs265t44=" + "integrity": "sha1-j5A0HmilPMySh4jaz80Rs265t44=", + "requires": { + "core-util-is": "1.0.2", + "inherits": "2.0.3", + "isarray": "1.0.0", + "process-nextick-args": "1.0.7", + "string_decoder": "0.10.31", + "util-deprecate": "1.0.2" + } }, "regenerator-runtime": { "version": "0.10.5", @@ -461,12 +583,37 @@ "request": { "version": "2.79.0", "resolved": "https://registry.npmjs.org/request/-/request-2.79.0.tgz", - "integrity": "sha1-Tf5b9r6LjNw3/Pk+BLZVd3InEN4=" + "integrity": "sha1-Tf5b9r6LjNw3/Pk+BLZVd3InEN4=", + "requires": { + "aws-sign2": "0.6.0", + "aws4": "1.6.0", + "caseless": "0.11.0", + "combined-stream": "1.0.5", + "extend": "3.0.1", + "forever-agent": "0.6.1", + "form-data": "2.1.4", + "har-validator": "2.0.6", + "hawk": "3.1.3", + "http-signature": "1.1.1", + "is-typedarray": "1.0.0", + "isstream": "0.1.2", + "json-stringify-safe": "5.0.1", + "mime-types": "2.1.16", + "oauth-sign": "0.8.2", + "qs": "6.3.2", + "stringstream": "0.0.5", + "tough-cookie": "2.3.2", + "tunnel-agent": "0.4.3", + "uuid": "3.1.0" + } }, "request-progress": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/request-progress/-/request-progress-2.0.1.tgz", - "integrity": "sha1-XTa7V5YcZzqlt4jbyBQf3yO0Tgg=" + "integrity": "sha1-XTa7V5YcZzqlt4jbyBQf3yO0Tgg=", + "requires": { + "throttleit": "1.0.0" + } }, "resolve-url": { "version": "0.2.1", @@ -476,17 +623,29 @@ "sntp": { "version": "1.0.9", "resolved": "https://registry.npmjs.org/sntp/-/sntp-1.0.9.tgz", - "integrity": "sha1-ZUEYTMkK7qbG57NeJlkIJEPGYZg=" + "integrity": "sha1-ZUEYTMkK7qbG57NeJlkIJEPGYZg=", + "requires": { + "hoek": "2.16.3" + } }, "source-map": { "version": "0.1.43", "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.1.43.tgz", - "integrity": "sha1-wkvBRspRfBRx9drL4lcbK3+eM0Y=" + "integrity": "sha1-wkvBRspRfBRx9drL4lcbK3+eM0Y=", + "requires": { + "amdefine": "1.0.1" + } }, "source-map-resolve": { "version": "0.3.1", "resolved": "https://registry.npmjs.org/source-map-resolve/-/source-map-resolve-0.3.1.tgz", - "integrity": "sha1-YQ9hIqRFuN1RU1oqcbeD38Ekh2E=" + "integrity": "sha1-YQ9hIqRFuN1RU1oqcbeD38Ekh2E=", + "requires": { + "atob": "1.1.3", + "resolve-url": "0.2.1", + "source-map-url": "0.3.0", + "urix": "0.1.0" + } }, "source-map-url": { "version": "0.3.0", @@ -494,9 +653,19 @@ "integrity": "sha1-fsrxO1e80J2opAxdJp2zN5nUqvk=" }, "sshpk": { - "version": "1.13.0", - "resolved": "https://registry.npmjs.org/sshpk/-/sshpk-1.13.0.tgz", - "integrity": "sha1-/yo+T9BEl1Vf7Zezmg/YL6+zozw=", + "version": "1.13.1", + "resolved": "https://registry.npmjs.org/sshpk/-/sshpk-1.13.1.tgz", + "integrity": "sha1-US322mKHFEMW3EwY/hzx2UBzm+M=", + "requires": { + "asn1": "0.2.3", + "assert-plus": "1.0.0", + "bcrypt-pbkdf": "1.0.1", + "dashdash": "1.14.1", + "ecc-jsbn": "0.1.1", + "getpass": "0.1.7", + "jsbn": "0.1.1", + "tweetnacl": "0.14.5" + }, "dependencies": { "assert-plus": { "version": "1.0.0", @@ -518,7 +687,10 @@ "strip-ansi": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz", - "integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=" + "integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=", + "requires": { + "ansi-regex": "2.1.1" + } }, "supports-color": { "version": "2.0.0", @@ -533,12 +705,18 @@ "tmp": { "version": "0.0.31", "resolved": "https://registry.npmjs.org/tmp/-/tmp-0.0.31.tgz", - "integrity": "sha1-jzirlDjhcxXl29izZX6L+yd65Kc=" + "integrity": "sha1-jzirlDjhcxXl29izZX6L+yd65Kc=", + "requires": { + "os-tmpdir": "1.0.2" + } }, "tough-cookie": { "version": "2.3.2", "resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-2.3.2.tgz", - "integrity": "sha1-8IH3bkyFcg5sN6X6ztc3FQ2EByo=" + "integrity": "sha1-8IH3bkyFcg5sN6X6ztc3FQ2EByo=", + "requires": { + "punycode": "1.4.1" + } }, "tunnel-agent": { "version": "0.4.3", @@ -567,19 +745,25 @@ "integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=" }, "uuid": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/uuid/-/uuid-3.0.1.tgz", - "integrity": "sha1-ZUS7ot/ajBzxfmKaOjBeK7H+5sE=" + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-3.1.0.tgz", + "integrity": "sha512-DIWtzUkw04M4k3bf1IcpS2tngXEL26YUD2M0tMDUpnUrz2hgzUBlD55a4FjdLGPvfHxS6uluGWvaVEqgBcVa+g==" }, "verror": { "version": "1.3.6", "resolved": "https://registry.npmjs.org/verror/-/verror-1.3.6.tgz", - "integrity": "sha1-z/XfEpRtKX0rqu+qJoniW+AcAFw=" + "integrity": "sha1-z/XfEpRtKX0rqu+qJoniW+AcAFw=", + "requires": { + "extsprintf": "1.0.2" + } }, "which": { "version": "1.2.14", "resolved": "https://registry.npmjs.org/which/-/which-1.2.14.tgz", - "integrity": "sha1-mofEN48D6CfOyvGs31bHNsAcFOU=" + "integrity": "sha1-mofEN48D6CfOyvGs31bHNsAcFOU=", + "requires": { + "isexe": "2.0.0" + } }, "xtend": { "version": "4.0.1", @@ -589,7 +773,10 @@ "yauzl": { "version": "2.4.1", "resolved": "https://registry.npmjs.org/yauzl/-/yauzl-2.4.1.tgz", - "integrity": "sha1-lSj0QtqxsihOWLQ3m7GU4i4MQAU=" + "integrity": "sha1-lSj0QtqxsihOWLQ3m7GU4i4MQAU=", + "requires": { + "fd-slicer": "1.0.1" + } } } } diff --git a/package.json b/package.json index 266a315..1e13ae2 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "lib": "lib" }, "dependencies": { - "penthouse": "=0.11.3" + "penthouse": "=0.11.5" }, "license": "MIT" } From 90a8e364c14e64a71e4df2f652f6185d52f93b5e Mon Sep 17 00:00:00 2001 From: Michael Misshore Date: Wed, 2 Aug 2017 09:57:15 -0500 Subject: [PATCH 16/81] Update gem to 1.0.0 --- README.md | 10 +++++----- lib/critical_path_css/rails/version.rb | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 183485d..3ddbbdf 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ This gem give you the ability to load only the CSS you *need* on an initial page This gem assumes that you'll load the rest of the CSS asyncronously. At the moment, the suggested way is to use the [loadcss-rails](https://github.com/michael-misshore/loadcss-rails) gem. -This gem uses [PhantomJS](https://github.com/colszowka/phantomjs-gem) and [Penthouse](https://github.com/pocketjoso/penthouse) to generate the critical CSS. +This gem uses [Penthouse](https://github.com/pocketjoso/penthouse) to generate the critical CSS. ## Update @@ -17,7 +17,7 @@ Versions below 0.3.0 are not compatible with this version. Please read the Upgr Add `critical-path-css-rails` to your Gemfile: ``` -gem 'critical-path-css-rails', '~> 0.4.0' +gem 'critical-path-css-rails', '~> 1.0.0' ``` Download and install by running: @@ -128,9 +128,9 @@ Answer 'Y' when prompted to overwrite `critical_path_css.rake`. However, overwr The critical-path-css-rails gem follows these version guidelines: ``` -patch version bump = updates to critical-path-css-rails and patch-level updates to Penthouse and PhantomJS -minor version bump = minor-level updates to critical-path-css-rails, Penthouse, and PhantomJS -major version bump = major-level updates to critical-path-css-rails, Penthouse, PhantomJS, and updates to Rails which may be backwards-incompatible +patch version bump = updates to critical-path-css-rails and patch-level updates to Penthouse +minor version bump = minor-level updates to critical-path-css-rails and Penthouse +major version bump = major-level updates to critical-path-css-rails, Penthouse, and updates to Rails which may be backwards-incompatible ``` ## Contributing diff --git a/lib/critical_path_css/rails/version.rb b/lib/critical_path_css/rails/version.rb index f31dfb1..ec32863 100644 --- a/lib/critical_path_css/rails/version.rb +++ b/lib/critical_path_css/rails/version.rb @@ -1,5 +1,5 @@ module CriticalPathCSS module Rails - VERSION = '0.4.0' + VERSION = '1.0.0' end end From 4a19e8c7bbb5eb6a13015199bafcf6a631013e24 Mon Sep 17 00:00:00 2001 From: Pavel Shushpan Date: Thu, 2 Nov 2017 17:37:04 +0200 Subject: [PATCH 17/81] Moved Rails::Generators::Base from namespace --- lib/generators/critical_path_css/install_generator.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/generators/critical_path_css/install_generator.rb b/lib/generators/critical_path_css/install_generator.rb index b7c221a..0d26f53 100644 --- a/lib/generators/critical_path_css/install_generator.rb +++ b/lib/generators/critical_path_css/install_generator.rb @@ -1,7 +1,7 @@ require 'rails/generators' module CriticalPathCss - class InstallGenerator < Rails::Generators::Base + class InstallGenerator < ::Rails::Generators::Base source_root File.expand_path('..', __FILE__) # Copy the needed rake task for generating critical CSS From 5ac0744b7548457d29eef990601a3947d24f2eb2 Mon Sep 17 00:00:00 2001 From: Michael Misshore Date: Thu, 2 Nov 2017 10:41:45 -0500 Subject: [PATCH 18/81] Add upgrade instructions --- README.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 3ddbbdf..f1a7e58 100644 --- a/README.md +++ b/README.md @@ -8,9 +8,9 @@ This gem assumes that you'll load the rest of the CSS asyncronously. At the mome This gem uses [Penthouse](https://github.com/pocketjoso/penthouse) to generate the critical CSS. -## Update +## Upgrading to the Latest Release -Versions below 0.3.0 are not compatible with this version. Please read the Upgrading from Previous Versions section below for more information. +Upgrade instructions from each version are included below. ## Installation @@ -110,7 +110,10 @@ Careful use of these methods allows the developer to generate critical path CSS A user can use these methods to [dynamically generate critical path CSS](https://gist.github.com/taranda/1597e97ccf24c978b59aef9249666c77) without using the `rake critical_path_css:generate` rake task and without hardcoding the application's routes into `config/critical_path_css.yml`. See [this Gist](https://gist.github.com/taranda/1597e97ccf24c978b59aef9249666c77) for an example of such an implementation. -## Upgrading from Previous Versions +## Upgrading from version 0.X.X to 1.0.0 +To maintain the latest version of Penthouse, this gem now depends on NodeJS and NVM to be installed on the system. + +## Upgrading from a version earlier than 0.3.0 The latest version of Critcal Path CSS Rails changes the functionality of the `generate` method. In past versions, `generate` would produce CSS for all of the routes listed in `config/critical_path_css.yml`. This functionality has been replaced by the `generate_all` method, and `generate` will only produce CSS for one route. From c5e0ebcd41db40d56861809eafeeb5b19a64ee0b Mon Sep 17 00:00:00 2001 From: Michael Misshore Date: Thu, 2 Nov 2017 10:42:19 -0500 Subject: [PATCH 19/81] Update version to 1.0.1 --- lib/critical_path_css/rails/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/critical_path_css/rails/version.rb b/lib/critical_path_css/rails/version.rb index ec32863..885da23 100644 --- a/lib/critical_path_css/rails/version.rb +++ b/lib/critical_path_css/rails/version.rb @@ -1,5 +1,5 @@ module CriticalPathCSS module Rails - VERSION = '1.0.0' + VERSION = '1.0.1' end end From 0bdb0466b85feacdfd3f7dd652ce20721fccc93d Mon Sep 17 00:00:00 2001 From: Michael Misshore Date: Thu, 14 Dec 2017 09:50:43 -0600 Subject: [PATCH 20/81] WIP: Update penthouse to 1.1 --- README.md | 4 ++-- lib/critical_path_css/css_fetcher.rb | 5 ----- lib/critical_path_css/rails/version.rb | 2 +- package.json | 4 ++-- 4 files changed, 5 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index f1a7e58..0e456b4 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ Upgrade instructions from each version are included below. Add `critical-path-css-rails` to your Gemfile: ``` -gem 'critical-path-css-rails', '~> 1.0.0' +gem 'critical-path-css-rails', '~> 2.0.0' ``` Download and install by running: @@ -110,7 +110,7 @@ Careful use of these methods allows the developer to generate critical path CSS A user can use these methods to [dynamically generate critical path CSS](https://gist.github.com/taranda/1597e97ccf24c978b59aef9249666c77) without using the `rake critical_path_css:generate` rake task and without hardcoding the application's routes into `config/critical_path_css.yml`. See [this Gist](https://gist.github.com/taranda/1597e97ccf24c978b59aef9249666c77) for an example of such an implementation. -## Upgrading from version 0.X.X to 1.0.0 +## Upgrading from version 0.X.X to 1.0.0 or later To maintain the latest version of Penthouse, this gem now depends on NodeJS and NVM to be installed on the system. ## Upgrading from a version earlier than 0.3.0 diff --git a/lib/critical_path_css/css_fetcher.rb b/lib/critical_path_css/css_fetcher.rb index bda7314..894cf2a 100644 --- a/lib/critical_path_css/css_fetcher.rb +++ b/lib/critical_path_css/css_fetcher.rb @@ -44,11 +44,6 @@ def css_for_route(route) 'renderWaitTime' => 100, # set to false to load (external) JS (default: true) 'blockJSRequests' => true, - # see `phantomjs --help` for the list of all available options - 'phantomJsOptions' => { - 'ignore-ssl-errors' => true, - 'ssl-protocol' => 'tlsv1' - }, 'customPageHeaders' => { # use if getting compression errors like 'Data corrupted': 'Accept-Encoding' => 'identity' diff --git a/lib/critical_path_css/rails/version.rb b/lib/critical_path_css/rails/version.rb index 885da23..1c9c58b 100644 --- a/lib/critical_path_css/rails/version.rb +++ b/lib/critical_path_css/rails/version.rb @@ -1,5 +1,5 @@ module CriticalPathCSS module Rails - VERSION = '1.0.1' + VERSION = '2.0.0' end end diff --git a/package.json b/package.json index 1e13ae2..3267ab8 100644 --- a/package.json +++ b/package.json @@ -1,13 +1,13 @@ { "name": "critical-path-css-rails", - "version": "1.0.0", + "version": "2.0.0", "description": "NPM dependencies of critical-path-css-rails", "private": true, "directories": { "lib": "lib" }, "dependencies": { - "penthouse": "=0.11.5" + "penthouse": "=1.1.0" }, "license": "MIT" } From f0750556496e2650eb7e102a2f33735a95fcf512 Mon Sep 17 00:00:00 2001 From: Michael Misshore Date: Thu, 14 Dec 2017 10:02:51 -0600 Subject: [PATCH 21/81] Remove note regarding contributing Penthouse is no longer a JS file and is managed by NPM. --- README.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/README.md b/README.md index 0e456b4..0e7cc5e 100644 --- a/README.md +++ b/README.md @@ -138,8 +138,6 @@ major version bump = major-level updates to critical-path-css-rails, Penthouse, ## Contributing -Feel free to open an issue ticket if you find something that could be improved. A couple notes: - -* If the Penthouse.js script is outdated (i.e. maybe a new version of Penthouse.js was released yesterday), feel free to open an issue and prod us to get that thing updated. However, for security reasons, we won't be accepting pull requests with updated Penthouse.js script. +Feel free to open an issue ticket if you find something that could be improved. Copyright Mudbug Media and Michael Misshore, released under the MIT License. \ No newline at end of file From e8b768b0d03d90e11fbfda730ee0b2db923a6b3a Mon Sep 17 00:00:00 2001 From: Michael Misshore Date: Wed, 27 Dec 2017 03:48:35 -0600 Subject: [PATCH 22/81] Update Penthouse to 1.3.0 --- README.md | 2 +- lib/critical_path_css/rails/version.rb | 2 +- package.json | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 0e7cc5e..d9c33aa 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ Upgrade instructions from each version are included below. Add `critical-path-css-rails` to your Gemfile: ``` -gem 'critical-path-css-rails', '~> 2.0.0' +gem 'critical-path-css-rails', '~> 2.3.0' ``` Download and install by running: diff --git a/lib/critical_path_css/rails/version.rb b/lib/critical_path_css/rails/version.rb index 1c9c58b..f8d9b09 100644 --- a/lib/critical_path_css/rails/version.rb +++ b/lib/critical_path_css/rails/version.rb @@ -1,5 +1,5 @@ module CriticalPathCSS module Rails - VERSION = '2.0.0' + VERSION = '2.3.0' end end diff --git a/package.json b/package.json index 3267ab8..7318be5 100644 --- a/package.json +++ b/package.json @@ -1,13 +1,13 @@ { "name": "critical-path-css-rails", - "version": "2.0.0", + "version": "2.3.0", "description": "NPM dependencies of critical-path-css-rails", "private": true, "directories": { "lib": "lib" }, "dependencies": { - "penthouse": "=1.1.0" + "penthouse": "=1.3.0" }, "license": "MIT" } From a5db88c5184872f73d0bb632b6a57f310b969d0b Mon Sep 17 00:00:00 2001 From: Michael Misshore Date: Fri, 29 Dec 2017 08:58:58 -0600 Subject: [PATCH 23/81] Initial Docker Setup --- .rubocop.yml | 1 - docker-compose.yml | 29 +++++++++++++++++++++++++++++ docker/postgres/config | 2 ++ docker/ruby/.env | 6 ++++++ docker/ruby/Dockerfile | 18 ++++++++++++++++++ docker/ruby/startup.dev | 5 +++++ 6 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 docker-compose.yml create mode 100644 docker/postgres/config create mode 100644 docker/ruby/.env create mode 100644 docker/ruby/Dockerfile create mode 100644 docker/ruby/startup.dev diff --git a/.rubocop.yml b/.rubocop.yml index 78a5571..3d4c7cc 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -6,7 +6,6 @@ AllCops: - 'spec/*_helper.rb' - 'Gemfile' - 'Rakefile' - - 'Vagrantfile' Documentation: Enabled: false \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..42c443c --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,29 @@ +version: '2' +services: + ruby: + build: + context: . + dockerfile: docker/ruby/Dockerfile + volumes: + - .:/app:rw + volumes_from: + - data + depends_on: + - postgres + env_file: docker/ruby/.env + container_name: criticalpathcss_ruby + + postgres: + image: postgres:10.1 + ports: + - 5432:5432 + volumes_from: + - data + env_file: ./docker/postgres/config + + data: + image: postgres:10.1 + volumes: + - /var/lib/postgresql/data + - /gems + command: "true" \ No newline at end of file diff --git a/docker/postgres/config b/docker/postgres/config new file mode 100644 index 0000000..f40c5cf --- /dev/null +++ b/docker/postgres/config @@ -0,0 +1,2 @@ +POSTGRES_PASSWORD=docker +POSTGRES_USER=docker \ No newline at end of file diff --git a/docker/ruby/.env b/docker/ruby/.env new file mode 100644 index 0000000..0c079d2 --- /dev/null +++ b/docker/ruby/.env @@ -0,0 +1,6 @@ +RAILS_ENV=development +DATABASE_HOST=postgres +DATABASE_NAME=critical_path_css_development +DATABASE_USERNAME=docker +DATABASE_PASSWORD=docker +DATABASE_TEST_NAME=critical_path_css_test diff --git a/docker/ruby/Dockerfile b/docker/ruby/Dockerfile new file mode 100644 index 0000000..27d32d9 --- /dev/null +++ b/docker/ruby/Dockerfile @@ -0,0 +1,18 @@ +FROM ruby:2.5.0 + +# Install Dependencies +RUN curl -sL https://deb.nodesource.com/setup_8.x | bash - +RUN apt-get update && apt-get install -y build-essential libpq-dev nodejs npm + +RUN npm cache clean -f +RUN npm install -g n +RUN n 8.9.3 +RUN ln -sf /usr/local/n/versions/node/8.9.3/bin/node /usr/bin/nodejs + +ENV BUNDLE_PATH /gems + +WORKDIR /app + +COPY docker/ruby/startup.dev /usr/local/bin/startup +RUN chmod 755 /usr/local/bin/startup +CMD "/usr/local/bin/startup" \ No newline at end of file diff --git a/docker/ruby/startup.dev b/docker/ruby/startup.dev new file mode 100644 index 0000000..583d6da --- /dev/null +++ b/docker/ruby/startup.dev @@ -0,0 +1,5 @@ +#!/bin/bash + +bundle check || bundle install + +tail -f /dev/null From 53a421c2c28d3792351b5375abe750bfd19a262c Mon Sep 17 00:00:00 2001 From: Michael Misshore Date: Fri, 29 Dec 2017 09:06:48 -0600 Subject: [PATCH 24/81] Update rubocop and rspec. Rubocop fixes --- .rubocop_todo.yml | 30 +++++++++++++++----- critical-path-css-rails.gemspec | 2 +- ext/npm/extconf.rb | 1 - lib/critical-path-css-rails.rb | 2 +- lib/critical_path_css/configuration.rb | 1 - lib/critical_path_css/css_fetcher.rb | 2 +- lib/critical_path_css/rails/config_loader.rb | 4 +-- lib/critical_path_css/rails/version.rb | 2 +- lib/npm_commands.rb | 5 ++-- spec/support/static_file_server.rb | 2 +- 10 files changed, 32 insertions(+), 19 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 8830607..04b6c11 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,18 +1,34 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2015-10-29 13:19:55 -0500 using RuboCop version 0.34.1. +# on 2017-12-29 15:04:25 +0000 using RuboCop version 0.52.1. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. -# Offense count: 3 -# Configuration parameters: AllowURI, URISchemes. -Metrics/LineLength: - Max: 91 +# Offense count: 1 +Metrics/AbcSize: + Max: 19 # Offense count: 1 -# Configuration parameters: Exclude. -Style/FileName: +# Configuration parameters: CountComments. +Metrics/MethodLength: + Max: 31 + +# Offense count: 1 +Naming/AccessorMethodName: + Exclude: + - 'spec/support/static_file_server.rb' + +# Offense count: 1 +# Configuration parameters: ExpectMatchingDefinition, Regex, IgnoreExecutableScripts, AllowedAcronyms. +# AllowedAcronyms: CLI, DSL, ACL, API, ASCII, CPU, CSS, DNS, EOF, GUID, HTML, HTTP, HTTPS, ID, IP, JSON, LHS, QPS, RAM, RHS, RPC, SLA, SMTP, SQL, SSH, TCP, TLS, TTL, UDP, UI, UID, UUID, URI, URL, UTF8, VM, XML, XMPP, XSRF, XSS +Naming/FileName: Exclude: - 'lib/critical-path-css-rails.rb' + +# Offense count: 4 +# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. +# URISchemes: http, https +Metrics/LineLength: + Max: 96 diff --git a/critical-path-css-rails.gemspec b/critical-path-css-rails.gemspec index ce7d39b..4533495 100644 --- a/critical-path-css-rails.gemspec +++ b/critical-path-css-rails.gemspec @@ -14,7 +14,7 @@ Gem::Specification.new do |s| s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) } s.require_path = 'lib' - s.add_development_dependency 'rspec', '~> 3.6' + s.add_development_dependency 'rspec', '~> 3.7' s.extensions = ['ext/npm/extconf.rb'] end diff --git a/ext/npm/extconf.rb b/ext/npm/extconf.rb index 7dce95c..449c2c7 100644 --- a/ext/npm/extconf.rb +++ b/ext/npm/extconf.rb @@ -1,3 +1,2 @@ File.write 'Makefile', "make:\n\t\ninstall:\n\truby install.rb\nclean:\n\t\n" - diff --git a/lib/critical-path-css-rails.rb b/lib/critical-path-css-rails.rb index f4c431f..7586934 100644 --- a/lib/critical-path-css-rails.rb +++ b/lib/critical-path-css-rails.rb @@ -3,7 +3,7 @@ require 'critical_path_css/rails/config_loader' module CriticalPathCss - CACHE_NAMESPACE = 'critical-path-css' + CACHE_NAMESPACE = 'critical-path-css'.freeze def self.generate(route) ::Rails.cache.write( diff --git a/lib/critical_path_css/configuration.rb b/lib/critical_path_css/configuration.rb index 2e4b794..b46669c 100644 --- a/lib/critical_path_css/configuration.rb +++ b/lib/critical_path_css/configuration.rb @@ -1,7 +1,6 @@ require 'erb' module CriticalPathCss class Configuration - def initialize(config) @config = config end diff --git a/lib/critical_path_css/css_fetcher.rb b/lib/critical_path_css/css_fetcher.rb index bda7314..7812d2b 100644 --- a/lib/critical_path_css/css_fetcher.rb +++ b/lib/critical_path_css/css_fetcher.rb @@ -33,7 +33,7 @@ def css_for_route(route) # '^\.regexWorksToo' ], # ms; abort critical CSS generation after this timeout - 'timeout' => 30000, + 'timeout' => 30_000, # set to true to throw on CSS errors (will run faster if no errors) 'strict' => false, # characters; strip out inline base64 encoded resources larger than this diff --git a/lib/critical_path_css/rails/config_loader.rb b/lib/critical_path_css/rails/config_loader.rb index c9a6add..11fc159 100644 --- a/lib/critical_path_css/rails/config_loader.rb +++ b/lib/critical_path_css/rails/config_loader.rb @@ -1,10 +1,10 @@ module CriticalPathCss module Rails class ConfigLoader - CONFIGURATION_FILENAME = 'critical_path_css.yml' + CONFIGURATION_FILENAME = 'critical_path_css.yml'.freeze def load - config = YAML.load(ERB.new(File.read(configuration_file_path)).result)[::Rails.env] + config = YAML.safe_load(ERB.new(File.read(configuration_file_path)).result)[::Rails.env] config['css_path'] = "#{::Rails.root}/public" + ( config['css_path'] || ActionController::Base.helpers.stylesheet_path( diff --git a/lib/critical_path_css/rails/version.rb b/lib/critical_path_css/rails/version.rb index 885da23..8c99d20 100644 --- a/lib/critical_path_css/rails/version.rb +++ b/lib/critical_path_css/rails/version.rb @@ -1,5 +1,5 @@ module CriticalPathCSS module Rails - VERSION = '1.0.1' + VERSION = '1.0.1'.freeze end end diff --git a/lib/npm_commands.rb b/lib/npm_commands.rb index 5f50095..9d3d0e0 100644 --- a/lib/npm_commands.rb +++ b/lib/npm_commands.rb @@ -2,9 +2,8 @@ # NPM wrapper with helpful error messages class NpmCommands - # @return [Boolean] whether the installation succeeded - def install(*args) # rubocop:disable Metrics/MethodLength + def install(*args) return false unless check_nodejs_installed STDERR.puts 'Installing npm dependencies...' install_status = Dir.chdir File.expand_path('..', File.dirname(__FILE__)) do @@ -24,7 +23,7 @@ def install(*args) # rubocop:disable Metrics/MethodLength private - def check_nodejs_installed # rubocop:disable Metrics/MethodLength + def check_nodejs_installed return true if executable?('node') STDERR.puts( '-' * 60, diff --git a/spec/support/static_file_server.rb b/spec/support/static_file_server.rb index 345baa9..b77a42b 100644 --- a/spec/support/static_file_server.rb +++ b/spec/support/static_file_server.rb @@ -2,7 +2,7 @@ module StaticFileServer class << self - def start # rubocop:disable Metrics/MethodLength,Metrics/AbcSize + def start @port = get_free_port rd, wt = IO.pipe @pid = fork do From 7fdb7f646bc645a6b5ca617c382bf7602f439a75 Mon Sep 17 00:00:00 2001 From: Michael Misshore Date: Fri, 29 Dec 2017 09:09:00 -0600 Subject: [PATCH 25/81] Change specification variable name --- critical-path-css-rails.gemspec | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/critical-path-css-rails.gemspec b/critical-path-css-rails.gemspec index 4533495..c8f84a3 100644 --- a/critical-path-css-rails.gemspec +++ b/critical-path-css-rails.gemspec @@ -1,20 +1,20 @@ require File.expand_path('../lib/critical_path_css/rails/version', __FILE__) -Gem::Specification.new do |s| - s.name = 'critical-path-css-rails' - s.version = CriticalPathCSS::Rails::VERSION - s.platform = Gem::Platform::RUBY - s.authors = ['Michael Misshore'] - s.email = 'mmisshore@gmail.com' - s.summary = 'Critical Path CSS for Rails!' - s.description = 'Only load the CSS you need for the initial viewport in Rails!' - s.license = 'MIT' +Gem::Specification.new do |gem| + gem.name = 'critical-path-css-rails' + gem.version = CriticalPathCSS::Rails::VERSION + gem.platform = Gem::Platform::RUBY + gem.authors = ['Michael Misshore'] + gem.email = 'mmisshore@gmail.com' + gem.summary = 'Critical Path CSS for Rails!' + gem.description = 'Only load the CSS you need for the initial viewport in Rails!' + gem.license = 'MIT' - s.files = `git ls-files`.split("\n") - s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) } - s.require_path = 'lib' + gem.files = `git ls-files`.split("\n") + gem.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) } + gem.require_path = 'lib' - s.add_development_dependency 'rspec', '~> 3.7' + gem.add_development_dependency 'rspec', '~> 3.7' - s.extensions = ['ext/npm/extconf.rb'] + gem.extensions = ['ext/npm/extconf.rb'] end From 3b6043048e6bd454414755eaa8f66865f7f75d99 Mon Sep 17 00:00:00 2001 From: Michael Misshore Date: Fri, 29 Dec 2017 09:25:16 -0600 Subject: [PATCH 26/81] Adding combustion --- Gemfile | 2 ++ config.ru | 7 +++++++ critical-path-css-rails.gemspec | 2 +- spec/internal/config/database.yml | 3 +++ spec/internal/config/routes.rb | 3 +++ spec/internal/db/schema.rb | 3 +++ spec/internal/log/.gitignore | 1 + spec/internal/public/favicon.ico | 0 spec/spec_helper.rb | 10 +++++++++- 9 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 config.ru create mode 100644 spec/internal/config/database.yml create mode 100644 spec/internal/config/routes.rb create mode 100644 spec/internal/db/schema.rb create mode 100644 spec/internal/log/.gitignore create mode 100644 spec/internal/public/favicon.ico diff --git a/Gemfile b/Gemfile index 1cfb04f..942cae9 100644 --- a/Gemfile +++ b/Gemfile @@ -3,8 +3,10 @@ source 'https://rubygems.org' gemspec group :development, :test do + gem 'actionpack' gem 'byebug', platform: [:ruby], require: false gem 'rubocop', require: false + gem 'rspec-rails', '~> 3.6' end # HACK: npm install on bundle diff --git a/config.ru b/config.ru new file mode 100644 index 0000000..2c8b242 --- /dev/null +++ b/config.ru @@ -0,0 +1,7 @@ +require 'rubygems' +require 'bundler' + +Bundler.require :default, :development + +Combustion.initialize! :all +run Combustion::Application diff --git a/critical-path-css-rails.gemspec b/critical-path-css-rails.gemspec index c8f84a3..b66cabe 100644 --- a/critical-path-css-rails.gemspec +++ b/critical-path-css-rails.gemspec @@ -14,7 +14,7 @@ Gem::Specification.new do |gem| gem.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) } gem.require_path = 'lib' - gem.add_development_dependency 'rspec', '~> 3.7' + gem.add_development_dependency 'combustion', '~> 0.7.0' gem.extensions = ['ext/npm/extconf.rb'] end diff --git a/spec/internal/config/database.yml b/spec/internal/config/database.yml new file mode 100644 index 0000000..b978119 --- /dev/null +++ b/spec/internal/config/database.yml @@ -0,0 +1,3 @@ +test: + adapter: sqlite3 + database: db/combustion_test.sqlite diff --git a/spec/internal/config/routes.rb b/spec/internal/config/routes.rb new file mode 100644 index 0000000..14560a4 --- /dev/null +++ b/spec/internal/config/routes.rb @@ -0,0 +1,3 @@ +Rails.application.routes.draw do + # +end diff --git a/spec/internal/db/schema.rb b/spec/internal/db/schema.rb new file mode 100644 index 0000000..a4ab1bb --- /dev/null +++ b/spec/internal/db/schema.rb @@ -0,0 +1,3 @@ +ActiveRecord::Schema.define do + # +end diff --git a/spec/internal/log/.gitignore b/spec/internal/log/.gitignore new file mode 100644 index 0000000..bf0824e --- /dev/null +++ b/spec/internal/log/.gitignore @@ -0,0 +1 @@ +*.log \ No newline at end of file diff --git a/spec/internal/public/favicon.ico b/spec/internal/public/favicon.ico new file mode 100644 index 0000000..e69de29 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 7b07287..53449c5 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,11 +1,19 @@ # frozen_string_literal: true -require 'bundler/setup' +require 'bundler' require 'critical-path-css-rails' require 'support/static_file_server' +Bundler.require :default, :development + +Combustion.initialize! :action_controller, :action_view + +require 'rspec/rails' + RSpec.configure do |config| + config.use_transactional_fixtures = true + # Enable flags like --only-failures and --next-failure config.example_status_persistence_file_path = '.rspec_status' From 409ddc4602fbc11a8cdd17a4c35f6427c858aec6 Mon Sep 17 00:00:00 2001 From: Michael Misshore Date: Fri, 29 Dec 2017 09:37:56 -0600 Subject: [PATCH 27/81] Tidy docker setup --- docker-compose.yml | 15 +++------------ docker/postgres/config | 2 -- docker/ruby/.env | 5 ----- 3 files changed, 3 insertions(+), 19 deletions(-) delete mode 100644 docker/postgres/config diff --git a/docker-compose.yml b/docker-compose.yml index 42c443c..49e4c71 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -8,22 +8,13 @@ services: - .:/app:rw volumes_from: - data - depends_on: - - postgres env_file: docker/ruby/.env container_name: criticalpathcss_ruby - postgres: - image: postgres:10.1 - ports: - - 5432:5432 - volumes_from: - - data - env_file: ./docker/postgres/config - data: - image: postgres:10.1 + build: + context: . + dockerfile: docker/ruby/Dockerfile volumes: - - /var/lib/postgresql/data - /gems command: "true" \ No newline at end of file diff --git a/docker/postgres/config b/docker/postgres/config deleted file mode 100644 index f40c5cf..0000000 --- a/docker/postgres/config +++ /dev/null @@ -1,2 +0,0 @@ -POSTGRES_PASSWORD=docker -POSTGRES_USER=docker \ No newline at end of file diff --git a/docker/ruby/.env b/docker/ruby/.env index 0c079d2..336ada1 100644 --- a/docker/ruby/.env +++ b/docker/ruby/.env @@ -1,6 +1 @@ RAILS_ENV=development -DATABASE_HOST=postgres -DATABASE_NAME=critical_path_css_development -DATABASE_USERNAME=docker -DATABASE_PASSWORD=docker -DATABASE_TEST_NAME=critical_path_css_test From 19a0f12a30db25c943382b169797e98bf1b261c7 Mon Sep 17 00:00:00 2001 From: Michael Misshore Date: Fri, 29 Dec 2017 10:09:09 -0600 Subject: [PATCH 28/81] Remove old test --- spec/css_fetcher_spec.rb | 25 ----------------- spec/fixtures/static/test.css | 3 -- spec/fixtures/static/test.html | 7 ----- spec/spec_helper.rb | 3 -- spec/support/static_file_server.rb | 45 ------------------------------ 5 files changed, 83 deletions(-) delete mode 100644 spec/css_fetcher_spec.rb delete mode 100644 spec/fixtures/static/test.css delete mode 100644 spec/fixtures/static/test.html delete mode 100644 spec/support/static_file_server.rb diff --git a/spec/css_fetcher_spec.rb b/spec/css_fetcher_spec.rb deleted file mode 100644 index 0475c9a..0000000 --- a/spec/css_fetcher_spec.rb +++ /dev/null @@ -1,25 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe 'CssFetcher' do - before :all do - StaticFileServer.start - end - - after :all do - StaticFileServer.stop - end - - it 'fetches css' do - config = CriticalPathCss::Configuration.new( - 'base_url' => StaticFileServer.url, - 'css_path' => 'spec/fixtures/static/test.css', - 'routes' => ['/test.html'] - ) - fetcher = CriticalPathCss::CssFetcher.new(config) - expect(fetcher.fetch).to( - eq('/test.html' => "p {\n color: red;\n}\n") - ) - end -end diff --git a/spec/fixtures/static/test.css b/spec/fixtures/static/test.css deleted file mode 100644 index 3d9a2b2..0000000 --- a/spec/fixtures/static/test.css +++ /dev/null @@ -1,3 +0,0 @@ -p { - color: red; -} diff --git a/spec/fixtures/static/test.html b/spec/fixtures/static/test.html deleted file mode 100644 index a16a45d..0000000 --- a/spec/fixtures/static/test.html +++ /dev/null @@ -1,7 +0,0 @@ - - - - - -

Hello world

- diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 53449c5..95025c6 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,9 +1,6 @@ # frozen_string_literal: true require 'bundler' -require 'critical-path-css-rails' - -require 'support/static_file_server' Bundler.require :default, :development diff --git a/spec/support/static_file_server.rb b/spec/support/static_file_server.rb deleted file mode 100644 index b77a42b..0000000 --- a/spec/support/static_file_server.rb +++ /dev/null @@ -1,45 +0,0 @@ -require 'socket' - -module StaticFileServer - class << self - def start - @port = get_free_port - rd, wt = IO.pipe - @pid = fork do - require 'webrick' - rd.close - server = WEBrick::HTTPServer.new( - DocumentRoot: File.expand_path('spec/fixtures/static'), - Port: @port, - BindAddress: '127.0.0.1', - StartCallback: lambda do - # write "1", signal a server start message - wt.write(1) - wt.close - end - ) - trap('INT') { server.shutdown } - server.start - end - wt.close - # read a byte for the server start signal - rd.read(1) - rd.close - end - - def stop - Process.kill('INT', @pid) - end - - def url - "http://localhost:#{@port}" - end - - def get_free_port - server = TCPServer.new('127.0.0.1', 0) - port = server.addr[1] - server.close - port - end - end -end From 586cc6c46ddc0634cb720879eb7f27040aa6fb1a Mon Sep 17 00:00:00 2001 From: Michael Misshore Date: Fri, 29 Dec 2017 10:31:30 -0600 Subject: [PATCH 29/81] Load alias for #safe_load --- lib/critical_path_css/rails/config_loader.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/critical_path_css/rails/config_loader.rb b/lib/critical_path_css/rails/config_loader.rb index 11fc159..bbab1ba 100644 --- a/lib/critical_path_css/rails/config_loader.rb +++ b/lib/critical_path_css/rails/config_loader.rb @@ -4,7 +4,7 @@ class ConfigLoader CONFIGURATION_FILENAME = 'critical_path_css.yml'.freeze def load - config = YAML.safe_load(ERB.new(File.read(configuration_file_path)).result)[::Rails.env] + config = YAML.safe_load(ERB.new(File.read(configuration_file_path)).result, [], [], true)[::Rails.env] config['css_path'] = "#{::Rails.root}/public" + ( config['css_path'] || ActionController::Base.helpers.stylesheet_path( From 2ecd852970169c6c8311d4d92d7c83f695a795ea Mon Sep 17 00:00:00 2001 From: Michael Misshore Date: Mon, 1 Jan 2018 05:55:30 -0600 Subject: [PATCH 30/81] Update Backlog --- BACKLOG.md | 4 ---- 1 file changed, 4 deletions(-) diff --git a/BACKLOG.md b/BACKLOG.md index 7f6b692..3713b97 100644 --- a/BACKLOG.md +++ b/BACKLOG.md @@ -1,12 +1,8 @@ # Backlog -## Tests -- Add a testing suite (preferably rspec) - ## Features - Allow the user to give a single route for a Controller#Show route, instead of hard coding every unique Resource#Show URL * Implementation should account for any route that allows variables/parameters in the URL - Error reporting during CSS generation (404, 500 errors, etc.) -- Allow the user to pass arguments to Penthouse.js, i.e. Viewport size, etc. For a list of the configurable options, please see [Penthouse](https://github.com/pocketjoso/penthouse) - Improve installation process, if possible - Improve implementation. Is their a better solution then using Rails.cache? \ No newline at end of file From 0d880c19b7796cefe3d24654841f09651dd9843a Mon Sep 17 00:00:00 2001 From: Samuel Gavassi Pismel Date: Fri, 5 Jan 2018 14:15:58 -0200 Subject: [PATCH 31/81] Update README instructions to use version 1.0.1 (stable) --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f1a7e58..dc84efd 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ Upgrade instructions from each version are included below. Add `critical-path-css-rails` to your Gemfile: ``` -gem 'critical-path-css-rails', '~> 1.0.0' +gem 'critical-path-css-rails', '~> 1.0.1' ``` Download and install by running: @@ -142,4 +142,4 @@ Feel free to open an issue ticket if you find something that could be improved. * If the Penthouse.js script is outdated (i.e. maybe a new version of Penthouse.js was released yesterday), feel free to open an issue and prod us to get that thing updated. However, for security reasons, we won't be accepting pull requests with updated Penthouse.js script. -Copyright Mudbug Media and Michael Misshore, released under the MIT License. \ No newline at end of file +Copyright Mudbug Media and Michael Misshore, released under the MIT License. From d294837bd3ff75a227a810f52530d9b8dfb0adb2 Mon Sep 17 00:00:00 2001 From: Michael Misshore Date: Wed, 3 Jan 2018 11:05:40 -0600 Subject: [PATCH 32/81] Add basic testing suite --- Gemfile | 2 ++ app_container_name | 1 + config.ru | 5 ++--- docker-compose.yml | 3 ++- docker/ruby/startup.dev | 2 +- spec/internal/app/controllers/root_controller.rb | 3 +++ .../app/views/layouts/application.html.erb | 4 ++++ spec/internal/app/views/root/index.html.erb | 1 + spec/internal/config/critical_path_css.yml | 11 +++++++++++ spec/internal/config/routes.rb | 2 +- spec/internal/public/test.css | 3 +++ spec/spec_helper.rb | 1 + spec/system/fetch_critical_css_spec.rb | 16 ++++++++++++++++ 13 files changed, 48 insertions(+), 6 deletions(-) create mode 100644 app_container_name create mode 100644 spec/internal/app/controllers/root_controller.rb create mode 100644 spec/internal/app/views/layouts/application.html.erb create mode 100644 spec/internal/app/views/root/index.html.erb create mode 100644 spec/internal/config/critical_path_css.yml create mode 100644 spec/internal/public/test.css create mode 100644 spec/system/fetch_critical_css_spec.rb diff --git a/Gemfile b/Gemfile index 942cae9..7b9a526 100644 --- a/Gemfile +++ b/Gemfile @@ -7,6 +7,8 @@ group :development, :test do gem 'byebug', platform: [:ruby], require: false gem 'rubocop', require: false gem 'rspec-rails', '~> 3.6' + gem 'capybara', '~> 2.16' + gem 'pry-rails' end # HACK: npm install on bundle diff --git a/app_container_name b/app_container_name new file mode 100644 index 0000000..532a712 --- /dev/null +++ b/app_container_name @@ -0,0 +1 @@ +criticalpathcss_ruby \ No newline at end of file diff --git a/config.ru b/config.ru index 2c8b242..4a1c95b 100644 --- a/config.ru +++ b/config.ru @@ -1,7 +1,6 @@ require 'rubygems' require 'bundler' +require 'combustion' -Bundler.require :default, :development - -Combustion.initialize! :all +Combustion.initialize! :action_controller, :action_view run Combustion::Application diff --git a/docker-compose.yml b/docker-compose.yml index 49e4c71..da22674 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -4,13 +4,14 @@ services: build: context: . dockerfile: docker/ruby/Dockerfile + ports: + - 9292:9292 volumes: - .:/app:rw volumes_from: - data env_file: docker/ruby/.env container_name: criticalpathcss_ruby - data: build: context: . diff --git a/docker/ruby/startup.dev b/docker/ruby/startup.dev index 583d6da..f9ddc5f 100644 --- a/docker/ruby/startup.dev +++ b/docker/ruby/startup.dev @@ -2,4 +2,4 @@ bundle check || bundle install -tail -f /dev/null +bundle exec rackup --host 0.0.0.0 diff --git a/spec/internal/app/controllers/root_controller.rb b/spec/internal/app/controllers/root_controller.rb new file mode 100644 index 0000000..eb82de8 --- /dev/null +++ b/spec/internal/app/controllers/root_controller.rb @@ -0,0 +1,3 @@ +class RootController < ActionController::Base + def index; end +end diff --git a/spec/internal/app/views/layouts/application.html.erb b/spec/internal/app/views/layouts/application.html.erb new file mode 100644 index 0000000..a98b7c4 --- /dev/null +++ b/spec/internal/app/views/layouts/application.html.erb @@ -0,0 +1,4 @@ + + + <%= yield %> + diff --git a/spec/internal/app/views/root/index.html.erb b/spec/internal/app/views/root/index.html.erb new file mode 100644 index 0000000..62b320d --- /dev/null +++ b/spec/internal/app/views/root/index.html.erb @@ -0,0 +1 @@ +

<%= CriticalPathCss.fetch(request.path) %>

diff --git a/spec/internal/config/critical_path_css.yml b/spec/internal/config/critical_path_css.yml new file mode 100644 index 0000000..e40cc85 --- /dev/null +++ b/spec/internal/config/critical_path_css.yml @@ -0,0 +1,11 @@ +defaults: &defaults + base_url: http://0.0.0.0:9292 + css_path: /test.css + routes: + - / + +development: + <<: *defaults + +test: + <<: *defaults diff --git a/spec/internal/config/routes.rb b/spec/internal/config/routes.rb index 14560a4..d09aa7b 100644 --- a/spec/internal/config/routes.rb +++ b/spec/internal/config/routes.rb @@ -1,3 +1,3 @@ Rails.application.routes.draw do - # + root 'root#index' end diff --git a/spec/internal/public/test.css b/spec/internal/public/test.css new file mode 100644 index 0000000..e21e2c2 --- /dev/null +++ b/spec/internal/public/test.css @@ -0,0 +1,3 @@ +p { + color: red; +} \ No newline at end of file diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 95025c6..6146035 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -7,6 +7,7 @@ Combustion.initialize! :action_controller, :action_view require 'rspec/rails' +require 'capybara/rails' RSpec.configure do |config| config.use_transactional_fixtures = true diff --git a/spec/system/fetch_critical_css_spec.rb b/spec/system/fetch_critical_css_spec.rb new file mode 100644 index 0000000..8b51c3f --- /dev/null +++ b/spec/system/fetch_critical_css_spec.rb @@ -0,0 +1,16 @@ +require 'spec_helper.rb' + +RSpec.describe 'fetching the critical css' do + before do + CriticalPathCss.generate_all + end + + context 'on the root page' do + let(:route) { '/' } + + it 'displays the correct critical CSS' do + visit route + expect(page).to have_content 'color: red;' + end + end +end From ec28057ada0724bb56b3fa24d6aa2dc94e3d62c4 Mon Sep 17 00:00:00 2001 From: Michael Misshore Date: Sat, 6 Jan 2018 12:51:00 -0600 Subject: [PATCH 33/81] Rename system to features --- .../generate_and_fetch_critical_css_spec.rb} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename spec/{system/fetch_critical_css_spec.rb => features/generate_and_fetch_critical_css_spec.rb} (82%) diff --git a/spec/system/fetch_critical_css_spec.rb b/spec/features/generate_and_fetch_critical_css_spec.rb similarity index 82% rename from spec/system/fetch_critical_css_spec.rb rename to spec/features/generate_and_fetch_critical_css_spec.rb index 8b51c3f..4c0aeba 100644 --- a/spec/system/fetch_critical_css_spec.rb +++ b/spec/features/generate_and_fetch_critical_css_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper.rb' -RSpec.describe 'fetching the critical css' do +RSpec.describe 'generate and fetch the critical css' do before do CriticalPathCss.generate_all end From 0239a1c543ce8b38501a6e1c3ba17a98db547a5e Mon Sep 17 00:00:00 2001 From: Michael Misshore Date: Sat, 6 Jan 2018 12:55:20 -0600 Subject: [PATCH 34/81] Add testing documentation --- README.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/README.md b/README.md index dc84efd..7d6d301 100644 --- a/README.md +++ b/README.md @@ -126,6 +126,20 @@ rails generate critical_path_css:install Answer 'Y' when prompted to overwrite `critical_path_css.rake`. However, overwriting `critical_path_css.yml` is not necessary and not recommended. + +## Testing + +This gem is to be tested inside of docker/docker-compose. [Combustion](https://github.com/pat/combustion), alongside rspec-rails and capybara, are the primary components for testing. To run the test, you'll need to have [Docker](https://docs.docker.com/engine/installation) installed. Once installed, run the following commands in the gem's root to build, run, and shell into the docker container. + +```Bash + docker-compose build + docker-compose up -d + docker exec -it $(cat app_container_name) /bin/bash +``` + +Once shell'd in, run `bundle exec rspec spec` to run the test. The test rails app lives in `spec/internal`, and it can be viewed locally at `http://localhost:9292/` + + ## Versions The critical-path-css-rails gem follows these version guidelines: From 4925e5da0c77d255da49e885236f75a73654f7c5 Mon Sep 17 00:00:00 2001 From: Michael Misshore Date: Sat, 6 Jan 2018 13:03:46 -0600 Subject: [PATCH 35/81] Freeze gem version --- lib/critical_path_css/rails/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/critical_path_css/rails/version.rb b/lib/critical_path_css/rails/version.rb index f8d9b09..7a86f6b 100644 --- a/lib/critical_path_css/rails/version.rb +++ b/lib/critical_path_css/rails/version.rb @@ -1,5 +1,5 @@ module CriticalPathCSS module Rails - VERSION = '2.3.0' + VERSION = '2.3.0'.freeze end end From 7eeef2262cbdeb1bbd6bec4771fbf992a99871bc Mon Sep 17 00:00:00 2001 From: Michael Misshore Date: Sat, 6 Jan 2018 13:13:00 -0600 Subject: [PATCH 36/81] Update package lock --- package-lock.json | 816 +++++++++++----------------------------------- 1 file changed, 194 insertions(+), 622 deletions(-) diff --git a/package-lock.json b/package-lock.json index 93145c6..570be9b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,119 +1,48 @@ { "name": "critical-path-css-rails", - "version": "1.0.0", + "version": "2.3.0", "lockfileVersion": 1, "requires": true, "dependencies": { - "amdefine": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/amdefine/-/amdefine-1.0.1.tgz", - "integrity": "sha1-SlKCrBZHKek2Gbz9OtFR+BfOkfU=" - }, - "ansi-regex": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz", - "integrity": "sha1-w7M6te42DYbg5ijwRorn7yfWVN8=" - }, - "ansi-styles": { - "version": "2.2.1", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-2.2.1.tgz", - "integrity": "sha1-tDLdM1i2NM914eRmQ2gkBTPB3b4=" - }, - "apartment": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/apartment/-/apartment-1.1.1.tgz", - "integrity": "sha1-/ZQGzcyodTWULxWzYKGrWkqpfiY=", - "requires": { - "css": "git+https://github.com/pocketjoso/css.git#8ddea7e3cbc0a183ecf694a7a5fbc84326893893", - "get-stdin": "5.0.1", - "lodash": "3.10.1", - "minimist": "1.2.0" - } - }, - "asn1": { - "version": "0.2.3", - "resolved": "https://registry.npmjs.org/asn1/-/asn1-0.2.3.tgz", - "integrity": "sha1-2sh4dxPJlmhJ/IGAd36+nB3fO4Y=" - }, - "assert-plus": { - "version": "0.2.0", - "resolved": "https://registry.npmjs.org/assert-plus/-/assert-plus-0.2.0.tgz", - "integrity": "sha1-104bh+ev/A24qttwIfP+SBAasjQ=" - }, - "asynckit": { - "version": "0.4.0", - "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", - "integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k=" - }, - "atob": { - "version": "1.1.3", - "resolved": "https://registry.npmjs.org/atob/-/atob-1.1.3.tgz", - "integrity": "sha1-lfE2KbEsOlGl0hWr3OKqnzL4B3M=" - }, - "aws-sign2": { - "version": "0.6.0", - "resolved": "https://registry.npmjs.org/aws-sign2/-/aws-sign2-0.6.0.tgz", - "integrity": "sha1-FDQt0428yU0OW4fXY81jYSwOeU8=" - }, - "aws4": { - "version": "1.6.0", - "resolved": "https://registry.npmjs.org/aws4/-/aws4-1.6.0.tgz", - "integrity": "sha1-g+9cqGCysy5KDe7e6MdxudtXRx4=" - }, - "bcrypt-pbkdf": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/bcrypt-pbkdf/-/bcrypt-pbkdf-1.0.1.tgz", - "integrity": "sha1-Y7xdy2EzG5K8Bf1SiVPDNGKgb40=", - "optional": true, + "agent-base": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-4.1.2.tgz", + "integrity": "sha512-VE6QoEdaugY86BohRtfGmTDabxdU5sCKOkbcPA6PXKJsRzEi/7A3RCTxJal1ft/4qSfPht5/iQLhMh/wzSkkNw==", "requires": { - "tweetnacl": "0.14.5" + "es6-promisify": "5.0.0" } }, - "boom": { - "version": "2.10.1", - "resolved": "https://registry.npmjs.org/boom/-/boom-2.10.1.tgz", - "integrity": "sha1-OciRjO/1eZ+D+UkqhI9iWt0Mdm8=", - "requires": { - "hoek": "2.16.3" - } - }, - "caseless": { - "version": "0.11.0", - "resolved": "https://registry.npmjs.org/caseless/-/caseless-0.11.0.tgz", - "integrity": "sha1-cVuW6phBWTzDMGeSP17GDr2k99c=" + "async-limiter": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/async-limiter/-/async-limiter-1.0.0.tgz", + "integrity": "sha512-jp/uFnooOiO+L211eZOoSyzpOITMXx1rBITauYykG3BRYPu8h0UcxsPNB04RR5vo4Tyz3+ay17tR6JVf9qzYWg==" }, - "chalk": { - "version": "1.1.3", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz", - "integrity": "sha1-qBFcVeSnAv5NFQq9OHKCKn4J/Jg=", - "requires": { - "ansi-styles": "2.2.1", - "escape-string-regexp": "1.0.5", - "has-ansi": "2.0.0", - "strip-ansi": "3.0.1", - "supports-color": "2.0.0" - } + "balanced-match": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", + "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=" }, - "combined-stream": { - "version": "1.0.5", - "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.5.tgz", - "integrity": "sha1-k4NwpXtKUd6ix3wV1cX9+JUWQAk=", + "brace-expansion": { + "version": "1.1.8", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.8.tgz", + "integrity": "sha1-wHshHHyVLsH479Uad+8NHTmQopI=", "requires": { - "delayed-stream": "1.0.0" + "balanced-match": "1.0.0", + "concat-map": "0.0.1" } }, - "commander": { - "version": "2.11.0", - "resolved": "https://registry.npmjs.org/commander/-/commander-2.11.0.tgz", - "integrity": "sha512-b0553uYA5YAEGgyYIGYROzKQ7X5RAqedkfjiZxwi0kL1g3bOaBNNZfYkzt/CL0umgD5wc9Jec2FbB98CjkMRvQ==" + "concat-map": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", + "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=" }, "concat-stream": { - "version": "1.5.0", - "resolved": "https://registry.npmjs.org/concat-stream/-/concat-stream-1.5.0.tgz", - "integrity": "sha1-U/fUPFHF5D+ByP3QMyHGMb5o1hE=", + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/concat-stream/-/concat-stream-1.6.0.tgz", + "integrity": "sha1-CqxmL9Ur54lk1VMvaUeE5wEQrPc=", "requires": { "inherits": "2.0.3", - "readable-stream": "2.0.6", + "readable-stream": "2.3.3", "typedarray": "0.0.6" } }, @@ -122,93 +51,62 @@ "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz", "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=" }, - "cryptiles": { - "version": "2.0.5", - "resolved": "https://registry.npmjs.org/cryptiles/-/cryptiles-2.0.5.tgz", - "integrity": "sha1-O9/s3GCBR8HGcgL6KR59ylnqo7g=", - "requires": { - "boom": "2.10.1" - } - }, - "css": { - "version": "git+https://github.com/pocketjoso/css.git#8ddea7e3cbc0a183ecf694a7a5fbc84326893893", - "requires": { - "inherits": "2.0.3", - "source-map": "0.1.43", - "source-map-resolve": "0.3.1", - "urix": "0.1.0" - } - }, "css-mediaquery": { "version": "0.1.2", "resolved": "https://registry.npmjs.org/css-mediaquery/-/css-mediaquery-0.1.2.tgz", "integrity": "sha1-aiw3NEkoYYYxxUvTPO3TAdoYvqA=" }, - "dashdash": { - "version": "1.14.1", - "resolved": "https://registry.npmjs.org/dashdash/-/dashdash-1.14.1.tgz", - "integrity": "sha1-hTz6D3y+L+1d4gMmuN1YEDX24vA=", + "css-tree": { + "version": "1.0.0-alpha.26", + "resolved": "https://registry.npmjs.org/css-tree/-/css-tree-1.0.0-alpha.26.tgz", + "integrity": "sha1-aQvuNFj7W2twAFU5g8jDCHbaCz4=", "requires": { - "assert-plus": "1.0.0" - }, - "dependencies": { - "assert-plus": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/assert-plus/-/assert-plus-1.0.0.tgz", - "integrity": "sha1-8S4PPF13sLHN2RRpQuTpbB5N1SU=" - } + "mdn-data": "1.0.0", + "source-map": "0.5.7" } }, "debug": { - "version": "0.7.4", - "resolved": "https://registry.npmjs.org/debug/-/debug-0.7.4.tgz", - "integrity": "sha1-BuHqgILCyxTjmAbiLi9vdX+Srzk=" - }, - "delayed-stream": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", - "integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk=" - }, - "ecc-jsbn": { - "version": "0.1.1", - "resolved": "https://registry.npmjs.org/ecc-jsbn/-/ecc-jsbn-0.1.1.tgz", - "integrity": "sha1-D8c6ntXw1Tw4GTOYUj735UN3dQU=", - "optional": true, + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz", + "integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==", "requires": { - "jsbn": "0.1.1" + "ms": "2.0.0" } }, "es6-promise": { - "version": "4.0.5", - "resolved": "https://registry.npmjs.org/es6-promise/-/es6-promise-4.0.5.tgz", - "integrity": "sha1-eILzCt3lskDM+n99eMVIMwlRrkI=" + "version": "4.2.2", + "resolved": "https://registry.npmjs.org/es6-promise/-/es6-promise-4.2.2.tgz", + "integrity": "sha512-LSas5vsuA6Q4nEdf9wokY5/AJYXry98i0IzXsv49rYsgDGDNDPbqAYR1Pe23iFxygfbGZNR/5VrHXBCh2BhvUQ==" }, - "escape-string-regexp": { - "version": "1.0.5", - "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", - "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=" - }, - "extend": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/extend/-/extend-3.0.1.tgz", - "integrity": "sha1-p1Xqe8Gt/MWjHOfnYtuq3F5jZEQ=" + "es6-promisify": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/es6-promisify/-/es6-promisify-5.0.0.tgz", + "integrity": "sha1-UQnWLz5W6pZ8S2NQWu8IKRyKUgM=", + "requires": { + "es6-promise": "4.2.2" + } }, "extract-zip": { - "version": "1.5.0", - "resolved": "https://registry.npmjs.org/extract-zip/-/extract-zip-1.5.0.tgz", - "integrity": "sha1-ksz22B73Cp+kwXRxFMzvbYaIpsQ=", + "version": "1.6.6", + "resolved": "https://registry.npmjs.org/extract-zip/-/extract-zip-1.6.6.tgz", + "integrity": "sha1-EpDt6NINCHK0Kf0/NRyhKOxe+Fw=", "requires": { - "concat-stream": "1.5.0", - "debug": "0.7.4", + "concat-stream": "1.6.0", + "debug": "2.6.9", "mkdirp": "0.5.0", "yauzl": "2.4.1" + }, + "dependencies": { + "debug": { + "version": "2.6.9", + "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", + "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", + "requires": { + "ms": "2.0.0" + } + } } }, - "extsprintf": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/extsprintf/-/extsprintf-1.0.2.tgz", - "integrity": "sha1-4QgOBljjALBilJkMxw4VAiNf1VA=" - }, "fd-slicer": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/fd-slicer/-/fd-slicer-1.0.1.tgz", @@ -217,121 +115,40 @@ "pend": "1.2.0" } }, - "forever-agent": { - "version": "0.6.1", - "resolved": "https://registry.npmjs.org/forever-agent/-/forever-agent-0.6.1.tgz", - "integrity": "sha1-+8cfDEGt6zf5bFd60e1C2P2sypE=" - }, - "form-data": { - "version": "2.1.4", - "resolved": "https://registry.npmjs.org/form-data/-/form-data-2.1.4.tgz", - "integrity": "sha1-M8GDrPGTJ27KqYFDpp6Uv+4XUNE=", - "requires": { - "asynckit": "0.4.0", - "combined-stream": "1.0.5", - "mime-types": "2.1.16" - } - }, - "fs-extra": { + "fs.realpath": { "version": "1.0.0", - "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-1.0.0.tgz", - "integrity": "sha1-zTzl9+fLYUWIP8rjGR6Yd/hYeVA=", - "requires": { - "graceful-fs": "4.1.11", - "jsonfile": "2.4.0", - "klaw": "1.3.1" - } - }, - "generate-function": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/generate-function/-/generate-function-2.0.0.tgz", - "integrity": "sha1-aFj+fAlpt9TpCTM3ZHrHn2DfvnQ=" - }, - "generate-object-property": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/generate-object-property/-/generate-object-property-1.2.0.tgz", - "integrity": "sha1-nA4cQDCM6AT0eDYYuTf6iPmdUNA=", - "requires": { - "is-property": "1.0.2" - } - }, - "get-stdin": { - "version": "5.0.1", - "resolved": "https://registry.npmjs.org/get-stdin/-/get-stdin-5.0.1.tgz", - "integrity": "sha1-Ei4WFZHiH/TFJTAwVpPyDmOTo5g=" - }, - "getpass": { - "version": "0.1.7", - "resolved": "https://registry.npmjs.org/getpass/-/getpass-0.1.7.tgz", - "integrity": "sha1-Xv+OPmhNVprkyysSgmBOi6YhSfo=", - "requires": { - "assert-plus": "1.0.0" - }, - "dependencies": { - "assert-plus": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/assert-plus/-/assert-plus-1.0.0.tgz", - "integrity": "sha1-8S4PPF13sLHN2RRpQuTpbB5N1SU=" - } - } + "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", + "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=" }, - "graceful-fs": { - "version": "4.1.11", - "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.1.11.tgz", - "integrity": "sha1-Dovf5NHduIVNZOBOp8AOKgJuVlg=" - }, - "har-validator": { - "version": "2.0.6", - "resolved": "https://registry.npmjs.org/har-validator/-/har-validator-2.0.6.tgz", - "integrity": "sha1-zcvAgYgmWtEZtqWnyKtw7s+10n0=", - "requires": { - "chalk": "1.1.3", - "commander": "2.11.0", - "is-my-json-valid": "2.16.0", - "pinkie-promise": "2.0.1" - } - }, - "has-ansi": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/has-ansi/-/has-ansi-2.0.0.tgz", - "integrity": "sha1-NPUEnOHs3ysGSa8+8k5F7TVBbZE=", + "glob": { + "version": "7.1.2", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.2.tgz", + "integrity": "sha512-MJTUg1kjuLeQCJ+ccE4Vpa6kKVXkPYJ2mOCQyUuKLcLQsdrMCpBPUi8qVE6+YuaJkozeA9NusTAw3hLr8Xe5EQ==", "requires": { - "ansi-regex": "2.1.1" - } - }, - "hasha": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/hasha/-/hasha-2.2.0.tgz", - "integrity": "sha1-eNfL/B5tZjA/55g3NlmEUXsvbuE=", - "requires": { - "is-stream": "1.1.0", - "pinkie-promise": "2.0.1" + "fs.realpath": "1.0.0", + "inflight": "1.0.6", + "inherits": "2.0.3", + "minimatch": "3.0.4", + "once": "1.4.0", + "path-is-absolute": "1.0.1" } }, - "hawk": { - "version": "3.1.3", - "resolved": "https://registry.npmjs.org/hawk/-/hawk-3.1.3.tgz", - "integrity": "sha1-B4REvXwWQLD+VA0sm3PVlnjo4cQ=", + "https-proxy-agent": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-2.1.1.tgz", + "integrity": "sha512-LK6tQUR/VOkTI6ygAfWUKKP95I+e6M1h7N3PncGu1CATHCnex+CAv9ttR0lbHu1Uk2PXm/WoAHFo6JCGwMjVMw==", "requires": { - "boom": "2.10.1", - "cryptiles": "2.0.5", - "hoek": "2.16.3", - "sntp": "1.0.9" + "agent-base": "4.1.2", + "debug": "3.1.0" } }, - "hoek": { - "version": "2.16.3", - "resolved": "https://registry.npmjs.org/hoek/-/hoek-2.16.3.tgz", - "integrity": "sha1-ILt0A9POo5jpHcRxCo/xuCdKJe0=" - }, - "http-signature": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/http-signature/-/http-signature-1.1.1.tgz", - "integrity": "sha1-33LiZwZs0Kxn+3at+OE0qPvPkb8=", + "inflight": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", + "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", "requires": { - "assert-plus": "0.2.0", - "jsprim": "1.4.0", - "sshpk": "1.13.1" + "once": "1.4.0", + "wrappy": "1.0.2" } }, "inherits": { @@ -339,134 +156,38 @@ "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=" }, - "is-my-json-valid": { - "version": "2.16.0", - "resolved": "https://registry.npmjs.org/is-my-json-valid/-/is-my-json-valid-2.16.0.tgz", - "integrity": "sha1-8Hndm/2uZe4gOKrorLyGqxCeNpM=", - "requires": { - "generate-function": "2.0.0", - "generate-object-property": "1.2.0", - "jsonpointer": "4.0.1", - "xtend": "4.0.1" - } - }, - "is-property": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/is-property/-/is-property-1.0.2.tgz", - "integrity": "sha1-V/4cTkhHTt1lsJkR8msc1Ald2oQ=" - }, - "is-stream": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-1.1.0.tgz", - "integrity": "sha1-EtSj3U5o4Lec6428hBc66A2RykQ=" - }, - "is-typedarray": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/is-typedarray/-/is-typedarray-1.0.0.tgz", - "integrity": "sha1-5HnICFjfDBsR3dppQPlgEfzaSpo=" - }, "isarray": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", "integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=" }, - "isexe": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", - "integrity": "sha1-6PvzdNxVb/iUehDcsFctYz8s+hA=" - }, - "isstream": { - "version": "0.1.2", - "resolved": "https://registry.npmjs.org/isstream/-/isstream-0.1.2.tgz", - "integrity": "sha1-R+Y/evVa+m+S4VAOaQ64uFKcCZo=" - }, - "jsbn": { - "version": "0.1.1", - "resolved": "https://registry.npmjs.org/jsbn/-/jsbn-0.1.1.tgz", - "integrity": "sha1-peZUwuWi3rXyAdls77yoDA7y9RM=", - "optional": true - }, "jsesc": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/jsesc/-/jsesc-1.3.0.tgz", "integrity": "sha1-RsP+yMGJKxKwgz25vHYiF226s0s=" }, - "json-schema": { - "version": "0.2.3", - "resolved": "https://registry.npmjs.org/json-schema/-/json-schema-0.2.3.tgz", - "integrity": "sha1-tIDIkuWaLwWVTOcnvT8qTogvnhM=" - }, - "json-stringify-safe": { - "version": "5.0.1", - "resolved": "https://registry.npmjs.org/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz", - "integrity": "sha1-Epai1Y/UXxmg9s4B1lcB4sc1tus=" - }, - "jsonfile": { - "version": "2.4.0", - "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-2.4.0.tgz", - "integrity": "sha1-NzaitCi4e72gzIO1P6PWM6NcKug=", - "requires": { - "graceful-fs": "4.1.11" - } - }, - "jsonpointer": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/jsonpointer/-/jsonpointer-4.0.1.tgz", - "integrity": "sha1-T9kss04OnbPInIYi7PUfm5eMbLk=" - }, - "jsprim": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/jsprim/-/jsprim-1.4.0.tgz", - "integrity": "sha1-o7h+QCmNjDgFUtjMdiigu5WiKRg=", - "requires": { - "assert-plus": "1.0.0", - "extsprintf": "1.0.2", - "json-schema": "0.2.3", - "verror": "1.3.6" - }, - "dependencies": { - "assert-plus": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/assert-plus/-/assert-plus-1.0.0.tgz", - "integrity": "sha1-8S4PPF13sLHN2RRpQuTpbB5N1SU=" - } - } - }, - "kew": { - "version": "0.7.0", - "resolved": "https://registry.npmjs.org/kew/-/kew-0.7.0.tgz", - "integrity": "sha1-edk9LTM2PW/dKXCzNdkUGtWR15s=" - }, - "klaw": { - "version": "1.3.1", - "resolved": "https://registry.npmjs.org/klaw/-/klaw-1.3.1.tgz", - "integrity": "sha1-QIhDO0azsbolnXh4XY6W9zugJDk=", - "requires": { - "graceful-fs": "4.1.11" - } - }, - "lodash": { - "version": "3.10.1", - "resolved": "https://registry.npmjs.org/lodash/-/lodash-3.10.1.tgz", - "integrity": "sha1-W/Rejkm6QYnhfUgnid/RW9FAt7Y=" + "mdn-data": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/mdn-data/-/mdn-data-1.0.0.tgz", + "integrity": "sha1-pp2dp2hHtNWDTBRl6iXAZTofv2Y=" }, - "mime-db": { - "version": "1.29.0", - "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.29.0.tgz", - "integrity": "sha1-SNJtI1WJZRcErFkWygYAGRQmaHg=" + "mime": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/mime/-/mime-1.6.0.tgz", + "integrity": "sha512-x0Vn8spI+wuJ1O6S7gnbaQg8Pxh4NNHb7KSINmEWKiPE4RKOplvijn+NkmYmmRgP68mc70j2EbeTFRsrswaQeg==" }, - "mime-types": { - "version": "2.1.16", - "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.16.tgz", - "integrity": "sha1-K4WKUuXs1RbbiXrCvodIeDBpjiM=", + "minimatch": { + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", + "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", "requires": { - "mime-db": "1.29.0" + "brace-expansion": "1.1.8" } }, "minimist": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz", - "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=" + "version": "0.0.8", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", + "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=" }, "mkdirp": { "version": "0.5.0", @@ -474,24 +195,25 @@ "integrity": "sha1-HXMHam35hs2TROFecfzAWkyavxI=", "requires": { "minimist": "0.0.8" - }, - "dependencies": { - "minimist": { - "version": "0.0.8", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", - "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=" - } } }, - "oauth-sign": { - "version": "0.8.2", - "resolved": "https://registry.npmjs.org/oauth-sign/-/oauth-sign-0.8.2.tgz", - "integrity": "sha1-Rqarfwrq2N6unsBWV4C31O/rnUM=" + "ms": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", + "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" }, - "os-tmpdir": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/os-tmpdir/-/os-tmpdir-1.0.2.tgz", - "integrity": "sha1-u+Z0BseaqFxc/sdm/lc0VV36EnQ=" + "once": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", + "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", + "requires": { + "wrappy": "1.0.2" + } + }, + "path-is-absolute": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", + "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=" }, "pend": { "version": "1.2.0", @@ -499,47 +221,15 @@ "integrity": "sha1-elfrVQpng/kRUzH89GY9XI4AelA=" }, "penthouse": { - "version": "0.11.5", - "resolved": "https://registry.npmjs.org/penthouse/-/penthouse-0.11.5.tgz", - "integrity": "sha1-/+y0LwrsYkhYWC8nLqLcIYGHyVI=", + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/penthouse/-/penthouse-1.3.0.tgz", + "integrity": "sha512-4Ex8KM4VKdW3avbuaNQfoyFpFnOXKHoX+zeCIL6zuQ7F2y+aHXNzG4rg3FtoLCh/M5So94SKEbAzBwAC97nRMg==", "requires": { - "apartment": "1.1.1", - "css": "git+https://github.com/pocketjoso/css.git#8ddea7e3cbc0a183ecf694a7a5fbc84326893893", "css-mediaquery": "0.1.2", + "css-tree": "1.0.0-alpha.26", + "debug": "3.1.0", "jsesc": "1.3.0", - "os-tmpdir": "1.0.2", - "phantomjs-prebuilt": "2.1.14", - "regenerator-runtime": "0.10.5", - "tmp": "0.0.31" - } - }, - "phantomjs-prebuilt": { - "version": "2.1.14", - "resolved": "https://registry.npmjs.org/phantomjs-prebuilt/-/phantomjs-prebuilt-2.1.14.tgz", - "integrity": "sha1-1T0xH8+30dCN2yQBRVjxGIxRbaA=", - "requires": { - "es6-promise": "4.0.5", - "extract-zip": "1.5.0", - "fs-extra": "1.0.0", - "hasha": "2.2.0", - "kew": "0.7.0", - "progress": "1.1.8", - "request": "2.79.0", - "request-progress": "2.0.1", - "which": "1.2.14" - } - }, - "pinkie": { - "version": "2.0.4", - "resolved": "https://registry.npmjs.org/pinkie/-/pinkie-2.0.4.tgz", - "integrity": "sha1-clVrgM+g1IqXToDnckjoDtT3+HA=" - }, - "pinkie-promise": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/pinkie-promise/-/pinkie-promise-2.0.1.tgz", - "integrity": "sha1-ITXW36ejWMBprJsXh3YogihFD/o=", - "requires": { - "pinkie": "2.0.4" + "puppeteer": "0.12.0" } }, "process-nextick-args": { @@ -548,228 +238,110 @@ "integrity": "sha1-FQ4gt1ZZCtP5EJPyWk8q2L/zC6M=" }, "progress": { - "version": "1.1.8", - "resolved": "https://registry.npmjs.org/progress/-/progress-1.1.8.tgz", - "integrity": "sha1-4mDHj2Fhzdmw5WzD4Khd4Xx6V74=" - }, - "punycode": { - "version": "1.4.1", - "resolved": "https://registry.npmjs.org/punycode/-/punycode-1.4.1.tgz", - "integrity": "sha1-wNWmOycYgArY4esPpSachN1BhF4=" + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/progress/-/progress-2.0.0.tgz", + "integrity": "sha1-ihvjZr+Pwj2yvSPxDG/pILQ4nR8=" }, - "qs": { - "version": "6.3.2", - "resolved": "https://registry.npmjs.org/qs/-/qs-6.3.2.tgz", - "integrity": "sha1-51vV9uJoEioqDgvaYwslUMFmUCw=" + "proxy-from-env": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.0.0.tgz", + "integrity": "sha1-M8UDmPcOp+uW0h97gXYwpVeRx+4=" + }, + "puppeteer": { + "version": "0.12.0", + "resolved": "https://registry.npmjs.org/puppeteer/-/puppeteer-0.12.0.tgz", + "integrity": "sha512-H/bylN7FccwbN7JZoSP+xRozxgJEDNy4uC4p727cyttKUVNXYjFuEMueJYHW0pblnrfLEH341SyFJVWhJMLxKQ==", + "requires": { + "debug": "2.6.9", + "extract-zip": "1.6.6", + "https-proxy-agent": "2.1.1", + "mime": "1.6.0", + "progress": "2.0.0", + "proxy-from-env": "1.0.0", + "rimraf": "2.6.2", + "ws": "3.3.3" + }, + "dependencies": { + "debug": { + "version": "2.6.9", + "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", + "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", + "requires": { + "ms": "2.0.0" + } + } + } }, "readable-stream": { - "version": "2.0.6", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.0.6.tgz", - "integrity": "sha1-j5A0HmilPMySh4jaz80Rs265t44=", + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.3.tgz", + "integrity": "sha512-m+qzzcn7KUxEmd1gMbchF+Y2eIUbieUaxkWtptyHywrX0rE8QEYqPC07Vuy4Wm32/xE16NcdBctb8S0Xe/5IeQ==", "requires": { "core-util-is": "1.0.2", "inherits": "2.0.3", "isarray": "1.0.0", "process-nextick-args": "1.0.7", - "string_decoder": "0.10.31", + "safe-buffer": "5.1.1", + "string_decoder": "1.0.3", "util-deprecate": "1.0.2" } }, - "regenerator-runtime": { - "version": "0.10.5", - "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.10.5.tgz", - "integrity": "sha1-M2w+/BIgrc7dosn6tntaeVWjNlg=" - }, - "request": { - "version": "2.79.0", - "resolved": "https://registry.npmjs.org/request/-/request-2.79.0.tgz", - "integrity": "sha1-Tf5b9r6LjNw3/Pk+BLZVd3InEN4=", + "rimraf": { + "version": "2.6.2", + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.6.2.tgz", + "integrity": "sha512-lreewLK/BlghmxtfH36YYVg1i8IAce4TI7oao75I1g245+6BctqTVQiBP3YUJ9C6DQOXJmkYR9X9fCLtCOJc5w==", "requires": { - "aws-sign2": "0.6.0", - "aws4": "1.6.0", - "caseless": "0.11.0", - "combined-stream": "1.0.5", - "extend": "3.0.1", - "forever-agent": "0.6.1", - "form-data": "2.1.4", - "har-validator": "2.0.6", - "hawk": "3.1.3", - "http-signature": "1.1.1", - "is-typedarray": "1.0.0", - "isstream": "0.1.2", - "json-stringify-safe": "5.0.1", - "mime-types": "2.1.16", - "oauth-sign": "0.8.2", - "qs": "6.3.2", - "stringstream": "0.0.5", - "tough-cookie": "2.3.2", - "tunnel-agent": "0.4.3", - "uuid": "3.1.0" + "glob": "7.1.2" } }, - "request-progress": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/request-progress/-/request-progress-2.0.1.tgz", - "integrity": "sha1-XTa7V5YcZzqlt4jbyBQf3yO0Tgg=", - "requires": { - "throttleit": "1.0.0" - } - }, - "resolve-url": { - "version": "0.2.1", - "resolved": "https://registry.npmjs.org/resolve-url/-/resolve-url-0.2.1.tgz", - "integrity": "sha1-LGN/53yJOv0qZj/iGqkIAGjiBSo=" - }, - "sntp": { - "version": "1.0.9", - "resolved": "https://registry.npmjs.org/sntp/-/sntp-1.0.9.tgz", - "integrity": "sha1-ZUEYTMkK7qbG57NeJlkIJEPGYZg=", - "requires": { - "hoek": "2.16.3" - } + "safe-buffer": { + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.1.tgz", + "integrity": "sha512-kKvNJn6Mm93gAczWVJg7wH+wGYWNrDHdWvpUmHyEsgCtIwwo3bqPtV4tR5tuPaUhTOo/kvhVwd8XwwOllGYkbg==" }, "source-map": { - "version": "0.1.43", - "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.1.43.tgz", - "integrity": "sha1-wkvBRspRfBRx9drL4lcbK3+eM0Y=", - "requires": { - "amdefine": "1.0.1" - } - }, - "source-map-resolve": { - "version": "0.3.1", - "resolved": "https://registry.npmjs.org/source-map-resolve/-/source-map-resolve-0.3.1.tgz", - "integrity": "sha1-YQ9hIqRFuN1RU1oqcbeD38Ekh2E=", - "requires": { - "atob": "1.1.3", - "resolve-url": "0.2.1", - "source-map-url": "0.3.0", - "urix": "0.1.0" - } - }, - "source-map-url": { - "version": "0.3.0", - "resolved": "https://registry.npmjs.org/source-map-url/-/source-map-url-0.3.0.tgz", - "integrity": "sha1-fsrxO1e80J2opAxdJp2zN5nUqvk=" - }, - "sshpk": { - "version": "1.13.1", - "resolved": "https://registry.npmjs.org/sshpk/-/sshpk-1.13.1.tgz", - "integrity": "sha1-US322mKHFEMW3EwY/hzx2UBzm+M=", - "requires": { - "asn1": "0.2.3", - "assert-plus": "1.0.0", - "bcrypt-pbkdf": "1.0.1", - "dashdash": "1.14.1", - "ecc-jsbn": "0.1.1", - "getpass": "0.1.7", - "jsbn": "0.1.1", - "tweetnacl": "0.14.5" - }, - "dependencies": { - "assert-plus": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/assert-plus/-/assert-plus-1.0.0.tgz", - "integrity": "sha1-8S4PPF13sLHN2RRpQuTpbB5N1SU=" - } - } + "version": "0.5.7", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.5.7.tgz", + "integrity": "sha1-igOdLRAh0i0eoUyA2OpGi6LvP8w=" }, "string_decoder": { - "version": "0.10.31", - "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz", - "integrity": "sha1-YuIDvEF2bGwoyfyEMB2rHFMQ+pQ=" - }, - "stringstream": { - "version": "0.0.5", - "resolved": "https://registry.npmjs.org/stringstream/-/stringstream-0.0.5.tgz", - "integrity": "sha1-TkhM1N5aC7vuGORjB3EKioFiGHg=" - }, - "strip-ansi": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz", - "integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=", + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.0.3.tgz", + "integrity": "sha512-4AH6Z5fzNNBcH+6XDMfA/BTt87skxqJlO0lAh3Dker5zThcAxG6mKz+iGu308UKoPPQ8Dcqx/4JhujzltRa+hQ==", "requires": { - "ansi-regex": "2.1.1" + "safe-buffer": "5.1.1" } }, - "supports-color": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-2.0.0.tgz", - "integrity": "sha1-U10EXOa2Nj+kARcIRimZXp3zJMc=" - }, - "throttleit": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/throttleit/-/throttleit-1.0.0.tgz", - "integrity": "sha1-nnhYNtr0Z0MUWlmEtiaNgoUorGw=" - }, - "tmp": { - "version": "0.0.31", - "resolved": "https://registry.npmjs.org/tmp/-/tmp-0.0.31.tgz", - "integrity": "sha1-jzirlDjhcxXl29izZX6L+yd65Kc=", - "requires": { - "os-tmpdir": "1.0.2" - } - }, - "tough-cookie": { - "version": "2.3.2", - "resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-2.3.2.tgz", - "integrity": "sha1-8IH3bkyFcg5sN6X6ztc3FQ2EByo=", - "requires": { - "punycode": "1.4.1" - } - }, - "tunnel-agent": { - "version": "0.4.3", - "resolved": "https://registry.npmjs.org/tunnel-agent/-/tunnel-agent-0.4.3.tgz", - "integrity": "sha1-Y3PbdpCf5XDgjXNYM2Xtgop07us=" - }, - "tweetnacl": { - "version": "0.14.5", - "resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-0.14.5.tgz", - "integrity": "sha1-WuaBd/GS1EViadEIr6k/+HQ/T2Q=", - "optional": true - }, "typedarray": { "version": "0.0.6", "resolved": "https://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz", "integrity": "sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=" }, - "urix": { - "version": "0.1.0", - "resolved": "https://registry.npmjs.org/urix/-/urix-0.1.0.tgz", - "integrity": "sha1-2pN/emLiH+wf0Y1Js1wpNQZ6bHI=" + "ultron": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/ultron/-/ultron-1.1.1.tgz", + "integrity": "sha512-UIEXBNeYmKptWH6z8ZnqTeS8fV74zG0/eRU9VGkpzz+LIJNs8W/zM/L+7ctCkRrgbNnnR0xxw4bKOr0cW0N0Og==" }, "util-deprecate": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", "integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=" }, - "uuid": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/uuid/-/uuid-3.1.0.tgz", - "integrity": "sha512-DIWtzUkw04M4k3bf1IcpS2tngXEL26YUD2M0tMDUpnUrz2hgzUBlD55a4FjdLGPvfHxS6uluGWvaVEqgBcVa+g==" - }, - "verror": { - "version": "1.3.6", - "resolved": "https://registry.npmjs.org/verror/-/verror-1.3.6.tgz", - "integrity": "sha1-z/XfEpRtKX0rqu+qJoniW+AcAFw=", - "requires": { - "extsprintf": "1.0.2" - } + "wrappy": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", + "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=" }, - "which": { - "version": "1.2.14", - "resolved": "https://registry.npmjs.org/which/-/which-1.2.14.tgz", - "integrity": "sha1-mofEN48D6CfOyvGs31bHNsAcFOU=", + "ws": { + "version": "3.3.3", + "resolved": "https://registry.npmjs.org/ws/-/ws-3.3.3.tgz", + "integrity": "sha512-nnWLa/NwZSt4KQJu51MYlCcSQ5g7INpOrOMt4XV8j4dqTXdmlUmSHQ8/oLC069ckre0fRsgfvsKwbTdtKLCDkA==", "requires": { - "isexe": "2.0.0" + "async-limiter": "1.0.0", + "safe-buffer": "5.1.1", + "ultron": "1.1.1" } }, - "xtend": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.1.tgz", - "integrity": "sha1-pcbVMr5lbiPbgg77lDofBJmNY68=" - }, "yauzl": { "version": "2.4.1", "resolved": "https://registry.npmjs.org/yauzl/-/yauzl-2.4.1.tgz", From 60a6f9d24734f284a3450b5e90727dd9709e6e60 Mon Sep 17 00:00:00 2001 From: Michael Misshore Date: Sat, 6 Jan 2018 13:13:25 -0600 Subject: [PATCH 37/81] Ensure the testing/dev environment uses the latest version of the gem --- docker/ruby/startup.dev | 1 + 1 file changed, 1 insertion(+) diff --git a/docker/ruby/startup.dev b/docker/ruby/startup.dev index f9ddc5f..c671745 100644 --- a/docker/ruby/startup.dev +++ b/docker/ruby/startup.dev @@ -1,5 +1,6 @@ #!/bin/bash bundle check || bundle install +bundle update critical-path-css-rails bundle exec rackup --host 0.0.0.0 From b7382cf5bec4ead58750c12efcb2b87f38464af8 Mon Sep 17 00:00:00 2001 From: Michael Misshore Date: Sat, 6 Jan 2018 13:50:06 -0600 Subject: [PATCH 38/81] Update documentation and Dockerfile to reflect necessary packages needed for Penthouse --- README.md | 25 ++++++++++++++++--------- docker/ruby/Dockerfile | 3 +++ 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 7431bb9..a1131f6 100644 --- a/README.md +++ b/README.md @@ -2,19 +2,29 @@ Only load the CSS you need for the initial viewport in Rails! -This gem give you the ability to load only the CSS you *need* on an initial page view. This gives you blazin' fast rending as there's no initial network call to grab your application's CSS. +This gem gives you the ability to load only the CSS you *need* on an initial page view. This gives you blazin' fast rending as there's no initial network call to grab your application's CSS. This gem assumes that you'll load the rest of the CSS asyncronously. At the moment, the suggested way is to use the [loadcss-rails](https://github.com/michael-misshore/loadcss-rails) gem. This gem uses [Penthouse](https://github.com/pocketjoso/penthouse) to generate the critical CSS. -## Upgrading to the Latest Release +## Dependency Requirements for / Upgrading to the Latest Release -Upgrade instructions from each version are included below. +### For 1.0.0 or later +To maintain the latest version of Penthouse, this gem depends on NodeJS and NVM to be installed on the system. + +### For 2.0.0 or later +This gem may require additional packages to be installed to run Chrome headless. Per the Penthouse documentation, this may be all you need: + +``` +sudo apt-get install libnss3 +``` + +However, more packages may need to be installed depending on your OS distribution which can be found via [this answer](https://github.com/GoogleChrome/puppeteer/issues/404#issuecomment-323555784) ## Installation -Add `critical-path-css-rails` to your Gemfile: +After reviewing the dependency requirements, add `critical-path-css-rails` to your Gemfile: ``` gem 'critical-path-css-rails', '~> 2.3.0' @@ -110,9 +120,6 @@ Careful use of these methods allows the developer to generate critical path CSS A user can use these methods to [dynamically generate critical path CSS](https://gist.github.com/taranda/1597e97ccf24c978b59aef9249666c77) without using the `rake critical_path_css:generate` rake task and without hardcoding the application's routes into `config/critical_path_css.yml`. See [this Gist](https://gist.github.com/taranda/1597e97ccf24c978b59aef9249666c77) for an example of such an implementation. -## Upgrading from version 0.X.X to 1.0.0 or later -To maintain the latest version of Penthouse, this gem now depends on NodeJS and NVM to be installed on the system. - ## Upgrading from a version earlier than 0.3.0 The latest version of Critcal Path CSS Rails changes the functionality of the `generate` method. In past versions, @@ -124,10 +131,10 @@ Developers upgrading from versions prior to 0.3.0 will need to replace `Critical rails generate critical_path_css:install ``` -Answer 'Y' when prompted to overwrite `critical_path_css.rake`. However, overwriting `critical_path_css.yml` is not necessary and not recommended. +Answer 'Y' when prompted to overwrite `critical_path_css.rake`. However, overwriting `critical_path_css.yml` is not recommend nor necessary. -## Testing +## Testing / Development This gem is to be tested inside of docker/docker-compose. [Combustion](https://github.com/pat/combustion), alongside rspec-rails and capybara, are the primary components for testing. To run the test, you'll need to have [Docker](https://docs.docker.com/engine/installation) installed. Once installed, run the following commands in the gem's root to build, run, and shell into the docker container. diff --git a/docker/ruby/Dockerfile b/docker/ruby/Dockerfile index 27d32d9..4376437 100644 --- a/docker/ruby/Dockerfile +++ b/docker/ruby/Dockerfile @@ -4,6 +4,9 @@ FROM ruby:2.5.0 RUN curl -sL https://deb.nodesource.com/setup_8.x | bash - RUN apt-get update && apt-get install -y build-essential libpq-dev nodejs npm +# Install Penthouse JS Dependencies +RUN apt-get install -y libpangocairo-1.0-0 libx11-xcb1 libxcomposite1 libxcursor1 libxdamage1 libxi6 libxtst6 libnss3 libcups2 libxss1 libxrandr2 libgconf2-4 libasound2 libatk1.0-0 libgtk-3-0 + RUN npm cache clean -f RUN npm install -g n RUN n 8.9.3 From 938831aa0018f2a51a2ed26471f039fef1253a70 Mon Sep 17 00:00:00 2001 From: Michael Misshore Date: Sat, 6 Jan 2018 13:50:19 -0600 Subject: [PATCH 39/81] Adjust tests for lates version of Penthouse --- spec/features/generate_and_fetch_critical_css_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/features/generate_and_fetch_critical_css_spec.rb b/spec/features/generate_and_fetch_critical_css_spec.rb index 4c0aeba..91ce7fb 100644 --- a/spec/features/generate_and_fetch_critical_css_spec.rb +++ b/spec/features/generate_and_fetch_critical_css_spec.rb @@ -10,7 +10,7 @@ it 'displays the correct critical CSS' do visit route - expect(page).to have_content 'color: red;' + expect(page).to have_content 'p{color:red}' end end end From 90a8bb96248c15ff228cc5b40cdb282f26ffab05 Mon Sep 17 00:00:00 2001 From: Michael Misshore Date: Sat, 6 Jan 2018 13:52:18 -0600 Subject: [PATCH 40/81] Fix typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a1131f6..7d338f2 100644 --- a/README.md +++ b/README.md @@ -131,7 +131,7 @@ Developers upgrading from versions prior to 0.3.0 will need to replace `Critical rails generate critical_path_css:install ``` -Answer 'Y' when prompted to overwrite `critical_path_css.rake`. However, overwriting `critical_path_css.yml` is not recommend nor necessary. +Answer 'Y' when prompted to overwrite `critical_path_css.rake`. However, overwriting `critical_path_css.yml` is not recommended nor necessary. ## Testing / Development From 75390ce14e5c75f94660d001481e06f0931fec02 Mon Sep 17 00:00:00 2001 From: Michael Misshore Date: Thu, 3 May 2018 09:19:04 -0500 Subject: [PATCH 41/81] Upgrade penthouse to 1.4.2 --- lib/critical_path_css/rails/version.rb | 2 +- package-lock.json | 108 ++++++++++++------------- package.json | 4 +- 3 files changed, 57 insertions(+), 57 deletions(-) diff --git a/lib/critical_path_css/rails/version.rb b/lib/critical_path_css/rails/version.rb index 7a86f6b..dfebb31 100644 --- a/lib/critical_path_css/rails/version.rb +++ b/lib/critical_path_css/rails/version.rb @@ -1,5 +1,5 @@ module CriticalPathCSS module Rails - VERSION = '2.3.0'.freeze + VERSION = '2.4.0'.freeze end end diff --git a/package-lock.json b/package-lock.json index 570be9b..2a77df2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,13 +1,13 @@ { "name": "critical-path-css-rails", - "version": "2.3.0", + "version": "2.4.0", "lockfileVersion": 1, "requires": true, "dependencies": { "agent-base": { - "version": "4.1.2", - "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-4.1.2.tgz", - "integrity": "sha512-VE6QoEdaugY86BohRtfGmTDabxdU5sCKOkbcPA6PXKJsRzEi/7A3RCTxJal1ft/4qSfPht5/iQLhMh/wzSkkNw==", + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-4.2.0.tgz", + "integrity": "sha512-c+R/U5X+2zz2+UCrCFv6odQzJdoqI+YecuhnAJLa1zYaMc13zPfwMwZrr91Pd1DYNo/yPRbiM4WVf9whgwFsIg==", "requires": { "es6-promisify": "5.0.0" } @@ -23,9 +23,9 @@ "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=" }, "brace-expansion": { - "version": "1.1.8", - "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.8.tgz", - "integrity": "sha1-wHshHHyVLsH479Uad+8NHTmQopI=", + "version": "1.1.11", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", + "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", "requires": { "balanced-match": "1.0.0", "concat-map": "0.0.1" @@ -42,7 +42,7 @@ "integrity": "sha1-CqxmL9Ur54lk1VMvaUeE5wEQrPc=", "requires": { "inherits": "2.0.3", - "readable-stream": "2.3.3", + "readable-stream": "2.3.6", "typedarray": "0.0.6" } }, @@ -57,11 +57,11 @@ "integrity": "sha1-aiw3NEkoYYYxxUvTPO3TAdoYvqA=" }, "css-tree": { - "version": "1.0.0-alpha.26", - "resolved": "https://registry.npmjs.org/css-tree/-/css-tree-1.0.0-alpha.26.tgz", - "integrity": "sha1-aQvuNFj7W2twAFU5g8jDCHbaCz4=", + "version": "1.0.0-alpha.28", + "resolved": "https://registry.npmjs.org/css-tree/-/css-tree-1.0.0-alpha.28.tgz", + "integrity": "sha512-joNNW1gCp3qFFzj4St6zk+Wh/NBv0vM5YbEreZk0SD4S23S+1xBKb6cLDg2uj4P4k/GUMlIm6cKIDqIG+vdt0w==", "requires": { - "mdn-data": "1.0.0", + "mdn-data": "1.1.2", "source-map": "0.5.7" } }, @@ -74,16 +74,16 @@ } }, "es6-promise": { - "version": "4.2.2", - "resolved": "https://registry.npmjs.org/es6-promise/-/es6-promise-4.2.2.tgz", - "integrity": "sha512-LSas5vsuA6Q4nEdf9wokY5/AJYXry98i0IzXsv49rYsgDGDNDPbqAYR1Pe23iFxygfbGZNR/5VrHXBCh2BhvUQ==" + "version": "4.2.4", + "resolved": "https://registry.npmjs.org/es6-promise/-/es6-promise-4.2.4.tgz", + "integrity": "sha512-/NdNZVJg+uZgtm9eS3O6lrOLYmQag2DjdEXuPaHlZ6RuVqgqaVZfgYCepEIKsLqwdQArOPtC3XzRLqGGfT8KQQ==" }, "es6-promisify": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/es6-promisify/-/es6-promisify-5.0.0.tgz", "integrity": "sha1-UQnWLz5W6pZ8S2NQWu8IKRyKUgM=", "requires": { - "es6-promise": "4.2.2" + "es6-promise": "4.2.4" } }, "extract-zip": { @@ -134,11 +134,11 @@ } }, "https-proxy-agent": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-2.1.1.tgz", - "integrity": "sha512-LK6tQUR/VOkTI6ygAfWUKKP95I+e6M1h7N3PncGu1CATHCnex+CAv9ttR0lbHu1Uk2PXm/WoAHFo6JCGwMjVMw==", + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-2.2.1.tgz", + "integrity": "sha512-HPCTS1LW51bcyMYbxUIOO4HEOlQ1/1qRaFWcyxvwaqUS9TY88aoEuHUY33kuAh1YhVVaDQhLZsnPd+XNARWZlQ==", "requires": { - "agent-base": "4.1.2", + "agent-base": "4.2.0", "debug": "3.1.0" } }, @@ -162,14 +162,14 @@ "integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=" }, "jsesc": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/jsesc/-/jsesc-1.3.0.tgz", - "integrity": "sha1-RsP+yMGJKxKwgz25vHYiF226s0s=" + "version": "2.5.1", + "resolved": "https://registry.npmjs.org/jsesc/-/jsesc-2.5.1.tgz", + "integrity": "sha1-5CGiqOINawgZ3yiQj3glJrlt0f4=" }, "mdn-data": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/mdn-data/-/mdn-data-1.0.0.tgz", - "integrity": "sha1-pp2dp2hHtNWDTBRl6iXAZTofv2Y=" + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/mdn-data/-/mdn-data-1.1.2.tgz", + "integrity": "sha512-HUqqf4U+XdKomJXe2Chw+b1zPXFRUZ3bfUbrGLQ2TGwMOBRULuTHI9geusGqRL4WzsusnLLxYAxV4f/F/8wV+g==" }, "mime": { "version": "1.6.0", @@ -181,7 +181,7 @@ "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", "requires": { - "brace-expansion": "1.1.8" + "brace-expansion": "1.1.11" } }, "minimist": { @@ -221,21 +221,21 @@ "integrity": "sha1-elfrVQpng/kRUzH89GY9XI4AelA=" }, "penthouse": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/penthouse/-/penthouse-1.3.0.tgz", - "integrity": "sha512-4Ex8KM4VKdW3avbuaNQfoyFpFnOXKHoX+zeCIL6zuQ7F2y+aHXNzG4rg3FtoLCh/M5So94SKEbAzBwAC97nRMg==", + "version": "1.4.2", + "resolved": "https://registry.npmjs.org/penthouse/-/penthouse-1.4.2.tgz", + "integrity": "sha512-GhpOTm1SPlX+Xm0MlWKB8MhNgIVC/u3dXxYA9gib/SxnDfBKMGOouQk7eRHPAqDQS6nRgjkd3idsIu1W1eqwiw==", "requires": { "css-mediaquery": "0.1.2", - "css-tree": "1.0.0-alpha.26", + "css-tree": "1.0.0-alpha.28", "debug": "3.1.0", - "jsesc": "1.3.0", - "puppeteer": "0.12.0" + "jsesc": "2.5.1", + "puppeteer": "1.0.0" } }, "process-nextick-args": { - "version": "1.0.7", - "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-1.0.7.tgz", - "integrity": "sha1-FQ4gt1ZZCtP5EJPyWk8q2L/zC6M=" + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.0.tgz", + "integrity": "sha512-MtEC1TqN0EU5nephaJ4rAtThHtC86dNN9qCuEhtshvpVBkAW5ZO7BASN9REnF9eoXGcRub+pFuKEpOHE+HbEMw==" }, "progress": { "version": "2.0.0", @@ -248,13 +248,13 @@ "integrity": "sha1-M8UDmPcOp+uW0h97gXYwpVeRx+4=" }, "puppeteer": { - "version": "0.12.0", - "resolved": "https://registry.npmjs.org/puppeteer/-/puppeteer-0.12.0.tgz", - "integrity": "sha512-H/bylN7FccwbN7JZoSP+xRozxgJEDNy4uC4p727cyttKUVNXYjFuEMueJYHW0pblnrfLEH341SyFJVWhJMLxKQ==", + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/puppeteer/-/puppeteer-1.0.0.tgz", + "integrity": "sha512-e00NMdUL32YhBcua9OkVXHgyDEMBWJhDXkYNv0pyKRU1Z1OrsRm5zCpppAdxAsBI+/MJBspFNfOUZuZ24qPGMQ==", "requires": { "debug": "2.6.9", "extract-zip": "1.6.6", - "https-proxy-agent": "2.1.1", + "https-proxy-agent": "2.2.1", "mime": "1.6.0", "progress": "2.0.0", "proxy-from-env": "1.0.0", @@ -273,16 +273,16 @@ } }, "readable-stream": { - "version": "2.3.3", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.3.tgz", - "integrity": "sha512-m+qzzcn7KUxEmd1gMbchF+Y2eIUbieUaxkWtptyHywrX0rE8QEYqPC07Vuy4Wm32/xE16NcdBctb8S0Xe/5IeQ==", + "version": "2.3.6", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.6.tgz", + "integrity": "sha512-tQtKA9WIAhBF3+VLAseyMqZeBjW0AHJoxOtYqSUZNJxauErmLbVm2FW1y+J/YA9dUrAC39ITejlZWhVIwawkKw==", "requires": { "core-util-is": "1.0.2", "inherits": "2.0.3", "isarray": "1.0.0", - "process-nextick-args": "1.0.7", - "safe-buffer": "5.1.1", - "string_decoder": "1.0.3", + "process-nextick-args": "2.0.0", + "safe-buffer": "5.1.2", + "string_decoder": "1.1.1", "util-deprecate": "1.0.2" } }, @@ -295,9 +295,9 @@ } }, "safe-buffer": { - "version": "5.1.1", - "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.1.tgz", - "integrity": "sha512-kKvNJn6Mm93gAczWVJg7wH+wGYWNrDHdWvpUmHyEsgCtIwwo3bqPtV4tR5tuPaUhTOo/kvhVwd8XwwOllGYkbg==" + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", + "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==" }, "source-map": { "version": "0.5.7", @@ -305,11 +305,11 @@ "integrity": "sha1-igOdLRAh0i0eoUyA2OpGi6LvP8w=" }, "string_decoder": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.0.3.tgz", - "integrity": "sha512-4AH6Z5fzNNBcH+6XDMfA/BTt87skxqJlO0lAh3Dker5zThcAxG6mKz+iGu308UKoPPQ8Dcqx/4JhujzltRa+hQ==", + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz", + "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==", "requires": { - "safe-buffer": "5.1.1" + "safe-buffer": "5.1.2" } }, "typedarray": { @@ -338,7 +338,7 @@ "integrity": "sha512-nnWLa/NwZSt4KQJu51MYlCcSQ5g7INpOrOMt4XV8j4dqTXdmlUmSHQ8/oLC069ckre0fRsgfvsKwbTdtKLCDkA==", "requires": { "async-limiter": "1.0.0", - "safe-buffer": "5.1.1", + "safe-buffer": "5.1.2", "ultron": "1.1.1" } }, diff --git a/package.json b/package.json index 7318be5..2c621a0 100644 --- a/package.json +++ b/package.json @@ -1,13 +1,13 @@ { "name": "critical-path-css-rails", - "version": "2.3.0", + "version": "2.4.0", "description": "NPM dependencies of critical-path-css-rails", "private": true, "directories": { "lib": "lib" }, "dependencies": { - "penthouse": "=1.3.0" + "penthouse": "=1.4.2" }, "license": "MIT" } From 4a53a418267fd2344dacbc471bc86a9ea0a994ad Mon Sep 17 00:00:00 2001 From: Michael Misshore Date: Thu, 3 May 2018 09:22:53 -0500 Subject: [PATCH 42/81] Update README to 2.4.0 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7d338f2..3b5fe7a 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ However, more packages may need to be installed depending on your OS distributio After reviewing the dependency requirements, add `critical-path-css-rails` to your Gemfile: ``` -gem 'critical-path-css-rails', '~> 2.3.0' +gem 'critical-path-css-rails', '~> 2.4.0' ``` Download and install by running: From 3e06e25429d93fbafc53880e03f797817e30e544 Mon Sep 17 00:00:00 2001 From: Michael Misshore Date: Sat, 16 Jun 2018 11:07:33 -0500 Subject: [PATCH 43/81] Update Penthouse to 1.6.0 --- lib/critical_path_css/rails/version.rb | 2 +- package-lock.json | 89 +++++++++++--------------- package.json | 2 +- 3 files changed, 41 insertions(+), 52 deletions(-) diff --git a/lib/critical_path_css/rails/version.rb b/lib/critical_path_css/rails/version.rb index dfebb31..ebfb91a 100644 --- a/lib/critical_path_css/rails/version.rb +++ b/lib/critical_path_css/rails/version.rb @@ -1,5 +1,5 @@ module CriticalPathCSS module Rails - VERSION = '2.4.0'.freeze + VERSION = '2.6.0'.freeze end end diff --git a/package-lock.json b/package-lock.json index 2a77df2..fd910d2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -31,16 +31,22 @@ "concat-map": "0.0.1" } }, + "buffer-from": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.0.tgz", + "integrity": "sha512-c5mRlguI/Pe2dSZmpER62rSCu0ryKmWddzRYsuXc50U2/g8jMOulc31VZMa4mYx31U5xsmSOpDCgH88Vl9cDGQ==" + }, "concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=" }, "concat-stream": { - "version": "1.6.0", - "resolved": "https://registry.npmjs.org/concat-stream/-/concat-stream-1.6.0.tgz", - "integrity": "sha1-CqxmL9Ur54lk1VMvaUeE5wEQrPc=", + "version": "1.6.2", + "resolved": "https://registry.npmjs.org/concat-stream/-/concat-stream-1.6.2.tgz", + "integrity": "sha512-27HBghJxjiZtIk3Ycvn/4kbJk/1uZuJFfuPEns6LaEvpvG1f0hTea8lilrouyo9mVc2GWdcEZ8OLoGmSADlrCw==", "requires": { + "buffer-from": "1.1.0", "inherits": "2.0.3", "readable-stream": "2.3.6", "typedarray": "0.0.6" @@ -61,7 +67,7 @@ "resolved": "https://registry.npmjs.org/css-tree/-/css-tree-1.0.0-alpha.28.tgz", "integrity": "sha512-joNNW1gCp3qFFzj4St6zk+Wh/NBv0vM5YbEreZk0SD4S23S+1xBKb6cLDg2uj4P4k/GUMlIm6cKIDqIG+vdt0w==", "requires": { - "mdn-data": "1.1.2", + "mdn-data": "1.1.4", "source-map": "0.5.7" } }, @@ -87,13 +93,13 @@ } }, "extract-zip": { - "version": "1.6.6", - "resolved": "https://registry.npmjs.org/extract-zip/-/extract-zip-1.6.6.tgz", - "integrity": "sha1-EpDt6NINCHK0Kf0/NRyhKOxe+Fw=", + "version": "1.6.7", + "resolved": "https://registry.npmjs.org/extract-zip/-/extract-zip-1.6.7.tgz", + "integrity": "sha1-qEC0uK9kAyZMjbV/Txp0Mz74H+k=", "requires": { - "concat-stream": "1.6.0", + "concat-stream": "1.6.2", "debug": "2.6.9", - "mkdirp": "0.5.0", + "mkdirp": "0.5.1", "yauzl": "2.4.1" }, "dependencies": { @@ -167,14 +173,14 @@ "integrity": "sha1-5CGiqOINawgZ3yiQj3glJrlt0f4=" }, "mdn-data": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/mdn-data/-/mdn-data-1.1.2.tgz", - "integrity": "sha512-HUqqf4U+XdKomJXe2Chw+b1zPXFRUZ3bfUbrGLQ2TGwMOBRULuTHI9geusGqRL4WzsusnLLxYAxV4f/F/8wV+g==" + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/mdn-data/-/mdn-data-1.1.4.tgz", + "integrity": "sha512-FSYbp3lyKjyj3E7fMl6rYvUdX0FBXaluGqlFoYESWQlyUTq8R+wp0rkFxoYFqZlHCvsUXGjyJmLQSnXToYhOSA==" }, "mime": { - "version": "1.6.0", - "resolved": "https://registry.npmjs.org/mime/-/mime-1.6.0.tgz", - "integrity": "sha512-x0Vn8spI+wuJ1O6S7gnbaQg8Pxh4NNHb7KSINmEWKiPE4RKOplvijn+NkmYmmRgP68mc70j2EbeTFRsrswaQeg==" + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/mime/-/mime-2.3.1.tgz", + "integrity": "sha512-OEUllcVoydBHGN1z84yfQDimn58pZNNNXgZlHXSboxMlFvgI6MXSWpWKpFRra7H1HxpVhHTkrghfRW49k6yjeg==" }, "minimatch": { "version": "3.0.4", @@ -190,9 +196,9 @@ "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=" }, "mkdirp": { - "version": "0.5.0", - "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.0.tgz", - "integrity": "sha1-HXMHam35hs2TROFecfzAWkyavxI=", + "version": "0.5.1", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz", + "integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=", "requires": { "minimist": "0.0.8" } @@ -221,15 +227,15 @@ "integrity": "sha1-elfrVQpng/kRUzH89GY9XI4AelA=" }, "penthouse": { - "version": "1.4.2", - "resolved": "https://registry.npmjs.org/penthouse/-/penthouse-1.4.2.tgz", - "integrity": "sha512-GhpOTm1SPlX+Xm0MlWKB8MhNgIVC/u3dXxYA9gib/SxnDfBKMGOouQk7eRHPAqDQS6nRgjkd3idsIu1W1eqwiw==", + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/penthouse/-/penthouse-1.6.0.tgz", + "integrity": "sha512-fQ2ylSTM7X51b10kIF9G1Esq4G/bmWj/TSIzxNyMO8x0It3hAqBi78xXdYmMRRPB3k57oJp0cjGHrYMgqBcHSQ==", "requires": { "css-mediaquery": "0.1.2", "css-tree": "1.0.0-alpha.28", "debug": "3.1.0", "jsesc": "2.5.1", - "puppeteer": "1.0.0" + "puppeteer": "1.5.0" } }, "process-nextick-args": { @@ -248,28 +254,18 @@ "integrity": "sha1-M8UDmPcOp+uW0h97gXYwpVeRx+4=" }, "puppeteer": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/puppeteer/-/puppeteer-1.0.0.tgz", - "integrity": "sha512-e00NMdUL32YhBcua9OkVXHgyDEMBWJhDXkYNv0pyKRU1Z1OrsRm5zCpppAdxAsBI+/MJBspFNfOUZuZ24qPGMQ==", + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/puppeteer/-/puppeteer-1.5.0.tgz", + "integrity": "sha512-eELwFtFxL+uhmg4jPZOZXzSrPEYy4CaYQNbcchBbfxY+KjMpnv6XGf/aYWaQG49OTpfi2/DMziXtDM8XuJgoUA==", "requires": { - "debug": "2.6.9", - "extract-zip": "1.6.6", + "debug": "3.1.0", + "extract-zip": "1.6.7", "https-proxy-agent": "2.2.1", - "mime": "1.6.0", + "mime": "2.3.1", "progress": "2.0.0", "proxy-from-env": "1.0.0", "rimraf": "2.6.2", - "ws": "3.3.3" - }, - "dependencies": { - "debug": { - "version": "2.6.9", - "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", - "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", - "requires": { - "ms": "2.0.0" - } - } + "ws": "5.2.0" } }, "readable-stream": { @@ -317,11 +313,6 @@ "resolved": "https://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz", "integrity": "sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=" }, - "ultron": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/ultron/-/ultron-1.1.1.tgz", - "integrity": "sha512-UIEXBNeYmKptWH6z8ZnqTeS8fV74zG0/eRU9VGkpzz+LIJNs8W/zM/L+7ctCkRrgbNnnR0xxw4bKOr0cW0N0Og==" - }, "util-deprecate": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", @@ -333,13 +324,11 @@ "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=" }, "ws": { - "version": "3.3.3", - "resolved": "https://registry.npmjs.org/ws/-/ws-3.3.3.tgz", - "integrity": "sha512-nnWLa/NwZSt4KQJu51MYlCcSQ5g7INpOrOMt4XV8j4dqTXdmlUmSHQ8/oLC069ckre0fRsgfvsKwbTdtKLCDkA==", + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/ws/-/ws-5.2.0.tgz", + "integrity": "sha512-c18dMeW+PEQdDFzkhDsnBAlS4Z8KGStBQQUcQ5mf7Nf689jyGk0594L+i9RaQuf4gog6SvWLJorz2NfSaqxZ7w==", "requires": { - "async-limiter": "1.0.0", - "safe-buffer": "5.1.2", - "ultron": "1.1.1" + "async-limiter": "1.0.0" } }, "yauzl": { diff --git a/package.json b/package.json index 2c621a0..5dd2a54 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "lib": "lib" }, "dependencies": { - "penthouse": "=1.4.2" + "penthouse": "=1.6.0" }, "license": "MIT" } From 2deb0b2361a205c4f951fda5a3e29d9360db1648 Mon Sep 17 00:00:00 2001 From: Michael Misshore Date: Sat, 16 Jun 2018 11:10:32 -0500 Subject: [PATCH 44/81] Update readme and package.json with correct gem version --- README.md | 2 +- package-lock.json | 2 +- package.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 3b5fe7a..9b354fb 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ However, more packages may need to be installed depending on your OS distributio After reviewing the dependency requirements, add `critical-path-css-rails` to your Gemfile: ``` -gem 'critical-path-css-rails', '~> 2.4.0' +gem 'critical-path-css-rails', '~> 2.6.0' ``` Download and install by running: diff --git a/package-lock.json b/package-lock.json index fd910d2..50654c0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "critical-path-css-rails", - "version": "2.4.0", + "version": "2.6.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 5dd2a54..a030f5f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "critical-path-css-rails", - "version": "2.4.0", + "version": "2.6.0", "description": "NPM dependencies of critical-path-css-rails", "private": true, "directories": { From 4c58d70b0907f0d4e09d8642f56d8457e0316fad Mon Sep 17 00:00:00 2001 From: Randall Reed Date: Fri, 22 Jun 2018 15:55:45 -0400 Subject: [PATCH 45/81] Support multiple css paths * Ensure only one css_path configuration is used * Raise error if length of css_paths does not match routes * Add comment in config file about css_paths --- lib/config/critical_path_css.yml | 3 + lib/critical_path_css/configuration.rb | 4 + lib/critical_path_css/css_fetcher.rb | 9 +- lib/critical_path_css/rails/config_loader.rb | 19 ++- lib/critical_path_css/rails/version.rb | 2 +- .../lib/critical_path_css/css_fetcher_spec.rb | 63 +++++++++ .../rails/config_loader_spec.rb | 125 ++++++++++++++++++ 7 files changed, 219 insertions(+), 6 deletions(-) create mode 100644 spec/lib/critical_path_css/css_fetcher_spec.rb create mode 100644 spec/lib/critical_path_css/rails/config_loader_spec.rb diff --git a/lib/config/critical_path_css.yml b/lib/config/critical_path_css.yml index e916570..5317754 100644 --- a/lib/config/critical_path_css.yml +++ b/lib/config/critical_path_css.yml @@ -3,6 +3,9 @@ defaults: &defaults manifest_name: application # Else provide the relative path of your CSS file from the /public directory # css_path: /path/to/css/from/public/main.css + # Or provide a separate path for each route + # css_paths: + # - /path/to/css/from/public/main.css routes: - / diff --git a/lib/critical_path_css/configuration.rb b/lib/critical_path_css/configuration.rb index b46669c..b8865ff 100644 --- a/lib/critical_path_css/configuration.rb +++ b/lib/critical_path_css/configuration.rb @@ -13,6 +13,10 @@ def css_path @config['css_path'] end + def css_paths + @config['css_paths'] + end + def manifest_name @config['manifest_name'] end diff --git a/lib/critical_path_css/css_fetcher.rb b/lib/critical_path_css/css_fetcher.rb index 680b7c9..3ead1a2 100644 --- a/lib/critical_path_css/css_fetcher.rb +++ b/lib/critical_path_css/css_fetcher.rb @@ -10,7 +10,10 @@ def initialize(config) end def fetch - @config.routes.map { |route| [route, css_for_route(route)] }.to_h + @config.routes.map.with_index { |route, index| + css_path = @config.css_paths[index].present? ? @config.css_paths[index] : @config.css_path + [route, css_for_route(route, css_path)] + }.to_h end def fetch_route(route) @@ -19,10 +22,10 @@ def fetch_route(route) protected - def css_for_route(route) + def css_for_route(route, css_path) options = { 'url' => @config.base_url + route, - 'css' => @config.css_path, + 'css' => css_path, ## optional params # viewport dimensions 'width' => 1300, diff --git a/lib/critical_path_css/rails/config_loader.rb b/lib/critical_path_css/rails/config_loader.rb index bbab1ba..ee4d00d 100644 --- a/lib/critical_path_css/rails/config_loader.rb +++ b/lib/critical_path_css/rails/config_loader.rb @@ -5,12 +5,19 @@ class ConfigLoader def load config = YAML.safe_load(ERB.new(File.read(configuration_file_path)).result, [], [], true)[::Rails.env] - config['css_path'] = "#{::Rails.root}/public" + ( + validate_css_path config + if config['css_path'] + config['css_path'] = "#{::Rails.root}/public" + ( config['css_path'] || ActionController::Base.helpers.stylesheet_path( config['manifest_name'], host: '' ) - ) + ) + config['css_paths'] = [] + else + config['css_path'] = '' + config['css_paths'] = config['css_paths'].collect { |path| "#{::Rails.root}/public#{path}" } + end config end @@ -19,6 +26,14 @@ def load def configuration_file_path @configuration_file_path ||= ::Rails.root.join('config', CONFIGURATION_FILENAME) end + + def validate_css_path(config) + if config['css_path'] && config['css_paths'] + raise LoadError, 'Cannot specify both css_path and css_paths' + elsif config['css_paths'] && config['css_paths'].length != config['routes'].length + raise LoadError, 'Must specify css_paths for each route' + end + end end end end diff --git a/lib/critical_path_css/rails/version.rb b/lib/critical_path_css/rails/version.rb index ebfb91a..58e0b8b 100644 --- a/lib/critical_path_css/rails/version.rb +++ b/lib/critical_path_css/rails/version.rb @@ -1,5 +1,5 @@ module CriticalPathCSS module Rails - VERSION = '2.6.0'.freeze + VERSION = '2.7.0'.freeze end end diff --git a/spec/lib/critical_path_css/css_fetcher_spec.rb b/spec/lib/critical_path_css/css_fetcher_spec.rb new file mode 100644 index 0000000..86e4d89 --- /dev/null +++ b/spec/lib/critical_path_css/css_fetcher_spec.rb @@ -0,0 +1,63 @@ +require 'spec_helper' + +RSpec.describe 'CssFetcher' do + describe '#fetch' do + let(:subject) { CriticalPathCss::CssFetcher.new(config) } + let(:response) { + ['foo','', OpenStruct.new(exitstatus: 0)] + } + let(:routes) { ['/', '/new_route'] } + let(:config) do + OpenStruct.new( + base_url: 'http://0.0.0.0:9292', + css_path: css_path, + css_paths: css_paths, + penthouse_options: {}, + routes: routes + ) + end + + context 'when a single css_path is configured' do + let(:css_path) { '/test.css' } + let(:css_paths) { [] } + + it 'generates css for each route from the same file' do + expect(Open3).to receive(:capture3) do |arg1, arg2, arg3| + options = JSON.parse(arg3) + expect(options['css']).to eq '/test.css' + end.twice.and_return(response) + subject.fetch + end + end + + context 'when multiple css_paths are configured' do + let(:css_path) { '' } + let(:css_paths) { ['/test.css', '/test2.css'] } + + it 'generates css for each route from the respective file' do + expect(Open3).to receive(:capture3) do |arg1, arg2, arg3| + options = JSON.parse(arg3) + expect(options['css']).to eq '/test.css' if options['url'] == 'http://0.0.0.0:9292/' + expect(options['css']).to eq '/test2.css' if options['url'] == 'http://0.0.0.0:9292/new_route' + end.twice.and_return(response) + subject.fetch + end + end + + context 'when same css file applies to multiple routes' do + let(:css_path) { '' } + let(:css_paths) { ['/test.css', '/test2.css', '/test.css'] } + let(:routes) { ['/', '/new_route', '/newer_route'] } + + it 'generates css for each route from the respective file' do + expect(Open3).to receive(:capture3) do |arg1, arg2, arg3| + options = JSON.parse(arg3) + expect(options['css']).to eq '/test.css' if options['url'] == 'http://0.0.0.0:9292/' + expect(options['css']).to eq '/test2.css' if options['url'] == 'http://0.0.0.0:9292/new_route' + expect(options['css']).to eq '/test.css' if options['url'] == 'http://0.0.0.0:9292/newer_route' + end.thrice.and_return(response) + subject.fetch + end + end + end +end diff --git a/spec/lib/critical_path_css/rails/config_loader_spec.rb b/spec/lib/critical_path_css/rails/config_loader_spec.rb new file mode 100644 index 0000000..232b7ab --- /dev/null +++ b/spec/lib/critical_path_css/rails/config_loader_spec.rb @@ -0,0 +1,125 @@ +require 'spec_helper' + +RSpec.describe 'ConfigLoader' do + let(:subject) { CriticalPathCss::Rails::ConfigLoader.new } + describe '#load' do + before do + allow(File).to receive(:read).and_return(config_file) + end + + context 'when single css_path is specified' do + let(:config_file) { + <<~CONFIG + defaults: &defaults + base_url: http://0.0.0.0:9292 + css_path: /test.css + routes: + - / + + development: + <<: *defaults + + test: + <<: *defaults + CONFIG + } + + it 'sets css_path with the path' do + config = subject.load + + expect(config['css_path']).to eq '/app/spec/internal/public/test.css' + end + + it 'leaves css_paths empty' do + config = subject.load + + expect(config['css_paths']).to eq [] + end + end + + context 'when multiple css_paths are specified' do + let(:config_file) { + <<~CONFIG + defaults: &defaults + base_url: http://0.0.0.0:9292 + css_paths: + - /test.css + - /test2.css + routes: + - / + - /new_route + + development: + <<: *defaults + + test: + <<: *defaults + CONFIG + } + + it 'sets css_path to empty string' do + config = subject.load + + expect(config['css_path']).to eq '' + end + + it 'leaves css_paths to an array of paths' do + config = subject.load + + expect(config['css_paths']).to eq ['/app/spec/internal/public/test.css','/app/spec/internal/public/test2.css'] + end + end + + context 'when single css_path and multiple css_paths are both specified' do + let(:config_file) { + <<~CONFIG + defaults: &defaults + base_url: http://0.0.0.0:9292 + css_path: /test.css + css_paths: + - /test.css + - /test2.css + routes: + - / + - /new_route + + development: + <<: *defaults + + test: + <<: *defaults + CONFIG + } + + it 'raises an error' do + expect { subject.load }.to raise_error LoadError, 'Cannot specify both css_path and css_paths' + end + end + + context 'when css_paths and routes are not the same length' do + let(:config_file) { + <<~CONFIG + defaults: &defaults + base_url: http://0.0.0.0:9292 + css_paths: + - /test.css + - /test2.css + routes: + - / + - /new_route + - /newer_route + + development: + <<: *defaults + + test: + <<: *defaults + CONFIG + } + + it 'raises an error' do + expect { subject.load }.to raise_error LoadError, 'Must specify css_paths for each route' + end + end + end +end From 667f2428483d3dd9d4ee3afc0e32bbd954ffa077 Mon Sep 17 00:00:00 2001 From: "Randall Reed, Jr" Date: Mon, 25 Jun 2018 13:35:32 -0400 Subject: [PATCH 46/81] Add note to readme about puppeteer --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 9b354fb..82960fc 100644 --- a/README.md +++ b/README.md @@ -146,6 +146,12 @@ This gem is to be tested inside of docker/docker-compose. [Combustion](https://g Once shell'd in, run `bundle exec rspec spec` to run the test. The test rails app lives in `spec/internal`, and it can be viewed locally at `http://localhost:9292/` +If you encounter Chromium errors trying to run the tests, installing [Puppeteer](https://github.com/GoogleChrome/puppeteer) might help. + +```Bash + npm install puppeteer +``` + ## Versions From 0682adf46db2c3c8ef1fc2ff528ffc94e83be70c Mon Sep 17 00:00:00 2001 From: "Randall Reed, Jr" Date: Mon, 25 Jun 2018 13:36:30 -0400 Subject: [PATCH 47/81] Add page h1 tag to more clearly identify test page --- spec/internal/app/views/root/index.html.erb | 1 + 1 file changed, 1 insertion(+) diff --git a/spec/internal/app/views/root/index.html.erb b/spec/internal/app/views/root/index.html.erb index 62b320d..6103952 100644 --- a/spec/internal/app/views/root/index.html.erb +++ b/spec/internal/app/views/root/index.html.erb @@ -1 +1,2 @@ +

Critical Path CSS Rails Test App

<%= CriticalPathCss.fetch(request.path) %>

From b8db8b860382b8f03a0a75f0612e08dadc5aa669 Mon Sep 17 00:00:00 2001 From: Michael Misshore Date: Fri, 29 Jun 2018 09:33:59 -0500 Subject: [PATCH 48/81] =?UTF-8?q?Move=20fetcher=20into=20it=E2=80=99s=20ow?= =?UTF-8?q?n=20method?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/critical-path-css-rails.rb | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/lib/critical-path-css-rails.rb b/lib/critical-path-css-rails.rb index 7586934..e770a78 100644 --- a/lib/critical-path-css-rails.rb +++ b/lib/critical-path-css-rails.rb @@ -6,16 +6,11 @@ module CriticalPathCss CACHE_NAMESPACE = 'critical-path-css'.freeze def self.generate(route) - ::Rails.cache.write( - route, - CssFetcher.new(config).fetch_route(route), - namespace: CACHE_NAMESPACE, - expires_in: nil - ) + ::Rails.cache.write(route, fetcher.fetch_route(route), namespace: CACHE_NAMESPACE, expires_in: nil) end def self.generate_all - CssFetcher.new(config).fetch.each do |route, css| + fetcher.fetch.each do |route, css| ::Rails.cache.write(route, css, namespace: CACHE_NAMESPACE, expires_in: nil) end end @@ -32,7 +27,7 @@ def self.fetch(route) ::Rails.cache.read(route, namespace: CACHE_NAMESPACE) || '' end - def self.config - @config ||= Configuration.new(CriticalPathCss::Rails::ConfigLoader.new.load) + def self.fetcher + @fetcher ||= CssFetcher.new(Configuration.new(CriticalPathCss::Rails::ConfigLoader.new.load)) end end From 90f7fa4f7784dcb304bbbcfe7cfe408167157245 Mon Sep 17 00:00:00 2001 From: "Randall Reed, Jr" Date: Tue, 14 Aug 2018 09:42:53 -0400 Subject: [PATCH 49/81] Add to Usage section of README --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 82960fc..c9e0353 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,7 @@ First, you'll need to configue a few things in the YAML file: `config/critical_p * `manifest_name`: If you're using the asset pipeline, add the manifest name. * `css_path`: If you're not using the asset pipeline, you'll need to define the path to the application's main CSS. The gem assumes your CSS lives in `RAILS_ROOT/public`. If your main CSS file is in `RAILS_ROOT/public/assets/main.css`, you would set the variable to `/assets/main.css`. +* `css_paths`: If you have the need to specify multiple CSS source files, you can do so with `css_paths`. Note that `css_path` and `css_paths` are **mutually exclusive**; if using `css_path`, configuration for `css_paths` should be omitted, and vice versa. When using this option, a separate CSS path must be specified for each route, and they will be matched based on the order specified (the first CSS path will be applied to the first route, the second CSS path to the second route, etc). * `routes`: List the routes that you would like to generate the critical CSS for. (i.e. /resources, /resources/show/1, etc.) * `base_url`: Add your application's URL for the necessary environments. From a6a4839d4bb9ef475d602f0f7941309d64d73c75 Mon Sep 17 00:00:00 2001 From: Michael Misshore Date: Thu, 1 Nov 2018 18:58:15 -0500 Subject: [PATCH 50/81] Update penthouse to 1.10.1 --- README.md | 2 +- lib/critical_path_css/rails/version.rb | 2 +- package-lock.json | 115 +++++++++++++++---------- package.json | 2 +- 4 files changed, 73 insertions(+), 48 deletions(-) diff --git a/README.md b/README.md index 9b354fb..456789b 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ However, more packages may need to be installed depending on your OS distributio After reviewing the dependency requirements, add `critical-path-css-rails` to your Gemfile: ``` -gem 'critical-path-css-rails', '~> 2.6.0' +gem 'critical-path-css-rails', '~> 2.10.0' ``` Download and install by running: diff --git a/lib/critical_path_css/rails/version.rb b/lib/critical_path_css/rails/version.rb index ebfb91a..861105b 100644 --- a/lib/critical_path_css/rails/version.rb +++ b/lib/critical_path_css/rails/version.rb @@ -1,5 +1,5 @@ module CriticalPathCSS module Rails - VERSION = '2.6.0'.freeze + VERSION = '2.10.1'.freeze end end diff --git a/package-lock.json b/package-lock.json index 50654c0..a3e7120 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5,9 +5,9 @@ "requires": true, "dependencies": { "agent-base": { - "version": "4.2.0", - "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-4.2.0.tgz", - "integrity": "sha512-c+R/U5X+2zz2+UCrCFv6odQzJdoqI+YecuhnAJLa1zYaMc13zPfwMwZrr91Pd1DYNo/yPRbiM4WVf9whgwFsIg==", + "version": "4.2.1", + "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-4.2.1.tgz", + "integrity": "sha512-JVwXMr9nHYTUXsBFKUqhJwvlcYU/blreOEUkhNR2eXZIvwd+c+o5V4MgDPKWnMS/56awN3TRzIP+KoPn+roQtg==", "requires": { "es6-promisify": "5.0.0" } @@ -32,9 +32,9 @@ } }, "buffer-from": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.0.tgz", - "integrity": "sha512-c5mRlguI/Pe2dSZmpER62rSCu0ryKmWddzRYsuXc50U2/g8jMOulc31VZMa4mYx31U5xsmSOpDCgH88Vl9cDGQ==" + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.1.tgz", + "integrity": "sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A==" }, "concat-map": { "version": "0.0.1", @@ -46,7 +46,7 @@ "resolved": "https://registry.npmjs.org/concat-stream/-/concat-stream-1.6.2.tgz", "integrity": "sha512-27HBghJxjiZtIk3Ycvn/4kbJk/1uZuJFfuPEns6LaEvpvG1f0hTea8lilrouyo9mVc2GWdcEZ8OLoGmSADlrCw==", "requires": { - "buffer-from": "1.1.0", + "buffer-from": "1.1.1", "inherits": "2.0.3", "readable-stream": "2.3.6", "typedarray": "0.0.6" @@ -72,24 +72,24 @@ } }, "debug": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz", - "integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==", + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.1.0.tgz", + "integrity": "sha512-heNPJUJIqC+xB6ayLAMHaIrmN9HKa7aQO8MGqKpvCA+uJYVcvR6l5kgdrhRuwPFHU7P5/A1w0BjByPHwpfTDKg==", "requires": { - "ms": "2.0.0" + "ms": "2.1.1" } }, "es6-promise": { - "version": "4.2.4", - "resolved": "https://registry.npmjs.org/es6-promise/-/es6-promise-4.2.4.tgz", - "integrity": "sha512-/NdNZVJg+uZgtm9eS3O6lrOLYmQag2DjdEXuPaHlZ6RuVqgqaVZfgYCepEIKsLqwdQArOPtC3XzRLqGGfT8KQQ==" + "version": "4.2.5", + "resolved": "https://registry.npmjs.org/es6-promise/-/es6-promise-4.2.5.tgz", + "integrity": "sha512-n6wvpdE43VFtJq+lUDYDBFUwV8TZbuGXLV4D6wKafg13ldznKsyEvatubnmUe31zcvelSzOHF+XbaT+Bl9ObDg==" }, "es6-promisify": { "version": "5.0.0", - "resolved": "https://registry.npmjs.org/es6-promisify/-/es6-promisify-5.0.0.tgz", + "resolved": "http://registry.npmjs.org/es6-promisify/-/es6-promisify-5.0.0.tgz", "integrity": "sha1-UQnWLz5W6pZ8S2NQWu8IKRyKUgM=", "requires": { - "es6-promise": "4.2.4" + "es6-promise": "4.2.5" } }, "extract-zip": { @@ -110,6 +110,11 @@ "requires": { "ms": "2.0.0" } + }, + "ms": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", + "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" } } }, @@ -127,9 +132,9 @@ "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=" }, "glob": { - "version": "7.1.2", - "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.2.tgz", - "integrity": "sha512-MJTUg1kjuLeQCJ+ccE4Vpa6kKVXkPYJ2mOCQyUuKLcLQsdrMCpBPUi8qVE6+YuaJkozeA9NusTAw3hLr8Xe5EQ==", + "version": "7.1.3", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.3.tgz", + "integrity": "sha512-vcfuiIxogLV4DlGBHIUOwI0IbrJ8HWPc4MU7HzviGeNho/UJDfi6B5p3sHeWIQ0KGIU0Jpxi5ZHxemQfLkkAwQ==", "requires": { "fs.realpath": "1.0.0", "inflight": "1.0.6", @@ -144,8 +149,18 @@ "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-2.2.1.tgz", "integrity": "sha512-HPCTS1LW51bcyMYbxUIOO4HEOlQ1/1qRaFWcyxvwaqUS9TY88aoEuHUY33kuAh1YhVVaDQhLZsnPd+XNARWZlQ==", "requires": { - "agent-base": "4.2.0", - "debug": "3.1.0" + "agent-base": "4.2.1", + "debug": "3.2.6" + }, + "dependencies": { + "debug": { + "version": "3.2.6", + "resolved": "https://registry.npmjs.org/debug/-/debug-3.2.6.tgz", + "integrity": "sha512-mel+jf7nrtEl5Pn1Qx46zARXKDpBbvzezse7p7LqINmdoIk8PYP5SySaxEmYv6TZ0JyEKA1hsCId6DIhgITtWQ==", + "requires": { + "ms": "2.1.1" + } + } } }, "inflight": { @@ -192,21 +207,21 @@ }, "minimist": { "version": "0.0.8", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", + "resolved": "http://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=" }, "mkdirp": { "version": "0.5.1", - "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz", + "resolved": "http://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz", "integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=", "requires": { "minimist": "0.0.8" } }, "ms": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", - "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.1.tgz", + "integrity": "sha512-tgp+dl5cGk28utYktBsrFqA7HKgrhgPsg6Z/EfhWI4gl1Hwq8B/GmY/0oXZ6nF8hDVesS/FpnYaD/kOWhYQvyg==" }, "once": { "version": "1.4.0", @@ -227,15 +242,15 @@ "integrity": "sha1-elfrVQpng/kRUzH89GY9XI4AelA=" }, "penthouse": { - "version": "1.6.0", - "resolved": "https://registry.npmjs.org/penthouse/-/penthouse-1.6.0.tgz", - "integrity": "sha512-fQ2ylSTM7X51b10kIF9G1Esq4G/bmWj/TSIzxNyMO8x0It3hAqBi78xXdYmMRRPB3k57oJp0cjGHrYMgqBcHSQ==", + "version": "1.10.1", + "resolved": "https://registry.npmjs.org/penthouse/-/penthouse-1.10.1.tgz", + "integrity": "sha512-D0fUazt6EvtoJvbKJ4u6yVIwfrWoSW1+2clr5JZaKag5pzgwLJKYcN8NgmAoBmWOwsMk+3ZAkV5Cv09LzQtqAw==", "requires": { "css-mediaquery": "0.1.2", "css-tree": "1.0.0-alpha.28", - "debug": "3.1.0", + "debug": "4.1.0", "jsesc": "2.5.1", - "puppeteer": "1.5.0" + "puppeteer": "1.9.0" } }, "process-nextick-args": { @@ -244,9 +259,9 @@ "integrity": "sha512-MtEC1TqN0EU5nephaJ4rAtThHtC86dNN9qCuEhtshvpVBkAW5ZO7BASN9REnF9eoXGcRub+pFuKEpOHE+HbEMw==" }, "progress": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/progress/-/progress-2.0.0.tgz", - "integrity": "sha1-ihvjZr+Pwj2yvSPxDG/pILQ4nR8=" + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/progress/-/progress-2.0.1.tgz", + "integrity": "sha512-OE+a6vzqazc+K6LxJrX5UPyKFvGnL5CYmq2jFGNIBWHpc4QyE49/YOumcrpQFJpfejmvRtbJzgO1zPmMCqlbBg==" }, "proxy-from-env": { "version": "1.0.0", @@ -254,23 +269,33 @@ "integrity": "sha1-M8UDmPcOp+uW0h97gXYwpVeRx+4=" }, "puppeteer": { - "version": "1.5.0", - "resolved": "https://registry.npmjs.org/puppeteer/-/puppeteer-1.5.0.tgz", - "integrity": "sha512-eELwFtFxL+uhmg4jPZOZXzSrPEYy4CaYQNbcchBbfxY+KjMpnv6XGf/aYWaQG49OTpfi2/DMziXtDM8XuJgoUA==", + "version": "1.9.0", + "resolved": "https://registry.npmjs.org/puppeteer/-/puppeteer-1.9.0.tgz", + "integrity": "sha512-GH4PmhJf9wBRAPvtJkEJLAvdNNOofZortmBZSj8cGWYni98GUFqsf66blOEfJbo5B8l0KG5HR2d/W2MejnUrzg==", "requires": { - "debug": "3.1.0", + "debug": "3.2.6", "extract-zip": "1.6.7", "https-proxy-agent": "2.2.1", "mime": "2.3.1", - "progress": "2.0.0", + "progress": "2.0.1", "proxy-from-env": "1.0.0", "rimraf": "2.6.2", - "ws": "5.2.0" + "ws": "5.2.2" + }, + "dependencies": { + "debug": { + "version": "3.2.6", + "resolved": "https://registry.npmjs.org/debug/-/debug-3.2.6.tgz", + "integrity": "sha512-mel+jf7nrtEl5Pn1Qx46zARXKDpBbvzezse7p7LqINmdoIk8PYP5SySaxEmYv6TZ0JyEKA1hsCId6DIhgITtWQ==", + "requires": { + "ms": "2.1.1" + } + } } }, "readable-stream": { "version": "2.3.6", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.6.tgz", + "resolved": "http://registry.npmjs.org/readable-stream/-/readable-stream-2.3.6.tgz", "integrity": "sha512-tQtKA9WIAhBF3+VLAseyMqZeBjW0AHJoxOtYqSUZNJxauErmLbVm2FW1y+J/YA9dUrAC39ITejlZWhVIwawkKw==", "requires": { "core-util-is": "1.0.2", @@ -287,7 +312,7 @@ "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.6.2.tgz", "integrity": "sha512-lreewLK/BlghmxtfH36YYVg1i8IAce4TI7oao75I1g245+6BctqTVQiBP3YUJ9C6DQOXJmkYR9X9fCLtCOJc5w==", "requires": { - "glob": "7.1.2" + "glob": "7.1.3" } }, "safe-buffer": { @@ -324,9 +349,9 @@ "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=" }, "ws": { - "version": "5.2.0", - "resolved": "https://registry.npmjs.org/ws/-/ws-5.2.0.tgz", - "integrity": "sha512-c18dMeW+PEQdDFzkhDsnBAlS4Z8KGStBQQUcQ5mf7Nf689jyGk0594L+i9RaQuf4gog6SvWLJorz2NfSaqxZ7w==", + "version": "5.2.2", + "resolved": "https://registry.npmjs.org/ws/-/ws-5.2.2.tgz", + "integrity": "sha512-jaHFD6PFv6UgoIVda6qZllptQsMlDEJkTQcybzzXDYM1XO9Y8em691FGMPmM46WGyLU4z9KMgQN+qrux/nhlHA==", "requires": { "async-limiter": "1.0.0" } diff --git a/package.json b/package.json index a030f5f..d781877 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "lib": "lib" }, "dependencies": { - "penthouse": "=1.6.0" + "penthouse": "=1.10.1" }, "license": "MIT" } From fb01490a370a8558e09da8cb9404a2dea3627f28 Mon Sep 17 00:00:00 2001 From: Justin Bantuelle Date: Thu, 13 Dec 2018 10:20:58 -0600 Subject: [PATCH 51/81] Update Example Based on loadCSS Best Practice --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 456789b..ecab6a2 100644 --- a/README.md +++ b/README.md @@ -87,7 +87,7 @@ A simple example using [loadcss-rails](https://github.com/michael-misshore/loadc - + From 3470ef8ae66c3cdc5d37e4ea93967a5bcd07165a Mon Sep 17 00:00:00 2001 From: Michael Misshore Date: Sun, 24 Feb 2019 09:47:43 -0600 Subject: [PATCH 52/81] Refactor config loader --- lib/critical-path-css-rails.rb | 10 ++++- lib/critical_path_css/rails/config_loader.rb | 39 +++++++++++-------- .../rails/config_loader_spec.rb | 25 ++++++------ 3 files changed, 45 insertions(+), 29 deletions(-) diff --git a/lib/critical-path-css-rails.rb b/lib/critical-path-css-rails.rb index e770a78..92d8408 100644 --- a/lib/critical-path-css-rails.rb +++ b/lib/critical-path-css-rails.rb @@ -28,6 +28,14 @@ def self.fetch(route) end def self.fetcher - @fetcher ||= CssFetcher.new(Configuration.new(CriticalPathCss::Rails::ConfigLoader.new.load)) + @fetcher ||= CssFetcher.new(Configuration.new(config)) + end + + def self.config + @config ||= begin + loader = CriticalPathCss::Rails::ConfigLoader.new + loader.load + loader.config + end end end diff --git a/lib/critical_path_css/rails/config_loader.rb b/lib/critical_path_css/rails/config_loader.rb index ee4d00d..2d0a9f5 100644 --- a/lib/critical_path_css/rails/config_loader.rb +++ b/lib/critical_path_css/rails/config_loader.rb @@ -3,22 +3,15 @@ module Rails class ConfigLoader CONFIGURATION_FILENAME = 'critical_path_css.yml'.freeze + attr_reader :config + def load - config = YAML.safe_load(ERB.new(File.read(configuration_file_path)).result, [], [], true)[::Rails.env] - validate_css_path config - if config['css_path'] - config['css_path'] = "#{::Rails.root}/public" + ( - config['css_path'] || - ActionController::Base.helpers.stylesheet_path( - config['manifest_name'], host: '' - ) - ) - config['css_paths'] = [] - else - config['css_path'] = '' - config['css_paths'] = config['css_paths'].collect { |path| "#{::Rails.root}/public#{path}" } - end - config + validate_css_paths + format_css_paths + end + + def config + @config ||= YAML.safe_load(ERB.new(File.read(configuration_file_path)).result, [], [], true)[::Rails.env] end private @@ -27,7 +20,21 @@ def configuration_file_path @configuration_file_path ||= ::Rails.root.join('config', CONFIGURATION_FILENAME) end - def validate_css_path(config) + def format_css_paths + if config['css_path'] + config['css_path'] = format_path(config['css_path']) + config['css_paths'] = [] + else + config['css_path'] = '' + config['css_paths'] = config['css_paths'].collect { |path| format_path(path) } + end + end + + def format_path(path) + "#{::Rails.root}/public#{path}" + end + + def validate_css_paths if config['css_path'] && config['css_paths'] raise LoadError, 'Cannot specify both css_path and css_paths' elsif config['css_paths'] && config['css_paths'].length != config['routes'].length diff --git a/spec/lib/critical_path_css/rails/config_loader_spec.rb b/spec/lib/critical_path_css/rails/config_loader_spec.rb index 232b7ab..70ad2bd 100644 --- a/spec/lib/critical_path_css/rails/config_loader_spec.rb +++ b/spec/lib/critical_path_css/rails/config_loader_spec.rb @@ -2,6 +2,7 @@ RSpec.describe 'ConfigLoader' do let(:subject) { CriticalPathCss::Rails::ConfigLoader.new } + describe '#load' do before do allow(File).to receive(:read).and_return(config_file) @@ -24,16 +25,16 @@ CONFIG } - it 'sets css_path with the path' do - config = subject.load + before do + subject.load + end - expect(config['css_path']).to eq '/app/spec/internal/public/test.css' + it 'sets css_path with the path' do + expect(subject.config['css_path']).to eq '/app/spec/internal/public/test.css' end it 'leaves css_paths empty' do - config = subject.load - - expect(config['css_paths']).to eq [] + expect(subject.config['css_paths']).to eq [] end end @@ -57,16 +58,16 @@ CONFIG } - it 'sets css_path to empty string' do - config = subject.load + before do + subject.load + end - expect(config['css_path']).to eq '' + it 'sets css_path to empty string' do + expect(subject.config['css_path']).to eq '' end it 'leaves css_paths to an array of paths' do - config = subject.load - - expect(config['css_paths']).to eq ['/app/spec/internal/public/test.css','/app/spec/internal/public/test2.css'] + expect(subject.config['css_paths']).to eq ['/app/spec/internal/public/test.css','/app/spec/internal/public/test2.css'] end end From 4c7f6c8794a2b40b912dba1afe2fa76287db4457 Mon Sep 17 00:00:00 2001 From: Michael Misshore Date: Sun, 24 Feb 2019 09:58:19 -0600 Subject: [PATCH 53/81] Add breaking test for #fetch_route --- .../lib/critical_path_css/css_fetcher_spec.rb | 42 ++++++++++++------- 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/spec/lib/critical_path_css/css_fetcher_spec.rb b/spec/lib/critical_path_css/css_fetcher_spec.rb index 86e4d89..32b0cd9 100644 --- a/spec/lib/critical_path_css/css_fetcher_spec.rb +++ b/spec/lib/critical_path_css/css_fetcher_spec.rb @@ -1,22 +1,36 @@ require 'spec_helper' RSpec.describe 'CssFetcher' do - describe '#fetch' do - let(:subject) { CriticalPathCss::CssFetcher.new(config) } - let(:response) { - ['foo','', OpenStruct.new(exitstatus: 0)] - } - let(:routes) { ['/', '/new_route'] } - let(:config) do - OpenStruct.new( - base_url: 'http://0.0.0.0:9292', - css_path: css_path, - css_paths: css_paths, - penthouse_options: {}, - routes: routes - ) + let(:subject) { CriticalPathCss::CssFetcher.new(config) } + let(:response) { ['foo','', OpenStruct.new(exitstatus: 0)] } + let(:routes) { ['/', '/new_route'] } + let(:config) do + OpenStruct.new( + base_url: 'http://0.0.0.0:9292', + css_path: css_path, + css_paths: css_paths, + penthouse_options: {}, + routes: routes + ) + end + + describe '#fetch_route' do + context 'when a single css_path is configured' do + let(:css_path) { '/test.css' } + let(:css_paths) { [] } + + it 'generates css for the single route' do + expect(Open3).to receive(:capture3) do |arg1, arg2, arg3| + options = JSON.parse(arg3) + expect(options['css']).to eq '/test.css' + end.once.and_return(response) + + subject.fetch_route(routes.first) + end end + end + describe '#fetch' do context 'when a single css_path is configured' do let(:css_path) { '/test.css' } let(:css_paths) { [] } From 3c7048b87f2978b7db1414452d8e68189ee59356 Mon Sep 17 00:00:00 2001 From: Michael Misshore Date: Sun, 24 Feb 2019 10:19:39 -0600 Subject: [PATCH 54/81] =?UTF-8?q?Refactor=20css=5Fpath=20logic=20into=20it?= =?UTF-8?q?=E2=80=99s=20own=20method?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Remove a few unnecessary comments in the penthouse config --- lib/critical_path_css/css_fetcher.rb | 30 ++++++++++++++-------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/lib/critical_path_css/css_fetcher.rb b/lib/critical_path_css/css_fetcher.rb index 3ead1a2..1ea95e4 100644 --- a/lib/critical_path_css/css_fetcher.rb +++ b/lib/critical_path_css/css_fetcher.rb @@ -10,33 +10,21 @@ def initialize(config) end def fetch - @config.routes.map.with_index { |route, index| - css_path = @config.css_paths[index].present? ? @config.css_paths[index] : @config.css_path - [route, css_for_route(route, css_path)] - }.to_h + @config.routes.map { |route| [route, fetch_route(route)] }.to_h end def fetch_route(route) - css_for_route route - end - - protected - - def css_for_route(route, css_path) options = { 'url' => @config.base_url + route, - 'css' => css_path, - ## optional params - # viewport dimensions + 'css' => fetch_css_path_for_route(route), #implement 'width' => 1300, 'height' => 900, + 'timeout' => 30_000, # CSS selectors to always include, e.g.: 'forceInclude' => [ # '.keepMeEvenIfNotSeenInDom', # '^\.regexWorksToo' ], - # ms; abort critical CSS generation after this timeout - 'timeout' => 30_000, # set to true to throw on CSS errors (will run faster if no errors) 'strict' => false, # characters; strip out inline base64 encoded resources larger than this @@ -63,5 +51,17 @@ def css_for_route(route, css_path) end out end + + private + + def fetch_css_path_for_route(route) + index_for_route = @config.routes.index(route) + + if index_for_route && @config.css_paths[index_for_route] + @config.css_paths[index_for_route] + else + @config.css_path + end + end end end From 018547b3209805fdec34991efba6a992fc7296c0 Mon Sep 17 00:00:00 2001 From: Michael Misshore Date: Sun, 24 Feb 2019 11:10:25 -0600 Subject: [PATCH 55/81] Update dev NodeJS --- docker/ruby/Dockerfile | 5 +- package-lock.json | 102 ++++++++++++++++++++--------------------- 2 files changed, 54 insertions(+), 53 deletions(-) diff --git a/docker/ruby/Dockerfile b/docker/ruby/Dockerfile index 4376437..3404a71 100644 --- a/docker/ruby/Dockerfile +++ b/docker/ruby/Dockerfile @@ -7,10 +7,11 @@ RUN apt-get update && apt-get install -y build-essential libpq-dev nodejs npm # Install Penthouse JS Dependencies RUN apt-get install -y libpangocairo-1.0-0 libx11-xcb1 libxcomposite1 libxcursor1 libxdamage1 libxi6 libxtst6 libnss3 libcups2 libxss1 libxrandr2 libgconf2-4 libasound2 libatk1.0-0 libgtk-3-0 +# Configure Node/NPM RUN npm cache clean -f RUN npm install -g n -RUN n 8.9.3 -RUN ln -sf /usr/local/n/versions/node/8.9.3/bin/node /usr/bin/nodejs +RUN n 10.15.1 +RUN ln -sf /usr/local/n/versions/node/10.15.1/bin/node /usr/bin/nodejs ENV BUNDLE_PATH /gems diff --git a/package-lock.json b/package-lock.json index a3e7120..bc55893 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-4.2.1.tgz", "integrity": "sha512-JVwXMr9nHYTUXsBFKUqhJwvlcYU/blreOEUkhNR2eXZIvwd+c+o5V4MgDPKWnMS/56awN3TRzIP+KoPn+roQtg==", "requires": { - "es6-promisify": "5.0.0" + "es6-promisify": "^5.0.0" } }, "async-limiter": { @@ -27,7 +27,7 @@ "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", "requires": { - "balanced-match": "1.0.0", + "balanced-match": "^1.0.0", "concat-map": "0.0.1" } }, @@ -46,10 +46,10 @@ "resolved": "https://registry.npmjs.org/concat-stream/-/concat-stream-1.6.2.tgz", "integrity": "sha512-27HBghJxjiZtIk3Ycvn/4kbJk/1uZuJFfuPEns6LaEvpvG1f0hTea8lilrouyo9mVc2GWdcEZ8OLoGmSADlrCw==", "requires": { - "buffer-from": "1.1.1", - "inherits": "2.0.3", - "readable-stream": "2.3.6", - "typedarray": "0.0.6" + "buffer-from": "^1.0.0", + "inherits": "^2.0.3", + "readable-stream": "^2.2.2", + "typedarray": "^0.0.6" } }, "core-util-is": { @@ -67,8 +67,8 @@ "resolved": "https://registry.npmjs.org/css-tree/-/css-tree-1.0.0-alpha.28.tgz", "integrity": "sha512-joNNW1gCp3qFFzj4St6zk+Wh/NBv0vM5YbEreZk0SD4S23S+1xBKb6cLDg2uj4P4k/GUMlIm6cKIDqIG+vdt0w==", "requires": { - "mdn-data": "1.1.4", - "source-map": "0.5.7" + "mdn-data": "~1.1.0", + "source-map": "^0.5.3" } }, "debug": { @@ -76,7 +76,7 @@ "resolved": "https://registry.npmjs.org/debug/-/debug-4.1.0.tgz", "integrity": "sha512-heNPJUJIqC+xB6ayLAMHaIrmN9HKa7aQO8MGqKpvCA+uJYVcvR6l5kgdrhRuwPFHU7P5/A1w0BjByPHwpfTDKg==", "requires": { - "ms": "2.1.1" + "ms": "^2.1.1" } }, "es6-promise": { @@ -86,10 +86,10 @@ }, "es6-promisify": { "version": "5.0.0", - "resolved": "http://registry.npmjs.org/es6-promisify/-/es6-promisify-5.0.0.tgz", + "resolved": "https://registry.npmjs.org/es6-promisify/-/es6-promisify-5.0.0.tgz", "integrity": "sha1-UQnWLz5W6pZ8S2NQWu8IKRyKUgM=", "requires": { - "es6-promise": "4.2.5" + "es6-promise": "^4.0.3" } }, "extract-zip": { @@ -123,7 +123,7 @@ "resolved": "https://registry.npmjs.org/fd-slicer/-/fd-slicer-1.0.1.tgz", "integrity": "sha1-i1vL2ewyfFBBv5qwI/1nUPEXfmU=", "requires": { - "pend": "1.2.0" + "pend": "~1.2.0" } }, "fs.realpath": { @@ -136,12 +136,12 @@ "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.3.tgz", "integrity": "sha512-vcfuiIxogLV4DlGBHIUOwI0IbrJ8HWPc4MU7HzviGeNho/UJDfi6B5p3sHeWIQ0KGIU0Jpxi5ZHxemQfLkkAwQ==", "requires": { - "fs.realpath": "1.0.0", - "inflight": "1.0.6", - "inherits": "2.0.3", - "minimatch": "3.0.4", - "once": "1.4.0", - "path-is-absolute": "1.0.1" + "fs.realpath": "^1.0.0", + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "^3.0.4", + "once": "^1.3.0", + "path-is-absolute": "^1.0.0" } }, "https-proxy-agent": { @@ -149,8 +149,8 @@ "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-2.2.1.tgz", "integrity": "sha512-HPCTS1LW51bcyMYbxUIOO4HEOlQ1/1qRaFWcyxvwaqUS9TY88aoEuHUY33kuAh1YhVVaDQhLZsnPd+XNARWZlQ==", "requires": { - "agent-base": "4.2.1", - "debug": "3.2.6" + "agent-base": "^4.1.0", + "debug": "^3.1.0" }, "dependencies": { "debug": { @@ -158,7 +158,7 @@ "resolved": "https://registry.npmjs.org/debug/-/debug-3.2.6.tgz", "integrity": "sha512-mel+jf7nrtEl5Pn1Qx46zARXKDpBbvzezse7p7LqINmdoIk8PYP5SySaxEmYv6TZ0JyEKA1hsCId6DIhgITtWQ==", "requires": { - "ms": "2.1.1" + "ms": "^2.1.1" } } } @@ -168,8 +168,8 @@ "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", "requires": { - "once": "1.4.0", - "wrappy": "1.0.2" + "once": "^1.3.0", + "wrappy": "1" } }, "inherits": { @@ -202,17 +202,17 @@ "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", "requires": { - "brace-expansion": "1.1.11" + "brace-expansion": "^1.1.7" } }, "minimist": { "version": "0.0.8", - "resolved": "http://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=" }, "mkdirp": { "version": "0.5.1", - "resolved": "http://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz", "integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=", "requires": { "minimist": "0.0.8" @@ -228,7 +228,7 @@ "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", "requires": { - "wrappy": "1.0.2" + "wrappy": "1" } }, "path-is-absolute": { @@ -246,10 +246,10 @@ "resolved": "https://registry.npmjs.org/penthouse/-/penthouse-1.10.1.tgz", "integrity": "sha512-D0fUazt6EvtoJvbKJ4u6yVIwfrWoSW1+2clr5JZaKag5pzgwLJKYcN8NgmAoBmWOwsMk+3ZAkV5Cv09LzQtqAw==", "requires": { - "css-mediaquery": "0.1.2", + "css-mediaquery": "^0.1.2", "css-tree": "1.0.0-alpha.28", - "debug": "4.1.0", - "jsesc": "2.5.1", + "debug": "^4.1.0", + "jsesc": "^2.5.1", "puppeteer": "1.9.0" } }, @@ -273,14 +273,14 @@ "resolved": "https://registry.npmjs.org/puppeteer/-/puppeteer-1.9.0.tgz", "integrity": "sha512-GH4PmhJf9wBRAPvtJkEJLAvdNNOofZortmBZSj8cGWYni98GUFqsf66blOEfJbo5B8l0KG5HR2d/W2MejnUrzg==", "requires": { - "debug": "3.2.6", - "extract-zip": "1.6.7", - "https-proxy-agent": "2.2.1", - "mime": "2.3.1", - "progress": "2.0.1", - "proxy-from-env": "1.0.0", - "rimraf": "2.6.2", - "ws": "5.2.2" + "debug": "^3.1.0", + "extract-zip": "^1.6.6", + "https-proxy-agent": "^2.2.1", + "mime": "^2.0.3", + "progress": "^2.0.0", + "proxy-from-env": "^1.0.0", + "rimraf": "^2.6.1", + "ws": "^5.1.1" }, "dependencies": { "debug": { @@ -288,23 +288,23 @@ "resolved": "https://registry.npmjs.org/debug/-/debug-3.2.6.tgz", "integrity": "sha512-mel+jf7nrtEl5Pn1Qx46zARXKDpBbvzezse7p7LqINmdoIk8PYP5SySaxEmYv6TZ0JyEKA1hsCId6DIhgITtWQ==", "requires": { - "ms": "2.1.1" + "ms": "^2.1.1" } } } }, "readable-stream": { "version": "2.3.6", - "resolved": "http://registry.npmjs.org/readable-stream/-/readable-stream-2.3.6.tgz", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.6.tgz", "integrity": "sha512-tQtKA9WIAhBF3+VLAseyMqZeBjW0AHJoxOtYqSUZNJxauErmLbVm2FW1y+J/YA9dUrAC39ITejlZWhVIwawkKw==", "requires": { - "core-util-is": "1.0.2", - "inherits": "2.0.3", - "isarray": "1.0.0", - "process-nextick-args": "2.0.0", - "safe-buffer": "5.1.2", - "string_decoder": "1.1.1", - "util-deprecate": "1.0.2" + "core-util-is": "~1.0.0", + "inherits": "~2.0.3", + "isarray": "~1.0.0", + "process-nextick-args": "~2.0.0", + "safe-buffer": "~5.1.1", + "string_decoder": "~1.1.1", + "util-deprecate": "~1.0.1" } }, "rimraf": { @@ -312,7 +312,7 @@ "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.6.2.tgz", "integrity": "sha512-lreewLK/BlghmxtfH36YYVg1i8IAce4TI7oao75I1g245+6BctqTVQiBP3YUJ9C6DQOXJmkYR9X9fCLtCOJc5w==", "requires": { - "glob": "7.1.3" + "glob": "^7.0.5" } }, "safe-buffer": { @@ -330,7 +330,7 @@ "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz", "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==", "requires": { - "safe-buffer": "5.1.2" + "safe-buffer": "~5.1.0" } }, "typedarray": { @@ -353,7 +353,7 @@ "resolved": "https://registry.npmjs.org/ws/-/ws-5.2.2.tgz", "integrity": "sha512-jaHFD6PFv6UgoIVda6qZllptQsMlDEJkTQcybzzXDYM1XO9Y8em691FGMPmM46WGyLU4z9KMgQN+qrux/nhlHA==", "requires": { - "async-limiter": "1.0.0" + "async-limiter": "~1.0.0" } }, "yauzl": { @@ -361,7 +361,7 @@ "resolved": "https://registry.npmjs.org/yauzl/-/yauzl-2.4.1.tgz", "integrity": "sha1-lSj0QtqxsihOWLQ3m7GU4i4MQAU=", "requires": { - "fd-slicer": "1.0.1" + "fd-slicer": "~1.0.1" } } } From 02853bee24c6b9e2f4967bb2424f2154f177b542 Mon Sep 17 00:00:00 2001 From: Michael Misshore Date: Sun, 24 Feb 2019 11:21:02 -0600 Subject: [PATCH 56/81] Fix minor issues --- lib/critical_path_css/css_fetcher.rb | 2 +- lib/critical_path_css/rails/config_loader.rb | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/critical_path_css/css_fetcher.rb b/lib/critical_path_css/css_fetcher.rb index 1ea95e4..54a9880 100644 --- a/lib/critical_path_css/css_fetcher.rb +++ b/lib/critical_path_css/css_fetcher.rb @@ -16,7 +16,7 @@ def fetch def fetch_route(route) options = { 'url' => @config.base_url + route, - 'css' => fetch_css_path_for_route(route), #implement + 'css' => fetch_css_path_for_route(route), 'width' => 1300, 'height' => 900, 'timeout' => 30_000, diff --git a/lib/critical_path_css/rails/config_loader.rb b/lib/critical_path_css/rails/config_loader.rb index 2d0a9f5..c11941d 100644 --- a/lib/critical_path_css/rails/config_loader.rb +++ b/lib/critical_path_css/rails/config_loader.rb @@ -3,8 +3,6 @@ module Rails class ConfigLoader CONFIGURATION_FILENAME = 'critical_path_css.yml'.freeze - attr_reader :config - def load validate_css_paths format_css_paths From 1f5d441c1e2535222e8b57a0319981b8733ca6be Mon Sep 17 00:00:00 2001 From: Michael Misshore Date: Sun, 24 Feb 2019 11:21:21 -0600 Subject: [PATCH 57/81] Update gem version in read me --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f25ab63..74a6e10 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ However, more packages may need to be installed depending on your OS distributio After reviewing the dependency requirements, add `critical-path-css-rails` to your Gemfile: ``` -gem 'critical-path-css-rails', '~> 2.10.0' +gem 'critical-path-css-rails', '~> 3.0.0' ``` Download and install by running: From c04137ca26162719f0edb03260abf084c0e152e4 Mon Sep 17 00:00:00 2001 From: Michael Misshore Date: Sun, 24 Feb 2019 11:28:28 -0600 Subject: [PATCH 58/81] Minor refactor to config loader --- lib/critical-path-css-rails.rb | 10 +++------- lib/critical_path_css/rails/config_loader.rb | 2 +- .../critical_path_css/rails/config_loader_spec.rb | 12 ++---------- 3 files changed, 6 insertions(+), 18 deletions(-) diff --git a/lib/critical-path-css-rails.rb b/lib/critical-path-css-rails.rb index 92d8408..e361d3a 100644 --- a/lib/critical-path-css-rails.rb +++ b/lib/critical-path-css-rails.rb @@ -28,14 +28,10 @@ def self.fetch(route) end def self.fetcher - @fetcher ||= CssFetcher.new(Configuration.new(config)) + @fetcher ||= CssFetcher.new(Configuration.new(config_loader.config)) end - def self.config - @config ||= begin - loader = CriticalPathCss::Rails::ConfigLoader.new - loader.load - loader.config - end + def self.config_loader + @config_loader ||= CriticalPathCss::Rails::ConfigLoader.new end end diff --git a/lib/critical_path_css/rails/config_loader.rb b/lib/critical_path_css/rails/config_loader.rb index c11941d..27f1d8a 100644 --- a/lib/critical_path_css/rails/config_loader.rb +++ b/lib/critical_path_css/rails/config_loader.rb @@ -3,7 +3,7 @@ module Rails class ConfigLoader CONFIGURATION_FILENAME = 'critical_path_css.yml'.freeze - def load + def initialize validate_css_paths format_css_paths end diff --git a/spec/lib/critical_path_css/rails/config_loader_spec.rb b/spec/lib/critical_path_css/rails/config_loader_spec.rb index 70ad2bd..d6fbfae 100644 --- a/spec/lib/critical_path_css/rails/config_loader_spec.rb +++ b/spec/lib/critical_path_css/rails/config_loader_spec.rb @@ -25,10 +25,6 @@ CONFIG } - before do - subject.load - end - it 'sets css_path with the path' do expect(subject.config['css_path']).to eq '/app/spec/internal/public/test.css' end @@ -58,10 +54,6 @@ CONFIG } - before do - subject.load - end - it 'sets css_path to empty string' do expect(subject.config['css_path']).to eq '' end @@ -93,7 +85,7 @@ } it 'raises an error' do - expect { subject.load }.to raise_error LoadError, 'Cannot specify both css_path and css_paths' + expect { subject }.to raise_error LoadError, 'Cannot specify both css_path and css_paths' end end @@ -119,7 +111,7 @@ } it 'raises an error' do - expect { subject.load }.to raise_error LoadError, 'Must specify css_paths for each route' + expect { subject }.to raise_error LoadError, 'Must specify css_paths for each route' end end end From 41a8c9f54b3b976243a68b38b2f8f8a738e31188 Mon Sep 17 00:00:00 2001 From: Michael Misshore Date: Sat, 2 Mar 2019 08:09:15 -0600 Subject: [PATCH 59/81] Update dev dependencies --- Gemfile | 4 ++-- critical-path-css-rails.gemspec | 2 +- spec/spec_helper.rb | 2 ++ 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Gemfile b/Gemfile index 7b9a526..673bb11 100644 --- a/Gemfile +++ b/Gemfile @@ -6,8 +6,8 @@ group :development, :test do gem 'actionpack' gem 'byebug', platform: [:ruby], require: false gem 'rubocop', require: false - gem 'rspec-rails', '~> 3.6' - gem 'capybara', '~> 2.16' + gem 'rspec-rails', '~> 3.8' + gem 'capybara', '~> 3.14' gem 'pry-rails' end diff --git a/critical-path-css-rails.gemspec b/critical-path-css-rails.gemspec index b66cabe..41196ce 100644 --- a/critical-path-css-rails.gemspec +++ b/critical-path-css-rails.gemspec @@ -14,7 +14,7 @@ Gem::Specification.new do |gem| gem.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) } gem.require_path = 'lib' - gem.add_development_dependency 'combustion', '~> 0.7.0' + gem.add_development_dependency 'combustion', '~> 1.1.0' gem.extensions = ['ext/npm/extconf.rb'] end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 6146035..8743788 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -10,6 +10,8 @@ require 'capybara/rails' RSpec.configure do |config| + config.include Capybara::DSL + config.use_transactional_fixtures = true # Enable flags like --only-failures and --next-failure From 794b74471cb09f37b16498692220159bfa31116a Mon Sep 17 00:00:00 2001 From: Michael Misshore Date: Sat, 2 Mar 2019 08:12:17 -0600 Subject: [PATCH 60/81] Add failing test --- spec/internal/config/critical_path_css.yml | 1 + .../rails/config_loader_spec.rb | 26 +++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/spec/internal/config/critical_path_css.yml b/spec/internal/config/critical_path_css.yml index e40cc85..da7c252 100644 --- a/spec/internal/config/critical_path_css.yml +++ b/spec/internal/config/critical_path_css.yml @@ -1,5 +1,6 @@ defaults: &defaults base_url: http://0.0.0.0:9292 + manifest_name: application css_path: /test.css routes: - / diff --git a/spec/lib/critical_path_css/rails/config_loader_spec.rb b/spec/lib/critical_path_css/rails/config_loader_spec.rb index d6fbfae..c34271d 100644 --- a/spec/lib/critical_path_css/rails/config_loader_spec.rb +++ b/spec/lib/critical_path_css/rails/config_loader_spec.rb @@ -63,6 +63,32 @@ end end + context 'when no paths are specified' do + let(:config_file) { + <<~CONFIG + defaults: &defaults + base_url: http://0.0.0.0:9292 + manifest_name: application + routes: + - / + + development: + <<: *defaults + + test: + <<: *defaults + CONFIG + } + + it 'sets css_path with the path' do + expect(subject.config['css_path']).to eq '/app/spec/internal/public/test.css' + end + + it 'leaves css_paths empty' do + expect(subject.config['css_paths']).to eq [] + end + end + context 'when single css_path and multiple css_paths are both specified' do let(:config_file) { <<~CONFIG From 144ed520dcc76ec989a52fbae5fb70df1268f4c5 Mon Sep 17 00:00:00 2001 From: Michael Misshore Date: Sat, 2 Mar 2019 08:22:21 -0600 Subject: [PATCH 61/81] Add tmp fix for manifest name installs --- lib/critical_path_css/rails/config_loader.rb | 5 ++++- spec/lib/critical_path_css/rails/config_loader_spec.rb | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/critical_path_css/rails/config_loader.rb b/lib/critical_path_css/rails/config_loader.rb index 27f1d8a..079f263 100644 --- a/lib/critical_path_css/rails/config_loader.rb +++ b/lib/critical_path_css/rails/config_loader.rb @@ -22,9 +22,12 @@ def format_css_paths if config['css_path'] config['css_path'] = format_path(config['css_path']) config['css_paths'] = [] - else + elsif config['css_paths'] config['css_path'] = '' config['css_paths'] = config['css_paths'].collect { |path| format_path(path) } + else + config['css_path'] = ActionController::Base.helpers.stylesheet_path(config['manifest_name'], host: '') + config['css_paths'] = [] end end diff --git a/spec/lib/critical_path_css/rails/config_loader_spec.rb b/spec/lib/critical_path_css/rails/config_loader_spec.rb index c34271d..d5c954c 100644 --- a/spec/lib/critical_path_css/rails/config_loader_spec.rb +++ b/spec/lib/critical_path_css/rails/config_loader_spec.rb @@ -81,7 +81,7 @@ } it 'sets css_path with the path' do - expect(subject.config['css_path']).to eq '/app/spec/internal/public/test.css' + expect(subject.config['css_path']).to eq '/stylesheets/application.css' end it 'leaves css_paths empty' do From 2483d47eecb3a23574b2e2cbb4aefdd68362bbed Mon Sep 17 00:00:00 2001 From: Michael Misshore Date: Sat, 2 Mar 2019 08:23:21 -0600 Subject: [PATCH 62/81] Increment version --- lib/critical_path_css/rails/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/critical_path_css/rails/version.rb b/lib/critical_path_css/rails/version.rb index 327827e..d1298d6 100644 --- a/lib/critical_path_css/rails/version.rb +++ b/lib/critical_path_css/rails/version.rb @@ -1,5 +1,5 @@ module CriticalPathCSS module Rails - VERSION = '3.0.0'.freeze + VERSION = '3.0.1'.freeze end end From d9205e863bf4b6d978d9776f8c1c555a23c865ec Mon Sep 17 00:00:00 2001 From: Michael Misshore Date: Sat, 2 Mar 2019 08:25:12 -0600 Subject: [PATCH 63/81] Remove manifest name --- spec/internal/config/critical_path_css.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/spec/internal/config/critical_path_css.yml b/spec/internal/config/critical_path_css.yml index da7c252..e40cc85 100644 --- a/spec/internal/config/critical_path_css.yml +++ b/spec/internal/config/critical_path_css.yml @@ -1,6 +1,5 @@ defaults: &defaults base_url: http://0.0.0.0:9292 - manifest_name: application css_path: /test.css routes: - / From ad2c9e4061042d4fd3992bc6e6f63fbdca344958 Mon Sep 17 00:00:00 2001 From: Michael Misshore Date: Sat, 2 Mar 2019 08:41:32 -0600 Subject: [PATCH 64/81] Update penthouse to 1.10.2 --- package-lock.json | 54 +++++++++++++++++++++++------------------------ package.json | 7 ++++-- 2 files changed, 32 insertions(+), 29 deletions(-) diff --git a/package-lock.json b/package-lock.json index bc55893..bee59b8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -72,17 +72,17 @@ } }, "debug": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/debug/-/debug-4.1.0.tgz", - "integrity": "sha512-heNPJUJIqC+xB6ayLAMHaIrmN9HKa7aQO8MGqKpvCA+uJYVcvR6l5kgdrhRuwPFHU7P5/A1w0BjByPHwpfTDKg==", + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.1.1.tgz", + "integrity": "sha512-pYAIzeRo8J6KPEaJ0VWOh5Pzkbw/RetuzehGM7QRRX5he4fPHx2rdKMB256ehJCkX+XRQm16eZLqLNS8RSZXZw==", "requires": { "ms": "^2.1.1" } }, "es6-promise": { - "version": "4.2.5", - "resolved": "https://registry.npmjs.org/es6-promise/-/es6-promise-4.2.5.tgz", - "integrity": "sha512-n6wvpdE43VFtJq+lUDYDBFUwV8TZbuGXLV4D6wKafg13ldznKsyEvatubnmUe31zcvelSzOHF+XbaT+Bl9ObDg==" + "version": "4.2.6", + "resolved": "https://registry.npmjs.org/es6-promise/-/es6-promise-4.2.6.tgz", + "integrity": "sha512-aRVgGdnmW2OiySVPUC9e6m+plolMAJKjZnQlCwNSuK5yQ0JN61DZSO1X1Ufd1foqWRAlig0rhduTCHe7sVtK5Q==" }, "es6-promisify": { "version": "5.0.0", @@ -183,9 +183,9 @@ "integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=" }, "jsesc": { - "version": "2.5.1", - "resolved": "https://registry.npmjs.org/jsesc/-/jsesc-2.5.1.tgz", - "integrity": "sha1-5CGiqOINawgZ3yiQj3glJrlt0f4=" + "version": "2.5.2", + "resolved": "https://registry.npmjs.org/jsesc/-/jsesc-2.5.2.tgz", + "integrity": "sha512-OYu7XEzjkCQ3C5Ps3QIZsQfNpqoJyZZA99wd9aWd05NCtC5pWOkShK2mkL6HXQR6/Cy2lbNdPlZBpuQHXE63gA==" }, "mdn-data": { "version": "1.1.4", @@ -193,9 +193,9 @@ "integrity": "sha512-FSYbp3lyKjyj3E7fMl6rYvUdX0FBXaluGqlFoYESWQlyUTq8R+wp0rkFxoYFqZlHCvsUXGjyJmLQSnXToYhOSA==" }, "mime": { - "version": "2.3.1", - "resolved": "https://registry.npmjs.org/mime/-/mime-2.3.1.tgz", - "integrity": "sha512-OEUllcVoydBHGN1z84yfQDimn58pZNNNXgZlHXSboxMlFvgI6MXSWpWKpFRra7H1HxpVhHTkrghfRW49k6yjeg==" + "version": "2.4.0", + "resolved": "https://registry.npmjs.org/mime/-/mime-2.4.0.tgz", + "integrity": "sha512-ikBcWwyqXQSHKtciCcctu9YfPbFYZ4+gbHEmE0Q8jzcTYQg5dHCr3g2wwAZjPoJfQVXZq6KXAjpXOTf5/cjT7w==" }, "minimatch": { "version": "3.0.4", @@ -242,15 +242,15 @@ "integrity": "sha1-elfrVQpng/kRUzH89GY9XI4AelA=" }, "penthouse": { - "version": "1.10.1", - "resolved": "https://registry.npmjs.org/penthouse/-/penthouse-1.10.1.tgz", - "integrity": "sha512-D0fUazt6EvtoJvbKJ4u6yVIwfrWoSW1+2clr5JZaKag5pzgwLJKYcN8NgmAoBmWOwsMk+3ZAkV5Cv09LzQtqAw==", + "version": "1.10.2", + "resolved": "https://registry.npmjs.org/penthouse/-/penthouse-1.10.2.tgz", + "integrity": "sha512-RgUVXpO/AAIA8GBesA/P/8S4XbxT0bLaA74+Oy4/iigIgWL3SlU5vdHNYH/VyneAYU56rbc9FkesjIVQGJwpng==", "requires": { "css-mediaquery": "^0.1.2", "css-tree": "1.0.0-alpha.28", "debug": "^4.1.0", - "jsesc": "^2.5.1", - "puppeteer": "1.9.0" + "jsesc": "^2.5.2", + "puppeteer": "1.10.0" } }, "process-nextick-args": { @@ -259,9 +259,9 @@ "integrity": "sha512-MtEC1TqN0EU5nephaJ4rAtThHtC86dNN9qCuEhtshvpVBkAW5ZO7BASN9REnF9eoXGcRub+pFuKEpOHE+HbEMw==" }, "progress": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/progress/-/progress-2.0.1.tgz", - "integrity": "sha512-OE+a6vzqazc+K6LxJrX5UPyKFvGnL5CYmq2jFGNIBWHpc4QyE49/YOumcrpQFJpfejmvRtbJzgO1zPmMCqlbBg==" + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/progress/-/progress-2.0.3.tgz", + "integrity": "sha512-7PiHtLll5LdnKIMw100I+8xJXR5gW2QwWYkT6iJva0bXitZKa/XMrSbdmg3r2Xnaidz9Qumd0VPaMrZlF9V9sA==" }, "proxy-from-env": { "version": "1.0.0", @@ -269,9 +269,9 @@ "integrity": "sha1-M8UDmPcOp+uW0h97gXYwpVeRx+4=" }, "puppeteer": { - "version": "1.9.0", - "resolved": "https://registry.npmjs.org/puppeteer/-/puppeteer-1.9.0.tgz", - "integrity": "sha512-GH4PmhJf9wBRAPvtJkEJLAvdNNOofZortmBZSj8cGWYni98GUFqsf66blOEfJbo5B8l0KG5HR2d/W2MejnUrzg==", + "version": "1.10.0", + "resolved": "https://registry.npmjs.org/puppeteer/-/puppeteer-1.10.0.tgz", + "integrity": "sha512-3i28X/ucX8t3eL4TZA60FLMOQNKqudFSOGDHr0cT7T4dE027CrcS885aAqjdxNybhMPliM5yImNsKJ6SQrPzhw==", "requires": { "debug": "^3.1.0", "extract-zip": "^1.6.6", @@ -308,11 +308,11 @@ } }, "rimraf": { - "version": "2.6.2", - "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.6.2.tgz", - "integrity": "sha512-lreewLK/BlghmxtfH36YYVg1i8IAce4TI7oao75I1g245+6BctqTVQiBP3YUJ9C6DQOXJmkYR9X9fCLtCOJc5w==", + "version": "2.6.3", + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.6.3.tgz", + "integrity": "sha512-mwqeW5XsA2qAejG46gYdENaxXjx9onRNCfn7L0duuP4hCuTIi/QO7PDK07KJfp1d+izWPrzEJDcSqBa0OZQriA==", "requires": { - "glob": "^7.0.5" + "glob": "^7.1.3" } }, "safe-buffer": { diff --git a/package.json b/package.json index d781877..c5e1637 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,10 @@ "lib": "lib" }, "dependencies": { - "penthouse": "=1.10.1" + "penthouse": "=1.10.2" }, - "license": "MIT" + "license": "MIT", + "config": { + "puppeteer_skip_chromium_download": true + } } From 22a1b25b0ad3bafd9c4adbef98b1cc544623693f Mon Sep 17 00:00:00 2001 From: Michael Misshore Date: Sat, 2 Mar 2019 08:41:52 -0600 Subject: [PATCH 65/81] Increment version --- lib/critical_path_css/rails/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/critical_path_css/rails/version.rb b/lib/critical_path_css/rails/version.rb index d1298d6..1e039c0 100644 --- a/lib/critical_path_css/rails/version.rb +++ b/lib/critical_path_css/rails/version.rb @@ -1,5 +1,5 @@ module CriticalPathCSS module Rails - VERSION = '3.0.1'.freeze + VERSION = '3.0.2'.freeze end end From 378a1289dd89f5f14770798befba0673961e376d Mon Sep 17 00:00:00 2001 From: Michael Misshore Date: Sun, 3 Mar 2019 06:43:31 -0600 Subject: [PATCH 66/81] Move configs into fixtures --- .../files/config/mutliple-css-paths.yml | 14 +++ .../files/config/no-paths-specified.yml | 11 +++ .../paths-and-routes-not-same-length.yml | 15 +++ .../files/config/paths-both-specified.yml | 15 +++ .../fixtures/files/config/single-css-path.yml | 11 +++ .../rails/config_loader_spec.rb | 91 +------------------ 6 files changed, 71 insertions(+), 86 deletions(-) create mode 100644 spec/fixtures/files/config/mutliple-css-paths.yml create mode 100644 spec/fixtures/files/config/no-paths-specified.yml create mode 100644 spec/fixtures/files/config/paths-and-routes-not-same-length.yml create mode 100644 spec/fixtures/files/config/paths-both-specified.yml create mode 100644 spec/fixtures/files/config/single-css-path.yml diff --git a/spec/fixtures/files/config/mutliple-css-paths.yml b/spec/fixtures/files/config/mutliple-css-paths.yml new file mode 100644 index 0000000..2c778c2 --- /dev/null +++ b/spec/fixtures/files/config/mutliple-css-paths.yml @@ -0,0 +1,14 @@ +defaults: &defaults + base_url: http://0.0.0.0:9292 + css_paths: + - /test.css + - /test2.css + routes: + - / + - /new_route + +development: + <<: *defaults + +test: + <<: *defaults \ No newline at end of file diff --git a/spec/fixtures/files/config/no-paths-specified.yml b/spec/fixtures/files/config/no-paths-specified.yml new file mode 100644 index 0000000..e327054 --- /dev/null +++ b/spec/fixtures/files/config/no-paths-specified.yml @@ -0,0 +1,11 @@ +defaults: &defaults + base_url: http://0.0.0.0:9292 + manifest_name: application + routes: + - / + +development: + <<: *defaults + +test: + <<: *defaults \ No newline at end of file diff --git a/spec/fixtures/files/config/paths-and-routes-not-same-length.yml b/spec/fixtures/files/config/paths-and-routes-not-same-length.yml new file mode 100644 index 0000000..f53a0ff --- /dev/null +++ b/spec/fixtures/files/config/paths-and-routes-not-same-length.yml @@ -0,0 +1,15 @@ +defaults: &defaults + base_url: http://0.0.0.0:9292 + css_paths: + - /test.css + - /test2.css + routes: + - / + - /new_route + - /newer_route + +development: + <<: *defaults + +test: + <<: *defaults \ No newline at end of file diff --git a/spec/fixtures/files/config/paths-both-specified.yml b/spec/fixtures/files/config/paths-both-specified.yml new file mode 100644 index 0000000..55f6396 --- /dev/null +++ b/spec/fixtures/files/config/paths-both-specified.yml @@ -0,0 +1,15 @@ +defaults: &defaults + base_url: http://0.0.0.0:9292 + css_path: /test.css + css_paths: + - /test.css + - /test2.css + routes: + - / + - /new_route + +development: + <<: *defaults + +test: + <<: *defaults \ No newline at end of file diff --git a/spec/fixtures/files/config/single-css-path.yml b/spec/fixtures/files/config/single-css-path.yml new file mode 100644 index 0000000..90d1711 --- /dev/null +++ b/spec/fixtures/files/config/single-css-path.yml @@ -0,0 +1,11 @@ +defaults: &defaults + base_url: http://0.0.0.0:9292 + css_path: /test.css + routes: + - / + +development: + <<: *defaults + +test: + <<: *defaults \ No newline at end of file diff --git a/spec/lib/critical_path_css/rails/config_loader_spec.rb b/spec/lib/critical_path_css/rails/config_loader_spec.rb index d5c954c..971386b 100644 --- a/spec/lib/critical_path_css/rails/config_loader_spec.rb +++ b/spec/lib/critical_path_css/rails/config_loader_spec.rb @@ -9,21 +9,7 @@ end context 'when single css_path is specified' do - let(:config_file) { - <<~CONFIG - defaults: &defaults - base_url: http://0.0.0.0:9292 - css_path: /test.css - routes: - - / - - development: - <<: *defaults - - test: - <<: *defaults - CONFIG - } + let(:config_file) { file_fixture('config/single-css-path.yml').read } it 'sets css_path with the path' do expect(subject.config['css_path']).to eq '/app/spec/internal/public/test.css' @@ -35,24 +21,7 @@ end context 'when multiple css_paths are specified' do - let(:config_file) { - <<~CONFIG - defaults: &defaults - base_url: http://0.0.0.0:9292 - css_paths: - - /test.css - - /test2.css - routes: - - / - - /new_route - - development: - <<: *defaults - - test: - <<: *defaults - CONFIG - } + let(:config_file) { file_fixture('config/mutliple-css-paths.yml').read } it 'sets css_path to empty string' do expect(subject.config['css_path']).to eq '' @@ -64,21 +33,7 @@ end context 'when no paths are specified' do - let(:config_file) { - <<~CONFIG - defaults: &defaults - base_url: http://0.0.0.0:9292 - manifest_name: application - routes: - - / - - development: - <<: *defaults - - test: - <<: *defaults - CONFIG - } + let(:config_file) { file_fixture('config/no-paths-specified.yml').read } it 'sets css_path with the path' do expect(subject.config['css_path']).to eq '/stylesheets/application.css' @@ -90,25 +45,7 @@ end context 'when single css_path and multiple css_paths are both specified' do - let(:config_file) { - <<~CONFIG - defaults: &defaults - base_url: http://0.0.0.0:9292 - css_path: /test.css - css_paths: - - /test.css - - /test2.css - routes: - - / - - /new_route - - development: - <<: *defaults - - test: - <<: *defaults - CONFIG - } + let(:config_file) { file_fixture('config/paths-both-specified.yml').read } it 'raises an error' do expect { subject }.to raise_error LoadError, 'Cannot specify both css_path and css_paths' @@ -116,25 +53,7 @@ end context 'when css_paths and routes are not the same length' do - let(:config_file) { - <<~CONFIG - defaults: &defaults - base_url: http://0.0.0.0:9292 - css_paths: - - /test.css - - /test2.css - routes: - - / - - /new_route - - /newer_route - - development: - <<: *defaults - - test: - <<: *defaults - CONFIG - } + let(:config_file) { file_fixture('config/paths-and-routes-not-same-length.yml').read } it 'raises an error' do expect { subject }.to raise_error LoadError, 'Must specify css_paths for each route' From 60ee217adb2331441cea38d516a7b6ba54ab81ca Mon Sep 17 00:00:00 2001 From: Michael Misshore Date: Sun, 3 Mar 2019 06:46:00 -0600 Subject: [PATCH 67/81] Use subject --- spec/lib/critical_path_css/css_fetcher_spec.rb | 3 ++- spec/lib/critical_path_css/rails/config_loader_spec.rb | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/spec/lib/critical_path_css/css_fetcher_spec.rb b/spec/lib/critical_path_css/css_fetcher_spec.rb index 32b0cd9..1c8c5a4 100644 --- a/spec/lib/critical_path_css/css_fetcher_spec.rb +++ b/spec/lib/critical_path_css/css_fetcher_spec.rb @@ -1,7 +1,8 @@ require 'spec_helper' RSpec.describe 'CssFetcher' do - let(:subject) { CriticalPathCss::CssFetcher.new(config) } + subject { CriticalPathCss::CssFetcher.new(config) } + let(:response) { ['foo','', OpenStruct.new(exitstatus: 0)] } let(:routes) { ['/', '/new_route'] } let(:config) do diff --git a/spec/lib/critical_path_css/rails/config_loader_spec.rb b/spec/lib/critical_path_css/rails/config_loader_spec.rb index 971386b..e3fe48b 100644 --- a/spec/lib/critical_path_css/rails/config_loader_spec.rb +++ b/spec/lib/critical_path_css/rails/config_loader_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' RSpec.describe 'ConfigLoader' do - let(:subject) { CriticalPathCss::Rails::ConfigLoader.new } + subject { CriticalPathCss::Rails::ConfigLoader.new } describe '#load' do before do From 7f85a105597d9fdb3ef5c38896bcc46a84957a82 Mon Sep 17 00:00:00 2001 From: Michael Misshore Date: Sun, 3 Mar 2019 07:26:06 -0600 Subject: [PATCH 68/81] Refactor fetcher spec Refactor base url and expect options --- .../lib/critical_path_css/css_fetcher_spec.rb | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/spec/lib/critical_path_css/css_fetcher_spec.rb b/spec/lib/critical_path_css/css_fetcher_spec.rb index 1c8c5a4..481a950 100644 --- a/spec/lib/critical_path_css/css_fetcher_spec.rb +++ b/spec/lib/critical_path_css/css_fetcher_spec.rb @@ -3,11 +3,12 @@ RSpec.describe 'CssFetcher' do subject { CriticalPathCss::CssFetcher.new(config) } + let(:base_url) { 'http://0.0.0.0:9292' } let(:response) { ['foo','', OpenStruct.new(exitstatus: 0)] } - let(:routes) { ['/', '/new_route'] } + let(:routes) { ['/', '/new_route'] } let(:config) do OpenStruct.new( - base_url: 'http://0.0.0.0:9292', + base_url: base_url, css_path: css_path, css_paths: css_paths, penthouse_options: {}, @@ -23,6 +24,7 @@ it 'generates css for the single route' do expect(Open3).to receive(:capture3) do |arg1, arg2, arg3| options = JSON.parse(arg3) + expect(options['css']).to eq '/test.css' end.once.and_return(response) @@ -39,8 +41,10 @@ it 'generates css for each route from the same file' do expect(Open3).to receive(:capture3) do |arg1, arg2, arg3| options = JSON.parse(arg3) + expect(options['css']).to eq '/test.css' end.twice.and_return(response) + subject.fetch end end @@ -52,9 +56,12 @@ it 'generates css for each route from the respective file' do expect(Open3).to receive(:capture3) do |arg1, arg2, arg3| options = JSON.parse(arg3) - expect(options['css']).to eq '/test.css' if options['url'] == 'http://0.0.0.0:9292/' - expect(options['css']).to eq '/test2.css' if options['url'] == 'http://0.0.0.0:9292/new_route' + + css_paths.each_with_index do |path, index| + expect(options['css']).to eq path if options['url'] == "#{base_url}/#{routes[index]}" + end end.twice.and_return(response) + subject.fetch end end @@ -67,10 +74,12 @@ it 'generates css for each route from the respective file' do expect(Open3).to receive(:capture3) do |arg1, arg2, arg3| options = JSON.parse(arg3) - expect(options['css']).to eq '/test.css' if options['url'] == 'http://0.0.0.0:9292/' - expect(options['css']).to eq '/test2.css' if options['url'] == 'http://0.0.0.0:9292/new_route' - expect(options['css']).to eq '/test.css' if options['url'] == 'http://0.0.0.0:9292/newer_route' + + css_paths.each_with_index do |path, index| + expect(options['css']).to eq path if options['url'] == "#{base_url}/#{routes[index]}" + end end.thrice.and_return(response) + subject.fetch end end From bdcbc593e24e6bb54d04b3ba4c0f6a319b94893e Mon Sep 17 00:00:00 2001 From: Michael Misshore Date: Sun, 3 Mar 2019 08:25:19 -0600 Subject: [PATCH 69/81] Only reference css_paths config --- lib/critical_path_css/configuration.rb | 4 ---- lib/critical_path_css/rails/config_loader.rb | 13 +++++------- .../lib/critical_path_css/css_fetcher_spec.rb | 8 ++------ .../rails/config_loader_spec.rb | 20 ++++--------------- 4 files changed, 11 insertions(+), 34 deletions(-) diff --git a/lib/critical_path_css/configuration.rb b/lib/critical_path_css/configuration.rb index b8865ff..ae5fb39 100644 --- a/lib/critical_path_css/configuration.rb +++ b/lib/critical_path_css/configuration.rb @@ -9,10 +9,6 @@ def base_url @config['base_url'] end - def css_path - @config['css_path'] - end - def css_paths @config['css_paths'] end diff --git a/lib/critical_path_css/rails/config_loader.rb b/lib/critical_path_css/rails/config_loader.rb index 079f263..d8dae0f 100644 --- a/lib/critical_path_css/rails/config_loader.rb +++ b/lib/critical_path_css/rails/config_loader.rb @@ -19,15 +19,12 @@ def configuration_file_path end def format_css_paths - if config['css_path'] - config['css_path'] = format_path(config['css_path']) - config['css_paths'] = [] - elsif config['css_paths'] - config['css_path'] = '' - config['css_paths'] = config['css_paths'].collect { |path| format_path(path) } + config['css_paths'] = [config['css_path']] if config['css_path'] + + if config['css_paths'] + config['css_paths'].map! { |path| format_path(path) } else - config['css_path'] = ActionController::Base.helpers.stylesheet_path(config['manifest_name'], host: '') - config['css_paths'] = [] + config['css_paths'] = [ActionController::Base.helpers.stylesheet_path(config['manifest_name'], host: '')] end end diff --git a/spec/lib/critical_path_css/css_fetcher_spec.rb b/spec/lib/critical_path_css/css_fetcher_spec.rb index 481a950..a117efd 100644 --- a/spec/lib/critical_path_css/css_fetcher_spec.rb +++ b/spec/lib/critical_path_css/css_fetcher_spec.rb @@ -18,8 +18,7 @@ describe '#fetch_route' do context 'when a single css_path is configured' do - let(:css_path) { '/test.css' } - let(:css_paths) { [] } + let(:css_paths) { ['/test.css'] } it 'generates css for the single route' do expect(Open3).to receive(:capture3) do |arg1, arg2, arg3| @@ -35,8 +34,7 @@ describe '#fetch' do context 'when a single css_path is configured' do - let(:css_path) { '/test.css' } - let(:css_paths) { [] } + let(:css_paths) { ['/test.css'] } it 'generates css for each route from the same file' do expect(Open3).to receive(:capture3) do |arg1, arg2, arg3| @@ -50,7 +48,6 @@ end context 'when multiple css_paths are configured' do - let(:css_path) { '' } let(:css_paths) { ['/test.css', '/test2.css'] } it 'generates css for each route from the respective file' do @@ -67,7 +64,6 @@ end context 'when same css file applies to multiple routes' do - let(:css_path) { '' } let(:css_paths) { ['/test.css', '/test2.css', '/test.css'] } let(:routes) { ['/', '/new_route', '/newer_route'] } diff --git a/spec/lib/critical_path_css/rails/config_loader_spec.rb b/spec/lib/critical_path_css/rails/config_loader_spec.rb index e3fe48b..e20c289 100644 --- a/spec/lib/critical_path_css/rails/config_loader_spec.rb +++ b/spec/lib/critical_path_css/rails/config_loader_spec.rb @@ -11,22 +11,14 @@ context 'when single css_path is specified' do let(:config_file) { file_fixture('config/single-css-path.yml').read } - it 'sets css_path with the path' do - expect(subject.config['css_path']).to eq '/app/spec/internal/public/test.css' - end - - it 'leaves css_paths empty' do - expect(subject.config['css_paths']).to eq [] + it 'sets css_paths with the lone path' do + expect(subject.config['css_paths']).to eq ['/app/spec/internal/public/test.css'] end end context 'when multiple css_paths are specified' do let(:config_file) { file_fixture('config/mutliple-css-paths.yml').read } - it 'sets css_path to empty string' do - expect(subject.config['css_path']).to eq '' - end - it 'leaves css_paths to an array of paths' do expect(subject.config['css_paths']).to eq ['/app/spec/internal/public/test.css','/app/spec/internal/public/test2.css'] end @@ -35,12 +27,8 @@ context 'when no paths are specified' do let(:config_file) { file_fixture('config/no-paths-specified.yml').read } - it 'sets css_path with the path' do - expect(subject.config['css_path']).to eq '/stylesheets/application.css' - end - - it 'leaves css_paths empty' do - expect(subject.config['css_paths']).to eq [] + it 'sets css_paths with the lone manifest path' do + expect(subject.config['css_paths']).to eq ['/stylesheets/application.css'] end end From 979758d32c3cc0d5992f360a7b2159671bbf3013 Mon Sep 17 00:00:00 2001 From: Michael Misshore Date: Sun, 3 Mar 2019 08:25:34 -0600 Subject: [PATCH 70/81] Refactor path for route --- lib/critical_path_css/configuration.rb | 4 ++++ lib/critical_path_css/css_fetcher.rb | 14 +------------- spec/lib/critical_path_css/css_fetcher_spec.rb | 13 +++++++------ 3 files changed, 12 insertions(+), 19 deletions(-) diff --git a/lib/critical_path_css/configuration.rb b/lib/critical_path_css/configuration.rb index ae5fb39..405787b 100644 --- a/lib/critical_path_css/configuration.rb +++ b/lib/critical_path_css/configuration.rb @@ -24,5 +24,9 @@ def routes def penthouse_options @config['penthouse_options'] || {} end + + def path_for_route(route) + css_paths[routes.index(route)] || css_paths.first + end end end diff --git a/lib/critical_path_css/css_fetcher.rb b/lib/critical_path_css/css_fetcher.rb index 54a9880..f213f90 100644 --- a/lib/critical_path_css/css_fetcher.rb +++ b/lib/critical_path_css/css_fetcher.rb @@ -16,7 +16,7 @@ def fetch def fetch_route(route) options = { 'url' => @config.base_url + route, - 'css' => fetch_css_path_for_route(route), + 'css' => @config.path_for_route(route), 'width' => 1300, 'height' => 900, 'timeout' => 30_000, @@ -51,17 +51,5 @@ def fetch_route(route) end out end - - private - - def fetch_css_path_for_route(route) - index_for_route = @config.routes.index(route) - - if index_for_route && @config.css_paths[index_for_route] - @config.css_paths[index_for_route] - else - @config.css_path - end - end end end diff --git a/spec/lib/critical_path_css/css_fetcher_spec.rb b/spec/lib/critical_path_css/css_fetcher_spec.rb index a117efd..e795af4 100644 --- a/spec/lib/critical_path_css/css_fetcher_spec.rb +++ b/spec/lib/critical_path_css/css_fetcher_spec.rb @@ -7,12 +7,13 @@ let(:response) { ['foo','', OpenStruct.new(exitstatus: 0)] } let(:routes) { ['/', '/new_route'] } let(:config) do - OpenStruct.new( - base_url: base_url, - css_path: css_path, - css_paths: css_paths, - penthouse_options: {}, - routes: routes + CriticalPathCss::Configuration.new( + OpenStruct.new( + base_url: base_url, + css_paths: css_paths, + penthouse_options: {}, + routes: routes + ) ) end From a59875c14a74a32568c1f2fbeed101a4e0741812 Mon Sep 17 00:00:00 2001 From: Michael Misshore Date: Sun, 3 Mar 2019 08:30:07 -0600 Subject: [PATCH 71/81] Version increment --- lib/critical_path_css/rails/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/critical_path_css/rails/version.rb b/lib/critical_path_css/rails/version.rb index 1e039c0..64aebf0 100644 --- a/lib/critical_path_css/rails/version.rb +++ b/lib/critical_path_css/rails/version.rb @@ -1,5 +1,5 @@ module CriticalPathCSS module Rails - VERSION = '3.0.2'.freeze + VERSION = '3.0.3'.freeze end end From 1cc72b9df6c9a08908c0f6221bb743749339dd44 Mon Sep 17 00:00:00 2001 From: Michael Misshore Date: Sun, 3 Mar 2019 08:35:08 -0600 Subject: [PATCH 72/81] Remove gem build warnings --- critical-path-css-rails.gemspec | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/critical-path-css-rails.gemspec b/critical-path-css-rails.gemspec index 41196ce..c519083 100644 --- a/critical-path-css-rails.gemspec +++ b/critical-path-css-rails.gemspec @@ -9,12 +9,13 @@ Gem::Specification.new do |gem| gem.summary = 'Critical Path CSS for Rails!' gem.description = 'Only load the CSS you need for the initial viewport in Rails!' gem.license = 'MIT' + gem.homepage = 'https://rubygems.org/gems/critical-path-css-rails' gem.files = `git ls-files`.split("\n") gem.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) } gem.require_path = 'lib' - gem.add_development_dependency 'combustion', '~> 1.1.0' + gem.add_development_dependency 'combustion', '~> 1.1', '>= 1.1.0' gem.extensions = ['ext/npm/extconf.rb'] end From 7d0a88a847f01c97eff8bdfaf26137df46441435 Mon Sep 17 00:00:00 2001 From: Michael Misshore Date: Sun, 7 Apr 2019 03:04:46 -0500 Subject: [PATCH 73/81] =?UTF-8?q?Don=E2=80=99t=20raise=20a=20hard=20error?= =?UTF-8?q?=20if=20a=20route=20is=20not=20present.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- lib/critical_path_css/css_fetcher.rb | 2 +- lib/critical_path_css/rails/version.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 74a6e10..9722182 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ However, more packages may need to be installed depending on your OS distributio After reviewing the dependency requirements, add `critical-path-css-rails` to your Gemfile: ``` -gem 'critical-path-css-rails', '~> 3.0.0' +gem 'critical-path-css-rails', '~> 3.1.0' ``` Download and install by running: diff --git a/lib/critical_path_css/css_fetcher.rb b/lib/critical_path_css/css_fetcher.rb index f213f90..987f000 100644 --- a/lib/critical_path_css/css_fetcher.rb +++ b/lib/critical_path_css/css_fetcher.rb @@ -46,7 +46,7 @@ def fetch_route(route) if !st.exitstatus.zero? || out.empty? && !err.empty? STDOUT.puts out STDERR.puts err - raise "Failed to get CSS for route #{route}\n" \ + STDERR.puts "Failed to get CSS for route #{route}\n" \ " with options=#{options.inspect}" end out diff --git a/lib/critical_path_css/rails/version.rb b/lib/critical_path_css/rails/version.rb index 64aebf0..f2e818f 100644 --- a/lib/critical_path_css/rails/version.rb +++ b/lib/critical_path_css/rails/version.rb @@ -1,5 +1,5 @@ module CriticalPathCSS module Rails - VERSION = '3.0.3'.freeze + VERSION = '3.1.0'.freeze end end From 535dfeb39336af024b7cef40e0a08441ad0cbdb2 Mon Sep 17 00:00:00 2001 From: Michael Misshore Date: Mon, 19 Aug 2019 14:56:18 -0500 Subject: [PATCH 74/81] Update penthouse to 2.2.0 --- lib/critical_path_css/rails/version.rb | 2 +- package-lock.json | 100 +++++++++++-------------- package.json | 2 +- 3 files changed, 47 insertions(+), 57 deletions(-) diff --git a/lib/critical_path_css/rails/version.rb b/lib/critical_path_css/rails/version.rb index f2e818f..2ee8821 100644 --- a/lib/critical_path_css/rails/version.rb +++ b/lib/critical_path_css/rails/version.rb @@ -1,5 +1,5 @@ module CriticalPathCSS module Rails - VERSION = '3.1.0'.freeze + VERSION = '4.0.0'.freeze end end diff --git a/package-lock.json b/package-lock.json index bee59b8..c0c6c3f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5,17 +5,17 @@ "requires": true, "dependencies": { "agent-base": { - "version": "4.2.1", - "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-4.2.1.tgz", - "integrity": "sha512-JVwXMr9nHYTUXsBFKUqhJwvlcYU/blreOEUkhNR2eXZIvwd+c+o5V4MgDPKWnMS/56awN3TRzIP+KoPn+roQtg==", + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-4.3.0.tgz", + "integrity": "sha512-salcGninV0nPrwpGNn4VTXBb1SOuXQBiqbrNXoeizJsHrsL6ERFM2Ne3JUSBWRE6aeNJI2ROP/WEEIDUiDe3cg==", "requires": { "es6-promisify": "^5.0.0" } }, "async-limiter": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/async-limiter/-/async-limiter-1.0.0.tgz", - "integrity": "sha512-jp/uFnooOiO+L211eZOoSyzpOITMXx1rBITauYykG3BRYPu8h0UcxsPNB04RR5vo4Tyz3+ay17tR6JVf9qzYWg==" + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/async-limiter/-/async-limiter-1.0.1.tgz", + "integrity": "sha512-csOlWGAcRFJaI6m+F2WKdnMKr4HhdhFVBk0H/QbJFMCr+uO2kwohwXQPxw/9OCxp05r5ghVBFSyioixx3gfkNQ==" }, "balanced-match": { "version": "1.0.0", @@ -80,9 +80,9 @@ } }, "es6-promise": { - "version": "4.2.6", - "resolved": "https://registry.npmjs.org/es6-promise/-/es6-promise-4.2.6.tgz", - "integrity": "sha512-aRVgGdnmW2OiySVPUC9e6m+plolMAJKjZnQlCwNSuK5yQ0JN61DZSO1X1Ufd1foqWRAlig0rhduTCHe7sVtK5Q==" + "version": "4.2.8", + "resolved": "https://registry.npmjs.org/es6-promise/-/es6-promise-4.2.8.tgz", + "integrity": "sha512-HJDGx5daxeIvxdBxvG2cb9g4tEvwIk3i8+nhX0yGrYmZUzbkdg8QbDevheDB8gd0//uPj4c1EQua8Q+MViT0/w==" }, "es6-promisify": { "version": "5.0.0", @@ -132,9 +132,9 @@ "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=" }, "glob": { - "version": "7.1.3", - "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.3.tgz", - "integrity": "sha512-vcfuiIxogLV4DlGBHIUOwI0IbrJ8HWPc4MU7HzviGeNho/UJDfi6B5p3sHeWIQ0KGIU0Jpxi5ZHxemQfLkkAwQ==", + "version": "7.1.4", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.4.tgz", + "integrity": "sha512-hkLPepehmnKk41pUGm3sYxoFs/umurYfYJCerbXEyFIWcAzvpipAgVkBqqT9RBKMGjnq6kMuyYwha6csxbiM1A==", "requires": { "fs.realpath": "^1.0.0", "inflight": "^1.0.4", @@ -145,11 +145,11 @@ } }, "https-proxy-agent": { - "version": "2.2.1", - "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-2.2.1.tgz", - "integrity": "sha512-HPCTS1LW51bcyMYbxUIOO4HEOlQ1/1qRaFWcyxvwaqUS9TY88aoEuHUY33kuAh1YhVVaDQhLZsnPd+XNARWZlQ==", + "version": "2.2.2", + "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-2.2.2.tgz", + "integrity": "sha512-c8Ndjc9Bkpfx/vCJueCPy0jlP4ccCCSNDp8xwCZzPjKJUm+B+u9WX2x98Qx4n1PiMNTWo3D7KK5ifNV/yJyRzg==", "requires": { - "agent-base": "^4.1.0", + "agent-base": "^4.3.0", "debug": "^3.1.0" }, "dependencies": { @@ -173,9 +173,9 @@ } }, "inherits": { - "version": "2.0.3", - "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", - "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=" + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", + "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==" }, "isarray": { "version": "1.0.0", @@ -193,9 +193,9 @@ "integrity": "sha512-FSYbp3lyKjyj3E7fMl6rYvUdX0FBXaluGqlFoYESWQlyUTq8R+wp0rkFxoYFqZlHCvsUXGjyJmLQSnXToYhOSA==" }, "mime": { - "version": "2.4.0", - "resolved": "https://registry.npmjs.org/mime/-/mime-2.4.0.tgz", - "integrity": "sha512-ikBcWwyqXQSHKtciCcctu9YfPbFYZ4+gbHEmE0Q8jzcTYQg5dHCr3g2wwAZjPoJfQVXZq6KXAjpXOTf5/cjT7w==" + "version": "2.4.4", + "resolved": "https://registry.npmjs.org/mime/-/mime-2.4.4.tgz", + "integrity": "sha512-LRxmNwziLPT828z+4YkNzloCFC2YM4wrB99k+AV5ZbEyfGNWfG8SO1FUXLmLDBSo89NrJZ4DIWeLjy1CHGhMGA==" }, "minimatch": { "version": "3.0.4", @@ -219,9 +219,9 @@ } }, "ms": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.1.tgz", - "integrity": "sha512-tgp+dl5cGk28utYktBsrFqA7HKgrhgPsg6Z/EfhWI4gl1Hwq8B/GmY/0oXZ6nF8hDVesS/FpnYaD/kOWhYQvyg==" + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" }, "once": { "version": "1.4.0", @@ -242,21 +242,21 @@ "integrity": "sha1-elfrVQpng/kRUzH89GY9XI4AelA=" }, "penthouse": { - "version": "1.10.2", - "resolved": "https://registry.npmjs.org/penthouse/-/penthouse-1.10.2.tgz", - "integrity": "sha512-RgUVXpO/AAIA8GBesA/P/8S4XbxT0bLaA74+Oy4/iigIgWL3SlU5vdHNYH/VyneAYU56rbc9FkesjIVQGJwpng==", + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/penthouse/-/penthouse-2.2.0.tgz", + "integrity": "sha512-Mgw9GpwV2D0ZwaJjW6FaXsybaHe/LiQBb2BcX0LQm+AkzHVMp1gyuy1Z4VQfKf4G2ovGVYg5T60UoO+BArculw==", "requires": { "css-mediaquery": "^0.1.2", "css-tree": "1.0.0-alpha.28", - "debug": "^4.1.0", + "debug": "^4.1.1", "jsesc": "^2.5.2", - "puppeteer": "1.10.0" + "puppeteer": "1.15.0" } }, "process-nextick-args": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.0.tgz", - "integrity": "sha512-MtEC1TqN0EU5nephaJ4rAtThHtC86dNN9qCuEhtshvpVBkAW5ZO7BASN9REnF9eoXGcRub+pFuKEpOHE+HbEMw==" + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.1.tgz", + "integrity": "sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==" }, "progress": { "version": "2.0.3", @@ -269,28 +269,18 @@ "integrity": "sha1-M8UDmPcOp+uW0h97gXYwpVeRx+4=" }, "puppeteer": { - "version": "1.10.0", - "resolved": "https://registry.npmjs.org/puppeteer/-/puppeteer-1.10.0.tgz", - "integrity": "sha512-3i28X/ucX8t3eL4TZA60FLMOQNKqudFSOGDHr0cT7T4dE027CrcS885aAqjdxNybhMPliM5yImNsKJ6SQrPzhw==", + "version": "1.15.0", + "resolved": "https://registry.npmjs.org/puppeteer/-/puppeteer-1.15.0.tgz", + "integrity": "sha512-D2y5kwA9SsYkNUmcBzu9WZ4V1SGHiQTmgvDZSx6sRYFsgV25IebL4V6FaHjF6MbwLK9C6f3G3pmck9qmwM8H3w==", "requires": { - "debug": "^3.1.0", + "debug": "^4.1.0", "extract-zip": "^1.6.6", "https-proxy-agent": "^2.2.1", "mime": "^2.0.3", - "progress": "^2.0.0", + "progress": "^2.0.1", "proxy-from-env": "^1.0.0", "rimraf": "^2.6.1", - "ws": "^5.1.1" - }, - "dependencies": { - "debug": { - "version": "3.2.6", - "resolved": "https://registry.npmjs.org/debug/-/debug-3.2.6.tgz", - "integrity": "sha512-mel+jf7nrtEl5Pn1Qx46zARXKDpBbvzezse7p7LqINmdoIk8PYP5SySaxEmYv6TZ0JyEKA1hsCId6DIhgITtWQ==", - "requires": { - "ms": "^2.1.1" - } - } + "ws": "^6.1.0" } }, "readable-stream": { @@ -308,9 +298,9 @@ } }, "rimraf": { - "version": "2.6.3", - "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.6.3.tgz", - "integrity": "sha512-mwqeW5XsA2qAejG46gYdENaxXjx9onRNCfn7L0duuP4hCuTIi/QO7PDK07KJfp1d+izWPrzEJDcSqBa0OZQriA==", + "version": "2.7.1", + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.7.1.tgz", + "integrity": "sha512-uWjbaKIK3T1OSVptzX7Nl6PvQ3qAGtKEtVRjRuazjfL3Bx5eI409VZSqgND+4UNnmzLVdPj9FqFJNPqBZFve4w==", "requires": { "glob": "^7.1.3" } @@ -349,9 +339,9 @@ "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=" }, "ws": { - "version": "5.2.2", - "resolved": "https://registry.npmjs.org/ws/-/ws-5.2.2.tgz", - "integrity": "sha512-jaHFD6PFv6UgoIVda6qZllptQsMlDEJkTQcybzzXDYM1XO9Y8em691FGMPmM46WGyLU4z9KMgQN+qrux/nhlHA==", + "version": "6.2.1", + "resolved": "https://registry.npmjs.org/ws/-/ws-6.2.1.tgz", + "integrity": "sha512-GIyAXC2cB7LjvpgMt9EKS2ldqr0MTrORaleiOno6TweZ6r3TKtoFQWay/2PceJ3RuBasOHzXNn5Lrw1X0bEjqA==", "requires": { "async-limiter": "~1.0.0" } diff --git a/package.json b/package.json index c5e1637..c82eb65 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "lib": "lib" }, "dependencies": { - "penthouse": "=1.10.2" + "penthouse": "=2.2.0" }, "license": "MIT", "config": { From 1371f5e27e665d8a074365c7d78d3a15b1af8835 Mon Sep 17 00:00:00 2001 From: Michael Misshore Date: Mon, 19 Aug 2019 15:27:18 -0500 Subject: [PATCH 75/81] Add exception to prevent invalid configuration manifest and css path(s) cannot/should not be both defined --- README.md | 4 +++- lib/critical_path_css/rails/config_loader.rb | 4 +++- lib/critical_path_css/rails/version.rb | 2 +- .../config/manifest-and-path-both-specified.yml | 10 ++++++++++ .../config/manifest-and-paths-both-specified.yml | 15 +++++++++++++++ .../rails/config_loader_spec.rb | 16 ++++++++++++++++ 6 files changed, 48 insertions(+), 3 deletions(-) create mode 100644 spec/fixtures/files/config/manifest-and-path-both-specified.yml create mode 100644 spec/fixtures/files/config/manifest-and-paths-both-specified.yml diff --git a/README.md b/README.md index 9722182..7d692f9 100644 --- a/README.md +++ b/README.md @@ -52,9 +52,11 @@ The generator adds the following files: First, you'll need to configue a few things in the YAML file: `config/critical_path_css.yml` +**Note** that `manifest_name`, `css_path`, `css_paths` are all **mutually exclusive**; if using `css_path`, configuration for `manifest_name` AND `css_paths` should be omitted. + * `manifest_name`: If you're using the asset pipeline, add the manifest name. * `css_path`: If you're not using the asset pipeline, you'll need to define the path to the application's main CSS. The gem assumes your CSS lives in `RAILS_ROOT/public`. If your main CSS file is in `RAILS_ROOT/public/assets/main.css`, you would set the variable to `/assets/main.css`. -* `css_paths`: If you have the need to specify multiple CSS source files, you can do so with `css_paths`. Note that `css_path` and `css_paths` are **mutually exclusive**; if using `css_path`, configuration for `css_paths` should be omitted, and vice versa. When using this option, a separate CSS path must be specified for each route, and they will be matched based on the order specified (the first CSS path will be applied to the first route, the second CSS path to the second route, etc). +* `css_paths`: If you have the need to specify multiple CSS source files, you can do so with `css_paths`. When using this option, a separate CSS path must be specified for each route, and they will be matched based on the order specified (the first CSS path will be applied to the first route, the second CSS path to the second route, etc). * `routes`: List the routes that you would like to generate the critical CSS for. (i.e. /resources, /resources/show/1, etc.) * `base_url`: Add your application's URL for the necessary environments. diff --git a/lib/critical_path_css/rails/config_loader.rb b/lib/critical_path_css/rails/config_loader.rb index d8dae0f..1158a1b 100644 --- a/lib/critical_path_css/rails/config_loader.rb +++ b/lib/critical_path_css/rails/config_loader.rb @@ -33,7 +33,9 @@ def format_path(path) end def validate_css_paths - if config['css_path'] && config['css_paths'] + if config['manifest_name'] && (config['css_path'] || config['css_paths']) + raise LoadError, 'Cannot specify both manifest_name and css_path(s)' + elsif config['css_path'] && config['css_paths'] raise LoadError, 'Cannot specify both css_path and css_paths' elsif config['css_paths'] && config['css_paths'].length != config['routes'].length raise LoadError, 'Must specify css_paths for each route' diff --git a/lib/critical_path_css/rails/version.rb b/lib/critical_path_css/rails/version.rb index 2ee8821..83f3347 100644 --- a/lib/critical_path_css/rails/version.rb +++ b/lib/critical_path_css/rails/version.rb @@ -1,5 +1,5 @@ module CriticalPathCSS module Rails - VERSION = '4.0.0'.freeze + VERSION = '4.0.1'.freeze end end diff --git a/spec/fixtures/files/config/manifest-and-path-both-specified.yml b/spec/fixtures/files/config/manifest-and-path-both-specified.yml new file mode 100644 index 0000000..8575dce --- /dev/null +++ b/spec/fixtures/files/config/manifest-and-path-both-specified.yml @@ -0,0 +1,10 @@ +defaults: &defaults + base_url: http://0.0.0.0:9292 + manifest_name: application + css_path: /test.css + +development: + <<: *defaults + +test: + <<: *defaults \ No newline at end of file diff --git a/spec/fixtures/files/config/manifest-and-paths-both-specified.yml b/spec/fixtures/files/config/manifest-and-paths-both-specified.yml new file mode 100644 index 0000000..990a290 --- /dev/null +++ b/spec/fixtures/files/config/manifest-and-paths-both-specified.yml @@ -0,0 +1,15 @@ +defaults: &defaults + base_url: http://0.0.0.0:9292 + manifest_name: application + css_paths: + - /test.css + - /test2.css + routes: + - / + - /new_route + +development: + <<: *defaults + +test: + <<: *defaults \ No newline at end of file diff --git a/spec/lib/critical_path_css/rails/config_loader_spec.rb b/spec/lib/critical_path_css/rails/config_loader_spec.rb index e20c289..dc7bfac 100644 --- a/spec/lib/critical_path_css/rails/config_loader_spec.rb +++ b/spec/lib/critical_path_css/rails/config_loader_spec.rb @@ -32,6 +32,22 @@ end end + context 'when manifest name and css path are both specified' do + let(:config_file) { file_fixture('config/manifest-and-path-both-specified.yml').read } + + it 'raises an error' do + expect { subject }.to raise_error LoadError, 'Cannot specify both manifest_name and css_path(s)' + end + end + + context 'when manifest name and css paths are both specified' do + let(:config_file) { file_fixture('config/manifest-and-paths-both-specified.yml').read } + + it 'raises an error' do + expect { subject }.to raise_error LoadError, 'Cannot specify both manifest_name and css_path(s)' + end + end + context 'when single css_path and multiple css_paths are both specified' do let(:config_file) { file_fixture('config/paths-both-specified.yml').read } From 89e6757d66f40fcb51f9f70d6dabcf5b68dc87c3 Mon Sep 17 00:00:00 2001 From: Niklas Bichinger Date: Mon, 27 Jan 2020 20:30:47 +0100 Subject: [PATCH 76/81] convert stylesheet path to absolute file url --- lib/critical_path_css/rails/config_loader.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/critical_path_css/rails/config_loader.rb b/lib/critical_path_css/rails/config_loader.rb index 1158a1b..90f40b4 100644 --- a/lib/critical_path_css/rails/config_loader.rb +++ b/lib/critical_path_css/rails/config_loader.rb @@ -24,7 +24,7 @@ def format_css_paths if config['css_paths'] config['css_paths'].map! { |path| format_path(path) } else - config['css_paths'] = [ActionController::Base.helpers.stylesheet_path(config['manifest_name'], host: '')] + config['css_paths'] = [format_path(ActionController::Base.helpers.stylesheet_path(config['manifest_name'], host: ''))] end end From 52e8e5c49daf1eee0782ed706ad059f60da060fe Mon Sep 17 00:00:00 2001 From: Niklas Bichinger Date: Wed, 11 Mar 2020 19:38:21 +0100 Subject: [PATCH 77/81] cleanup --- lib/critical_path_css/rails/config_loader.rb | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/critical_path_css/rails/config_loader.rb b/lib/critical_path_css/rails/config_loader.rb index 90f40b4..5addd98 100644 --- a/lib/critical_path_css/rails/config_loader.rb +++ b/lib/critical_path_css/rails/config_loader.rb @@ -21,11 +21,10 @@ def configuration_file_path def format_css_paths config['css_paths'] = [config['css_path']] if config['css_path'] - if config['css_paths'] - config['css_paths'].map! { |path| format_path(path) } - else - config['css_paths'] = [format_path(ActionController::Base.helpers.stylesheet_path(config['manifest_name'], host: ''))] + unless config['css_paths'] + config['css_paths'] = [ActionController::Base.helpers.stylesheet_path(config['manifest_name'], host: '')] end + config['css_paths'].map! { |path| format_path(path) } end def format_path(path) From 5c44f4a318dd437cf3c74a57d63f960d055699a1 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 16 Apr 2020 04:16:44 +0000 Subject: [PATCH 78/81] Bump https-proxy-agent from 2.2.2 to 2.2.4 Bumps [https-proxy-agent](https://github.com/TooTallNate/node-https-proxy-agent) from 2.2.2 to 2.2.4. - [Release notes](https://github.com/TooTallNate/node-https-proxy-agent/releases) - [Commits](https://github.com/TooTallNate/node-https-proxy-agent/compare/2.2.2...2.2.4) Signed-off-by: dependabot[bot] --- package-lock.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index c0c6c3f..1c56b5a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -145,9 +145,9 @@ } }, "https-proxy-agent": { - "version": "2.2.2", - "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-2.2.2.tgz", - "integrity": "sha512-c8Ndjc9Bkpfx/vCJueCPy0jlP4ccCCSNDp8xwCZzPjKJUm+B+u9WX2x98Qx4n1PiMNTWo3D7KK5ifNV/yJyRzg==", + "version": "2.2.4", + "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-2.2.4.tgz", + "integrity": "sha512-OmvfoQ53WLjtA9HeYP9RNrWMJzzAz1JGaSFr1nijg0PVR1JaD/xbJq1mdEIIlxGpXp9eSe/O2LgU9DJmTPd0Eg==", "requires": { "agent-base": "^4.3.0", "debug": "^3.1.0" From 847a74baa56184eb129d383a06da327e9ad829ce Mon Sep 17 00:00:00 2001 From: Michael Misshore Date: Wed, 29 Apr 2020 17:44:33 -0500 Subject: [PATCH 79/81] Update version to 4.1.0 --- lib/critical_path_css/rails/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/critical_path_css/rails/version.rb b/lib/critical_path_css/rails/version.rb index 83f3347..dfe4bcf 100644 --- a/lib/critical_path_css/rails/version.rb +++ b/lib/critical_path_css/rails/version.rb @@ -1,5 +1,5 @@ module CriticalPathCSS module Rails - VERSION = '4.0.1'.freeze + VERSION = '4.1.0'.freeze end end From 5ceff9db82c307b40559329e76366eba41b58dbb Mon Sep 17 00:00:00 2001 From: Shinn Chong Date: Tue, 25 Aug 2020 16:38:40 +0800 Subject: [PATCH 80/81] Return first css path when route index is nil --- lib/critical_path_css/configuration.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/critical_path_css/configuration.rb b/lib/critical_path_css/configuration.rb index 405787b..5c9dd16 100644 --- a/lib/critical_path_css/configuration.rb +++ b/lib/critical_path_css/configuration.rb @@ -26,7 +26,7 @@ def penthouse_options end def path_for_route(route) - css_paths[routes.index(route)] || css_paths.first + css_paths[routes.index(route).to_i] end end end From 909dfc53ce1b262741a94b06d600352de5587881 Mon Sep 17 00:00:00 2001 From: Michael Misshore Date: Wed, 23 Dec 2020 13:19:25 -0600 Subject: [PATCH 81/81] Update Version --- lib/critical_path_css/rails/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/critical_path_css/rails/version.rb b/lib/critical_path_css/rails/version.rb index dfe4bcf..f005d4d 100644 --- a/lib/critical_path_css/rails/version.rb +++ b/lib/critical_path_css/rails/version.rb @@ -1,5 +1,5 @@ module CriticalPathCSS module Rails - VERSION = '4.1.0'.freeze + VERSION = '4.1.1'.freeze end end