@craft-ng/dev-tools 0.1.3 → 0.1.5

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": "@craft-ng/dev-tools",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "description": "Development tools for ng-craft: ESLint configs, ESLint rules, and codemods",
5
5
  "type": "module",
6
6
  "main": "./src/index.js",
@@ -1,7 +1,10 @@
1
1
  const fs = require('node:fs');
2
2
  const path = require('node:path');
3
3
 
4
- process.env.TS_NODE_PROJECT ??= path.resolve(__dirname, '../tsconfig.codemod.json');
4
+ process.env.TS_NODE_PROJECT ??= path.resolve(
5
+ __dirname,
6
+ '../tsconfig.codemod.json',
7
+ );
5
8
  require('ts-node/register/transpile-only');
6
9
 
7
10
  const { Project } = require('ts-morph');
@@ -35,13 +38,24 @@ module.exports = {
35
38
  return;
36
39
  }
37
40
 
38
- const sourceFile = getProjectSourceFile(getProject(getCwd(context)), filePath, text);
41
+ const sourceFile = getProjectSourceFile(
42
+ getProject(getCwd(context)),
43
+ filePath,
44
+ text,
45
+ );
39
46
  const analysis = analyzeSourceFileDependencies(sourceFile);
40
- if (!analysis.classDeclaration || analysis.skipped || !analysis.className) {
47
+ if (
48
+ !analysis.classDeclaration ||
49
+ analysis.skipped ||
50
+ !analysis.className
51
+ ) {
41
52
  return;
42
53
  }
43
54
 
44
- const existing = readExistingDependencyGroups(sourceFile, analysis.className);
55
+ const existing = readExistingDependencyGroups(
56
+ sourceFile,
57
+ analysis.className,
58
+ );
45
59
  if (!existing.found) {
46
60
  return;
47
61
  }
@@ -137,7 +151,14 @@ function getCwd(context) {
137
151
  return context.cwd ?? process.cwd();
138
152
  }
139
153
 
140
- function reportIfMismatch(context, sourceCode, existing, propertyName, expected, actual) {
154
+ function reportIfMismatch(
155
+ context,
156
+ sourceCode,
157
+ existing,
158
+ propertyName,
159
+ expected,
160
+ actual,
161
+ ) {
141
162
  if (isSameDependencyList(expected, actual)) {
142
163
  return;
143
164
  }
@@ -145,7 +166,9 @@ function reportIfMismatch(context, sourceCode, existing, propertyName, expected,
145
166
  reportNode(
146
167
  context,
147
168
  sourceCode,
148
- existing.propertyNodes[propertyName] ?? existing.depsObjectNode ?? existing.exportAssignmentNode,
169
+ existing.propertyNodes[propertyName] ??
170
+ existing.depsObjectNode ??
171
+ existing.exportAssignmentNode,
149
172
  `deps.${propertyName} does not match the Angular symbol. Expected ${formatDependencyList(expected)} but found ${formatDependencyList(actual)}.`,
150
173
  );
151
174
  }
@@ -165,7 +188,10 @@ function getNodeLoc(sourceCode, node) {
165
188
  }
166
189
 
167
190
  function isSameDependencyList(left, right) {
168
- return left.length === right.length && left.every((value, index) => value === right[index]);
191
+ return (
192
+ left.length === right.length &&
193
+ left.every((value, index) => value === right[index])
194
+ );
169
195
  }
170
196
 
171
197
  function formatDependencyList(dependencies) {
@@ -1,7 +1,10 @@
1
1
  const fs = require('node:fs');
2
2
  const path = require('node:path');
3
3
 
4
- process.env.TS_NODE_PROJECT ??= path.resolve(__dirname, '../tsconfig.codemod.json');
4
+ process.env.TS_NODE_PROJECT ??= path.resolve(
5
+ __dirname,
6
+ '../tsconfig.codemod.json',
7
+ );
5
8
  require('ts-node/register/transpile-only');
6
9
 
7
10
  const { Project, Node, SyntaxKind } = require('ts-morph');
@@ -32,7 +35,11 @@ module.exports = {
32
35
  return;
33
36
  }
34
37
 
35
- const sourceFile = getProjectSourceFile(getProject(getCwd(context)), filePath, text);
38
+ const sourceFile = getProjectSourceFile(
39
+ getProject(getCwd(context)),
40
+ filePath,
41
+ text,
42
+ );
36
43
  const angularClasses = sourceFile
37
44
  .getClasses()
38
45
  .map((classDeclaration) => ({
@@ -42,7 +49,12 @@ module.exports = {
42
49
  .filter((entry) => Boolean(entry.angularKind));
43
50
 
44
51
  for (const { classDeclaration, angularKind } of angularClasses) {
45
- reportDirectClassExport(context, sourceCode, classDeclaration, angularKind);
52
+ reportDirectClassExport(
53
+ context,
54
+ sourceCode,
55
+ classDeclaration,
56
+ angularKind,
57
+ );
46
58
  reportIdentifierExportAssignment(
47
59
  context,
48
60
  sourceCode,
@@ -50,7 +62,13 @@ module.exports = {
50
62
  classDeclaration,
51
63
  angularKind,
52
64
  );
53
- reportNamedExports(context, sourceCode, sourceFile, classDeclaration, angularKind);
65
+ reportNamedExports(
66
+ context,
67
+ sourceCode,
68
+ sourceFile,
69
+ classDeclaration,
70
+ angularKind,
71
+ );
54
72
  }
55
73
  },
56
74
  };
@@ -107,7 +125,12 @@ function getCwd(context) {
107
125
  return context.cwd ?? process.cwd();
108
126
  }
109
127
 
110
- function reportDirectClassExport(context, sourceCode, classDeclaration, angularKind) {
128
+ function reportDirectClassExport(
129
+ context,
130
+ sourceCode,
131
+ classDeclaration,
132
+ angularKind,
133
+ ) {
111
134
  const hasDirectExportModifier = classDeclaration
112
135
  .getModifiers()
113
136
  .some(
@@ -159,7 +182,13 @@ function reportIdentifierExportAssignment(
159
182
  }
160
183
  }
161
184
 
162
- function reportNamedExports(context, sourceCode, sourceFile, classDeclaration, angularKind) {
185
+ function reportNamedExports(
186
+ context,
187
+ sourceCode,
188
+ sourceFile,
189
+ classDeclaration,
190
+ angularKind,
191
+ ) {
163
192
  const className = classDeclaration.getName();
164
193
  if (!className) {
165
194
  return;
@@ -8,6 +8,8 @@ export type TransformResult = {
8
8
  className?: string;
9
9
  dependencies: string[];
10
10
  dependencyGroups: DependencyGroups;
11
+ generatedTypeName?: string;
12
+ generatedDependencyGroups: GeneratedDependencyGroups;
11
13
  };
12
14
  export type AngularBrandCodemodOptions = {
13
15
  helperImportPath?: string;
@@ -31,6 +33,19 @@ export type DependencyGroups = {
31
33
  importDeps: string[];
32
34
  providers: string[];
33
35
  };
36
+ export type GeneratedDependencyEntry = {
37
+ key: string;
38
+ typeText: string;
39
+ typeImport?: {
40
+ moduleSpecifier: string;
41
+ name: string;
42
+ };
43
+ };
44
+ export type GeneratedDependencyGroups = {
45
+ deps: GeneratedDependencyEntry[];
46
+ provided: GeneratedDependencyEntry[];
47
+ missingProvider: GeneratedDependencyEntry[];
48
+ };
34
49
  export type DependencyAnalysisResult = Omit<TransformResult, 'changed'> & {
35
50
  classDeclaration?: ClassDeclaration;
36
51
  };
@@ -61,9 +76,9 @@ export declare function extractDecoratorMetadataDeps(classDeclaration: ClassDecl
61
76
  export declare function extractConstructorDeps(classDeclaration: ClassDeclaration): DependencyExtractionResult;
62
77
  export declare function extractInjectCallDeps(classDeclaration: ClassDeclaration): DependencyExtractionResult;
63
78
  export declare function mergeDeps(...dependencyGroups: readonly string[][]): string[];
79
+ export declare function writeGeneratedDepsTypeAlias(sourceFile: SourceFile, className: string, generatedDependencyGroups: GeneratedDependencyGroups): void;
80
+ export declare function migrateLegacyBrandExport(sourceFile: SourceFile, classDeclaration: ClassDeclaration, className: string): void;
64
81
  export declare function ensureHelperImports(sourceFile: SourceFile, helperImportPath: string): void;
65
- export declare function removeConflictingExports(sourceFile: SourceFile, classDeclaration: ClassDeclaration, className: string): void;
66
- export declare function writeDefaultBrandExport(sourceFile: SourceFile, className: string, dependencyGroups: DependencyGroups): void;
67
82
  export declare function readExistingDependencyGroups(sourceFile: SourceFile, className?: string): ExistingDependencyGroupsResult;
68
83
  export declare function formatDependencyGroups(dependencyGroups: DependencyGroups): string;
69
84
  export declare function runAngularBrandCodemod(options?: AngularBrandCodemodOptions & {