sverweij / dependency-cruiser

Validate and visualize dependencies. Your rules. JavaScript, TypeScript, CoffeeScript. ES6, CommonJS, AMD.
https://npmjs.com/dependency-cruiser
MIT License
5.27k stars 250 forks source link

fix(config-util): adds utility that extracts dependency-cruiser options from a dependency-cruiser config #933

Closed sverweij closed 5 months ago

sverweij commented 5 months ago

Description

Motivation and Context

fixes #932

extractDepcruiseConfig returns an IConfiguration object while the cruise function needs an ICruiseOptions. Changing the signature of extractDepcruiseConfig would constitute a breaking change - and extractDepcruiseConfig also has its own uses => we need an additional utility function that translates a dependency-cruiser configuration file into an ICruiseOptions object. This PR adds that.

Example

import {
  cruise,
  type ICruiseOptions,
  type IReporterOutput,
  type IResolveOptions,
} from "dependency-cruiser";
import extractDepcruiseOptions from "dependency-cruiser/config-utl/extract-depcruise-options";
import extractTSConfig from "dependency-cruiser/config-utl/extract-ts-config";
import extractWebpackResolveConfig from "dependency-cruiser/config-utl/extract-webpack-resolve-config";

try {
  const lArrayOfFilesAndDirectoriesToCruise = ["src"];

  const depcruiseOptions: ICruiseOptions = await extractDepcruiseOptions(
    "./.dependency-cruiser.json",
  );
  const lWebpackResolveConfig = (await extractWebpackResolveConfig(
    "./webpack.config.js",
  )) as IResolveOptions;
  const tsConfig = extractTSConfig("./tsconfig.json");

  const cruiseResult: IReporterOutput = await cruise(
    lArrayOfFilesAndDirectoriesToCruise,
    depcruiseOptions,
    lWebpackResolveConfig,
    {
      tsConfig,
    },
  );

  console.dir(cruiseResult.output, { depth: 10 });
} catch (pError) {
  console.error(pError);
}

How Has This Been Tested?

Types of changes

Checklist

codeclimate[bot] commented 5 months ago

Code Climate has analyzed commit 622d1adb and detected 0 issues on this pull request.

View more on Code Climate.