@leancodepl/folder-structure-cruiser 10.2.1 → 10.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +25 -0
- package/README.md +2 -2
- package/dist/bin.cjs +1 -1
- package/dist/bin.js +16 -10
- package/dist/commands/validateCrossFeatureImports.d.ts +2 -2
- package/dist/commands/validateCrossFeatureImports.d.ts.map +1 -1
- package/dist/commands/validateSharedComponent.d.ts +2 -2
- package/dist/commands/validateSharedComponent.d.ts.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/validateSharedComponent-CZqzEHqN.js +113 -0
- package/dist/validateSharedComponent-oM_e4L8S.cjs +3 -0
- package/package.json +2 -2
- package/dist/validateSharedComponent-BqvIbK3d.cjs +0 -3
- package/dist/validateSharedComponent-YmSG2wR9.js +0 -118
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,31 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See
|
|
4
4
|
[Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [10.3.1](https://github.com/leancodepl/js_corelibrary/compare/v10.3.0...v10.3.1) (2026-05-20)
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
- cross feature imports test
|
|
11
|
+
([ef8c45a](https://github.com/leancodepl/js_corelibrary/commit/ef8c45adec390da0032987d7bd29338e433e45e1))
|
|
12
|
+
- **folder-structure-cruiser:** address review feedback
|
|
13
|
+
([4714a5b](https://github.com/leancodepl/js_corelibrary/commit/4714a5b8106a670adbfa921742c5ce91fdb334cd))
|
|
14
|
+
- **folder-structure-cruiser:** return non-zero exit code on violations
|
|
15
|
+
([1ad84d5](https://github.com/leancodepl/js_corelibrary/commit/1ad84d5720396e12a1ccc64eacb85fe1e9e034cb))
|
|
16
|
+
|
|
17
|
+
# Change Log
|
|
18
|
+
|
|
19
|
+
All notable changes to this project will be documented in this file. See
|
|
20
|
+
[Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
21
|
+
|
|
22
|
+
# [10.3.0](https://github.com/leancodepl/js_corelibrary/compare/v10.2.1...v10.3.0) (2026-04-16)
|
|
23
|
+
|
|
24
|
+
**Note:** Version bump only for package @leancodepl/folder-structure-cruiser
|
|
25
|
+
|
|
26
|
+
# Change Log
|
|
27
|
+
|
|
28
|
+
All notable changes to this project will be documented in this file. See
|
|
29
|
+
[Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
30
|
+
|
|
6
31
|
## [10.2.1](https://github.com/leancodepl/js_corelibrary/compare/v10.2.0...v10.2.1) (2026-04-13)
|
|
7
32
|
|
|
8
33
|
### Bug Fixes
|
package/README.md
CHANGED
|
@@ -22,7 +22,7 @@ Validates cross-feature nested imports according to folder structure rules.
|
|
|
22
22
|
- `tsConfigPath: string` - Optional path to TypeScript configuration file for enhanced type resolution
|
|
23
23
|
- `webpackConfigPath?: string` - Optional path to webpack configuration file for webpack alias resolution
|
|
24
24
|
|
|
25
|
-
**Returns:** `Promise<
|
|
25
|
+
**Returns:** `Promise<number>` - Number of detected violations
|
|
26
26
|
|
|
27
27
|
**Throws:** `Error` - Throws an error if the dependency analysis fails or configuration is invalid
|
|
28
28
|
|
|
@@ -38,7 +38,7 @@ Validates if shared components are located at the first shared level.
|
|
|
38
38
|
- `tsConfigPath: string` - Optional path to TypeScript configuration file for enhanced type resolution
|
|
39
39
|
- `webpackConfigPath?: string` - Optional path to webpack configuration file for webpack alias resolution
|
|
40
40
|
|
|
41
|
-
**Returns:** `Promise<
|
|
41
|
+
**Returns:** `Promise<number>` - Number of detected violations
|
|
42
42
|
|
|
43
43
|
**Throws:** `Error` - Throws an error if the dependency analysis fails or configuration is invalid
|
|
44
44
|
|
package/dist/bin.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
"use strict";const
|
|
2
|
+
"use strict";const t=require("commander"),r=require("./validateSharedComponent-oM_e4L8S.cjs");t.program.name("folder-structure-cruiser").description("CLI tool for validating folder structure rules");function s(o){o>0&&(process.exitCode=1)}function f(o){r.logger.error(o instanceof Error?o:new Error(String(o))),process.exitCode=1}t.program.command("validate-shared-components").description("Validate if shared components are located at the first shared level").option("-d, --directory <dir>","Directory to analyze",".").option("-c, --config <path_to_config>","Path to config file").option("-t, --tsConfig <path_to_ts_config>","Path to ts config file").option("-w, --webpackConfig <path_to_webpack_config>","Path to webpack config file").action(async o=>{const e=o.directory?[o.directory]:[".*"],i=o.config??"",a=o.tsConfig,n=o.webpackConfig,c=await r.validateSharedComponent({directories:e,configPath:i,tsConfigPath:a,webpackConfigPath:n});s(c)});t.program.command("validate-cross-feature-imports").description("Validate if cross-feature nested imports are allowed").option("-d, --directory <dir>","Directory to analyze",".").option("-c, --config <path_to_config>","Path to config file").option("-t, --tsConfig <path_to_ts_config>","Path to ts config file").option("-w, --webpackConfig <path_to_webpack_config>","Path to webpack config file").action(async o=>{const e=o.directory?[o.directory]:[".*"],i=o.config??"",a=o.tsConfig,n=o.webpackConfig,c=await r.validateCrossFeatureImports({directories:e,configPath:i,tsConfigPath:a,webpackConfigPath:n});s(c)});t.program.parseAsync().catch(f);
|
package/dist/bin.js
CHANGED
|
@@ -1,13 +1,19 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { program as
|
|
3
|
-
import { a as
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
import { program as t } from "commander";
|
|
3
|
+
import { a as s, v as f, l as d } from "./validateSharedComponent-CZqzEHqN.js";
|
|
4
|
+
t.name("folder-structure-cruiser").description("CLI tool for validating folder structure rules");
|
|
5
|
+
function r(o) {
|
|
6
|
+
o > 0 && (process.exitCode = 1);
|
|
7
|
+
}
|
|
8
|
+
function g(o) {
|
|
9
|
+
d.error(o instanceof Error ? o : new Error(String(o))), process.exitCode = 1;
|
|
10
|
+
}
|
|
11
|
+
t.command("validate-shared-components").description("Validate if shared components are located at the first shared level").option("-d, --directory <dir>", "Directory to analyze", ".").option("-c, --config <path_to_config>", "Path to config file").option("-t, --tsConfig <path_to_ts_config>", "Path to ts config file").option("-w, --webpackConfig <path_to_webpack_config>", "Path to webpack config file").action(async (o) => {
|
|
12
|
+
const i = o.directory ? [o.directory] : [".*"], a = o.config ?? "", e = o.tsConfig, n = o.webpackConfig, c = await s({ directories: i, configPath: a, tsConfigPath: e, webpackConfigPath: n });
|
|
13
|
+
r(c);
|
|
8
14
|
});
|
|
9
|
-
|
|
10
|
-
const i =
|
|
11
|
-
|
|
15
|
+
t.command("validate-cross-feature-imports").description("Validate if cross-feature nested imports are allowed").option("-d, --directory <dir>", "Directory to analyze", ".").option("-c, --config <path_to_config>", "Path to config file").option("-t, --tsConfig <path_to_ts_config>", "Path to ts config file").option("-w, --webpackConfig <path_to_webpack_config>", "Path to webpack config file").action(async (o) => {
|
|
16
|
+
const i = o.directory ? [o.directory] : [".*"], a = o.config ?? "", e = o.tsConfig, n = o.webpackConfig, c = await f({ directories: i, configPath: a, tsConfigPath: e, webpackConfigPath: n });
|
|
17
|
+
r(c);
|
|
12
18
|
});
|
|
13
|
-
|
|
19
|
+
t.parseAsync().catch(g);
|
|
@@ -16,7 +16,7 @@ import { CruiseParams } from '../lib/getCruiseResult.js';
|
|
|
16
16
|
* @param cruiseParams.tsConfigPath - Optional path to TypeScript configuration file for enhanced type resolution
|
|
17
17
|
* @param cruiseParams.webpackConfigPath - Optional path to webpack configuration file for webpack alias resolution
|
|
18
18
|
*
|
|
19
|
-
* @returns Promise<
|
|
19
|
+
* @returns Promise<number> - Number of detected violations
|
|
20
20
|
*
|
|
21
21
|
* @throws {Error} - Throws an error if the dependency analysis fails or configuration is invalid
|
|
22
22
|
*
|
|
@@ -56,5 +56,5 @@ import { CruiseParams } from '../lib/getCruiseResult.js';
|
|
|
56
56
|
* }
|
|
57
57
|
* ```
|
|
58
58
|
*/
|
|
59
|
-
export declare function validateCrossFeatureImports(cruiseParams: CruiseParams): Promise<
|
|
59
|
+
export declare function validateCrossFeatureImports(cruiseParams: CruiseParams): Promise<number>;
|
|
60
60
|
//# sourceMappingURL=validateCrossFeatureImports.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validateCrossFeatureImports.d.ts","sourceRoot":"","sources":["../../src/commands/validateCrossFeatureImports.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAmB,MAAM,2BAA2B,CAAA;AAGzE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwDG;AACH,wBAAsB,2BAA2B,CAAC,YAAY,EAAE,YAAY,
|
|
1
|
+
{"version":3,"file":"validateCrossFeatureImports.d.ts","sourceRoot":"","sources":["../../src/commands/validateCrossFeatureImports.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAmB,MAAM,2BAA2B,CAAA;AAGzE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwDG;AACH,wBAAsB,2BAA2B,CAAC,YAAY,EAAE,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC,CAgB7F"}
|
|
@@ -16,7 +16,7 @@ import { CruiseParams } from '../lib/getCruiseResult.js';
|
|
|
16
16
|
* @param cruiseParams.tsConfigPath - Optional path to TypeScript configuration file for enhanced type resolution
|
|
17
17
|
* @param cruiseParams.webpackConfigPath - Optional path to webpack configuration file for webpack alias resolution
|
|
18
18
|
*
|
|
19
|
-
* @returns Promise<
|
|
19
|
+
* @returns Promise<number> - Number of detected violations
|
|
20
20
|
*
|
|
21
21
|
* @throws {Error} - Throws an error if the dependency analysis fails or configuration is invalid
|
|
22
22
|
*
|
|
@@ -56,5 +56,5 @@ import { CruiseParams } from '../lib/getCruiseResult.js';
|
|
|
56
56
|
* }
|
|
57
57
|
* ```
|
|
58
58
|
*/
|
|
59
|
-
export declare function validateSharedComponent(cruiseParams: CruiseParams): Promise<
|
|
59
|
+
export declare function validateSharedComponent(cruiseParams: CruiseParams): Promise<number>;
|
|
60
60
|
//# sourceMappingURL=validateSharedComponent.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validateSharedComponent.d.ts","sourceRoot":"","sources":["../../src/commands/validateSharedComponent.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAmB,MAAM,2BAA2B,CAAA;AAGzE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwDG;AACH,wBAAsB,uBAAuB,CAAC,YAAY,EAAE,YAAY,
|
|
1
|
+
{"version":3,"file":"validateSharedComponent.d.ts","sourceRoot":"","sources":["../../src/commands/validateSharedComponent.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAmB,MAAM,2BAA2B,CAAA;AAGzE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwDG;AACH,wBAAsB,uBAAuB,CAAC,YAAY,EAAE,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC,CAgBzF"}
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./validateSharedComponent-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./validateSharedComponent-oM_e4L8S.cjs");exports.validateCrossFeatureImports=e.validateCrossFeatureImports;exports.validateSharedComponent=e.validateSharedComponent;
|
package/dist/index.js
CHANGED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import C from "chalk";
|
|
2
|
+
import { cruise as x } from "dependency-cruiser";
|
|
3
|
+
import P from "dependency-cruiser/config-utl/extract-depcruise-options";
|
|
4
|
+
import y from "dependency-cruiser/config-utl/extract-ts-config";
|
|
5
|
+
import M from "dependency-cruiser/config-utl/extract-webpack-resolve-config";
|
|
6
|
+
import { createCliLogger as $ } from "@leancodepl/logger/cli";
|
|
7
|
+
function m(e) {
|
|
8
|
+
if (e.length === 0) return [];
|
|
9
|
+
if (e.length === 1) return e[0];
|
|
10
|
+
const s = [], t = Math.min(...e.map((o) => o.length));
|
|
11
|
+
for (let o = 0; o < t; o++) {
|
|
12
|
+
const n = e[0][o];
|
|
13
|
+
if (e.every((r) => r[o] === n))
|
|
14
|
+
s.push(n);
|
|
15
|
+
else
|
|
16
|
+
break;
|
|
17
|
+
}
|
|
18
|
+
return s;
|
|
19
|
+
}
|
|
20
|
+
function g(e) {
|
|
21
|
+
return m(e).length;
|
|
22
|
+
}
|
|
23
|
+
function j(e) {
|
|
24
|
+
const s = typeof e.output == "object" ? e.output : void 0, t = s?.modules ?? [], o = [];
|
|
25
|
+
for (const n of t) {
|
|
26
|
+
if (n.coreModule)
|
|
27
|
+
continue;
|
|
28
|
+
const r = n.dependencies || [], i = n.source.split("/");
|
|
29
|
+
r.forEach((u) => {
|
|
30
|
+
const l = u.resolved.split("/"), c = g([i, l]);
|
|
31
|
+
(!c || c < i.length && l.length > c + 2) && o.push({
|
|
32
|
+
source: n.source,
|
|
33
|
+
target: u.resolved,
|
|
34
|
+
rule: "cross-feature-nested-imports",
|
|
35
|
+
severity: "error"
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
return {
|
|
40
|
+
messages: o,
|
|
41
|
+
totalCruised: s?.summary.totalCruised ?? 0
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
const { bold: d } = C;
|
|
45
|
+
function p(e) {
|
|
46
|
+
return e.map((s) => `${s.rule}: ${d(s.source)} → ${d(s.target)}`);
|
|
47
|
+
}
|
|
48
|
+
async function h({
|
|
49
|
+
directories: e = [".*"],
|
|
50
|
+
configPath: s,
|
|
51
|
+
tsConfigPath: t,
|
|
52
|
+
webpackConfigPath: o
|
|
53
|
+
}) {
|
|
54
|
+
const n = await P(s), r = o ? await M(o) : void 0, i = t ? y(t) : void 0;
|
|
55
|
+
return await x(e, { ...n }, r, {
|
|
56
|
+
tsConfig: i
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
const a = $();
|
|
60
|
+
async function S(e) {
|
|
61
|
+
const s = await h(e), { messages: t, totalCruised: o } = j(s);
|
|
62
|
+
if (t.length === 0 && a.success("✅ No issues found!"), t.length > 0) {
|
|
63
|
+
const n = p(t);
|
|
64
|
+
a.error(n.join(`
|
|
65
|
+
`)), a.error(`Found ${t.length} violation(s). ${o} modules cruised.`);
|
|
66
|
+
}
|
|
67
|
+
return t.length;
|
|
68
|
+
}
|
|
69
|
+
function F(e, s, t) {
|
|
70
|
+
const o = e.at(-1) ?? "";
|
|
71
|
+
if (!/index\.(tsx?|jsx?|ts|js)$/.test(o))
|
|
72
|
+
return !1;
|
|
73
|
+
const n = e.at(-3) ?? "", r = s.at(-1);
|
|
74
|
+
return n === r && t === e.length - 2;
|
|
75
|
+
}
|
|
76
|
+
function L(e) {
|
|
77
|
+
const s = typeof e.output == "object" ? e.output : void 0, t = s?.modules ?? [], o = [];
|
|
78
|
+
for (const n of t) {
|
|
79
|
+
if (n.coreModule)
|
|
80
|
+
continue;
|
|
81
|
+
const r = n.dependents || [];
|
|
82
|
+
if (r.length <= 1)
|
|
83
|
+
continue;
|
|
84
|
+
const i = n.source.split("/"), u = i.length;
|
|
85
|
+
if (u <= 2)
|
|
86
|
+
continue;
|
|
87
|
+
const l = r.map((v) => v.split("/")), c = m(l), f = g([i, c]);
|
|
88
|
+
F(i, c, f) || f < u - 1 && o.push({
|
|
89
|
+
source: n.source,
|
|
90
|
+
target: c.join("/"),
|
|
91
|
+
rule: "not-shared-level",
|
|
92
|
+
severity: "info"
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
return {
|
|
96
|
+
messages: o,
|
|
97
|
+
totalCruised: s?.summary.totalCruised ?? 0
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
async function D(e) {
|
|
101
|
+
const s = await h(e), { messages: t, totalCruised: o } = L(s);
|
|
102
|
+
if (t.length === 0 && a.success("✅ No issues found!"), t.length > 0) {
|
|
103
|
+
const n = p(t);
|
|
104
|
+
a.info(n.join(`
|
|
105
|
+
`)), a.info(`Found ${t.length} violation(s). ${o} modules cruised.`);
|
|
106
|
+
}
|
|
107
|
+
return t.length;
|
|
108
|
+
}
|
|
109
|
+
export {
|
|
110
|
+
D as a,
|
|
111
|
+
a as l,
|
|
112
|
+
S as v
|
|
113
|
+
};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
"use strict";const v=require("chalk"),x=require("dependency-cruiser"),P=require("dependency-cruiser/config-utl/extract-depcruise-options"),y=require("dependency-cruiser/config-utl/extract-ts-config"),F=require("dependency-cruiser/config-utl/extract-webpack-resolve-config"),M=require("@leancodepl/logger/cli");function g(e){if(e.length===0)return[];if(e.length===1)return e[0];const s=[],t=Math.min(...e.map(o=>o.length));for(let o=0;o<t;o++){const n=e[0][o];if(e.every(r=>r[o]===n))s.push(n);else break}return s}function m(e){return g(e).length}function $(e){const s=typeof e.output=="object"?e.output:void 0,t=s?.modules??[],o=[];for(const n of t){if(n.coreModule)continue;const r=n.dependencies||[],i=n.source.split("/");r.forEach(a=>{const l=a.resolved.split("/"),c=m([i,l]);(!c||c<i.length&&l.length>c+2)&&o.push({source:n.source,target:a.resolved,rule:"cross-feature-nested-imports",severity:"error"})})}return{messages:o,totalCruised:s?.summary.totalCruised??0}}const{bold:f}=v;function p(e){return e.map(s=>`${s.rule}: ${f(s.source)} → ${f(s.target)}`)}async function h({directories:e=[".*"],configPath:s,tsConfigPath:t,webpackConfigPath:o}){const n=await P(s),r=o?await F(o):void 0,i=t?y(t):void 0;return await x.cruise(e,{...n},r,{tsConfig:i})}const u=M.createCliLogger();async function j(e){const s=await h(e),{messages:t,totalCruised:o}=$(s);if(t.length===0&&u.success("✅ No issues found!"),t.length>0){const n=p(t);u.error(n.join(`
|
|
2
|
+
`)),u.error(`Found ${t.length} violation(s). ${o} modules cruised.`)}return t.length}function q(e,s,t){const o=e.at(-1)??"";if(!/index\.(tsx?|jsx?|ts|js)$/.test(o))return!1;const n=e.at(-3)??"",r=s.at(-1);return n===r&&t===e.length-2}function L(e){const s=typeof e.output=="object"?e.output:void 0,t=s?.modules??[],o=[];for(const n of t){if(n.coreModule)continue;const r=n.dependents||[];if(r.length<=1)continue;const i=n.source.split("/"),a=i.length;if(a<=2)continue;const l=r.map(C=>C.split("/")),c=g(l),d=m([i,c]);q(i,c,d)||d<a-1&&o.push({source:n.source,target:c.join("/"),rule:"not-shared-level",severity:"info"})}return{messages:o,totalCruised:s?.summary.totalCruised??0}}async function R(e){const s=await h(e),{messages:t,totalCruised:o}=L(s);if(t.length===0&&u.success("✅ No issues found!"),t.length>0){const n=p(t);u.info(n.join(`
|
|
3
|
+
`)),u.info(`Found ${t.length} violation(s). ${o} modules cruised.`)}return t.length}exports.logger=u;exports.validateCrossFeatureImports=j;exports.validateSharedComponent=R;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leancodepl/folder-structure-cruiser",
|
|
3
|
-
"version": "10.
|
|
3
|
+
"version": "10.3.1",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"folder-structure-cruiser": "./dist/bin.js"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@leancodepl/logger": "10.
|
|
22
|
+
"@leancodepl/logger": "10.3.1",
|
|
23
23
|
"chalk": ">=5.0.0",
|
|
24
24
|
"commander": "^14.0.0"
|
|
25
25
|
},
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
"use strict";const v=require("chalk"),x=require("dependency-cruiser"),y=require("dependency-cruiser/config-utl/extract-depcruise-options"),P=require("dependency-cruiser/config-utl/extract-ts-config"),F=require("dependency-cruiser/config-utl/extract-webpack-resolve-config"),M=require("@leancodepl/logger/cli");function m(e){if(e.length===0)return[];if(e.length===1)return e[0];const t=[],s=Math.min(...e.map(o=>o.length));for(let o=0;o<s;o++){const n=e[0][o];if(e.every(r=>r[o]===n))t.push(n);else break}return t}function g(e){return m(e).length}function $(e){const t=typeof e.output=="object"?e.output:void 0,s=t?.modules??[],o=[];for(const n of s){if(n.coreModule)continue;const r=n.dependencies||[],i=n.source.split("/");r.forEach(a=>{const l=a.resolved.split("/"),u=g([i,l]);(!u||u<i.length&&l.length>u+2)&&o.push({source:n.source,target:a.resolved,rule:"cross-feature-nested-imports",severity:"error"})})}return{messages:o,totalCruised:t?.summary.totalCruised??0}}const{bold:f}=v;function p(e){return e.map(t=>`${t.rule}: ${f(t.source)} → ${f(t.target)}`)}async function h({directories:e=[".*"],configPath:t,tsConfigPath:s,webpackConfigPath:o}){const n=await y(t),r=o?await F(o):void 0,i=s?P(s):void 0;return await x.cruise(e,{...n},r,{tsConfig:i})}const c=M.createCliLogger();async function j(e){try{const t=await h(e),{messages:s,totalCruised:o}=$(t);if(s.length===0&&c.success("✅ No issues found!"),s.length>0){const n=p(s);c.error(n.join(`
|
|
2
|
-
`)),c.error(`Found ${s.length} violations(s). ${o} modules cruised.`)}}catch(t){c.error(t)}}function q(e,t,s){const o=e.at(-1)??"";if(!/index\.(tsx?|jsx?|ts|js)$/.test(o))return!1;const n=e.at(-3)??"",r=t.at(-1);return n===r&&s===e.length-2}function L(e){const t=typeof e.output=="object"?e.output:void 0,s=t?.modules??[],o=[];for(const n of s){if(n.coreModule)continue;const r=n.dependents||[];if(r.length<=1)continue;const i=n.source.split("/"),a=i.length;if(a<=2)continue;const l=r.map(C=>C.split("/")),u=m(l),d=g([i,u]);q(i,u,d)||d<a-1&&o.push({source:n.source,target:u.join("/"),rule:"not-shared-level",severity:"info"})}return{messages:o,totalCruised:t?.summary.totalCruised??0}}async function R(e){try{const t=await h(e),{messages:s,totalCruised:o}=L(t);if(s.length===0&&c.success("✅ No issues found!"),s.length>0){const n=p(s);c.info(n.join(`
|
|
3
|
-
`)),c.info(`Found ${s.length} violations(s). ${o} modules cruised.`)}}catch(t){c.error(t)}}exports.validateCrossFeatureImports=j;exports.validateSharedComponent=R;
|
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
import C from "chalk";
|
|
2
|
-
import { cruise as x } from "dependency-cruiser";
|
|
3
|
-
import P from "dependency-cruiser/config-utl/extract-depcruise-options";
|
|
4
|
-
import y from "dependency-cruiser/config-utl/extract-ts-config";
|
|
5
|
-
import M from "dependency-cruiser/config-utl/extract-webpack-resolve-config";
|
|
6
|
-
import { createCliLogger as $ } from "@leancodepl/logger/cli";
|
|
7
|
-
function m(e) {
|
|
8
|
-
if (e.length === 0) return [];
|
|
9
|
-
if (e.length === 1) return e[0];
|
|
10
|
-
const t = [], s = Math.min(...e.map((o) => o.length));
|
|
11
|
-
for (let o = 0; o < s; o++) {
|
|
12
|
-
const n = e[0][o];
|
|
13
|
-
if (e.every((r) => r[o] === n))
|
|
14
|
-
t.push(n);
|
|
15
|
-
else
|
|
16
|
-
break;
|
|
17
|
-
}
|
|
18
|
-
return t;
|
|
19
|
-
}
|
|
20
|
-
function p(e) {
|
|
21
|
-
return m(e).length;
|
|
22
|
-
}
|
|
23
|
-
function j(e) {
|
|
24
|
-
const t = typeof e.output == "object" ? e.output : void 0, s = t?.modules ?? [], o = [];
|
|
25
|
-
for (const n of s) {
|
|
26
|
-
if (n.coreModule)
|
|
27
|
-
continue;
|
|
28
|
-
const r = n.dependencies || [], i = n.source.split("/");
|
|
29
|
-
r.forEach((a) => {
|
|
30
|
-
const l = a.resolved.split("/"), u = p([i, l]);
|
|
31
|
-
(!u || u < i.length && l.length > u + 2) && o.push({
|
|
32
|
-
source: n.source,
|
|
33
|
-
target: a.resolved,
|
|
34
|
-
rule: "cross-feature-nested-imports",
|
|
35
|
-
severity: "error"
|
|
36
|
-
});
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
return {
|
|
40
|
-
messages: o,
|
|
41
|
-
totalCruised: t?.summary.totalCruised ?? 0
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
const { bold: d } = C;
|
|
45
|
-
function g(e) {
|
|
46
|
-
return e.map((t) => `${t.rule}: ${d(t.source)} → ${d(t.target)}`);
|
|
47
|
-
}
|
|
48
|
-
async function h({
|
|
49
|
-
directories: e = [".*"],
|
|
50
|
-
configPath: t,
|
|
51
|
-
tsConfigPath: s,
|
|
52
|
-
webpackConfigPath: o
|
|
53
|
-
}) {
|
|
54
|
-
const n = await P(t), r = o ? await M(o) : void 0, i = s ? y(s) : void 0;
|
|
55
|
-
return await x(e, { ...n }, r, {
|
|
56
|
-
tsConfig: i
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
const c = $();
|
|
60
|
-
async function N(e) {
|
|
61
|
-
try {
|
|
62
|
-
const t = await h(e), { messages: s, totalCruised: o } = j(t);
|
|
63
|
-
if (s.length === 0 && c.success("✅ No issues found!"), s.length > 0) {
|
|
64
|
-
const n = g(s);
|
|
65
|
-
c.error(n.join(`
|
|
66
|
-
`)), c.error(`Found ${s.length} violations(s). ${o} modules cruised.`);
|
|
67
|
-
}
|
|
68
|
-
} catch (t) {
|
|
69
|
-
c.error(t);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
function F(e, t, s) {
|
|
73
|
-
const o = e.at(-1) ?? "";
|
|
74
|
-
if (!/index\.(tsx?|jsx?|ts|js)$/.test(o))
|
|
75
|
-
return !1;
|
|
76
|
-
const n = e.at(-3) ?? "", r = t.at(-1);
|
|
77
|
-
return n === r && s === e.length - 2;
|
|
78
|
-
}
|
|
79
|
-
function L(e) {
|
|
80
|
-
const t = typeof e.output == "object" ? e.output : void 0, s = t?.modules ?? [], o = [];
|
|
81
|
-
for (const n of s) {
|
|
82
|
-
if (n.coreModule)
|
|
83
|
-
continue;
|
|
84
|
-
const r = n.dependents || [];
|
|
85
|
-
if (r.length <= 1)
|
|
86
|
-
continue;
|
|
87
|
-
const i = n.source.split("/"), a = i.length;
|
|
88
|
-
if (a <= 2)
|
|
89
|
-
continue;
|
|
90
|
-
const l = r.map((v) => v.split("/")), u = m(l), f = p([i, u]);
|
|
91
|
-
F(i, u, f) || f < a - 1 && o.push({
|
|
92
|
-
source: n.source,
|
|
93
|
-
target: u.join("/"),
|
|
94
|
-
rule: "not-shared-level",
|
|
95
|
-
severity: "info"
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
return {
|
|
99
|
-
messages: o,
|
|
100
|
-
totalCruised: t?.summary.totalCruised ?? 0
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
async function S(e) {
|
|
104
|
-
try {
|
|
105
|
-
const t = await h(e), { messages: s, totalCruised: o } = L(t);
|
|
106
|
-
if (s.length === 0 && c.success("✅ No issues found!"), s.length > 0) {
|
|
107
|
-
const n = g(s);
|
|
108
|
-
c.info(n.join(`
|
|
109
|
-
`)), c.info(`Found ${s.length} violations(s). ${o} modules cruised.`);
|
|
110
|
-
}
|
|
111
|
-
} catch (t) {
|
|
112
|
-
c.error(t);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
export {
|
|
116
|
-
S as a,
|
|
117
|
-
N as v
|
|
118
|
-
};
|