Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Do not fail trying to append_to_file which does not exist #269

Merged
merged 2 commits into from
Apr 19, 2017

Conversation

nfedyashev
Copy link
Contributor

Steps to reproduce:

  • generate a new rails app with (--skip-git) argument
  • add "webpacker" gem to Gemfile
  • Run webpacker:install

Expected result:

Successful completion of webpacker:install generator call

Actual result:

rails webpacker:install
Creating javascript app source directory
      create  app/javascript
      create  app/javascript/packs/application.js
Copying binstubs
       exist  bin
      create  bin/webpack-dev-server
      create  bin/webpack-watcher
      create  bin/webpack
      create  bin/yarn
Copying webpack core config and loaders
      create  config/webpack
      create  config/webpack/configuration.js
      create  config/webpack/development.js
      create  config/webpack/development.server.js
      create  config/webpack/development.server.yml
      create  config/webpack/paths.yml
      create  config/webpack/production.js
      create  config/webpack/shared.js
      create  config/webpack/test.js
      create  config/webpack/loaders
      create  config/webpack/loaders/assets.js
      create  config/webpack/loaders/babel.js
      create  config/webpack/loaders/coffee.js
      create  config/webpack/loaders/erb.js
      create  config/webpack/loaders/sass.js
      create  .postcssrc.yml
      append  .gitignore
rails aborted!
Errno::ENOENT: No such file or directory @ rb_sysopen - /Users/nfedyashev/Projects/hello_world/.gitignore
/Users/nfedyashev/.gem/ruby/2.4.0/gems/thor-0.19.4/lib/thor/actions/inject_into_file.rb:95:in `binread'
/Users/nfedyashev/.gem/ruby/2.4.0/gems/thor-0.19.4/lib/thor/actions/inject_into_file.rb:95:in `replace!'
/Users/nfedyashev/.gem/ruby/2.4.0/gems/thor-0.19.4/lib/thor/actions/inject_into_file.rb:56:in `invoke!'
/Users/nfedyashev/.gem/ruby/2.4.0/gems/thor-0.19.4/lib/thor/actions.rb:95:in `action'
/Users/nfedyashev/.gem/ruby/2.4.0/gems/thor-0.19.4/lib/thor/actions/inject_into_file.rb:27:in `insert_into_file'
/Users/nfedyashev/.gem/ruby/2.4.0/gems/thor-0.19.4/lib/thor/actions/file_manipulation.rb:180:in `append_to_file'
/usr/local/Cellar/rbenv/1.1.0/versions/2.4.1/lib/ruby/gems/2.4.0/bundler/gems/webpacker-814cabae36da/lib/install/template.rb:14:in `apply'
/Users/nfedyashev/.gem/ruby/2.4.0/gems/thor-0.19.4/lib/thor/actions.rb:224:in `instance_eval'
/Users/nfedyashev/.gem/ruby/2.4.0/gems/thor-0.19.4/lib/thor/actions.rb:224:in `apply'
/Users/nfedyashev/.gem/ruby/2.4.0/gems/railties-5.0.2/lib/rails/tasks/framework.rake:15:in `block (2 levels) in <top (required)>'
/Users/nfedyashev/.gem/ruby/2.4.0/gems/railties-5.0.2/lib/rails/commands/rake_proxy.rb:14:in `block in run_rake_task'
/Users/nfedyashev/.gem/ruby/2.4.0/gems/railties-5.0.2/lib/rails/commands/rake_proxy.rb:11:in `run_rake_task'
/Users/nfedyashev/.gem/ruby/2.4.0/gems/railties-5.0.2/lib/rails/commands/commands_tasks.rb:51:in `run_command!'
/Users/nfedyashev/.gem/ruby/2.4.0/gems/railties-5.0.2/lib/rails/commands.rb:18:in `<top (required)>'
./bin/rails:4:in `require'
./bin/rails:4:in `<main>'
Tasks: TOP => app:template
(See full trace by running task with --trace)

@gauravtiwari
Copy link
Member

@nfedyashev Thanks for the fix. If you could make rubocop happy I will merge this in 👍 There seems to be an extra whitespace on line 20 in template.rb

@nfedyashev
Copy link
Contributor Author

nfedyashev commented Apr 19, 2017

@gauravtiwari sorry about that! The commit has just been updated

@@ -11,10 +11,12 @@
directory "#{__dir__}/config/loaders/core", "config/webpack/loaders"
copy_file "#{__dir__}/config/.postcssrc.yml", ".postcssrc.yml"

append_to_file ".gitignore", <<-EOS
if File.exists?(".gitignore")
append_to_file ".gitignore", <<-EOS
Copy link
Member

Choose a reason for hiding this comment

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

Lets format it like this so, it's all nicely aligned :)

if File.exists?(".gitignore")
  append_to_file ".gitignore", <<-EOS
  /public/packs
  /node_modules
  EOS
end

Copy link
Contributor Author

@nfedyashev nfedyashev Apr 19, 2017

Choose a reason for hiding this comment

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

It is nicely aligned but the content of that string is now different than what it was

Copy link
Member

Choose a reason for hiding this comment

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

Yepp, I mean that we align that string block inline with append_to_file so, it's all in one line 👍 At the moment there is 2 whitespace for append_to_file, but none for string block

@gauravtiwari gauravtiwari merged commit 3ff0517 into rails:master Apr 19, 2017
@gauravtiwari
Copy link
Member

thanks @nfedyashev 👍 🍰

@nfedyashev
Copy link
Contributor Author

@gauravtiwari I'm sorry but my job here was to fix the bug so that it doesn't fail if .gitignore is missing.
I wasn't going to change the content that's being appended to the file.

Try it locally:

➜  webpacker cat pull-request.rb
x1 =  <<-EOS
/public/packs
/node_modules
EOS

if true
    x2 = <<-EOS
    /public/packs
    /node_modules
    EOS
end

puts x1
puts x2
raise (x1 == x2).to_s

➜  webpacker  ruby pull-request.rb
/public/packs
/node_modules
    /public/packs
    /node_modules
pull-request.rb:15:in `<main>': false (RuntimeError)

gauravtiwari added a commit that referenced this pull request Apr 19, 2017
@gauravtiwari
Copy link
Member

@nfedyashev Sorry, you were right 👍 My bad, just reverted the change :)

gauravtiwari added a commit that referenced this pull request Apr 19, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants