mirror of
https://github.com/tailwindlabs/tailwindcss.git
synced 2025-12-08 21:36:08 +00:00
When migrating a project from Tailwind CSS v3 to Tailwind CSS v4, then we started the migration process in the following order: 1. Migrate the JS/TS config file 2. Migrate the source files (found via the `content` option) 3. Migrate the CSS files However, if you have a setup where you have multiple CSS root files (e.g.: `frontend` and `admin` are separated), then that typically means that you have an `@config` directive in your CSS files. These point to the Tailwind CSS config file. This PR changes the migration order to do the following: 1. Build a tree of all the CSS files 2. For each `@config` directive, migrate the JS/TS config file 3. For each JS/TS config file, migrate the source files If a CSS file does not contain any `@config` directives, then we start by filling in the `@config` directive with the default Tailwind CSS config file (if found, or the one passed in). If no default config file or passed in config file can be found, then we will error out (just like we do now) --------- Co-authored-by: Adam Wathan <adam.wathan@gmail.com>
71 lines
2.1 KiB
TypeScript
71 lines
2.1 KiB
TypeScript
import path from 'node:path'
|
||
import { describe, expect, it } from 'vitest'
|
||
import { relative, wordWrap } from './renderer'
|
||
import { normalizeWindowsSeperators } from './test-helpers'
|
||
|
||
describe('relative', () => {
|
||
it('should print an absolute path relative to the current working directory', () => {
|
||
expect(normalizeWindowsSeperators(relative(path.resolve('index.css')))).toMatchInlineSnapshot(
|
||
`"./index.css"`,
|
||
)
|
||
})
|
||
|
||
it('should prefer the shortest value by default', () => {
|
||
// Shortest between absolute and relative paths
|
||
expect(normalizeWindowsSeperators(relative('index.css'))).toMatchInlineSnapshot(`"index.css"`)
|
||
})
|
||
|
||
it('should be possible to override the current working directory', () => {
|
||
expect(normalizeWindowsSeperators(relative('../utils/index.css', '..'))).toMatchInlineSnapshot(
|
||
`"./utils/index.css"`,
|
||
)
|
||
})
|
||
|
||
it('should be possible to always prefer the relative path', () => {
|
||
expect(
|
||
normalizeWindowsSeperators(
|
||
relative('index.css', process.cwd(), { preferAbsoluteIfShorter: false }),
|
||
),
|
||
).toMatchInlineSnapshot(`"./index.css"`)
|
||
})
|
||
})
|
||
|
||
describe('word wrap', () => {
|
||
it('should wrap a sentence', () => {
|
||
expect(wordWrap('The quick brown fox jumps over the lazy dog', 10)).toMatchInlineSnapshot(`
|
||
[
|
||
"The quick",
|
||
"brown fox",
|
||
"jumps over",
|
||
"the lazy",
|
||
"dog",
|
||
]
|
||
`)
|
||
expect(wordWrap('The quick brown fox jumps over the lazy dog', 30)).toMatchInlineSnapshot(`
|
||
[
|
||
"The quick brown fox jumps over",
|
||
"the lazy dog",
|
||
]
|
||
`)
|
||
})
|
||
|
||
it('should wrap a sentence with ANSI escape codes', () => {
|
||
// The ANSI escape codes are not counted in the length, but they should
|
||
// still be rendered correctly.
|
||
expect(
|
||
wordWrap(
|
||
'\x1B[31mThe\x1B[39m \x1B[32mquick\x1B[39m \x1B[34mbrown\x1B[39m \x1B[35mfox\x1B[39m jumps over the lazy dog',
|
||
10,
|
||
),
|
||
).toMatchInlineSnapshot(`
|
||
[
|
||
"[31mThe[39m [32mquick[39m",
|
||
"[34mbrown[39m [35mfox[39m",
|
||
"jumps over",
|
||
"the lazy",
|
||
"dog",
|
||
]
|
||
`)
|
||
})
|
||
})
|