Skip to main content

Module config_parser

Module config_parser 

Source
Expand description

AST-based config file parser utilities.

Provides helpers to extract configuration values from JS/TS config files without evaluating them. Uses Oxc’s parser for fast, safe AST walking.

Common patterns handled:

  • export default { key: "value" } (default export object)
  • export default defineConfig({ key: "value" }) (factory function)
  • module.exports = { key: "value" } (CJS)
  • Import specifiers (import x from 'pkg')
  • Array literals (["a", "b"])
  • Object properties ({ key: "value" })

Functions§

config_default_export_unreachable
True when a parsed config has neither an object default export (find_config_object) nor an array default export (find_default_export_array). Used to emit a diagnostic when a config shape such as mergeConfig(base, defineConfig({...})) or an imported-and-spread base config cannot be statically reached.
extract_config_aliases
Extract alias mappings from an object or array-based alias config.
extract_config_aliases_kinded
Like extract_config_aliases but each tuple carries a third element: replacement_is_bare_string_literal, true ONLY when the replacement was written as a plain bare string literal (not starting with .//..///) rather than a path expression (path.resolve(...), path.join(...), fileURLToPath(...), new URL(...)). This is the filesystem-free discriminator between a package-to-package alias ('lodash-es' -> 'lodash', bare literal) and a directory/file alias ('@' -> path.resolve(__dirname, 'src'), path expression). See test_alias::process_test_alias.
extract_config_array_nested_aliases
Extract alias mappings nested inside an array of config objects.
extract_config_array_nested_aliases_kinded
Kinded variant of extract_config_array_nested_aliases (see extract_config_aliases_kinded for the third tuple element).
extract_config_array_nested_string_or_array
Extract string values from a property path, also searching inside array elements.
extract_config_array_object_string_pairs
Extract paired (primary, optional secondary) string values from each object element of an array at array_path.
extract_config_array_object_strings
Extract string values from a nested array, supporting both string elements and object elements with a named string/path field.
extract_config_nested_shallow_strings
Extract shallow strings from an array property inside a nested object path.
extract_config_object_keys
Extract keys of an object property at a nested path.
extract_config_object_nested_string_or_array
Extract string values from a property path, searching inside all values of an object.
extract_config_object_nested_strings
Extract string values from a property path, searching inside all values of an object.
extract_config_path_string
Extract a statically recoverable path-like string from a property path.
extract_config_plugin_option_string
Extract a string-like option from a plugin tuple inside a config plugin array.
extract_config_plugin_option_string_from_paths
Extract a string-like option from the first plugin array path that contains it.
extract_config_property_strings
Extract string values from top-level properties of the default export/module.exports object. Returns all string literal values found for the given property key, recursively.
extract_config_require_strings
Extract require('...') call argument strings from a property’s value.
extract_config_shallow_strings
Extract only top-level string values from a property’s array.
extract_config_shallow_strings_or_object_property
Extract top-level string values from a config array, including object entries.
extract_config_static_dir_entries
Extract Storybook-style static directory entries from an array.
extract_config_string
Extract a single string from a property at a nested path.
extract_config_string_array
Extract string array from a property at a nested path in a config’s default export.
extract_config_string_or_array
Extract a value that may be a single string, a string array, or an object with string/array values.
extract_config_truthy_bool_or_object
True when a nested config property is a static true boolean or object value.
extract_default_export_array_aliases_kinded
Extract kinded aliases from a default-exported ARRAY config, the defineWorkspace([...]) / vitest.workspace.{ts,js} shape. find_config_object only finds an object default export, so the workspace array file is invisible to the object-based extractors; this walks each object element of the array and reads alias_path from it. One level only (nested test.projects inside an element is out of scope).
extract_imports
Extract all import source specifiers from JS/TS source code.
extract_imports_and_requires
Extract all import sources AND top-level require('...') expression statements.
extract_lazy_imports_in_array
Extract static specifiers from thunk-wrapped dynamic imports inside an array property.
extract_vite_react_babel_dependencies
Extract Babel plugin and preset package names configured through @vitejs/plugin-react options in a Vite-style plugins array.
find_config_object_pub
Public wrapper for find_config_object for plugins that need manual AST walking.
normalize_config_path
Normalize a config-relative path string to a project-root-relative path.