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?
[x] green ci
[x] additional integration tests
Types of changes
[x] 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
[x] :book:
My change doesn't require a documentation update, or ...
it does and I have updated it
[x] :balance_scale:
The contribution will be subject to The MIT license, and I'm OK with that.
Description
ICruiseOptions
one can use as input parameter for thecruise
function. This function also sets thevalidate
attribute totrue
if there's a rule set in the config (and tofalse
otherwise), so there's no need to do that anymore either.extractDepcruiseConfig
to what it really returns (anIConfiguration
)Motivation and Context
fixes #932
extractDepcruiseConfig
returns anIConfiguration
object while the cruise function needs anICruiseOptions
. Changing the signature ofextractDepcruiseConfig
would constitute a breaking change - andextractDepcruiseConfig
also has its own uses => we need an additional utility function that translates a dependency-cruiser configuration file into anICruiseOptions
object. This PR adds that.Example
How Has This Been Tested?
Types of changes
Checklist
[x] :book:
[x] :balance_scale: