extract-dependencies-from-sources

Inferring dependencies from the source code of a monorepo app

      

⚡ Quickstart

🔶 Install

yarn add -D extract-dependencies-from-sources
pnpm i -D extract-dependencies-from-sources

🔶 Usage

extractDeps --packagejson ./package.json --path codebasePath

Options:
  --help          Show help                                            [boolean]
  --version       Show version number                                  [boolean]
  --packagejson   Root package.json path  [required] [default: "./package.json"]
  --path          Codebase path                                       [required]
  --externaldeps  Path to external dependencies file (optional)

Examples:
  extractDeps --packagejson ./package.json --path ./apps/back --path
  ./libs/back

Inferring dependencies from the source code of a monorepo app

For example, running the following command will replace the dependencies property of the root package.json with the dependencies found in the codebases located in apps/back and libs/back/database.

yarn extractDeps --path apps/back --path libs/back/database

You can also use the function directly in your code:

import { getCodebasesDependencies } from 'extract-dependencies-from-sources';
import { readJson } from 'fs-extra';

(async () => {
  const data = await readJson('./package.json');
  const deps = await getCodebasesDependencies(data.dependencies, [
    'apps/front/auth',
    'lib/front/components',
  ]);
})();

🧿 Including external dependencies

You can also specify external dependencies to include in the output by providing a path to a yaml file containing a map of dependencies:

external-deps.yml

externaldeps:
  - msw: ^1.1.0
  - eslint: ~8.36.0

You can then use the --externaldeps option to include them:

yarn extractDeps --path apps/front --externaldeps ./external-deps.yml