@onecx/nx-migration-utils 6.0.0-rc.9 → 6.0.0

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 (127) hide show
  1. package/package.json +4 -2
  2. package/src/index.d.ts +20 -2
  3. package/src/index.js +20 -2
  4. package/src/index.js.map +1 -1
  5. package/src/lib/angular/html-templates.utils.d.ts +48 -0
  6. package/src/lib/angular/html-templates.utils.js +108 -0
  7. package/src/lib/angular/html-templates.utils.js.map +1 -0
  8. package/src/lib/angular/index.d.ts +16 -0
  9. package/src/lib/angular/index.js +20 -0
  10. package/src/lib/angular/index.js.map +1 -1
  11. package/src/lib/angular/model/matching-module.model.d.ts +4 -0
  12. package/src/lib/angular/model/matching-module.model.js +3 -0
  13. package/src/lib/angular/model/matching-module.model.js.map +1 -0
  14. package/src/lib/angular/model/module.model.d.ts +3 -0
  15. package/src/lib/angular/model/module.model.js +3 -0
  16. package/src/lib/angular/model/module.model.js.map +1 -0
  17. package/src/lib/angular/model/provider.model.d.ts +4 -0
  18. package/src/lib/angular/model/provider.model.js +3 -0
  19. package/src/lib/angular/model/provider.model.js.map +1 -0
  20. package/src/lib/angular/parameters.utils.d.ts +11 -0
  21. package/src/lib/angular/parameters.utils.js +49 -0
  22. package/src/lib/angular/parameters.utils.js.map +1 -0
  23. package/src/lib/angular/replacement-in-files.utils.d.ts +17 -0
  24. package/src/lib/angular/replacement-in-files.utils.js +52 -0
  25. package/src/lib/angular/replacement-in-files.utils.js.map +1 -0
  26. package/src/lib/angular/utils/detection/detect-modules-importing-module.utils.d.ts +12 -0
  27. package/src/lib/angular/utils/detection/detect-modules-importing-module.utils.js +40 -0
  28. package/src/lib/angular/utils/detection/detect-modules-importing-module.utils.js.map +1 -0
  29. package/src/lib/angular/utils/detection/detect-variables-with-module.utils.d.ts +10 -0
  30. package/src/lib/angular/utils/detection/detect-variables-with-module.utils.js +15 -0
  31. package/src/lib/angular/utils/detection/detect-variables-with-module.utils.js.map +1 -0
  32. package/src/lib/angular/utils/detection/detect-variables-with-provider.utils.d.ts +10 -0
  33. package/src/lib/angular/utils/detection/detect-variables-with-provider.utils.js +15 -0
  34. package/src/lib/angular/utils/detection/detect-variables-with-provider.utils.js.map +1 -0
  35. package/src/lib/angular/utils/modification/add-provider-import-if-does-not-exist.utils.d.ts +9 -0
  36. package/src/lib/angular/utils/modification/add-provider-import-if-does-not-exist.utils.js +24 -0
  37. package/src/lib/angular/utils/modification/add-provider-import-if-does-not-exist.utils.js.map +1 -0
  38. package/src/lib/angular/utils/modification/add-provider-import-in-file.utils.d.ts +8 -0
  39. package/src/lib/angular/utils/modification/add-provider-import-in-file.utils.js +25 -0
  40. package/src/lib/angular/utils/modification/add-provider-import-in-file.utils.js.map +1 -0
  41. package/src/lib/angular/utils/modification/add-provider-in-module-if-does-not-exist.utils.d.ts +11 -0
  42. package/src/lib/angular/utils/modification/add-provider-in-module-if-does-not-exist.utils.js +25 -0
  43. package/src/lib/angular/utils/modification/add-provider-in-module-if-does-not-exist.utils.js.map +1 -0
  44. package/src/lib/angular/utils/modification/add-provider-in-module.utils.d.ts +10 -0
  45. package/src/lib/angular/utils/modification/add-provider-in-module.utils.js +29 -0
  46. package/src/lib/angular/utils/modification/add-provider-in-module.utils.js.map +1 -0
  47. package/src/lib/angular/utils/patterns.utils.d.ts +26 -0
  48. package/src/lib/angular/utils/patterns.utils.js +42 -0
  49. package/src/lib/angular/utils/patterns.utils.js.map +1 -0
  50. package/src/lib/angular/utils/validation/is-provider-import-in-file.utils.d.ts +8 -0
  51. package/src/lib/angular/utils/validation/is-provider-import-in-file.utils.js +19 -0
  52. package/src/lib/angular/utils/validation/is-provider-import-in-file.utils.js.map +1 -0
  53. package/src/lib/angular/utils/validation/is-provider-in-module.utils.d.ts +11 -0
  54. package/src/lib/angular/utils/validation/is-provider-in-module.utils.js +22 -0
  55. package/src/lib/angular/utils/validation/is-provider-in-module.utils.js.map +1 -0
  56. package/src/lib/common-migrations/common-migrate-onecx-to-v6.utils.d.ts +2 -0
  57. package/src/lib/common-migrations/common-migrate-onecx-to-v6.utils.js +278 -0
  58. package/src/lib/common-migrations/common-migrate-onecx-to-v6.utils.js.map +1 -0
  59. package/src/lib/utils/detect-method-calls-in-files.d.ts +0 -8
  60. package/src/lib/utils/detect-method-calls-in-files.js +0 -28
  61. package/src/lib/utils/detect-method-calls-in-files.js.map +1 -1
  62. package/src/lib/utils/detect-method-calls-in-files.utils.d.ts +20 -0
  63. package/src/lib/utils/detect-method-calls-in-files.utils.js +138 -0
  64. package/src/lib/utils/detect-method-calls-in-files.utils.js.map +1 -0
  65. package/src/lib/utils/detection/detect-variables-with-identifier.utils.d.ts +9 -0
  66. package/src/lib/utils/detection/detect-variables-with-identifier.utils.js +27 -0
  67. package/src/lib/utils/detection/detect-variables-with-identifier.utils.js.map +1 -0
  68. package/src/lib/utils/import-statements.utils.d.ts +137 -0
  69. package/src/lib/utils/import-statements.utils.js +319 -0
  70. package/src/lib/utils/import-statements.utils.js.map +1 -0
  71. package/src/lib/utils/modification/add-new-import.utils.d.ts +8 -0
  72. package/src/lib/utils/modification/add-new-import.utils.js +14 -0
  73. package/src/lib/utils/modification/add-new-import.utils.js.map +1 -0
  74. package/src/lib/utils/modification/add-to-first-import.utils.d.ts +8 -0
  75. package/src/lib/utils/modification/add-to-first-import.utils.js +21 -0
  76. package/src/lib/utils/modification/add-to-first-import.utils.js.map +1 -0
  77. package/src/lib/utils/modification/remove-import-specifier.utils.d.ts +9 -0
  78. package/src/lib/utils/modification/remove-import-specifier.utils.js +33 -0
  79. package/src/lib/utils/modification/remove-import-specifier.utils.js.map +1 -0
  80. package/src/lib/utils/modification/remove-json-references.utils.d.ts +11 -0
  81. package/src/lib/utils/modification/remove-json-references.utils.js +34 -0
  82. package/src/lib/utils/modification/remove-json-references.utils.js.map +1 -0
  83. package/src/lib/utils/modification/replace-tag-in-html.utils.d.ts +9 -0
  84. package/src/lib/utils/modification/replace-tag-in-html.utils.js +29 -0
  85. package/src/lib/utils/modification/replace-tag-in-html.utils.js.map +1 -0
  86. package/src/lib/utils/modification/update-json-files.utils.d.ts +18 -0
  87. package/src/lib/utils/modification/update-json-files.utils.js +28 -0
  88. package/src/lib/utils/modification/update-json-files.utils.js.map +1 -0
  89. package/src/lib/utils/modification/update-style-sheet.utils.d.ts +11 -0
  90. package/src/lib/utils/modification/update-style-sheet.utils.js +23 -0
  91. package/src/lib/utils/modification/update-style-sheet.utils.js.map +1 -0
  92. package/src/lib/utils/modification/update-style-sheets.utils.d.ts +20 -0
  93. package/src/lib/utils/modification/update-style-sheets.utils.js +31 -0
  94. package/src/lib/utils/modification/update-style-sheets.utils.js.map +1 -0
  95. package/src/lib/utils/patterns.utils.d.ts +31 -0
  96. package/src/lib/utils/patterns.utils.js +51 -0
  97. package/src/lib/utils/patterns.utils.js.map +1 -0
  98. package/src/lib/utils/print-warnings.d.ts +0 -5
  99. package/src/lib/utils/print-warnings.js +0 -5
  100. package/src/lib/utils/print-warnings.js.map +1 -1
  101. package/src/lib/utils/print-warnings.utils.d.ts +6 -0
  102. package/src/lib/utils/print-warnings.utils.js +15 -0
  103. package/src/lib/utils/print-warnings.utils.js.map +1 -0
  104. package/src/lib/utils/typescript-files.utils.d.ts +20 -0
  105. package/src/lib/utils/typescript-files.utils.js +57 -0
  106. package/src/lib/utils/typescript-files.utils.js.map +1 -0
  107. package/src/lib/utils/update-gitignore.utils.d.ts +9 -0
  108. package/src/lib/utils/update-gitignore.utils.js +42 -0
  109. package/src/lib/utils/update-gitignore.utils.js.map +1 -0
  110. package/src/lib/utils/validation/has-html-tag.utils.d.ts +10 -0
  111. package/src/lib/utils/validation/has-html-tag.utils.js +29 -0
  112. package/src/lib/utils/validation/has-html-tag.utils.js.map +1 -0
  113. package/src/lib/utils/validation/is-file-style-sheet.utils.d.ts +8 -0
  114. package/src/lib/utils/validation/is-file-style-sheet.utils.js +14 -0
  115. package/src/lib/utils/validation/is-file-style-sheet.utils.js.map +1 -0
  116. package/src/lib/utils/validation/is-import-in-content.utils.d.ts +7 -0
  117. package/src/lib/utils/validation/is-import-in-content.utils.js +17 -0
  118. package/src/lib/utils/validation/is-import-in-content.utils.js.map +1 -0
  119. package/src/lib/utils/validation/is-import-in-file-content.utils.d.ts +8 -0
  120. package/src/lib/utils/validation/is-import-in-file-content.utils.js +18 -0
  121. package/src/lib/utils/validation/is-import-in-file-content.utils.js.map +1 -0
  122. package/src/lib/utils/validation/is-namespace-import-in-content.utils.d.ts +7 -0
  123. package/src/lib/utils/validation/is-namespace-import-in-content.utils.js +17 -0
  124. package/src/lib/utils/validation/is-namespace-import-in-content.utils.js.map +1 -0
  125. package/src/test-setup.d.ts +1 -0
  126. package/src/test-setup.js +6 -0
  127. package/src/test-setup.js.map +1 -0
