Skip to content

Commit

Permalink
bugfix(cli): adds using the baseDir when checking for file existence (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
sverweij authored Nov 20, 2022
1 parent 0e7b3c2 commit 6c0e2a1
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 6 deletions.
14 changes: 10 additions & 4 deletions src/cli/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const path = require("path");
const glob = require("glob");
const clone = require("lodash/clone");
const set = require("lodash/set");
Expand Down Expand Up @@ -89,14 +90,19 @@ function setUpListener(pCruiseOptions) {
}

function runCruise(pFileDirectoryArray, pCruiseOptions) {
pFileDirectoryArray
.filter((pFileOrDirectory) => !glob.hasMagic(pFileOrDirectory))
.forEach(validateFileExistence);

const lCruiseOptions = addKnownViolations(
normalizeCliOptions(pCruiseOptions)
);

pFileDirectoryArray
.filter((pFileOrDirectory) => !glob.hasMagic(pFileOrDirectory))
.map((pFileOrDirectory) =>
lCruiseOptions?.ruleSet?.options?.baseDir
? path.join(lCruiseOptions.ruleSet.options.baseDir, pFileOrDirectory)
: pFileOrDirectory
)
.forEach(validateFileExistence);

setUpListener(lCruiseOptions);

bus.emit("start");
Expand Down
41 changes: 41 additions & 0 deletions test/cli/__fixtures__/alternate-basedir/expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"modules": [
{
"source": "src/index.ts",
"dependencies": [],
"dependents": [],
"orphan": true,
"valid": true
}
],
"summary": {
"violations": [],
"error": 0,
"warn": 0,
"info": 0,
"ignore": 0,
"totalCruised": 1,
"totalDependenciesCruised": 0,
"optionsUsed": {
"combinedDependencies": false,
"doNotFollow": {
"path": "node_modules"
},
"exoticRequireStrings": [],
"externalModuleResolutionStrategy": "node_modules",
"metrics": false,
"moduleSystems": [
"es6",
"cjs",
"tsd",
"amd"
],
"outputTo": "test/cli/__output__/alternate-basedir.json",
"outputType": "json",
"preserveSymlinks": false,
"tsPreCompilationDeps": false,
"args": "src"
},
"ruleSetUsed": {}
}
}
Empty file.
File renamed without changes.
20 changes: 18 additions & 2 deletions test/cli/index.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import deleteDammit from "./delete-dammit.utl.cjs";
const OUT_DIR = "./test/cli/__output__";
const FIX_DIR = "./test/cli/__fixtures__";

/* eslint max-len:0*/
/* eslint max-len:0 */
const TEST_PAIRS = [
{
description:
Expand Down Expand Up @@ -91,7 +91,7 @@ const TEST_PAIRS = [
outputType: "dot",
exclude: "node_modules",
},
expect: "duplicate-subs.dot",
expect: "duplicate-subs/expected.dot",
cleanup: true,
},
{
Expand All @@ -106,6 +106,22 @@ const TEST_PAIRS = [
expect: "{{moduleType}}.dir.filtered.csv",
cleanup: true,
},
{
description: "alternate basedir",
dirOrFile: "src",
options: {
outputTo: path.join(OUT_DIR, "alternate-basedir.json"),
outputType: "json",
doNotFollow: "node_modules",
ruleSet: {
options: {
baseDir: "test/cli/__fixtures__/alternate-basedir",
},
},
},
expect: "alternate-basedir/expected.json",
cleanup: true,
},
];

function resetOutputDirectory() {
Expand Down

0 comments on commit 6c0e2a1

Please sign in to comment.