packages/kbn-dependency-usage/README.md
A CLI tool for analyzing dependencies across packages and plugins. This tool provides commands to check dependency usage, aggregate it, debug dependency graphs, and more.
Use this command to list all packages or plugins within a directory that use a specified dependency.
bash scripts/dependency_usage.sh -d <dependency> -p <path_to_directory>
or
bash scripts/dependency_usage.sh --dependency-name <dependency> --paths <path_to_directory>
Example:
bash scripts/dependency_usage.sh -d rxjs -p x-pack/solutions/security/plugins/security_solution
-d rxjs: Specifies the dependency to look for (rxjs).-p x-pack/solutions/security/plugins/security_solution: Sets the directory to search within (x-pack/solutions/security/plugins/security_solution).Group the dependencies used within a directory by code owner.
bash scripts/dependency_usage.sh -p <path_to_directory> -g owner
or
bash scripts/dependency_usage.sh --paths <path_to_directory> --group-by owner
Example:
bash scripts/dependency_usage.sh -p x-pack/plugins -g owner
-p x-pack/plugins: Sets the directory to scan for plugins using this dependency.-g owner: Groups results by code owner.x-pack/plugins, organized by code owner.To display all dependencies used within a specific directory.
bash scripts/dependency_usage.sh -p <path_to_directory>
or
bash scripts/dependency_usage.sh --paths <path_to_directory>
Example:
bash scripts/dependency_usage.sh -p x-pack/solutions/security/plugins/security_solution
-p x-pack/solutions/security/plugins/security_solution: Specifies the package or directory for which to list all dependencies.x-pack/solutions/security/plugins/security_solution.When a package or plugin has multiple subteams, use the --collapse-depth option to control how granular the grouping by code owner should be.
Shows all subteams within security_solution.
bash scripts/dependency_usage.sh -p x-pack/solutions/security/plugins/security_solution -g owner --collapse-depth 4
Groups the results under a higher-level owner (e.g., security_solution as a single group).
bash scripts/dependency_usage.sh -p x-pack/solutions/security/plugins/security_solution -g owner --collapse-depth 1
Explanation:
-p x-pack/solutions/security/plugins/security_solution: Specifies the directory to scan.-g owner: Groups results by code owner.--collapse-depth: Defines the depth for grouping, where higher numbers show more granular subteams.--collapse-depth value.Search for dependencies that match a specific pattern (such as react-*) within a package and output the results to a specified file.
bash scripts/dependency_usage.sh -p <path_to_directory> -d '<pattern>' -o <output_file>
Example:
bash scripts/dependency_usage.sh -d 'react-*' -p x-pack/solutions/security/plugins/security_solution -o ./tmp/results.json
-p x-pack/solutions/security/plugins/security_solution: Specifies the directory or package to search within.-d 'react-*': Searches for dependencies that match the pattern react-*.-o ./tmp/results.json: Outputs the results to a specified file (results.json in the ./tmp directory).react-* in x-pack/solutions/security/plugins/security_solution to ./tmp/results.json.Enable verbose mode to log additional details for debugging dependency graphs. This includes generating a non-aggregated dependency graph in .dependency-graph-log.json.
bash scripts/dependency_usage.sh -p <path_to_directory> -o <output_file> -v
Example:
bash scripts/dependency_usage.sh -p x-pack/solutions/security/plugins/security_solution -o ./tmp/results.json
-p x-pack/solutions/security/plugins/security_solution: Specifies the target directory or package to analyze.-o ./tmp/results.json: Saves the output to the results.json file in the ./tmp directory.-v: Enables verbose mode.Output: Saves a list of all dependencies in x-pack/solutions/security/plugins/security_solution to ./tmp/results.json. Additionally, it logs a detailed, non aggregated dependency graph to .dependency-graph-log.json for debugging purposes.
For further information on additional flags and options, refer to the script's help command.