@webpieces/dev-config 0.2.21 → 0.2.23
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/README.md +44 -1
- package/generators/init/generator.ts +130 -0
- package/generators/init/schema.json +15 -0
- package/generators.json +10 -0
- package/package.json +9 -2
- package/plugin/README.md +236 -0
- package/plugin/index.ts +4 -0
- package/plugins/circular-deps/index.d.ts +0 -8
- package/plugins/circular-deps/index.js +0 -14
- package/plugins/circular-deps/index.js.map +0 -1
- package/plugins/circular-deps/index.ts +0 -9
- package/plugins/circular-deps/plugin.d.ts +0 -32
- package/plugins/circular-deps/plugin.js +0 -73
- package/plugins/circular-deps/plugin.js.map +0 -1
- package/plugins/circular-deps/plugin.ts +0 -83
package/README.md
CHANGED
|
@@ -6,6 +6,7 @@ Development configuration, scripts, and patterns for WebPieces projects.
|
|
|
6
6
|
|
|
7
7
|
This package provides shareable development tools for projects using the WebPieces framework:
|
|
8
8
|
|
|
9
|
+
- **Nx Plugin** for automatic architecture validation and circular dependency checking
|
|
9
10
|
- **Executable scripts** for common development tasks
|
|
10
11
|
- **ESLint configuration** with WebPieces patterns and best practices
|
|
11
12
|
- **Jest preset** for testing TypeScript projects
|
|
@@ -14,6 +15,14 @@ This package provides shareable development tools for projects using the WebPiec
|
|
|
14
15
|
|
|
15
16
|
## Installation
|
|
16
17
|
|
|
18
|
+
For Nx workspaces (recommended):
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
nx add @webpieces/dev-config
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
For non-Nx projects:
|
|
25
|
+
|
|
17
26
|
```bash
|
|
18
27
|
npm install --save-dev @webpieces/dev-config
|
|
19
28
|
```
|
|
@@ -73,7 +82,41 @@ To develop against a local copy of webpieces-ts:
|
|
|
73
82
|
wp-use-published
|
|
74
83
|
```
|
|
75
84
|
|
|
76
|
-
### 2.
|
|
85
|
+
### 2. Nx Plugin (Architecture Validation)
|
|
86
|
+
|
|
87
|
+
Automatically adds architecture validation and circular dependency checking to Nx workspaces.
|
|
88
|
+
|
|
89
|
+
#### Quick Start
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
# Install and register the plugin
|
|
93
|
+
nx add @webpieces/dev-config
|
|
94
|
+
|
|
95
|
+
# Generate dependency graph
|
|
96
|
+
nx run .:arch:generate
|
|
97
|
+
|
|
98
|
+
# Validate architecture
|
|
99
|
+
nx run .:arch:validate-no-cycles
|
|
100
|
+
|
|
101
|
+
# Check project for circular dependencies
|
|
102
|
+
nx run my-project:check-circular-deps
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
#### Available Targets
|
|
106
|
+
|
|
107
|
+
**Workspace-level:**
|
|
108
|
+
- `arch:generate` - Generate dependency graph
|
|
109
|
+
- `arch:visualize` - Visualize dependency graph
|
|
110
|
+
- `arch:validate-no-cycles` - Validate no circular dependencies
|
|
111
|
+
- `arch:validate-no-skiplevel-deps` - Validate no redundant dependencies
|
|
112
|
+
- `arch:validate-architecture-unchanged` - Validate against blessed graph
|
|
113
|
+
|
|
114
|
+
**Per-project:**
|
|
115
|
+
- `check-circular-deps` - Check for circular dependencies (auto-added to all projects)
|
|
116
|
+
|
|
117
|
+
For detailed documentation, see [Plugin README](./plugin/README.md).
|
|
118
|
+
|
|
119
|
+
### 3. ESLint Configuration
|
|
77
120
|
|
|
78
121
|
Import the base configuration in your `eslint.config.mjs`:
|
|
79
122
|
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { formatFiles, readNxJson, Tree, updateNxJson, updateJson, addDependenciesToPackageJson } from '@nx/devkit';
|
|
2
|
+
import type { InitGeneratorSchema } from './schema';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Init generator for @webpieces/dev-config
|
|
6
|
+
*
|
|
7
|
+
* Automatically runs when users execute: nx add @webpieces/dev-config
|
|
8
|
+
*
|
|
9
|
+
* Responsibilities:
|
|
10
|
+
* - Registers the plugin in nx.json
|
|
11
|
+
* - Creates architecture/ directory if needed
|
|
12
|
+
* - Adds madge as a devDependency (required for circular dep checking)
|
|
13
|
+
* - Adds convenient npm scripts to package.json
|
|
14
|
+
* - Provides helpful output about available targets
|
|
15
|
+
*/
|
|
16
|
+
export default async function initGenerator(tree: Tree, options: InitGeneratorSchema) {
|
|
17
|
+
registerPlugin(tree);
|
|
18
|
+
const installTask = addMadgeDependency(tree);
|
|
19
|
+
createArchitectureDirectory(tree);
|
|
20
|
+
addNpmScripts(tree);
|
|
21
|
+
|
|
22
|
+
if (!options.skipFormat) {
|
|
23
|
+
await formatFiles(tree);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return createSuccessCallback(installTask);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function registerPlugin(tree: Tree): void {
|
|
30
|
+
const nxJson = readNxJson(tree);
|
|
31
|
+
if (!nxJson) {
|
|
32
|
+
throw new Error('Could not read nx.json. Are you in an Nx workspace?');
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (!nxJson.plugins) {
|
|
36
|
+
nxJson.plugins = [];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const pluginName = '@webpieces/dev-config';
|
|
40
|
+
const alreadyRegistered = nxJson.plugins.some(
|
|
41
|
+
(p) => typeof p === 'string' ? p === pluginName : p.plugin === pluginName
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
if (!alreadyRegistered) {
|
|
45
|
+
nxJson.plugins.push(pluginName);
|
|
46
|
+
updateNxJson(tree, nxJson);
|
|
47
|
+
console.log(`✅ Registered ${pluginName} plugin in nx.json`);
|
|
48
|
+
} else {
|
|
49
|
+
console.log(`ℹ️ ${pluginName} plugin is already registered`);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function addMadgeDependency(tree: Tree) {
|
|
54
|
+
return addDependenciesToPackageJson(tree, {}, { 'madge': '^8.0.0' });
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function createArchitectureDirectory(tree: Tree): void {
|
|
58
|
+
if (!tree.exists('architecture')) {
|
|
59
|
+
tree.write('architecture/.gitkeep', '');
|
|
60
|
+
console.log('✅ Created architecture/ directory');
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function addNpmScripts(tree: Tree): void {
|
|
65
|
+
updateJson(tree, 'package.json', (pkgJson) => {
|
|
66
|
+
pkgJson.scripts = pkgJson.scripts ?? {};
|
|
67
|
+
|
|
68
|
+
// Add architecture validation scripts
|
|
69
|
+
pkgJson.scripts['arch:generate'] = 'nx run .:arch:generate';
|
|
70
|
+
pkgJson.scripts['arch:visualize'] = 'nx run .:arch:visualize';
|
|
71
|
+
pkgJson.scripts['arch:validate'] = 'nx run .:arch:validate-no-cycles && nx run .:arch:validate-no-skiplevel-deps';
|
|
72
|
+
pkgJson.scripts['arch:validate-all'] = 'nx run .:arch:validate-no-cycles && nx run .:arch:validate-no-skiplevel-deps && nx run .:arch:validate-architecture-unchanged';
|
|
73
|
+
|
|
74
|
+
// Add circular dependency checking scripts
|
|
75
|
+
pkgJson.scripts['arch:check-circular'] = 'nx run-many --target=check-circular-deps --all';
|
|
76
|
+
pkgJson.scripts['arch:check-circular-affected'] = 'nx affected --target=check-circular-deps';
|
|
77
|
+
|
|
78
|
+
// Complete validation including circular deps
|
|
79
|
+
pkgJson.scripts['arch:validate-complete'] = 'npm run arch:validate-all && npm run arch:check-circular';
|
|
80
|
+
|
|
81
|
+
return pkgJson;
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
console.log('✅ Added npm scripts for architecture validation and circular dependency checking');
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function createSuccessCallback(installTask: ReturnType<typeof addDependenciesToPackageJson>) {
|
|
88
|
+
return async () => {
|
|
89
|
+
await installTask();
|
|
90
|
+
console.log('✅ Added madge to devDependencies');
|
|
91
|
+
console.log('');
|
|
92
|
+
console.log('✅ @webpieces/dev-config plugin initialized!');
|
|
93
|
+
console.log('');
|
|
94
|
+
printAvailableTargets();
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function printAvailableTargets(): void {
|
|
99
|
+
console.log('📝 Available npm scripts (convenient shortcuts):');
|
|
100
|
+
console.log('');
|
|
101
|
+
console.log(' Architecture graph:');
|
|
102
|
+
console.log(' npm run arch:generate # Generate dependency graph');
|
|
103
|
+
console.log(' npm run arch:visualize # Visualize dependency graph');
|
|
104
|
+
console.log('');
|
|
105
|
+
console.log(' Validation:');
|
|
106
|
+
console.log(' npm run arch:validate # Quick validation (no-cycles + no-skiplevel-deps)');
|
|
107
|
+
console.log(' npm run arch:validate-all # Full arch validation (+ unchanged check)');
|
|
108
|
+
console.log(' npm run arch:check-circular # Check all projects for circular deps');
|
|
109
|
+
console.log(' npm run arch:check-circular-affected # Check affected projects only');
|
|
110
|
+
console.log(' npm run arch:validate-complete # Complete validation (arch + circular)');
|
|
111
|
+
console.log('');
|
|
112
|
+
console.log('📝 Available Nx targets:');
|
|
113
|
+
console.log('');
|
|
114
|
+
console.log(' Workspace-level architecture validation:');
|
|
115
|
+
console.log(' nx run .:arch:generate # Generate dependency graph');
|
|
116
|
+
console.log(' nx run .:arch:visualize # Visualize dependency graph');
|
|
117
|
+
console.log(' nx run .:arch:validate-no-cycles # Check for circular dependencies');
|
|
118
|
+
console.log(' nx run .:arch:validate-no-skiplevel-deps # Check for redundant dependencies');
|
|
119
|
+
console.log(' nx run .:arch:validate-architecture-unchanged # Validate against blessed graph');
|
|
120
|
+
console.log('');
|
|
121
|
+
console.log(' Per-project circular dependency checking:');
|
|
122
|
+
console.log(' nx run <project>:check-circular-deps # Check project for circular deps');
|
|
123
|
+
console.log(' nx affected --target=check-circular-deps # Check all affected projects');
|
|
124
|
+
console.log(' nx run-many --target=check-circular-deps --all # Check all projects');
|
|
125
|
+
console.log('');
|
|
126
|
+
console.log('💡 Quick start:');
|
|
127
|
+
console.log(' npm run arch:generate # Generate the graph first');
|
|
128
|
+
console.log(' npm run arch:validate-complete # Run complete validation');
|
|
129
|
+
console.log('');
|
|
130
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://json-schema.org/schema",
|
|
3
|
+
"$id": "InitGenerator",
|
|
4
|
+
"title": "Initialize @webpieces/dev-config",
|
|
5
|
+
"description": "Initialize @webpieces/dev-config plugin in an Nx workspace",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"properties": {
|
|
8
|
+
"skipFormat": {
|
|
9
|
+
"type": "boolean",
|
|
10
|
+
"description": "Skip formatting files with Prettier",
|
|
11
|
+
"default": false
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"required": []
|
|
15
|
+
}
|
package/generators.json
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webpieces/dev-config",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.23",
|
|
4
4
|
"description": "Development configuration, scripts, and patterns for WebPieces projects",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"bin": {
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
"wp-setup-patterns": "./bin/setup-claude-patterns.sh"
|
|
13
13
|
},
|
|
14
14
|
"executors": "./executors.json",
|
|
15
|
+
"generators": "./generators.json",
|
|
15
16
|
"exports": {
|
|
16
17
|
".": "./index.js",
|
|
17
18
|
"./package.json": "./package.json",
|
|
@@ -19,9 +20,11 @@
|
|
|
19
20
|
"./eslint-plugin": "./eslint-plugin/index.js",
|
|
20
21
|
"./jest": "./config/jest/preset.js",
|
|
21
22
|
"./tsconfig": "./config/typescript/tsconfig.base.json",
|
|
23
|
+
"./plugin": "./plugin.js",
|
|
22
24
|
"./plugins/circular-deps": "./plugins/circular-deps/index.js",
|
|
23
25
|
"./architecture": "./architecture/index.js",
|
|
24
|
-
"./executors.json": "./executors.json"
|
|
26
|
+
"./executors.json": "./executors.json",
|
|
27
|
+
"./generators.json": "./generators.json"
|
|
25
28
|
},
|
|
26
29
|
"files": [
|
|
27
30
|
"bin/**/*",
|
|
@@ -29,6 +32,10 @@
|
|
|
29
32
|
"eslint-plugin/**/*",
|
|
30
33
|
"patterns/**/*",
|
|
31
34
|
"plugins/**/*",
|
|
35
|
+
"plugin/**/*",
|
|
36
|
+
"plugin.js",
|
|
37
|
+
"generators/**/*",
|
|
38
|
+
"generators.json",
|
|
32
39
|
"architecture/**/*",
|
|
33
40
|
"executors.json",
|
|
34
41
|
"README.md"
|
package/plugin/README.md
ADDED
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
# @webpieces/dev-config Plugin
|
|
2
|
+
|
|
3
|
+
Nx inference plugin that automatically provides architecture validation and circular dependency checking for your workspace.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
### Workspace-Level Architecture Validation
|
|
8
|
+
|
|
9
|
+
Automatically adds targets for managing and validating your project architecture:
|
|
10
|
+
|
|
11
|
+
- **`arch:generate`** - Generate dependency graph from project.json files
|
|
12
|
+
- **`arch:visualize`** - Create visual representations of the dependency graph
|
|
13
|
+
- **`arch:validate-no-cycles`** - Validate the architecture has no circular dependencies
|
|
14
|
+
- **`arch:validate-no-skiplevel-deps`** - Validate no redundant transitive dependencies
|
|
15
|
+
- **`arch:validate-architecture-unchanged`** - Validate against blessed dependency graph
|
|
16
|
+
|
|
17
|
+
### Per-Project Circular Dependency Checking
|
|
18
|
+
|
|
19
|
+
Automatically adds a `check-circular-deps` target to every project with a `src/` directory using [madge](https://github.com/pahen/madge).
|
|
20
|
+
|
|
21
|
+
## Installation
|
|
22
|
+
|
|
23
|
+
Add the plugin to your Nx workspace:
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
nx add @webpieces/dev-config
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
This automatically:
|
|
30
|
+
- Registers the plugin in `nx.json`
|
|
31
|
+
- Adds `madge` as a devDependency (required for circular dependency checking)
|
|
32
|
+
- Creates the `architecture/` directory
|
|
33
|
+
- Adds convenient npm scripts to `package.json`
|
|
34
|
+
- Makes all targets immediately available
|
|
35
|
+
|
|
36
|
+
## Usage
|
|
37
|
+
|
|
38
|
+
### Convenient npm Scripts
|
|
39
|
+
|
|
40
|
+
The init generator adds these npm scripts for easy access:
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
# Generate and visualize
|
|
44
|
+
npm run arch:generate # Generate dependency graph
|
|
45
|
+
npm run arch:visualize # Visualize in browser
|
|
46
|
+
|
|
47
|
+
# Validation
|
|
48
|
+
npm run arch:validate # Quick: no-cycles + no-skiplevel-deps
|
|
49
|
+
npm run arch:validate-all # Full: adds architecture-unchanged check
|
|
50
|
+
npm run arch:check-circular # Check all projects for circular deps (madge)
|
|
51
|
+
npm run arch:check-circular-affected # Check only affected projects
|
|
52
|
+
npm run arch:validate-complete # Complete: all validations + circular deps
|
|
53
|
+
|
|
54
|
+
# Recommended workflow
|
|
55
|
+
npm run arch:generate # 1. Generate graph first
|
|
56
|
+
npm run arch:validate-complete # 2. Run all validations
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### Direct Nx Targets
|
|
60
|
+
|
|
61
|
+
You can also run targets directly with Nx:
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
# Generate the dependency graph
|
|
65
|
+
nx run .:arch:generate
|
|
66
|
+
|
|
67
|
+
# Visualize the graph in your browser
|
|
68
|
+
nx run .:arch:visualize
|
|
69
|
+
|
|
70
|
+
# Validate no circular dependencies
|
|
71
|
+
nx run .:arch:validate-no-cycles
|
|
72
|
+
|
|
73
|
+
# Validate against blessed graph (for CI)
|
|
74
|
+
nx run .:arch:validate-architecture-unchanged
|
|
75
|
+
|
|
76
|
+
# Check for redundant dependencies
|
|
77
|
+
nx run .:arch:validate-no-skiplevel-deps
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### Per-Project Circular Dependency Checking
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
# Check a specific project
|
|
84
|
+
nx run my-project:check-circular-deps
|
|
85
|
+
|
|
86
|
+
# Check all affected projects
|
|
87
|
+
nx affected --target=check-circular-deps
|
|
88
|
+
|
|
89
|
+
# Check all projects
|
|
90
|
+
nx run-many --target=check-circular-deps --all
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## Configuration
|
|
94
|
+
|
|
95
|
+
Configure the plugin in `nx.json`:
|
|
96
|
+
|
|
97
|
+
```json
|
|
98
|
+
{
|
|
99
|
+
"plugins": [
|
|
100
|
+
{
|
|
101
|
+
"plugin": "@webpieces/dev-config",
|
|
102
|
+
"options": {
|
|
103
|
+
"circularDeps": {
|
|
104
|
+
"enabled": true,
|
|
105
|
+
"targetName": "check-circular-deps",
|
|
106
|
+
"excludePatterns": ["**/test-fixtures/**"]
|
|
107
|
+
},
|
|
108
|
+
"workspace": {
|
|
109
|
+
"enabled": true,
|
|
110
|
+
"targetPrefix": "arch:",
|
|
111
|
+
"validations": {
|
|
112
|
+
"noCycles": true,
|
|
113
|
+
"noSkipLevelDeps": true,
|
|
114
|
+
"architectureUnchanged": true
|
|
115
|
+
},
|
|
116
|
+
"features": {
|
|
117
|
+
"generate": true,
|
|
118
|
+
"visualize": true
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
]
|
|
124
|
+
}
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### Configuration Options
|
|
128
|
+
|
|
129
|
+
#### `circularDeps`
|
|
130
|
+
|
|
131
|
+
- **`enabled`** (boolean, default: `true`) - Enable/disable circular dependency checking
|
|
132
|
+
- **`targetName`** (string, default: `'check-circular-deps'`) - Name of the target to create
|
|
133
|
+
- **`excludePatterns`** (string[], default: `[]`) - Patterns to exclude from checking
|
|
134
|
+
|
|
135
|
+
#### `workspace`
|
|
136
|
+
|
|
137
|
+
- **`enabled`** (boolean, default: `true`) - Enable/disable workspace-level validation
|
|
138
|
+
- **`targetPrefix`** (string, default: `'arch:'`) - Prefix for workspace target names
|
|
139
|
+
- **`graphPath`** (string, default: `'architecture/dependencies.json'`) - Path to dependency graph file
|
|
140
|
+
|
|
141
|
+
##### `workspace.validations`
|
|
142
|
+
|
|
143
|
+
- **`noCycles`** (boolean, default: `true`) - Enable no-cycles validation
|
|
144
|
+
- **`noSkipLevelDeps`** (boolean, default: `true`) - Enable skip-level deps validation
|
|
145
|
+
- **`architectureUnchanged`** (boolean, default: `true`) - Enable unchanged graph validation
|
|
146
|
+
|
|
147
|
+
##### `workspace.features`
|
|
148
|
+
|
|
149
|
+
- **`generate`** (boolean, default: `true`) - Enable graph generation target
|
|
150
|
+
- **`visualize`** (boolean, default: `true`) - Enable visualization target
|
|
151
|
+
|
|
152
|
+
## Examples
|
|
153
|
+
|
|
154
|
+
### Disable Architecture Validation, Keep Circular Deps
|
|
155
|
+
|
|
156
|
+
```json
|
|
157
|
+
{
|
|
158
|
+
"plugin": "@webpieces/dev-config",
|
|
159
|
+
"options": {
|
|
160
|
+
"workspace": { "enabled": false }
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
### Disable Circular Deps, Keep Architecture Validation
|
|
166
|
+
|
|
167
|
+
```json
|
|
168
|
+
{
|
|
169
|
+
"plugin": "@webpieces/dev-config",
|
|
170
|
+
"options": {
|
|
171
|
+
"circularDeps": { "enabled": false }
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
### Disable Specific Validations
|
|
177
|
+
|
|
178
|
+
```json
|
|
179
|
+
{
|
|
180
|
+
"plugin": "@webpieces/dev-config",
|
|
181
|
+
"options": {
|
|
182
|
+
"workspace": {
|
|
183
|
+
"validations": {
|
|
184
|
+
"architectureUnchanged": false,
|
|
185
|
+
"noSkipLevelDeps": false
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
### Exclude Test Fixtures from Circular Deps
|
|
193
|
+
|
|
194
|
+
```json
|
|
195
|
+
{
|
|
196
|
+
"plugin": "@webpieces/dev-config",
|
|
197
|
+
"options": {
|
|
198
|
+
"circularDeps": {
|
|
199
|
+
"excludePatterns": ["**/test-fixtures/**", "**/__tests__/**"]
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
### Custom Target Names
|
|
206
|
+
|
|
207
|
+
```json
|
|
208
|
+
{
|
|
209
|
+
"plugin": "@webpieces/dev-config",
|
|
210
|
+
"options": {
|
|
211
|
+
"circularDeps": { "targetName": "circular-check" },
|
|
212
|
+
"workspace": { "targetPrefix": "architecture:" }
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
## How It Works
|
|
218
|
+
|
|
219
|
+
The plugin uses Nx's [Project Crystal (Inferred Tasks)](https://nx.dev/concepts/inferred-tasks) feature via the `createNodesV2` API to automatically detect and configure targets:
|
|
220
|
+
|
|
221
|
+
1. **Workspace Detection**: Looks for a `project.json` at the workspace root to add architecture targets
|
|
222
|
+
2. **Project Detection**: Scans all projects for `src/` directories to add circular-deps targets
|
|
223
|
+
3. **Pattern Matching**: Respects exclude patterns for fine-grained control
|
|
224
|
+
|
|
225
|
+
## Requirements
|
|
226
|
+
|
|
227
|
+
- Nx >= 18.0.0
|
|
228
|
+
- Node.js >= 18.0.0
|
|
229
|
+
- [Graphviz](https://graphviz.org/) (for visualization)
|
|
230
|
+
- [madge](https://github.com/pahen/madge) (bundled, used for circular dep checking)
|
|
231
|
+
|
|
232
|
+
## Related Documentation
|
|
233
|
+
|
|
234
|
+
- [Nx Inferred Tasks](https://nx.dev/concepts/inferred-tasks)
|
|
235
|
+
- [Architecture Validation Guide](../../architecture/README.md)
|
|
236
|
+
- [ESLint Plugin](../eslint-plugin/README.md)
|
package/plugin/index.ts
ADDED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Circular Dependencies Plugin
|
|
4
|
-
*
|
|
5
|
-
* Nx inference plugin that automatically adds check-circular-deps target
|
|
6
|
-
* to all projects with a src/ directory.
|
|
7
|
-
*/
|
|
8
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.default = void 0;
|
|
10
|
-
const tslib_1 = require("tslib");
|
|
11
|
-
tslib_1.__exportStar(require("./plugin"), exports);
|
|
12
|
-
var plugin_1 = require("./plugin");
|
|
13
|
-
Object.defineProperty(exports, "default", { enumerable: true, get: function () { return tslib_1.__importDefault(plugin_1).default; } });
|
|
14
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../packages/tooling/dev-config/plugins/circular-deps/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAEH,mDAAyB;AACzB,mCAAmC;AAA1B,0HAAA,OAAO,OAAA","sourcesContent":["/**\n * Circular Dependencies Plugin\n *\n * Nx inference plugin that automatically adds check-circular-deps target\n * to all projects with a src/ directory.\n */\n\nexport * from './plugin';\nexport { default } from './plugin';\n"]}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Nx Inference Plugin for Circular Dependency Checking
|
|
3
|
-
*
|
|
4
|
-
* This plugin automatically creates a "check-circular-deps" target for ANY project
|
|
5
|
-
* that has a src/ directory, similar to how @nx/eslint/plugin creates lint targets.
|
|
6
|
-
*
|
|
7
|
-
* Benefits:
|
|
8
|
-
* - Zero configuration per project
|
|
9
|
-
* - Works for ALL projects (services + libraries)
|
|
10
|
-
* - New projects automatically get the target
|
|
11
|
-
* - `nx affected --target=check-circular-deps` works on everything
|
|
12
|
-
*
|
|
13
|
-
* Usage:
|
|
14
|
-
* Add to nx.json plugins array:
|
|
15
|
-
* {
|
|
16
|
-
* "plugins": ["@webpieces/dev-config/plugins/circular-deps"]
|
|
17
|
-
* }
|
|
18
|
-
*
|
|
19
|
-
* Then run:
|
|
20
|
-
* - nx run <project>:check-circular-deps
|
|
21
|
-
* - nx affected --target=check-circular-deps
|
|
22
|
-
*/
|
|
23
|
-
import type { CreateNodesV2 } from '@nx/devkit';
|
|
24
|
-
/**
|
|
25
|
-
* Nx V2 Inference Plugin
|
|
26
|
-
* Matches project.json files and creates check-circular-deps target
|
|
27
|
-
*/
|
|
28
|
-
export declare const createNodesV2: CreateNodesV2;
|
|
29
|
-
declare const _default: {
|
|
30
|
-
createNodesV2: CreateNodesV2;
|
|
31
|
-
};
|
|
32
|
-
export default _default;
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Nx Inference Plugin for Circular Dependency Checking
|
|
4
|
-
*
|
|
5
|
-
* This plugin automatically creates a "check-circular-deps" target for ANY project
|
|
6
|
-
* that has a src/ directory, similar to how @nx/eslint/plugin creates lint targets.
|
|
7
|
-
*
|
|
8
|
-
* Benefits:
|
|
9
|
-
* - Zero configuration per project
|
|
10
|
-
* - Works for ALL projects (services + libraries)
|
|
11
|
-
* - New projects automatically get the target
|
|
12
|
-
* - `nx affected --target=check-circular-deps` works on everything
|
|
13
|
-
*
|
|
14
|
-
* Usage:
|
|
15
|
-
* Add to nx.json plugins array:
|
|
16
|
-
* {
|
|
17
|
-
* "plugins": ["@webpieces/dev-config/plugins/circular-deps"]
|
|
18
|
-
* }
|
|
19
|
-
*
|
|
20
|
-
* Then run:
|
|
21
|
-
* - nx run <project>:check-circular-deps
|
|
22
|
-
* - nx affected --target=check-circular-deps
|
|
23
|
-
*/
|
|
24
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
exports.createNodesV2 = void 0;
|
|
26
|
-
const path_1 = require("path");
|
|
27
|
-
const fs_1 = require("fs");
|
|
28
|
-
/**
|
|
29
|
-
* Nx V2 Inference Plugin
|
|
30
|
-
* Matches project.json files and creates check-circular-deps target
|
|
31
|
-
*/
|
|
32
|
-
exports.createNodesV2 = [
|
|
33
|
-
// Pattern to match: look for project.json files
|
|
34
|
-
'**/project.json',
|
|
35
|
-
// Inference function
|
|
36
|
-
async (projectFiles, _options, context) => {
|
|
37
|
-
const results = [];
|
|
38
|
-
for (const projectFile of projectFiles) {
|
|
39
|
-
const projectRoot = (0, path_1.dirname)(projectFile);
|
|
40
|
-
const srcDir = (0, path_1.join)(context.workspaceRoot, projectRoot, 'src');
|
|
41
|
-
// Only create target if project has a src/ directory
|
|
42
|
-
if ((0, fs_1.existsSync)(srcDir)) {
|
|
43
|
-
const checkCircularDepsTarget = {
|
|
44
|
-
executor: 'nx:run-commands',
|
|
45
|
-
cache: true,
|
|
46
|
-
inputs: ['default'],
|
|
47
|
-
outputs: [],
|
|
48
|
-
options: {
|
|
49
|
-
command: 'npx madge --circular --extensions ts,tsx src',
|
|
50
|
-
cwd: projectRoot,
|
|
51
|
-
},
|
|
52
|
-
metadata: {
|
|
53
|
-
technologies: ['madge'],
|
|
54
|
-
description: 'Check for circular dependencies using madge',
|
|
55
|
-
},
|
|
56
|
-
};
|
|
57
|
-
const result = {
|
|
58
|
-
projects: {
|
|
59
|
-
[projectRoot]: {
|
|
60
|
-
targets: {
|
|
61
|
-
'check-circular-deps': checkCircularDepsTarget,
|
|
62
|
-
},
|
|
63
|
-
},
|
|
64
|
-
},
|
|
65
|
-
};
|
|
66
|
-
results.push([projectFile, result]);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
return results;
|
|
70
|
-
},
|
|
71
|
-
];
|
|
72
|
-
exports.default = { createNodesV2: exports.createNodesV2 };
|
|
73
|
-
//# sourceMappingURL=plugin.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../../../../../../packages/tooling/dev-config/plugins/circular-deps/plugin.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;;;AAEH,+BAAqC;AACrC,2BAAgC;AAGhC;;;GAGG;AACU,QAAA,aAAa,GAAkB;IACxC,gDAAgD;IAChD,iBAAiB;IAEjB,qBAAqB;IACrB,KAAK,EACD,YAA+B,EAC/B,QAAiB,EACjB,OAA6B,EACD,EAAE;QAC9B,MAAM,OAAO,GAAgD,EAAE,CAAC;QAEhE,KAAK,MAAM,WAAW,IAAI,YAAY,EAAE,CAAC;YACrC,MAAM,WAAW,GAAG,IAAA,cAAO,EAAC,WAAW,CAAC,CAAC;YACzC,MAAM,MAAM,GAAG,IAAA,WAAI,EAAC,OAAO,CAAC,aAAa,EAAE,WAAW,EAAE,KAAK,CAAC,CAAC;YAE/D,qDAAqD;YACrD,IAAI,IAAA,eAAU,EAAC,MAAM,CAAC,EAAE,CAAC;gBACrB,MAAM,uBAAuB,GAAG;oBAC5B,QAAQ,EAAE,iBAAiB;oBAC3B,KAAK,EAAE,IAAI;oBACX,MAAM,EAAE,CAAC,SAAS,CAAC;oBACnB,OAAO,EAAE,EAAc;oBACvB,OAAO,EAAE;wBACL,OAAO,EAAE,8CAA8C;wBACvD,GAAG,EAAE,WAAW;qBACnB;oBACD,QAAQ,EAAE;wBACN,YAAY,EAAE,CAAC,OAAO,CAAC;wBACvB,WAAW,EAAE,6CAA6C;qBAC7D;iBACJ,CAAC;gBAEF,MAAM,MAAM,GAAsB;oBAC9B,QAAQ,EAAE;wBACN,CAAC,WAAW,CAAC,EAAE;4BACX,OAAO,EAAE;gCACL,qBAAqB,EAAE,uBAAuB;6BACjD;yBACJ;qBACJ;iBACJ,CAAC;gBAEF,OAAO,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,MAAM,CAAU,CAAC,CAAC;YACjD,CAAC;QACL,CAAC;QAED,OAAO,OAAO,CAAC;IACnB,CAAC;CACJ,CAAC;AAEF,kBAAe,EAAE,aAAa,EAAb,qBAAa,EAAE,CAAC","sourcesContent":["/**\n * Nx Inference Plugin for Circular Dependency Checking\n *\n * This plugin automatically creates a \"check-circular-deps\" target for ANY project\n * that has a src/ directory, similar to how @nx/eslint/plugin creates lint targets.\n *\n * Benefits:\n * - Zero configuration per project\n * - Works for ALL projects (services + libraries)\n * - New projects automatically get the target\n * - `nx affected --target=check-circular-deps` works on everything\n *\n * Usage:\n * Add to nx.json plugins array:\n * {\n * \"plugins\": [\"@webpieces/dev-config/plugins/circular-deps\"]\n * }\n *\n * Then run:\n * - nx run <project>:check-circular-deps\n * - nx affected --target=check-circular-deps\n */\n\nimport { dirname, join } from 'path';\nimport { existsSync } from 'fs';\nimport type { CreateNodesV2, CreateNodesContextV2, CreateNodesResultV2, CreateNodesResult } from '@nx/devkit';\n\n/**\n * Nx V2 Inference Plugin\n * Matches project.json files and creates check-circular-deps target\n */\nexport const createNodesV2: CreateNodesV2 = [\n // Pattern to match: look for project.json files\n '**/project.json',\n\n // Inference function\n async (\n projectFiles: readonly string[],\n _options: unknown,\n context: CreateNodesContextV2\n ): Promise<CreateNodesResultV2> => {\n const results: Array<readonly [string, CreateNodesResult]> = [];\n\n for (const projectFile of projectFiles) {\n const projectRoot = dirname(projectFile);\n const srcDir = join(context.workspaceRoot, projectRoot, 'src');\n\n // Only create target if project has a src/ directory\n if (existsSync(srcDir)) {\n const checkCircularDepsTarget = {\n executor: 'nx:run-commands',\n cache: true,\n inputs: ['default'],\n outputs: [] as string[],\n options: {\n command: 'npx madge --circular --extensions ts,tsx src',\n cwd: projectRoot,\n },\n metadata: {\n technologies: ['madge'],\n description: 'Check for circular dependencies using madge',\n },\n };\n\n const result: CreateNodesResult = {\n projects: {\n [projectRoot]: {\n targets: {\n 'check-circular-deps': checkCircularDepsTarget,\n },\n },\n },\n };\n\n results.push([projectFile, result] as const);\n }\n }\n\n return results;\n },\n];\n\nexport default { createNodesV2 };\n"]}
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Nx Inference Plugin for Circular Dependency Checking
|
|
3
|
-
*
|
|
4
|
-
* This plugin automatically creates a "check-circular-deps" target for ANY project
|
|
5
|
-
* that has a src/ directory, similar to how @nx/eslint/plugin creates lint targets.
|
|
6
|
-
*
|
|
7
|
-
* Benefits:
|
|
8
|
-
* - Zero configuration per project
|
|
9
|
-
* - Works for ALL projects (services + libraries)
|
|
10
|
-
* - New projects automatically get the target
|
|
11
|
-
* - `nx affected --target=check-circular-deps` works on everything
|
|
12
|
-
*
|
|
13
|
-
* Usage:
|
|
14
|
-
* Add to nx.json plugins array:
|
|
15
|
-
* {
|
|
16
|
-
* "plugins": ["@webpieces/dev-config/plugins/circular-deps"]
|
|
17
|
-
* }
|
|
18
|
-
*
|
|
19
|
-
* Then run:
|
|
20
|
-
* - nx run <project>:check-circular-deps
|
|
21
|
-
* - nx affected --target=check-circular-deps
|
|
22
|
-
*/
|
|
23
|
-
|
|
24
|
-
import { dirname, join } from 'path';
|
|
25
|
-
import { existsSync } from 'fs';
|
|
26
|
-
import type { CreateNodesV2, CreateNodesContextV2, CreateNodesResultV2, CreateNodesResult } from '@nx/devkit';
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Nx V2 Inference Plugin
|
|
30
|
-
* Matches project.json files and creates check-circular-deps target
|
|
31
|
-
*/
|
|
32
|
-
export const createNodesV2: CreateNodesV2 = [
|
|
33
|
-
// Pattern to match: look for project.json files
|
|
34
|
-
'**/project.json',
|
|
35
|
-
|
|
36
|
-
// Inference function
|
|
37
|
-
async (
|
|
38
|
-
projectFiles: readonly string[],
|
|
39
|
-
_options: unknown,
|
|
40
|
-
context: CreateNodesContextV2
|
|
41
|
-
): Promise<CreateNodesResultV2> => {
|
|
42
|
-
const results: Array<readonly [string, CreateNodesResult]> = [];
|
|
43
|
-
|
|
44
|
-
for (const projectFile of projectFiles) {
|
|
45
|
-
const projectRoot = dirname(projectFile);
|
|
46
|
-
const srcDir = join(context.workspaceRoot, projectRoot, 'src');
|
|
47
|
-
|
|
48
|
-
// Only create target if project has a src/ directory
|
|
49
|
-
if (existsSync(srcDir)) {
|
|
50
|
-
const checkCircularDepsTarget = {
|
|
51
|
-
executor: 'nx:run-commands',
|
|
52
|
-
cache: true,
|
|
53
|
-
inputs: ['default'],
|
|
54
|
-
outputs: [] as string[],
|
|
55
|
-
options: {
|
|
56
|
-
command: 'npx madge --circular --extensions ts,tsx src',
|
|
57
|
-
cwd: projectRoot,
|
|
58
|
-
},
|
|
59
|
-
metadata: {
|
|
60
|
-
technologies: ['madge'],
|
|
61
|
-
description: 'Check for circular dependencies using madge',
|
|
62
|
-
},
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
const result: CreateNodesResult = {
|
|
66
|
-
projects: {
|
|
67
|
-
[projectRoot]: {
|
|
68
|
-
targets: {
|
|
69
|
-
'check-circular-deps': checkCircularDepsTarget,
|
|
70
|
-
},
|
|
71
|
-
},
|
|
72
|
-
},
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
results.push([projectFile, result] as const);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
return results;
|
|
80
|
-
},
|
|
81
|
-
];
|
|
82
|
-
|
|
83
|
-
export default { createNodesV2 };
|