@webpieces/dev-config 0.2.38 → 0.2.40
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/architecture/executors/validate-new-methods/executor.d.ts +22 -0
- package/architecture/executors/validate-new-methods/executor.js +351 -0
- package/architecture/executors/validate-new-methods/executor.js.map +1 -0
- package/architecture/executors/validate-new-methods/executor.ts +408 -0
- package/architecture/executors/validate-new-methods/schema.json +14 -0
- 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/executors.json +5 -0
- package/package.json +1 -1
- package/plugin.js +43 -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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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,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AAE,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');
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validate New Methods Executor
|
|
3
|
+
*
|
|
4
|
+
* Validates that newly added methods don't exceed a maximum line count.
|
|
5
|
+
* Only runs when NX_BASE environment variable is set (affected mode).
|
|
6
|
+
*
|
|
7
|
+
* This validator encourages writing methods that read like a "table of contents"
|
|
8
|
+
* where each method call describes a larger piece of work.
|
|
9
|
+
*
|
|
10
|
+
* Usage:
|
|
11
|
+
* nx affected --target=validate-new-methods --base=origin/main
|
|
12
|
+
*
|
|
13
|
+
* Escape hatch: Add eslint-disable comment with justification
|
|
14
|
+
*/
|
|
15
|
+
import type { ExecutorContext } from '@nx/devkit';
|
|
16
|
+
export interface ValidateNewMethodsOptions {
|
|
17
|
+
max?: number;
|
|
18
|
+
}
|
|
19
|
+
export interface ExecutorResult {
|
|
20
|
+
success: boolean;
|
|
21
|
+
}
|
|
22
|
+
export default function runExecutor(options: ValidateNewMethodsOptions, context: ExecutorContext): Promise<ExecutorResult>;
|