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

Fix bin/setup modification failure in installation #229

Merged
merged 4 commits into from
Jan 31, 2023

Conversation

ahangarha
Copy link
Contributor

@ahangarha ahangarha commented Dec 26, 2022

Due to different content of bin/setup in different Rails versions, the earlier version of the generator couldn't modify this file properly in all circumstances.

This commit handles the following scenarios:

  • If there is a commented line for system('bin/yarn'), uncomment it.
  • Otherwise, regardless of using single or double quotations in different Rails versions, add system! 'bin/yarn' after the intended line.

I have manually checked the impact of this PR on the following Rails versions:

  • 5.2.8: where we already have commented system('bin/yarn')
  • 6.1.7: where we have system('bundle check') || system!('bundle install')
  • 7.0.4: where we have system("bundle check") || system!("bundle install")

closes #226

lib/install/template.rb Outdated Show resolved Hide resolved
lib/install/template.rb Outdated Show resolved Hide resolved
@ahangarha ahangarha force-pushed the improve-robustness-in-modifying-bin-setup branch 2 times, most recently from 58f5df3 to 4292001 Compare January 7, 2023 14:00
@ahangarha ahangarha changed the title Fix bin/setup modification failure in installation WIP - Fix bin/setup modification failure in installation Jan 7, 2023
Comment on lines 55 to 61
else
say <<~MSG, :red
It seems your `bin/setup` file doesn't have the expected content.
Please review the file and manually add `system! "bin/yarn"`.
MSG
end
end
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Judahmeek @justin808
What about adding these lines at the end of the file if we couldn't find the pattern? The job of this step in the generator is to ensure we have system!("bin/yarn") in the setup file. So why should we ask the user to do it manually?

I think it would be good to print out some text and say thought we have updated the setup file, but the format of the file was not what we expected. This way, we can ask the developer to review the content of this file and ensure everything is right in the file.

It is not a very important thing to be worried about but I think if we are updating this part, we do it in the right way. Is my proposal the right way? What do you think?

@ahangarha ahangarha force-pushed the improve-robustness-in-modifying-bin-setup branch from 4292001 to 21e33ba Compare January 9, 2023 10:09
@ahangarha ahangarha changed the title WIP - Fix bin/setup modification failure in installation Fix bin/setup modification failure in installation Jan 9, 2023
@ahangarha ahangarha requested a review from Judahmeek January 9, 2023 10:12
@justin808
Copy link
Member

@ahangarha I'll merge after you update the CHANGELOG.

However, I'm not convinced this modification regarding bin/yarn is even needed longer term.

Due to different content of bin/setup in different Rails versions and
installation date, the earlier version of the generator couldn't modify
this file properly in all circumstances.

This commit handles the following scenarios:
- If there is a commented line for `system('bin/yarn')`, uncomment it.
- Otherwise, regardless of using single or double quotations in
  different Rails versions, add `system! 'bin/yarn'` after the intended
  line.
@ahangarha ahangarha force-pushed the improve-robustness-in-modifying-bin-setup branch from 21e33ba to 4eb8964 Compare January 19, 2023 12:34
@ahangarha
Copy link
Contributor Author

@ahangarha I'll merge after you update the CHANGELOG.

However, I'm not convinced this modification regarding bin/yarn is even needed longer term.

@justin808 I updated the changelog.
If we don't need such modification at all, then we should remove it entirely.
I think it would be good to make a final decision about this matter before our next major release.

@@ -38,11 +38,27 @@

if (setup_path = Rails.root.join("bin/setup")).exist?
say "Run bin/yarn during bin/setup"
insert_into_file setup_path.to_s, <<-RUBY, after: %( system("bundle check") || system!("bundle install")\n)

if File.read(setup_path).match? Regexp.escape(" # system('bin/yarn')\n")
Copy link
Contributor

Choose a reason for hiding this comment

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

@ahangarha

[] please extract system('bin/yarn') to a const, also why it's system('bin/yarn') and system**!**('bin/yarn') in other places?
[] please add a warn, that the file has been modified.
[] (optional), add a comment what and why we are uncommenting, unless this will not be intuitive from the log above.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  • May you elaborate on the extraction of system('bin/yarn')? If it is for DRY, I don't think this is a good place to do so because of having a different format in some parts. And then if I extract it, I think we get into a readability issue.
  • Regarding system and system!, rails 5 used system only. I didn't check if it was intended. Since we use ! for it, it is uncommented and changed to system!. Do you think there was a particular reason behind using system in Rails 5?
  • Do we need to warn the user about this? I think the message generated by gsub_file and insert_into_file is sufficient and enough informative.
  • Well, as per my understanding we want to run yarn install when we run ./bin/setup script. In rails 5 and 6, they had this item in the file. In Rails 5 it was commented and without ! and in Rails 6 it was uncommented with !. In Rails 7 they removed it entirely (even if one specifies --javascript=webpack).

Copy link
Contributor

Choose a reason for hiding this comment

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

Regarding system and system!, rails 5 used system only. I didn't check if it was intended. Since we use ! for it, it is uncommented and changed to system!. Do you think there was a particular reason behind using system in Rails 5?

@ahangarha thanks, this makes sense. Could you please then just some comments, or extract a function, so the code will be easier to understand?

RUBY
else
say <<~MSG, :red
It seems your `bin/setup` file doesn't have the expected content.
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we have a section in the docs, which might be referenced in this warn message?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think so. But also see my comment here:

What about adding these lines at the end of the file if we couldn't find the pattern? The job of this step in the generator is to ensure we have system!("bin/yarn") in the setup file. So why should we ask the user to do it manually?

I didn't get any response on it. Do you have any?

Copy link
Contributor

Choose a reason for hiding this comment

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

@ahangarha I think it's a good idea to add both in this case and keep the message, which will give heads-up to the user.

Copy link
Contributor

@vaukalak vaukalak left a comment

Choose a reason for hiding this comment

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

please give feedback to the comments above.

@justin808 justin808 merged commit 9deec04 into master Jan 31, 2023
@justin808 justin808 deleted the improve-robustness-in-modifying-bin-setup branch January 31, 2023 20:46
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.

Fail in updating bin/setup
4 participants