Skip to content

feat: fall back to locally-installed tailwindcss executables #226

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

Merged
merged 1 commit into from
Mar 30, 2023

Conversation

flavorjones
Copy link
Member

If a user has installed the ruby platform gem, but has the tailwindcss executable installed in their path, then we should fall back to that.

Closes #224

@flavorjones flavorjones force-pushed the flavorjones-fallback-to-manually-installed branch 2 times, most recently from 9474737 to e5c406c Compare November 15, 2022 16:56
@flavorjones
Copy link
Member Author

@TheNeikos do you want to give this branch a try and let me know if it works for you?

Here's how you can try it out:

  • checkout this branch (flavorjones-fallback-to-manually-installed)
  • bundle install && bundle exec rake gem:ruby
  • gem install --local pkg/tailwindcss-rails-2.0.21.gem

@TheNeikos
Copy link

Sadly it still does not work :c

This is because you are explicitly checking for wrapper scripts and ignore them? I don't think that is necessary, since users can decide themselves how they want their executables to be called.

In my case for example, and quite usual for NixOS, tailwindcss is a wrapper script that sets a bunch of env variables before calling the actual binary.

@flavorjones
Copy link
Member Author

Can you help me understand what "does not work" looks like for you? Can you give me more information about how it doesn't work?

I chose to ignore wrapper scripts because Rubygems will install a tailwindcss wrapper script that's in the user's path, and so I need some mechanism to avoid infinite recursion (calling the tailwindcss rubygems shim, which calls this gem's tailwindcss script, which then call the rubygems shim again). If you have any ideas on how to do this in a robust manner that works on your system, please let me know.

@flavorjones
Copy link
Member Author

Maybe I'm overthinking this, would a suitable alternative be to set an environment variable to the path of your "real" tailwindcss installation?

Something like this in your .envrc for example:

TAILWINDCSS_RAILS_LOCAL_PATH=/path/to/nix/installation/bin/tailwindcss

Would that solve your use case?

@TheNeikos
Copy link

TheNeikos commented Nov 17, 2022

Can you help me understand what "does not work" looks like for you? Can you give me more information about how it doesn't work?

I chose to ignore wrapper scripts because Rubygems will install a tailwindcss wrapper script that's in the user's path, and so I need some mechanism to avoid infinite recursion (calling the tailwindcss rubygems shim, which calls this gem's tailwindcss script, which then call the rubygems shim again). If you have any ideas on how to do this in a robust manner that works on your system, please let me know.

Sorry I didn't go into more detail. But basically, same behaviour as before. It just tells me that I need to have it installed (since it is just a wrapper script I have in my PATH, I assume that whatever it does find, it just skips it).

My first question would be, why does the rubygems shim have the same name? Could it be removed/renamed?

Would that solve your use case?

That would 100% solve it! I can easily set things like that.

@flavorjones
Copy link
Member Author

why does the rubygems shim have the same name

For the same reason that Nix's shim has the same name?

That would 100% solve it

OK, I'll overhaul this PR with that approach.

@TheNeikos
Copy link

For the same reason that Nix's shim has the same name?

Haha, fair enough! I just wouldn't expect a rubygem to install an executable with the same name as the one it tries to catch only to say that it is not installed!

In the NixOS case its to make sure tailwind can find all the plugins it needs and is more of a redirect to the actual executable.

@piperswe
Copy link

Another Nix user here: this is the main blocker for me moving my app's build process entirely under Nix, is there anything I can do to help move it along?

@piperswe
Copy link

I just ended up creating a new PR (#259) with the environment variable override approach

@nanaya
Copy link

nanaya commented Mar 30, 2023

fwiw, it's also a problem for people running on "unsupported" platform (freebsd etc). I just override the whole function for now. Actual tailwindcss can be installed no problem on platforms with node using npm/yarn.

# config/initializers/00tailwind_freebsd.rb
module Tailwindcss
  module Commands
    def self.executable(*)
      File.expand_path(File.join(__dir__, "..", "..", "node_modules", ".bin", "tailwindcss"))
    end
  end
end

@flavorjones flavorjones force-pushed the flavorjones-fallback-to-manually-installed branch from e5c406c to 30bf340 Compare March 30, 2023 04:56
@flavorjones
Copy link
Member Author

I've updated this branch with an environment-variable-setting approach.

@flavorjones flavorjones force-pushed the flavorjones-fallback-to-manually-installed branch 4 times, most recently from 05c32bb to fa95991 Compare March 30, 2023 05:30
this will work for both the vanilla "ruby" platform as well as
override the behavior of the native platform gem.
@flavorjones flavorjones force-pushed the flavorjones-fallback-to-manually-installed branch from fa95991 to 56bdb1f Compare March 30, 2023 05:41
@flavorjones flavorjones merged commit efab5f0 into main Mar 30, 2023
@flavorjones flavorjones deleted the flavorjones-fallback-to-manually-installed branch March 30, 2023 05:41
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.

Pointing to the tailwindcss executable
4 participants