|
1 | 1 | import os from 'node:os'
|
2 | 2 | import path from 'node:path'
|
3 |
| -import { describe } from 'vitest' |
| 3 | +import { describe, expect } from 'vitest' |
4 | 4 | import { candidate, css, html, js, json, test, yaml } from '../utils'
|
5 | 5 |
|
6 | 6 | const STANDALONE_BINARY = (() => {
|
@@ -255,3 +255,110 @@ describe.each([
|
255 | 255 | },
|
256 | 256 | )
|
257 | 257 | })
|
| 258 | + |
| 259 | +describe.only('@source', () => { |
| 260 | + test( |
| 261 | + 'it works', |
| 262 | + { |
| 263 | + fs: { |
| 264 | + 'package.json': json`{}`, |
| 265 | + 'pnpm-workspace.yaml': yaml` |
| 266 | + # |
| 267 | + packages: |
| 268 | + - project-a |
| 269 | + `, |
| 270 | + 'project-a/package.json': json` |
| 271 | + { |
| 272 | + "dependencies": { |
| 273 | + "tailwindcss": "workspace:^", |
| 274 | + "@tailwindcss/cli": "workspace:^" |
| 275 | + } |
| 276 | + } |
| 277 | + `, |
| 278 | + 'project-a/src/index.css': css` |
| 279 | + @import 'tailwindcss/theme' theme(reference); |
| 280 | +
|
| 281 | + /* Run auto-content detection in ../../project-b */ |
| 282 | + @import 'tailwindcss/utilities' source('../../project-b'); |
| 283 | +
|
| 284 | + /* Additive: */ |
| 285 | + /* {my-lib-1,my-lib-2}: expand */ |
| 286 | + /* *.html: only look for .html */ |
| 287 | + @source '../node_modules/{my-lib-1,my-lib-2}/src/**/*.html'; |
| 288 | + @source './logo.{jpg,png}'; /* Don't worry about it */ |
| 289 | + `, |
| 290 | + 'project-a/src/index.html': html` |
| 291 | + <div |
| 292 | + class="content-['SHOULD-NOT-EXIST-IN-OUTPUT'] content-['project-a/src/index.html']" |
| 293 | + ></div> |
| 294 | + `, |
| 295 | + 'project-a/src/logo.jpg': html` |
| 296 | + <div |
| 297 | + class="content-['project-a/src/logo.jpg']" |
| 298 | + ></div> |
| 299 | + `, |
| 300 | + 'project-a/node_modules/my-lib-1/src/index.html': html` |
| 301 | + <div |
| 302 | + class="content-['project-a/node_modules/my-lib-1/src/index.html']" |
| 303 | + ></div> |
| 304 | + `, |
| 305 | + 'project-a/node_modules/my-lib-2/src/index.html': html` |
| 306 | + <div |
| 307 | + class="content-['project-a/node_modules/my-lib-2/src/index.html']" |
| 308 | + ></div> |
| 309 | + `, |
| 310 | + 'project-b/src/index.html': html` |
| 311 | + <div |
| 312 | + class="content-['project-b/src/index.html']" |
| 313 | + ></div> |
| 314 | + `, |
| 315 | + 'project-b/node_modules/my-lib-3/src/index.html': html` |
| 316 | + <div |
| 317 | + class="content-['SHOULD-NOT-EXIST-IN-OUTPUT'] content-['project-b/node_modules/my-lib-3/src/index.html']" |
| 318 | + ></div> |
| 319 | + `, |
| 320 | + }, |
| 321 | + }, |
| 322 | + async ({ fs, exec, root }) => { |
| 323 | + await exec('pnpm tailwindcss --input src/index.css --output dist/out.css', { |
| 324 | + cwd: path.join(root, 'project-a'), |
| 325 | + }) |
| 326 | + |
| 327 | + expect(await fs.dumpFiles('./project-a/dist/*.css')).toMatchInlineSnapshot(` |
| 328 | + " |
| 329 | + --- ./project-a/dist/out.css --- |
| 330 | + @tailwind utilities source('../../project-b') { |
| 331 | + .content-\\[\\'project-a\\/node_modules\\/my-lib-1\\/src\\/index\\.html\\'\\] { |
| 332 | + --tw-content: 'project-a/node modules/my-lib-1/src/index.html'; |
| 333 | + content: var(--tw-content); |
| 334 | + } |
| 335 | + .content-\\[\\'project-a\\/node_modules\\/my-lib-2\\/src\\/index\\.html\\'\\] { |
| 336 | + --tw-content: 'project-a/node modules/my-lib-2/src/index.html'; |
| 337 | + content: var(--tw-content); |
| 338 | + } |
| 339 | + .content-\\[\\'project-a\\/src\\/logo\\.jpg\\'\\] { |
| 340 | + --tw-content: 'project-a/src/logo.jpg'; |
| 341 | + content: var(--tw-content); |
| 342 | + } |
| 343 | + .content-\\[\\'project-b\\/src\\/index\\.html\\'\\] { |
| 344 | + --tw-content: 'project-b/src/index.html'; |
| 345 | + content: var(--tw-content); |
| 346 | + } |
| 347 | + } |
| 348 | + @supports (-moz-orient: inline) { |
| 349 | + @layer base { |
| 350 | + *, ::before, ::after, ::backdrop { |
| 351 | + --tw-content: ""; |
| 352 | + } |
| 353 | + } |
| 354 | + } |
| 355 | + @property --tw-content { |
| 356 | + syntax: "*"; |
| 357 | + inherits: false; |
| 358 | + initial-value: ""; |
| 359 | + } |
| 360 | + " |
| 361 | + `) |
| 362 | + }, |
| 363 | + ) |
| 364 | +}) |
0 commit comments