- 
                Notifications
    You must be signed in to change notification settings 
- Fork 22k
          Fix rails new and rails app:update hanging on master bug.
          #40646
        
          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
Conversation
rails new and rails app:update hanging on master bug.
      | Can we do #39619 (comment)? | 
| Actually, I tried and thought it didn't work, but on second try I got it; commiting changes. | 
| @rafaelfranca Done 👌 . | 
| Actually, I kept testing and I don't think it's working. If the first params to  Isn't it an acceptable solution to assign the full path back once the call has been finished? I reckon that having the path that we are excluding ( | 
| This is more what we had in mind: require 'pathname'
APP_ROOT = File.expand_path('..', __dir__)
Dir.chdir(APP_ROOT) do
  executable_path = ENV["PATH"].split(File::PATH_SEPARATOR).find do |path|
    normalized_path = File.expand_path(path)
    normalized_path != __dir__ && File.executable?(Pathname.new(normalized_path).join('yarn'))
  end
  exec File.expand_path(Pathname.new(executable_path).join('yarn')), *ARGV
rescue Errno::ENOENT
  $stderr.puts "Yarn executable was not detected in the system."
  $stderr.puts "Download Yarn at https://yarnpkg.com/en/docs/install"
  exit 1
endCan you apply those changes? | 
| I'll test locally and apply 👌 | 
Prevent script from looping onto itself
| @rafaelfranca done 👌. | 
Fix `rails new` and `rails app:update` hanging on master bug.
| Thank you for your work here! | 
When we use `bin/yarn` without original yarn, the following error will be occurred: ``` bin/yarn:12:in `initialize': no implicit conversion of nil into String (TypeError) ``` This means `executable_path` is `nil`. To handle missing yarn correctly, checking `executable_path` seems good. This is a result of my local without yarn. ``` Yarn executable was not detected in the system. Download Yarn at https://yarnpkg.com/en/docs/install rake aborted! ``` This commit follows up rails#40646.
Since rails#40646, `bin/yarn` manually searches `PATH` for the `yarn` executable. In Windows environments, executables have an `.exe` file extension, so we must search for `yarn.exe` as well. Fixes rails#40942.
Summary
Filter PATH environment variable so script doesn't loop on itself.
Fixes: #38666
Related: #39619
When updating a rails application to the master branch, and running rails app:update, if you have bin in your PATH you would get thrown into an infinite loop.
This excludes bin from the PATH variable, so when bin/yarn is called, it does not loop on itself when calling exec "yarn".
Related Issue: #38666
Also briefly mentioned here: #39282 (comment)
Other Information