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

Railsties yarn.rake fails when the Rails.root folder name has spaces in its name. #40783

Closed
thebravoman opened this issue Dec 10, 2020 · 7 comments · Fixed by #40785
Closed

Comments

@thebravoman
Copy link

thebravoman commented Dec 10, 2020

Steps to reproduce

Create a rails folder that has spaces in its name.
Example is "is-commands Build and Release/workspace"
The folder in question is "/var/lib/jenkins/jobs/is-commands Build and Release/workspace" and the rails project is located in it.

Build a rake task that calls:

Rake::Task["assets:precompile"].invoke

Expected behavior

Yarn completes successfully. Precompilation completes successfully.

Actual behavior

Errno::ENOENT: No such file or directory - /var/lib/jenkins/jobs/is-commands
/usr/local/rvm/gems/ruby-2.6.5/gems/railties-6.1.0/lib/rails/tasks/yarn.rake:13:in ``'
/usr/local/rvm/gems/ruby-2.6.5/gems/railties-6.1.0/lib/rails/tasks/yarn.rake:13:in `block (2 levels) in <top (required)>'
/usr/local/rvm/gems/ruby-2.6.5/gems/is-gcc_tools-1.3.18/lib/tasks/is/gcc_tools_tasks.rake:172:in `assets_and_closure' (this calls Rake::Task["assets:precompile"].invoke)
/usr/local/rvm/gems/ruby-2.6.5/gems/is-gcc_tools-1.3.18/lib/tasks/is/gcc_tools_tasks.rake:139:in `block (3 levels) in <top (required)>'
/usr/local/rvm/gems/ruby-2.6.5/gems/rake-13.0.1/exe/rake:27:in `<top (required)>'
/usr/local/rvm/gems/ruby-2.6.5/bin/ruby_executable_hooks:24:in `eval'
/usr/local/rvm/gems/ruby-2.6.5/bin/ruby_executable_hooks:24:in `<main>'

System configuration

Rails version: 6.1

Ruby version: 2.6.5

Update 1

Yesterday this was working with

Using railties 6.0.3.4

Today it is not working with

Using railties 6.1.0 (was 6.0.3.4)

About 150 projects have failed because of this. Trying to understand it further.

Update 2

The problem is in

[9, 18] in /usr/local/rvm/gems/ruby-2.6.5/gems/railties-6.1.0/lib/rails/tasks/yarn.rake
    9:       valid_node_envs.include?(Rails.env) ? Rails.env : "production"
   10:     end
   11: 
   12:     byebug
   13:     yarn_flags =
=> 14:       if `#{Rails.root}/bin/yarn --version`.start_with?("1")
   15:         "--no-progress --frozen-lockfile"
   16:       else
   17:         "--immutable"
   18:       end
(byebug) Rails.root
#<Pathname:/var/lib/jenkins/jobs/is-commands Build and Release/workspace/test/dummy>
(byebug) `#{Rails.root}/bin/yarn --version`
*** Errno::ENOENT Exception: No such file or directory - /var/lib/jenkins/jobs/is-commands

nil

You can not call #{Rails.root}/bin/yarn --version when there is a space in the name of the folder

This was introduce about 2 days ago with bd4d8fd
I am not sure If I should tag the people that have made the commit (please tell me if I should not)
@rafaelfranca @doits

I do have yarn in

jenkins@vpszap6s:~/jobs/is-commands Build and Release/workspace/test/dummy/bin$ ls
bundle  rails  rake  setup  update  yarn

I could prepare a PR if you want.

@thebravoman thebravoman changed the title Railsties yarn fails when the folder has spaces in its name. Railsties yarn.rake fails when the folder has spaces in its name. Dec 10, 2020
@thebravoman thebravoman changed the title Railsties yarn.rake fails when the folder has spaces in its name. Railsties yarn.rake fails when the Rails.root folder name has spaces in its name. Dec 10, 2020
@doits
Copy link
Contributor

doits commented Dec 10, 2020

Thanks for your report, I created #40785 – can you see if this fixes it for you?

NB: I think this error was present before already, because the next system call a few lines later had the same problem if I am correct. Maybe it simply doesn't hard fail in this case?

@doits
Copy link
Contributor

doits commented Dec 10, 2020

Yeah indeed, that is the difference:

system("not present")
# => nil

`not present`
# Traceback (most recent call last):
#         2: from (irb):4
#         1: from (irb):4:in ``'
# Errno::ENOENT (No such file or directory - not)

So before it silently wasn't doing anything at all in such cases and now it hard fails because of the different way to execute yarn.

@thebravoman
Copy link
Author

thebravoman commented Dec 10, 2020

Yes. It does fix it. Thanks.

system("not present") and not present follow different protocol. system reports it to the error log. they also return different results.

@doits
Copy link
Contributor

doits commented Dec 10, 2020

👍 so when it is merged it will actually run yarn install for you now, on Rails 6.0 it didn't – looks like yarn is called by some other means in your pipeline.

@thebravoman
Copy link
Author

thebravoman commented Dec 10, 2020

No sure what you mean.

I was calling Rake::Task["assets:precompile"].invoke and this was calling yarn.rake.

We have all the project builds do a

bundle install
yarn install

and they then continue. Why do you call yarn install in a yarn.rake on an asset precompile?
Isn't this like calling bundle install in rake spec? Or bundle install in rake db:migrate.

Why should "rake assets:precompile" call "yarn install" and "rake db:migrate" will not call "bundle install"?

@doits
Copy link
Contributor

doits commented Dec 10, 2020

I can't reason about the logic, but look at:

# Run Yarn prior to Sprockets assets precompilation, so dependencies are available for use.
if Rake::Task.task_defined?("assets:precompile")
Rake::Task["assets:precompile"].enhance [ "yarn:install" ]
end

This makes yarn:install run before assets:precompile. This was not changed in 6.1 but was like this in 6.0 from the beginning in Rails 5.1 already.

@thebravoman
Copy link
Author

thebravoman commented Dec 10, 2020

Ok. Thanks. I was sometimes wondering looking at the logs why yarn install runя two times, but I never got to the point to look at it further.

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 a pull request may close this issue.

2 participants