@webpieces/dev-config 0.2.27 → 0.2.28

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webpieces/dev-config",
3
- "version": "0.2.27",
3
+ "version": "0.2.28",
4
4
  "description": "Development configuration, scripts, and patterns for WebPieces projects",
5
5
  "type": "commonjs",
6
6
  "bin": {
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Re-export plugin from parent directory for clean imports
3
+ */
4
+ export * from '../plugin';
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ /**
5
+ * Re-export plugin from parent directory for clean imports
6
+ */
7
+ tslib_1.__exportStar(require("../plugin"), exports);
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/tooling/dev-config/plugin/index.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,oDAA0B","sourcesContent":["/**\n * Re-export plugin from parent directory for clean imports\n */\nexport * from '../plugin';\n"]}
package/plugin.js ADDED
@@ -0,0 +1,260 @@
1
+ "use strict";
2
+ /**
3
+ * Unified Nx Inference Plugin for @webpieces/dev-config
4
+ *
5
+ * This plugin automatically creates targets for:
6
+ * 1. Workspace-level architecture validation (generate, visualize, validate-*)
7
+ * 2. Per-project circular dependency checking
8
+ *
9
+ * Install with: nx add @webpieces/dev-config
10
+ *
11
+ * Usage:
12
+ * Add to nx.json plugins array:
13
+ * {
14
+ * "plugins": ["@webpieces/dev-config"]
15
+ * }
16
+ *
17
+ * Then all targets appear automatically without manual project.json configuration.
18
+ */
19
+ Object.defineProperty(exports, "__esModule", { value: true });
20
+ exports.createNodesV2 = void 0;
21
+ const path_1 = require("path");
22
+ const fs_1 = require("fs");
23
+ const DEFAULT_OPTIONS = {
24
+ circularDeps: {
25
+ enabled: true,
26
+ targetName: 'check-circular-deps',
27
+ excludePatterns: [],
28
+ },
29
+ workspace: {
30
+ enabled: true,
31
+ targetPrefix: 'arch:',
32
+ graphPath: 'architecture/dependencies.json',
33
+ validations: {
34
+ noCycles: true,
35
+ noSkipLevelDeps: true,
36
+ architectureUnchanged: true,
37
+ },
38
+ features: {
39
+ generate: true,
40
+ visualize: true,
41
+ },
42
+ },
43
+ };
44
+ function normalizeOptions(options) {
45
+ const circularDeps = {
46
+ ...DEFAULT_OPTIONS.circularDeps,
47
+ ...options?.circularDeps,
48
+ };
49
+ const workspace = {
50
+ ...DEFAULT_OPTIONS.workspace,
51
+ ...options?.workspace,
52
+ validations: {
53
+ ...DEFAULT_OPTIONS.workspace.validations,
54
+ ...options?.workspace?.validations,
55
+ },
56
+ features: {
57
+ ...DEFAULT_OPTIONS.workspace.features,
58
+ ...options?.workspace?.features,
59
+ },
60
+ };
61
+ return {
62
+ circularDeps,
63
+ workspace,
64
+ };
65
+ }
66
+ /**
67
+ * Nx V2 Inference Plugin
68
+ * Matches project.json files and creates architecture + circular-deps targets
69
+ */
70
+ exports.createNodesV2 = [
71
+ // Pattern to match: look for project.json files
72
+ '**/project.json',
73
+ // Inference function
74
+ async (projectFiles, options, context) => {
75
+ const opts = normalizeOptions(options);
76
+ const results = [];
77
+ // Phase 1: Add workspace-level architecture targets to root
78
+ if (opts.workspace.enabled) {
79
+ const rootProject = projectFiles.find((f) => (0, path_1.dirname)(f) === '.');
80
+ if (rootProject) {
81
+ const workspaceTargets = createWorkspaceTargets(opts);
82
+ if (Object.keys(workspaceTargets).length > 0) {
83
+ const result = {
84
+ projects: {
85
+ '.': {
86
+ targets: workspaceTargets,
87
+ },
88
+ },
89
+ };
90
+ results.push([rootProject, result]);
91
+ }
92
+ }
93
+ }
94
+ // Phase 2: Add per-project circular-deps targets
95
+ if (opts.circularDeps.enabled) {
96
+ for (const projectFile of projectFiles) {
97
+ const projectRoot = (0, path_1.dirname)(projectFile);
98
+ // Skip workspace root (already handled)
99
+ if (projectRoot === '.')
100
+ continue;
101
+ // Check exclude patterns
102
+ if (isExcluded(projectRoot, opts.circularDeps.excludePatterns)) {
103
+ continue;
104
+ }
105
+ // Only create target if project has a src/ directory
106
+ const srcDir = (0, path_1.join)(context.workspaceRoot, projectRoot, 'src');
107
+ if ((0, fs_1.existsSync)(srcDir)) {
108
+ const targetName = opts.circularDeps.targetName;
109
+ const checkCircularDepsTarget = createCircularDepsTarget(projectRoot, targetName);
110
+ const result = {
111
+ projects: {
112
+ [projectRoot]: {
113
+ targets: {
114
+ [targetName]: checkCircularDepsTarget,
115
+ },
116
+ },
117
+ },
118
+ };
119
+ results.push([projectFile, result]);
120
+ }
121
+ }
122
+ }
123
+ return results;
124
+ },
125
+ ];
126
+ /**
127
+ * Create workspace-level architecture validation targets
128
+ */
129
+ function createWorkspaceTargets(opts) {
130
+ const targets = {};
131
+ const prefix = opts.workspace.targetPrefix;
132
+ const graphPath = opts.workspace.graphPath;
133
+ // Add help target (always available)
134
+ targets[`${prefix}help`] = createHelpTarget();
135
+ if (opts.workspace.features.generate) {
136
+ targets[`${prefix}generate`] = createGenerateTarget(graphPath);
137
+ }
138
+ if (opts.workspace.features.visualize) {
139
+ targets[`${prefix}visualize`] = createVisualizeTarget(prefix, graphPath);
140
+ }
141
+ if (opts.workspace.validations.noCycles) {
142
+ targets[`${prefix}validate-no-cycles`] = createValidateNoCyclesTarget();
143
+ }
144
+ if (opts.workspace.validations.architectureUnchanged) {
145
+ targets[`${prefix}validate-architecture-unchanged`] = createValidateUnchangedTarget(graphPath);
146
+ }
147
+ if (opts.workspace.validations.noSkipLevelDeps) {
148
+ targets[`${prefix}validate-no-skiplevel-deps`] = createValidateNoSkipLevelTarget();
149
+ }
150
+ return targets;
151
+ }
152
+ function createGenerateTarget(graphPath) {
153
+ return {
154
+ executor: '@webpieces/dev-config:generate',
155
+ cache: true,
156
+ inputs: ['default'],
157
+ outputs: ['{workspaceRoot}/architecture/dependencies.json'],
158
+ options: { graphPath },
159
+ metadata: {
160
+ technologies: ['nx'],
161
+ description: 'Generate the architecture dependency graph from project.json files',
162
+ },
163
+ };
164
+ }
165
+ function createVisualizeTarget(prefix, graphPath) {
166
+ return {
167
+ executor: '@webpieces/dev-config:visualize',
168
+ dependsOn: [`${prefix}generate`],
169
+ options: { graphPath },
170
+ metadata: {
171
+ technologies: ['nx'],
172
+ description: 'Generate visual representations of the architecture graph',
173
+ },
174
+ };
175
+ }
176
+ function createValidateNoCyclesTarget() {
177
+ return {
178
+ executor: '@webpieces/dev-config:validate-no-cycles',
179
+ cache: true,
180
+ inputs: ['default'],
181
+ metadata: {
182
+ technologies: ['nx'],
183
+ description: 'Validate the architecture has no circular dependencies',
184
+ },
185
+ };
186
+ }
187
+ function createValidateUnchangedTarget(graphPath) {
188
+ return {
189
+ executor: '@webpieces/dev-config:validate-architecture-unchanged',
190
+ cache: true,
191
+ inputs: ['default', '{workspaceRoot}/architecture/dependencies.json'],
192
+ options: { graphPath },
193
+ metadata: {
194
+ technologies: ['nx'],
195
+ description: 'Validate the architecture matches the saved blessed graph',
196
+ },
197
+ };
198
+ }
199
+ function createValidateNoSkipLevelTarget() {
200
+ return {
201
+ executor: '@webpieces/dev-config:validate-no-skiplevel-deps',
202
+ cache: true,
203
+ inputs: ['default'],
204
+ metadata: {
205
+ technologies: ['nx'],
206
+ description: 'Validate no project has redundant transitive dependencies',
207
+ },
208
+ };
209
+ }
210
+ function createHelpTarget() {
211
+ return {
212
+ executor: '@webpieces/dev-config:help',
213
+ cache: true,
214
+ metadata: {
215
+ technologies: ['nx'],
216
+ description: 'Display help for @webpieces/dev-config commands and targets',
217
+ },
218
+ };
219
+ }
220
+ /**
221
+ * Create per-project circular dependency checking target
222
+ */
223
+ function createCircularDepsTarget(projectRoot, targetName) {
224
+ return {
225
+ executor: 'nx:run-commands',
226
+ cache: true,
227
+ inputs: ['default'],
228
+ outputs: [],
229
+ options: {
230
+ command: 'npx madge --circular --extensions ts,tsx src',
231
+ cwd: projectRoot,
232
+ },
233
+ metadata: {
234
+ technologies: ['madge'],
235
+ description: 'Check for circular dependencies using madge',
236
+ },
237
+ };
238
+ }
239
+ /**
240
+ * Check if a project should be excluded based on patterns
241
+ */
242
+ function isExcluded(projectRoot, excludePatterns) {
243
+ if (excludePatterns.length === 0) {
244
+ return false;
245
+ }
246
+ // Simple glob matching (could be enhanced with minimatch if needed)
247
+ return excludePatterns.some((pattern) => {
248
+ // Convert glob pattern to regex
249
+ const regexPattern = pattern
250
+ .replace(/\*\*/g, '.*') // ** matches any path
251
+ .replace(/\*/g, '[^/]*'); // * matches any string except /
252
+ const regex = new RegExp(`^${regexPattern}$`);
253
+ return regex.test(projectRoot);
254
+ });
255
+ }
256
+ /**
257
+ * Export plugin as default for Nx
258
+ */
259
+ exports.default = { createNodesV2: exports.createNodesV2 };
260
+ //# sourceMappingURL=plugin.js.map