Enable tailwindcss to run in restricted permissions environment (eg. Deno Webworker w/o read permissions) #14300
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.