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

Add @content support to @tailwindcss/cli #14067

Merged

Conversation

RobinMalfait
Copy link
Member

@RobinMalfait RobinMalfait commented Jul 26, 2024

This is a continuation of #14048 where we specifically focus on the @tailwindcss/cli.

This PR optimizes the globs such that we always have a clean base and the glob (which is the first dynamic part).

This PR also refactors the CLI such that we can watch files defined by the @content at-rules in the CSS. The @parcel/watcher watches from a base path (not a glob), which means that we have to create a watcher for each glob's base.

This PR also adds a scanFiles to the scanDir result, so that we can verify that a scanned file matches the globs we already know from scanDir.

@RobinMalfait RobinMalfait marked this pull request as draft July 26, 2024 19:49
@RobinMalfait RobinMalfait marked this pull request as ready for review July 29, 2024 07:09
crates/node/src/lib.rs Outdated Show resolved Hide resolved
packages/@tailwindcss-cli/src/commands/build/index.ts Outdated Show resolved Hide resolved
packages/@tailwindcss-cli/src/commands/build/index.ts Outdated Show resolved Hide resolved
packages/@tailwindcss-postcss/src/index.test.ts Outdated Show resolved Hide resolved
Copy link
Member

@philipp-spiess philipp-spiess left a comment

Choose a reason for hiding this comment

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

Awesome! This is great. I left a few comments inline.

crates/node/src/lib.rs Outdated Show resolved Hide resolved
crates/oxide/src/glob.rs Outdated Show resolved Hide resolved
crates/oxide/src/glob.rs Outdated Show resolved Hide resolved
crates/oxide/src/lib.rs Outdated Show resolved Hide resolved
packages/@tailwindcss-cli/src/commands/build/index.ts Outdated Show resolved Hide resolved
@RobinMalfait RobinMalfait mentioned this pull request Jul 29, 2024
8 tasks
@RobinMalfait RobinMalfait force-pushed the feat/content-path-cli-watch-mode branch from 3716b75 to eaf5a20 Compare July 29, 2024 14:15
@RobinMalfait RobinMalfait changed the base branch from feat/content-path to feat/add-content-support-to-core July 29, 2024 14:15
@RobinMalfait RobinMalfait force-pushed the feat/add-content-support-to-core branch from d69d260 to cd37016 Compare July 29, 2024 17:05
@RobinMalfait RobinMalfait force-pushed the feat/content-path-cli-watch-mode branch from fef5964 to dadb584 Compare July 29, 2024 17:28
@RobinMalfait RobinMalfait force-pushed the feat/content-path-cli-watch-mode branch from 546f5f5 to c03ad86 Compare July 29, 2024 17:42
@RobinMalfait RobinMalfait force-pushed the feat/add-content-support-to-core branch from 2710729 to 105293e Compare July 30, 2024 08:48
@RobinMalfait RobinMalfait force-pushed the feat/content-path-cli-watch-mode branch 2 times, most recently from 55bc10c to 6879b85 Compare July 30, 2024 10:11
@RobinMalfait RobinMalfait force-pushed the feat/add-content-support-to-core branch from 97683da to 1c1bbca Compare July 30, 2024 15:28
@RobinMalfait RobinMalfait force-pushed the feat/content-path-cli-watch-mode branch from 521cbaa to ba6b356 Compare July 30, 2024 15:29
@RobinMalfait RobinMalfait force-pushed the feat/add-content-support-to-core branch from 1c1bbca to fb8228e Compare July 30, 2024 16:06
@RobinMalfait RobinMalfait force-pushed the feat/content-path-cli-watch-mode branch from ba6b356 to e2118b2 Compare July 30, 2024 16:07
Base automatically changed from feat/add-content-support-to-core to feat/add-content-support August 1, 2024 16:00
@philipp-spiess philipp-spiess force-pushed the feat/content-path-cli-watch-mode branch from e2118b2 to a45b396 Compare August 1, 2024 16:04
This currently invokes the `build` command directly. In a future PR we
will add proper integration tests where the CLI is tested from the
outside.

For now, this will do.
This will use a variable to hold everything instead of destructuring
such that it will be easier to completely replace them with new
instances.
Otherwise `compiler.globs` is referring to the older compiler's globs
and `input` refers to the older `input` as well.

This commit now makes sure that we are working with the new input and
compiler before re-compiling the CSS.
@philipp-spiess philipp-spiess force-pushed the feat/content-path-cli-watch-mode branch from 91447a2 to 6654f6b Compare August 2, 2024 11:45
@RobinMalfait RobinMalfait force-pushed the feat/content-path-cli-watch-mode branch from e3c6245 to 8558f6e Compare August 2, 2024 16:05
RobinMalfait and others added 5 commits August 2, 2024 18:07
This reverts commit 8558f6e.
This reverts commit fa3f288.
Instead of relying on CLI output, let's rely on changes made to the File
System itself.

