@webpieces/dev-config 0.2.17 → 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.
Files changed (85) hide show
  1. package/README.md +44 -1
  2. package/architecture/executors/generate/executor.d.ts +17 -0
  3. package/architecture/executors/generate/executor.js +67 -0
  4. package/architecture/executors/generate/executor.js.map +1 -0
  5. package/architecture/executors/generate/executor.ts +83 -0
  6. package/architecture/executors/generate/schema.json +14 -0
  7. package/architecture/executors/validate-architecture-unchanged/executor.d.ts +17 -0
  8. package/architecture/executors/validate-architecture-unchanged/executor.js +65 -0
  9. package/architecture/executors/validate-architecture-unchanged/executor.js.map +1 -0
  10. package/architecture/executors/validate-architecture-unchanged/executor.ts +81 -0
  11. package/architecture/executors/validate-architecture-unchanged/schema.json +14 -0
  12. package/architecture/executors/validate-no-cycles/executor.d.ts +16 -0
  13. package/architecture/executors/validate-no-cycles/executor.js +48 -0
  14. package/architecture/executors/validate-no-cycles/executor.js.map +1 -0
  15. package/architecture/executors/validate-no-cycles/executor.ts +60 -0
  16. package/architecture/executors/validate-no-cycles/schema.json +8 -0
  17. package/architecture/executors/validate-no-skiplevel-deps/executor.d.ts +19 -0
  18. package/architecture/executors/validate-no-skiplevel-deps/executor.js +227 -0
  19. package/architecture/executors/validate-no-skiplevel-deps/executor.js.map +1 -0
  20. package/architecture/executors/validate-no-skiplevel-deps/executor.ts +267 -0
  21. package/architecture/executors/validate-no-skiplevel-deps/schema.json +8 -0
  22. package/architecture/executors/visualize/executor.d.ts +17 -0
  23. package/architecture/executors/visualize/executor.js +49 -0
  24. package/architecture/executors/visualize/executor.js.map +1 -0
  25. package/architecture/executors/visualize/executor.ts +63 -0
  26. package/architecture/executors/visualize/schema.json +14 -0
  27. package/architecture/index.d.ts +19 -0
  28. package/architecture/index.js +23 -0
  29. package/architecture/index.js.map +1 -0
  30. package/architecture/index.ts +20 -0
  31. package/architecture/lib/graph-comparator.d.ts +39 -0
  32. package/architecture/lib/graph-comparator.js +100 -0
  33. package/architecture/lib/graph-comparator.js.map +1 -0
  34. package/architecture/lib/graph-comparator.ts +141 -0
  35. package/architecture/lib/graph-generator.d.ts +19 -0
  36. package/architecture/lib/graph-generator.js +88 -0
  37. package/architecture/lib/graph-generator.js.map +1 -0
  38. package/architecture/lib/graph-generator.ts +102 -0
  39. package/architecture/lib/graph-loader.d.ts +31 -0
  40. package/architecture/lib/graph-loader.js +70 -0
  41. package/architecture/lib/graph-loader.js.map +1 -0
  42. package/architecture/lib/graph-loader.ts +82 -0
  43. package/architecture/lib/graph-sorter.d.ts +37 -0
  44. package/architecture/lib/graph-sorter.js +110 -0
  45. package/architecture/lib/graph-sorter.js.map +1 -0
  46. package/architecture/lib/graph-sorter.ts +137 -0
  47. package/architecture/lib/graph-visualizer.d.ts +29 -0
  48. package/architecture/lib/graph-visualizer.js +209 -0
  49. package/architecture/lib/graph-visualizer.js.map +1 -0
  50. package/architecture/lib/graph-visualizer.ts +222 -0
  51. package/architecture/lib/package-validator.d.ts +38 -0
  52. package/architecture/lib/package-validator.js +105 -0
  53. package/architecture/lib/package-validator.js.map +1 -0
  54. package/architecture/lib/package-validator.ts +144 -0
  55. package/config/eslint/base.mjs +6 -0
  56. package/eslint-plugin/__tests__/max-file-lines.test.ts +207 -0
  57. package/eslint-plugin/__tests__/max-method-lines.test.ts +258 -0
  58. package/eslint-plugin/__tests__/no-unmanaged-exceptions.test.ts +359 -0
  59. package/eslint-plugin/index.d.ts +11 -0
  60. package/eslint-plugin/index.js +15 -0
  61. package/eslint-plugin/index.js.map +1 -1
  62. package/eslint-plugin/index.ts +15 -0
  63. package/eslint-plugin/rules/enforce-architecture.d.ts +15 -0
  64. package/eslint-plugin/rules/enforce-architecture.js +406 -0
  65. package/eslint-plugin/rules/enforce-architecture.js.map +1 -0
  66. package/eslint-plugin/rules/enforce-architecture.ts +469 -0
  67. package/eslint-plugin/rules/max-file-lines.d.ts +12 -0
  68. package/eslint-plugin/rules/max-file-lines.js +257 -0
  69. package/eslint-plugin/rules/max-file-lines.js.map +1 -0
  70. package/eslint-plugin/rules/max-file-lines.ts +272 -0
  71. package/eslint-plugin/rules/max-method-lines.d.ts +12 -0
  72. package/eslint-plugin/rules/max-method-lines.js +240 -0
  73. package/eslint-plugin/rules/max-method-lines.js.map +1 -0
  74. package/eslint-plugin/rules/max-method-lines.ts +287 -0
  75. package/eslint-plugin/rules/no-unmanaged-exceptions.d.ts +22 -0
  76. package/eslint-plugin/rules/no-unmanaged-exceptions.js +605 -0
  77. package/eslint-plugin/rules/no-unmanaged-exceptions.js.map +1 -0
  78. package/eslint-plugin/rules/no-unmanaged-exceptions.ts +621 -0
  79. package/executors.json +29 -0
  80. package/generators/init/generator.ts +130 -0
  81. package/generators/init/schema.json +15 -0
  82. package/generators.json +10 -0
  83. package/package.json +20 -3
  84. package/plugin/README.md +236 -0
  85. package/plugin/index.ts +4 -0
