Home / Function/ migrateImport() — tailwindcss Function Reference

migrateImport() — tailwindcss Function Reference

Architecture documentation for the migrateImport() function in migrate-import.ts from the tailwindcss codebase.

Entity Profile

Dependency Diagram

graph TD
  22885c03_eded_5619_af73_329b957dad5a["migrateImport()"]
  ffa4ef8b_4732_bebf_750e_316fc71430db["migrate()"]
  ffa4ef8b_4732_bebf_750e_316fc71430db -->|calls| 22885c03_eded_5619_af73_329b957dad5a
  b1aa79a5_bad0_a9e2_1c70_8e14489ee8dd["migrateContents()"]
  b1aa79a5_bad0_a9e2_1c70_8e14489ee8dd -->|calls| 22885c03_eded_5619_af73_329b957dad5a
  2a20ea29_c850_cd61_5600_aeebbe3dda66["segment()"]
  22885c03_eded_5619_af73_329b957dad5a -->|calls| 2a20ea29_c850_cd61_5600_aeebbe3dda66
  d4cb5436_afc5_b498_b798_03165e495710["parseImportParams()"]
  22885c03_eded_5619_af73_329b957dad5a -->|calls| d4cb5436_afc5_b498_b798_03165e495710
  0638028e_f2f7_8e77_2f19_1bd2ce4b2d6a["parse()"]
  22885c03_eded_5619_af73_329b957dad5a -->|calls| 0638028e_f2f7_8e77_2f19_1bd2ce4b2d6a
  style 22885c03_eded_5619_af73_329b957dad5a fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/@tailwindcss-upgrade/src/codemods/css/migrate-import.ts lines 8–52

export function migrateImport(): Plugin {
  async function migrate(root: Root) {
    let file = root.source?.input.file
    if (!file) return

    let promises: Promise<void>[] = []
    root.walkAtRules('import', (rule) => {
      try {
        let [firstParam, ...rest] = segment(rule.params, ' ')

        let params = parseImportParams(ValueParser.parse(firstParam))
        if (!params) return

        let isRelative = params.uri[0] === '.'
        let hasCssExtension = params.uri.endsWith('.css')

        if (isRelative && hasCssExtension) {
          return
        }

        let fullPath = resolve(dirname(file), params.uri)
        if (!hasCssExtension) fullPath += '.css'

        promises.push(
          fs.stat(fullPath).then(() => {
            let ext = hasCssExtension ? '' : '.css'
            let path = isRelative ? params.uri : `./${params.uri}`
            rule.params = [`'${path}${ext}'`, ...rest].join(' ')
          }),
        )
      } catch {
        // When an error occurs while parsing the `@import` statement, we skip
        // the import. This will happen in cases where you import an external
        // URL.
      }
    })

    await Promise.allSettled(promises)
  }

  return {
    postcssPlugin: '@tailwindcss/upgrade/migrate-import',
    OnceExit: migrate,
  }
}

Domain

Subdomains

Frequently Asked Questions

What does migrateImport() do?
migrateImport() is a function in the tailwindcss codebase.
What does migrateImport() call?
migrateImport() calls 3 function(s): parse, parseImportParams, segment.
What calls migrateImport()?
migrateImport() is called by 2 function(s): migrate, migrateContents.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free