Auto source detection improvements (#14820)
This PR introduces a new `source(…)` argument and improves on the
existing `@source`. The goal of this PR is to make the automatic source
detection configurable, let's dig in.
By default, we will perform automatic source detection starting at the
current working directory. Auto source detection will find plain text
files (no binaries, images, ...) and will ignore git-ignored files.
If you want to start from a different directory, you can use the new
`source(…)` next to the `@import "tailwindcss/utilities"
layer(utilities) source(…)`.
E.g.:
```css
/* ./src/styles/index.css */
@import 'tailwindcss/utilities' layer(utilities) source('../../');
```
Most people won't split their source files, and will just use the simple
`@import "tailwindcss";`, because of this reason, you can use
`source(…)` on the import as well:
E.g.:
```css
/* ./src/styles/index.css */
@import 'tailwindcss' source('../../');
```
Sometimes, you want to rely on auto source detection, but also want to
look in another directory for source files. In this case, yuo can use
the `@source` directive:
```css
/* ./src/index.css */
@import 'tailwindcss';
/* Look for `blade.php` files in `../resources/views` */
@source '../resources/views/**/*.blade.php';
```
However, you don't need to specify the extension, instead you can just
point the directory and all the same automatic source detection rules
will apply.
```css
/* ./src/index.css */
@import 'tailwindcss';
@source '../resources/views';
```
If, for whatever reason, you want to disable the default source
detection feature entirely, and only want to rely on very specific glob
patterns you define, then you can disable it via `source(none)`.
```css
/* Completely disable the default auto source detection */
@import 'tailwindcss' source(none);
/* Only look at .blade.php files, nothing else */
@source "../resources/views/**/*.blade.php";
```
Note: even with `source(none)`, if your `@source` points to a directory,
then auto source detection will still be performed in that directory. If
you don't want that, then you can simply add explicit files in the globs
as seen in the previous example.
```css
/* Completely disable the default auto source detection */
@import 'tailwindcss' source(none);
/* Run auto source detection in `../resources/views` */
@source "../resources/views";
```
---------
Co-authored-by: Jordan Pittman <jordan@cryptica.me>
Co-authored-by: Adam Wathan <4323180+adamwathan@users.noreply.github.com>
2024-10-29 21:33:34 +01:00
|
|
|
import dedent from 'dedent'
|
2024-09-02 15:23:46 +02:00
|
|
|
import os from 'node:os'
|
2024-08-07 16:38:44 +02:00
|
|
|
import path from 'node:path'
|
Improve integration tests (stability + performance) (#15125)
This PR improves the integration tests in two ways:
1. Make the integration tests more reliable and thus less flakey
2. Make the integration tests faster (by introducing concurrency)
Tried a lot of different things to make sure that these tests are fast
and stable.
---
The biggest issue we noticed is that some tests are flakey, these are
tests with long running dev-mode processes where watchers are being used
and/or dev servers are created.
To solve this, all the tests that spawn a process look at stdout/stderr
and wait for a message from the process to know whether we can start
making changes.
For example, in case of an Astro project, you get a `watching for file
changes` message. In case of Nuxt project you can wait for an `server
warmed up in` and in case of Next.js there is a `Ready in` message.
These depend on the tools being used, so this is hardcoded per test
instead of a magically automatic solution.
These messages allow us to wait until all the initial necessary work,
internal watchers and/or dev servers are setup before we start making
changes to the files and/or request CSS stylesheets before the server(s)
are ready.
---
Another improvement is how we setup the dev servers. Before, we used to
try and get a free port on the system and use a `--port` flag or a
`PORT` environment variable. Instead of doing this (which is slow), we
rely on the process itself to show a URL with a port. Basically all
tools will try to find a free port if the default port is in use. We can
then use the stdout/stderr messages to get the URL and the port to use.
To reduce the amount of potential conflicts in ports, we used to run
every test and every file sequentially to basically guarantee that ports
are free. With this new approach where we rely on the process, I noticed
that we don't really run into this issue again (I reran the tests
multiple times and they were always stable)
<img width="316" alt="image"
src="https://github.com/user-attachments/assets/b75ddab4-f919-4995-85d0-f212b603e5c2"
/>
Note: these tests run Linux, Windows and macOS in this branch just for
testing purposes. Once this is done, we will only run Linux tests on PRs
and run all 3 of them on the `next` branch.
We do make the tests concurrent by default now, which in theory means
that there could be conflicts (which in practice means that the process
has to do a few more tries to find a free port). To reduce these
conflicts, we split up the integration tests such that Vite, PostCSS,
CLI, … tests all run in a separate job in the GitHub actions workflow.
<img width="312" alt="image"
src="https://github.com/user-attachments/assets/fe9a58a1-98eb-4d9b-8845-a7c8a7af5766"
/>
Comparing this branch against the `next` branch, this is what CI looks
like right now:
| `next` | `feat/improve-integration-tests` |
| --- | --- |
| <img width="594" alt="image"
src="https://github.com/user-attachments/assets/540d21eb-ab03-42e8-9f6f-b3a071fc7635"
/> | <img width="672" alt="image"
src="https://github.com/user-attachments/assets/8ef2e891-08a1-464b-9954-4153174ebce7"
/> |
There also was a point in time where I introduced sequential tests such
that all spawned processes still run after each other, but so far I
didn't run into issues if we keep them concurrent so I dropped that
code.
Some small changes I made to make things more reliable:
1. When relying on stdout/stderr messages, we split lines on `\n` and we
strip all the ANSI escapes which allows us to not worry about special
ANSI characters when finding the URL or a specific message to wait for.
2. Once a test is done, we `child.kill()` the spawned process. If that
doesn't work, for whatever reason, we run a `child.kill('SIGKILL')` to
force kill the process. This could technically lead to some memory or
files not being cleaned up properly, but once CI is done, everything is
thrown away anyway.
3. As you can see in the screenshots, I used some nicer names for the
workflows.
| `next` | `feat/improve-integration-tests` |
| --- | --- |
| <img width="276" alt="image"
src="https://github.com/user-attachments/assets/e574bb53-e21b-4619-9cdb-515431b255b9"
/> | <img width="179" alt="image"
src="https://github.com/user-attachments/assets/8bc75119-fb91-4500-a1d0-bd09f74c93ad"
/> |
They also look a bit nicer in the PR overview as well:
<img width="929" alt="image"
src="https://github.com/user-attachments/assets/04fc71fc-74b0-4e7c-9047-2aada664efef"
/>
The very last commit just filters out Windows and macOS tests again for
PRs (but they are executed on the `next` branch.
---
### Nest steps
I think for now we are in a pretty good state, but there are some things
we can do to further improve everything (mainly make things faster) but
aren't necessary. I also ran into issue while trying it so there is more
work to do.
1. More splits — instead of having a Vite folder and PostCSS folder, we
can go a step further and have folders for Next.js, Astro, Nuxt, Remix,
…
2. Caching — right now we have to run the build step for every OS on
every "job". We can re-use the work here by introducing a setup job that
the other jobs rely on. @thecrypticace and I tried it already, but were
running into some Bun specific Standalone CLI issues when doing that.
3. Remote caching — we could re-enable remote caching such that the
`build` step can be full turbo (e.g.: after a PR is merged in `next` and
we run everything again)
2024-12-12 13:48:56 +01:00
|
|
|
import { describe } from 'vitest'
|
2024-11-19 18:39:49 +01:00
|
|
|
import { candidate, css, html, js, json, test, ts, yaml } from '../utils'
|
2024-08-07 16:38:44 +02:00
|
|
|
|
2024-09-02 15:23:46 +02:00
|
|
|
const STANDALONE_BINARY = (() => {
|
|
|
|
|
switch (os.platform()) {
|
|
|
|
|
case 'win32':
|
|
|
|
|
return 'tailwindcss-windows-x64.exe'
|
|
|
|
|
case 'darwin':
|
|
|
|
|
return os.arch() === 'x64' ? 'tailwindcss-macos-x64' : 'tailwindcss-macos-arm64'
|
|
|
|
|
case 'linux':
|
|
|
|
|
return os.arch() === 'x64' ? 'tailwindcss-linux-x64' : 'tailwindcss-linux-arm64'
|
|
|
|
|
default:
|
|
|
|
|
throw new Error(`Unsupported platform: ${os.platform()} ${os.arch()}`)
|
|
|
|
|
}
|
|
|
|
|
})()
|
|
|
|
|
|
|
|
|
|
describe.each([
|
|
|
|
|
['CLI', 'pnpm tailwindcss'],
|
|
|
|
|
[
|
|
|
|
|
'Standalone CLI',
|
|
|
|
|
path.resolve(__dirname, `../../packages/@tailwindcss-standalone/dist/${STANDALONE_BINARY}`),
|
|
|
|
|
],
|
|
|
|
|
])('%s', (_, command) => {
|
|
|
|
|
test(
|
|
|
|
|
'production build',
|
|
|
|
|
{
|
|
|
|
|
fs: {
|
|
|
|
|
'package.json': json`{}`,
|
|
|
|
|
'pnpm-workspace.yaml': yaml`
|
|
|
|
|
#
|
|
|
|
|
packages:
|
|
|
|
|
- project-a
|
|
|
|
|
`,
|
|
|
|
|
'project-a/package.json': json`
|
|
|
|
|
{
|
|
|
|
|
"dependencies": {
|
|
|
|
|
"tailwindcss": "workspace:^",
|
|
|
|
|
"@tailwindcss/cli": "workspace:^"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
`,
|
|
|
|
|
'project-a/index.html': html`
|
|
|
|
|
<div
|
2024-11-07 16:48:49 +01:00
|
|
|
class="underline 2xl:font-bold hocus:underline inverted:flex *:flex **:flex"
|
2024-09-02 15:23:46 +02:00
|
|
|
></div>
|
|
|
|
|
`,
|
|
|
|
|
'project-a/plugin.js': js`
|
|
|
|
|
module.exports = function ({ addVariant }) {
|
|
|
|
|
addVariant('inverted', '@media (inverted-colors: inverted)')
|
|
|
|
|
addVariant('hocus', ['&:focus', '&:hover'])
|
2024-08-07 16:38:44 +02:00
|
|
|
}
|
2024-09-02 15:23:46 +02:00
|
|
|
`,
|
2024-09-03 16:54:08 +02:00
|
|
|
'project-a/tailwind.config.js': js`
|
|
|
|
|
module.exports = {
|
|
|
|
|
content: ['../project-b/src/**/*.js'],
|
|
|
|
|
}
|
|
|
|
|
`,
|
2024-09-02 15:23:46 +02:00
|
|
|
'project-a/src/index.css': css`
|
|
|
|
|
@import 'tailwindcss/utilities';
|
2024-09-03 16:54:08 +02:00
|
|
|
@config '../tailwind.config.js';
|
|
|
|
|
@source '../../project-b/src/**/*.html';
|
2024-09-02 15:23:46 +02:00
|
|
|
@plugin '../plugin.js';
|
|
|
|
|
`,
|
|
|
|
|
'project-a/src/index.js': js`
|
|
|
|
|
const className = "content-['project-a/src/index.js']"
|
|
|
|
|
module.exports = { className }
|
|
|
|
|
`,
|
2024-09-03 16:54:08 +02:00
|
|
|
'project-b/src/index.html': html`
|
|
|
|
|
<div class="flex" />
|
|
|
|
|
`,
|
2024-09-02 15:23:46 +02:00
|
|
|
'project-b/src/index.js': js`
|
|
|
|
|
const className = "content-['project-b/src/index.js']"
|
|
|
|
|
module.exports = { className }
|
|
|
|
|
`,
|
|
|
|
|
},
|
2024-08-07 16:38:44 +02:00
|
|
|
},
|
2024-09-02 15:23:46 +02:00
|
|
|
async ({ root, fs, exec }) => {
|
|
|
|
|
await exec(`${command} --input src/index.css --output dist/out.css`, {
|
|
|
|
|
cwd: path.join(root, 'project-a'),
|
|
|
|
|
})
|
2024-08-07 16:38:44 +02:00
|
|
|
|
2024-09-02 15:23:46 +02:00
|
|
|
await fs.expectFileToContain('project-a/dist/out.css', [
|
|
|
|
|
candidate`underline`,
|
2024-09-03 16:54:08 +02:00
|
|
|
candidate`flex`,
|
2024-09-02 15:23:46 +02:00
|
|
|
candidate`content-['project-a/src/index.js']`,
|
|
|
|
|
candidate`content-['project-b/src/index.js']`,
|
|
|
|
|
candidate`inverted:flex`,
|
|
|
|
|
candidate`hocus:underline`,
|
2024-11-07 16:48:49 +01:00
|
|
|
candidate`*:flex`,
|
|
|
|
|
candidate`**:flex`,
|
2024-09-02 15:23:46 +02:00
|
|
|
])
|
|
|
|
|
},
|
|
|
|
|
)
|
2024-08-07 16:38:44 +02:00
|
|
|
|
2025-01-17 16:23:34 +01:00
|
|
|
test(
|
|
|
|
|
'production build — read input from stdin',
|
|
|
|
|
{
|
|
|
|
|
fs: {
|
|
|
|
|
'package.json': json`{}`,
|
|
|
|
|
'pnpm-workspace.yaml': yaml`
|
|
|
|
|
#
|
|
|
|
|
packages:
|
|
|
|
|
- project-a
|
|
|
|
|
`,
|
|
|
|
|
'project-a/package.json': json`
|
|
|
|
|
{
|
|
|
|
|
"dependencies": {
|
|
|
|
|
"tailwindcss": "workspace:^",
|
|
|
|
|
"@tailwindcss/cli": "workspace:^"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
`,
|
|
|
|
|
'project-a/index.html': html`
|
|
|
|
|
<div
|
|
|
|
|
class="underline 2xl:font-bold hocus:underline inverted:flex *:flex **:flex"
|
|
|
|
|
></div>
|
|
|
|
|
`,
|
|
|
|
|
'project-a/plugin.js': js`
|
|
|
|
|
module.exports = function ({ addVariant }) {
|
|
|
|
|
addVariant('inverted', '@media (inverted-colors: inverted)')
|
|
|
|
|
addVariant('hocus', ['&:focus', '&:hover'])
|
|
|
|
|
}
|
|
|
|
|
`,
|
|
|
|
|
'project-a/tailwind.config.js': js`
|
|
|
|
|
module.exports = {
|
|
|
|
|
content: ['../project-b/src/**/*.js'],
|
|
|
|
|
}
|
|
|
|
|
`,
|
|
|
|
|
'project-a/src/index.js': js`
|
|
|
|
|
const className = "content-['project-a/src/index.js']"
|
|
|
|
|
module.exports = { className }
|
|
|
|
|
`,
|
|
|
|
|
'project-b/src/index.html': html`
|
|
|
|
|
<div class="flex" />
|
|
|
|
|
`,
|
|
|
|
|
'project-b/src/index.js': js`
|
|
|
|
|
const className = "content-['project-b/src/index.js']"
|
|
|
|
|
module.exports = { className }
|
|
|
|
|
`,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
async ({ root, fs, exec }) => {
|
|
|
|
|
await exec(
|
|
|
|
|
`${command} --input - --output dist/out.css`,
|
|
|
|
|
{ cwd: path.join(root, 'project-a') },
|
|
|
|
|
{
|
|
|
|
|
stdin: css`
|
|
|
|
|
@import 'tailwindcss/utilities';
|
|
|
|
|
@config './tailwind.config.js';
|
|
|
|
|
@source '../project-b/src/**/*.html';
|
|
|
|
|
@plugin './plugin.js';
|
|
|
|
|
`,
|
|
|
|
|
},
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
await fs.expectFileToContain('project-a/dist/out.css', [
|
|
|
|
|
candidate`underline`,
|
|
|
|
|
candidate`flex`,
|
|
|
|
|
candidate`content-['project-a/src/index.js']`,
|
|
|
|
|
candidate`content-['project-b/src/index.js']`,
|
|
|
|
|
candidate`inverted:flex`,
|
|
|
|
|
candidate`hocus:underline`,
|
|
|
|
|
candidate`*:flex`,
|
|
|
|
|
candidate`**:flex`,
|
|
|
|
|
])
|
|
|
|
|
},
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
test(
|
|
|
|
|
'production build — (write to stdout)',
|
|
|
|
|
{
|
|
|
|
|
fs: {
|
|
|
|
|
'package.json': json`{}`,
|
|
|
|
|
'pnpm-workspace.yaml': yaml`
|
|
|
|
|
#
|
|
|
|
|
packages:
|
|
|
|
|
- project-a
|
|
|
|
|
`,
|
|
|
|
|
'project-a/package.json': json`
|
|
|
|
|
{
|
|
|
|
|
"dependencies": {
|
|
|
|
|
"tailwindcss": "workspace:^",
|
|
|
|
|
"@tailwindcss/cli": "workspace:^"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
`,
|
|
|
|
|
'project-a/index.html': html`
|
|
|
|
|
<div
|
|
|
|
|
class="underline 2xl:font-bold hocus:underline inverted:flex *:flex **:flex"
|
|
|
|
|
></div>
|
|
|
|
|
`,
|
|
|
|
|
'project-a/plugin.js': js`
|
|
|
|
|
module.exports = function ({ addVariant }) {
|
|
|
|
|
addVariant('inverted', '@media (inverted-colors: inverted)')
|
|
|
|
|
addVariant('hocus', ['&:focus', '&:hover'])
|
|
|
|
|
}
|
|
|
|
|
`,
|
|
|
|
|
'project-a/tailwind.config.js': js`
|
|
|
|
|
module.exports = {
|
|
|
|
|
content: ['../project-b/src/**/*.js'],
|
|
|
|
|
}
|
|
|
|
|
`,
|
|
|
|
|
'project-a/src/index.css': css`
|
|
|
|
|
@import 'tailwindcss/utilities';
|
|
|
|
|
@config '../tailwind.config.js';
|
|
|
|
|
@source '../../project-b/src/**/*.html';
|
|
|
|
|
@plugin '../plugin.js';
|
|
|
|
|
`,
|
|
|
|
|
'project-a/src/index.js': js`
|
|
|
|
|
const className = "content-['project-a/src/index.js']"
|
|
|
|
|
module.exports = { className }
|
|
|
|
|
`,
|
|
|
|
|
'project-b/src/index.html': html`
|
|
|
|
|
<div class="flex" />
|
|
|
|
|
`,
|
|
|
|
|
'project-b/src/index.js': js`
|
|
|
|
|
const className = "content-['project-b/src/index.js']"
|
|
|
|
|
module.exports = { className }
|
|
|
|
|
`,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
async ({ root, expect, exec }) => {
|
|
|
|
|
let stdout = await exec(`${command} --input src/index.css --output -`, {
|
|
|
|
|
cwd: path.join(root, 'project-a'),
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
expect(stdout).toContain(candidate`underline`)
|
|
|
|
|
expect(stdout).toContain(candidate`flex`)
|
|
|
|
|
expect(stdout).toContain(candidate`content-['project-a/src/index.js']`)
|
|
|
|
|
expect(stdout).toContain(candidate`content-['project-b/src/index.js']`)
|
|
|
|
|
expect(stdout).toContain(candidate`inverted:flex`)
|
|
|
|
|
expect(stdout).toContain(candidate`hocus:underline`)
|
|
|
|
|
expect(stdout).toContain(candidate`*:flex`)
|
|
|
|
|
expect(stdout).toContain(candidate`**:flex`)
|
|
|
|
|
},
|
|
|
|
|
)
|
|
|
|
|
|
2024-09-02 15:23:46 +02:00
|
|
|
test(
|
|
|
|
|
'watch mode',
|
|
|
|
|
{
|
|
|
|
|
fs: {
|
|
|
|
|
'package.json': json`{}`,
|
|
|
|
|
'pnpm-workspace.yaml': yaml`
|
|
|
|
|
#
|
|
|
|
|
packages:
|
|
|
|
|
- project-a
|
|
|
|
|
`,
|
|
|
|
|
'project-a/package.json': json`
|
|
|
|
|
{
|
|
|
|
|
"dependencies": {
|
|
|
|
|
"tailwindcss": "workspace:^",
|
|
|
|
|
"@tailwindcss/cli": "workspace:^"
|
|
|
|
|
}
|
2024-08-07 16:38:44 +02:00
|
|
|
}
|
2024-09-02 15:23:46 +02:00
|
|
|
`,
|
|
|
|
|
'project-a/index.html': html`
|
|
|
|
|
<div
|
2024-10-01 13:52:12 +02:00
|
|
|
class="underline 2xl:font-bold hocus:underline inverted:flex text-primary"
|
2024-09-02 15:23:46 +02:00
|
|
|
></div>
|
|
|
|
|
`,
|
|
|
|
|
'project-a/plugin.js': js`
|
|
|
|
|
module.exports = function ({ addVariant }) {
|
|
|
|
|
addVariant('inverted', '@media (inverted-colors: inverted)')
|
|
|
|
|
addVariant('hocus', ['&:focus', '&:hover'])
|
|
|
|
|
}
|
|
|
|
|
`,
|
2024-09-03 16:54:08 +02:00
|
|
|
'project-a/tailwind.config.js': js`
|
|
|
|
|
module.exports = {
|
|
|
|
|
content: ['../project-b/src/**/*.js'],
|
|
|
|
|
}
|
|
|
|
|
`,
|
2024-09-02 15:23:46 +02:00
|
|
|
'project-a/src/index.css': css`
|
|
|
|
|
@import 'tailwindcss/utilities';
|
2024-10-01 13:52:12 +02:00
|
|
|
@import './custom-theme.css';
|
2024-09-03 16:54:08 +02:00
|
|
|
@config '../tailwind.config.js';
|
|
|
|
|
@source '../../project-b/src/**/*.html';
|
2024-09-02 15:23:46 +02:00
|
|
|
@plugin '../plugin.js';
|
|
|
|
|
`,
|
2024-10-01 13:52:12 +02:00
|
|
|
'project-a/src/custom-theme.css': css`
|
|
|
|
|
/* Will be overwritten later */
|
|
|
|
|
@theme {
|
|
|
|
|
--color-primary: black;
|
|
|
|
|
}
|
|
|
|
|
`,
|
2024-09-02 15:23:46 +02:00
|
|
|
'project-a/src/index.js': js`
|
|
|
|
|
const className = "content-['project-a/src/index.js']"
|
|
|
|
|
module.exports = { className }
|
|
|
|
|
`,
|
2024-09-03 16:54:08 +02:00
|
|
|
'project-b/src/index.html': html`
|
|
|
|
|
<div class="flex" />
|
|
|
|
|
`,
|
2024-09-02 15:23:46 +02:00
|
|
|
'project-b/src/index.js': js`
|
|
|
|
|
const className = "content-['project-b/src/index.js']"
|
|
|
|
|
module.exports = { className }
|
|
|
|
|
`,
|
|
|
|
|
},
|
2024-08-07 16:38:44 +02:00
|
|
|
},
|
2024-09-02 15:23:46 +02:00
|
|
|
async ({ root, fs, spawn }) => {
|
Improve integration tests (stability + performance) (#15125)
This PR improves the integration tests in two ways:
1. Make the integration tests more reliable and thus less flakey
2. Make the integration tests faster (by introducing concurrency)
Tried a lot of different things to make sure that these tests are fast
and stable.
---
The biggest issue we noticed is that some tests are flakey, these are
tests with long running dev-mode processes where watchers are being used
and/or dev servers are created.
To solve this, all the tests that spawn a process look at stdout/stderr
and wait for a message from the process to know whether we can start
making changes.
For example, in case of an Astro project, you get a `watching for file
changes` message. In case of Nuxt project you can wait for an `server
warmed up in` and in case of Next.js there is a `Ready in` message.
These depend on the tools being used, so this is hardcoded per test
instead of a magically automatic solution.
These messages allow us to wait until all the initial necessary work,
internal watchers and/or dev servers are setup before we start making
changes to the files and/or request CSS stylesheets before the server(s)
are ready.
---
Another improvement is how we setup the dev servers. Before, we used to
try and get a free port on the system and use a `--port` flag or a
`PORT` environment variable. Instead of doing this (which is slow), we
rely on the process itself to show a URL with a port. Basically all
tools will try to find a free port if the default port is in use. We can
then use the stdout/stderr messages to get the URL and the port to use.
To reduce the amount of potential conflicts in ports, we used to run
every test and every file sequentially to basically guarantee that ports
are free. With this new approach where we rely on the process, I noticed
that we don't really run into this issue again (I reran the tests
multiple times and they were always stable)
<img width="316" alt="image"
src="https://github.com/user-attachments/assets/b75ddab4-f919-4995-85d0-f212b603e5c2"
/>
Note: these tests run Linux, Windows and macOS in this branch just for
testing purposes. Once this is done, we will only run Linux tests on PRs
and run all 3 of them on the `next` branch.
We do make the tests concurrent by default now, which in theory means
that there could be conflicts (which in practice means that the process
has to do a few more tries to find a free port). To reduce these
conflicts, we split up the integration tests such that Vite, PostCSS,
CLI, … tests all run in a separate job in the GitHub actions workflow.
<img width="312" alt="image"
src="https://github.com/user-attachments/assets/fe9a58a1-98eb-4d9b-8845-a7c8a7af5766"
/>
Comparing this branch against the `next` branch, this is what CI looks
like right now:
| `next` | `feat/improve-integration-tests` |
| --- | --- |
| <img width="594" alt="image"
src="https://github.com/user-attachments/assets/540d21eb-ab03-42e8-9f6f-b3a071fc7635"
/> | <img width="672" alt="image"
src="https://github.com/user-attachments/assets/8ef2e891-08a1-464b-9954-4153174ebce7"
/> |
There also was a point in time where I introduced sequential tests such
that all spawned processes still run after each other, but so far I
didn't run into issues if we keep them concurrent so I dropped that
code.
Some small changes I made to make things more reliable:
1. When relying on stdout/stderr messages, we split lines on `\n` and we
strip all the ANSI escapes which allows us to not worry about special
ANSI characters when finding the URL or a specific message to wait for.
2. Once a test is done, we `child.kill()` the spawned process. If that
doesn't work, for whatever reason, we run a `child.kill('SIGKILL')` to
force kill the process. This could technically lead to some memory or
files not being cleaned up properly, but once CI is done, everything is
thrown away anyway.
3. As you can see in the screenshots, I used some nicer names for the
workflows.
| `next` | `feat/improve-integration-tests` |
| --- | --- |
| <img width="276" alt="image"
src="https://github.com/user-attachments/assets/e574bb53-e21b-4619-9cdb-515431b255b9"
/> | <img width="179" alt="image"
src="https://github.com/user-attachments/assets/8bc75119-fb91-4500-a1d0-bd09f74c93ad"
/> |
They also look a bit nicer in the PR overview as well:
<img width="929" alt="image"
src="https://github.com/user-attachments/assets/04fc71fc-74b0-4e7c-9047-2aada664efef"
/>
The very last commit just filters out Windows and macOS tests again for
PRs (but they are executed on the `next` branch.
---
### Nest steps
I think for now we are in a pretty good state, but there are some things
we can do to further improve everything (mainly make things faster) but
aren't necessary. I also ran into issue while trying it so there is more
work to do.
1. More splits — instead of having a Vite folder and PostCSS folder, we
can go a step further and have folders for Next.js, Astro, Nuxt, Remix,
…
2. Caching — right now we have to run the build step for every OS on
every "job". We can re-use the work here by introducing a setup job that
the other jobs rely on. @thecrypticace and I tried it already, but were
running into some Bun specific Standalone CLI issues when doing that.
3. Remote caching — we could re-enable remote caching such that the
`build` step can be full turbo (e.g.: after a PR is merged in `next` and
we run everything again)
2024-12-12 13:48:56 +01:00
|
|
|
let process = await spawn(`${command} --input src/index.css --output dist/out.css --watch`, {
|
2024-09-02 15:23:46 +02:00
|
|
|
cwd: path.join(root, 'project-a'),
|
|
|
|
|
})
|
Improve integration tests (stability + performance) (#15125)
This PR improves the integration tests in two ways:
1. Make the integration tests more reliable and thus less flakey
2. Make the integration tests faster (by introducing concurrency)
Tried a lot of different things to make sure that these tests are fast
and stable.
---
The biggest issue we noticed is that some tests are flakey, these are
tests with long running dev-mode processes where watchers are being used
and/or dev servers are created.
To solve this, all the tests that spawn a process look at stdout/stderr
and wait for a message from the process to know whether we can start
making changes.
For example, in case of an Astro project, you get a `watching for file
changes` message. In case of Nuxt project you can wait for an `server
warmed up in` and in case of Next.js there is a `Ready in` message.
These depend on the tools being used, so this is hardcoded per test
instead of a magically automatic solution.
These messages allow us to wait until all the initial necessary work,
internal watchers and/or dev servers are setup before we start making
changes to the files and/or request CSS stylesheets before the server(s)
are ready.
---
Another improvement is how we setup the dev servers. Before, we used to
try and get a free port on the system and use a `--port` flag or a
`PORT` environment variable. Instead of doing this (which is slow), we
rely on the process itself to show a URL with a port. Basically all
tools will try to find a free port if the default port is in use. We can
then use the stdout/stderr messages to get the URL and the port to use.
To reduce the amount of potential conflicts in ports, we used to run
every test and every file sequentially to basically guarantee that ports
are free. With this new approach where we rely on the process, I noticed
that we don't really run into this issue again (I reran the tests
multiple times and they were always stable)
<img width="316" alt="image"
src="https://github.com/user-attachments/assets/b75ddab4-f919-4995-85d0-f212b603e5c2"
/>
Note: these tests run Linux, Windows and macOS in this branch just for
testing purposes. Once this is done, we will only run Linux tests on PRs
and run all 3 of them on the `next` branch.
We do make the tests concurrent by default now, which in theory means
that there could be conflicts (which in practice means that the process
has to do a few more tries to find a free port). To reduce these
conflicts, we split up the integration tests such that Vite, PostCSS,
CLI, … tests all run in a separate job in the GitHub actions workflow.
<img width="312" alt="image"
src="https://github.com/user-attachments/assets/fe9a58a1-98eb-4d9b-8845-a7c8a7af5766"
/>
Comparing this branch against the `next` branch, this is what CI looks
like right now:
| `next` | `feat/improve-integration-tests` |
| --- | --- |
| <img width="594" alt="image"
src="https://github.com/user-attachments/assets/540d21eb-ab03-42e8-9f6f-b3a071fc7635"
/> | <img width="672" alt="image"
src="https://github.com/user-attachments/assets/8ef2e891-08a1-464b-9954-4153174ebce7"
/> |
There also was a point in time where I introduced sequential tests such
that all spawned processes still run after each other, but so far I
didn't run into issues if we keep them concurrent so I dropped that
code.
Some small changes I made to make things more reliable:
1. When relying on stdout/stderr messages, we split lines on `\n` and we
strip all the ANSI escapes which allows us to not worry about special
ANSI characters when finding the URL or a specific message to wait for.
2. Once a test is done, we `child.kill()` the spawned process. If that
doesn't work, for whatever reason, we run a `child.kill('SIGKILL')` to
force kill the process. This could technically lead to some memory or
files not being cleaned up properly, but once CI is done, everything is
thrown away anyway.
3. As you can see in the screenshots, I used some nicer names for the
workflows.
| `next` | `feat/improve-integration-tests` |
| --- | --- |
| <img width="276" alt="image"
src="https://github.com/user-attachments/assets/e574bb53-e21b-4619-9cdb-515431b255b9"
/> | <img width="179" alt="image"
src="https://github.com/user-attachments/assets/8bc75119-fb91-4500-a1d0-bd09f74c93ad"
/> |
They also look a bit nicer in the PR overview as well:
<img width="929" alt="image"
src="https://github.com/user-attachments/assets/04fc71fc-74b0-4e7c-9047-2aada664efef"
/>
The very last commit just filters out Windows and macOS tests again for
PRs (but they are executed on the `next` branch.
---
### Nest steps
I think for now we are in a pretty good state, but there are some things
we can do to further improve everything (mainly make things faster) but
aren't necessary. I also ran into issue while trying it so there is more
work to do.
1. More splits — instead of having a Vite folder and PostCSS folder, we
can go a step further and have folders for Next.js, Astro, Nuxt, Remix,
…
2. Caching — right now we have to run the build step for every OS on
every "job". We can re-use the work here by introducing a setup job that
the other jobs rely on. @thecrypticace and I tried it already, but were
running into some Bun specific Standalone CLI issues when doing that.
3. Remote caching — we could re-enable remote caching such that the
`build` step can be full turbo (e.g.: after a PR is merged in `next` and
we run everything again)
2024-12-12 13:48:56 +01:00
|
|
|
await process.onStderr((m) => m.includes('Done in'))
|
2024-08-07 16:38:44 +02:00
|
|
|
|
2024-09-02 15:23:46 +02:00
|
|
|
await fs.expectFileToContain('project-a/dist/out.css', [
|
|
|
|
|
candidate`underline`,
|
2024-09-03 16:54:08 +02:00
|
|
|
candidate`flex`,
|
2024-09-02 15:23:46 +02:00
|
|
|
candidate`content-['project-a/src/index.js']`,
|
|
|
|
|
candidate`content-['project-b/src/index.js']`,
|
|
|
|
|
candidate`inverted:flex`,
|
|
|
|
|
candidate`hocus:underline`,
|
2024-10-01 13:52:12 +02:00
|
|
|
css`
|
|
|
|
|
.text-primary {
|
2024-11-05 15:44:21 -05:00
|
|
|
color: var(--color-primary);
|
2024-10-01 13:52:12 +02:00
|
|
|
}
|
|
|
|
|
`,
|
2024-09-02 15:23:46 +02:00
|
|
|
])
|
2024-08-07 16:38:44 +02:00
|
|
|
|
2024-09-02 15:23:46 +02:00
|
|
|
await fs.write(
|
|
|
|
|
'project-a/src/index.js',
|
|
|
|
|
js`
|
|
|
|
|
const className = "[.changed_&]:content-['project-a/src/index.js']"
|
|
|
|
|
module.exports = { className }
|
|
|
|
|
`,
|
|
|
|
|
)
|
|
|
|
|
await fs.expectFileToContain('project-a/dist/out.css', [
|
|
|
|
|
candidate`[.changed_&]:content-['project-a/src/index.js']`,
|
|
|
|
|
])
|
2024-08-07 16:38:44 +02:00
|
|
|
|
2024-09-02 15:23:46 +02:00
|
|
|
await fs.write(
|
|
|
|
|
'project-b/src/index.js',
|
|
|
|
|
js`
|
|
|
|
|
const className = "[.changed_&]:content-['project-b/src/index.js']"
|
|
|
|
|
module.exports = { className }
|
|
|
|
|
`,
|
|
|
|
|
)
|
|
|
|
|
await fs.expectFileToContain('project-a/dist/out.css', [
|
|
|
|
|
candidate`[.changed_&]:content-['project-b/src/index.js']`,
|
|
|
|
|
])
|
2024-10-01 13:52:12 +02:00
|
|
|
|
|
|
|
|
await fs.write(
|
|
|
|
|
'project-a/src/custom-theme.css',
|
|
|
|
|
css`
|
|
|
|
|
/* Overriding the primary color */
|
|
|
|
|
@theme {
|
|
|
|
|
--color-primary: red;
|
|
|
|
|
}
|
|
|
|
|
`,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
await fs.expectFileToContain('project-a/dist/out.css', [
|
|
|
|
|
css`
|
|
|
|
|
.text-primary {
|
2024-11-05 15:44:21 -05:00
|
|
|
color: var(--color-primary);
|
2024-10-01 13:52:12 +02:00
|
|
|
}
|
|
|
|
|
`,
|
|
|
|
|
])
|
2024-10-21 16:29:33 -04:00
|
|
|
|
|
|
|
|
await fs.write(
|
|
|
|
|
'project-a/src/index.css',
|
|
|
|
|
css`
|
|
|
|
|
@import 'tailwindcss/utilities';
|
|
|
|
|
@theme {
|
|
|
|
|
--color-*: initial;
|
|
|
|
|
}
|
|
|
|
|
`,
|
|
|
|
|
)
|
|
|
|
|
|
2025-01-31 17:56:52 +01:00
|
|
|
await fs.expectFileToContain('project-a/dist/out.css', [css``])
|
2024-09-02 15:23:46 +02:00
|
|
|
},
|
|
|
|
|
)
|
2024-09-26 12:32:46 +02:00
|
|
|
|
|
|
|
|
test(
|
|
|
|
|
'production build (stdin)',
|
|
|
|
|
{
|
|
|
|
|
fs: {
|
|
|
|
|
'package.json': json`
|
|
|
|
|
{
|
|
|
|
|
"dependencies": {
|
|
|
|
|
"tailwindcss": "workspace:^",
|
|
|
|
|
"@tailwindcss/cli": "workspace:^"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
`,
|
|
|
|
|
'index.html': html`
|
|
|
|
|
<div class="underline"></div>
|
|
|
|
|
`,
|
|
|
|
|
'src/index.css': css`@import 'tailwindcss';`,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
async ({ fs, exec }) => {
|
|
|
|
|
await exec(`${command} --input=- --output dist/out.css < src/index.css`)
|
|
|
|
|
|
|
|
|
|
await fs.expectFileToContain('dist/out.css', [candidate`underline`])
|
|
|
|
|
},
|
|
|
|
|
)
|
2024-11-19 18:39:49 +01:00
|
|
|
|
|
|
|
|
test(
|
|
|
|
|
'module resolution using CJS, ESM, CTS, and MTS',
|
|
|
|
|
{
|
|
|
|
|
fs: {
|
|
|
|
|
'package.json': json`{}`,
|
|
|
|
|
'pnpm-workspace.yaml': yaml`
|
|
|
|
|
#
|
|
|
|
|
packages:
|
|
|
|
|
- project-cjs
|
|
|
|
|
- project-esm
|
|
|
|
|
- plugin-cjs
|
|
|
|
|
- plugin-esm
|
|
|
|
|
- plugin-cts
|
|
|
|
|
- plugin-mts
|
|
|
|
|
`,
|
|
|
|
|
'project-cjs/package.json': json`
|
|
|
|
|
{
|
|
|
|
|
"type": "commonjs",
|
|
|
|
|
"dependencies": {
|
|
|
|
|
"tailwindcss": "workspace:^",
|
|
|
|
|
"@tailwindcss/cli": "workspace:^",
|
|
|
|
|
"plugin-cjs": "workspace:*",
|
|
|
|
|
"plugin-esm": "workspace:*",
|
|
|
|
|
"plugin-cts": "workspace:*",
|
|
|
|
|
"plugin-mts": "workspace:*"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
`,
|
|
|
|
|
'project-cjs/index.html': html`
|
|
|
|
|
<div class="cjs esm cts mts"></div>
|
|
|
|
|
`,
|
|
|
|
|
'project-cjs/src/index.css': css`
|
|
|
|
|
@import 'tailwindcss/utilities';
|
|
|
|
|
@plugin 'plugin-cjs';
|
|
|
|
|
@plugin 'plugin-esm';
|
|
|
|
|
@plugin 'plugin-cts';
|
|
|
|
|
@plugin 'plugin-mts';
|
|
|
|
|
`,
|
|
|
|
|
|
|
|
|
|
'project-esm/package.json': json`
|
|
|
|
|
{
|
|
|
|
|
"type": "module",
|
|
|
|
|
"dependencies": {
|
|
|
|
|
"tailwindcss": "workspace:^",
|
|
|
|
|
"@tailwindcss/cli": "workspace:^",
|
|
|
|
|
"plugin-cjs": "workspace:*",
|
|
|
|
|
"plugin-esm": "workspace:*",
|
|
|
|
|
"plugin-cts": "workspace:*",
|
|
|
|
|
"plugin-mts": "workspace:*"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
`,
|
|
|
|
|
'project-esm/index.html': html`
|
|
|
|
|
<div class="cjs esm cts mts"></div>
|
|
|
|
|
`,
|
|
|
|
|
'project-esm/src/index.css': css`
|
|
|
|
|
@import 'tailwindcss/utilities';
|
|
|
|
|
@plugin 'plugin-cjs';
|
|
|
|
|
@plugin 'plugin-esm';
|
|
|
|
|
@plugin 'plugin-cts';
|
|
|
|
|
@plugin 'plugin-mts';
|
|
|
|
|
`,
|
|
|
|
|
|
|
|
|
|
'plugin-cjs/package.json': json`
|
|
|
|
|
{
|
|
|
|
|
"name": "plugin-cjs",
|
|
|
|
|
"type": "commonjs",
|
|
|
|
|
"exports": {
|
|
|
|
|
".": {
|
|
|
|
|
"require": "./index.cjs"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
`,
|
|
|
|
|
'plugin-cjs/index.cjs': js`
|
|
|
|
|
module.exports = function ({ addUtilities }) {
|
|
|
|
|
addUtilities({ '.cjs': { content: '"cjs"' } })
|
|
|
|
|
}
|
|
|
|
|
`,
|
|
|
|
|
|
|
|
|
|
'plugin-esm/package.json': json`
|
|
|
|
|
{
|
|
|
|
|
"name": "plugin-esm",
|
|
|
|
|
"type": "module",
|
|
|
|
|
"exports": {
|
|
|
|
|
".": {
|
|
|
|
|
"import": "./index.mjs"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
`,
|
|
|
|
|
'plugin-esm/index.mjs': js`
|
|
|
|
|
export default function ({ addUtilities }) {
|
|
|
|
|
addUtilities({ '.esm': { content: '"esm"' } })
|
|
|
|
|
}
|
|
|
|
|
`,
|
|
|
|
|
|
|
|
|
|
'plugin-cts/package.json': json`
|
|
|
|
|
{
|
|
|
|
|
"name": "plugin-cts",
|
|
|
|
|
"type": "commonjs",
|
|
|
|
|
"exports": {
|
|
|
|
|
".": {
|
|
|
|
|
"require": "./index.cts"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
`,
|
|
|
|
|
'plugin-cts/index.cts': ts`
|
|
|
|
|
export default function ({ addUtilities }) {
|
|
|
|
|
addUtilities({ '.cts': { content: '"cts"' as const } })
|
|
|
|
|
}
|
|
|
|
|
`,
|
|
|
|
|
|
|
|
|
|
'plugin-mts/package.json': json`
|
|
|
|
|
{
|
|
|
|
|
"name": "plugin-mts",
|
|
|
|
|
"type": "module",
|
|
|
|
|
"exports": {
|
|
|
|
|
".": {
|
|
|
|
|
"import": "./index.mts"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
`,
|
|
|
|
|
'plugin-mts/index.mts': ts`
|
|
|
|
|
export default function ({ addUtilities }) {
|
|
|
|
|
addUtilities({ '.mts': { content: '"mts"' as const } })
|
|
|
|
|
}
|
|
|
|
|
`,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
async ({ root, fs, exec }) => {
|
|
|
|
|
await exec(`${command} --input src/index.css --output dist/out.css`, {
|
|
|
|
|
cwd: path.join(root, 'project-cjs'),
|
|
|
|
|
})
|
|
|
|
|
await exec(`${command} --input src/index.css --output dist/out.css`, {
|
|
|
|
|
cwd: path.join(root, 'project-esm'),
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
await fs.expectFileToContain('./project-cjs/dist/out.css', [
|
|
|
|
|
candidate`cjs`,
|
|
|
|
|
candidate`esm`,
|
|
|
|
|
candidate`cts`,
|
|
|
|
|
candidate`mts`,
|
|
|
|
|
])
|
|
|
|
|
await fs.expectFileToContain('./project-esm/dist/out.css', [
|
|
|
|
|
candidate`cjs`,
|
|
|
|
|
candidate`esm`,
|
|
|
|
|
candidate`cts`,
|
|
|
|
|
candidate`mts`,
|
|
|
|
|
])
|
|
|
|
|
},
|
|
|
|
|
)
|
2025-01-28 11:13:16 -05:00
|
|
|
|
|
|
|
|
test(
|
|
|
|
|
'git ignore files outside of a repo are not considered',
|
|
|
|
|
{
|
|
|
|
|
fs: {
|
|
|
|
|
// Ignore everything in the "home" directory
|
|
|
|
|
'home/.gitignore': '*',
|
|
|
|
|
|
|
|
|
|
// Only ignore files called ignore-*.html in the actual git repo
|
|
|
|
|
'home/project/.gitignore': 'ignore-*.html',
|
|
|
|
|
|
|
|
|
|
'home/project/package.json': json`
|
|
|
|
|
{
|
|
|
|
|
"type": "module",
|
|
|
|
|
"dependencies": {
|
|
|
|
|
"tailwindcss": "workspace:^",
|
|
|
|
|
"@tailwindcss/cli": "workspace:^"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
`,
|
|
|
|
|
|
|
|
|
|
'home/project/src/index.css': css` @import 'tailwindcss'; `,
|
|
|
|
|
'home/project/src/index.html': html`
|
|
|
|
|
<div
|
|
|
|
|
class="content-['index.html']"
|
|
|
|
|
></div>
|
|
|
|
|
`,
|
|
|
|
|
'home/project/src/ignore-1.html': html`
|
|
|
|
|
<div
|
|
|
|
|
class="content-['ignore-1.html']"
|
|
|
|
|
></div>
|
|
|
|
|
`,
|
|
|
|
|
'home/project/src/ignore-2.html': html`
|
|
|
|
|
<div
|
|
|
|
|
class="content-['ignore-2.html']"
|
|
|
|
|
></div>
|
|
|
|
|
`,
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
installDependencies: false,
|
|
|
|
|
},
|
|
|
|
|
async ({ fs, root, exec }) => {
|
|
|
|
|
await exec(`pnpm install --ignore-workspace`, {
|
|
|
|
|
cwd: path.join(root, 'home/project'),
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// No git repo = all ignore files are considered
|
|
|
|
|
await exec(`${command} --input src/index.css --output dist/out.css`, {
|
|
|
|
|
cwd: path.join(root, 'home/project'),
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
await fs.expectFileNotToContain('./home/project/dist/out.css', [
|
|
|
|
|
candidate`content-['index.html']`,
|
|
|
|
|
candidate`content-['ignore-1.html']`,
|
|
|
|
|
candidate`content-['ignore-2.html']`,
|
|
|
|
|
])
|
|
|
|
|
|
|
|
|
|
// Make home/project a git repo
|
|
|
|
|
// Only ignore files within the repo are considered
|
|
|
|
|
await exec(`git init`, {
|
|
|
|
|
cwd: path.join(root, 'home/project'),
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
await exec(`${command} --input src/index.css --output dist/out.css`, {
|
|
|
|
|
cwd: path.join(root, 'home/project'),
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
await fs.expectFileToContain('./home/project/dist/out.css', [
|
|
|
|
|
candidate`content-['index.html']`,
|
|
|
|
|
])
|
|
|
|
|
|
|
|
|
|
await fs.expectFileNotToContain('./home/project/dist/out.css', [
|
|
|
|
|
candidate`content-['ignore-1.html']`,
|
|
|
|
|
candidate`content-['ignore-2.html']`,
|
|
|
|
|
])
|
|
|
|
|
},
|
|
|
|
|
)
|
2024-09-02 15:23:46 +02:00
|
|
|
})
|
Auto source detection improvements (#14820)
This PR introduces a new `source(…)` argument and improves on the
existing `@source`. The goal of this PR is to make the automatic source
detection configurable, let's dig in.
By default, we will perform automatic source detection starting at the
current working directory. Auto source detection will find plain text
files (no binaries, images, ...) and will ignore git-ignored files.
If you want to start from a different directory, you can use the new
`source(…)` next to the `@import "tailwindcss/utilities"
layer(utilities) source(…)`.
E.g.:
```css
/* ./src/styles/index.css */
@import 'tailwindcss/utilities' layer(utilities) source('../../');
```
Most people won't split their source files, and will just use the simple
`@import "tailwindcss";`, because of this reason, you can use
`source(…)` on the import as well:
E.g.:
```css
/* ./src/styles/index.css */
@import 'tailwindcss' source('../../');
```
Sometimes, you want to rely on auto source detection, but also want to
look in another directory for source files. In this case, yuo can use
the `@source` directive:
```css
/* ./src/index.css */
@import 'tailwindcss';
/* Look for `blade.php` files in `../resources/views` */
@source '../resources/views/**/*.blade.php';
```
However, you don't need to specify the extension, instead you can just
point the directory and all the same automatic source detection rules
will apply.
```css
/* ./src/index.css */
@import 'tailwindcss';
@source '../resources/views';
```
If, for whatever reason, you want to disable the default source
detection feature entirely, and only want to rely on very specific glob
patterns you define, then you can disable it via `source(none)`.
```css
/* Completely disable the default auto source detection */
@import 'tailwindcss' source(none);
/* Only look at .blade.php files, nothing else */
@source "../resources/views/**/*.blade.php";
```
Note: even with `source(none)`, if your `@source` points to a directory,
then auto source detection will still be performed in that directory. If
you don't want that, then you can simply add explicit files in the globs
as seen in the previous example.
```css
/* Completely disable the default auto source detection */
@import 'tailwindcss' source(none);
/* Run auto source detection in `../resources/views` */
@source "../resources/views";
```
---------
Co-authored-by: Jordan Pittman <jordan@cryptica.me>
Co-authored-by: Adam Wathan <4323180+adamwathan@users.noreply.github.com>
2024-10-29 21:33:34 +01:00
|
|
|
|
|
|
|
|
test(
|
|
|
|
|
'auto source detection kitchen sink',
|
|
|
|
|
{
|
|
|
|
|
fs: {
|
|
|
|
|
'package.json': json`
|
|
|
|
|
{
|
|
|
|
|
"dependencies": {
|
|
|
|
|
"tailwindcss": "workspace:^",
|
|
|
|
|
"@tailwindcss/cli": "workspace:^"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
`,
|
|
|
|
|
'index.css': css`
|
|
|
|
|
@import 'tailwindcss/theme' theme(reference);
|
|
|
|
|
|
|
|
|
|
/* (1) */
|
|
|
|
|
/* - Only './src' should be auto-scanned, not the current working directory */
|
|
|
|
|
/* - .gitignore'd paths should be ignored (node_modules) */
|
|
|
|
|
/* - Binary extensions should be ignored (jpg, zip) */
|
|
|
|
|
@import 'tailwindcss/utilities' source('./src');
|
|
|
|
|
|
|
|
|
|
/* (2) */
|
|
|
|
|
/* - All HTML and JSX files in 'ignored/components' should be scanned */
|
|
|
|
|
/* - All other extensions should be ignored */
|
|
|
|
|
@source "./ignored/components/*.{html,jsx}";
|
|
|
|
|
|
|
|
|
|
/* (3) */
|
|
|
|
|
/* - './components' should be auto-scanned in addition to './src' */
|
|
|
|
|
/* - './components/ignored.html' should still be ignored */
|
|
|
|
|
/* - Binary extensions in './components' should be ignored */
|
|
|
|
|
@source "./components";
|
|
|
|
|
|
|
|
|
|
/* (4) */
|
|
|
|
|
/* - './pages' should be auto-scanned */
|
|
|
|
|
/* - Only '.html' files should be included */
|
|
|
|
|
/* - './page/ignored.html' should be ignored */
|
|
|
|
|
@source "./pages/**/*.html";
|
|
|
|
|
`,
|
|
|
|
|
|
|
|
|
|
'.gitignore': dedent`
|
|
|
|
|
/src/ignored
|
|
|
|
|
/ignored
|
|
|
|
|
/components/ignored.html
|
|
|
|
|
/pages/ignored.html
|
|
|
|
|
`,
|
|
|
|
|
|
|
|
|
|
// (1)
|
|
|
|
|
'index.html': 'content-["index.html"] content-["BAD"]', // "Root" source is in `./src`
|
|
|
|
|
'src/index.html': 'content-["src/index.html"]',
|
|
|
|
|
'src/nested/index.html': 'content-["src/nested/index.html"]',
|
|
|
|
|
'src/index.jpg': 'content-["src/index.jpg"] content-["BAD"]',
|
|
|
|
|
'src/nested/index.tar': 'content-["src/nested/index.tar"] content-["BAD"]',
|
|
|
|
|
'src/ignored/index.html': 'content-["src/ignored/index.html"] content-["BAD"]',
|
|
|
|
|
|
|
|
|
|
// (2)
|
|
|
|
|
'ignored/components/my-component.html': 'content-["ignored/components/my-component.html"]',
|
|
|
|
|
'ignored/components/my-component.jsx': 'content-["ignored/components/my-component.jsx"]',
|
|
|
|
|
|
|
|
|
|
// Ignored and not explicitly listed by (2)
|
|
|
|
|
'ignored/components/my-component.tsx':
|
|
|
|
|
'content-["ignored/components/my-component.tsx"] content-["BAD"]',
|
|
|
|
|
'ignored/components/nested/my-component.html':
|
|
|
|
|
'content-["ignored/components/nested/my-component.html"] content-["BAD"]',
|
|
|
|
|
|
|
|
|
|
// (3)
|
|
|
|
|
'components/my-component.tsx': 'content-["components/my-component.tsx"]',
|
|
|
|
|
'components/nested/my-component.tsx': 'content-["components/nested/my-component.tsx"]',
|
|
|
|
|
'components/ignored.html': 'content-["components/ignored.html"] content-["BAD"]',
|
|
|
|
|
|
|
|
|
|
// (4)
|
|
|
|
|
'pages/foo.html': 'content-["pages/foo.html"]',
|
|
|
|
|
'pages/nested/foo.html': 'content-["pages/nested/foo.html"]',
|
|
|
|
|
'pages/ignored.html': 'content-["pages/ignored.html"] content-["BAD"]',
|
|
|
|
|
'pages/foo.jsx': 'content-["pages/foo.jsx"] content-["BAD"]',
|
|
|
|
|
'pages/nested/foo.jsx': 'content-["pages/nested/foo.jsx"] content-["BAD"]',
|
|
|
|
|
},
|
|
|
|
|
},
|
Improve integration tests (stability + performance) (#15125)
This PR improves the integration tests in two ways:
1. Make the integration tests more reliable and thus less flakey
2. Make the integration tests faster (by introducing concurrency)
Tried a lot of different things to make sure that these tests are fast
and stable.
---
The biggest issue we noticed is that some tests are flakey, these are
tests with long running dev-mode processes where watchers are being used
and/or dev servers are created.
To solve this, all the tests that spawn a process look at stdout/stderr
and wait for a message from the process to know whether we can start
making changes.
For example, in case of an Astro project, you get a `watching for file
changes` message. In case of Nuxt project you can wait for an `server
warmed up in` and in case of Next.js there is a `Ready in` message.
These depend on the tools being used, so this is hardcoded per test
instead of a magically automatic solution.
These messages allow us to wait until all the initial necessary work,
internal watchers and/or dev servers are setup before we start making
changes to the files and/or request CSS stylesheets before the server(s)
are ready.
---
Another improvement is how we setup the dev servers. Before, we used to
try and get a free port on the system and use a `--port` flag or a
`PORT` environment variable. Instead of doing this (which is slow), we
rely on the process itself to show a URL with a port. Basically all
tools will try to find a free port if the default port is in use. We can
then use the stdout/stderr messages to get the URL and the port to use.
To reduce the amount of potential conflicts in ports, we used to run
every test and every file sequentially to basically guarantee that ports
are free. With this new approach where we rely on the process, I noticed
that we don't really run into this issue again (I reran the tests
multiple times and they were always stable)
<img width="316" alt="image"
src="https://github.com/user-attachments/assets/b75ddab4-f919-4995-85d0-f212b603e5c2"
/>
Note: these tests run Linux, Windows and macOS in this branch just for
testing purposes. Once this is done, we will only run Linux tests on PRs
and run all 3 of them on the `next` branch.
We do make the tests concurrent by default now, which in theory means
that there could be conflicts (which in practice means that the process
has to do a few more tries to find a free port). To reduce these
conflicts, we split up the integration tests such that Vite, PostCSS,
CLI, … tests all run in a separate job in the GitHub actions workflow.
<img width="312" alt="image"
src="https://github.com/user-attachments/assets/fe9a58a1-98eb-4d9b-8845-a7c8a7af5766"
/>
Comparing this branch against the `next` branch, this is what CI looks
like right now:
| `next` | `feat/improve-integration-tests` |
| --- | --- |
| <img width="594" alt="image"
src="https://github.com/user-attachments/assets/540d21eb-ab03-42e8-9f6f-b3a071fc7635"
/> | <img width="672" alt="image"
src="https://github.com/user-attachments/assets/8ef2e891-08a1-464b-9954-4153174ebce7"
/> |
There also was a point in time where I introduced sequential tests such
that all spawned processes still run after each other, but so far I
didn't run into issues if we keep them concurrent so I dropped that
code.
Some small changes I made to make things more reliable:
1. When relying on stdout/stderr messages, we split lines on `\n` and we
strip all the ANSI escapes which allows us to not worry about special
ANSI characters when finding the URL or a specific message to wait for.
2. Once a test is done, we `child.kill()` the spawned process. If that
doesn't work, for whatever reason, we run a `child.kill('SIGKILL')` to
force kill the process. This could technically lead to some memory or
files not being cleaned up properly, but once CI is done, everything is
thrown away anyway.
3. As you can see in the screenshots, I used some nicer names for the
workflows.
| `next` | `feat/improve-integration-tests` |
| --- | --- |
| <img width="276" alt="image"
src="https://github.com/user-attachments/assets/e574bb53-e21b-4619-9cdb-515431b255b9"
/> | <img width="179" alt="image"
src="https://github.com/user-attachments/assets/8bc75119-fb91-4500-a1d0-bd09f74c93ad"
/> |
They also look a bit nicer in the PR overview as well:
<img width="929" alt="image"
src="https://github.com/user-attachments/assets/04fc71fc-74b0-4e7c-9047-2aada664efef"
/>
The very last commit just filters out Windows and macOS tests again for
PRs (but they are executed on the `next` branch.
---
### Nest steps
I think for now we are in a pretty good state, but there are some things
we can do to further improve everything (mainly make things faster) but
aren't necessary. I also ran into issue while trying it so there is more
work to do.
1. More splits — instead of having a Vite folder and PostCSS folder, we
can go a step further and have folders for Next.js, Astro, Nuxt, Remix,
…
2. Caching — right now we have to run the build step for every OS on
every "job". We can re-use the work here by introducing a setup job that
the other jobs rely on. @thecrypticace and I tried it already, but were
running into some Bun specific Standalone CLI issues when doing that.
3. Remote caching — we could re-enable remote caching such that the
`build` step can be full turbo (e.g.: after a PR is merged in `next` and
we run everything again)
2024-12-12 13:48:56 +01:00
|
|
|
async ({ fs, exec, expect }) => {
|
Auto source detection improvements (#14820)
This PR introduces a new `source(…)` argument and improves on the
existing `@source`. The goal of this PR is to make the automatic source
detection configurable, let's dig in.
By default, we will perform automatic source detection starting at the
current working directory. Auto source detection will find plain text
files (no binaries, images, ...) and will ignore git-ignored files.
If you want to start from a different directory, you can use the new
`source(…)` next to the `@import "tailwindcss/utilities"
layer(utilities) source(…)`.
E.g.:
```css
/* ./src/styles/index.css */
@import 'tailwindcss/utilities' layer(utilities) source('../../');
```
Most people won't split their source files, and will just use the simple
`@import "tailwindcss";`, because of this reason, you can use
`source(…)` on the import as well:
E.g.:
```css
/* ./src/styles/index.css */
@import 'tailwindcss' source('../../');
```
Sometimes, you want to rely on auto source detection, but also want to
look in another directory for source files. In this case, yuo can use
the `@source` directive:
```css
/* ./src/index.css */
@import 'tailwindcss';
/* Look for `blade.php` files in `../resources/views` */
@source '../resources/views/**/*.blade.php';
```
However, you don't need to specify the extension, instead you can just
point the directory and all the same automatic source detection rules
will apply.
```css
/* ./src/index.css */
@import 'tailwindcss';
@source '../resources/views';
```
If, for whatever reason, you want to disable the default source
detection feature entirely, and only want to rely on very specific glob
patterns you define, then you can disable it via `source(none)`.
```css
/* Completely disable the default auto source detection */
@import 'tailwindcss' source(none);
/* Only look at .blade.php files, nothing else */
@source "../resources/views/**/*.blade.php";
```
Note: even with `source(none)`, if your `@source` points to a directory,
then auto source detection will still be performed in that directory. If
you don't want that, then you can simply add explicit files in the globs
as seen in the previous example.
```css
/* Completely disable the default auto source detection */
@import 'tailwindcss' source(none);
/* Run auto source detection in `../resources/views` */
@source "../resources/views";
```
---------
Co-authored-by: Jordan Pittman <jordan@cryptica.me>
Co-authored-by: Adam Wathan <4323180+adamwathan@users.noreply.github.com>
2024-10-29 21:33:34 +01:00
|
|
|
await exec('pnpm tailwindcss --input index.css --output dist/out.css')
|
|
|
|
|
|
|
|
|
|
expect(await fs.dumpFiles('./dist/*.css')).toMatchInlineSnapshot(`
|
|
|
|
|
"
|
|
|
|
|
--- ./dist/out.css ---
|
|
|
|
|
.content-\\[\\"components\\/my-component\\.tsx\\"\\] {
|
|
|
|
|
--tw-content: "components/my-component.tsx";
|
|
|
|
|
content: var(--tw-content);
|
|
|
|
|
}
|
|
|
|
|
.content-\\[\\"components\\/nested\\/my-component\\.tsx\\"\\] {
|
|
|
|
|
--tw-content: "components/nested/my-component.tsx";
|
|
|
|
|
content: var(--tw-content);
|
|
|
|
|
}
|
|
|
|
|
.content-\\[\\"ignored\\/components\\/my-component\\.html\\"\\] {
|
|
|
|
|
--tw-content: "ignored/components/my-component.html";
|
|
|
|
|
content: var(--tw-content);
|
|
|
|
|
}
|
|
|
|
|
.content-\\[\\"ignored\\/components\\/my-component\\.jsx\\"\\] {
|
|
|
|
|
--tw-content: "ignored/components/my-component.jsx";
|
|
|
|
|
content: var(--tw-content);
|
|
|
|
|
}
|
|
|
|
|
.content-\\[\\"pages\\/foo\\.html\\"\\] {
|
|
|
|
|
--tw-content: "pages/foo.html";
|
|
|
|
|
content: var(--tw-content);
|
|
|
|
|
}
|
|
|
|
|
.content-\\[\\"pages\\/nested\\/foo\\.html\\"\\] {
|
|
|
|
|
--tw-content: "pages/nested/foo.html";
|
|
|
|
|
content: var(--tw-content);
|
|
|
|
|
}
|
|
|
|
|
.content-\\[\\"src\\/index\\.html\\"\\] {
|
|
|
|
|
--tw-content: "src/index.html";
|
|
|
|
|
content: var(--tw-content);
|
|
|
|
|
}
|
|
|
|
|
.content-\\[\\"src\\/nested\\/index\\.html\\"\\] {
|
|
|
|
|
--tw-content: "src/nested/index.html";
|
|
|
|
|
content: var(--tw-content);
|
|
|
|
|
}
|
|
|
|
|
@property --tw-content {
|
|
|
|
|
syntax: "*";
|
|
|
|
|
inherits: false;
|
|
|
|
|
initial-value: "";
|
|
|
|
|
}
|
|
|
|
|
"
|
|
|
|
|
`)
|
|
|
|
|
},
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
test(
|
|
|
|
|
'auto source detection in depth, source(…) and `@source` can be configured to use auto source detection (build + watch mode)',
|
|
|
|
|
{
|
|
|
|
|
fs: {
|
|
|
|
|
'package.json': json`{}`,
|
|
|
|
|
'pnpm-workspace.yaml': yaml`
|
|
|
|
|
#
|
|
|
|
|
packages:
|
|
|
|
|
- project-a
|
|
|
|
|
`,
|
|
|
|
|
'project-a/package.json': json`
|
|
|
|
|
{
|
|
|
|
|
"dependencies": {
|
|
|
|
|
"tailwindcss": "workspace:^",
|
|
|
|
|
"@tailwindcss/cli": "workspace:^"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
`,
|
|
|
|
|
'project-a/src/index.css': css`
|
|
|
|
|
@import 'tailwindcss/theme' theme(reference);
|
|
|
|
|
|
|
|
|
|
/* Run auto-content detection in ../../project-b */
|
|
|
|
|
@import 'tailwindcss/utilities' source('../../project-b');
|
|
|
|
|
|
|
|
|
|
/* Explicitly using node_modules in the @source allows git ignored folders */
|
|
|
|
|
@source '../node_modules/{my-lib-1,my-lib-2}/src/**/*.html';
|
|
|
|
|
|
|
|
|
|
/* We typically ignore these extensions, but now include them explicitly */
|
|
|
|
|
@source './logo.{jpg,png}';
|
|
|
|
|
|
|
|
|
|
/* Project C should apply auto source detection */
|
|
|
|
|
@source '../../project-c';
|
|
|
|
|
|
|
|
|
|
/* Project D should apply auto source detection rules, such as ignoring node_modules */
|
|
|
|
|
@source '../../project-d/**/*.{html,js}';
|
|
|
|
|
@source '../../project-d/**/*.bin';
|
|
|
|
|
|
|
|
|
|
/* Same as above, but my-lib-2 _should_ be includes */
|
|
|
|
|
@source '../../project-d/node_modules/my-lib-2/src/*.{html,js}';
|
|
|
|
|
|
|
|
|
|
/* bar.html is git ignored, but explicitly listed here to scan */
|
|
|
|
|
@source '../../project-d/src/bar.html';
|
2024-10-30 21:24:48 +01:00
|
|
|
|
|
|
|
|
/* Project E's source ends with '..' */
|
|
|
|
|
@source '../../project-e/nested/..';
|
Auto source detection improvements (#14820)
This PR introduces a new `source(…)` argument and improves on the
existing `@source`. The goal of this PR is to make the automatic source
detection configurable, let's dig in.
By default, we will perform automatic source detection starting at the
current working directory. Auto source detection will find plain text
files (no binaries, images, ...) and will ignore git-ignored files.
If you want to start from a different directory, you can use the new
`source(…)` next to the `@import "tailwindcss/utilities"
layer(utilities) source(…)`.
E.g.:
```css
/* ./src/styles/index.css */
@import 'tailwindcss/utilities' layer(utilities) source('../../');
```
Most people won't split their source files, and will just use the simple
`@import "tailwindcss";`, because of this reason, you can use
`source(…)` on the import as well:
E.g.:
```css
/* ./src/styles/index.css */
@import 'tailwindcss' source('../../');
```
Sometimes, you want to rely on auto source detection, but also want to
look in another directory for source files. In this case, yuo can use
the `@source` directive:
```css
/* ./src/index.css */
@import 'tailwindcss';
/* Look for `blade.php` files in `../resources/views` */
@source '../resources/views/**/*.blade.php';
```
However, you don't need to specify the extension, instead you can just
point the directory and all the same automatic source detection rules
will apply.
```css
/* ./src/index.css */
@import 'tailwindcss';
@source '../resources/views';
```
If, for whatever reason, you want to disable the default source
detection feature entirely, and only want to rely on very specific glob
patterns you define, then you can disable it via `source(none)`.
```css
/* Completely disable the default auto source detection */
@import 'tailwindcss' source(none);
/* Only look at .blade.php files, nothing else */
@source "../resources/views/**/*.blade.php";
```
Note: even with `source(none)`, if your `@source` points to a directory,
then auto source detection will still be performed in that directory. If
you don't want that, then you can simply add explicit files in the globs
as seen in the previous example.
```css
/* Completely disable the default auto source detection */
@import 'tailwindcss' source(none);
/* Run auto source detection in `../resources/views` */
@source "../resources/views";
```
---------
Co-authored-by: Jordan Pittman <jordan@cryptica.me>
Co-authored-by: Adam Wathan <4323180+adamwathan@users.noreply.github.com>
2024-10-29 21:33:34 +01:00
|
|
|
`,
|
|
|
|
|
|
|
|
|
|
// Project A is the current folder, but we explicitly configured
|
|
|
|
|
// `source(project-b)`, therefore project-a should not be included in
|
|
|
|
|
// the output.
|
|
|
|
|
'project-a/src/index.html': html`
|
|
|
|
|
<div
|
|
|
|
|
class="content-['SHOULD-NOT-EXIST-IN-OUTPUT'] content-['project-a/src/index.html']"
|
|
|
|
|
></div>
|
|
|
|
|
`,
|
|
|
|
|
|
|
|
|
|
// Project A explicitly includes an extension we usually ignore,
|
|
|
|
|
// therefore it should be included in the output.
|
|
|
|
|
'project-a/src/logo.jpg': html`
|
|
|
|
|
<div
|
|
|
|
|
class="content-['project-a/src/logo.jpg']"
|
|
|
|
|
></div>
|
|
|
|
|
`,
|
|
|
|
|
|
|
|
|
|
// Project A explicitly includes node_modules/{my-lib-1,my-lib-2},
|
|
|
|
|
// therefore these files should be included in the output.
|
|
|
|
|
'project-a/node_modules/my-lib-1/src/index.html': html`
|
|
|
|
|
<div
|
|
|
|
|
class="content-['project-a/node_modules/my-lib-1/src/index.html']"
|
|
|
|
|
></div>
|
|
|
|
|
`,
|
|
|
|
|
'project-a/node_modules/my-lib-2/src/index.html': html`
|
|
|
|
|
<div
|
|
|
|
|
class="content-['project-a/node_modules/my-lib-2/src/index.html']"
|
|
|
|
|
></div>
|
|
|
|
|
`,
|
|
|
|
|
|
|
|
|
|
// Project B is the configured `source(…)`, therefore auto source
|
|
|
|
|
// detection should include known extensions and folders in the output.
|
|
|
|
|
'project-b/src/index.html': html`
|
|
|
|
|
<div
|
|
|
|
|
class="content-['project-b/src/index.html']"
|
|
|
|
|
></div>
|
|
|
|
|
`,
|
|
|
|
|
|
|
|
|
|
// Project B is the configured `source(…)`, therefore auto source
|
|
|
|
|
// detection should apply and node_modules should not be included in the
|
|
|
|
|
// output.
|
|
|
|
|
'project-b/node_modules/my-lib-3/src/index.html': html`
|
|
|
|
|
<div
|
|
|
|
|
class="content-['SHOULD-NOT-EXIST-IN-OUTPUT'] content-['project-b/node_modules/my-lib-3/src/index.html']"
|
|
|
|
|
></div>
|
|
|
|
|
`,
|
|
|
|
|
|
|
|
|
|
// Project C should apply auto source detection, therefore known
|
|
|
|
|
// extensions and folders should be included in the output.
|
|
|
|
|
'project-c/src/index.html': html`
|
|
|
|
|
<div
|
|
|
|
|
class="content-['project-c/src/index.html']"
|
|
|
|
|
></div>
|
|
|
|
|
`,
|
|
|
|
|
|
|
|
|
|
// Project C should apply auto source detection, therefore known ignored
|
|
|
|
|
// extensions should not be included in the output.
|
|
|
|
|
'project-c/src/logo.jpg': html`
|
|
|
|
|
<div
|
|
|
|
|
class="content-['SHOULD-NOT-EXIST-IN-OUTPUT'] content-['project-c/src/logo.jpg']"
|
|
|
|
|
></div>
|
|
|
|
|
`,
|
|
|
|
|
|
|
|
|
|
// Project C should apply auto source detection, therefore node_modules
|
|
|
|
|
// should not be included in the output.
|
|
|
|
|
'project-c/node_modules/my-lib-1/src/index.html': html`
|
|
|
|
|
<div
|
|
|
|
|
class="content-['SHOULD-NOT-EXIST-IN-OUTPUT'] content-['project-c/node_modules/my-lib-1/src/index.html']"
|
|
|
|
|
></div>
|
|
|
|
|
`,
|
|
|
|
|
|
|
|
|
|
// Project D should apply auto source detection rules, such as ignoring
|
|
|
|
|
// node_modules.
|
|
|
|
|
'project-d/node_modules/my-lib-1/src/index.html': html`
|
|
|
|
|
<div
|
|
|
|
|
class="content-['SHOULD-NOT-EXIST-IN-OUTPUT'] content-['project-d/node_modules/my-lib-1/src/index.html']"
|
|
|
|
|
></div>
|
|
|
|
|
`,
|
|
|
|
|
|
|
|
|
|
// Project D has an explicit glob containing node_modules, thus should include the html file
|
|
|
|
|
'project-d/node_modules/my-lib-2/src/index.html': html`
|
|
|
|
|
<div
|
|
|
|
|
class="content-['project-d/node_modules/my-lib-2/src/index.html']"
|
|
|
|
|
></div>
|
|
|
|
|
`,
|
|
|
|
|
|
|
|
|
|
'project-d/src/.gitignore': dedent`
|
|
|
|
|
foo.html
|
|
|
|
|
bar.html
|
|
|
|
|
`,
|
|
|
|
|
|
|
|
|
|
// Project D, foo.html is ignored by the gitignore file.
|
|
|
|
|
'project-d/src/foo.html': html`
|
|
|
|
|
<div
|
|
|
|
|
class="content-['SHOULD-NOT-EXIST-IN-OUTPUT'] content-['project-d/src/foo.html']"
|
|
|
|
|
></div>
|
|
|
|
|
`,
|
|
|
|
|
|
|
|
|
|
// Project D, bar.html is ignored by the gitignore file. But explicitly
|
|
|
|
|
// listed as a `@source` glob.
|
|
|
|
|
'project-d/src/bar.html': html`
|
|
|
|
|
<div
|
|
|
|
|
class="content-['project-d/src/bar.html']"
|
|
|
|
|
></div>
|
|
|
|
|
`,
|
|
|
|
|
|
|
|
|
|
// Project D should look for files with the extensions html and js.
|
|
|
|
|
'project-d/src/index.html': html`
|
|
|
|
|
<div
|
|
|
|
|
class="content-['project-d/src/index.html']"
|
|
|
|
|
></div>
|
|
|
|
|
`,
|
|
|
|
|
|
|
|
|
|
// Project D should have a binary file even though we ignore binary files
|
|
|
|
|
// by default, but it's explicitly listed.
|
|
|
|
|
'project-d/my-binary-file.bin': html`
|
|
|
|
|
<div
|
|
|
|
|
class="content-['project-d/my-binary-file.bin']"
|
|
|
|
|
></div>
|
|
|
|
|
`,
|
2024-10-30 21:24:48 +01:00
|
|
|
|
|
|
|
|
// Project E's `@source "project-e/nested/.."` ends with `..`, which
|
|
|
|
|
// should look for files in `project-e` itself.
|
|
|
|
|
'project-e/index.html': html`<div class="content-['project-e/index.html']"></div>`,
|
|
|
|
|
'project-e/nested/index.html': html`<div
|
|
|
|
|
class="content-['project-e/nested/index.html']"
|
|
|
|
|
></div>`,
|
Auto source detection improvements (#14820)
This PR introduces a new `source(…)` argument and improves on the
existing `@source`. The goal of this PR is to make the automatic source
detection configurable, let's dig in.
By default, we will perform automatic source detection starting at the
current working directory. Auto source detection will find plain text
files (no binaries, images, ...) and will ignore git-ignored files.
If you want to start from a different directory, you can use the new
`source(…)` next to the `@import "tailwindcss/utilities"
layer(utilities) source(…)`.
E.g.:
```css
/* ./src/styles/index.css */
@import 'tailwindcss/utilities' layer(utilities) source('../../');
```
Most people won't split their source files, and will just use the simple
`@import "tailwindcss";`, because of this reason, you can use
`source(…)` on the import as well:
E.g.:
```css
/* ./src/styles/index.css */
@import 'tailwindcss' source('../../');
```
Sometimes, you want to rely on auto source detection, but also want to
look in another directory for source files. In this case, yuo can use
the `@source` directive:
```css
/* ./src/index.css */
@import 'tailwindcss';
/* Look for `blade.php` files in `../resources/views` */
@source '../resources/views/**/*.blade.php';
```
However, you don't need to specify the extension, instead you can just
point the directory and all the same automatic source detection rules
will apply.
```css
/* ./src/index.css */
@import 'tailwindcss';
@source '../resources/views';
```
If, for whatever reason, you want to disable the default source
detection feature entirely, and only want to rely on very specific glob
patterns you define, then you can disable it via `source(none)`.
```css
/* Completely disable the default auto source detection */
@import 'tailwindcss' source(none);
/* Only look at .blade.php files, nothing else */
@source "../resources/views/**/*.blade.php";
```
Note: even with `source(none)`, if your `@source` points to a directory,
then auto source detection will still be performed in that directory. If
you don't want that, then you can simply add explicit files in the globs
as seen in the previous example.
```css
/* Completely disable the default auto source detection */
@import 'tailwindcss' source(none);
/* Run auto source detection in `../resources/views` */
@source "../resources/views";
```
---------
Co-authored-by: Jordan Pittman <jordan@cryptica.me>
Co-authored-by: Adam Wathan <4323180+adamwathan@users.noreply.github.com>
2024-10-29 21:33:34 +01:00
|
|
|
},
|
|
|
|
|
},
|
Improve integration tests (stability + performance) (#15125)
This PR improves the integration tests in two ways:
1. Make the integration tests more reliable and thus less flakey
2. Make the integration tests faster (by introducing concurrency)
Tried a lot of different things to make sure that these tests are fast
and stable.
---
The biggest issue we noticed is that some tests are flakey, these are
tests with long running dev-mode processes where watchers are being used
and/or dev servers are created.
To solve this, all the tests that spawn a process look at stdout/stderr
and wait for a message from the process to know whether we can start
making changes.
For example, in case of an Astro project, you get a `watching for file
changes` message. In case of Nuxt project you can wait for an `server
warmed up in` and in case of Next.js there is a `Ready in` message.
These depend on the tools being used, so this is hardcoded per test
instead of a magically automatic solution.
These messages allow us to wait until all the initial necessary work,
internal watchers and/or dev servers are setup before we start making
changes to the files and/or request CSS stylesheets before the server(s)
are ready.
---
Another improvement is how we setup the dev servers. Before, we used to
try and get a free port on the system and use a `--port` flag or a
`PORT` environment variable. Instead of doing this (which is slow), we
rely on the process itself to show a URL with a port. Basically all
tools will try to find a free port if the default port is in use. We can
then use the stdout/stderr messages to get the URL and the port to use.
To reduce the amount of potential conflicts in ports, we used to run
every test and every file sequentially to basically guarantee that ports
are free. With this new approach where we rely on the process, I noticed
that we don't really run into this issue again (I reran the tests
multiple times and they were always stable)
<img width="316" alt="image"
src="https://github.com/user-attachments/assets/b75ddab4-f919-4995-85d0-f212b603e5c2"
/>
Note: these tests run Linux, Windows and macOS in this branch just for
testing purposes. Once this is done, we will only run Linux tests on PRs
and run all 3 of them on the `next` branch.
We do make the tests concurrent by default now, which in theory means
that there could be conflicts (which in practice means that the process
has to do a few more tries to find a free port). To reduce these
conflicts, we split up the integration tests such that Vite, PostCSS,
CLI, … tests all run in a separate job in the GitHub actions workflow.
<img width="312" alt="image"
src="https://github.com/user-attachments/assets/fe9a58a1-98eb-4d9b-8845-a7c8a7af5766"
/>
Comparing this branch against the `next` branch, this is what CI looks
like right now:
| `next` | `feat/improve-integration-tests` |
| --- | --- |
| <img width="594" alt="image"
src="https://github.com/user-attachments/assets/540d21eb-ab03-42e8-9f6f-b3a071fc7635"
/> | <img width="672" alt="image"
src="https://github.com/user-attachments/assets/8ef2e891-08a1-464b-9954-4153174ebce7"
/> |
There also was a point in time where I introduced sequential tests such
that all spawned processes still run after each other, but so far I
didn't run into issues if we keep them concurrent so I dropped that
code.
Some small changes I made to make things more reliable:
1. When relying on stdout/stderr messages, we split lines on `\n` and we
strip all the ANSI escapes which allows us to not worry about special
ANSI characters when finding the URL or a specific message to wait for.
2. Once a test is done, we `child.kill()` the spawned process. If that
doesn't work, for whatever reason, we run a `child.kill('SIGKILL')` to
force kill the process. This could technically lead to some memory or
files not being cleaned up properly, but once CI is done, everything is
thrown away anyway.
3. As you can see in the screenshots, I used some nicer names for the
workflows.
| `next` | `feat/improve-integration-tests` |
| --- | --- |
| <img width="276" alt="image"
src="https://github.com/user-attachments/assets/e574bb53-e21b-4619-9cdb-515431b255b9"
/> | <img width="179" alt="image"
src="https://github.com/user-attachments/assets/8bc75119-fb91-4500-a1d0-bd09f74c93ad"
/> |
They also look a bit nicer in the PR overview as well:
<img width="929" alt="image"
src="https://github.com/user-attachments/assets/04fc71fc-74b0-4e7c-9047-2aada664efef"
/>
The very last commit just filters out Windows and macOS tests again for
PRs (but they are executed on the `next` branch.
---
### Nest steps
I think for now we are in a pretty good state, but there are some things
we can do to further improve everything (mainly make things faster) but
aren't necessary. I also ran into issue while trying it so there is more
work to do.
1. More splits — instead of having a Vite folder and PostCSS folder, we
can go a step further and have folders for Next.js, Astro, Nuxt, Remix,
…
2. Caching — right now we have to run the build step for every OS on
every "job". We can re-use the work here by introducing a setup job that
the other jobs rely on. @thecrypticace and I tried it already, but were
running into some Bun specific Standalone CLI issues when doing that.
3. Remote caching — we could re-enable remote caching such that the
`build` step can be full turbo (e.g.: after a PR is merged in `next` and
we run everything again)
2024-12-12 13:48:56 +01:00
|
|
|
async ({ fs, exec, spawn, root, expect }) => {
|
Auto source detection improvements (#14820)
This PR introduces a new `source(…)` argument and improves on the
existing `@source`. The goal of this PR is to make the automatic source
detection configurable, let's dig in.
By default, we will perform automatic source detection starting at the
current working directory. Auto source detection will find plain text
files (no binaries, images, ...) and will ignore git-ignored files.
If you want to start from a different directory, you can use the new
`source(…)` next to the `@import "tailwindcss/utilities"
layer(utilities) source(…)`.
E.g.:
```css
/* ./src/styles/index.css */
@import 'tailwindcss/utilities' layer(utilities) source('../../');
```
Most people won't split their source files, and will just use the simple
`@import "tailwindcss";`, because of this reason, you can use
`source(…)` on the import as well:
E.g.:
```css
/* ./src/styles/index.css */
@import 'tailwindcss' source('../../');
```
Sometimes, you want to rely on auto source detection, but also want to
look in another directory for source files. In this case, yuo can use
the `@source` directive:
```css
/* ./src/index.css */
@import 'tailwindcss';
/* Look for `blade.php` files in `../resources/views` */
@source '../resources/views/**/*.blade.php';
```
However, you don't need to specify the extension, instead you can just
point the directory and all the same automatic source detection rules
will apply.
```css
/* ./src/index.css */
@import 'tailwindcss';
@source '../resources/views';
```
If, for whatever reason, you want to disable the default source
detection feature entirely, and only want to rely on very specific glob
patterns you define, then you can disable it via `source(none)`.
```css
/* Completely disable the default auto source detection */
@import 'tailwindcss' source(none);
/* Only look at .blade.php files, nothing else */
@source "../resources/views/**/*.blade.php";
```
Note: even with `source(none)`, if your `@source` points to a directory,
then auto source detection will still be performed in that directory. If
you don't want that, then you can simply add explicit files in the globs
as seen in the previous example.
```css
/* Completely disable the default auto source detection */
@import 'tailwindcss' source(none);
/* Run auto source detection in `../resources/views` */
@source "../resources/views";
```
---------
Co-authored-by: Jordan Pittman <jordan@cryptica.me>
Co-authored-by: Adam Wathan <4323180+adamwathan@users.noreply.github.com>
2024-10-29 21:33:34 +01:00
|
|
|
await exec('pnpm tailwindcss --input src/index.css --output dist/out.css', {
|
|
|
|
|
cwd: path.join(root, 'project-a'),
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
expect(await fs.dumpFiles('./project-a/dist/*.css')).toMatchInlineSnapshot(`
|
|
|
|
|
"
|
|
|
|
|
--- ./project-a/dist/out.css ---
|
|
|
|
|
.content-\\[\\'project-a\\/node_modules\\/my-lib-1\\/src\\/index\\.html\\'\\] {
|
|
|
|
|
--tw-content: 'project-a/node modules/my-lib-1/src/index.html';
|
|
|
|
|
content: var(--tw-content);
|
|
|
|
|
}
|
|
|
|
|
.content-\\[\\'project-a\\/node_modules\\/my-lib-2\\/src\\/index\\.html\\'\\] {
|
|
|
|
|
--tw-content: 'project-a/node modules/my-lib-2/src/index.html';
|
|
|
|
|
content: var(--tw-content);
|
|
|
|
|
}
|
|
|
|
|
.content-\\[\\'project-a\\/src\\/logo\\.jpg\\'\\] {
|
|
|
|
|
--tw-content: 'project-a/src/logo.jpg';
|
|
|
|
|
content: var(--tw-content);
|
|
|
|
|
}
|
|
|
|
|
.content-\\[\\'project-b\\/src\\/index\\.html\\'\\] {
|
|
|
|
|
--tw-content: 'project-b/src/index.html';
|
|
|
|
|
content: var(--tw-content);
|
|
|
|
|
}
|
|
|
|
|
.content-\\[\\'project-c\\/src\\/index\\.html\\'\\] {
|
|
|
|
|
--tw-content: 'project-c/src/index.html';
|
|
|
|
|
content: var(--tw-content);
|
|
|
|
|
}
|
|
|
|
|
.content-\\[\\'project-d\\/my-binary-file\\.bin\\'\\] {
|
|
|
|
|
--tw-content: 'project-d/my-binary-file.bin';
|
|
|
|
|
content: var(--tw-content);
|
|
|
|
|
}
|
|
|
|
|
.content-\\[\\'project-d\\/node_modules\\/my-lib-2\\/src\\/index\\.html\\'\\] {
|
|
|
|
|
--tw-content: 'project-d/node modules/my-lib-2/src/index.html';
|
|
|
|
|
content: var(--tw-content);
|
|
|
|
|
}
|
|
|
|
|
.content-\\[\\'project-d\\/src\\/bar\\.html\\'\\] {
|
|
|
|
|
--tw-content: 'project-d/src/bar.html';
|
|
|
|
|
content: var(--tw-content);
|
|
|
|
|
}
|
|
|
|
|
.content-\\[\\'project-d\\/src\\/index\\.html\\'\\] {
|
|
|
|
|
--tw-content: 'project-d/src/index.html';
|
|
|
|
|
content: var(--tw-content);
|
|
|
|
|
}
|
2024-10-30 21:24:48 +01:00
|
|
|
.content-\\[\\'project-e\\/index\\.html\\'\\] {
|
|
|
|
|
--tw-content: 'project-e/index.html';
|
|
|
|
|
content: var(--tw-content);
|
|
|
|
|
}
|
|
|
|
|
.content-\\[\\'project-e\\/nested\\/index\\.html\\'\\] {
|
|
|
|
|
--tw-content: 'project-e/nested/index.html';
|
|
|
|
|
content: var(--tw-content);
|
|
|
|
|
}
|
Auto source detection improvements (#14820)
This PR introduces a new `source(…)` argument and improves on the
existing `@source`. The goal of this PR is to make the automatic source
detection configurable, let's dig in.
By default, we will perform automatic source detection starting at the
current working directory. Auto source detection will find plain text
files (no binaries, images, ...) and will ignore git-ignored files.
If you want to start from a different directory, you can use the new
`source(…)` next to the `@import "tailwindcss/utilities"
layer(utilities) source(…)`.
E.g.:
```css
/* ./src/styles/index.css */
@import 'tailwindcss/utilities' layer(utilities) source('../../');
```
Most people won't split their source files, and will just use the simple
`@import "tailwindcss";`, because of this reason, you can use
`source(…)` on the import as well:
E.g.:
```css
/* ./src/styles/index.css */
@import 'tailwindcss' source('../../');
```
Sometimes, you want to rely on auto source detection, but also want to
look in another directory for source files. In this case, yuo can use
the `@source` directive:
```css
/* ./src/index.css */
@import 'tailwindcss';
/* Look for `blade.php` files in `../resources/views` */
@source '../resources/views/**/*.blade.php';
```
However, you don't need to specify the extension, instead you can just
point the directory and all the same automatic source detection rules
will apply.
```css
/* ./src/index.css */
@import 'tailwindcss';
@source '../resources/views';
```
If, for whatever reason, you want to disable the default source
detection feature entirely, and only want to rely on very specific glob
patterns you define, then you can disable it via `source(none)`.
```css
/* Completely disable the default auto source detection */
@import 'tailwindcss' source(none);
/* Only look at .blade.php files, nothing else */
@source "../resources/views/**/*.blade.php";
```
Note: even with `source(none)`, if your `@source` points to a directory,
then auto source detection will still be performed in that directory. If
you don't want that, then you can simply add explicit files in the globs
as seen in the previous example.
```css
/* Completely disable the default auto source detection */
@import 'tailwindcss' source(none);
/* Run auto source detection in `../resources/views` */
@source "../resources/views";
```
---------
Co-authored-by: Jordan Pittman <jordan@cryptica.me>
Co-authored-by: Adam Wathan <4323180+adamwathan@users.noreply.github.com>
2024-10-29 21:33:34 +01:00
|
|
|
@property --tw-content {
|
|
|
|
|
syntax: "*";
|
|
|
|
|
inherits: false;
|
|
|
|
|
initial-value: "";
|
|
|
|
|
}
|
|
|
|
|
"
|
|
|
|
|
`)
|
|
|
|
|
|
|
|
|
|
// Watch mode tests
|
Improve integration tests (stability + performance) (#15125)
This PR improves the integration tests in two ways:
1. Make the integration tests more reliable and thus less flakey
2. Make the integration tests faster (by introducing concurrency)
Tried a lot of different things to make sure that these tests are fast
and stable.
---
The biggest issue we noticed is that some tests are flakey, these are
tests with long running dev-mode processes where watchers are being used
and/or dev servers are created.
To solve this, all the tests that spawn a process look at stdout/stderr
and wait for a message from the process to know whether we can start
making changes.
For example, in case of an Astro project, you get a `watching for file
changes` message. In case of Nuxt project you can wait for an `server
warmed up in` and in case of Next.js there is a `Ready in` message.
These depend on the tools being used, so this is hardcoded per test
instead of a magically automatic solution.
These messages allow us to wait until all the initial necessary work,
internal watchers and/or dev servers are setup before we start making
changes to the files and/or request CSS stylesheets before the server(s)
are ready.
---
Another improvement is how we setup the dev servers. Before, we used to
try and get a free port on the system and use a `--port` flag or a
`PORT` environment variable. Instead of doing this (which is slow), we
rely on the process itself to show a URL with a port. Basically all
tools will try to find a free port if the default port is in use. We can
then use the stdout/stderr messages to get the URL and the port to use.
To reduce the amount of potential conflicts in ports, we used to run
every test and every file sequentially to basically guarantee that ports
are free. With this new approach where we rely on the process, I noticed
that we don't really run into this issue again (I reran the tests
multiple times and they were always stable)
<img width="316" alt="image"
src="https://github.com/user-attachments/assets/b75ddab4-f919-4995-85d0-f212b603e5c2"
/>
Note: these tests run Linux, Windows and macOS in this branch just for
testing purposes. Once this is done, we will only run Linux tests on PRs
and run all 3 of them on the `next` branch.
We do make the tests concurrent by default now, which in theory means
that there could be conflicts (which in practice means that the process
has to do a few more tries to find a free port). To reduce these
conflicts, we split up the integration tests such that Vite, PostCSS,
CLI, … tests all run in a separate job in the GitHub actions workflow.
<img width="312" alt="image"
src="https://github.com/user-attachments/assets/fe9a58a1-98eb-4d9b-8845-a7c8a7af5766"
/>
Comparing this branch against the `next` branch, this is what CI looks
like right now:
| `next` | `feat/improve-integration-tests` |
| --- | --- |
| <img width="594" alt="image"
src="https://github.com/user-attachments/assets/540d21eb-ab03-42e8-9f6f-b3a071fc7635"
/> | <img width="672" alt="image"
src="https://github.com/user-attachments/assets/8ef2e891-08a1-464b-9954-4153174ebce7"
/> |
There also was a point in time where I introduced sequential tests such
that all spawned processes still run after each other, but so far I
didn't run into issues if we keep them concurrent so I dropped that
code.
Some small changes I made to make things more reliable:
1. When relying on stdout/stderr messages, we split lines on `\n` and we
strip all the ANSI escapes which allows us to not worry about special
ANSI characters when finding the URL or a specific message to wait for.
2. Once a test is done, we `child.kill()` the spawned process. If that
doesn't work, for whatever reason, we run a `child.kill('SIGKILL')` to
force kill the process. This could technically lead to some memory or
files not being cleaned up properly, but once CI is done, everything is
thrown away anyway.
3. As you can see in the screenshots, I used some nicer names for the
workflows.
| `next` | `feat/improve-integration-tests` |
| --- | --- |
| <img width="276" alt="image"
src="https://github.com/user-attachments/assets/e574bb53-e21b-4619-9cdb-515431b255b9"
/> | <img width="179" alt="image"
src="https://github.com/user-attachments/assets/8bc75119-fb91-4500-a1d0-bd09f74c93ad"
/> |
They also look a bit nicer in the PR overview as well:
<img width="929" alt="image"
src="https://github.com/user-attachments/assets/04fc71fc-74b0-4e7c-9047-2aada664efef"
/>
The very last commit just filters out Windows and macOS tests again for
PRs (but they are executed on the `next` branch.
---
### Nest steps
I think for now we are in a pretty good state, but there are some things
we can do to further improve everything (mainly make things faster) but
aren't necessary. I also ran into issue while trying it so there is more
work to do.
1. More splits — instead of having a Vite folder and PostCSS folder, we
can go a step further and have folders for Next.js, Astro, Nuxt, Remix,
…
2. Caching — right now we have to run the build step for every OS on
every "job". We can re-use the work here by introducing a setup job that
the other jobs rely on. @thecrypticace and I tried it already, but were
running into some Bun specific Standalone CLI issues when doing that.
3. Remote caching — we could re-enable remote caching such that the
`build` step can be full turbo (e.g.: after a PR is merged in `next` and
we run everything again)
2024-12-12 13:48:56 +01:00
|
|
|
let process = await spawn(
|
|
|
|
|
'pnpm tailwindcss --input src/index.css --output dist/out.css --watch',
|
|
|
|
|
{
|
|
|
|
|
cwd: path.join(root, 'project-a'),
|
|
|
|
|
},
|
|
|
|
|
)
|
|
|
|
|
await process.onStderr((m) => m.includes('Done in'))
|
Auto source detection improvements (#14820)
This PR introduces a new `source(…)` argument and improves on the
existing `@source`. The goal of this PR is to make the automatic source
detection configurable, let's dig in.
By default, we will perform automatic source detection starting at the
current working directory. Auto source detection will find plain text
files (no binaries, images, ...) and will ignore git-ignored files.
If you want to start from a different directory, you can use the new
`source(…)` next to the `@import "tailwindcss/utilities"
layer(utilities) source(…)`.
E.g.:
```css
/* ./src/styles/index.css */
@import 'tailwindcss/utilities' layer(utilities) source('../../');
```
Most people won't split their source files, and will just use the simple
`@import "tailwindcss";`, because of this reason, you can use
`source(…)` on the import as well:
E.g.:
```css
/* ./src/styles/index.css */
@import 'tailwindcss' source('../../');
```
Sometimes, you want to rely on auto source detection, but also want to
look in another directory for source files. In this case, yuo can use
the `@source` directive:
```css
/* ./src/index.css */
@import 'tailwindcss';
/* Look for `blade.php` files in `../resources/views` */
@source '../resources/views/**/*.blade.php';
```
However, you don't need to specify the extension, instead you can just
point the directory and all the same automatic source detection rules
will apply.
```css
/* ./src/index.css */
@import 'tailwindcss';
@source '../resources/views';
```
If, for whatever reason, you want to disable the default source
detection feature entirely, and only want to rely on very specific glob
patterns you define, then you can disable it via `source(none)`.
```css
/* Completely disable the default auto source detection */
@import 'tailwindcss' source(none);
/* Only look at .blade.php files, nothing else */
@source "../resources/views/**/*.blade.php";
```
Note: even with `source(none)`, if your `@source` points to a directory,
then auto source detection will still be performed in that directory. If
you don't want that, then you can simply add explicit files in the globs
as seen in the previous example.
```css
/* Completely disable the default auto source detection */
@import 'tailwindcss' source(none);
/* Run auto source detection in `../resources/views` */
@source "../resources/views";
```
---------
Co-authored-by: Jordan Pittman <jordan@cryptica.me>
Co-authored-by: Adam Wathan <4323180+adamwathan@users.noreply.github.com>
2024-10-29 21:33:34 +01:00
|
|
|
|
|
|
|
|
// Changes to project-a should not be included in the output, we changed the
|
|
|
|
|
// base folder to project-b.
|
|
|
|
|
await fs.write(
|
|
|
|
|
'project-a/src/index.html',
|
|
|
|
|
html`<div class="[.changed_&]:content-['project-a/src/index.html']"></div>`,
|
|
|
|
|
)
|
|
|
|
|
await fs.expectFileNotToContain('./project-a/dist/out.css', [
|
|
|
|
|
candidate`[.changed_&]:content-['project-a/src/index.html']`,
|
|
|
|
|
])
|
|
|
|
|
|
|
|
|
|
// Changes to this file should be included, because we explicitly listed
|
|
|
|
|
// them using `@source`.
|
|
|
|
|
await fs.write(
|
|
|
|
|
'project-a/src/logo.jpg',
|
|
|
|
|
html`<div class="[.changed_&]:content-['project-a/src/logo.jpg']"></div>`,
|
|
|
|
|
)
|
|
|
|
|
await fs.expectFileToContain('./project-a/dist/out.css', [
|
|
|
|
|
candidate`[.changed_&]:content-['project-a/src/logo.jpg']`,
|
|
|
|
|
])
|
|
|
|
|
|
|
|
|
|
// Changes to these files should be included, because we explicitly listed
|
|
|
|
|
// them using `@source`.
|
|
|
|
|
await fs.write(
|
|
|
|
|
'project-a/node_modules/my-lib-1/src/index.html',
|
|
|
|
|
html`<div
|
|
|
|
|
class="[.changed_&]:content-['project-a/node_modules/my-lib-1/src/index.html']"
|
|
|
|
|
></div>`,
|
|
|
|
|
)
|
|
|
|
|
await fs.expectFileToContain('./project-a/dist/out.css', [
|
|
|
|
|
candidate`[.changed_&]:content-['project-a/node_modules/my-lib-1/src/index.html']`,
|
|
|
|
|
])
|
|
|
|
|
await fs.write(
|
|
|
|
|
'project-a/node_modules/my-lib-2/src/index.html',
|
|
|
|
|
html`<div
|
|
|
|
|
class="[.changed_&]:content-['project-a/node_modules/my-lib-2/src/index.html']"
|
|
|
|
|
></div>`,
|
|
|
|
|
)
|
|
|
|
|
await fs.expectFileToContain('./project-a/dist/out.css', [
|
|
|
|
|
candidate`[.changed_&]:content-['project-a/node_modules/my-lib-2/src/index.html']`,
|
|
|
|
|
])
|
|
|
|
|
|
|
|
|
|
// Changes to this file should be included, because we changed the base to
|
|
|
|
|
// `project-b`.
|
|
|
|
|
await fs.write(
|
|
|
|
|
'project-b/src/index.html',
|
|
|
|
|
html`<div class="[.changed_&]:content-['project-b/src/index.html']"></div>`,
|
|
|
|
|
)
|
|
|
|
|
await fs.expectFileToContain('./project-a/dist/out.css', [
|
|
|
|
|
candidate`[.changed_&]:content-['project-b/src/index.html']`,
|
|
|
|
|
])
|
|
|
|
|
|
|
|
|
|
// Changes to this file should not be included. We did change the base to
|
|
|
|
|
// `project-b`, but we still apply the auto source detection rules which
|
|
|
|
|
// ignore `node_modules`.
|
|
|
|
|
await fs.write(
|
|
|
|
|
'project-b/node_modules/my-lib-3/src/index.html',
|
|
|
|
|
html`<div
|
|
|
|
|
class="[.changed_&]:content-['project-b/node_modules/my-lib-3/src/index.html']"
|
|
|
|
|
></div>`,
|
|
|
|
|
)
|
|
|
|
|
await fs.expectFileNotToContain('./project-a/dist/out.css', [
|
|
|
|
|
candidate`[.changed_&]:content-['project-b/node_modules/my-lib-3/src/index.html']`,
|
|
|
|
|
])
|
|
|
|
|
|
|
|
|
|
// Project C was added explicitly via `@source`, therefore changes to these
|
|
|
|
|
// files should be included.
|
|
|
|
|
await fs.write(
|
|
|
|
|
'project-c/src/index.html',
|
|
|
|
|
html`<div class="[.changed_&]:content-['project-c/src/index.html']"></div>`,
|
|
|
|
|
)
|
|
|
|
|
await fs.expectFileToContain('./project-a/dist/out.css', [
|
|
|
|
|
candidate`[.changed_&]:content-['project-c/src/index.html']`,
|
|
|
|
|
])
|
|
|
|
|
|
|
|
|
|
// Except for these files, since they are ignored by the default auto source
|
|
|
|
|
// detection rules.
|
|
|
|
|
await fs.write(
|
|
|
|
|
'project-c/src/logo.jpg',
|
|
|
|
|
html`<div class="[.changed_&]:content-['project-c/src/logo.jpg']"></div>`,
|
|
|
|
|
)
|
|
|
|
|
await fs.expectFileNotToContain('./project-a/dist/out.css', [
|
|
|
|
|
candidate`[.changed_&]:content-['project-c/src/logo.jpg']`,
|
|
|
|
|
])
|
|
|
|
|
await fs.write(
|
|
|
|
|
'project-c/node_modules/my-lib-1/src/index.html',
|
|
|
|
|
html`<div
|
|
|
|
|
class="[.changed_&]:content-['project-c/node_modules/my-lib-1/src/index.html']"
|
|
|
|
|
></div>`,
|
|
|
|
|
)
|
|
|
|
|
await fs.expectFileNotToContain('./project-a/dist/out.css', [
|
|
|
|
|
candidate`[.changed_&]:content-['project-c/node_modules/my-lib-1/src/index.html']`,
|
|
|
|
|
])
|
|
|
|
|
|
|
|
|
|
// Creating new files in the "root" of auto source detected folders
|
|
|
|
|
await fs.write(
|
|
|
|
|
'project-b/new-file.html',
|
|
|
|
|
html`<div class="[.created_&]:content-['project-b/new-file.html']"></div>`,
|
|
|
|
|
)
|
|
|
|
|
await fs.write(
|
|
|
|
|
'project-b/new-folder/new-file.html',
|
|
|
|
|
html`<div class="[.created_&]:content-['project-b/new-folder/new-file.html']"></div>`,
|
|
|
|
|
)
|
|
|
|
|
await fs.write(
|
|
|
|
|
'project-c/new-file.html',
|
|
|
|
|
html`<div class="[.created_&]:content-['project-c/new-file.html']"></div>`,
|
|
|
|
|
)
|
|
|
|
|
await fs.write(
|
|
|
|
|
'project-c/new-folder/new-file.html',
|
|
|
|
|
html`<div class="[.created_&]:content-['project-c/new-folder/new-file.html']"></div>`,
|
|
|
|
|
)
|
|
|
|
|
await fs.expectFileToContain('./project-a/dist/out.css', [
|
|
|
|
|
candidate`[.created_&]:content-['project-b/new-file.html']`,
|
|
|
|
|
candidate`[.created_&]:content-['project-b/new-folder/new-file.html']`,
|
|
|
|
|
candidate`[.created_&]:content-['project-c/new-file.html']`,
|
|
|
|
|
candidate`[.created_&]:content-['project-c/new-folder/new-file.html']`,
|
|
|
|
|
])
|
|
|
|
|
},
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
test(
|
|
|
|
|
'auto source detection disabled',
|
|
|
|
|
{
|
|
|
|
|
fs: {
|
|
|
|
|
'package.json': json`
|
|
|
|
|
{
|
|
|
|
|
"dependencies": {
|
|
|
|
|
"tailwindcss": "workspace:^",
|
|
|
|
|
"@tailwindcss/cli": "workspace:^"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
`,
|
|
|
|
|
'index.css': css`
|
|
|
|
|
@import 'tailwindcss/theme' theme(reference);
|
|
|
|
|
|
|
|
|
|
/* (1) */
|
|
|
|
|
/* - Only './src' should be auto-scanned, not the current working directory */
|
|
|
|
|
/* - .gitignore'd paths should be ignored (node_modules) */
|
|
|
|
|
/* - Binary extensions should be ignored (jpg, zip) */
|
|
|
|
|
@import 'tailwindcss/utilities' source(none);
|
|
|
|
|
|
|
|
|
|
/* (2) */
|
|
|
|
|
/* - './pages' should be auto-scanned */
|
|
|
|
|
/* - Only '.html' files should be included */
|
|
|
|
|
/* - './page/ignored.html' should be ignored */
|
|
|
|
|
@source "./pages/**/*.html";
|
|
|
|
|
`,
|
|
|
|
|
|
|
|
|
|
'.gitignore': dedent`
|
|
|
|
|
/src/ignored
|
|
|
|
|
/pages/ignored.html
|
|
|
|
|
`,
|
|
|
|
|
|
|
|
|
|
// (1)
|
|
|
|
|
'index.html': 'content-["index.html"] content-["BAD"]', // "Root" source is in `./src`
|
|
|
|
|
'src/index.html': 'content-["src/index.html"] content-["BAD"]',
|
|
|
|
|
'src/nested/index.html': 'content-["src/nested/index.html"] content-["BAD"]',
|
|
|
|
|
'src/index.jpg': 'content-["src/index.jpg"] content-["BAD"]',
|
|
|
|
|
'src/nested/index.tar': 'content-["src/nested/index.tar"] content-["BAD"]',
|
|
|
|
|
'src/ignored/index.html': 'content-["src/ignored/index.html"] content-["BAD"]',
|
|
|
|
|
|
|
|
|
|
// (4)
|
|
|
|
|
'pages/foo.html': 'content-["pages/foo.html"]',
|
|
|
|
|
'pages/nested/foo.html': 'content-["pages/nested/foo.html"]',
|
|
|
|
|
'pages/ignored.html': 'content-["pages/ignored.html"] content-["BAD"]',
|
|
|
|
|
'pages/foo.jsx': 'content-["pages/foo.jsx"] content-["BAD"]',
|
|
|
|
|
'pages/nested/foo.jsx': 'content-["pages/nested/foo.jsx"] content-["BAD"]',
|
|
|
|
|
},
|
|
|
|
|
},
|
Improve integration tests (stability + performance) (#15125)
This PR improves the integration tests in two ways:
1. Make the integration tests more reliable and thus less flakey
2. Make the integration tests faster (by introducing concurrency)
Tried a lot of different things to make sure that these tests are fast
and stable.
---
The biggest issue we noticed is that some tests are flakey, these are
tests with long running dev-mode processes where watchers are being used
and/or dev servers are created.
To solve this, all the tests that spawn a process look at stdout/stderr
and wait for a message from the process to know whether we can start
making changes.
For example, in case of an Astro project, you get a `watching for file
changes` message. In case of Nuxt project you can wait for an `server
warmed up in` and in case of Next.js there is a `Ready in` message.
These depend on the tools being used, so this is hardcoded per test
instead of a magically automatic solution.
These messages allow us to wait until all the initial necessary work,
internal watchers and/or dev servers are setup before we start making
changes to the files and/or request CSS stylesheets before the server(s)
are ready.
---
Another improvement is how we setup the dev servers. Before, we used to
try and get a free port on the system and use a `--port` flag or a
`PORT` environment variable. Instead of doing this (which is slow), we
rely on the process itself to show a URL with a port. Basically all
tools will try to find a free port if the default port is in use. We can
then use the stdout/stderr messages to get the URL and the port to use.
To reduce the amount of potential conflicts in ports, we used to run
every test and every file sequentially to basically guarantee that ports
are free. With this new approach where we rely on the process, I noticed
that we don't really run into this issue again (I reran the tests
multiple times and they were always stable)
<img width="316" alt="image"
src="https://github.com/user-attachments/assets/b75ddab4-f919-4995-85d0-f212b603e5c2"
/>
Note: these tests run Linux, Windows and macOS in this branch just for
testing purposes. Once this is done, we will only run Linux tests on PRs
and run all 3 of them on the `next` branch.
We do make the tests concurrent by default now, which in theory means
that there could be conflicts (which in practice means that the process
has to do a few more tries to find a free port). To reduce these
conflicts, we split up the integration tests such that Vite, PostCSS,
CLI, … tests all run in a separate job in the GitHub actions workflow.
<img width="312" alt="image"
src="https://github.com/user-attachments/assets/fe9a58a1-98eb-4d9b-8845-a7c8a7af5766"
/>
Comparing this branch against the `next` branch, this is what CI looks
like right now:
| `next` | `feat/improve-integration-tests` |
| --- | --- |
| <img width="594" alt="image"
src="https://github.com/user-attachments/assets/540d21eb-ab03-42e8-9f6f-b3a071fc7635"
/> | <img width="672" alt="image"
src="https://github.com/user-attachments/assets/8ef2e891-08a1-464b-9954-4153174ebce7"
/> |
There also was a point in time where I introduced sequential tests such
that all spawned processes still run after each other, but so far I
didn't run into issues if we keep them concurrent so I dropped that
code.
Some small changes I made to make things more reliable:
1. When relying on stdout/stderr messages, we split lines on `\n` and we
strip all the ANSI escapes which allows us to not worry about special
ANSI characters when finding the URL or a specific message to wait for.
2. Once a test is done, we `child.kill()` the spawned process. If that
doesn't work, for whatever reason, we run a `child.kill('SIGKILL')` to
force kill the process. This could technically lead to some memory or
files not being cleaned up properly, but once CI is done, everything is
thrown away anyway.
3. As you can see in the screenshots, I used some nicer names for the
workflows.
| `next` | `feat/improve-integration-tests` |
| --- | --- |
| <img width="276" alt="image"
src="https://github.com/user-attachments/assets/e574bb53-e21b-4619-9cdb-515431b255b9"
/> | <img width="179" alt="image"
src="https://github.com/user-attachments/assets/8bc75119-fb91-4500-a1d0-bd09f74c93ad"
/> |
They also look a bit nicer in the PR overview as well:
<img width="929" alt="image"
src="https://github.com/user-attachments/assets/04fc71fc-74b0-4e7c-9047-2aada664efef"
/>
The very last commit just filters out Windows and macOS tests again for
PRs (but they are executed on the `next` branch.
---
### Nest steps
I think for now we are in a pretty good state, but there are some things
we can do to further improve everything (mainly make things faster) but
aren't necessary. I also ran into issue while trying it so there is more
work to do.
1. More splits — instead of having a Vite folder and PostCSS folder, we
can go a step further and have folders for Next.js, Astro, Nuxt, Remix,
…
2. Caching — right now we have to run the build step for every OS on
every "job". We can re-use the work here by introducing a setup job that
the other jobs rely on. @thecrypticace and I tried it already, but were
running into some Bun specific Standalone CLI issues when doing that.
3. Remote caching — we could re-enable remote caching such that the
`build` step can be full turbo (e.g.: after a PR is merged in `next` and
we run everything again)
2024-12-12 13:48:56 +01:00
|
|
|
async ({ fs, exec, expect }) => {
|
Auto source detection improvements (#14820)
This PR introduces a new `source(…)` argument and improves on the
existing `@source`. The goal of this PR is to make the automatic source
detection configurable, let's dig in.
By default, we will perform automatic source detection starting at the
current working directory. Auto source detection will find plain text
files (no binaries, images, ...) and will ignore git-ignored files.
If you want to start from a different directory, you can use the new
`source(…)` next to the `@import "tailwindcss/utilities"
layer(utilities) source(…)`.
E.g.:
```css
/* ./src/styles/index.css */
@import 'tailwindcss/utilities' layer(utilities) source('../../');
```
Most people won't split their source files, and will just use the simple
`@import "tailwindcss";`, because of this reason, you can use
`source(…)` on the import as well:
E.g.:
```css
/* ./src/styles/index.css */
@import 'tailwindcss' source('../../');
```
Sometimes, you want to rely on auto source detection, but also want to
look in another directory for source files. In this case, yuo can use
the `@source` directive:
```css
/* ./src/index.css */
@import 'tailwindcss';
/* Look for `blade.php` files in `../resources/views` */
@source '../resources/views/**/*.blade.php';
```
However, you don't need to specify the extension, instead you can just
point the directory and all the same automatic source detection rules
will apply.
```css
/* ./src/index.css */
@import 'tailwindcss';
@source '../resources/views';
```
If, for whatever reason, you want to disable the default source
detection feature entirely, and only want to rely on very specific glob
patterns you define, then you can disable it via `source(none)`.
```css
/* Completely disable the default auto source detection */
@import 'tailwindcss' source(none);
/* Only look at .blade.php files, nothing else */
@source "../resources/views/**/*.blade.php";
```
Note: even with `source(none)`, if your `@source` points to a directory,
then auto source detection will still be performed in that directory. If
you don't want that, then you can simply add explicit files in the globs
as seen in the previous example.
```css
/* Completely disable the default auto source detection */
@import 'tailwindcss' source(none);
/* Run auto source detection in `../resources/views` */
@source "../resources/views";
```
---------
Co-authored-by: Jordan Pittman <jordan@cryptica.me>
Co-authored-by: Adam Wathan <4323180+adamwathan@users.noreply.github.com>
2024-10-29 21:33:34 +01:00
|
|
|
await exec('pnpm tailwindcss --input index.css --output dist/out.css')
|
|
|
|
|
|
|
|
|
|
expect(await fs.dumpFiles('./dist/*.css')).toMatchInlineSnapshot(`
|
|
|
|
|
"
|
|
|
|
|
--- ./dist/out.css ---
|
|
|
|
|
.content-\\[\\"pages\\/foo\\.html\\"\\] {
|
|
|
|
|
--tw-content: "pages/foo.html";
|
|
|
|
|
content: var(--tw-content);
|
|
|
|
|
}
|
|
|
|
|
.content-\\[\\"pages\\/nested\\/foo\\.html\\"\\] {
|
|
|
|
|
--tw-content: "pages/nested/foo.html";
|
|
|
|
|
content: var(--tw-content);
|
|
|
|
|
}
|
|
|
|
|
@property --tw-content {
|
|
|
|
|
syntax: "*";
|
|
|
|
|
inherits: false;
|
|
|
|
|
initial-value: "";
|
|
|
|
|
}
|
|
|
|
|
"
|
|
|
|
|
`)
|
|
|
|
|
},
|
|
|
|
|
)
|
Do not emit `@keyframes` in `@theme reference` (#16120)
This PR fixes na issue where `@keyframes` were emitted if they wre in a
`@theme
reference` and anothe `@theme {}` (that is not a reference) was present.
E.g.:
```css
@reference "tailwindcss";
@theme {
/* ... */
}
```
Produces:
```css
:root, :host {
}
@keyframes spin {
to {
transform: rotate(360deg);
}
}
@keyframes ping {
75%, 100% {
transform: scale(2);
opacity: 0;
}
}
@keyframes pulse {
50% {
opacity: 0.5;
}
}
@keyframes bounce {
0%, 100% {
transform: translateY(-25%);
animation-timing-function: cubic-bezier(0.8, 0, 1, 1);
}
50% {
transform: none;
animation-timing-function: cubic-bezier(0, 0, 0.2, 1);
}
}
```
With this PR, the produced CSS looks like this instead:
```css
:root, :host {
}
```
Note: the empty `:root, :host` will be solved in a subsequent PR.
### Test plan
Added some unit tests, and a dedicated integration test.
2025-01-31 15:13:17 +01:00
|
|
|
|
|
|
|
|
test(
|
|
|
|
|
'@theme reference should never emit values',
|
|
|
|
|
{
|
|
|
|
|
fs: {
|
|
|
|
|
'package.json': json`
|
|
|
|
|
{
|
|
|
|
|
"dependencies": {
|
|
|
|
|
"tailwindcss": "workspace:^",
|
|
|
|
|
"@tailwindcss/cli": "workspace:^"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
`,
|
|
|
|
|
'src/index.css': css`
|
|
|
|
|
@reference "tailwindcss";
|
|
|
|
|
|
|
|
|
|
.keep-me {
|
|
|
|
|
color: red;
|
|
|
|
|
}
|
|
|
|
|
`,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
async ({ fs, spawn, expect }) => {
|
|
|
|
|
let process = await spawn(
|
|
|
|
|
`pnpm tailwindcss --input src/index.css --output dist/out.css --watch`,
|
|
|
|
|
)
|
|
|
|
|
await process.onStderr((m) => m.includes('Done in'))
|
|
|
|
|
|
|
|
|
|
expect(await fs.dumpFiles('./dist/*.css')).toMatchInlineSnapshot(`
|
|
|
|
|
"
|
|
|
|
|
--- ./dist/out.css ---
|
|
|
|
|
.keep-me {
|
|
|
|
|
color: red;
|
|
|
|
|
}
|
|
|
|
|
"
|
|
|
|
|
`)
|
|
|
|
|
|
|
|
|
|
await fs.write(
|
|
|
|
|
'./src/index.css',
|
|
|
|
|
css`
|
|
|
|
|
@reference "tailwindcss";
|
|
|
|
|
|
|
|
|
|
/* Not a reference! */
|
|
|
|
|
@theme {
|
|
|
|
|
--color-pink: pink;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.keep-me {
|
|
|
|
|
color: red;
|
|
|
|
|
}
|
|
|
|
|
`,
|
|
|
|
|
)
|
|
|
|
|
expect(await fs.dumpFiles('./dist/*.css')).toMatchInlineSnapshot(`
|
|
|
|
|
"
|
|
|
|
|
--- ./dist/out.css ---
|
|
|
|
|
.keep-me {
|
|
|
|
|
color: red;
|
|
|
|
|
}
|
|
|
|
|
"
|
|
|
|
|
`)
|
|
|
|
|
},
|
|
|
|
|
)
|