@@ -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
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "$schema": "http://json-schema.org/schema",
3
+ "generators": {
4
+ "init": {
5
+ "factory": "./generators/init/generator",
6
+ "schema": "./generators/init/schema.json",
7
+ "description": "Initialize @webpieces/dev-config in an Nx workspace"
8
+ }
9
+ }
10
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webpieces/dev-config",
3
- "version": "0.2.17",
3
+ "version": "0.2.23",
4
4
  "description": "Development configuration, scripts, and patterns for WebPieces projects",
5
5
  "type": "commonjs",
6
6
  "bin": {
@@ -11,21 +11,38 @@
11
11
  "wp-use-published": "./bin/use-published-webpieces.sh",
12
12
  "wp-setup-patterns": "./bin/setup-claude-patterns.sh"
13
13
  },
14
+ "executors": "./executors.json",
15
+ "generators": "./generators.json",
14
16
  "exports": {
17
+ ".": "./index.js",
18
+ "./package.json": "./package.json",
15
19
  "./eslint": "./config/eslint/base.mjs",
16
20
  "./eslint-plugin": "./eslint-plugin/index.js",
17
21
  "./jest": "./config/jest/preset.js",
18
- "./tsconfig": "./config/typescript/tsconfig.base.json"
22
+ "./tsconfig": "./config/typescript/tsconfig.base.json",
23
+ "./plugin": "./plugin.js",
24
+ "./plugins/circular-deps": "./plugins/circular-deps/index.js",
25
+ "./architecture": "./architecture/index.js",
26
+ "./executors.json": "./executors.json",
27
+ "./generators.json": "./generators.json"
19
28
  },
20
29
  "files": [
21
30
  "bin/**/*",
22
31
  "config/**/*",
23
32
  "eslint-plugin/**/*",
24
33
  "patterns/**/*",
34
+ "plugins/**/*",
35
+ "plugin/**/*",
36
+ "plugin.js",
37
+ "generators/**/*",
38
+ "generators.json",
39
+ "architecture/**/*",
40
+ "executors.json",
25
41
  "README.md"
26
42
  ],
27
43
  "peerDependencies": {
28
- "eslint": ">=8.0.0"
44
+ "eslint": ">=8.0.0",
45
+ "@nx/devkit": ">=18.0.0"
29
46
  },
30
47
  "keywords": [
31
48
  "webpieces",
@@ -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)
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Re-export plugin from parent directory for clean imports
3
+ */
4
+ export * from '../plugin';