Home / Function/ findStaticPlugins() — tailwindcss Function Reference

findStaticPlugins() — tailwindcss Function Reference

Architecture documentation for the findStaticPlugins() function in extract-static-plugins.ts from the tailwindcss codebase.

Function typescript OxideCore Scanner calls 2 called by 2

Entity Profile

Dependency Diagram

graph TD
  7269613d_689c_049b_c5a1_169a57d36e90["findStaticPlugins()"]
  8d0812d4_61e4_e939_916d_a33e94faf43f["migrateJsConfig()"]
  8d0812d4_61e4_e939_916d_a33e94faf43f -->|calls| 7269613d_689c_049b_c5a1_169a57d36e90
  392cc8ca_1b35_56b9_6e03_2bbdf381e0f2["canMigrateConfig()"]
  392cc8ca_1b35_56b9_6e03_2bbdf381e0f2 -->|calls| 7269613d_689c_049b_c5a1_169a57d36e90
  2b431003_a49e_6971_10da_2cfab5fd0a7f["extractStaticImportMap()"]
  7269613d_689c_049b_c5a1_169a57d36e90 -->|calls| 2b431003_a49e_6971_10da_2cfab5fd0a7f
  17b4c7ea_e1f9_d654_8915_782187d7e404["extractValue()"]
  7269613d_689c_049b_c5a1_169a57d36e90 -->|calls| 17b4c7ea_e1f9_d654_8915_782187d7e404
  style 7269613d_689c_049b_c5a1_169a57d36e90 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/@tailwindcss-upgrade/src/utils/extract-static-plugins.ts lines 138–279

export function findStaticPlugins(source: string): [string, null | StaticPluginOptions][] | null {
  try {
    let tree = parser.parse(source)
    let root = tree.rootNode

    let imports = extractStaticImportMap(source)
    let captures = PLUGINS_QUERY.matches(root)

    let plugins: [string, null | StaticPluginOptions][] = []
    for (let match of captures) {
      for (let capture of match.captures) {
        if (capture.name !== 'imports') continue

        for (let pluginDefinition of capture.node.children) {
          if (
            pluginDefinition.type === '[' ||
            pluginDefinition.type === ']' ||
            pluginDefinition.type === ','
          )
            continue

          switch (pluginDefinition.type) {
            case 'identifier':
              let source = imports[pluginDefinition.text]
              if (!source || source.export !== null) {
                return null
              }
              plugins.push([source.module, null])
              break
            case 'string':
              plugins.push([pluginDefinition.children[1].text, null])
              break
            case 'call_expression':
              let matches = PLUGIN_CALL_OPTIONS_QUERY.matches(pluginDefinition)
              if (matches.length === 0) return null

              let moduleName: string | null = null
              let moduleIdentifier: string | null = null

              let options: StaticPluginOptions | null = null
              let lastProperty: string | null = null

              let captures = matches.flatMap((m) => m.captures)
              for (let i = 0; i < captures.length; i++) {
                let capture = captures[i]
                switch (capture.name) {
                  case 'module_identifier': {
                    moduleIdentifier = capture.node.text
                    break
                  }
                  case 'module_string': {
                    moduleName = capture.node.text
                    break
                  }
                  case 'property': {
                    if (lastProperty !== null) return null
                    lastProperty = capture.node.text
                    break
                  }
                  case 'str_value':
                  case 'num_value':
                  case 'null_value':
                  case 'true_value':
                  case 'false_value': {
                    if (lastProperty === null) return null
                    options ??= {}
                    options[lastProperty] = extractValue(capture)
                    lastProperty = null
                    break
                  }
                  case 'array_value': {
                    if (lastProperty === null) return null
                    options ??= {}

                    // Loop over all captures after this one that are on the
                    // same property (it will be one match for any array
                    // element)
                    let array: Array<string | number | boolean | null> = []
                    let lastConsumedIndex = i
                    arrayLoop: for (let j = i + 1; j < captures.length; j++) {
                      let innerCapture = captures[j]

                      switch (innerCapture.name) {
                        case 'property': {
                          if (innerCapture.node.text !== lastProperty) {
                            break arrayLoop
                          }
                          break
                        }
                        case 'str_value':
                        case 'num_value':
                        case 'null_value':
                        case 'true_value':
                        case 'false_value': {
                          array.push(extractValue(innerCapture))
                          lastConsumedIndex = j
                        }
                      }
                    }

                    i = lastConsumedIndex
                    options[lastProperty] = array
                    lastProperty = null
                    break
                  }

                  case '_name':
                  case '_empty_args':
                    break
                  default:
                    return null
                }
              }

              if (lastProperty !== null) return null

              if (moduleIdentifier !== null) {
                let source = imports[moduleIdentifier]
                if (!source || (source.export !== null && source.export !== '*')) {
                  return null
                }
                moduleName = source.module
              }

              if (moduleName === null) {
                return null
              }

              plugins.push([moduleName, options])
              break
            default:
              return null
          }
        }
      }
    }
    return plugins
  } catch (error: any) {
    error(`${error?.message ?? error}`, { prefix: '↳ ' })
    return null
  }
}

Domain

Subdomains

Frequently Asked Questions

What does findStaticPlugins() do?
findStaticPlugins() is a function in the tailwindcss codebase.
What does findStaticPlugins() call?
findStaticPlugins() calls 2 function(s): extractStaticImportMap, extractValue.
What calls findStaticPlugins()?
findStaticPlugins() is called by 2 function(s): canMigrateConfig, migrateJsConfig.

Analyze Your Own Codebase

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

Try Supermodel Free