Skip to content

Commit a77a7b1

Browse files
committed
error when no CSS file with Tailwind CSS setup can be found
1 parent d123c18 commit a77a7b1

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

integrations/upgrade/index.test.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,51 @@
11
import { expect } from 'vitest'
22
import { candidate, css, html, js, json, test } from '../utils'
33

4+
test(
5+
'error when no CSS file with @tailwind is used',
6+
{
7+
fs: {
8+
'package.json': json`
9+
{
10+
"dependencies": {
11+
"@tailwindcss/upgrade": "workspace:^"
12+
},
13+
"devDependencies": {
14+
"@tailwindcss/cli": "workspace:^"
15+
}
16+
}
17+
`,
18+
'tailwind.config.js': js`
19+
/** @type {import('tailwindcss').Config} */
20+
module.exports = {
21+
content: ['./src/**/*.{html,js}'],
22+
}
23+
`,
24+
'src/index.html': html`
25+
<h1>🤠👋</h1>
26+
<div class="!flex"></div>
27+
`,
28+
'src/fonts.css': css`/* Unrelated CSS file */`,
29+
},
30+
},
31+
async ({ fs, exec }) => {
32+
let output = await exec('npx @tailwindcss/upgrade')
33+
expect(output).toContain('Cannot find a CSS file where Tailwind CSS is setup.')
34+
35+
// Files should not be modified
36+
expect(await fs.dumpFiles('./src/**/*.{css,html}')).toMatchInlineSnapshot(`
37+
"
38+
--- ./src/index.html ---
39+
<h1>🤠👋</h1>
40+
<div class="!flex"></div>
41+
42+
--- ./src/fonts.css ---
43+
/* Unrelated CSS file */
44+
"
45+
`)
46+
},
47+
)
48+
449
test(
550
`upgrades a v3 project to v4`,
651
{

packages/@tailwindcss-upgrade/src/migrate.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,11 @@ export async function linkConfigs(
302302
{ configPath, base }: { configPath: string | null; base: string },
303303
) {
304304
let rootStylesheets = stylesheets.filter((sheet) => sheet.isTailwindRoot)
305+
if (rootStylesheets.length === 0) {
306+
throw new Error(
307+
'Cannot find a CSS file where Tailwind CSS is setup.\nMake sure to create a CSS file where Tailwind CSS is setup and try again.',
308+
)
309+
}
305310
let withoutAtConfig = rootStylesheets.filter((sheet) => {
306311
let hasConfig = false
307312
sheet.root.walkAtRules('config', (node) => {

0 commit comments

Comments
 (0)