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

Enable tailwindcss to run in restricted permissions environment (eg. Deno Webworker w/o read permissions) #14300

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

vfssantos
Copy link

This PR is a suggestion implementation for solving #14299 .

Description:

I have identified a potential improvement for TailwindCSS that would enhance its compatibility with environments that have limited read permissions, such as Cloudflare Workers or Deno WebWorkers / Deno Deploy with limited read / write permissions.

Problem:

When running TailwindCSS in environments where read access to the file system is restricted (e.g., serverless functions, WebWorkers), the dependency on fast-glob for resolving file paths can cause issues. Specifically, fast-glob requires read access to the instance's current directory (via process.cwd()), which is not necessary for use cases where the Tailwind config is passed directly into PostCSS, and the HTML containing Tailwind CSS utilities is provided in-memory as the raw property in content.files.

Proposed Solution:

A simple solution (about 10 lines of code) could be implemented to check if the length of the paths to be verified is greater than zero. If paths are present, the regular logic using fast-glob would proceed. If not, we can skip the fast-glob call, allowing TailwindCSS to function in environments with restricted read permissions.

Benefits:

This change would enable dynamic CSS generation in restricted serverless environments, making TailwindCSS more versatile and opening up new use cases, such as running on platforms like Cloudflare Workers or Deno WebWorkers without the need for read access.

Reproduction URL

Clone the repo: https://github.com/vfssantos/tailwind-edge-test/tree/main
As we're using Deno in that repo, make sure you have Deno installed locally
Run the project as instructed. You'll be prompted for permissions. You can deny all of them and would still work, except for the --read for cwd command (which is used by fast-glob).

**Expected Behavior ** : TailwindCSS should allow dynamic CSS generation without requiring file system read access when the paths to be checked are empty.

Proposed Changes Behavior: With the simple proposed changes in this PR, the repo in Reproduction URL works seamlessly.

If the maintainers agree, I'd be happy to change this PR to comply with any other requirement.

@vfssantos
Copy link
Author

I'd like to make the case for going forward with this PR - even if the maintainers get to the conclusion that the goal this PR is is not relevant to the project - because, at least, it should improve compiling performance for some edge-cases where calling fast-glob is not necessary.

@vfssantos
Copy link
Author

@adamwathan @philipp-spiess @thecrypticace

If have any time to review this, should be a quick and simple one, and I think it would greatly benefit the community :)

If you have any concerns or suggestions, please, let me know so I can work on it.

Thanks!

@sntran
Copy link

sntran commented Sep 9, 2024

You mentioned Cloudflare Workers, but have you tested on them? AFAIK, it would take a lot more to get Tailwind to work on there, especially when dealing with NPM dependencies like fast-glob.

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.

2 participants