Comparing version 5.3.0 to 5.4.0
@@ -84,3 +84,3 @@ "use strict"; | ||
var levelUp = path_1.default.resolve(pathName, ".."); | ||
if (path_1.default.relative(levelUp, pathName) === pathName) { | ||
if (path_1.default.relative(levelUp, pathName) === "") { | ||
return undefined; | ||
@@ -87,0 +87,0 @@ } |
@@ -13,2 +13,2 @@ import { ProjectedEdge, ProjectedGraph } from "../../common/projection/projectEdges"; | ||
export declare function gatherViolations(graph: ProjectedEdge[], forbidden: Rule[]): ViolatingEdge[]; | ||
export declare function gatherPositiveViolations(graph: ProjectedGraph, allowed: Rule[]): ViolatingEdge[]; | ||
export declare function gatherPositiveViolations(graph: ProjectedGraph, allowed: Rule[], nodesOfInterest: string[], ignoreNonListed: boolean): ViolatingEdge[]; |
@@ -56,6 +56,10 @@ "use strict"; | ||
exports.gatherViolations = gatherViolations; | ||
function gatherPositiveViolations(graph, allowed) { | ||
function gatherPositiveViolations(graph, allowed, nodesOfInterest, ignoreNonListed) { | ||
var e_3, _a; | ||
var violatingEdges = []; | ||
var _loop_1 = function (edge) { | ||
if (ignoreNonListed && | ||
!(nodesOfInterest.includes(edge.sourceLabel) && nodesOfInterest.includes(edge.targetLabel))) { | ||
return "continue"; | ||
} | ||
var match = allowed.find(function (allowedRule) { | ||
@@ -62,0 +66,0 @@ return edge.sourceLabel === allowedRule.source && edge.targetLabel === allowedRule.target; |
import { Checkable } from "../../common/fluentapi/checkable"; | ||
import { Rule } from "../assertion/admissibleEdges"; | ||
import { Violation } from "../../common/assertion/violation"; | ||
import { MapFunction } from "../../common/projection/projectEdges"; | ||
import { Graph } from "../../common/extraction/graph"; | ||
export declare function slicesOfProject(filename?: string): SliceConditionBuilder; | ||
export declare class SliceConditionBuilder { | ||
readonly filename?: string | undefined; | ||
constructor(filename?: string | undefined); | ||
definedBy(pattern: string): SlicesShouldCondition; | ||
} | ||
export declare class SlicesShouldCondition { | ||
readonly sliceCondition: SliceConditionBuilder; | ||
readonly pattern: string; | ||
constructor(sliceCondition: SliceConditionBuilder, pattern: string); | ||
readonly graphProvider: GraphProvider; | ||
mapFunction: MapFunction; | ||
constructor(graphProvider: GraphProvider); | ||
definedBy(pattern: string): SliceConditionBuilder; | ||
should(): PositiveConditionBuilder; | ||
@@ -18,5 +16,5 @@ shouldNot(): NegativeSliceCondition; | ||
export declare class NegativeSliceCondition implements Checkable { | ||
readonly slicesShouldcondition: SlicesShouldCondition; | ||
readonly sliceConditionBuilder: SliceConditionBuilder; | ||
private readonly forbiddenEdges; | ||
constructor(slicesShouldcondition: SlicesShouldCondition, forbiddenEdges: Rule[]); | ||
constructor(sliceConditionBuilder: SliceConditionBuilder, forbiddenEdges: Rule[]); | ||
containDependency(from: string, to: string): NegativeSliceCondition; | ||
@@ -26,6 +24,10 @@ check(): Promise<Violation[]>; | ||
export declare class PositiveConditionBuilder { | ||
readonly slicesShouldCondition: SlicesShouldCondition; | ||
constructor(slicesShouldCondition: SlicesShouldCondition); | ||
readonly sliceConditionBuilder: SliceConditionBuilder; | ||
ignoreUnknownNodes: boolean; | ||
ignoreExternals: boolean; | ||
constructor(sliceConditionBuilder: SliceConditionBuilder); | ||
adhereToDiagram(diagram: string): PositiveSliceCondition; | ||
adhereToDiagramInFile(filename: string): PositiveSliceCondition; | ||
ignoringUnknownNodes(): PositiveConditionBuilder; | ||
ignoringExternalDependencies(): this; | ||
} | ||
@@ -44,1 +46,4 @@ export declare class PositiveSliceCondition implements Checkable { | ||
} | ||
declare type GraphProvider = () => Promise<Graph>; | ||
export declare function slicesOfNxProject(rootFolder?: string): SliceConditionBuilder; | ||
export {}; |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
@@ -58,10 +77,8 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.PositiveSliceCondition = exports.PositiveConditionBuilder = exports.NegativeSliceCondition = exports.SlicesShouldCondition = exports.SliceConditionBuilder = exports.slicesOfProject = void 0; | ||
exports.slicesOfNxProject = exports.PositiveSliceCondition = exports.PositiveConditionBuilder = exports.NegativeSliceCondition = exports.SliceConditionBuilder = exports.slicesOfProject = void 0; | ||
var generateRules_1 = require("../uml/generateRules"); | ||
var extractGraph_1 = require("../../common/extraction/extractGraph"); | ||
var fs_1 = __importDefault(require("fs")); | ||
var extractNxGraph_1 = require("../../common/extraction/extractNxGraph"); | ||
var fs = __importStar(require("fs")); | ||
var errors_1 = require("../../common/error/errors"); | ||
@@ -72,36 +89,31 @@ var admissibleEdges_1 = require("../assertion/admissibleEdges"); | ||
function slicesOfProject(filename) { | ||
return new SliceConditionBuilder(filename); | ||
var graphProvider = function () { return extractGraph_1.extractGraph(filename); }; | ||
return new SliceConditionBuilder(graphProvider); | ||
} | ||
exports.slicesOfProject = slicesOfProject; | ||
var SliceConditionBuilder = /** @class */ (function () { | ||
function SliceConditionBuilder(filename) { | ||
this.filename = filename; | ||
function SliceConditionBuilder(graphProvider) { | ||
this.graphProvider = graphProvider; | ||
this.mapFunction = slicingProjections_1.identity(); | ||
} | ||
SliceConditionBuilder.prototype.definedBy = function (pattern) { | ||
return new SlicesShouldCondition(this, pattern); | ||
this.mapFunction = slicingProjections_1.sliceByPattern(pattern); | ||
return this; | ||
}; | ||
return SliceConditionBuilder; | ||
}()); | ||
exports.SliceConditionBuilder = SliceConditionBuilder; | ||
var SlicesShouldCondition = /** @class */ (function () { | ||
function SlicesShouldCondition(sliceCondition, pattern) { | ||
this.sliceCondition = sliceCondition; | ||
this.pattern = pattern; | ||
} | ||
SlicesShouldCondition.prototype.should = function () { | ||
SliceConditionBuilder.prototype.should = function () { | ||
return new PositiveConditionBuilder(this); | ||
}; | ||
SlicesShouldCondition.prototype.shouldNot = function () { | ||
SliceConditionBuilder.prototype.shouldNot = function () { | ||
return new NegativeSliceCondition(this, []); | ||
}; | ||
return SlicesShouldCondition; | ||
return SliceConditionBuilder; | ||
}()); | ||
exports.SlicesShouldCondition = SlicesShouldCondition; | ||
exports.SliceConditionBuilder = SliceConditionBuilder; | ||
var NegativeSliceCondition = /** @class */ (function () { | ||
function NegativeSliceCondition(slicesShouldcondition, forbiddenEdges) { | ||
this.slicesShouldcondition = slicesShouldcondition; | ||
function NegativeSliceCondition(sliceConditionBuilder, forbiddenEdges) { | ||
this.sliceConditionBuilder = sliceConditionBuilder; | ||
this.forbiddenEdges = forbiddenEdges; | ||
} | ||
NegativeSliceCondition.prototype.containDependency = function (from, to) { | ||
return new NegativeSliceCondition(this.slicesShouldcondition, __spread(this.forbiddenEdges, [ | ||
return new NegativeSliceCondition(this.sliceConditionBuilder, __spread(this.forbiddenEdges, [ | ||
{ source: from, target: to } | ||
@@ -112,10 +124,9 @@ ])); | ||
return __awaiter(this, void 0, void 0, function () { | ||
var graph, mapFunction, mapped; | ||
var graph, mapped; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, extractGraph_1.extractGraph(this.slicesShouldcondition.sliceCondition.filename)]; | ||
case 0: return [4 /*yield*/, this.sliceConditionBuilder.graphProvider()]; | ||
case 1: | ||
graph = _a.sent(); | ||
mapFunction = slicingProjections_1.sliceByPattern(this.slicesShouldcondition.pattern); | ||
mapped = projectEdges_1.projectEdges(graph, mapFunction); | ||
mapped = projectEdges_1.projectEdges(graph, this.sliceConditionBuilder.mapFunction); | ||
return [2 /*return*/, admissibleEdges_1.gatherViolations(mapped, this.forbiddenEdges)]; | ||
@@ -130,4 +141,6 @@ } | ||
var PositiveConditionBuilder = /** @class */ (function () { | ||
function PositiveConditionBuilder(slicesShouldCondition) { | ||
this.slicesShouldCondition = slicesShouldCondition; | ||
function PositiveConditionBuilder(sliceConditionBuilder) { | ||
this.sliceConditionBuilder = sliceConditionBuilder; | ||
this.ignoreUnknownNodes = false; | ||
this.ignoreExternals = false; | ||
} | ||
@@ -140,2 +153,10 @@ PositiveConditionBuilder.prototype.adhereToDiagram = function (diagram) { | ||
}; | ||
PositiveConditionBuilder.prototype.ignoringUnknownNodes = function () { | ||
this.ignoreUnknownNodes = true; | ||
return this; | ||
}; | ||
PositiveConditionBuilder.prototype.ignoringExternalDependencies = function () { | ||
this.ignoreExternals = true; | ||
return this; | ||
}; | ||
return PositiveConditionBuilder; | ||
@@ -151,8 +172,11 @@ }()); | ||
return __awaiter(this, void 0, void 0, function () { | ||
var graph, diagram, filename, rules, mapFunction, mapped; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, extractGraph_1.extractGraph(this.positiveConditionBuilder.slicesShouldCondition.sliceCondition.filename)]; | ||
var graph, filtered, diagram, filename, _a, rules, containedNodes, mapped; | ||
return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: return [4 /*yield*/, this.positiveConditionBuilder.sliceConditionBuilder.graphProvider()]; | ||
case 1: | ||
graph = _a.sent(); | ||
graph = _b.sent(); | ||
filtered = this.positiveConditionBuilder.ignoreExternals | ||
? graph.filter(function (edge) { return !edge.external; }) | ||
: graph; | ||
diagram = this.diagram.diagram; | ||
@@ -162,3 +186,3 @@ filename = this.diagram.filename; | ||
if (filename !== undefined) { | ||
diagram = fs_1.default.readFileSync(filename).toString(); | ||
diagram = fs.readFileSync(filename).toString(); | ||
} | ||
@@ -169,6 +193,5 @@ else { | ||
} | ||
rules = generateRules_1.generateRule(diagram); | ||
mapFunction = slicingProjections_1.sliceByPattern(this.positiveConditionBuilder.slicesShouldCondition.pattern); | ||
mapped = projectEdges_1.projectEdges(graph, mapFunction); | ||
return [2 /*return*/, admissibleEdges_1.gatherPositiveViolations(mapped, rules)]; | ||
_a = generateRules_1.generateRule(diagram), rules = _a.rules, containedNodes = _a.containedNodes; | ||
mapped = projectEdges_1.projectEdges(filtered, this.positiveConditionBuilder.sliceConditionBuilder.mapFunction); | ||
return [2 /*return*/, admissibleEdges_1.gatherPositiveViolations(mapped, rules, containedNodes, this.positiveConditionBuilder.ignoreUnknownNodes)]; | ||
} | ||
@@ -181,2 +204,9 @@ }); | ||
exports.PositiveSliceCondition = PositiveSliceCondition; | ||
function slicesOfNxProject(rootFolder) { | ||
var graphProvider = function () { | ||
return Promise.resolve(extractNxGraph_1.extractNxGraph(rootFolder)); | ||
}; | ||
return new SliceConditionBuilder(graphProvider); | ||
} | ||
exports.slicesOfNxProject = slicesOfNxProject; | ||
//# sourceMappingURL=slices.js.map |
import { MapFunction } from "../../common/projection/projectEdges"; | ||
export declare function identity(): MapFunction; | ||
export declare function sliceByPattern(pattern: string): MapFunction; | ||
export declare function sliceByRegex(regexp: RegExp): MapFunction; | ||
export declare function sliceByFileSuffix(labeling: Map<string, string>): MapFunction; |
@@ -30,4 +30,13 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.sliceByFileSuffix = exports.sliceByRegex = exports.sliceByPattern = void 0; | ||
exports.sliceByFileSuffix = exports.sliceByRegex = exports.sliceByPattern = exports.identity = void 0; | ||
var arrayUtils_1 = require("../../common/util/arrayUtils"); | ||
function identity() { | ||
return function id(edge) { | ||
return { | ||
sourceLabel: edge.source, | ||
targetLabel: edge.target | ||
}; | ||
}; | ||
} | ||
exports.identity = identity; | ||
function sliceByPattern(pattern) { | ||
@@ -34,0 +43,0 @@ var index = pattern.indexOf("(**)"); |
import { Rule } from "../assertion/admissibleEdges"; | ||
export declare function generateRule(data: string): Rule[]; | ||
export declare function generateRule(data: string): { | ||
rules: Rule[]; | ||
containedNodes: string[]; | ||
}; |
@@ -8,3 +8,3 @@ "use strict"; | ||
var diagram = parsed[0]; | ||
return diagram.elements | ||
var rules = diagram.elements | ||
.map(function (element) { | ||
@@ -19,4 +19,13 @@ if (element instanceof plantuml_parser_1.Relationship) { | ||
.flat(); | ||
var containedNodes = diagram.elements.flatMap(function (element) { | ||
if (element instanceof plantuml_parser_1.Component) { | ||
return [element.name]; | ||
} | ||
else { | ||
return []; | ||
} | ||
}); | ||
return { rules: rules, containedNodes: containedNodes }; | ||
} | ||
exports.generateRule = generateRule; | ||
//# sourceMappingURL=generateRules.js.map |
@@ -8,3 +8,6 @@ "use strict"; | ||
var rules = generateRules_1.generateRule(data); | ||
expect(rules).toContainEqual({ source: "controllers", target: "services" }); | ||
expect(rules).toEqual({ | ||
rules: [{ source: "controllers", target: "services" }], | ||
containedNodes: ["controllers", "services"] | ||
}); | ||
}); | ||
@@ -14,6 +17,6 @@ it("generates more complex rules", function () { | ||
var rules = generateRules_1.generateRule(data); | ||
expect(rules).toContainEqual({ source: "controllers", target: "services" }); | ||
expect(rules).toContainEqual({ source: "services", target: "facades" }); | ||
expect(rules.rules).toContainEqual({ source: "controllers", target: "services" }); | ||
expect(rules.rules).toContainEqual({ source: "services", target: "facades" }); | ||
}); | ||
}); | ||
//# sourceMappingURL=generateRules.spec.js.map |
@@ -204,3 +204,3 @@ "use strict"; | ||
}); }); | ||
it("correctly ignores files exlucded by tsconfig", function () { return __awaiter(void 0, void 0, void 0, function () { | ||
it("correctly ignores files excluded by tsconfig", function () { return __awaiter(void 0, void 0, void 0, function () { | ||
var violations; | ||
@@ -207,0 +207,0 @@ return __generator(this, function (_a) { |
@@ -89,3 +89,3 @@ "use strict"; | ||
sliced = projectEdges_1.projectEdges(graph, mapFunction); | ||
expect(admissibleEdges_1.gatherPositiveViolations(sliced, [])).toEqual([ | ||
expect(admissibleEdges_1.gatherPositiveViolations(sliced, [], ["another", "one"], false)).toEqual([ | ||
{ | ||
@@ -214,3 +214,53 @@ projectedEdge: { | ||
}); }); | ||
it("finds not adherent parts in nx projects", function () { return __awaiter(void 0, void 0, void 0, function () { | ||
var diagram, violations; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
diagram = "\n@startuml\n component [is-even]\n component [is-odd]\n@enduml\n "; | ||
return [4 /*yield*/, slices_1.slicesOfNxProject(__dirname) | ||
.should() | ||
.ignoringExternalDependencies() | ||
.adhereToDiagram(diagram) | ||
.check()]; | ||
case 1: | ||
violations = _a.sent(); | ||
expect(violations).toContainEqual({ | ||
rule: null, | ||
projectedEdge: { | ||
sourceLabel: "is-even", | ||
targetLabel: "is-odd", | ||
cumulatedEdges: [ | ||
{ | ||
source: "is-even", | ||
target: "is-odd", | ||
external: false | ||
} | ||
] | ||
} | ||
}); | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); }); | ||
it("ignores parts not listed in architecture diagram", function () { return __awaiter(void 0, void 0, void 0, function () { | ||
var diagram, violations; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
diagram = "\n@startuml\n component [is-even]\n@enduml\n "; | ||
return [4 /*yield*/, slices_1.slicesOfNxProject(__dirname) | ||
.should() | ||
.ignoringUnknownNodes() | ||
.ignoringExternalDependencies() | ||
.adhereToDiagram(diagram) | ||
.check()]; | ||
case 1: | ||
violations = _a.sent(); | ||
expect(violations).toEqual([]); | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); }); | ||
}); | ||
//# sourceMappingURL=integration.spec.js.map |
{ | ||
"name": "tsarch", | ||
"version": "5.3.0", | ||
"version": "5.4.0", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "keywords": [], |
@@ -95,1 +95,31 @@ # TSArch | ||
begin with `src/...` | ||
## Dependency checks on nx monorepositories | ||
`ts-arch` supports dependency checks on nx monorepositories. It reads the project graph | ||
and makes it accessible for the slices api. | ||
The following example illustrates this: | ||
```typescript | ||
import "tsarch/dist/jest" | ||
import {slicesOfProject} from "tsarch" | ||
import * as path from "path" | ||
describe("architecture", ()=> { | ||
jest.setTimeout(60000); | ||
it('the architecture adheres to the diagram', async () => { | ||
const diagramLocation = path.resolve('docs', 'components.puml'); | ||
const rule = await slicesOfNxProject() | ||
.ignoringExternalDependencies() | ||
.should() | ||
.adhereToDiagramInFile(diagramLocation) | ||
.check() | ||
await expect(rule).toPassAsync() | ||
}); | ||
}) | ||
``` |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
232784
174
3407
125
4