@webpieces/nx-webpieces-rules 0.0.1 → 0.2.114

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 (120) hide show
  1. package/package.json +4 -4
  2. package/src/executor-result.d.ts +4 -0
  3. package/src/executor-result.js +10 -0
  4. package/src/executor-result.js.map +1 -0
  5. package/src/executors/generate/executor.d.ts +16 -0
  6. package/src/executors/generate/{executor.ts → executor.js} +15 -30
  7. package/src/executors/generate/executor.js.map +1 -0
  8. package/src/executors/help/executor.d.ts +8 -0
  9. package/src/executors/help/{executor.ts → executor.js} +5 -12
  10. package/src/executors/help/executor.js.map +1 -0
  11. package/src/executors/validate-architecture-unchanged/executor.d.ts +17 -0
  12. package/src/executors/validate-architecture-unchanged/{executor.ts → executor.js} +24 -46
  13. package/src/executors/validate-architecture-unchanged/executor.js.map +1 -0
  14. package/src/executors/validate-catch-error-pattern/executor.d.ts +3 -0
  15. package/src/executors/validate-catch-error-pattern/executor.js +10 -0
  16. package/src/executors/validate-catch-error-pattern/executor.js.map +1 -0
  17. package/src/executors/validate-code/executor.d.ts +3 -0
  18. package/src/executors/validate-code/executor.js +10 -0
  19. package/src/executors/validate-code/executor.js.map +1 -0
  20. package/src/executors/validate-dtos/executor.d.ts +3 -0
  21. package/src/executors/validate-dtos/executor.js +10 -0
  22. package/src/executors/validate-dtos/executor.js.map +1 -0
  23. package/src/executors/validate-eslint-sync/executor.d.ts +7 -0
  24. package/src/executors/validate-eslint-sync/{executor.ts → executor.js} +19 -37
  25. package/src/executors/validate-eslint-sync/executor.js.map +1 -0
  26. package/src/executors/validate-modified-files/executor.d.ts +3 -0
  27. package/src/executors/validate-modified-files/executor.js +10 -0
  28. package/src/executors/validate-modified-files/executor.js.map +1 -0
  29. package/src/executors/validate-modified-methods/executor.d.ts +3 -0
  30. package/src/executors/validate-modified-methods/executor.js +10 -0
  31. package/src/executors/validate-modified-methods/executor.js.map +1 -0
  32. package/src/executors/validate-new-methods/executor.d.ts +3 -0
  33. package/src/executors/validate-new-methods/executor.js +10 -0
  34. package/src/executors/validate-new-methods/executor.js.map +1 -0
  35. package/src/executors/validate-no-any-unknown/executor.d.ts +3 -0
  36. package/src/executors/validate-no-any-unknown/executor.js +10 -0
  37. package/src/executors/validate-no-any-unknown/executor.js.map +1 -0
  38. package/src/executors/validate-no-architecture-cycles/executor.d.ts +16 -0
  39. package/src/executors/validate-no-architecture-cycles/{executor.ts → executor.js} +16 -28
  40. package/src/executors/validate-no-architecture-cycles/executor.js.map +1 -0
  41. package/src/executors/validate-no-destructure/executor.d.ts +3 -0
  42. package/src/executors/validate-no-destructure/executor.js +10 -0
  43. package/src/executors/validate-no-destructure/executor.js.map +1 -0
  44. package/src/executors/validate-no-direct-api-resolver/executor.d.ts +3 -0
  45. package/src/executors/validate-no-direct-api-resolver/executor.js +10 -0
  46. package/src/executors/validate-no-direct-api-resolver/executor.js.map +1 -0
  47. package/src/executors/validate-no-implicit-any/executor.d.ts +3 -0
  48. package/src/executors/validate-no-implicit-any/executor.js +10 -0
  49. package/src/executors/validate-no-implicit-any/executor.js.map +1 -0
  50. package/src/executors/validate-no-inline-types/executor.d.ts +3 -0
  51. package/src/executors/validate-no-inline-types/executor.js +10 -0
  52. package/src/executors/validate-no-inline-types/executor.js.map +1 -0
  53. package/src/executors/validate-no-skiplevel-deps/executor.d.ts +19 -0
  54. package/src/executors/validate-no-skiplevel-deps/{executor.ts → executor.js} +23 -63
  55. package/src/executors/validate-no-skiplevel-deps/executor.js.map +1 -0
  56. package/src/executors/validate-no-unmanaged-exceptions/executor.d.ts +3 -0
  57. package/src/executors/validate-no-unmanaged-exceptions/executor.js +10 -0
  58. package/src/executors/validate-no-unmanaged-exceptions/executor.js.map +1 -0
  59. package/src/executors/validate-packagejson/executor.d.ts +16 -0
  60. package/src/executors/validate-packagejson/{executor.ts → executor.js} +15 -32
  61. package/src/executors/validate-packagejson/executor.js.map +1 -0
  62. package/src/executors/validate-prisma-converters/executor.d.ts +3 -0
  63. package/src/executors/validate-prisma-converters/executor.js +10 -0
  64. package/src/executors/validate-prisma-converters/executor.js.map +1 -0
  65. package/src/executors/validate-return-types/executor.d.ts +3 -0
  66. package/src/executors/validate-return-types/executor.js +10 -0
  67. package/src/executors/validate-return-types/executor.js.map +1 -0
  68. package/src/executors/validate-ts-in-src/executor.d.ts +32 -0
  69. package/src/executors/validate-ts-in-src/{executor.ts → executor.js} +80 -135
  70. package/src/executors/validate-ts-in-src/executor.js.map +1 -0
  71. package/src/executors/validate-versions-locked/executor.d.ts +22 -0
  72. package/src/executors/validate-versions-locked/{executor.ts → executor.js} +49 -116
  73. package/src/executors/validate-versions-locked/executor.js.map +1 -0
  74. package/src/executors/visualize/executor.d.ts +17 -0
  75. package/src/executors/visualize/{executor.ts → executor.js} +16 -30
  76. package/src/executors/visualize/executor.js.map +1 -0
  77. package/src/{index.ts → index.d.ts} +5 -1
  78. package/src/index.js +14 -0
  79. package/src/index.js.map +1 -0
  80. package/src/lib/graph-comparator.d.ts +39 -0
  81. package/src/lib/{graph-comparator.ts → graph-comparator.js} +18 -67
  82. package/src/lib/graph-comparator.js.map +1 -0
  83. package/src/lib/graph-generator.d.ts +19 -0
  84. package/src/lib/{graph-generator.ts → graph-generator.js} +17 -30
  85. package/src/lib/graph-generator.js.map +1 -0
  86. package/src/lib/graph-loader.d.ts +31 -0
  87. package/src/lib/{graph-loader.ts → graph-loader.js} +24 -42
  88. package/src/lib/graph-loader.js.map +1 -0
  89. package/src/lib/graph-sorter.d.ts +37 -0
  90. package/src/lib/{graph-sorter.ts → graph-sorter.js} +26 -53
  91. package/src/lib/graph-sorter.js.map +1 -0
  92. package/src/lib/graph-visualizer.d.ts +31 -0
  93. package/src/lib/{graph-visualizer.ts → graph-visualizer.js} +32 -56
  94. package/src/lib/graph-visualizer.js.map +1 -0
  95. package/src/lib/package-validator.d.ts +40 -0
  96. package/src/lib/package-validator.js +175 -0
  97. package/src/lib/package-validator.js.map +1 -0
  98. package/src/plugin.d.ts +86 -0
  99. package/src/{plugin.ts → plugin.js} +100 -255
  100. package/src/plugin.js.map +1 -0
  101. package/src/toError.d.ts +5 -0
  102. package/src/{toError.ts → toError.js} +7 -6
  103. package/src/toError.js.map +1 -0
  104. package/LICENSE +0 -373
  105. package/src/executor-result.ts +0 -7
  106. package/src/executors/validate-catch-error-pattern/executor.ts +0 -11
  107. package/src/executors/validate-code/executor.ts +0 -11
  108. package/src/executors/validate-dtos/executor.ts +0 -11
  109. package/src/executors/validate-modified-files/executor.ts +0 -11
  110. package/src/executors/validate-modified-methods/executor.ts +0 -11
  111. package/src/executors/validate-new-methods/executor.ts +0 -11
  112. package/src/executors/validate-no-any-unknown/executor.ts +0 -11
  113. package/src/executors/validate-no-destructure/executor.ts +0 -11
  114. package/src/executors/validate-no-direct-api-resolver/executor.ts +0 -11
  115. package/src/executors/validate-no-implicit-any/executor.ts +0 -11
  116. package/src/executors/validate-no-inline-types/executor.ts +0 -11
  117. package/src/executors/validate-no-unmanaged-exceptions/executor.ts +0 -11
  118. package/src/executors/validate-prisma-converters/executor.ts +0 -11
  119. package/src/executors/validate-return-types/executor.ts +0 -11
  120. package/src/lib/package-validator.ts +0 -184
