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

Remove assets:precompile task enhancement #131

Merged
merged 1 commit into from
May 26, 2022

Conversation

jherdman
Copy link
Contributor

Move this responsibility to the host application

Resolves #125

Copy link
Collaborator

@tomdracz tomdracz left a comment

Choose a reason for hiding this comment

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

@jherdman
Copy link
Contributor Author

Updated as requested.

Copy link
Collaborator

@tomdracz tomdracz left a comment

Choose a reason for hiding this comment

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

Two more changes and we're good to go @jherdman

else
Rake::Task.define_task("assets:precompile" => ["webpacker:yarn_install", "webpacker:compile"])
end
Rake::Task.define_task("assets:precompile" => ["webpacker:compile"])
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should still use enhance_assets_precompile here so we need something like:

  if Rake::Task.task_defined?("assets:precompile")
    enhance_assets_precompile
  else
    Rake::Task.define_task("assets:precompile" => ["webpacker:compile"])
  end


Rake::Task["#{prefix}webpacker:compile"].invoke
end
end
Copy link
Collaborator

Choose a reason for hiding this comment

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

Don't need the yarn_install_available? but we should keep the enhance_assets_precompile method, just without the deps so something like:

def enhance_assets_precompile
  Rake::Task["assets:precompile"].enhance do |task|
    prefix = task.name.split(/#|assets:precompile/).first

    Rake::Task["#{prefix}webpacker:compile"].invoke
  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.

smh... oops!

Move this responsibility to the host application

Resolves shakacode#125
@jherdman
Copy link
Contributor Author

Fixed. Apologies for the bumps along the way on this one.

@jherdman
Copy link
Contributor Author

@justin808
Copy link
Member

LGTM

@tomdracz
Copy link
Collaborator

I think we can remove this too? https://github.com/shakacode/shakapacker/blob/master/lib/install/bin/yarn

This is still used during setup and diagnostic check so good to remain. All looks good now, merging! Thanks @jherdman

@tomdracz tomdracz merged commit 1f34a4a into shakacode:master May 26, 2022
Eric-Guo added a commit to Eric-Guo/shakapacker that referenced this pull request Jun 3, 2022
@justin808 justin808 mentioned this pull request Jun 6, 2022
@Judahmeek
Copy link
Contributor

@tomdracz I don't understand the point of this PR.

Isn't yarn install is a no-op if node_modules is already up to date?

@tomdracz
Copy link
Collaborator

tomdracz commented Jun 7, 2022

@tomdracz I don't understand the point of this PR.

Isn't yarn install is a no-op if node_modules is already up to date?

Kinda. Still takes few seconds to fetch and check things. Think Rails also implements yarn:install task (or at least it did before v7) so the task actually gets run twice.

Then you've got stuff like Heroku. You can very easily end up in situation where packages are fetched and reinstalled again when they don't need to. Can't find the issue in the heroku buildpack now but the only solution offered is removing the install task enhancement.

All in all, this is removing bit of "magic" behind the scenes. In the same way as rails server or migrate tasks are not running bundle install, the precompile task should not be installing yarn packages. Principle of least suprise!

@jherdman jherdman deleted the issue-125 branch June 7, 2022 13:02
@jherdman
Copy link
Contributor Author

jherdman commented Jun 7, 2022

Broadly speaking, too, I'd argue that Shakapacker shouldn't care which package manager I use whatsoever.

@tomdracz
Copy link
Collaborator

tomdracz commented Jun 7, 2022

Valid point @jherdman it was on my mind too. There should be nothing stopping users from npm or similar being used, as long as packages are installed, it's a fair game

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.

Don't enhance precompile with yarn install
4 participants