Enable tailwindcss to run in restricted permissions environment (eg. Deno Webworker w/o read permissions)
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.
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.
@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!
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.
Hey!
Now that v4 is out, I would recommend to try and upgrade to v4 instead. The core of v4 (tailwindcss) doesn't require any I/O (only the clients such as @tailwindcss/cli, @tailwincdss/postcss and @tailwindcss/vite) do.
I am going to close this PR for now because there is much more work involved to properly test this behavior to ensure that this change actually makes sense in a v3 project.
Can you try and use v4 instead and see if this improves your workflow?
Appreciate the PR! If this is still an issue in v4, we can revisit this.
Thanks!