dependency-cruiser-fork
Version:
Validate and visualize dependencies. With your rules. JavaScript, TypeScript, CoffeeScript. ES6, CommonJS, AMD.
47 lines (43 loc) • 1.35 kB
JavaScript
const $dependencyCruiserManifest = require("../../../package.json");
const {
getSourceFolderCandidates,
getTestFolderCandidates,
hasTestsWithinSource,
toSourceLocationArray,
} = require("./environment-helpers");
function populate(pInitOptions) {
return {
version: $dependencyCruiserManifest.version,
date: new Date().toJSON(),
configType: "self-contained",
...pInitOptions,
sourceLocation: toSourceLocationArray(
pInitOptions.sourceLocation || getSourceFolderCandidates()
),
testLocation: pInitOptions.isMonoRepo
? []
: toSourceLocationArray(
pInitOptions.testLocation || getTestFolderCandidates()
),
};
}
module.exports = function normalizeInitOptions(pInitOptions) {
let lReturnValue = populate(pInitOptions);
if (lReturnValue.configType === "preset" && !lReturnValue.preset) {
lReturnValue.preset = "dependency-cruiser/configs/recommended-warn-only";
}
if (lReturnValue.useYarnPnP) {
lReturnValue.externalModuleResolutionStrategy = "yarn-pnp";
}
if (
!Object.prototype.hasOwnProperty.call(lReturnValue, "hasTestsOutsideSource")
) {
lReturnValue.hasTestsOutsideSource =
!pInitOptions.isMonoRepo &&
!hasTestsWithinSource(
lReturnValue.testLocation,
lReturnValue.sourceLocation
);
}
return lReturnValue;
};