@webpieces/dev-config 0.2.38 → 0.2.39
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/architecture/executors/validate-architecture-unchanged/executor.js +166 -2
- package/architecture/executors/validate-architecture-unchanged/executor.js.map +1 -1
- package/architecture/executors/validate-architecture-unchanged/executor.ts +172 -2
- package/eslint-plugin/rules/enforce-architecture.js +12 -3
- package/eslint-plugin/rules/enforce-architecture.js.map +1 -1
- package/eslint-plugin/rules/enforce-architecture.ts +12 -3
- package/package.json +1 -1
- package/plugin.js +21 -0
|
@@ -10,10 +10,164 @@
|
|
|
10
10
|
*/
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.default = runExecutor;
|
|
13
|
+
const tslib_1 = require("tslib");
|
|
14
|
+
const fs = tslib_1.__importStar(require("fs"));
|
|
15
|
+
const path = tslib_1.__importStar(require("path"));
|
|
13
16
|
const graph_generator_1 = require("../../lib/graph-generator");
|
|
14
17
|
const graph_sorter_1 = require("../../lib/graph-sorter");
|
|
15
18
|
const graph_comparator_1 = require("../../lib/graph-comparator");
|
|
16
19
|
const graph_loader_1 = require("../../lib/graph-loader");
|
|
20
|
+
const TMP_DIR = 'tmp/webpieces';
|
|
21
|
+
const TMP_MD_FILE = 'webpieces.dependencies.md';
|
|
22
|
+
const DEPENDENCIES_DOC_CONTENT = `# Instructions: Architecture Dependency Violation
|
|
23
|
+
|
|
24
|
+
IN GENERAL, it is better to avoid these changes and find a different way by moving classes
|
|
25
|
+
around to existing packages you already depend on. It is not always avoidable though.
|
|
26
|
+
A clean dependency graph keeps you out of huge trouble later.
|
|
27
|
+
|
|
28
|
+
If you are a human, simply run these commands:
|
|
29
|
+
* nx run architecture:visualize - to see the new dependencies and validate that change is desired
|
|
30
|
+
* nx run architecture:generate - updates the dep graph
|
|
31
|
+
* git diff architecture/dependencies.json - to see the deps changes you made
|
|
32
|
+
|
|
33
|
+
**READ THIS FILE FIRST before making any changes!**
|
|
34
|
+
|
|
35
|
+
## ⚠️ CRITICAL WARNING ⚠️
|
|
36
|
+
|
|
37
|
+
**This is a VERY IMPORTANT change that has LARGE REPERCUSSIONS later!**
|
|
38
|
+
|
|
39
|
+
Adding new dependencies creates technical debt that compounds over time:
|
|
40
|
+
- Creates coupling between packages that may be hard to undo
|
|
41
|
+
- Can create circular dependency tangles
|
|
42
|
+
- Makes packages harder to test in isolation
|
|
43
|
+
- Increases build times and bundle sizes
|
|
44
|
+
- May force unnecessary upgrades across the codebase
|
|
45
|
+
|
|
46
|
+
**DO NOT add dependencies without senior developer approval!**
|
|
47
|
+
|
|
48
|
+
## Understanding the Error
|
|
49
|
+
|
|
50
|
+
You've attempted to import from a package that is not in your project's allowed dependencies.
|
|
51
|
+
The architecture enforces a layered dependency structure where:
|
|
52
|
+
- Level 0 packages are foundation packages with NO dependencies on other @webpieces packages
|
|
53
|
+
- Higher level packages can only depend on lower level packages
|
|
54
|
+
- All dependencies must be explicitly declared
|
|
55
|
+
|
|
56
|
+
## Steps to Resolve
|
|
57
|
+
|
|
58
|
+
### Step 1: Generate Current Dependency Graph
|
|
59
|
+
Run this command to see the current architecture:
|
|
60
|
+
\`\`\`bash
|
|
61
|
+
npx nx run architecture:generate
|
|
62
|
+
\`\`\`
|
|
63
|
+
This creates/updates \`architecture/dependencies.json\` showing all packages and their levels.
|
|
64
|
+
|
|
65
|
+
### Step 2: Analyze the Proposed Change
|
|
66
|
+
Ask yourself:
|
|
67
|
+
1. **Is this import truly necessary?** Can you refactor to avoid it?
|
|
68
|
+
2. **Should the code move instead?** Maybe the code belongs in a different package.
|
|
69
|
+
3. **Will this create a cycle?** Use \`npx nx graph\` to visualize dependencies.
|
|
70
|
+
4. **Can you use an interface/abstraction?** Define interface in lower-level package, implement in higher-level.
|
|
71
|
+
|
|
72
|
+
### Step 3: Get Senior Developer Approval
|
|
73
|
+
|
|
74
|
+
## 🛑 AI AGENTS: STOP HERE AND ASK FOR HUMAN APPROVAL! 🛑
|
|
75
|
+
|
|
76
|
+
**YOU MUST NOT PROCEED TO STEP 4 WITHOUT EXPLICIT HUMAN APPROVAL!**
|
|
77
|
+
|
|
78
|
+
**REQUIRED**: Discuss this architectural change with a senior developer before proceeding.
|
|
79
|
+
- Explain why the dependency is needed
|
|
80
|
+
- Show you've considered alternatives (Step 2)
|
|
81
|
+
- **WAIT for explicit approval before making ANY changes to project.json or package.json**
|
|
82
|
+
|
|
83
|
+
**AI Agent Instructions:**
|
|
84
|
+
1. Present your analysis from Step 2 to the human
|
|
85
|
+
2. Explain which package needs which dependency and why
|
|
86
|
+
3. ASK: "Do you approve adding this dependency?"
|
|
87
|
+
4. **DO NOT modify project.json or package.json until you receive explicit "yes" or approval**
|
|
88
|
+
|
|
89
|
+
### Step 4: If Approved, Add the Dependency
|
|
90
|
+
|
|
91
|
+
## ⛔ NEVER MODIFY THESE FILES WITHOUT HUMAN APPROVAL FROM STEP 3! ⛔
|
|
92
|
+
|
|
93
|
+
Only after receiving explicit human approval in Step 3, make these changes:
|
|
94
|
+
|
|
95
|
+
1. **Update project.json** - Add to \`build.dependsOn\`:
|
|
96
|
+
\`\`\`json
|
|
97
|
+
{
|
|
98
|
+
"targets": {
|
|
99
|
+
"build": {
|
|
100
|
+
"dependsOn": ["^build", "dep1:build", "NEW_PACKAGE:build"]
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
\`\`\`
|
|
105
|
+
|
|
106
|
+
2. **Update package.json** - Add to \`dependencies\`:
|
|
107
|
+
\`\`\`json
|
|
108
|
+
{
|
|
109
|
+
"dependencies": {
|
|
110
|
+
"@webpieces/NEW_PACKAGE": "*"
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
\`\`\`
|
|
114
|
+
|
|
115
|
+
### Step 5: Update Architecture Definition
|
|
116
|
+
Run this command to validate and update the architecture:
|
|
117
|
+
\`\`\`bash
|
|
118
|
+
npx nx run architecture:generate
|
|
119
|
+
\`\`\`
|
|
120
|
+
|
|
121
|
+
This will:
|
|
122
|
+
- Detect any cycles (which MUST be fixed before proceeding)
|
|
123
|
+
- Update \`architecture/dependencies.json\` with the new dependency
|
|
124
|
+
- Recalculate package levels
|
|
125
|
+
|
|
126
|
+
### Step 6: Verify No Cycles
|
|
127
|
+
\`\`\`bash
|
|
128
|
+
npx nx run architecture:validate-no-cycles
|
|
129
|
+
\`\`\`
|
|
130
|
+
|
|
131
|
+
If cycles are detected, you MUST refactor to break the cycle. Common strategies:
|
|
132
|
+
- Move shared code to a lower-level package
|
|
133
|
+
- Use dependency inversion (interfaces in low-level, implementations in high-level)
|
|
134
|
+
- Restructure package boundaries
|
|
135
|
+
|
|
136
|
+
## Alternative Solutions (Preferred over adding dependencies)
|
|
137
|
+
|
|
138
|
+
### Option A: Move the Code
|
|
139
|
+
If you need functionality from another package, consider moving that code to a shared lower-level package.
|
|
140
|
+
|
|
141
|
+
### Option B: Dependency Inversion
|
|
142
|
+
Define an interface in the lower-level package, implement it in the higher-level package:
|
|
143
|
+
\`\`\`typescript
|
|
144
|
+
// In foundation package (level 0)
|
|
145
|
+
export interface Logger { log(msg: string): void; }
|
|
146
|
+
|
|
147
|
+
// In higher-level package
|
|
148
|
+
export class ConsoleLogger implements Logger { ... }
|
|
149
|
+
\`\`\`
|
|
150
|
+
|
|
151
|
+
### Option C: Pass Dependencies as Parameters
|
|
152
|
+
Instead of importing, receive the dependency as a constructor or method parameter.
|
|
153
|
+
|
|
154
|
+
## Remember
|
|
155
|
+
- Every dependency you add today is technical debt for tomorrow
|
|
156
|
+
- The best dependency is the one you don't need
|
|
157
|
+
- When in doubt, refactor rather than add dependencies
|
|
158
|
+
`;
|
|
159
|
+
/**
|
|
160
|
+
* Write the instructions documentation to tmp directory
|
|
161
|
+
*/
|
|
162
|
+
function writeTmpInstructionsFile(workspaceRoot) {
|
|
163
|
+
const tmpDir = path.join(workspaceRoot, TMP_DIR);
|
|
164
|
+
const mdPath = path.join(tmpDir, TMP_MD_FILE);
|
|
165
|
+
// Ensure tmp directory exists
|
|
166
|
+
fs.mkdirSync(tmpDir, { recursive: true });
|
|
167
|
+
// Write documentation MD file
|
|
168
|
+
fs.writeFileSync(mdPath, DEPENDENCIES_DOC_CONTENT);
|
|
169
|
+
return mdPath;
|
|
170
|
+
}
|
|
17
171
|
async function runExecutor(options, context) {
|
|
18
172
|
const { graphPath } = options;
|
|
19
173
|
const workspaceRoot = context.root;
|
|
@@ -22,7 +176,12 @@ async function runExecutor(options, context) {
|
|
|
22
176
|
// Check if saved graph exists
|
|
23
177
|
if (!(0, graph_loader_1.graphFileExists)(workspaceRoot, graphPath)) {
|
|
24
178
|
console.error('❌ No saved graph found at architecture/dependencies.json');
|
|
25
|
-
console.error('
|
|
179
|
+
console.error('');
|
|
180
|
+
console.error('To initialize:');
|
|
181
|
+
console.error(' 1. Run: nx run architecture:generate');
|
|
182
|
+
console.error(' 2. Run: nx run architecture:visualize');
|
|
183
|
+
console.error(' 3. Manually inspect the generated graph to confirm it is the desired architecture');
|
|
184
|
+
console.error(' 4. Commit architecture/dependencies.json');
|
|
26
185
|
return { success: false };
|
|
27
186
|
}
|
|
28
187
|
// Step 1: Generate current graph from project.json files
|
|
@@ -46,10 +205,15 @@ async function runExecutor(options, context) {
|
|
|
46
205
|
return { success: true };
|
|
47
206
|
}
|
|
48
207
|
else {
|
|
208
|
+
// Write instructions file for AI agent
|
|
209
|
+
const mdPath = writeTmpInstructionsFile(workspaceRoot);
|
|
49
210
|
console.error('❌ Architecture has changed since last update!');
|
|
50
211
|
console.error('\nDifferences:');
|
|
51
212
|
console.error(comparison.summary);
|
|
52
|
-
console.error('
|
|
213
|
+
console.error('');
|
|
214
|
+
console.error('⚠️ *** Refer to ' + mdPath + ' for instructions on how to fix *** ⚠️');
|
|
215
|
+
console.error('');
|
|
216
|
+
console.error('To fix:');
|
|
53
217
|
console.error(' 1. Review the changes above');
|
|
54
218
|
console.error(' 2. If intentional, ASK USER to run: nx run architecture:generate since this is a critical change');
|
|
55
219
|
console.error(' 3. Commit the updated architecture/dependencies.json');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"executor.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/dev-config/architecture/executors/validate-architecture-unchanged/executor.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG;;AAgBH,8BAwDC;AArED,+DAA0D;AAC1D,yDAAgE;AAChE,iEAA2D;AAC3D,yDAA2E;AAU5D,KAAK,UAAU,WAAW,CACrC,OAA6C,EAC7C,OAAwB;IAExB,MAAM,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC;IAC9B,MAAM,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;IAEnC,OAAO,CAAC,GAAG,CAAC,0CAA0C,CAAC,CAAC;IAExD,IAAI,CAAC;QACD,8BAA8B;QAC9B,IAAI,CAAC,IAAA,8BAAe,EAAC,aAAa,EAAE,SAAS,CAAC,EAAE,CAAC;YAC7C,OAAO,CAAC,KAAK,CAAC,0DAA0D,CAAC,CAAC;YAC1E,OAAO,CAAC,KAAK,CAAC,4CAA4C,CAAC,CAAC;YAC5D,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;QAC9B,CAAC;QAED,yDAAyD;QACzD,OAAO,CAAC,GAAG,CAAC,2CAA2C,CAAC,CAAC;QACzD,MAAM,QAAQ,GAAG,MAAM,IAAA,+BAAa,GAAE,CAAC;QAEvC,+DAA+D;QAC/D,OAAO,CAAC,GAAG,CAAC,oCAAoC,CAAC,CAAC;QAClD,MAAM,YAAY,GAAG,IAAA,qCAAsB,EAAC,QAAQ,CAAC,CAAC;QAEtD,2BAA2B;QAC3B,OAAO,CAAC,GAAG,CAAC,2BAA2B,CAAC,CAAC;QACzC,MAAM,UAAU,GAAG,IAAA,+BAAgB,EAAC,aAAa,EAAE,SAAS,CAAC,CAAC;QAE9D,IAAI,CAAC,UAAU,EAAE,CAAC;YACd,OAAO,CAAC,KAAK,CAAC,8BAA8B,CAAC,CAAC;YAC9C,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;QAC9B,CAAC;QAED,yBAAyB;QACzB,OAAO,CAAC,GAAG,CAAC,8CAA8C,CAAC,CAAC;QAC5D,MAAM,UAAU,GAAG,IAAA,gCAAa,EAAC,YAAY,EAAE,UAAU,CAAC,CAAC;QAE3D,IAAI,UAAU,CAAC,SAAS,EAAE,CAAC;YACvB,OAAO,CAAC,GAAG,CAAC,8DAA8D,CAAC,CAAC;YAC5E,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;QAC7B,CAAC;aAAM,CAAC;YACJ,OAAO,CAAC,KAAK,CAAC,+CAA+C,CAAC,CAAC;YAC/D,OAAO,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC;YAChC,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;YAClC,OAAO,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;YAC3B,OAAO,CAAC,KAAK,CAAC,+BAA+B,CAAC,CAAC;YAC/C,OAAO,CAAC,KAAK,CAAC,oGAAoG,CAAC,CAAC;YACpH,OAAO,CAAC,KAAK,CAAC,wDAAwD,CAAC,CAAC;YACxE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;QAC9B,CAAC;IACL,CAAC;IAAC,OAAO,GAAY,EAAE,CAAC;QACpB,MAAM,KAAK,GAAG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;QAClE,OAAO,CAAC,KAAK,CAAC,mCAAmC,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;QAClE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;IAC9B,CAAC;AACL,CAAC","sourcesContent":["/**\n * Validate Architecture Unchanged Executor\n *\n * Validates that the current architecture graph matches the saved blessed graph.\n * This ensures no unapproved architecture changes have been made.\n *\n * Usage:\n * nx run architecture:validate-architecture-unchanged\n */\n\nimport type { ExecutorContext } from '@nx/devkit';\nimport { generateGraph } from '../../lib/graph-generator';\nimport { sortGraphTopologically } from '../../lib/graph-sorter';\nimport { compareGraphs } from '../../lib/graph-comparator';\nimport { loadBlessedGraph, graphFileExists } from '../../lib/graph-loader';\n\nexport interface ValidateArchitectureUnchangedOptions {\n graphPath?: string;\n}\n\nexport interface ExecutorResult {\n success: boolean;\n}\n\nexport default async function runExecutor(\n options: ValidateArchitectureUnchangedOptions,\n context: ExecutorContext\n): Promise<ExecutorResult> {\n const { graphPath } = options;\n const workspaceRoot = context.root;\n\n console.log('\\n🔍 Validating Architecture Unchanged\\n');\n\n try {\n // Check if saved graph exists\n if (!graphFileExists(workspaceRoot, graphPath)) {\n console.error('❌ No saved graph found at architecture/dependencies.json');\n console.error(' Run: nx run architecture:generate first');\n return { success: false };\n }\n\n // Step 1: Generate current graph from project.json files\n console.log('📊 Generating current dependency graph...');\n const rawGraph = await generateGraph();\n\n // Step 2: Topological sort (to get enhanced graph with levels)\n console.log('🔄 Computing topological layers...');\n const currentGraph = sortGraphTopologically(rawGraph);\n\n // Step 3: Load saved graph\n console.log('📂 Loading saved graph...');\n const savedGraph = loadBlessedGraph(workspaceRoot, graphPath);\n\n if (!savedGraph) {\n console.error('❌ Could not load saved graph');\n return { success: false };\n }\n\n // Step 4: Compare graphs\n console.log('🔍 Comparing current graph to saved graph...');\n const comparison = compareGraphs(currentGraph, savedGraph);\n\n if (comparison.identical) {\n console.log('✅ Architecture unchanged - current graph matches saved graph');\n return { success: true };\n } else {\n console.error('❌ Architecture has changed since last update!');\n console.error('\\nDifferences:');\n console.error(comparison.summary);\n console.error('\\nTo fix:');\n console.error(' 1. Review the changes above');\n console.error(' 2. If intentional, ASK USER to run: nx run architecture:generate since this is a critical change');\n console.error(' 3. Commit the updated architecture/dependencies.json');\n return { success: false };\n }\n } catch (err: unknown) {\n const error = err instanceof Error ? err : new Error(String(err));\n console.error('❌ Architecture validation failed:', error.message);\n return { success: false };\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"executor.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/dev-config/architecture/executors/validate-architecture-unchanged/executor.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG;;AA+KH,8BAmEC;;AA/OD,+CAAyB;AACzB,mDAA6B;AAC7B,+DAA0D;AAC1D,yDAAgE;AAChE,iEAA2D;AAC3D,yDAA2E;AAU3E,MAAM,OAAO,GAAG,eAAe,CAAC;AAChC,MAAM,WAAW,GAAG,2BAA2B,CAAC;AAEhD,MAAM,wBAAwB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAwIhC,CAAC;AAEF;;GAEG;AACH,SAAS,wBAAwB,CAAC,aAAqB;IACnD,MAAM,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC;IACjD,MAAM,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;IAE9C,8BAA8B;IAC9B,EAAE,CAAC,SAAS,CAAC,MAAM,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAE1C,8BAA8B;IAC9B,EAAE,CAAC,aAAa,CAAC,MAAM,EAAE,wBAAwB,CAAC,CAAC;IAEnD,OAAO,MAAM,CAAC;AAClB,CAAC;AAEc,KAAK,UAAU,WAAW,CACrC,OAA6C,EAC7C,OAAwB;IAExB,MAAM,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC;IAC9B,MAAM,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;IAEnC,OAAO,CAAC,GAAG,CAAC,0CAA0C,CAAC,CAAC;IAExD,IAAI,CAAC;QACD,8BAA8B;QAC9B,IAAI,CAAC,IAAA,8BA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AAC;YAC5E,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;QAC7B,CAAC;aAAM,CAAC;YACJ,uCAAuC;YACvC,MAAM,MAAM,GAAG,wBAAwB,CAAC,aAAa,CAAC,CAAC;YAEvD,OAAO,CAAC,KAAK,CAAC,+CAA+C,CAAC,CAAC;YAC/D,OAAO,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC;YAChC,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;YAClC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;YAClB,OAAO,CAAC,KAAK,CAAC,mBAAmB,GAAG,MAAM,GAAG,wCAAwC,CAAC,CAAC;YACvF,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;YAClB,OAAO,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;YACzB,OAAO,CAAC,KAAK,CAAC,+BAA+B,CAAC,CAAC;YAC/C,OAAO,CAAC,KAAK,CAAC,oGAAoG,CAAC,CAAC;YACpH,OAAO,CAAC,KAAK,CAAC,wDAAwD,CAAC,CAAC;YACxE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;QAC9B,CAAC;IACL,CAAC;IAAC,OAAO,GAAY,EAAE,CAAC;QACpB,MAAM,KAAK,GAAG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;QAClE,OAAO,CAAC,KAAK,CAAC,mCAAmC,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;QAClE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;IAC9B,CAAC;AACL,CAAC","sourcesContent":["/**\n * Validate Architecture Unchanged Executor\n *\n * Validates that the current architecture graph matches the saved blessed graph.\n * This ensures no unapproved architecture changes have been made.\n *\n * Usage:\n * nx run architecture:validate-architecture-unchanged\n */\n\nimport type { ExecutorContext } from '@nx/devkit';\nimport * as fs from 'fs';\nimport * as path from 'path';\nimport { generateGraph } from '../../lib/graph-generator';\nimport { sortGraphTopologically } from '../../lib/graph-sorter';\nimport { compareGraphs } from '../../lib/graph-comparator';\nimport { loadBlessedGraph, graphFileExists } from '../../lib/graph-loader';\n\nexport interface ValidateArchitectureUnchangedOptions {\n graphPath?: string;\n}\n\nexport interface ExecutorResult {\n success: boolean;\n}\n\nconst TMP_DIR = 'tmp/webpieces';\nconst TMP_MD_FILE = 'webpieces.dependencies.md';\n\nconst DEPENDENCIES_DOC_CONTENT = `# Instructions: Architecture Dependency Violation\n\nIN GENERAL, it is better to avoid these changes and find a different way by moving classes\naround to existing packages you already depend on. It is not always avoidable though.\nA clean dependency graph keeps you out of huge trouble later.\n\nIf you are a human, simply run these commands:\n* nx run architecture:visualize - to see the new dependencies and validate that change is desired\n* nx run architecture:generate - updates the dep graph\n* git diff architecture/dependencies.json - to see the deps changes you made\n\n**READ THIS FILE FIRST before making any changes!**\n\n## ⚠️ CRITICAL WARNING ⚠️\n\n**This is a VERY IMPORTANT change that has LARGE REPERCUSSIONS later!**\n\nAdding new dependencies creates technical debt that compounds over time:\n- Creates coupling between packages that may be hard to undo\n- Can create circular dependency tangles\n- Makes packages harder to test in isolation\n- Increases build times and bundle sizes\n- May force unnecessary upgrades across the codebase\n\n**DO NOT add dependencies without senior developer approval!**\n\n## Understanding the Error\n\nYou've attempted to import from a package that is not in your project's allowed dependencies.\nThe architecture enforces a layered dependency structure where:\n- Level 0 packages are foundation packages with NO dependencies on other @webpieces packages\n- Higher level packages can only depend on lower level packages\n- All dependencies must be explicitly declared\n\n## Steps to Resolve\n\n### Step 1: Generate Current Dependency Graph\nRun this command to see the current architecture:\n\\`\\`\\`bash\nnpx nx run architecture:generate\n\\`\\`\\`\nThis creates/updates \\`architecture/dependencies.json\\` showing all packages and their levels.\n\n### Step 2: Analyze the Proposed Change\nAsk yourself:\n1. **Is this import truly necessary?** Can you refactor to avoid it?\n2. **Should the code move instead?** Maybe the code belongs in a different package.\n3. **Will this create a cycle?** Use \\`npx nx graph\\` to visualize dependencies.\n4. **Can you use an interface/abstraction?** Define interface in lower-level package, implement in higher-level.\n\n### Step 3: Get Senior Developer Approval\n\n## 🛑 AI AGENTS: STOP HERE AND ASK FOR HUMAN APPROVAL! 🛑\n\n**YOU MUST NOT PROCEED TO STEP 4 WITHOUT EXPLICIT HUMAN APPROVAL!**\n\n**REQUIRED**: Discuss this architectural change with a senior developer before proceeding.\n- Explain why the dependency is needed\n- Show you've considered alternatives (Step 2)\n- **WAIT for explicit approval before making ANY changes to project.json or package.json**\n\n**AI Agent Instructions:**\n1. Present your analysis from Step 2 to the human\n2. Explain which package needs which dependency and why\n3. ASK: \"Do you approve adding this dependency?\"\n4. **DO NOT modify project.json or package.json until you receive explicit \"yes\" or approval**\n\n### Step 4: If Approved, Add the Dependency\n\n## ⛔ NEVER MODIFY THESE FILES WITHOUT HUMAN APPROVAL FROM STEP 3! ⛔\n\nOnly after receiving explicit human approval in Step 3, make these changes:\n\n1. **Update project.json** - Add to \\`build.dependsOn\\`:\n \\`\\`\\`json\n {\n \"targets\": {\n \"build\": {\n \"dependsOn\": [\"^build\", \"dep1:build\", \"NEW_PACKAGE:build\"]\n }\n }\n }\n \\`\\`\\`\n\n2. **Update package.json** - Add to \\`dependencies\\`:\n \\`\\`\\`json\n {\n \"dependencies\": {\n \"@webpieces/NEW_PACKAGE\": \"*\"\n }\n }\n \\`\\`\\`\n\n### Step 5: Update Architecture Definition\nRun this command to validate and update the architecture:\n\\`\\`\\`bash\nnpx nx run architecture:generate\n\\`\\`\\`\n\nThis will:\n- Detect any cycles (which MUST be fixed before proceeding)\n- Update \\`architecture/dependencies.json\\` with the new dependency\n- Recalculate package levels\n\n### Step 6: Verify No Cycles\n\\`\\`\\`bash\nnpx nx run architecture:validate-no-cycles\n\\`\\`\\`\n\nIf cycles are detected, you MUST refactor to break the cycle. Common strategies:\n- Move shared code to a lower-level package\n- Use dependency inversion (interfaces in low-level, implementations in high-level)\n- Restructure package boundaries\n\n## Alternative Solutions (Preferred over adding dependencies)\n\n### Option A: Move the Code\nIf you need functionality from another package, consider moving that code to a shared lower-level package.\n\n### Option B: Dependency Inversion\nDefine an interface in the lower-level package, implement it in the higher-level package:\n\\`\\`\\`typescript\n// In foundation package (level 0)\nexport interface Logger { log(msg: string): void; }\n\n// In higher-level package\nexport class ConsoleLogger implements Logger { ... }\n\\`\\`\\`\n\n### Option C: Pass Dependencies as Parameters\nInstead of importing, receive the dependency as a constructor or method parameter.\n\n## Remember\n- Every dependency you add today is technical debt for tomorrow\n- The best dependency is the one you don't need\n- When in doubt, refactor rather than add dependencies\n`;\n\n/**\n * Write the instructions documentation to tmp directory\n */\nfunction writeTmpInstructionsFile(workspaceRoot: string): string {\n const tmpDir = path.join(workspaceRoot, TMP_DIR);\n const mdPath = path.join(tmpDir, TMP_MD_FILE);\n\n // Ensure tmp directory exists\n fs.mkdirSync(tmpDir, { recursive: true });\n\n // Write documentation MD file\n fs.writeFileSync(mdPath, DEPENDENCIES_DOC_CONTENT);\n\n return mdPath;\n}\n\nexport default async function runExecutor(\n options: ValidateArchitectureUnchangedOptions,\n context: ExecutorContext\n): Promise<ExecutorResult> {\n const { graphPath } = options;\n const workspaceRoot = context.root;\n\n console.log('\\n🔍 Validating Architecture Unchanged\\n');\n\n try {\n // Check if saved graph exists\n if (!graphFileExists(workspaceRoot, graphPath)) {\n console.error('❌ No saved graph found at architecture/dependencies.json');\n console.error('');\n console.error('To initialize:');\n console.error(' 1. Run: nx run architecture:generate');\n console.error(' 2. Run: nx run architecture:visualize');\n console.error(' 3. Manually inspect the generated graph to confirm it is the desired architecture');\n console.error(' 4. Commit architecture/dependencies.json');\n return { success: false };\n }\n\n // Step 1: Generate current graph from project.json files\n console.log('📊 Generating current dependency graph...');\n const rawGraph = await generateGraph();\n\n // Step 2: Topological sort (to get enhanced graph with levels)\n console.log('🔄 Computing topological layers...');\n const currentGraph = sortGraphTopologically(rawGraph);\n\n // Step 3: Load saved graph\n console.log('📂 Loading saved graph...');\n const savedGraph = loadBlessedGraph(workspaceRoot, graphPath);\n\n if (!savedGraph) {\n console.error('❌ Could not load saved graph');\n return { success: false };\n }\n\n // Step 4: Compare graphs\n console.log('🔍 Comparing current graph to saved graph...');\n const comparison = compareGraphs(currentGraph, savedGraph);\n\n if (comparison.identical) {\n console.log('✅ Architecture unchanged - current graph matches saved graph');\n return { success: true };\n } else {\n // Write instructions file for AI agent\n const mdPath = writeTmpInstructionsFile(workspaceRoot);\n\n console.error('❌ Architecture has changed since last update!');\n console.error('\\nDifferences:');\n console.error(comparison.summary);\n console.error('');\n console.error('⚠️ *** Refer to ' + mdPath + ' for instructions on how to fix *** ⚠️');\n console.error('');\n console.error('To fix:');\n console.error(' 1. Review the changes above');\n console.error(' 2. If intentional, ASK USER to run: nx run architecture:generate since this is a critical change');\n console.error(' 3. Commit the updated architecture/dependencies.json');\n return { success: false };\n }\n } catch (err: unknown) {\n const error = err instanceof Error ? err : new Error(String(err));\n console.error('❌ Architecture validation failed:', error.message);\n return { success: false };\n }\n}\n"]}
|
|
@@ -9,6 +9,8 @@
|
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
import type { ExecutorContext } from '@nx/devkit';
|
|
12
|
+
import * as fs from 'fs';
|
|
13
|
+
import * as path from 'path';
|
|
12
14
|
import { generateGraph } from '../../lib/graph-generator';
|
|
13
15
|
import { sortGraphTopologically } from '../../lib/graph-sorter';
|
|
14
16
|
import { compareGraphs } from '../../lib/graph-comparator';
|
|
@@ -22,6 +24,163 @@ export interface ExecutorResult {
|
|
|
22
24
|
success: boolean;
|
|
23
25
|
}
|
|
24
26
|
|
|
27
|
+
const TMP_DIR = 'tmp/webpieces';
|
|
28
|
+
const TMP_MD_FILE = 'webpieces.dependencies.md';
|
|
29
|
+
|
|
30
|
+
const DEPENDENCIES_DOC_CONTENT = `# Instructions: Architecture Dependency Violation
|
|
31
|
+
|
|
32
|
+
IN GENERAL, it is better to avoid these changes and find a different way by moving classes
|
|
33
|
+
around to existing packages you already depend on. It is not always avoidable though.
|
|
34
|
+
A clean dependency graph keeps you out of huge trouble later.
|
|
35
|
+
|
|
36
|
+
If you are a human, simply run these commands:
|
|
37
|
+
* nx run architecture:visualize - to see the new dependencies and validate that change is desired
|
|
38
|
+
* nx run architecture:generate - updates the dep graph
|
|
39
|
+
* git diff architecture/dependencies.json - to see the deps changes you made
|
|
40
|
+
|
|
41
|
+
**READ THIS FILE FIRST before making any changes!**
|
|
42
|
+
|
|
43
|
+
## ⚠️ CRITICAL WARNING ⚠️
|
|
44
|
+
|
|
45
|
+
**This is a VERY IMPORTANT change that has LARGE REPERCUSSIONS later!**
|
|
46
|
+
|
|
47
|
+
Adding new dependencies creates technical debt that compounds over time:
|
|
48
|
+
- Creates coupling between packages that may be hard to undo
|
|
49
|
+
- Can create circular dependency tangles
|
|
50
|
+
- Makes packages harder to test in isolation
|
|
51
|
+
- Increases build times and bundle sizes
|
|
52
|
+
- May force unnecessary upgrades across the codebase
|
|
53
|
+
|
|
54
|
+
**DO NOT add dependencies without senior developer approval!**
|
|
55
|
+
|
|
56
|
+
## Understanding the Error
|
|
57
|
+
|
|
58
|
+
You've attempted to import from a package that is not in your project's allowed dependencies.
|
|
59
|
+
The architecture enforces a layered dependency structure where:
|
|
60
|
+
- Level 0 packages are foundation packages with NO dependencies on other @webpieces packages
|
|
61
|
+
- Higher level packages can only depend on lower level packages
|
|
62
|
+
- All dependencies must be explicitly declared
|
|
63
|
+
|
|
64
|
+
## Steps to Resolve
|
|
65
|
+
|
|
66
|
+
### Step 1: Generate Current Dependency Graph
|
|
67
|
+
Run this command to see the current architecture:
|
|
68
|
+
\`\`\`bash
|
|
69
|
+
npx nx run architecture:generate
|
|
70
|
+
\`\`\`
|
|
71
|
+
This creates/updates \`architecture/dependencies.json\` showing all packages and their levels.
|
|
72
|
+
|
|
73
|
+
### Step 2: Analyze the Proposed Change
|
|
74
|
+
Ask yourself:
|
|
75
|
+
1. **Is this import truly necessary?** Can you refactor to avoid it?
|
|
76
|
+
2. **Should the code move instead?** Maybe the code belongs in a different package.
|
|
77
|
+
3. **Will this create a cycle?** Use \`npx nx graph\` to visualize dependencies.
|
|
78
|
+
4. **Can you use an interface/abstraction?** Define interface in lower-level package, implement in higher-level.
|
|
79
|
+
|
|
80
|
+
### Step 3: Get Senior Developer Approval
|
|
81
|
+
|
|
82
|
+
## 🛑 AI AGENTS: STOP HERE AND ASK FOR HUMAN APPROVAL! 🛑
|
|
83
|
+
|
|
84
|
+
**YOU MUST NOT PROCEED TO STEP 4 WITHOUT EXPLICIT HUMAN APPROVAL!**
|
|
85
|
+
|
|
86
|
+
**REQUIRED**: Discuss this architectural change with a senior developer before proceeding.
|
|
87
|
+
- Explain why the dependency is needed
|
|
88
|
+
- Show you've considered alternatives (Step 2)
|
|
89
|
+
- **WAIT for explicit approval before making ANY changes to project.json or package.json**
|
|
90
|
+
|
|
91
|
+
**AI Agent Instructions:**
|
|
92
|
+
1. Present your analysis from Step 2 to the human
|
|
93
|
+
2. Explain which package needs which dependency and why
|
|
94
|
+
3. ASK: "Do you approve adding this dependency?"
|
|
95
|
+
4. **DO NOT modify project.json or package.json until you receive explicit "yes" or approval**
|
|
96
|
+
|
|
97
|
+
### Step 4: If Approved, Add the Dependency
|
|
98
|
+
|
|
99
|
+
## ⛔ NEVER MODIFY THESE FILES WITHOUT HUMAN APPROVAL FROM STEP 3! ⛔
|
|
100
|
+
|
|
101
|
+
Only after receiving explicit human approval in Step 3, make these changes:
|
|
102
|
+
|
|
103
|
+
1. **Update project.json** - Add to \`build.dependsOn\`:
|
|
104
|
+
\`\`\`json
|
|
105
|
+
{
|
|
106
|
+
"targets": {
|
|
107
|
+
"build": {
|
|
108
|
+
"dependsOn": ["^build", "dep1:build", "NEW_PACKAGE:build"]
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
\`\`\`
|
|
113
|
+
|
|
114
|
+
2. **Update package.json** - Add to \`dependencies\`:
|
|
115
|
+
\`\`\`json
|
|
116
|
+
{
|
|
117
|
+
"dependencies": {
|
|
118
|
+
"@webpieces/NEW_PACKAGE": "*"
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
\`\`\`
|
|
122
|
+
|
|
123
|
+
### Step 5: Update Architecture Definition
|
|
124
|
+
Run this command to validate and update the architecture:
|
|
125
|
+
\`\`\`bash
|
|
126
|
+
npx nx run architecture:generate
|
|
127
|
+
\`\`\`
|
|
128
|
+
|
|
129
|
+
This will:
|
|
130
|
+
- Detect any cycles (which MUST be fixed before proceeding)
|
|
131
|
+
- Update \`architecture/dependencies.json\` with the new dependency
|
|
132
|
+
- Recalculate package levels
|
|
133
|
+
|
|
134
|
+
### Step 6: Verify No Cycles
|
|
135
|
+
\`\`\`bash
|
|
136
|
+
npx nx run architecture:validate-no-cycles
|
|
137
|
+
\`\`\`
|
|
138
|
+
|
|
139
|
+
If cycles are detected, you MUST refactor to break the cycle. Common strategies:
|
|
140
|
+
- Move shared code to a lower-level package
|
|
141
|
+
- Use dependency inversion (interfaces in low-level, implementations in high-level)
|
|
142
|
+
- Restructure package boundaries
|
|
143
|
+
|
|
144
|
+
## Alternative Solutions (Preferred over adding dependencies)
|
|
145
|
+
|
|
146
|
+
### Option A: Move the Code
|
|
147
|
+
If you need functionality from another package, consider moving that code to a shared lower-level package.
|
|
148
|
+
|
|
149
|
+
### Option B: Dependency Inversion
|
|
150
|
+
Define an interface in the lower-level package, implement it in the higher-level package:
|
|
151
|
+
\`\`\`typescript
|
|
152
|
+
// In foundation package (level 0)
|
|
153
|
+
export interface Logger { log(msg: string): void; }
|
|
154
|
+
|
|
155
|
+
// In higher-level package
|
|
156
|
+
export class ConsoleLogger implements Logger { ... }
|
|
157
|
+
\`\`\`
|
|
158
|
+
|
|
159
|
+
### Option C: Pass Dependencies as Parameters
|
|
160
|
+
Instead of importing, receive the dependency as a constructor or method parameter.
|
|
161
|
+
|
|
162
|
+
## Remember
|
|
163
|
+
- Every dependency you add today is technical debt for tomorrow
|
|
164
|
+
- The best dependency is the one you don't need
|
|
165
|
+
- When in doubt, refactor rather than add dependencies
|
|
166
|
+
`;
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Write the instructions documentation to tmp directory
|
|
170
|
+
*/
|
|
171
|
+
function writeTmpInstructionsFile(workspaceRoot: string): string {
|
|
172
|
+
const tmpDir = path.join(workspaceRoot, TMP_DIR);
|
|
173
|
+
const mdPath = path.join(tmpDir, TMP_MD_FILE);
|
|
174
|
+
|
|
175
|
+
// Ensure tmp directory exists
|
|
176
|
+
fs.mkdirSync(tmpDir, { recursive: true });
|
|
177
|
+
|
|
178
|
+
// Write documentation MD file
|
|
179
|
+
fs.writeFileSync(mdPath, DEPENDENCIES_DOC_CONTENT);
|
|
180
|
+
|
|
181
|
+
return mdPath;
|
|
182
|
+
}
|
|
183
|
+
|
|
25
184
|
export default async function runExecutor(
|
|
26
185
|
options: ValidateArchitectureUnchangedOptions,
|
|
27
186
|
context: ExecutorContext
|
|
@@ -35,7 +194,12 @@ export default async function runExecutor(
|
|
|
35
194
|
// Check if saved graph exists
|
|
36
195
|
if (!graphFileExists(workspaceRoot, graphPath)) {
|
|
37
196
|
console.error('❌ No saved graph found at architecture/dependencies.json');
|
|
38
|
-
console.error('
|
|
197
|
+
console.error('');
|
|
198
|
+
console.error('To initialize:');
|
|
199
|
+
console.error(' 1. Run: nx run architecture:generate');
|
|
200
|
+
console.error(' 2. Run: nx run architecture:visualize');
|
|
201
|
+
console.error(' 3. Manually inspect the generated graph to confirm it is the desired architecture');
|
|
202
|
+
console.error(' 4. Commit architecture/dependencies.json');
|
|
39
203
|
return { success: false };
|
|
40
204
|
}
|
|
41
205
|
|
|
@@ -64,10 +228,16 @@ export default async function runExecutor(
|
|
|
64
228
|
console.log('✅ Architecture unchanged - current graph matches saved graph');
|
|
65
229
|
return { success: true };
|
|
66
230
|
} else {
|
|
231
|
+
// Write instructions file for AI agent
|
|
232
|
+
const mdPath = writeTmpInstructionsFile(workspaceRoot);
|
|
233
|
+
|
|
67
234
|
console.error('❌ Architecture has changed since last update!');
|
|
68
235
|
console.error('\nDifferences:');
|
|
69
236
|
console.error(comparison.summary);
|
|
70
|
-
console.error('
|
|
237
|
+
console.error('');
|
|
238
|
+
console.error('⚠️ *** Refer to ' + mdPath + ' for instructions on how to fix *** ⚠️');
|
|
239
|
+
console.error('');
|
|
240
|
+
console.error('To fix:');
|
|
71
241
|
console.error(' 1. Review the changes above');
|
|
72
242
|
console.error(' 2. If intentional, ASK USER to run: nx run architecture:generate since this is a critical change');
|
|
73
243
|
console.error(' 3. Commit the updated architecture/dependencies.json');
|
|
@@ -14,7 +14,16 @@
|
|
|
14
14
|
const tslib_1 = require("tslib");
|
|
15
15
|
const fs = tslib_1.__importStar(require("fs"));
|
|
16
16
|
const path = tslib_1.__importStar(require("path"));
|
|
17
|
-
const DEPENDENCIES_DOC_CONTENT = `#
|
|
17
|
+
const DEPENDENCIES_DOC_CONTENT = `# Instructions: Architecture Dependency Violation
|
|
18
|
+
|
|
19
|
+
IN GENERAL, it is better to avoid these changes and find a different way by moving classes
|
|
20
|
+
around to existing packages you already depend on. It is not always avoidable though.
|
|
21
|
+
A clean dependency graph keeps you out of huge trouble later.
|
|
22
|
+
|
|
23
|
+
If you are a human, simply run these commands:
|
|
24
|
+
* nx run architecture:visualize - to see the new dependencies and validate that change is desired
|
|
25
|
+
* nx run architecture:generate - updates the dep graph
|
|
26
|
+
* git diff architecture/dependencies.json - to see the deps changes you made
|
|
18
27
|
|
|
19
28
|
**READ THIS FILE FIRST before making any changes!**
|
|
20
29
|
|
|
@@ -101,7 +110,7 @@ Only after receiving explicit human approval in Step 3, make these changes:
|
|
|
101
110
|
### Step 5: Update Architecture Definition
|
|
102
111
|
Run this command to validate and update the architecture:
|
|
103
112
|
\`\`\`bash
|
|
104
|
-
npx nx run architecture:
|
|
113
|
+
npx nx run architecture:generate
|
|
105
114
|
\`\`\`
|
|
106
115
|
|
|
107
116
|
This will:
|
|
@@ -111,7 +120,7 @@ This will:
|
|
|
111
120
|
|
|
112
121
|
### Step 6: Verify No Cycles
|
|
113
122
|
\`\`\`bash
|
|
114
|
-
npx nx run architecture:validate
|
|
123
|
+
npx nx run architecture:validate-no-cycles
|
|
115
124
|
\`\`\`
|
|
116
125
|
|
|
117
126
|
If cycles are detected, you MUST refactor to break the cycle. Common strategies:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"enforce-architecture.js","sourceRoot":"","sources":["../../../../../../packages/tooling/dev-config/eslint-plugin/rules/enforce-architecture.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;GAWG;;AAGH,+CAAyB;AACzB,mDAA6B;AAE7B,MAAM,wBAAwB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA+HhC,CAAC;AAEF,uDAAuD;AACvD,IAAI,sBAAsB,GAAG,KAAK,CAAC;AAEnC;;GAEG;AACH,SAAS,aAAa,CAAC,OAAe,EAAE,OAAe;IACnD,IAAI,CAAC;QACD,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QACzD,EAAE,CAAC,aAAa,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;QAC5C,OAAO,IAAI,CAAC;IAChB,CAAC;IAAC,OAAO,GAAQ,EAAE,CAAC;QAChB,KAAK,GAAG,CAAC;QACT,OAAO,CAAC,IAAI,CAAC,0CAA0C,OAAO,EAAE,CAAC,CAAC;QAClE,OAAO,KAAK,CAAC;IACjB,CAAC;AACL,CAAC;AAED;;;GAGG;AACH,SAAS,qBAAqB,CAAC,aAAqB;IAChD,IAAI,sBAAsB;QAAE,OAAO;IACnC,MA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E,CAAC;oBAChD,MAAM,WAAW,GACb,UAAU,CAAC,MAAM,GAAG,CAAC;wBACjB,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,OAAO,GAAG,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;4BAChD,yCAAyC;wBAC3C,CAAC,CAAC,yCAAyC,CAAC;oBAEpD,OAAO,CAAC,MAAM,CAAC;wBACX,IAAI,EAAE,IAAI,CAAC,MAAM;wBACjB,SAAS,EAAE,eAAe;wBAC1B,IAAI,EAAE;4BACF,QAAQ,EAAE,UAAU;4BACpB,OAAO,EAAE,aAAa;4BACtB,KAAK,EAAE,MAAM,CAAC,YAAY,CAAC,KAAK,CAAC;4BACjC,WAAW,EAAE,WAAW;yBAC3B;qBACJ,CAAC,CAAC;gBACP,CAAC;YACL,CAAC;SACJ,CAAC;IACN,CAAC;CACJ,CAAC;AAEF,iBAAS,IAAI,CAAC","sourcesContent":["/**\n * ESLint rule to enforce architecture boundaries\n *\n * Validates that imports from @webpieces/* packages comply with the\n * blessed dependency graph in .graphs/dependencies.json\n *\n * Supports transitive dependencies: if A depends on B and B depends on C,\n * then A can import from C.\n *\n * Configuration:\n * '@webpieces/enforce-architecture': 'error'\n */\n\nimport type { Rule } from 'eslint';\nimport * as fs from 'fs';\nimport * as path from 'path';\n\nconst DEPENDENCIES_DOC_CONTENT = `# AI Agent Instructions: Architecture Dependency Violation\n\n**READ THIS FILE FIRST before making any changes!**\n\n## ⚠️ CRITICAL WARNING ⚠️\n\n**This is a VERY IMPORTANT change that has LARGE REPERCUSSIONS later!**\n\nAdding new dependencies creates technical debt that compounds over time:\n- Creates coupling between packages that may be hard to undo\n- Can create circular dependency tangles\n- Makes packages harder to test in isolation\n- Increases build times and bundle sizes\n- May force unnecessary upgrades across the codebase\n\n**DO NOT add dependencies without senior developer approval!**\n\n## Understanding the Error\n\nYou've attempted to import from a package that is not in your project's allowed dependencies.\nThe architecture enforces a layered dependency structure where:\n- Level 0 packages are foundation packages with NO dependencies on other @webpieces packages\n- Higher level packages can only depend on lower level packages\n- All dependencies must be explicitly declared\n\n## Steps to Resolve\n\n### Step 1: Generate Current Dependency Graph\nRun this command to see the current architecture:\n\\`\\`\\`bash\nnpx nx run architecture:generate\n\\`\\`\\`\nThis creates/updates \\`architecture/dependencies.json\\` showing all packages and their levels.\n\n### Step 2: Analyze the Proposed Change\nAsk yourself:\n1. **Is this import truly necessary?** Can you refactor to avoid it?\n2. **Should the code move instead?** Maybe the code belongs in a different package.\n3. **Will this create a cycle?** Use \\`npx nx graph\\` to visualize dependencies.\n4. **Can you use an interface/abstraction?** Define interface in lower-level package, implement in higher-level.\n\n### Step 3: Get Senior Developer Approval\n\n## 🛑 AI AGENTS: STOP HERE AND ASK FOR HUMAN APPROVAL! 🛑\n\n**YOU MUST NOT PROCEED TO STEP 4 WITHOUT EXPLICIT HUMAN APPROVAL!**\n\n**REQUIRED**: Discuss this architectural change with a senior developer before proceeding.\n- Explain why the dependency is needed\n- Show you've considered alternatives (Step 2)\n- **WAIT for explicit approval before making ANY changes to project.json or package.json**\n\n**AI Agent Instructions:**\n1. Present your analysis from Step 2 to the human\n2. Explain which package needs which dependency and why\n3. ASK: \"Do you approve adding this dependency?\"\n4. **DO NOT modify project.json or package.json until you receive explicit \"yes\" or approval**\n\n### Step 4: If Approved, Add the Dependency\n\n## ⛔ NEVER MODIFY THESE FILES WITHOUT HUMAN APPROVAL FROM STEP 3! ⛔\n\nOnly after receiving explicit human approval in Step 3, make these changes:\n\n1. **Update project.json** - Add to \\`build.dependsOn\\`:\n \\`\\`\\`json\n {\n \"targets\": {\n \"build\": {\n \"dependsOn\": [\"^build\", \"dep1:build\", \"NEW_PACKAGE:build\"]\n }\n }\n }\n \\`\\`\\`\n\n2. **Update package.json** - Add to \\`dependencies\\`:\n \\`\\`\\`json\n {\n \"dependencies\": {\n \"@webpieces/NEW_PACKAGE\": \"*\"\n }\n }\n \\`\\`\\`\n\n### Step 5: Update Architecture Definition\nRun this command to validate and update the architecture:\n\\`\\`\\`bash\nnpx nx run architecture:validate --mode=update\n\\`\\`\\`\n\nThis will:\n- Detect any cycles (which MUST be fixed before proceeding)\n- Update \\`architecture/dependencies.json\\` with the new dependency\n- Recalculate package levels\n\n### Step 6: Verify No Cycles\n\\`\\`\\`bash\nnpx nx run architecture:validate\n\\`\\`\\`\n\nIf cycles are detected, you MUST refactor to break the cycle. Common strategies:\n- Move shared code to a lower-level package\n- Use dependency inversion (interfaces in low-level, implementations in high-level)\n- Restructure package boundaries\n\n## Alternative Solutions (Preferred over adding dependencies)\n\n### Option A: Move the Code\nIf you need functionality from another package, consider moving that code to a shared lower-level package.\n\n### Option B: Dependency Inversion\nDefine an interface in the lower-level package, implement it in the higher-level package:\n\\`\\`\\`typescript\n// In foundation package (level 0)\nexport interface Logger { log(msg: string): void; }\n\n// In higher-level package\nexport class ConsoleLogger implements Logger { ... }\n\\`\\`\\`\n\n### Option C: Pass Dependencies as Parameters\nInstead of importing, receive the dependency as a constructor or method parameter.\n\n## Remember\n- Every dependency you add today is technical debt for tomorrow\n- The best dependency is the one you don't need\n- When in doubt, refactor rather than add dependencies\n`;\n\n// Module-level flag to prevent redundant file creation\nlet dependenciesDocCreated = false;\n\n/**\n * Ensure a documentation file exists at the given path.\n */\nfunction ensureDocFile(docPath: string, content: string): boolean {\n try {\n fs.mkdirSync(path.dirname(docPath), { recursive: true });\n fs.writeFileSync(docPath, content, 'utf-8');\n return true;\n } catch (err: any) {\n void err;\n console.warn(`[webpieces] Could not create doc file: ${docPath}`);\n return false;\n }\n}\n\n/**\n * Ensure the dependencies documentation file exists.\n * Called when an architecture violation is detected.\n */\nfunction ensureDependenciesDoc(workspaceRoot: string): void {\n if (dependenciesDocCreated) return;\n const docPath = path.join(workspaceRoot, 'tmp', 'webpieces', 'webpieces.dependencies.md');\n if (ensureDocFile(docPath, DEPENDENCIES_DOC_CONTENT)) {\n dependenciesDocCreated = true;\n }\n}\n\n/**\n * Graph entry format from .graphs/dependencies.json\n */\ninterface GraphEntry {\n level: number;\n dependsOn: string[];\n}\n\ntype EnhancedGraph = Record<string, GraphEntry>;\n\n/**\n * Project mapping entry\n */\ninterface ProjectMapping {\n root: string;\n name: string;\n}\n\n// Cache for blessed graph (loaded once per lint run)\nlet cachedGraph: EnhancedGraph | null = null;\nlet cachedGraphPath: string | null = null;\n\n// Cache for project mappings\nlet cachedProjectMappings: ProjectMapping[] | null = null;\n\n/**\n * Find workspace root by walking up from file location\n */\nfunction findWorkspaceRoot(startPath: string): string {\n let currentDir = path.dirname(startPath);\n\n for (let i = 0; i < 20; i++) {\n const packagePath = path.join(currentDir, 'package.json');\n if (fs.existsSync(packagePath)) {\n try {\n const pkg = JSON.parse(fs.readFileSync(packagePath, 'utf-8'));\n if (pkg.workspaces || pkg.name === 'webpieces-ts') {\n return currentDir;\n }\n } catch (err: any) {\n //const error = toError(err);\n void err;\n }\n }\n\n const parent = path.dirname(currentDir);\n if (parent === currentDir) break;\n currentDir = parent;\n }\n\n return process.cwd();\n}\n\n/**\n * Load blessed graph from architecture/dependencies.json\n */\nfunction loadBlessedGraph(workspaceRoot: string): EnhancedGraph | null {\n const graphPath = path.join(workspaceRoot, 'architecture', 'dependencies.json');\n\n // Return cached if same path\n if (cachedGraphPath === graphPath && cachedGraph !== null) {\n return cachedGraph;\n }\n\n if (!fs.existsSync(graphPath)) {\n return null;\n }\n\n try {\n const content = fs.readFileSync(graphPath, 'utf-8');\n cachedGraph = JSON.parse(content) as EnhancedGraph;\n cachedGraphPath = graphPath;\n return cachedGraph;\n } catch (err: any) {\n //const error = toError(err);\n // err is used below\n console.error(`[ESLint @webpieces/enforce-architecture] Could not load graph: ${err}`);\n return null;\n }\n}\n\n/**\n * Build set of all workspace package names (from package.json files)\n * Used to detect workspace imports (works for any scope or unscoped)\n */\nfunction buildWorkspacePackageNames(workspaceRoot: string): Set<string> {\n const packageNames = new Set<string>();\n const mappings = buildProjectMappings(workspaceRoot);\n\n for (const mapping of mappings) {\n const pkgJsonPath = path.join(workspaceRoot, mapping.root, 'package.json');\n if (fs.existsSync(pkgJsonPath)) {\n try {\n const pkgJson = JSON.parse(fs.readFileSync(pkgJsonPath, 'utf-8'));\n if (pkgJson.name) {\n packageNames.add(pkgJson.name);\n }\n } catch {\n // Ignore parse errors\n }\n }\n }\n\n return packageNames;\n}\n\n/**\n * Check if an import path is a workspace project\n * Works for scoped (@scope/name) or unscoped (name) packages\n */\nfunction isWorkspaceImport(importPath: string, workspaceRoot: string): boolean {\n const workspacePackages = buildWorkspacePackageNames(workspaceRoot);\n return workspacePackages.has(importPath);\n}\n\n/**\n * Get project name from package name\n * e.g., '@webpieces/client' → 'client', 'apis' → 'apis'\n */\nfunction getProjectNameFromPackageName(packageName: string, workspaceRoot: string): string {\n const mappings = buildProjectMappings(workspaceRoot);\n\n // Try to find by reading package.json files\n for (const mapping of mappings) {\n const pkgJsonPath = path.join(workspaceRoot, mapping.root, 'package.json');\n if (fs.existsSync(pkgJsonPath)) {\n try {\n const pkgJson = JSON.parse(fs.readFileSync(pkgJsonPath, 'utf-8'));\n if (pkgJson.name === packageName) {\n return mapping.name; // Return project name\n }\n } catch {\n // Ignore parse errors\n }\n }\n }\n\n // Fallback: return package name as-is (might be unscoped project name)\n return packageName;\n}\n\n/**\n * Build project mappings from project.json files in workspace\n */\nfunction buildProjectMappings(workspaceRoot: string): ProjectMapping[] {\n if (cachedProjectMappings !== null) {\n return cachedProjectMappings;\n }\n\n const mappings: ProjectMapping[] = [];\n\n // Scan common locations for project.json files\n const searchDirs = ['packages', 'apps', 'libs', 'libraries', 'services'];\n\n for (const searchDir of searchDirs) {\n const searchPath = path.join(workspaceRoot, searchDir);\n if (!fs.existsSync(searchPath)) continue;\n\n scanForProjects(searchPath, workspaceRoot, mappings);\n }\n\n // Sort by path length (longest first) for more specific matching\n mappings.sort((a, b) => b.root.length - a.root.length);\n\n cachedProjectMappings = mappings;\n return mappings;\n}\n\n/**\n * Recursively scan for project.json files\n */\nfunction scanForProjects(\n dir: string,\n workspaceRoot: string,\n mappings: ProjectMapping[]\n): void {\n try {\n const entries = fs.readdirSync(dir, { withFileTypes: true });\n\n for (const entry of entries) {\n const fullPath = path.join(dir, entry.name);\n\n if (entry.isDirectory() && !entry.name.startsWith('.') && entry.name !== 'node_modules') {\n // Check for project.json in this directory\n const projectJsonPath = path.join(fullPath, 'project.json');\n if (fs.existsSync(projectJsonPath)) {\n try {\n const projectJson = JSON.parse(fs.readFileSync(projectJsonPath, 'utf-8'));\n const projectRoot = path.relative(workspaceRoot, fullPath);\n\n // Use project name from project.json as-is (no scope forcing)\n const projectName = projectJson.name || entry.name;\n\n mappings.push({\n root: projectRoot,\n name: projectName,\n });\n } catch (err: any) {\n //const error = toError(err);\n void err;\n }\n }\n\n // Continue scanning subdirectories\n scanForProjects(fullPath, workspaceRoot, mappings);\n }\n }\n } catch (err: any) {\n //const error = toError(err);\n void err;\n }\n}\n\n/**\n * Get project name from file path\n */\nfunction getProjectFromFile(filePath: string, workspaceRoot: string): string | null {\n const relativePath = path.relative(workspaceRoot, filePath).replace(/\\\\/g, '/');\n const mappings = buildProjectMappings(workspaceRoot);\n\n for (const mapping of mappings) {\n if (relativePath.startsWith(mapping.root + '/') || relativePath.startsWith(mapping.root)) {\n return mapping.name;\n }\n }\n\n return null;\n}\n\n/**\n * Compute all transitive dependencies for a project\n */\nfunction computeTransitiveDependencies(project: string, graph: EnhancedGraph): Set<string> {\n const result = new Set<string>();\n const visited = new Set<string>();\n\n function visit(currentProject: string): void {\n if (visited.has(currentProject)) return;\n visited.add(currentProject);\n\n const entry = graph[currentProject];\n if (!entry || !entry.dependsOn) return;\n\n for (const dep of entry.dependsOn) {\n result.add(dep);\n visit(dep);\n }\n }\n\n visit(project);\n return result;\n}\n\nconst rule: Rule.RuleModule = {\n meta: {\n type: 'problem',\n docs: {\n description: 'Enforce blessed architecture dependencies',\n category: 'Best Practices',\n recommended: true,\n url: 'https://github.com/deanhiller/webpieces-ts',\n },\n messages: {\n illegalImport:\n \"⚠️ AI Agent: READ tmp/webpieces/webpieces.dependencies.md for resolution steps!\\n\\n\" +\n \"Import '{{imported}}' violates architecture boundaries.\\n\\n\" +\n \"Project '{{project}}' (level {{level}}) can only import from:\\n\" +\n '{{allowedList}}',\n noGraph:\n 'No architecture graph found at architecture/dependencies.json\\n' +\n 'Run: nx run architecture:validate --mode=update',\n },\n schema: [],\n },\n\n create(context: Rule.RuleContext): Rule.RuleListener {\n const filename = context.filename || context.getFilename();\n const workspaceRoot = findWorkspaceRoot(filename);\n\n return {\n ImportDeclaration(node: any): void {\n const importPath = node.source.value as string;\n\n // Check if this is a workspace import (works for any scope or unscoped)\n if (!isWorkspaceImport(importPath, workspaceRoot)) {\n return; // Not a workspace import, skip validation\n }\n\n // Determine which project this file belongs to\n const sourceProject = getProjectFromFile(filename, workspaceRoot);\n if (!sourceProject) {\n // File not in any known project (e.g., tools/, scripts/)\n return;\n }\n\n // Convert import (package name) to project name\n const targetProject = getProjectNameFromPackageName(importPath, workspaceRoot);\n\n // Self-import is always allowed\n if (targetProject === sourceProject) {\n return;\n }\n\n // Load blessed graph\n const graph = loadBlessedGraph(workspaceRoot);\n if (!graph) {\n // No graph file - warn but don't fail (allows gradual adoption)\n return;\n }\n\n // Get project entry\n const projectEntry = graph[sourceProject];\n if (!projectEntry) {\n // Project not in graph (new project?) - allow\n return;\n }\n\n // Compute allowed dependencies (direct + transitive)\n const allowedDeps = computeTransitiveDependencies(sourceProject, graph);\n\n // Check if import is allowed (use project name, not package name)\n if (!allowedDeps.has(targetProject)) {\n // Write documentation file for AI/developer to read\n ensureDependenciesDoc(workspaceRoot);\n\n const directDeps = projectEntry.dependsOn || [];\n const allowedList =\n directDeps.length > 0\n ? directDeps.map((dep) => ` - ${dep}`).join('\\n') +\n '\\n (and their transitive dependencies)'\n : ' (none - this is a foundation project)';\n\n context.report({\n node: node.source,\n messageId: 'illegalImport',\n data: {\n imported: importPath,\n project: sourceProject,\n level: String(projectEntry.level),\n allowedList: allowedList,\n },\n });\n }\n },\n };\n },\n};\n\nexport = rule;\n"]}
|
|
1
|
+
{"version":3,"file":"enforce-architecture.js","sourceRoot":"","sources":["../../../../../../packages/tooling/dev-config/eslint-plugin/rules/enforce-architecture.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;GAWG;;AAGH,+CAAyB;AACzB,mDAA6B;AAE7B,MAAM,wBAAwB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAwIhC,CAAC;AAEF,uDAAuD;AACvD,IAAI,sBAAsB,GAAG,KAAK,CAAC;AAEnC;;GAEG;AACH,SAAS,aAAa,CAAC,OAAe,EAAE,OAAe;IACnD,IAAI,CAAC;QACD,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QACzD,EAAE,CAAC,aAAa,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;QAC5C,OAAO,IAAI,CAAC;IAChB,CAAC;IAAC,OAAO,GAAQ,EAAE,CAAC;QAChB,KAAK,GAAG,CAAC;QACT,OAAO,CAAC,IAAI,CAAC,0CAA0C,OAAO,EAAE,CAAC,CAAC;QAClE,OAAO,KAAK,CAAC;IACjB,CAAC;AACL,CAAC;AAED;;;GAGG;AACH,SAAS,qBAAqB,CAAC,aAAqB;IAChD,IAAI,sBAAsB;QAAE,OAAO;IACnC,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,KAAK,EAAE,WAAW,EAAE,2BAA2B,CAAC,CAAC;IAC1F,IAAI,aAAa,CAAC,OAAO,EAAE,wBAAwB,CAAC,EAAE,CAAC;QACnD,sBAAsB,GAAG,IAAI,CAAC;IAClC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yCAAyC;wBAC3C,CAAC,CAAC,yCAAyC,CAAC;oBAEpD,OAAO,CAAC,MAAM,CAAC;wBACX,IAAI,EAAE,IAAI,CAAC,MAAM;wBACjB,SAAS,EAAE,eAAe;wBAC1B,IAAI,EAAE;4BACF,QAAQ,EAAE,UAAU;4BACpB,OAAO,EAAE,aAAa;4BACtB,KAAK,EAAE,MAAM,CAAC,YAAY,CAAC,KAAK,CAAC;4BACjC,WAAW,EAAE,WAAW;yBAC3B;qBACJ,CAAC,CAAC;gBACP,CAAC;YACL,CAAC;SACJ,CAAC;IACN,CAAC;CACJ,CAAC;AAEF,iBAAS,IAAI,CAAC","sourcesContent":["/**\n * ESLint rule to enforce architecture boundaries\n *\n * Validates that imports from @webpieces/* packages comply with the\n * blessed dependency graph in .graphs/dependencies.json\n *\n * Supports transitive dependencies: if A depends on B and B depends on C,\n * then A can import from C.\n *\n * Configuration:\n * '@webpieces/enforce-architecture': 'error'\n */\n\nimport type { Rule } from 'eslint';\nimport * as fs from 'fs';\nimport * as path from 'path';\n\nconst DEPENDENCIES_DOC_CONTENT = `# Instructions: Architecture Dependency Violation\n\nIN GENERAL, it is better to avoid these changes and find a different way by moving classes\naround to existing packages you already depend on. It is not always avoidable though.\nA clean dependency graph keeps you out of huge trouble later.\n\nIf you are a human, simply run these commands:\n* nx run architecture:visualize - to see the new dependencies and validate that change is desired\n* nx run architecture:generate - updates the dep graph\n* git diff architecture/dependencies.json - to see the deps changes you made\n\n**READ THIS FILE FIRST before making any changes!**\n\n## ⚠️ CRITICAL WARNING ⚠️\n\n**This is a VERY IMPORTANT change that has LARGE REPERCUSSIONS later!**\n\nAdding new dependencies creates technical debt that compounds over time:\n- Creates coupling between packages that may be hard to undo\n- Can create circular dependency tangles\n- Makes packages harder to test in isolation\n- Increases build times and bundle sizes\n- May force unnecessary upgrades across the codebase\n\n**DO NOT add dependencies without senior developer approval!**\n\n## Understanding the Error\n\nYou've attempted to import from a package that is not in your project's allowed dependencies.\nThe architecture enforces a layered dependency structure where:\n- Level 0 packages are foundation packages with NO dependencies on other @webpieces packages\n- Higher level packages can only depend on lower level packages\n- All dependencies must be explicitly declared\n\n## Steps to Resolve\n\n### Step 1: Generate Current Dependency Graph\nRun this command to see the current architecture:\n\\`\\`\\`bash\nnpx nx run architecture:generate\n\\`\\`\\`\nThis creates/updates \\`architecture/dependencies.json\\` showing all packages and their levels.\n\n### Step 2: Analyze the Proposed Change\nAsk yourself:\n1. **Is this import truly necessary?** Can you refactor to avoid it?\n2. **Should the code move instead?** Maybe the code belongs in a different package.\n3. **Will this create a cycle?** Use \\`npx nx graph\\` to visualize dependencies.\n4. **Can you use an interface/abstraction?** Define interface in lower-level package, implement in higher-level.\n\n### Step 3: Get Senior Developer Approval\n\n## 🛑 AI AGENTS: STOP HERE AND ASK FOR HUMAN APPROVAL! 🛑\n\n**YOU MUST NOT PROCEED TO STEP 4 WITHOUT EXPLICIT HUMAN APPROVAL!**\n\n**REQUIRED**: Discuss this architectural change with a senior developer before proceeding.\n- Explain why the dependency is needed\n- Show you've considered alternatives (Step 2)\n- **WAIT for explicit approval before making ANY changes to project.json or package.json**\n\n**AI Agent Instructions:**\n1. Present your analysis from Step 2 to the human\n2. Explain which package needs which dependency and why\n3. ASK: \"Do you approve adding this dependency?\"\n4. **DO NOT modify project.json or package.json until you receive explicit \"yes\" or approval**\n\n### Step 4: If Approved, Add the Dependency\n\n## ⛔ NEVER MODIFY THESE FILES WITHOUT HUMAN APPROVAL FROM STEP 3! ⛔\n\nOnly after receiving explicit human approval in Step 3, make these changes:\n\n1. **Update project.json** - Add to \\`build.dependsOn\\`:\n \\`\\`\\`json\n {\n \"targets\": {\n \"build\": {\n \"dependsOn\": [\"^build\", \"dep1:build\", \"NEW_PACKAGE:build\"]\n }\n }\n }\n \\`\\`\\`\n\n2. **Update package.json** - Add to \\`dependencies\\`:\n \\`\\`\\`json\n {\n \"dependencies\": {\n \"@webpieces/NEW_PACKAGE\": \"*\"\n }\n }\n \\`\\`\\`\n\n### Step 5: Update Architecture Definition\nRun this command to validate and update the architecture:\n\\`\\`\\`bash\nnpx nx run architecture:generate\n\\`\\`\\`\n\nThis will:\n- Detect any cycles (which MUST be fixed before proceeding)\n- Update \\`architecture/dependencies.json\\` with the new dependency\n- Recalculate package levels\n\n### Step 6: Verify No Cycles\n\\`\\`\\`bash\nnpx nx run architecture:validate-no-cycles\n\\`\\`\\`\n\nIf cycles are detected, you MUST refactor to break the cycle. Common strategies:\n- Move shared code to a lower-level package\n- Use dependency inversion (interfaces in low-level, implementations in high-level)\n- Restructure package boundaries\n\n## Alternative Solutions (Preferred over adding dependencies)\n\n### Option A: Move the Code\nIf you need functionality from another package, consider moving that code to a shared lower-level package.\n\n### Option B: Dependency Inversion\nDefine an interface in the lower-level package, implement it in the higher-level package:\n\\`\\`\\`typescript\n// In foundation package (level 0)\nexport interface Logger { log(msg: string): void; }\n\n// In higher-level package\nexport class ConsoleLogger implements Logger { ... }\n\\`\\`\\`\n\n### Option C: Pass Dependencies as Parameters\nInstead of importing, receive the dependency as a constructor or method parameter.\n\n## Remember\n- Every dependency you add today is technical debt for tomorrow\n- The best dependency is the one you don't need\n- When in doubt, refactor rather than add dependencies\n`;\n\n// Module-level flag to prevent redundant file creation\nlet dependenciesDocCreated = false;\n\n/**\n * Ensure a documentation file exists at the given path.\n */\nfunction ensureDocFile(docPath: string, content: string): boolean {\n try {\n fs.mkdirSync(path.dirname(docPath), { recursive: true });\n fs.writeFileSync(docPath, content, 'utf-8');\n return true;\n } catch (err: any) {\n void err;\n console.warn(`[webpieces] Could not create doc file: ${docPath}`);\n return false;\n }\n}\n\n/**\n * Ensure the dependencies documentation file exists.\n * Called when an architecture violation is detected.\n */\nfunction ensureDependenciesDoc(workspaceRoot: string): void {\n if (dependenciesDocCreated) return;\n const docPath = path.join(workspaceRoot, 'tmp', 'webpieces', 'webpieces.dependencies.md');\n if (ensureDocFile(docPath, DEPENDENCIES_DOC_CONTENT)) {\n dependenciesDocCreated = true;\n }\n}\n\n/**\n * Graph entry format from .graphs/dependencies.json\n */\ninterface GraphEntry {\n level: number;\n dependsOn: string[];\n}\n\ntype EnhancedGraph = Record<string, GraphEntry>;\n\n/**\n * Project mapping entry\n */\ninterface ProjectMapping {\n root: string;\n name: string;\n}\n\n// Cache for blessed graph (loaded once per lint run)\nlet cachedGraph: EnhancedGraph | null = null;\nlet cachedGraphPath: string | null = null;\n\n// Cache for project mappings\nlet cachedProjectMappings: ProjectMapping[] | null = null;\n\n/**\n * Find workspace root by walking up from file location\n */\nfunction findWorkspaceRoot(startPath: string): string {\n let currentDir = path.dirname(startPath);\n\n for (let i = 0; i < 20; i++) {\n const packagePath = path.join(currentDir, 'package.json');\n if (fs.existsSync(packagePath)) {\n try {\n const pkg = JSON.parse(fs.readFileSync(packagePath, 'utf-8'));\n if (pkg.workspaces || pkg.name === 'webpieces-ts') {\n return currentDir;\n }\n } catch (err: any) {\n //const error = toError(err);\n void err;\n }\n }\n\n const parent = path.dirname(currentDir);\n if (parent === currentDir) break;\n currentDir = parent;\n }\n\n return process.cwd();\n}\n\n/**\n * Load blessed graph from architecture/dependencies.json\n */\nfunction loadBlessedGraph(workspaceRoot: string): EnhancedGraph | null {\n const graphPath = path.join(workspaceRoot, 'architecture', 'dependencies.json');\n\n // Return cached if same path\n if (cachedGraphPath === graphPath && cachedGraph !== null) {\n return cachedGraph;\n }\n\n if (!fs.existsSync(graphPath)) {\n return null;\n }\n\n try {\n const content = fs.readFileSync(graphPath, 'utf-8');\n cachedGraph = JSON.parse(content) as EnhancedGraph;\n cachedGraphPath = graphPath;\n return cachedGraph;\n } catch (err: any) {\n //const error = toError(err);\n // err is used below\n console.error(`[ESLint @webpieces/enforce-architecture] Could not load graph: ${err}`);\n return null;\n }\n}\n\n/**\n * Build set of all workspace package names (from package.json files)\n * Used to detect workspace imports (works for any scope or unscoped)\n */\nfunction buildWorkspacePackageNames(workspaceRoot: string): Set<string> {\n const packageNames = new Set<string>();\n const mappings = buildProjectMappings(workspaceRoot);\n\n for (const mapping of mappings) {\n const pkgJsonPath = path.join(workspaceRoot, mapping.root, 'package.json');\n if (fs.existsSync(pkgJsonPath)) {\n try {\n const pkgJson = JSON.parse(fs.readFileSync(pkgJsonPath, 'utf-8'));\n if (pkgJson.name) {\n packageNames.add(pkgJson.name);\n }\n } catch {\n // Ignore parse errors\n }\n }\n }\n\n return packageNames;\n}\n\n/**\n * Check if an import path is a workspace project\n * Works for scoped (@scope/name) or unscoped (name) packages\n */\nfunction isWorkspaceImport(importPath: string, workspaceRoot: string): boolean {\n const workspacePackages = buildWorkspacePackageNames(workspaceRoot);\n return workspacePackages.has(importPath);\n}\n\n/**\n * Get project name from package name\n * e.g., '@webpieces/client' → 'client', 'apis' → 'apis'\n */\nfunction getProjectNameFromPackageName(packageName: string, workspaceRoot: string): string {\n const mappings = buildProjectMappings(workspaceRoot);\n\n // Try to find by reading package.json files\n for (const mapping of mappings) {\n const pkgJsonPath = path.join(workspaceRoot, mapping.root, 'package.json');\n if (fs.existsSync(pkgJsonPath)) {\n try {\n const pkgJson = JSON.parse(fs.readFileSync(pkgJsonPath, 'utf-8'));\n if (pkgJson.name === packageName) {\n return mapping.name; // Return project name\n }\n } catch {\n // Ignore parse errors\n }\n }\n }\n\n // Fallback: return package name as-is (might be unscoped project name)\n return packageName;\n}\n\n/**\n * Build project mappings from project.json files in workspace\n */\nfunction buildProjectMappings(workspaceRoot: string): ProjectMapping[] {\n if (cachedProjectMappings !== null) {\n return cachedProjectMappings;\n }\n\n const mappings: ProjectMapping[] = [];\n\n // Scan common locations for project.json files\n const searchDirs = ['packages', 'apps', 'libs', 'libraries', 'services'];\n\n for (const searchDir of searchDirs) {\n const searchPath = path.join(workspaceRoot, searchDir);\n if (!fs.existsSync(searchPath)) continue;\n\n scanForProjects(searchPath, workspaceRoot, mappings);\n }\n\n // Sort by path length (longest first) for more specific matching\n mappings.sort((a, b) => b.root.length - a.root.length);\n\n cachedProjectMappings = mappings;\n return mappings;\n}\n\n/**\n * Recursively scan for project.json files\n */\nfunction scanForProjects(\n dir: string,\n workspaceRoot: string,\n mappings: ProjectMapping[]\n): void {\n try {\n const entries = fs.readdirSync(dir, { withFileTypes: true });\n\n for (const entry of entries) {\n const fullPath = path.join(dir, entry.name);\n\n if (entry.isDirectory() && !entry.name.startsWith('.') && entry.name !== 'node_modules') {\n // Check for project.json in this directory\n const projectJsonPath = path.join(fullPath, 'project.json');\n if (fs.existsSync(projectJsonPath)) {\n try {\n const projectJson = JSON.parse(fs.readFileSync(projectJsonPath, 'utf-8'));\n const projectRoot = path.relative(workspaceRoot, fullPath);\n\n // Use project name from project.json as-is (no scope forcing)\n const projectName = projectJson.name || entry.name;\n\n mappings.push({\n root: projectRoot,\n name: projectName,\n });\n } catch (err: any) {\n //const error = toError(err);\n void err;\n }\n }\n\n // Continue scanning subdirectories\n scanForProjects(fullPath, workspaceRoot, mappings);\n }\n }\n } catch (err: any) {\n //const error = toError(err);\n void err;\n }\n}\n\n/**\n * Get project name from file path\n */\nfunction getProjectFromFile(filePath: string, workspaceRoot: string): string | null {\n const relativePath = path.relative(workspaceRoot, filePath).replace(/\\\\/g, '/');\n const mappings = buildProjectMappings(workspaceRoot);\n\n for (const mapping of mappings) {\n if (relativePath.startsWith(mapping.root + '/') || relativePath.startsWith(mapping.root)) {\n return mapping.name;\n }\n }\n\n return null;\n}\n\n/**\n * Compute all transitive dependencies for a project\n */\nfunction computeTransitiveDependencies(project: string, graph: EnhancedGraph): Set<string> {\n const result = new Set<string>();\n const visited = new Set<string>();\n\n function visit(currentProject: string): void {\n if (visited.has(currentProject)) return;\n visited.add(currentProject);\n\n const entry = graph[currentProject];\n if (!entry || !entry.dependsOn) return;\n\n for (const dep of entry.dependsOn) {\n result.add(dep);\n visit(dep);\n }\n }\n\n visit(project);\n return result;\n}\n\nconst rule: Rule.RuleModule = {\n meta: {\n type: 'problem',\n docs: {\n description: 'Enforce blessed architecture dependencies',\n category: 'Best Practices',\n recommended: true,\n url: 'https://github.com/deanhiller/webpieces-ts',\n },\n messages: {\n illegalImport:\n \"⚠️ AI Agent: READ tmp/webpieces/webpieces.dependencies.md for resolution steps!\\n\\n\" +\n \"Import '{{imported}}' violates architecture boundaries.\\n\\n\" +\n \"Project '{{project}}' (level {{level}}) can only import from:\\n\" +\n '{{allowedList}}',\n noGraph:\n 'No architecture graph found at architecture/dependencies.json\\n' +\n 'Run: nx run architecture:validate --mode=update',\n },\n schema: [],\n },\n\n create(context: Rule.RuleContext): Rule.RuleListener {\n const filename = context.filename || context.getFilename();\n const workspaceRoot = findWorkspaceRoot(filename);\n\n return {\n ImportDeclaration(node: any): void {\n const importPath = node.source.value as string;\n\n // Check if this is a workspace import (works for any scope or unscoped)\n if (!isWorkspaceImport(importPath, workspaceRoot)) {\n return; // Not a workspace import, skip validation\n }\n\n // Determine which project this file belongs to\n const sourceProject = getProjectFromFile(filename, workspaceRoot);\n if (!sourceProject) {\n // File not in any known project (e.g., tools/, scripts/)\n return;\n }\n\n // Convert import (package name) to project name\n const targetProject = getProjectNameFromPackageName(importPath, workspaceRoot);\n\n // Self-import is always allowed\n if (targetProject === sourceProject) {\n return;\n }\n\n // Load blessed graph\n const graph = loadBlessedGraph(workspaceRoot);\n if (!graph) {\n // No graph file - warn but don't fail (allows gradual adoption)\n return;\n }\n\n // Get project entry\n const projectEntry = graph[sourceProject];\n if (!projectEntry) {\n // Project not in graph (new project?) - allow\n return;\n }\n\n // Compute allowed dependencies (direct + transitive)\n const allowedDeps = computeTransitiveDependencies(sourceProject, graph);\n\n // Check if import is allowed (use project name, not package name)\n if (!allowedDeps.has(targetProject)) {\n // Write documentation file for AI/developer to read\n ensureDependenciesDoc(workspaceRoot);\n\n const directDeps = projectEntry.dependsOn || [];\n const allowedList =\n directDeps.length > 0\n ? directDeps.map((dep) => ` - ${dep}`).join('\\n') +\n '\\n (and their transitive dependencies)'\n : ' (none - this is a foundation project)';\n\n context.report({\n node: node.source,\n messageId: 'illegalImport',\n data: {\n imported: importPath,\n project: sourceProject,\n level: String(projectEntry.level),\n allowedList: allowedList,\n },\n });\n }\n },\n };\n },\n};\n\nexport = rule;\n"]}
|
|
@@ -15,7 +15,16 @@ import type { Rule } from 'eslint';
|
|
|
15
15
|
import * as fs from 'fs';
|
|
16
16
|
import * as path from 'path';
|
|
17
17
|
|
|
18
|
-
const DEPENDENCIES_DOC_CONTENT = `#
|
|
18
|
+
const DEPENDENCIES_DOC_CONTENT = `# Instructions: Architecture Dependency Violation
|
|
19
|
+
|
|
20
|
+
IN GENERAL, it is better to avoid these changes and find a different way by moving classes
|
|
21
|
+
around to existing packages you already depend on. It is not always avoidable though.
|
|
22
|
+
A clean dependency graph keeps you out of huge trouble later.
|
|
23
|
+
|
|
24
|
+
If you are a human, simply run these commands:
|
|
25
|
+
* nx run architecture:visualize - to see the new dependencies and validate that change is desired
|
|
26
|
+
* nx run architecture:generate - updates the dep graph
|
|
27
|
+
* git diff architecture/dependencies.json - to see the deps changes you made
|
|
19
28
|
|
|
20
29
|
**READ THIS FILE FIRST before making any changes!**
|
|
21
30
|
|
|
@@ -102,7 +111,7 @@ Only after receiving explicit human approval in Step 3, make these changes:
|
|
|
102
111
|
### Step 5: Update Architecture Definition
|
|
103
112
|
Run this command to validate and update the architecture:
|
|
104
113
|
\`\`\`bash
|
|
105
|
-
npx nx run architecture:
|
|
114
|
+
npx nx run architecture:generate
|
|
106
115
|
\`\`\`
|
|
107
116
|
|
|
108
117
|
This will:
|
|
@@ -112,7 +121,7 @@ This will:
|
|
|
112
121
|
|
|
113
122
|
### Step 6: Verify No Cycles
|
|
114
123
|
\`\`\`bash
|
|
115
|
-
npx nx run architecture:validate
|
|
124
|
+
npx nx run architecture:validate-no-cycles
|
|
116
125
|
\`\`\`
|
|
117
126
|
|
|
118
127
|
If cycles are detected, you MUST refactor to break the cycle. Common strategies:
|
package/package.json
CHANGED
package/plugin.js
CHANGED
|
@@ -34,6 +34,7 @@ const DEFAULT_OPTIONS = {
|
|
|
34
34
|
noCycles: true,
|
|
35
35
|
noSkipLevelDeps: true,
|
|
36
36
|
architectureUnchanged: true,
|
|
37
|
+
validatePackageJson: true,
|
|
37
38
|
},
|
|
38
39
|
features: {
|
|
39
40
|
generate: true,
|
|
@@ -157,6 +158,9 @@ function createWorkspaceTargetsWithoutPrefix(opts) {
|
|
|
157
158
|
if (opts.workspace.validations.noSkipLevelDeps) {
|
|
158
159
|
targets['validate-no-skiplevel-deps'] = createValidateNoSkipLevelTarget();
|
|
159
160
|
}
|
|
161
|
+
if (opts.workspace.validations.validatePackageJson) {
|
|
162
|
+
targets['validate-packagejson'] = createValidatePackageJsonTarget();
|
|
163
|
+
}
|
|
160
164
|
// Add validate-complete target that runs all validations
|
|
161
165
|
const validationTargets = [];
|
|
162
166
|
if (opts.workspace.validations.noCycles) {
|
|
@@ -168,6 +172,9 @@ function createWorkspaceTargetsWithoutPrefix(opts) {
|
|
|
168
172
|
if (opts.workspace.validations.noSkipLevelDeps) {
|
|
169
173
|
validationTargets.push('validate-no-skiplevel-deps');
|
|
170
174
|
}
|
|
175
|
+
if (opts.workspace.validations.validatePackageJson) {
|
|
176
|
+
validationTargets.push('validate-packagejson');
|
|
177
|
+
}
|
|
171
178
|
if (validationTargets.length > 0) {
|
|
172
179
|
targets['validate-complete'] = createValidateCompleteTarget(validationTargets);
|
|
173
180
|
}
|
|
@@ -198,6 +205,9 @@ function createWorkspaceTargets(opts) {
|
|
|
198
205
|
if (opts.workspace.validations.noSkipLevelDeps) {
|
|
199
206
|
targets[`${prefix}validate-no-skiplevel-deps`] = createValidateNoSkipLevelTarget();
|
|
200
207
|
}
|
|
208
|
+
if (opts.workspace.validations.validatePackageJson) {
|
|
209
|
+
targets[`${prefix}validate-packagejson`] = createValidatePackageJsonTarget();
|
|
210
|
+
}
|
|
201
211
|
return targets;
|
|
202
212
|
}
|
|
203
213
|
function createGenerateTarget(graphPath) {
|
|
@@ -269,6 +279,17 @@ function createValidateNoSkipLevelTarget() {
|
|
|
269
279
|
},
|
|
270
280
|
};
|
|
271
281
|
}
|
|
282
|
+
function createValidatePackageJsonTarget() {
|
|
283
|
+
return {
|
|
284
|
+
executor: '@webpieces/dev-config:validate-packagejson',
|
|
285
|
+
cache: true,
|
|
286
|
+
inputs: ['default'],
|
|
287
|
+
metadata: {
|
|
288
|
+
technologies: ['nx'],
|
|
289
|
+
description: 'Validate package.json dependencies match project.json build dependencies',
|
|
290
|
+
},
|
|
291
|
+
};
|
|
292
|
+
}
|
|
272
293
|
function createValidateCompleteTarget(validationTargets) {
|
|
273
294
|
return {
|
|
274
295
|
executor: 'nx:noop',
|