Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
May 9, 2024

Conversation

sverweij
Copy link
Owner

@sverweij sverweij commented May 9, 2024

Description

  • adds utility that extracts dependency-cruiser options from a dependency-cruiser config, and that returns an ICruiseOptions one can use as input parameter for the cruise function. This function also sets the validate attribute to true if there's a rule set in the config (and to false otherwise), so there's no need to do that anymore either.
  • corrects the documented method signature of extractDepcruiseConfig to what it really returns (an IConfiguration)
  • updates the docs/api.md documentation so all examples (1) run as intended (2) reflect current situation of the API.

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?

  • green ci
  • additional integration tests

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • Documentation only change
  • Refactor (non-breaking change which fixes an issue without changing functionality)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • 📖

    • My change doesn't require a documentation update, or ...
    • it does and I have updated it
  • ⚖️

    • The contribution will be subject to The MIT license, and I'm OK with that.
    • The contribution is my own original work.
    • I am ok with the stuff in CONTRIBUTING.md.

@sverweij sverweij force-pushed the bugfix/adds-extract-depcruise-options branch from cc609e6 to 622d1ad Compare May 9, 2024 09:45
Copy link

codeclimate bot commented May 9, 2024

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

View more on Code Climate.

@sverweij sverweij merged commit 54a7f42 into main May 9, 2024
13 checks passed
@sverweij sverweij deleted the bugfix/adds-extract-depcruise-options branch May 9, 2024 11:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Issue: cruise API - breaking changes
1 participant