Skip to content

Support singleton webpacker (3 and above) #777

New issue

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

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

Already on GitHub? Sign in to your account

Merged
merged 50 commits into from
Sep 18, 2017
Merged
Show file tree
Hide file tree
Changes from 38 commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
392ec00
Support singleton webpacker (3 and above)
BookOfGreg Aug 31, 2017
4531b1c
Support Specific versions of webpacker in appraisal
BookOfGreg Aug 31, 2017
14865d8
Update appraisal
BookOfGreg Aug 31, 2017
80c03d8
Simplify
BookOfGreg Aug 31, 2017
8c7dcd8
Pin to 3 or greater
BookOfGreg Aug 31, 2017
cd74273
Compatibility for Webpacker new
BookOfGreg Aug 31, 2017
2b7cf68
Reference correct constant
BookOfGreg Sep 1, 2017
d1e665e
Fixes #778
BookOfGreg Sep 5, 2017
ea8810e
Handle manifest load
BookOfGreg Sep 5, 2017
5a78e5d
WIP, trying to get webpacker3 config with webpacker1 and 2
BookOfGreg Sep 5, 2017
b960b9a
Extract out data
BookOfGreg Sep 5, 2017
cc8528f
Ruby 2.1 doesnt support twiddledocs
BookOfGreg Sep 5, 2017
54f95b7
Take on the configuration comment, also reduce the react regex as the…
BookOfGreg Sep 8, 2017
ed8a891
Split out dummy apps for the asset pipelines.
BookOfGreg Sep 8, 2017
488a840
Split out Webpacker dummy and sprockets dummy, then change to that di…
BookOfGreg Sep 8, 2017
2c8ec5e
ignore ruby 2.1 with Rails 5
BookOfGreg Sep 8, 2017
29c1d02
Add new dummy webpacker3 app
BookOfGreg Sep 8, 2017
ca48da9
Typo in appraisal gemfile name
BookOfGreg Sep 8, 2017
41b633f
Typo in appraisal gemfile name
BookOfGreg Sep 8, 2017
a5f3da5
Pin webpacker 1.1
BookOfGreg Sep 8, 2017
9b7af66
Set directory based on gem version
BookOfGreg Sep 8, 2017
2492053
Define methods based on which webpacker version is loaded to make con…
BookOfGreg Sep 11, 2017
f33976a
Update appraisals for each version of webpacker
BookOfGreg Sep 11, 2017
1b210b0
Each one seems to need turbolinks
BookOfGreg Sep 11, 2017
72285ce
Shouldnt need turbolinks
BookOfGreg Sep 11, 2017
8c88a3b
Turns out _no_sprockets_ name is actually executable code...
BookOfGreg Sep 11, 2017
4fad8b3
Reinitialize webpacker with default config except for the following d…
BookOfGreg Sep 11, 2017
c587945
Add new Webpacker 2 folder
BookOfGreg Sep 11, 2017
b6dc2aa
Regenerate webpacker configs for webpacker 2
BookOfGreg Sep 11, 2017
7b1b5ad
Tweaking configs and requires to sensible version
BookOfGreg Sep 11, 2017
6324185
Use local node_module
BookOfGreg Sep 11, 2017
77536cd
Dont test Rails 5 on ruby 2.1
BookOfGreg Sep 11, 2017
253ccde
Make it use localhost rather than 0.0.0.0, also React 15.4 so I do no…
BookOfGreg Sep 11, 2017
2805d9d
Add Webpacker 3 test app
BookOfGreg Sep 11, 2017
9390b09
Webpack 3 settings
BookOfGreg Sep 11, 2017
4aa297f
Tweak dev-server detector
BookOfGreg Sep 12, 2017
f15b255
Use Webpackers native dev_server detection
BookOfGreg Sep 12, 2017
c61f74d
properly scope config access
BookOfGreg Sep 12, 2017
0c0b9bc
Remove require pry references
BookOfGreg Sep 12, 2017
e3efcb8
Introduce rubocop to project
BookOfGreg Sep 15, 2017
0f75fe7
rubocop --only Layout/SpaceInsideHashLiteralBraces -a
BookOfGreg Sep 15, 2017
07afcb7
rubocop --only Style/StringLiterals -a
BookOfGreg Sep 15, 2017
384a406
Test scanned the file for specific quotes.
BookOfGreg Sep 18, 2017
579367f
rubocop --only Layout/SpaceInsideBlockBraces -a
BookOfGreg Sep 18, 2017
940f5dd
rubocop --only Style/NegatedIf -a
BookOfGreg Sep 18, 2017
9437671
rubocop --only Style/TrailingCommaInLiteral -a
BookOfGreg Sep 18, 2017
caf0827
rubocop --only Layout/SpaceInsideBrackets -a
BookOfGreg Sep 18, 2017
f2330d9
rubocop --only Layout/SpaceBeforeComment -a
BookOfGreg Sep 18, 2017
e5bbe14
rubocop --only Style/ParallelAssignment -a
BookOfGreg Sep 18, 2017
83fbdaf
rubocop --only Layout/EmptyLines -a
BookOfGreg Sep 18, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
*.gem
Gemfile.lock
*.log
test/dummy/tmp
test/dummy/public/packs
test/*/tmp
test/*/public/packs
gemfiles/*.lock
*.swp
/vendor/react
Expand Down
23 changes: 20 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ rvm:
gemfile:
# These have webpacker:
- gemfiles/rails_4.2_sprockets_4.gemfile
- gemfiles/rails_5_no_sprockets_webpacker.gemfile
- gemfiles/rails_5_no_sprockets_webpacker_1_1.gemfile
- gemfiles/rails_5_no_sprockets_webpacker_1_x.gemfile
- gemfiles/rails_5_no_sprockets_webpacker_2.gemfile
- gemfiles/rails_5_no_sprockets_webpacker_3.gemfile
# These don't have webpacker:
- gemfiles/rails_3.2.gemfile
- gemfiles/rails_4.0.5.gemfile
Expand All @@ -39,7 +42,13 @@ matrix:
- rvm: 2.1
gemfile: gemfiles/rails_4.2_sprockets_4.gemfile
- rvm: 2.1
gemfile: gemfiles/rails_5_no_sprockets_webpacker.gemfile
gemfile: gemfiles/rails_5_no_sprockets_webpacker_1_1.gemfile
- rvm: 2.1
gemfile: gemfiles/rails_5_no_sprockets_webpacker_1_x.gemfile
- rvm: 2.1
gemfile: gemfiles/rails_5_no_sprockets_webpacker_2.gemfile
- rvm: 2.1
gemfile: gemfiles/rails_5_no_sprockets_webpacker_3.gemfile
- rvm: 2.1
gemfile: gemfiles/rails_5_no_sprockets.gemfile
- rvm: 2.1
Expand All @@ -53,7 +62,15 @@ matrix:
- rvm: jruby-9.0.1.0
gemfile: gemfiles/rails_4.2_sprockets_2.gemfile
- rvm: jruby-9.0.1.0
gemfile: gemfiles/rails_5_no_sprockets_webpacker.gemfile
gemfile: gemfiles/rails_5_no_sprockets_webpacker_1_1.gemfile
- rvm: jruby-9.0.1.0
gemfile: gemfiles/rails_5_no_sprockets_webpacker_1_x.gemfile
- rvm: jruby-9.0.1.0
gemfile: gemfiles/rails_5_no_sprockets_webpacker_2.gemfile
- rvm: jruby-9.0.1.0
gemfile: gemfiles/rails_5_no_sprockets_webpacker_3.gemfile
- rvm: jruby-9.0.1.0
gemfile: gemfiles/rails_5_no_sprockets.gemfile

allow_failures:
- rvm: jruby-9.0.1.0
Expand Down
33 changes: 29 additions & 4 deletions Appraisals
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,40 @@ appraise "rails-4.2-sprockets_4" do
gem 'rails', '~> 4.2.1'
gem "sprockets", "~> 4.0.x"
gem "turbolinks", "~> 2.5.0"
gem "webpacker", github: "rails/webpacker"
# This ExecJS backend provides stateful context
# which the default nodejs backend does not
gem "mini_racer"
end

appraise "rails-5_no_sprockets_webpacker" do
# no_sprockets is a magical name from sprockets_helper.rb in test to
# load in certain tests or not.
appraise "rails-5_no_sprockets_webpacker_1_1" do
gem 'rails', '~> 5.0.0'
gem "webpacker", github: "rails/webpacker"
gem "webpacker", '~> 1.1.0'
# This ExecJS backend provides stateful context
# which the default nodejs backend does not
gem "therubyracer"
end

appraise "rails-5_no_sprockets_webpacker_1_x" do
gem 'rails', '~> 5.0.0'
gem "webpacker", '~> 1.2'
# This ExecJS backend provides stateful context
# which the default nodejs backend does not
gem "therubyracer"
end

appraise "rails-5_no_sprockets_webpacker_2" do
gem 'rails', '~> 5.0.0'
gem "webpacker", '~> 2.0'
# This ExecJS backend provides stateful context
# which the default nodejs backend does not
gem "therubyracer"
end

appraise "rails-5_no_sprockets_webpacker_3" do
gem 'rails', '~> 5.0.0'
gem 'webpacker', '>= 3.0'
# This ExecJS backend provides stateful context
# which the default nodejs backend does not
gem "therubyracer"
Expand All @@ -66,7 +91,7 @@ appraise "rails-5-no_sprockets" do
end

appraise "rails-5.1-sprockets_4" do
gem "rails", "5.1.0.rc1"
gem "rails", "~> 5.1"
gem "sprockets", "~> 4.0.x"
gem "turbolinks", "~> 5.0.0"
end
1 change: 0 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@ source 'http://rubygems.org'

gemspec
# This is an optional dev-dependency, required whenever sprockets is required
gem "turbolinks"
11 changes: 10 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,16 @@ end
task default: :test

task :test_setup do
Dir.chdir("./test/dummy") do
Dir.chdir("./test/dummy_sprockets") do
`yarn install`
end
Dir.chdir("./test/dummy_webpacker1") do
`yarn install`
end
Dir.chdir("./test/dummy_webpacker2") do
`yarn install`
end
Dir.chdir("./test/dummy_webpacker3") do
`yarn install`
end
end
Expand Down
2 changes: 1 addition & 1 deletion gemfiles/rails_3.2.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

source "http://rubygems.org"

gem "turbolinks", "~> 2.0"
gem "rails", "~> 3.2.21"
gem "rack-cache", "~> 1.6.1"
gem "turbolinks", "~> 2.0"

gemspec :path => "../"
2 changes: 1 addition & 1 deletion gemfiles/rails_4.0.5.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

source "http://rubygems.org"

gem "turbolinks"
gem "rails", "4.0.5"
gem "turbolinks"

gemspec :path => "../"
2 changes: 1 addition & 1 deletion gemfiles/rails_4.0_with_therubyracer.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

source "http://rubygems.org"

gem "turbolinks"
gem "rails", "~> 4.0.13"
gem "therubyracer", "0.12.0", :platform => :mri
gem "turbolinks"

gemspec :path => "../"
2 changes: 1 addition & 1 deletion gemfiles/rails_4.1.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

source "http://rubygems.org"

gem "turbolinks", "~> 2.3.0"
gem "rails", "~> 4.1.10"
gem "turbolinks", "~> 2.3.0"

gemspec :path => "../"
2 changes: 1 addition & 1 deletion gemfiles/rails_4.2_sprockets_2.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

source "http://rubygems.org"

gem "turbolinks"
gem "rails", "~> 4.2.1"
gem "sprockets", "~> 2.12"
gem "turbolinks"

gemspec :path => "../"
2 changes: 1 addition & 1 deletion gemfiles/rails_4.2_sprockets_3.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

source "http://rubygems.org"

gem "turbolinks", "~> 2.5.0"
gem "rails", "~> 4.2.1"
gem "sprockets", "~> 3.5"
gem "turbolinks", "~> 2.5.0"

gemspec :path => "../"
3 changes: 1 addition & 2 deletions gemfiles/rails_4.2_sprockets_4.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@

source "http://rubygems.org"

gem "turbolinks", "~> 2.5.0"
gem "rails", "~> 4.2.1"
gem "sprockets", "~> 4.0.x"
gem "webpacker", :github => "rails/webpacker"
gem "turbolinks", "~> 2.5.0"
gem "mini_racer"

gemspec :path => "../"
4 changes: 2 additions & 2 deletions gemfiles/rails_5.1_sprockets_4.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

source "http://rubygems.org"

gem "turbolinks", "~> 5.0.0"
gem "rails", "5.1.0.rc1"
gem "rails", "~> 5.1"
gem "sprockets", "~> 4.0.x"
gem "turbolinks", "~> 5.0.0"

gemspec :path => "../"
1 change: 0 additions & 1 deletion gemfiles/rails_5_no_sprockets.gemfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# This file was generated by Appraisal
# This shouldn't have turbolinks or sprockets

source "http://rubygems.org"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
# This file was generated by Appraisal
# This file shouldn't have turbolinks or sprockets in it

source "http://rubygems.org"

gem "rails", "~> 5.0.0"
gem "webpacker", :github => "rails/webpacker"
gem "webpacker", "~> 1.1.0"
gem "therubyracer"

gemspec :path => "../"
9 changes: 9 additions & 0 deletions gemfiles/rails_5_no_sprockets_webpacker_1_x.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# This file was generated by Appraisal

source "http://rubygems.org"

gem "rails", "~> 5.0.0"
gem "webpacker", "~> 1.2"
gem "therubyracer"

gemspec :path => "../"
9 changes: 9 additions & 0 deletions gemfiles/rails_5_no_sprockets_webpacker_2.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# This file was generated by Appraisal

source "http://rubygems.org"

gem "rails", "~> 5.0.0"
gem "webpacker", "~> 2.0"
gem "therubyracer"

gemspec :path => "../"
9 changes: 9 additions & 0 deletions gemfiles/rails_5_no_sprockets_webpacker_3.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# This file was generated by Appraisal

source "http://rubygems.org"

gem "rails", "~> 5.0.0"
gem "webpacker", ">= 3.0"
gem "therubyracer"

gemspec :path => "../"
9 changes: 9 additions & 0 deletions gemfiles/rails_5_webpacker_1_1.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# This file was generated by Appraisal

source "http://rubygems.org"

gem "rails", "~> 5.0.0"
gem "webpacker", "~> 1.1.0"
gem "therubyracer"

gemspec :path => "../"
10 changes: 10 additions & 0 deletions gemfiles/rails_5_webpacker_1_x.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# This file was generated by Appraisal

source "http://rubygems.org"

gem "turbolinks"
gem "rails", "~> 5.0.0"
gem "webpacker", "~> 1.2"
gem "therubyracer"

gemspec :path => "../"
10 changes: 10 additions & 0 deletions gemfiles/rails_5_webpacker_2.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# This file was generated by Appraisal

source "http://rubygems.org"

gem "turbolinks"
gem "rails", "~> 5.0.0"
gem "webpacker", "~> 2.0"
gem "therubyracer"

gemspec :path => "../"
10 changes: 10 additions & 0 deletions gemfiles/rails_5_webpacker_3.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# This file was generated by Appraisal

source "http://rubygems.org"

gem "turbolinks"
gem "rails", "~> 5.0.0"
gem "webpacker", ">= 3.0"
gem "therubyracer"

gemspec :path => "../"
6 changes: 5 additions & 1 deletion lib/generators/react/component_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def create_component_file
if webpacker?
new_file_name = file_name.camelize
extension = options[:coffee] ? "coffee" : "js"
target_dir = Webpacker::Configuration.source_path
target_dir = webpack_configuration.source_path
.join("components")
.relative_path_from(::Rails.root)
.to_s
Expand All @@ -119,6 +119,10 @@ def create_component_file

private

def webpack_configuration
Webpacker.respond_to?(:config) ? Webpacker.config : Webpacker::Configuration
end

def component_name
file_name.camelize
end
Expand Down
13 changes: 11 additions & 2 deletions lib/generators/react/install_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ def webpacker?

def javascript_dir
if webpacker?
Webpacker::Configuration.source_path
.join(Webpacker::Configuration.entry_path)
webpack_source_path
.relative_path_from(::Rails.root)
.to_s
else
Expand Down Expand Up @@ -110,6 +109,16 @@ def setup_react_webpacker
create_file(manifest, WEBPACKER_SETUP_UJS)
end
end

private

def webpack_source_path
if Webpacker.respond_to?(:config)
Webpacker.config.source_entry_path # Webpacker >3

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it works for me

Webpacker.config.source_path.join(Webpacker.config.source_entry_path)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It works..... but is it correct?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is correct as-is: Webpacker.config.source_entry_path

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Webpacker.config.source_entry_path is the correct way to call this, as this is defined in webpacker.

else
Webpacker::Configuration.source_path.join(Webpacker::Configuration.entry_path) # Webpacker <3
end
end
end
end
end
Loading