@@ -1,13 +1,5 @@
1
1
  import { Tree } from '@nx/devkit';
2
2
  import { CallExpression } from 'typescript';
3
3
  type MatchingMethodCalls = Map<string, CallExpression[]>;
4
- /**
5
- * Detects method calls with a given name on a specified class in files within a specified directory or its subdirectories.
6
- * @param tree The file tree to search in.
7
- * @param rootDir The directory to start searching from.
8
- * @param methodName The name of the method to search for (e.g. 'myMethod').
9
- * @param className The name of the class to search for (e.g. 'MyClass').
10
- * @returns A map where the keys are file paths and the values are arrays of CallExpression nodes representing the detected method calls in the respective files.
11
- */
12
4
  export declare function detectMethodCallsInFiles(tree: Tree, rootDir: string, methodName: string, className: string): MatchingMethodCalls;
13
5
  export {};
@@ -4,13 +4,6 @@ exports.detectMethodCallsInFiles = detectMethodCallsInFiles;
4
4
  const devkit_1 = require("@nx/devkit");
5
5
  const tsquery_1 = require("@phenomnomnominal/tsquery");
6
6
  const typescript_1 = require("typescript");
7
- /**
8
- * Retrieves the names of all declarations that are of the specified type and contain a NewExpression (e.g., 'new MyClass()') with the specified class name.
9
- * @param contentAst The abstract syntax tree of the file to search in.
10
- * @param className The name of the class to search for (e.g. 'MyClass').
11
- * @param type The type of declaration to search for ('PropertyDeclaration' or 'VariableDeclaration').
12
- * @returns A string array of names of the declarations that match the criteria.
13
- */
14
7
  function getDeclarationNames(contentAst, className, type) {
15
8
  const declarations = (0, tsquery_1.query)(contentAst, `${type}:has(NewExpression > Identifier[name="${className}"])`);
16
9
  const memberNames = declarations.map((node) => {
@@ -21,12 +14,6 @@ function getDeclarationNames(contentAst, className, type) {
21
14
  });
22
15
  return memberNames;
23
16
  }
24
- /**
25
- * Retrieves the names of all properties and variables that are assigned a value from a NewExpression (e.g., 'new MyClass()') with the specified class name.
26
- * @param contentAst The abstract syntax tree of the file to search in.
27
- * @param className The name of the class to search for (e.g. 'MyClass').
28
- * @returns A string array of names of the assignments that match the criteria.
29
- */
30
17
  function getAssignmentNames(contentAst, className) {
31
18
  const assignments = (0, tsquery_1.query)(contentAst, `ExpressionStatement:has(BinaryExpression:has(EqualsToken):has(NewExpression > Identifier[name="${className}"]))`);
32
19
  const assignmentNames = assignments.map((node) => {
@@ -50,13 +37,6 @@ function getAssignmentNames(contentAst, className) {
50
37
  });
51
38
  return assignmentNames;
52
39
  }
53
- /**
54
- * Generates an array of computed queries to find method calls with a given method name on identifiers that are either variables or properties and type of the specified class.
55
- * @param contentAst The abstract syntax tree of the file to search in.
56
- * @param className The name of the class to search for (e.g. 'MyClass').
57
- * @param methodName The name of the method to search for (e.g. 'myMethod').
58
- * @returns A string array of computed queries to find method calls on identifiers.
59
- */
60
40
  function getIdentifierCallQueries(contentAst, className, methodName) {
61
41
  const variableNames = getDeclarationNames(contentAst, className, 'VariableDeclaration');
62
42
  const memberNames = getDeclarationNames(contentAst, className, 'PropertyDeclaration');
@@ -67,14 +47,6 @@ function getIdentifierCallQueries(contentAst, className, methodName) {
67
47
  const identifierCallPatterns = distinctIdentifiers.map((name) => `CallExpression:has(PropertyAccessExpression > Identifier[name="${name}"]):has(Identifier[name="${methodName}"])`);
68
48
  return identifierCallPatterns;
69
49
  }
70
- /**
71
- * Detects method calls with a given name on a specified class in files within a specified directory or its subdirectories.
72
- * @param tree The file tree to search in.
73
- * @param rootDir The directory to start searching from.
74
- * @param methodName The name of the method to search for (e.g. 'myMethod').
75
- * @param className The name of the class to search for (e.g. 'MyClass').
76
- * @returns A map where the keys are file paths and the values are arrays of CallExpression nodes representing the detected method calls in the respective files.
77
- */
78
50
  function detectMethodCallsInFiles(tree, rootDir, methodName, className) {
79
51
  const matchingFiles = new Map();
80
52
  // Look at each file inside of specified rootDir or any of its subdirectories that isn't gitignored
@@ -1 +1 @@
1
- {"version":3,"file":"detect-method-calls-in-files.js","sourceRoot":"","sources":["../../../../../../libs/nx-migration-utils/src/lib/utils/detect-method-calls-in-files.ts"],"names":[],"mappings":";;AAgGA,4DAkCC;AAlID,uCAAuD;AACvD,uDAAsD;AACtD,2CAAwN;AAKxN;;;;;;GAMG;AACH,SAAS,mBAAmB,CAAC,UAAsB,EAAE,SAAiB,EAAE,IAAqB;IAC3F,MAAM,YAAY,GAAG,IAAA,eAAK,EACxB,UAAU,EACV,GAAG,IAAI,yCAAyC,SAAS,KAAK,CAC/D,CAAA;IACD,MAAM,WAAW,GAAG,YAAY,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;QAC5C,IAAI,CAAC,IAAI,KAAK,qBAAqB,IAAI,IAAA,kCAAqB,EAAC,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,KAAK,qBAAqB,IAAI,IAAA,kCAAqB,EAAC,IAAI,CAAC,CAAC,EAAE,CAAC;YACvI,OAAO,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAA;QAC5B,CAAC;QACD,MAAM,IAAI,KAAK,CAAC,iBAAiB,IAAI,EAAE,CAAC,CAAA;IAC1C,CAAC,CAAC,CAAA;IAEF,OAAO,WAAW,CAAA;AACpB,CAAC;AAED;;;;;GAKG;AACH,SAAS,kBAAkB,CAAC,UAAsB,EAAE,SAAiB;IACnE,MAAM,WAAW,GAAG,IAAA,eAAK,EACvB,UAAU,EACV,kGAAkG,SAAS,MAAM,CAClH,CAAA;IACD,MAAM,eAAe,GAAG,WAAW,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AAA,6BAAgB,EAAC,IAAI,CAAC,CAAC,CAAA;QACpF,aAAa,CAAC,GAAG,CAAC,IAAI,EAAE,oBAAoB,CAAC,CAAA;IAC/C,CAAC,CAAC,CAAA;IAEF,OAAO,aAAa,CAAA;AACtB,CAAC"}
1
+ {"version":3,"file":"detect-method-calls-in-files.js","sourceRoot":"","sources":["../../../../../../libs/nx-migration-utils/src/lib/utils/detect-method-calls-in-files.ts"],"names":[],"mappings":";;AAoEA,4DAkCC;AAtGD,uCAAuD;AACvD,uDAAsD;AACtD,2CAAwN;AAKxN,SAAS,mBAAmB,CAAC,UAAsB,EAAE,SAAiB,EAAE,IAAqB;IAC3F,MAAM,YAAY,GAAG,IAAA,eAAK,EACxB,UAAU,EACV,GAAG,IAAI,yCAAyC,SAAS,KAAK,CAC/D,CAAA;IACD,MAAM,WAAW,GAAG,YAAY,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;QAC5C,IAAI,CAAC,IAAI,KAAK,qBAAqB,IAAI,IAAA,kCAAqB,EAAC,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,KAAK,qBAAqB,IAAI,IAAA,kCAAqB,EAAC,IAAI,CAAC,CAAC,EAAE,CAAC;YACvI,OAAO,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAA;QAC5B,CAAC;QACD,MAAM,IAAI,KAAK,CAAC,iBAAiB,IAAI,EAAE,CAAC,CAAA;IAC1C,CAAC,CAAC,CAAA;IAEF,OAAO,WAAW,CAAA;AACpB,CAAC;AAED,SAAS,kBAAkB,CAAC,UAAsB,EAAE,SAAiB;IACnE,MAAM,WAAW,GAAG,IAAA,eAAK,EACvB,UAAU,EACV,kGAAkG,SAAS,MAAM,CAClH,CAAA;IACD,MAAM,eAAe,GAAG,WAAW,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;QAC/C,IAAI,IAAA,kCAAqB,EAAC,IAAI,CAAC,EAAE,CAAC;YAChC,MAAM,gBAAgB,GAAG,IAAI,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}
@@ -0,0 +1,20 @@
1
+ import { Tree } from '@nx/devkit';
2
+ import { CallExpression, SourceFile } from 'typescript';
3
+ type MatchingMethodCalls = Map<string, CallExpression[]>;
4
+ /**
5
+ * Retrieves the names of all parameters that are of type className and constructor-based injections (e.g., myClass: MyClass).
6
+ * @param contentAst The abstract syntax tree of the file to search in.
7
+ * @param className The name of the class to search for (e.g. 'MyClass').
8
+ * @returns A string array of names of the parameters that match the criteria.
9
+ */
10
+ export declare function getParameterNames(contentAst: SourceFile, className: string): string[];
11
+ /**
12
+ * Detects method calls with a given name on a specified class in files within a specified directory or its subdirectories.
13
+ * @param tree The file tree to search in.
14
+ * @param rootDir The directory to start searching from.
15
+ * @param methodName The name of the method to search for (e.g. 'myMethod').
16
+ * @param className The name of the class to search for (e.g. 'MyClass').
17
+ * @returns A map where the keys are file paths and the values are arrays of CallExpression nodes representing the detected method calls in the respective files.
18
+ */
19
+ export declare function detectMethodCallsInFiles(tree: Tree, rootDir: string, methodName: string, className: string): MatchingMethodCalls;
20
+ export {};
@@ -0,0 +1,138 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getParameterNames = getParameterNames;
4
+ exports.detectMethodCallsInFiles = detectMethodCallsInFiles;
5
+ const devkit_1 = require("@nx/devkit");
6
+ const tsquery_1 = require("@phenomnomnominal/tsquery");
7
+ const typescript_1 = require("typescript");
8
+ /**
9
+ * Retrieves the names of all declarations that are of the specified type and contain a NewExpression (e.g., 'new MyClass()') with the specified class name.
10
+ * @param contentAst The abstract syntax tree of the file to search in.
11
+ * @param className The name of the class to search for (e.g. 'MyClass').
12
+ * @param type The type of declaration to search for ('PropertyDeclaration' or 'VariableDeclaration').
13
+ * @returns A string array of names of the declarations that match the criteria.
14
+ */
15
+ function getDeclarationNames(contentAst, className, type) {
16
+ const declarations = (0, tsquery_1.query)(contentAst, `${type}:has(NewExpression > Identifier[name="${className}"])`);
17
+ const memberNames = declarations.map((node) => {
18
+ if ((type === 'VariableDeclaration' && (0, typescript_1.isVariableDeclaration)(node)) ||
19
+ (type === 'PropertyDeclaration' && (0, typescript_1.isPropertyDeclaration)(node))) {
20
+ return node.name.getText();
21
+ }
22
+ throw new Error(`Node is not a ${type}`);
23
+ });
24
+ return memberNames;
25
+ }
26
+ /**
27
+ * Retrieves the names of all properties and variables that are assigned a value from a NewExpression (e.g., 'new MyClass()') with the specified class name.
28
+ * @param contentAst The abstract syntax tree of the file to search in.
29
+ * @param className The name of the class to search for (e.g. 'MyClass').
30
+ * @returns A string array of names of the assignments that match the criteria.
31
+ */
32
+ function getAssignmentNames(contentAst, className) {
33
+ const assignments = (0, tsquery_1.query)(contentAst, `ExpressionStatement:has(BinaryExpression:has(EqualsToken):has(NewExpression > Identifier[name="${className}"]))`);
34
+ const assignmentNames = assignments.map((node) => {
35
+ if ((0, typescript_1.isExpressionStatement)(node)) {
36
+ const binaryExpression = node.expression;
37
+ if ((0, typescript_1.isBinaryExpression)(binaryExpression)) {
38
+ if (binaryExpression.operatorToken.kind == typescript_1.SyntaxKind.EqualsToken) {
39
+ if ((0, typescript_1.isPropertyAccessExpression)(binaryExpression.left)) {
40
+ return binaryExpression.left.name.escapedText.toString();
41
+ }
42
+ else if ((0, typescript_1.isIdentifier)(binaryExpression.left)) {
43
+ return binaryExpression.left.escapedText.toString();
44
+ }
45
+ else {
46
+ throw new Error('Node is not a PropertyAccessExpression or Identifier');
47
+ }
48
+ }
49
+ }
50
+ }
51
+ throw new Error('Node is not an ExpressionStatement');
52
+ });
53
+ return assignmentNames;
54
+ }
55
+ /**
56
+ * Retrieves the names of all parameters that are of type className and constructor-based injections (e.g., myClass: MyClass).
57
+ * @param contentAst The abstract syntax tree of the file to search in.
58
+ * @param className The name of the class to search for (e.g. 'MyClass').
59
+ * @returns A string array of names of the parameters that match the criteria.
60
+ */
61
+ function getParameterNames(contentAst, className) {
62
+ const parameters = (0, tsquery_1.query)(contentAst, `Parameter:has(TypeReference:has(Identifier[name="${className}"]))`);
63
+ const parameterNames = parameters.map((node) => {
64
+ if ((0, typescript_1.isParameter)(node)) {
65
+ return node.name.getText();
66
+ }
67
+ throw new Error('Node is not a Parameter');
68
+ });
69
+ return parameterNames;
70
+ }
71
+ /**
72
+ * Retrieves the names of all injections that are injected via the inject CallExpression (e.g., myService = inject(MyService)).
73
+ * @param contentAst The abstract syntax tree of the file to search in.
74
+ * @param className The name of the class to search for (e.g. 'MyClass').
75
+ * @returns A string array of names of the injections that match the criteria.
76
+ */
77
+ function getInjectionNames(contentAst, className) {
78
+ const injections = (0, tsquery_1.query)(contentAst, `PropertyDeclaration:has(CallExpression:has(Identifier[name="inject"]) > Identifier[name="${className}"]), VariableDeclaration:has(CallExpression:has(Identifier[name="inject"]):has(Identifier[name="${className}"]))`);
79
+ const injectionNames = injections.map((node) => {
80
+ if ((0, typescript_1.isPropertyDeclaration)(node) || (0, typescript_1.isVariableDeclaration)(node)) {
81
+ return node.name.getText();
82
+ }
83
+ throw new Error('Node is not a PropertyDeclaration');
84
+ });
85
+ return injectionNames;
86
+ }
87
+ /**
88
+ * Generates an array of computed queries to find method calls with a given method name on identifiers that are either variables or properties and type of the specified class.
89
+ * @param contentAst The abstract syntax tree of the file to search in.
90
+ * @param className The name of the class to search for (e.g. 'MyClass').
91
+ * @param methodName The name of the method to search for (e.g. 'myMethod').
92
+ * @returns A string array of computed queries to find method calls on identifiers.
93
+ */
94
+ function getIdentifierCallQueries(contentAst, className, methodName) {
95
+ const variableNames = getDeclarationNames(contentAst, className, 'VariableDeclaration');
96
+ const memberNames = getDeclarationNames(contentAst, className, 'PropertyDeclaration');
97
+ const assignmentNames = getAssignmentNames(contentAst, className);
98
+ const parameterNames = getParameterNames(contentAst, className);
99
+ const injectionNames = getInjectionNames(contentAst, className);
100
+ const allIdentifiers = [...variableNames, ...memberNames, ...assignmentNames, ...parameterNames, ...injectionNames];
101
+ // Only check variables once, even if their value is set multiple times
102
+ const distinctIdentifiers = Array.from(new Set(allIdentifiers));
103
+ const identifierCallPatterns = distinctIdentifiers.map((name) => `CallExpression:has(PropertyAccessExpression > Identifier[name="${name}"]):has(Identifier[name="${methodName}"])`);
104
+ return identifierCallPatterns;
105
+ }
106
+ /**
107
+ * Detects method calls with a given name on a specified class in files within a specified directory or its subdirectories.
108
+ * @param tree The file tree to search in.
109
+ * @param rootDir The directory to start searching from.
110
+ * @param methodName The name of the method to search for (e.g. 'myMethod').
111
+ * @param className The name of the class to search for (e.g. 'MyClass').
112
+ * @returns A map where the keys are file paths and the values are arrays of CallExpression nodes representing the detected method calls in the respective files.
113
+ */
114
+ function detectMethodCallsInFiles(tree, rootDir, methodName, className) {
115
+ const matchingFiles = new Map();
116
+ // Look at each file inside of specified rootDir or any of its subdirectories that isn't gitignored
117
+ (0, devkit_1.visitNotIgnoredFiles)(tree, rootDir, (file) => {
118
+ const content = tree.read(file, 'utf-8');
119
+ if (!content)
120
+ return;
121
+ const contentAst = (0, tsquery_1.ast)(content);
122
+ // Queries for method calls on identifiers (e.g. x.method() or this.x.method())
123
+ const identifierCallPatterns = getIdentifierCallQueries(contentAst, className, methodName);
124
+ // Query for inline method calls (e.g. new ClassName().method())
125
+ const inlineCallPattern = `CallExpression:has(NewExpression > Identifier[name="${className}"]):has(Identifier[name="${methodName}"])`;
126
+ const allPatterns = [...identifierCallPatterns, inlineCallPattern].join(', ');
127
+ // Search for all elements matching computed queries
128
+ let potentialMethodCalls = (0, tsquery_1.query)(contentAst, allPatterns);
129
+ // If no potential method calls are found, file can be ignored
130
+ if (potentialMethodCalls.length === 0)
131
+ return;
132
+ // Ensure that all detected method calls are indeed CallExpressions and filter out any other types
133
+ potentialMethodCalls = potentialMethodCalls.filter((node) => (0, typescript_1.isCallExpression)(node));
134
+ matchingFiles.set(file, potentialMethodCalls);
135
+ });
136
+ return matchingFiles;
137
+ }
138
+ //# sourceMappingURL=detect-method-calls-in-files.utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"detect-method-calls-in-files.utils.js","sourceRoot":"","sources":["../../../../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wB,IAAI,GAAG,EAAE,CAAA;IAEpD,mGAAmG;IACnG,IAAA,6BAAoB,EAAC,IAAI,EAAE,OAAO,EAAE,CAAC,IAAI,EAAE,EAAE;QAC3C,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA;QACxC,IAAI,CAAC,OAAO;YAAE,OAAM;QACpB,MAAM,UAAU,GAAG,IAAA,aAAG,EAAC,OAAO,CAAC,CAAA;QAE/B,+EAA+E;QAC/E,MAAM,sBAAsB,GAAG,wBAAwB,CAAC,UAAU,EAAE,SAAS,EAAE,UAAU,CAAC,CAAA;QAE1F,gEAAgE;QAChE,MAAM,iBAAiB,GAAG,uDAAuD,SAAS,4BAA4B,UAAU,KAAK,CAAA;QAErI,MAAM,WAAW,GAAG,CAAC,GAAG,sBAAsB,EAAE,iBAAiB,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QAE7E,oDAAoD;QACpD,IAAI,oBAAoB,GAAqB,IAAA,eAAK,EAAC,UAAU,EAAE,WAAW,CAAC,CAAA;QAE3E,8DAA8D;QAC9D,IAAI,oBAAoB,CAAC,MAAM,KAAK,CAAC;YAAE,OAAM;QAE7C,kGAAkG;QAClG,oBAAoB,GAAG,oBAAoB,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAA,6BAAgB,EAAC,IAAI,CAAC,CAAC,CAAA;QACpF,aAAa,CAAC,GAAG,CAAC,IAAI,EAAE,oBAAoB,CAAC,CAAA;IAC/C,CAAC,CAAC,CAAA;IAEF,OAAO,aAAa,CAAA;AACtB,CAAC"}
@@ -0,0 +1,9 @@
1
+ import { Tree } from '@nx/devkit';
2
+ /**
3
+ * Detects variables that include the identifier.
4
+ * @param tree - the file tree to search in
5
+ * @param rootDir - the directory to start searching from
6
+ * @param identifierName - the name of the identifier to search for (e.g., 'MyClass')
7
+ * @returns {string[]} a list of variable names that include the identifier
8
+ */
9
+ export declare function detectVariablesWithIdentifier(tree: Tree, rootDir: string, identifierName: string): string[];
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.detectVariablesWithIdentifier = detectVariablesWithIdentifier;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const tsquery_1 = require("@phenomnomnominal/tsquery");
6
+ const patterns_utils_1 = require("../patterns.utils");
7
+ /**
8
+ * Detects variables that include the identifier.
9
+ * @param tree - the file tree to search in
10
+ * @param rootDir - the directory to start searching from
11
+ * @param identifierName - the name of the identifier to search for (e.g., 'MyClass')
12
+ * @returns {string[]} a list of variable names that include the identifier
13
+ */
14
+ function detectVariablesWithIdentifier(tree, rootDir, identifierName) {
15
+ const variableNames = new Set();
16
+ (0, devkit_1.visitNotIgnoredFiles)(tree, rootDir, (file) => {
17
+ const content = tree.read(file, 'utf-8');
18
+ if (!content)
19
+ return;
20
+ const contentAst = (0, tsquery_1.ast)(content);
21
+ // Query for import via a variable
22
+ const names = (0, tsquery_1.query)(contentAst, (0, patterns_utils_1.variableContainingIdentifierPattern)(identifierName)).map((node) => node.name.getText());
23
+ names.forEach((name) => variableNames.add(name));
24
+ });
25
+ return Array.from(variableNames);
26
+ }
27
+ //# sourceMappingURL=detect-variables-with-identifier.utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"detect-variables-with-identifier.utils.js","sourceRoot":"","sources":["../../../../../../../libs/nx-migration-utils/src/lib/utils/detection/detect-variables-with-identifier.utils.ts"],"names":[],"mappings":";;AAYA,sEAiBC;AA7BD,uCAAuD;AACvD,uDAAsD;AAEtD,sDAAuE;AAEvE;;;;;;GAMG;AACH,SAAgB,6BAA6B,CAAC,IAAU,EAAE,OAAe,EAAE,cAAsB;IAC/F,MAAM,aAAa,GAAG,IAAI,GAAG,EAAU,CAAA;IACvC,IAAA,6BAAoB,EAAC,IAAI,EAAE,OAAO,EAAE,CAAC,IAAI,EAAE,EAAE;QAC3C,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA;QACxC,IAAI,CAAC,OAAO;YAAE,OAAM;QAEpB,MAAM,UAAU,GAAG,IAAA,aAAG,EAAC,OAAO,CAAC,CAAA;QAE/B,kCAAkC;QAClC,MAAM,KAAK,GAAG,IAAA,eAAK,EAAsB,UAAU,EAAE,IAAA,oDAAmC,EAAC,cAAc,CAAC,CAAC,CAAC,GAAG,CAC3G,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAC9B,CAAA;QAED,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,aAAa,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAA;IAClD,CAAC,CAAC,CAAA;IAEF,OAAO,KAAK,CAAC,IAAI,CAAC,aAAa,CAAC,CAAA;AAClC,CAAC"}
@@ -0,0 +1,137 @@
1
+ import { Tree } from '@nx/devkit';
2
+ import { ImportDeclaration, ImportSpecifier, NamedImports, NodeArray, SourceFile } from 'typescript';
3
+ interface ImportValueReplacement {
4
+ oldValue: string;
5
+ newValue: string;
6
+ }
7
+ interface ModuleImportReplacement {
8
+ oldModuleSpecifier: string;
9
+ newModuleSpecifier: string;
10
+ valueReplacements: ImportValueReplacement[];
11
+ }
12
+ interface ImportUpdateResult {
13
+ updatedImportDeclaration: ImportDeclaration | null;
14
+ remainingImportDeclaration: ImportDeclaration | null;
15
+ }
16
+ interface SplitImportSpecifiersResult {
17
+ matchedSpecifiers: ImportSpecifier[];
18
+ unmatchedSpecifiers: ImportSpecifier[];
19
+ }
20
+ /**
21
+ * Removes all import statements (ESM or CommonJS) for a given module from TypeScript files in a directory.
22
+ * @param tree - The Nx virtual file system tree.
23
+ * @param directoryPath - Path to the directory containing TypeScript files.
24
+ * @param moduleSpecifier - The module name whose import statements should be removed.
25
+ */
26
+ export declare function removeImportsByModuleSpecifier(tree: Tree, directoryPath: string, moduleSpecifier: string): void;
27
+ /**
28
+ * Replaces the module specifier in import statements with a new module name.
29
+ * @param tree - The Nx virtual file system tree.
30
+ * @param directoryPath - Path to the directory containing TypeScript files.
31
+ * @param oldModule - The current module name to be replaced.
32
+ * @param newModule - The new module name to use in import statements.
33
+ */
34
+ export declare function replaceImportModuleSpecifier(tree: Tree, directoryPath: string, oldModule: string, newModule: string): void;
35
+ /**
36
+ * Replaces specific named imports from a module with a new identifier
37
+ * @param tree - The Nx virtual file system tree.
38
+ * @param directoryOrFilePath - Path to a directory or a specific file.
39
+ * @param moduleSpecifier - The module from which imports are being replaced.
40
+ * @param oldImportValues - One or more named imports to replace.
41
+ * @param newImportValue - The new identifier to replace the old named imports with.
42
+ */
43
+ export declare function replaceImportValues(tree: Tree, directoryOrFilePath: string, moduleSpecifier: string, oldImportValues: string | string[], newImportValue: string): void;
44
+ /**
45
+ * Removes specific named imports from a module by replacing them with an empty string.
46
+ * @param tree - The Nx virtual file system tree.
47
+ * @param directoryPath - Path to the directory containing TypeScript files.
48
+ * @param moduleSpecifier - The module from which to remove imports.
49
+ * @param importValuesToRemove - One or more named imports to remove.
50
+ * @param filterQuery - Optional custom string query to filter files before applying changes.
51
+ * This can be used to limit the operation to files containing specific content (e.g., a class name or decorator).
52
+ */
53
+ export declare function removeImportValuesFromModule(tree: Tree, directoryPath: string, moduleSpecifier: string, importValuesToRemove: string | string[], filterQuery?: string): void;
54
+ /**
55
+ * Replaces both import values and module names in TypeScript files.
56
+ * @param tree - The Nx virtual file system tree.
57
+ * @param directoryPath - Directory to search for files.
58
+ * @param importReplacements - List of import module and value replacements.
59
+ * @param filterQuery - Optional query to filter files before applying changes.
60
+ */
61
+ export declare function replaceImportValuesAndModule(tree: Tree, directoryPath: string, importReplacements: ModuleImportReplacement[], filterQuery?: string): void;
62
+ /**
63
+ * Processes a file's AST to apply import replacements.
64
+ * @param fileContent - The content of the file to process.
65
+ * @param replacements - List of module and value replacements.
66
+ * @param filterQuery - Optional custom string query to filter files before applying changes.
67
+ * This can be used to limit the operation to files containing specific content (e.g., a class name or decorator).
68
+ * @returns The updated file content, or null if no changes were made.
69
+ */
70
+ export declare function replaceImportsInFile(fileContent: string, replacements: ModuleImportReplacement[], filterQuery?: string): string | null;
71
+ /**
72
+ * Applies import replacements to a TypeScript AST.
73
+ * @param contentAst - The AST of the source file.
74
+ * @param replacement - The module and value replacement configuration.
75
+ * @returns The updated AST, or null if no changes were made.
76
+ */
77
+ export declare function applyImportReplacement(contentAst: SourceFile, replacement: ModuleImportReplacement): SourceFile | null;
78
+ /**
79
+ * Updates an import declaration by replacing specific named imports and updating the module specifier.
80
+ * Only creates a new import if at least one named import is matched and replaced.
81
+ * Remove import statement if all named imports are removed.
82
+ * @param originalImport - The original import declaration node.
83
+ * @param importValueReplacements - List of named import replacements.
84
+ * @param newModuleName - The new module specifier.
85
+ * @returns The updated import declaration, or the original if no replacements were made.
86
+ */
87
+ export declare function updateImportDeclaration(originalImport: ImportDeclaration, importValueReplacements: ImportValueReplacement[], newModuleName: string): ImportUpdateResult;
88
+ /**
89
+ * Creates an updated import declaration with matched specifiers.
90
+ * When you want to move or rename specific named imports to a new module.
91
+ * @param matchedSpecifiers - The matched import specifiers.
92
+ * @param newModuleName - The new module specifier.
93
+ * @returns The updated import declaration, or null if no specifiers were matched.
94
+ *
95
+ */
96
+ export declare function createUpdatedImport(matchedSpecifiers: ImportSpecifier[], newModuleName: string): ImportDeclaration | null;
97
+ /**
98
+ * Creates a remaining import declaration with unmatched specifiers.
99
+ * If no unmatched specifiers remain, remove the entire import.
100
+ * To preserve the parts of the import that are not being changed.
101
+ * @param unmatchedSpecifiers - The unmatched import specifiers.
102
+ * @param originalCount - The original count of specifiers.
103
+ * @param newModuleName - The new module specifier.
104
+ * @param originalImport - The original import declaration.
105
+ * @returns The remaining import declaration, or null if no specifiers were unmatched.
106
+ *
107
+ */
108
+ export declare function createRemainingImport(unmatchedSpecifiers: ImportSpecifier[], originalCount: number, newModuleName: string, originalImport: ImportDeclaration): ImportDeclaration | null;
109
+ /**
110
+ * Constructs a new import declaration with the given specifiers and module name.
111
+ * @param specifiers - The updated import specifiers.
112
+ * @param moduleName - The new module specifier.
113
+ * @returns A new ImportDeclaration node.
114
+ */
115
+ export declare function buildImportDeclaration(specifiers: ImportSpecifier[], moduleName: string): ImportDeclaration | null;
116
+ /**
117
+ * Splits import specifiers into matched and unmatched based on replacements.
118
+ * Separate import specifiers that need to be replaced from those that don't.
119
+ * @param specifiers - The original import specifiers.
120
+ * @param replacements - List of replacements to apply.
121
+ * @returns An object containing matched and unmatched specifiers.
122
+ */
123
+ export declare function splitSpecifiers(specifiers: NodeArray<ImportSpecifier>, replacements: ImportValueReplacement[]): SplitImportSpecifiersResult;
124
+ /**
125
+ * Extracts named imports from an import declaration.
126
+ * @param importDeclaration - The import declaration node.
127
+ * @returns The NamedImports node, if present.
128
+ */
129
+ export declare function getNamedImports(importDeclaration: ImportDeclaration): NamedImports | undefined;
130
+ /**
131
+ * Finds the first import declaration for a given module name.
132
+ * @param sourceFile - The TypeScript source file AST.
133
+ * @param moduleName - The module name to search for.
134
+ * @returns The matching ImportDeclaration node, if found.
135
+ */
136
+ export declare function findImportDeclaration(sourceFile: SourceFile, moduleName: string): ImportDeclaration | undefined;
137
+ export {};