aboutsummaryrefslogtreecommitdiffstats
path: root/railties
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2016-12-01 18:51:43 +0100
committerGitHub <noreply@github.com>2016-12-01 18:51:43 +0100
commit3dac36bd8e26363bb10f4d2a7b21efa75d200e26 (patch)
tree8d4b5348a8f08ec3f90681e12bbcb41f347a2e31 /railties
parenta1dbc4ee0b01e4a15bdea9108a776a982ce4158e (diff)
downloadrails-3dac36bd8e26363bb10f4d2a7b21efa75d200e26.tar.gz
rails-3dac36bd8e26363bb10f4d2a7b21efa75d200e26.tar.bz2
rails-3dac36bd8e26363bb10f4d2a7b21efa75d200e26.zip
Yarn: Move node_modules, package.json, and yarn.lock file to vendor (#27245)
Move node_modules, package.json, and yarn.lock file to vendor
Diffstat (limited to 'railties')
-rw-r--r--railties/CHANGELOG.md4
-rw-r--r--railties/lib/rails/generators/app_base.rb2
-rw-r--r--railties/lib/rails/generators/rails/app/app_generator.rb10
-rw-r--r--railties/lib/rails/generators/rails/app/templates/bin/setup.tt2
-rw-r--r--railties/lib/rails/generators/rails/app/templates/bin/yarn2
-rw-r--r--railties/lib/rails/generators/rails/app/templates/config/initializers/assets.rb.tt2
-rw-r--r--railties/lib/rails/generators/rails/app/templates/gitignore4
-rw-r--r--railties/test/generators/app_generator_test.rb2
8 files changed, 16 insertions, 12 deletions
diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md
index f328df8539..0188f91997 100644
--- a/railties/CHANGELOG.md
+++ b/railties/CHANGELOG.md
@@ -1,7 +1,7 @@
-* Add Yarn support in new apps using --yarn option. This adds a package.json
+* Add Yarn support in new apps using --yarn option. This adds a yarn binstop, vendor/package.json,
and the settings needed to get npm modules integrated in new apps.
- *Liceth Ovalles*, *Guillermo Iguaran*
+ *Liceth Ovalles*, *Guillermo Iguaran*, *DHH*
* Removed jquery-rails from default stack, instead rails-ujs that is shipped
with Action View is included as default UJS adapter.
diff --git a/railties/lib/rails/generators/app_base.rb b/railties/lib/rails/generators/app_base.rb
index 6feb8431a7..87f6f01750 100644
--- a/railties/lib/rails/generators/app_base.rb
+++ b/railties/lib/rails/generators/app_base.rb
@@ -427,7 +427,7 @@ module Rails
end
def package_json_exist?
- File.exist?("package.json")
+ File.exist?("vendor/package.json")
end
def yarn_path
diff --git a/railties/lib/rails/generators/rails/app/app_generator.rb b/railties/lib/rails/generators/rails/app/app_generator.rb
index 5f14f989d7..49d23d682a 100644
--- a/railties/lib/rails/generators/rails/app/app_generator.rb
+++ b/railties/lib/rails/generators/rails/app/app_generator.rb
@@ -54,7 +54,7 @@ module Rails
end
def packagejson
- template "package.json"
+ template "package.json", "vendor/package.json"
end
def app
@@ -155,8 +155,12 @@ module Rails
end
def vendor
- vendor_javascripts
- vendor_stylesheets
+ if options[:yarn]
+ empty_directory_with_keep_file "vendor"
+ else
+ vendor_javascripts
+ vendor_stylesheets
+ end
end
def vendor_javascripts
diff --git a/railties/lib/rails/generators/rails/app/templates/bin/setup.tt b/railties/lib/rails/generators/rails/app/templates/bin/setup.tt
index c82a922eef..73b0732463 100644
--- a/railties/lib/rails/generators/rails/app/templates/bin/setup.tt
+++ b/railties/lib/rails/generators/rails/app/templates/bin/setup.tt
@@ -17,7 +17,7 @@ chdir APP_ROOT do
system! 'gem install bundler --conservative'
system('bundle check') || system!('bundle install')
<% if options[:yarn] %>
- system! 'yarn'
+ system! 'bin/yarn'
<% end %>
<% unless options.skip_active_record -%>
diff --git a/railties/lib/rails/generators/rails/app/templates/bin/yarn b/railties/lib/rails/generators/rails/app/templates/bin/yarn
new file mode 100644
index 0000000000..cf48e2e5b7
--- /dev/null
+++ b/railties/lib/rails/generators/rails/app/templates/bin/yarn
@@ -0,0 +1,2 @@
+VENDOR_PATH = File.expand_path('../vendor', __dir__)
+Dir.chdir(VENDOR_PATH) { exec "yarnpkg #{ARGV.join(" ")}" }
diff --git a/railties/lib/rails/generators/rails/app/templates/config/initializers/assets.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/initializers/assets.rb.tt
index 1ba182e562..bf5399ac2d 100644
--- a/railties/lib/rails/generators/rails/app/templates/config/initializers/assets.rb.tt
+++ b/railties/lib/rails/generators/rails/app/templates/config/initializers/assets.rb.tt
@@ -7,7 +7,7 @@ Rails.application.config.assets.version = '1.0'
# Rails.application.config.assets.paths << Emoji.images_path
<%- if options[:yarn] -%>
# Add Yarn node_modules folder to the asset load path.
-Rails.application.config.assets.paths << Rails.root.join('node_modules')
+Rails.application.config.assets.paths << Rails.root.join('vendor/node_modules')
<%- end -%>
# Precompile additional assets.
diff --git a/railties/lib/rails/generators/rails/app/templates/gitignore b/railties/lib/rails/generators/rails/app/templates/gitignore
index bdcbe8d629..dee42ebb87 100644
--- a/railties/lib/rails/generators/rails/app/templates/gitignore
+++ b/railties/lib/rails/generators/rails/app/templates/gitignore
@@ -22,9 +22,7 @@
<% end -%>
<% if options[:yarn] -%>
-# Ignore node modules.
-/node_modules/*
+/vendor/node_modules
<% end -%>
-# Ignore Byebug command history file.
.byebug_history
diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb
index 0f73c43e0c..15a923676d 100644
--- a/railties/test/generators/app_generator_test.rb
+++ b/railties/test/generators/app_generator_test.rb
@@ -494,7 +494,7 @@ class AppGeneratorTest < Rails::Generators::TestCase
def test_generator_if_yarn_option_is_given
run_generator([destination_root, "--yarn"])
- assert_file "package.json", /dependencies/
+ assert_file "vendor/package.json", /dependencies/
assert_file "config/initializers/assets.rb", /node_modules/
end