kibana/packages/kbn-dependency-usage
Kibana Machine cc35bc14b0
[8.x] [CI] Only emit .d.ts when running typecheck (#209259) (#214943)
# Backport

This will backport the following commits from `main` to `8.x`:
- [[CI] Only emit .d.ts when running typecheck
(#209259)](https://github.com/elastic/kibana/pull/209259)

<!--- Backport version: 9.6.6 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sorenlouv/backport)

<!--BACKPORT [{"author":{"name":"Alex
Szabo","email":"alex.szabo@elastic.co"},"sourceCommit":{"committedDate":"2025-03-18T10:48:14Z","message":"[CI]
Only emit .d.ts when running typecheck (#209259)\n\n## Summary\nStop
emitting any `.js` files during typechecking. We only depend on
the\ndeclarations, not the emitted, compiled javascript files.\n\nAn
added benefit, is making some bad import errors more obvious. \nWe'll no
longer try to build javascript files in place if a poor\nimport/require
is made, rather the error of importing outside projects\n(in the forest
of a bunch of errors possibly) will be visible in the\ntypescript
logs:\n```\n# instead of:\nproc [tsc] error TS5055: Cannot write file
'/opt/buildkite-agent/builds/bk-agent-prod-gcp-1741789017236110254/elastic/kibana-pull-request/kibana/src/platform/packages/shared/kbn-babel-register/cache/no_cache_cache.js'
because it would overwrite input file.\n\n# we'll see:\n... several
others like this\n proc [tsc]
src/platform/packages/shared/kbn-grok-ui/scripts/generate_patterns.js:10:9
- error TS6307: File
'/Users/alex/Git/elastic-kibana/src/setup_node_env/index.js' is not
listed within the file list of project
'/Users/alex/Git/elastic-kibana/src/platform/packages/shared/kbn-grok-ui/tsconfig.type_check.json'.
Projects must list all files or use an 'include' pattern.\n proc [tsc]
\n proc [tsc] 10 require('../../../../../setup_node_env');\n... several
others like
this\n```","sha":"702c9c49dcbc9036af80ba5473c961cf96573030","branchLabelMapping":{"^v9.1.0$":"main","^v8.19.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Team:Operations","release_note:skip","backport:all-open","v9.1.0"],"title":"[CI]
Only emit .d.ts when running
typecheck","number":209259,"url":"https://github.com/elastic/kibana/pull/209259","mergeCommit":{"message":"[CI]
Only emit .d.ts when running typecheck (#209259)\n\n## Summary\nStop
emitting any `.js` files during typechecking. We only depend on
the\ndeclarations, not the emitted, compiled javascript files.\n\nAn
added benefit, is making some bad import errors more obvious. \nWe'll no
longer try to build javascript files in place if a poor\nimport/require
is made, rather the error of importing outside projects\n(in the forest
of a bunch of errors possibly) will be visible in the\ntypescript
logs:\n```\n# instead of:\nproc [tsc] error TS5055: Cannot write file
'/opt/buildkite-agent/builds/bk-agent-prod-gcp-1741789017236110254/elastic/kibana-pull-request/kibana/src/platform/packages/shared/kbn-babel-register/cache/no_cache_cache.js'
because it would overwrite input file.\n\n# we'll see:\n... several
others like this\n proc [tsc]
src/platform/packages/shared/kbn-grok-ui/scripts/generate_patterns.js:10:9
- error TS6307: File
'/Users/alex/Git/elastic-kibana/src/setup_node_env/index.js' is not
listed within the file list of project
'/Users/alex/Git/elastic-kibana/src/platform/packages/shared/kbn-grok-ui/tsconfig.type_check.json'.
Projects must list all files or use an 'include' pattern.\n proc [tsc]
\n proc [tsc] 10 require('../../../../../setup_node_env');\n... several
others like
this\n```","sha":"702c9c49dcbc9036af80ba5473c961cf96573030"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/209259","number":209259,"mergeCommit":{"message":"[CI]
Only emit .d.ts when running typecheck (#209259)\n\n## Summary\nStop
emitting any `.js` files during typechecking. We only depend on
the\ndeclarations, not the emitted, compiled javascript files.\n\nAn
added benefit, is making some bad import errors more obvious. \nWe'll no
longer try to build javascript files in place if a poor\nimport/require
is made, rather the error of importing outside projects\n(in the forest
of a bunch of errors possibly) will be visible in the\ntypescript
logs:\n```\n# instead of:\nproc [tsc] error TS5055: Cannot write file
'/opt/buildkite-agent/builds/bk-agent-prod-gcp-1741789017236110254/elastic/kibana-pull-request/kibana/src/platform/packages/shared/kbn-babel-register/cache/no_cache_cache.js'
because it would overwrite input file.\n\n# we'll see:\n... several
others like this\n proc [tsc]
src/platform/packages/shared/kbn-grok-ui/scripts/generate_patterns.js:10:9
- error TS6307: File
'/Users/alex/Git/elastic-kibana/src/setup_node_env/index.js' is not
listed within the file list of project
'/Users/alex/Git/elastic-kibana/src/platform/packages/shared/kbn-grok-ui/tsconfig.type_check.json'.
Projects must list all files or use an 'include' pattern.\n proc [tsc]
\n proc [tsc] 10 require('../../../../../setup_node_env');\n... several
others like
this\n```","sha":"702c9c49dcbc9036af80ba5473c961cf96573030"}}]}]
BACKPORT-->

Co-authored-by: Alex Szabo <alex.szabo@elastic.co>
2025-03-18 15:05:07 +02:00
..
src [8.x] [CI] Only emit .d.ts when running typecheck (#209259) (#214943) 2025-03-18 15:05:07 +02:00
jest.config.js [Backport] Dependency Usage CLI (#201815) 2024-11-26 21:48:26 +01:00
kibana.jsonc [Backport] Dependency Usage CLI (#201815) 2024-11-26 21:48:26 +01:00
package.json [Backport] Dependency Usage CLI (#201815) 2024-11-26 21:48:26 +01:00
README.md [8.x] SKA: Relocate modules owned by @elastic/security-solution (#204523) 2024-12-17 20:13:10 +01:00
tsconfig.json [Backport] Dependency Usage CLI (#201815) 2024-11-26 21:48:26 +01:00

@kbn/dependency-usage

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.


Table of Contents

  1. Show all packages/plugins using a dependency
  2. Show dependencies grouped by code owner
  3. List all dependencies for a package or directory
  4. Group by code owner with adjustable collapse depth
  5. Show dependencies matching a pattern
  6. Verbose flag to debug dependency graph issues

1. Show all packages/plugins using a specific dependency

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).

2. Show dependencies grouped by code owner

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.
  • Output: Lists all dependencies for x-pack/plugins, organized by code owner.

3. List all dependencies for source directory

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.
  • Output: Lists all dependencies for x-pack/solutions/security/plugins/security_solution.

4. Group by code owner with adjustable collapse depth

When a package or plugin has multiple subteams, use the --collapse-depth option to control how granular the grouping by code owner should be.

Detailed Subteam Grouping

Shows all subteams within security_solution.

bash scripts/dependency_usage.sh -p x-pack/solutions/security/plugins/security_solution -g owner --collapse-depth 4

Collapsed Grouping

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.
  • Output: Lists dependencies grouped by code owner at different levels of depth based on the --collapse-depth value.

5. Show dependencies matching a pattern

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).
  • Output: Saves a list of all dependencies matching react-* in x-pack/solutions/security/plugins/security_solution to ./tmp/results.json.

6. Verbose flag to debug dependency graph issues

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.