migrate-config.ts — tailwindcss Source File
Architecture documentation for migrate-config.ts, a typescript file in the tailwindcss codebase. 6 imports, 1 dependents.
Entity Profile
Dependency Diagram
graph LR deadb2f6_312c_a055_6892_b63958628b61["migrate-config.ts"] 342c0afc_3173_535b_9e25_ef41f6768585["normalize-path.ts"] deadb2f6_312c_a055_6892_b63958628b61 --> 342c0afc_3173_535b_9e25_ef41f6768585 df397cc3_5766_b5b5_66f1_04e0e5873574["normalizePath"] deadb2f6_312c_a055_6892_b63958628b61 --> df397cc3_5766_b5b5_66f1_04e0e5873574 41fd12a7_15c2_7d83_2e55_c5b9a8faf9b1["stylesheet.ts"] deadb2f6_312c_a055_6892_b63958628b61 --> 41fd12a7_15c2_7d83_2e55_c5b9a8faf9b1 b2ba3368_7330_fe20_4543_9cafa8cfedc0["migrate-js-config.ts"] deadb2f6_312c_a055_6892_b63958628b61 --> b2ba3368_7330_fe20_4543_9cafa8cfedc0 2a7660a5_3e09_bd74_37f0_e4e54bc64ce5["node:path"] deadb2f6_312c_a055_6892_b63958628b61 --> 2a7660a5_3e09_bd74_37f0_e4e54bc64ce5 ba54c7c3_7b1e_9984_bfef_a693a3df2d84["postcss"] deadb2f6_312c_a055_6892_b63958628b61 --> ba54c7c3_7b1e_9984_bfef_a693a3df2d84 67f80607_3a88_f275_79a1_b9557100d939["migrate.ts"] 67f80607_3a88_f275_79a1_b9557100d939 --> deadb2f6_312c_a055_6892_b63958628b61 style deadb2f6_312c_a055_6892_b63958628b61 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
import path from 'node:path'
import postcss, { AtRule, type Plugin } from 'postcss'
import { normalizePath } from '../../../../@tailwindcss-node/src/normalize-path'
import type { Stylesheet } from '../../stylesheet'
import type { JSConfigMigration } from '../config/migrate-js-config'
const ALREADY_INJECTED = new WeakMap<Stylesheet, string[]>()
export function migrateConfig(
sheet: Stylesheet,
{
configFilePath,
jsConfigMigration,
}: { configFilePath: string | null; jsConfigMigration: JSConfigMigration | null },
): Plugin {
function migrate() {
if (!sheet.isTailwindRoot) return
if (!configFilePath) return
let alreadyInjected = ALREADY_INJECTED.get(sheet)
if (alreadyInjected && alreadyInjected.includes(configFilePath)) {
return
} else if (alreadyInjected) {
alreadyInjected.push(configFilePath)
} else {
ALREADY_INJECTED.set(sheet, [configFilePath])
}
let root = sheet.root
// We don't have a sheet with a file path
if (!sheet.file) return
let cssConfig = new AtRule()
// Remove the `@config` directive if it exists and we couldn't migrate the
// config file.
if (jsConfigMigration !== null) {
root.walkAtRules('config', (node) => {
node.remove()
})
let css = '\n\n'
css += '\n@tw-bucket source {'
for (let source of jsConfigMigration.sources) {
let absolute = path.resolve(source.base, source.pattern)
css += `@source '${relativeToStylesheet(sheet, absolute)}';\n`
}
css += '}\n'
css += '\n@tw-bucket plugin {\n'
for (let plugin of jsConfigMigration.plugins) {
let relative =
plugin.path[0] === '.'
? relativeToStylesheet(sheet, path.resolve(plugin.base, plugin.path))
: plugin.path
if (plugin.options === null) {
css += `@plugin '${relative}';\n`
} else {
css += `@plugin '${relative}' {\n`
for (let [property, value] of Object.entries(plugin.options)) {
let cssValue = ''
if (typeof value === 'string') {
cssValue = quoteString(value)
} else if (Array.isArray(value)) {
cssValue = value
.map((v) => (typeof v === 'string' ? quoteString(v) : '' + v))
.join(', ')
} else {
cssValue = '' + value
}
css += ` ${property}: ${cssValue};\n`
}
css += '}\n' // @plugin
}
}
css += '}\n' // @tw-bucket
cssConfig.append(postcss.parse(css + jsConfigMigration.css))
}
// Inject the `@config` directive
root.append(cssConfig.nodes)
}
return {
postcssPlugin: '@tailwindcss/upgrade/migrate-config',
OnceExit: migrate,
}
}
function relativeToStylesheet(sheet: Stylesheet, absolute: string) {
if (!sheet.file) throw new Error('Can not find a path for the stylesheet')
let sheetPath = sheet.file
let relative = path.relative(path.dirname(sheetPath), absolute)
if (relative[0] !== '.') {
relative = `./${relative}`
}
// Ensure relative is a POSIX style path since we will merge it with the
// glob.
return normalizePath(relative)
}
function quoteString(value: string): string {
return `'${value.replace(/\\/g, '\\\\').replace(/'/g, "\\'")}'`
}
Domain
Subdomains
Dependencies
- migrate-js-config.ts
- node:path
- normalize-path.ts
- normalizePath
- postcss
- stylesheet.ts
Source
Frequently Asked Questions
What does migrate-config.ts do?
migrate-config.ts is a source file in the tailwindcss codebase, written in typescript. It belongs to the UpgradeToolkit domain, Codemods subdomain.
What functions are defined in migrate-config.ts?
migrate-config.ts defines 3 function(s): migrateConfig, quoteString, relativeToStylesheet.
What does migrate-config.ts depend on?
migrate-config.ts imports 6 module(s): migrate-js-config.ts, node:path, normalize-path.ts, normalizePath, postcss, stylesheet.ts.
What files import migrate-config.ts?
migrate-config.ts is imported by 1 file(s): migrate.ts.
Where is migrate-config.ts in the architecture?
migrate-config.ts is located at packages/@tailwindcss-upgrade/src/codemods/css/migrate-config.ts (domain: UpgradeToolkit, subdomain: Codemods, directory: packages/@tailwindcss-upgrade/src/codemods/css).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free