Home / Function/ prepareConfig() — tailwindcss Function Reference

prepareConfig() — tailwindcss Function Reference

Architecture documentation for the prepareConfig() function in prepare-config.ts from the tailwindcss codebase.

Entity Profile

Dependency Diagram

graph TD
  3dec545a_c324_15f0_cdd3_7c9a86137145["prepareConfig()"]
  d58c78f4_5856_72aa_9dca_c418a7d7f31e["prepare-config.ts"]
  3dec545a_c324_15f0_cdd3_7c9a86137145 -->|defined in| d58c78f4_5856_72aa_9dca_c418a7d7f31e
  817bb61a_7ad0_1186_790a_6a40126eed80["run()"]
  817bb61a_7ad0_1186_790a_6a40126eed80 -->|calls| 3dec545a_c324_15f0_cdd3_7c9a86137145
  af4df363_0f48_b01c_23c9_2fbbbb45c164["detectConfigPath()"]
  3dec545a_c324_15f0_cdd3_7c9a86137145 -->|calls| af4df363_0f48_b01c_23c9_2fbbbb45c164
  1c806fef_a933_285c_65d9_c10998b12c7d["relative()"]
  3dec545a_c324_15f0_cdd3_7c9a86137145 -->|calls| 1c806fef_a933_285c_65d9_c10998b12c7d
  2e186872_4660_9caa_6330_7fce815c6ad0["createResolvedUserConfig()"]
  3dec545a_c324_15f0_cdd3_7c9a86137145 -->|calls| 2e186872_4660_9caa_6330_7fce815c6ad0
  137edc0b_e9b1_6852_6d97_d3956c8deba4["migratePrefixValue()"]
  3dec545a_c324_15f0_cdd3_7c9a86137145 -->|calls| 137edc0b_e9b1_6852_6d97_d3956c8deba4
  d357b59a_0b9f_aa27_15e3_243121d6420c["compile()"]
  3dec545a_c324_15f0_cdd3_7c9a86137145 -->|calls| d357b59a_0b9f_aa27_15e3_243121d6420c
  6c5b3bb2_4069_e0af_8887_216e1c995446["error()"]
  3dec545a_c324_15f0_cdd3_7c9a86137145 -->|calls| 6c5b3bb2_4069_e0af_8887_216e1c995446
  style 3dec545a_c324_15f0_cdd3_7c9a86137145 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/@tailwindcss-upgrade/src/codemods/template/prepare-config.ts lines 17–71

export async function prepareConfig(
  configFilePath: string | null,
  options: { base: string },
): Promise<{
  designSystem: DesignSystem
  sources: { base: string; pattern: string }[]
  userConfig: Config
  configFilePath: string

  newPrefix: string | null
}> {
  try {
    if (configFilePath === null) {
      configFilePath = await detectConfigPath(options.base)
    } else if (!path.isAbsolute(configFilePath)) {
      configFilePath = path.resolve(options.base, configFilePath)
    }

    // We create a relative path from the current file to the config file. This is
    // required so that the base for Tailwind CSS can bet inside the
    // @tailwindcss-upgrade package and we can require `tailwindcss` properly.
    let relative = path.relative(__dirname, configFilePath)

    // If the path points to a file in the same directory, `path.relative` will
    // remove the leading `./` and we need to add it back in order to still
    // consider the path relative
    if (!relative.startsWith('.') && !path.isAbsolute(relative)) {
      relative = './' + relative
    }

    let userConfig = await createResolvedUserConfig(configFilePath)

    let newPrefix = userConfig.prefix ? migratePrefixValue(userConfig.prefix) : null
    let input = css`
      @import 'tailwindcss' ${newPrefix ? `prefix(${newPrefix})` : ''};
      @config '${relative}';
    `

    let [compiler, designSystem] = await Promise.all([
      compile(input, { base: __dirname, onDependency: () => {} }),
      __unstable__loadDesignSystem(input, { base: __dirname }),
    ])

    return {
      designSystem,
      sources: compiler.sources,
      userConfig,
      newPrefix,
      configFilePath,
    }
  } catch (e: any) {
    error('Could not load the configuration file: ' + e.message, { prefix: '↳ ' })
    process.exit(1)
  }
}

Subdomains

Called By

Frequently Asked Questions

What does prepareConfig() do?
prepareConfig() is a function in the tailwindcss codebase, defined in packages/@tailwindcss-upgrade/src/codemods/template/prepare-config.ts.
Where is prepareConfig() defined?
prepareConfig() is defined in packages/@tailwindcss-upgrade/src/codemods/template/prepare-config.ts at line 17.
What does prepareConfig() call?
prepareConfig() calls 6 function(s): compile, createResolvedUserConfig, detectConfigPath, error, migratePrefixValue, relative.
What calls prepareConfig()?
prepareConfig() is called by 1 function(s): run.

Analyze Your Own Codebase

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

Try Supermodel Free