Skip to content

Commit 894ddd8

Browse files
Improve comments and API naming
1 parent 7d660db commit 894ddd8

File tree

3 files changed

+13
-15
lines changed

3 files changed

+13
-15
lines changed

integrations/upgrade/js-config.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { expect } from 'vitest'
22
import { css, json, test, ts } from '../utils'
33

44
test(
5-
`upgrades a simple JS config file to CSS`,
5+
`upgrade JS config files with flat theme values, darkMode, and content fields`,
66
{
77
fs: {
88
'package.json': json`

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

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,8 @@ export function migrateConfig(
6363
cssConfig.append(postcss.parse(css + jsConfigMigration.css))
6464
}
6565

66-
// Inject the `@config` in a sensible place
67-
// 1. Below the last `@import`
68-
// 2. At the top of the file
66+
// Inject the `@config` directive after the last `@import` or at the
67+
// top of the file if no `@import` rules are present
6968
let locationNode = null as AtRule | null
7069

7170
walk(root, (node) => {
@@ -99,10 +98,9 @@ export function migrateConfig(
9998

10099
if (!hasTailwindImport) return
101100

102-
// - If a full `@import "tailwindcss"` is present, we can inject the
103-
// `@config` directive directly into this stylesheet.
104-
// - If we are the root file (no parents), then we can inject the `@config`
105-
// directive directly into this file as well.
101+
// If a full `@import "tailwindcss"` is present or this is the root
102+
// stylesheet, we can inject the `@config` directive directly into this
103+
// file.
106104
if (hasFullTailwindImport || sheet.parents.size <= 0) {
107105
injectInto(sheet)
108106
return
@@ -134,7 +132,7 @@ function relativeToStylesheet(sheet: Stylesheet, absolute: string) {
134132
if (relative[0] !== '.') {
135133
relative = `./${relative}`
136134
}
137-
// Ensure relative is a posix style path since we will merge it with the
135+
// Ensure relative is a POSIX style path since we will merge it with the
138136
// glob.
139137
return normalizePath(relative)
140138
}

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ export async function migrateJsConfig(
3131
fs.readFile(fullConfigPath, 'utf-8'),
3232
])
3333

34-
if (!isSimpleConfig(unresolvedConfig, source)) {
34+
if (!canMigrateConfig(unresolvedConfig, source)) {
3535
info(
36-
'The configuration file is not a simple object. Please refer to the migration guide for how to migrate it fully to Tailwind CSS v4. For now, we will load the configuration file as-is.',
36+
'Your configuration file could not be automatically migrated to the new CSS configuration format, so your CSS has been updated to load your existing configuration file.',
3737
)
3838
return null
3939
}
@@ -63,8 +63,8 @@ async function migrateTheme(unresolvedConfig: Config & { theme: any }): Promise<
6363
let { extend: extendTheme, ...overwriteTheme } = unresolvedConfig.theme
6464

6565
let resetNamespaces = new Map<string, boolean>()
66-
// Before we merge the resetting theme values with the `extend` values, we
67-
// capture all namespaces that need to be reset
66+
// Before we merge theme overrides with theme extensions, we capture all
67+
// namespaces that need to be reset.
6868
for (let [key, value] of themeableValues(overwriteTheme)) {
6969
if (typeof value !== 'string' && typeof value !== 'number') {
7070
continue
@@ -119,7 +119,7 @@ function createSectionKey(key: string[]): string {
119119
let sectionSegments = []
120120
for (let i = 0; i < key.length - 1; i++) {
121121
let segment = key[i]
122-
// ignore tuples
122+
// Ignore tuples
123123
if (key[i + 1][0] === '-') {
124124
break
125125
}
@@ -143,7 +143,7 @@ function migrateContent(
143143
}
144144

145145
// Applies heuristics to determine if we can attempt to migrate the config
146-
function isSimpleConfig(unresolvedConfig: Config, source: string): boolean {
146+
function canMigrateConfig(unresolvedConfig: Config, source: string): boolean {
147147
// The file may not contain any functions
148148
if (source.includes('function') || source.includes(' => ')) {
149149
return false

0 commit comments

Comments
 (0)