Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add @content support to @tailwindcss/cli #14067

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
ee2d8e5
setup CLI tests
RobinMalfait Jul 29, 2024
d2013e2
collect `globs`, and pass them to `scanDir`
RobinMalfait Jul 29, 2024
2e9c9b2
add disposables
RobinMalfait Jul 26, 2024
1b6afb7
remove destructuring
RobinMalfait Jul 26, 2024
5dce494
ensure we are working with the new input and compiler
RobinMalfait Jul 26, 2024
949c0db
create watchers for each glob's base
RobinMalfait Jul 26, 2024
13767d6
attach `scanFiles` directly on the scan dir result
RobinMalfait Jul 26, 2024
496eb4b
bail when no new candidates are found
RobinMalfait Jul 26, 2024
8b05128
dedupe events
RobinMalfait Jul 26, 2024
52b575a
check for cssImportPaths first
RobinMalfait Jul 26, 2024
6fd6bd6
use a macrotask instead of microtask
RobinMalfait Jul 26, 2024
21b39e8
revert unnecessary change
RobinMalfait Jul 29, 2024
5a27fda
Rename `flush` to `enqueueFlush`
RobinMalfait Jul 29, 2024
5e13276
setup watchers before the initial build
RobinMalfait Jul 29, 2024
f5fa220
improve fast-path check
RobinMalfait Jul 29, 2024
d2e5c2f
keep glob as-is
RobinMalfait Jul 29, 2024
0981753
add comments for `createWatchers`
RobinMalfait Jul 29, 2024
903341d
use returned object from `compile` directly
RobinMalfait Jul 30, 2024
e8b7b3d
`contentPaths` accept a `Vec<GlobEntry>`
RobinMalfait Jul 30, 2024
002cb77
rename `inputFilePath` to `inputBasePath`
RobinMalfait Jul 30, 2024
6654f6b
Migrate CLI test to the new integration test setup
philipp-spiess Aug 2, 2024
b4c5980
fix pnpm-lock.yaml file
RobinMalfait Aug 2, 2024
72b4a69
Add test for cli watch mode
philipp-spiess Aug 2, 2024
8f3868a
remove console.log
RobinMalfait Aug 2, 2024
193f748
remove `--force` flag
RobinMalfait Aug 2, 2024
422cce5
setup watchers for all directories
RobinMalfait Aug 2, 2024
314d377
use a full `scanDir()` build in watch mode
RobinMalfait Aug 2, 2024
432207b
use `watchDirectories` abstraction to calculate all directories we want
RobinMalfait Aug 2, 2024
cb39bd2
improve test naming and setup
RobinMalfait Aug 2, 2024
0511192
add step where we change file outside of current pwd
RobinMalfait Aug 2, 2024
87d17e8
output stdout/stderr in CI
RobinMalfait Aug 2, 2024
3e91cb2
collect stdout and stderr, only print output when tests fail
RobinMalfait Aug 2, 2024
8558f6e
tmp
RobinMalfait Aug 2, 2024
fa3f288
add debug logs
RobinMalfait Aug 2, 2024
643cedd
Write a file in the right repo
philipp-spiess Aug 2, 2024
898846d
Revert "tmp"
RobinMalfait Aug 2, 2024
05fcd4c
Revert "add debug logs"
RobinMalfait Aug 2, 2024
9559a98
add `waitForOutputFileChange`
RobinMalfait Aug 2, 2024
9354db7
accept return value from inner callback
RobinMalfait Aug 2, 2024
0faba68
wait for disk file change on initial spawn
RobinMalfait Aug 2, 2024
c824b54
Introduce fs.expectFileToContain helper
philipp-spiess Aug 5, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
142 changes: 142 additions & 0 deletions integrations/cli/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
import path from 'node:path'
import { candidate, css, html, js, json, test, yaml } from '../utils'

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
class="underline 2xl:font-bold hocus:underline inverted:flex"
></div>
`,
'project-a/plugin.js': js`
module.exports = function ({ addVariant }) {
addVariant('inverted', '@media (inverted-colors: inverted)')
addVariant('hocus', ['&:focus', '&:hover'])
}
`,
'project-a/src/index.css': css`
@import 'tailwindcss/utilities';
@content '../../project-b/src/**/*.js';
@plugin '../plugin.js';
`,
'project-a/src/index.js': js`
const className = "content-['a/src/index.js']"
module.exports = { className }
`,
'project-b/src/index.js': js`
const className = "content-['b/src/index.js']"
module.exports = { className }
`,
},
},
async ({ root, fs, exec }) => {
await exec('pnpm tailwindcss --input src/index.css --output dist/out.css', {
cwd: path.join(root, 'project-a'),
})

await fs.expectFileToContain('project-a/dist/out.css', [
candidate`underline`,
candidate`content-['a/src/index.js']`,
candidate`content-['b/src/index.js']`,
candidate`inverted:flex`,
candidate`hocus:underline`,
])
},
)

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:^"
}
}
`,
'project-a/index.html': html`
<div
class="underline 2xl:font-bold hocus:underline inverted:flex"
></div>
`,
'project-a/plugin.js': js`
module.exports = function ({ addVariant }) {
addVariant('inverted', '@media (inverted-colors: inverted)')
addVariant('hocus', ['&:focus', '&:hover'])
}
`,
'project-a/src/index.css': css`
@import 'tailwindcss/utilities';
@content '../../project-b/src/**/*.js';
@plugin '../plugin.js';
`,
'project-a/src/index.js': js`
const className = "content-['a/src/index.js']"
module.exports = { className }
`,
'project-b/src/index.js': js`
const className = "content-['b/src/index.js']"
module.exports = { className }
`,
},
},
async ({ root, fs, spawn }) => {
await spawn('pnpm tailwindcss --input src/index.css --output dist/out.css --watch', {
cwd: path.join(root, 'project-a'),
})

await fs.expectFileToContain('project-a/dist/out.css', [
candidate`underline`,
candidate`content-['a/src/index.js']`,
candidate`content-['b/src/index.js']`,
candidate`inverted:flex`,
candidate`hocus:underline`,
])

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']`,
])

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']`,
])
},
)
Loading
Loading