The API looks like:

```
await waitForOutputFileChange(path, cb => {
  // Do something
})
```

It will setup a watcher for the given `path`, once the watcher is ready,
we will invoke the callback.

Once the file on disk changes, we can resolve the wrapping promise.

We also have this helper in the v3 codebase, a rename might be good,

Let's see if this fixes flakey tests on CI or not.
@RobinMalfait RobinMalfait force-pushed the feat/content-path-cli-watch-mode branch from d73e82e to 9559a98 Compare August 2, 2024 18:15
@RobinMalfait RobinMalfait merged commit 9579da7 into feat/add-content-support Aug 5, 2024
2 checks passed
@RobinMalfait RobinMalfait deleted the feat/content-path-cli-watch-mode branch August 5, 2024 11:11
philipp-spiess added a commit that referenced this pull request Aug 5, 2024
This is a continuation of #14048 where we specifically focus on the
`@tailwindcss/cli`.

This PR optimizes the globs such that we always have a clean `base` and
the `glob` (which is the first dynamic part).

This PR also refactors the CLI such that we can watch files defined by
the `@content` at-rules in the CSS. The `@parcel/watcher` watches from a
base path (not a glob), which means that we have to create a watcher for
each glob's base.

This PR also adds a `scanFiles` to the `scanDir` result, so that we can
verify that a scanned file matches the globs we already know from
`scanDir`.

Co-authored-by: Philipp Spiess <[email protected]>
RobinMalfait added a commit that referenced this pull request Aug 7, 2024
This is a continuation of #14048 where we specifically focus on the
`@tailwindcss/cli`.

This PR optimizes the globs such that we always have a clean `base` and
the `glob` (which is the first dynamic part).

This PR also refactors the CLI such that we can watch files defined by
the `@content` at-rules in the CSS. The `@parcel/watcher` watches from a
base path (not a glob), which means that we have to create a watcher for
each glob's base.

This PR also adds a `scanFiles` to the `scanDir` result, so that we can
verify that a scanned file matches the globs we already know from
`scanDir`.

Co-authored-by: Philipp Spiess <[email protected]>
RobinMalfait added a commit that referenced this pull request Aug 7, 2024
This PR is an umbrella PR where we will add support for the new
`@source` directive. This will allow you to add explicit content glob
patterns if you want to look for Tailwind classes in other files that
are not automatically detected yet.

Right now this is an addition to the existing auto content detection
that is automatically enabled in the `@tailwindcss/postcss` and
`@tailwindcss/cli` packages. The `@tailwindcss/vite` package doesn't use
the auto content detection, but uses the module graph instead.

From an API perspective there is not a lot going on. There are only a
few things that you have to know when using the `@source` directive, and
you probably already know the rules:

1. You can use multiple `@source` directives if you want.
2. The `@source` accepts a glob pattern so that you can match multiple
files at once
3. The pattern is relative to the current file you are in
4. The pattern includes all files it is matching, even git ignored files
1. The motivation for this is so that you can explicitly point to a
`node_modules` folder if you want to look at `node_modules` for whatever
reason.
6. Right now we don't support negative globs (starting with a `!`) yet,
that will be available in the near future.

Usage example:

```css
/* ./src/input.css */
@import "tailwindcss";
@source "../laravel/resources/views/**/*.blade.php";
@source "../../packages/monorepo-package/**/*.js";
```

It looks like the PR introduced a lot of changes, but this is a side
effect of all the other plumbing work we had to do to make this work.
For example:

1. We added dedicated integration tests that run on Linux and Windows in
CI (just to make sure that all the `path` logic is correct)
2. We Have to make sure that the glob patterns are always correct even
if you are using `@import` in your CSS and use `@source` in an imported
file. This is because we receive the flattened CSS contents where all
`@import`s are inlined.
3. We have to make sure that we also listen for changes in the files
that match any of these patterns and trigger a rebuild.

PRs:

- [x] #14063
- [x] #14085
- [x] #14079
- [x] #14067
- [x] #14076
- [x] #14080
- [x] #14127
- [x] #14135

Once all the PRs are merged, then this umbrella PR can be merged. 

> [!IMPORTANT]  
> Make sure to merge this without rebasing such that each individual PR
ends up on the main branch.

---------

Co-authored-by: Philipp Spiess <[email protected]>
Co-authored-by: Jordan Pittman <[email protected]>
Co-authored-by: Adam Wathan <[email protected]>
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.

4 participants