@@ -1,11 +0,0 @@
1
- import type { ExecutorContext } from '@nx/devkit';
2
- import { ExecutorResult } from '../../executor-result';
3
- import { validateNoInlineTypes } from '@webpieces/code-rules';
4
-
5
- export default async function runExecutor(
6
- // webpieces-disable no-any-unknown -- options are passed through to code-rules validators
7
- options: Record<string, unknown>,
8
- context: ExecutorContext,
9
- ): Promise<ExecutorResult> {
10
- return validateNoInlineTypes(options, context.root);
11
- }
@@ -1,11 +0,0 @@
1
- import type { ExecutorContext } from '@nx/devkit';
2
- import { ExecutorResult } from '../../executor-result';
3
- import { validateNoUnmanagedExceptions } from '@webpieces/code-rules';
4
-
5
- export default async function runExecutor(
6
- // webpieces-disable no-any-unknown -- options are passed through to code-rules validators
7
- options: Record<string, unknown>,
8
- context: ExecutorContext,
9
- ): Promise<ExecutorResult> {
10
- return validateNoUnmanagedExceptions(options, context.root);
11
- }
@@ -1,11 +0,0 @@
1
- import type { ExecutorContext } from '@nx/devkit';
2
- import { ExecutorResult } from '../../executor-result';
3
- import { validatePrismaConverters } from '@webpieces/code-rules';
4
-
5
- export default async function runExecutor(
6
- // webpieces-disable no-any-unknown -- options are passed through to code-rules validators
7
- options: Record<string, unknown>,
8
- context: ExecutorContext,
9
- ): Promise<ExecutorResult> {
10
- return validatePrismaConverters(options, context.root);
11
- }
@@ -1,11 +0,0 @@
1
- import type { ExecutorContext } from '@nx/devkit';
2
- import { ExecutorResult } from '../../executor-result';
3
- import { validateReturnTypes } from '@webpieces/code-rules';
4
-
5
- export default async function runExecutor(
6
- // webpieces-disable no-any-unknown -- options are passed through to code-rules validators
7
- options: Record<string, unknown>,
8
- context: ExecutorContext,
9
- ): Promise<ExecutorResult> {
10
- return validateReturnTypes(options, context.root);
11
- }
@@ -1,184 +0,0 @@
1
- /**
2
- * Package Validator
3
- *
4
- * Validates that package.json dependencies match the project.json build.dependsOn
5
- * This ensures the two sources of truth don't drift apart.
6
- */
7
-
8
- import * as fs from 'fs';
9
- import * as path from 'path';
10
- import {
11
- createProjectGraphAsync,
12
- readProjectsConfigurationFromProjectGraph,
13
- } from '@nx/devkit';
14
- import { toError } from '../toError';
15
-
16
- /**
17
- * Validation result for a single project
18
- */
19
- export interface ProjectValidationResult {
20
- project: string;
21
- valid: boolean;
22
- missingInPackageJson: string[];
23
- extraInPackageJson: string[];
24
- }
25
-
26
- /**
27
- * Overall validation result
28
- */
29
- export interface ValidationResult {
30
- valid: boolean;
31
- errors: string[];
32
- projectResults: ProjectValidationResult[];
33
- }
34
-
35
- /**
36
- * Read package.json dependencies for a project
37
- * Returns null if package.json doesn't exist (apps often don't have one)
38
- */
39
- function readPackageJsonDeps(workspaceRoot: string, projectRoot: string): string[] | null {
40
- const packageJsonPath = path.join(workspaceRoot, projectRoot, 'package.json');
41
-
42
- if (!fs.existsSync(packageJsonPath)) {
43
- return null; // No package.json - skip validation for this project
44
- }
45
-
46
- // eslint-disable-next-line @webpieces/no-unmanaged-exceptions
47
- try {
48
- const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
49
- const deps: string[] = [];
50
-
51
- // Collect ALL dependencies from package.json
52
- for (const depType of ['dependencies', 'peerDependencies']) {
53
- const depObj = packageJson[depType] || {};
54
- for (const depName of Object.keys(depObj)) {
55
- if (!deps.includes(depName)) {
56
- deps.push(depName);
57
- }
58
- }
59
- }
60
-
61
- return deps.sort();
62
- } catch (err: unknown) {
63
- //const error = toError(err);
64
- void err;
65
- console.warn(`Could not read package.json at ${packageJsonPath}`);
66
- return [];
67
- }
68
- }
69
-
70
- /**
71
- * Build map of project names to their package names
72
- * e.g., "core-util" → "@webpieces/core-util"
73
- */
74
- function buildProjectToPackageMap(
75
- workspaceRoot: string,
76
- // webpieces-disable no-any-unknown -- Nx devkit projectsConfig type is dynamic and not strongly typed
77
- projectsConfig: any
78
- ): Map<string, string> {
79
- const map = new Map<string, string>();
80
-
81
- // webpieces-disable no-any-unknown -- Nx devkit projects config entries are untyped
82
- for (const [projectName, config] of Object.entries<any>(projectsConfig.projects)) {
83
- const packageJsonPath = path.join(workspaceRoot, config.root, 'package.json');
84
- if (fs.existsSync(packageJsonPath)) {
85
- // eslint-disable-next-line @webpieces/no-unmanaged-exceptions
86
- try {
87
- const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
88
- if (packageJson.name) {
89
- map.set(projectName, packageJson.name);
90
- }
91
- } catch (err: unknown) {
92
- //const error = toError(err);
93
- void err;
94
- // Ignore parse errors
95
- }
96
- }
97
- }
98
-
99
- return map;
100
- }
101
-
102
- /**
103
- * Validate that package.json dependencies match the dependency graph
104
- *
105
- * For each project in the graph:
106
- * - Check that all graph dependencies exist in package.json
107
- * - Maps project names to package names for accurate comparison
108
- *
109
- * @param graph - Enhanced graph with project dependencies (uses project names)
110
- * @param workspaceRoot - Absolute path to workspace root
111
- * @returns Validation result with errors if any
112
- */
113
- interface GraphEntry {
114
- level: number;
115
- dependsOn: string[];
116
- }
117
-
118
- export async function validatePackageJsonDependencies(
119
- graph: Record<string, GraphEntry>,
120
- workspaceRoot: string
121
- ): Promise<ValidationResult> {
122
- const projectGraph = await createProjectGraphAsync();
123
- const projectsConfig = readProjectsConfigurationFromProjectGraph(projectGraph);
124
-
125
- // Build map: project name → package name
126
- const projectToPackage = buildProjectToPackageMap(workspaceRoot, projectsConfig);
127
-
128
- const errors: string[] = [];
129
- const projectResults: ProjectValidationResult[] = [];
130
-
131
- for (const [projectName, entry] of Object.entries(graph)) {
132
- // Find the project config using project name directly
133
- const projectConfig = projectsConfig.projects[projectName];
134
- if (!projectConfig) {
135
- continue;
136
- }
137
-
138
- const projectRoot = projectConfig.root;
139
- const packageJsonDeps = readPackageJsonDeps(workspaceRoot, projectRoot);
140
-
141
- if (packageJsonDeps === null) {
142
- continue;
143
- }
144
-
145
- // Convert graph dependencies (project names) to package names for comparison
146
- const missingInPackageJson: string[] = [];
147
- for (const depProjectName of entry.dependsOn) {
148
- const depPackageName = projectToPackage.get(depProjectName) || depProjectName;
149
- if (!packageJsonDeps.includes(depPackageName)) {
150
- missingInPackageJson.push(depProjectName);
151
- }
152
- }
153
-
154
- // Check for extra dependencies in package.json (not critical, just informational)
155
- const extraInPackageJson: string[] = [];
156
- for (const dep of packageJsonDeps) {
157
- if (!entry.dependsOn.includes(dep)) {
158
- extraInPackageJson.push(dep);
159
- }
160
- }
161
-
162
- const valid = missingInPackageJson.length === 0;
163
-
164
- if (!valid) {
165
- errors.push(
166
- `Project ${projectName} (${projectRoot}/package.json) is missing dependencies: ${missingInPackageJson.join(', ')}\n` +
167
- ` Fix: Add these to package.json dependencies`
168
- );
169
- }
170
-
171
- projectResults.push({
172
- project: projectName,
173
- valid,
174
- missingInPackageJson,
175
- extraInPackageJson,
176
- });
177
- }
178
-
179
- return {
180
- valid: errors.length === 0,
181
- errors,
182
- projectResults,
183
- };
184
- }