@onecx/nx-migration-utils 5.35.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.
- package/README.md +15 -0
- package/package.json +18 -0
- package/src/index.d.ts +2 -0
- package/src/index.js +7 -0
- package/src/index.js.map +1 -0
- package/src/lib/angular/index.d.ts +0 -0
- package/src/lib/angular/index.js +3 -0
- package/src/lib/angular/index.js.map +1 -0
- package/src/lib/utils/detect-method-calls-in-files.d.ts +5 -0
- package/src/lib/utils/detect-method-calls-in-files.js +74 -0
- package/src/lib/utils/detect-method-calls-in-files.js.map +1 -0
- package/src/lib/utils/print-warnings.d.ts +1 -0
- package/src/lib/utils/print-warnings.js +14 -0
- package/src/lib/utils/print-warnings.js.map +1 -0
package/README.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# nx-migration-utils
|
|
2
|
+
|
|
3
|
+
This library contains helpers for creating NX migrations.
|
|
4
|
+
|
|
5
|
+
Framework agnostic utility functions are located in the `src/lib/utils` directory and can be imported from `@onecx/nx-migration-utils`.
|
|
6
|
+
|
|
7
|
+
Framework specific utilities are located in subdirectories of `src/lib` (e.g. `src/lib/angular`) and can be imported from `@onecx/nx-migration-utils/<framework>`.
|
|
8
|
+
|
|
9
|
+
## Building
|
|
10
|
+
|
|
11
|
+
Run `nx build nx-migration-utils` to build the library.
|
|
12
|
+
|
|
13
|
+
## Running unit tests
|
|
14
|
+
|
|
15
|
+
Run `nx test nx-migration-utils` to execute the unit tests via [Jest](https://jestjs.io).
|
package/package.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@onecx/nx-migration-utils",
|
|
3
|
+
"version": "5.35.0",
|
|
4
|
+
"license": "Apache-2.0",
|
|
5
|
+
"peerDependencies": {
|
|
6
|
+
"tslib": "^2.3.0",
|
|
7
|
+
"@phenomnomnominal/tsquery": "^6",
|
|
8
|
+
"@nx/devkit": "^19.8.0",
|
|
9
|
+
"typescript": "^5.5.4"
|
|
10
|
+
},
|
|
11
|
+
"type": "commonjs",
|
|
12
|
+
"main": "./src/index.js",
|
|
13
|
+
"typings": "./src/index.d.ts",
|
|
14
|
+
"publishConfig": {
|
|
15
|
+
"access": "public"
|
|
16
|
+
},
|
|
17
|
+
"types": "./src/index.d.ts"
|
|
18
|
+
}
|
package/src/index.d.ts
ADDED
package/src/index.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
// General purpose and framework-agnostic utilities for NX migrations
|
|
5
|
+
tslib_1.__exportStar(require("./lib/utils/detect-method-calls-in-files"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./lib/utils/print-warnings"), exports);
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
package/src/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../libs/nx-migration-utils/src/index.ts"],"names":[],"mappings":";;;AAAA,qEAAqE;AACrE,mFAAwD;AACxD,qEAA0C"}
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../libs/nx-migration-utils/src/lib/angular/index.ts"],"names":[],"mappings":";AAAA,0CAA0C"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Tree } from '@nx/devkit';
|
|
2
|
+
import { CallExpression } from 'typescript';
|
|
3
|
+
type MatchingMethodCalls = Map<string, CallExpression[]>;
|
|
4
|
+
export declare function detectMethodCallsInFiles(tree: Tree, rootDir: string, methodName: string, className: string): MatchingMethodCalls;
|
|
5
|
+
export {};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.detectMethodCallsInFiles = detectMethodCallsInFiles;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
const tsquery_1 = require("@phenomnomnominal/tsquery");
|
|
6
|
+
const typescript_1 = require("typescript");
|
|
7
|
+
function getDeclarationNames(contentAst, className, type) {
|
|
8
|
+
const declarations = (0, tsquery_1.query)(contentAst, `${type}:has(NewExpression > Identifier[name="${className}"])`);
|
|
9
|
+
const memberNames = declarations.map((node) => {
|
|
10
|
+
if ((type === 'VariableDeclaration' && (0, typescript_1.isVariableDeclaration)(node)) || (type === 'PropertyDeclaration' && (0, typescript_1.isPropertyDeclaration)(node))) {
|
|
11
|
+
return node.name.getText();
|
|
12
|
+
}
|
|
13
|
+
throw new Error(`Node is not a ${type}`);
|
|
14
|
+
});
|
|
15
|
+
return memberNames;
|
|
16
|
+
}
|
|
17
|
+
function getAssignmentNames(contentAst, className) {
|
|
18
|
+
const assignments = (0, tsquery_1.query)(contentAst, `ExpressionStatement:has(BinaryExpression:has(EqualsToken):has(NewExpression > Identifier[name="${className}"]))`);
|
|
19
|
+
const assignmentNames = assignments.map((node) => {
|
|
20
|
+
if ((0, typescript_1.isExpressionStatement)(node)) {
|
|
21
|
+
const binaryExpression = node.expression;
|
|
22
|
+
if ((0, typescript_1.isBinaryExpression)(binaryExpression)) {
|
|
23
|
+
if (binaryExpression.operatorToken.kind == typescript_1.SyntaxKind.EqualsToken) {
|
|
24
|
+
if ((0, typescript_1.isPropertyAccessExpression)(binaryExpression.left)) {
|
|
25
|
+
return binaryExpression.left.name.escapedText.toString();
|
|
26
|
+
}
|
|
27
|
+
else if ((0, typescript_1.isIdentifier)(binaryExpression.left)) {
|
|
28
|
+
return binaryExpression.left.escapedText.toString();
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
throw new Error('Node is not a PropertyAccessExpression or Identifier');
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
throw new Error('Node is not an ExpressionStatement');
|
|
37
|
+
});
|
|
38
|
+
return assignmentNames;
|
|
39
|
+
}
|
|
40
|
+
function getIdentifierCallQueries(contentAst, className, methodName) {
|
|
41
|
+
const variableNames = getDeclarationNames(contentAst, className, 'VariableDeclaration');
|
|
42
|
+
const memberNames = getDeclarationNames(contentAst, className, 'PropertyDeclaration');
|
|
43
|
+
const assignmentNames = getAssignmentNames(contentAst, className);
|
|
44
|
+
const allIdentifiers = [...variableNames, ...memberNames, ...assignmentNames];
|
|
45
|
+
// Only check variables once, even if their value is set multiple times
|
|
46
|
+
const distinctIdentifiers = Array.from(new Set(allIdentifiers));
|
|
47
|
+
const identifierCallPatterns = distinctIdentifiers.map((name) => `CallExpression:has(PropertyAccessExpression > Identifier[name="${name}"]):has(Identifier[name="${methodName}"])`);
|
|
48
|
+
return identifierCallPatterns;
|
|
49
|
+
}
|
|
50
|
+
function detectMethodCallsInFiles(tree, rootDir, methodName, className) {
|
|
51
|
+
const matchingFiles = new Map();
|
|
52
|
+
// Look at each file inside of specified rootDir or any of its subdirectories that isn't gitignored
|
|
53
|
+
(0, devkit_1.visitNotIgnoredFiles)(tree, rootDir, (file) => {
|
|
54
|
+
const content = tree.read(file, 'utf-8');
|
|
55
|
+
if (!content)
|
|
56
|
+
return;
|
|
57
|
+
const contentAst = (0, tsquery_1.ast)(content);
|
|
58
|
+
// Queries for method calls on identifiers (e.g. x.method() or this.x.method())
|
|
59
|
+
const identifierCallPatterns = getIdentifierCallQueries(contentAst, className, methodName);
|
|
60
|
+
// Query for inline method calls (e.g. new ClassName().method())
|
|
61
|
+
const inlineCallPattern = `CallExpression:has(NewExpression > Identifier[name="${className}"]):has(Identifier[name="${methodName}"])`;
|
|
62
|
+
const allPatterns = [...identifierCallPatterns, inlineCallPattern].join(', ');
|
|
63
|
+
// Search for all elements matching computed queries
|
|
64
|
+
let potentialMethodCalls = (0, tsquery_1.query)(contentAst, allPatterns);
|
|
65
|
+
// If no potential method calls are found, file can be ignored
|
|
66
|
+
if (potentialMethodCalls.length === 0)
|
|
67
|
+
return;
|
|
68
|
+
// Ensure that all detected method calls are indeed CallExpressions and filter out any other types
|
|
69
|
+
potentialMethodCalls = potentialMethodCalls.filter((node) => (0, typescript_1.isCallExpression)(node));
|
|
70
|
+
matchingFiles.set(file, potentialMethodCalls);
|
|
71
|
+
});
|
|
72
|
+
return matchingFiles;
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=detect-method-calls-in-files.js.map
|
|
@@ -0,0 +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":";;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,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a,CAAC,GAAG,CAAC,IAAI,EAAE,oBAAoB,CAAC,CAAA;IAC/C,CAAC,CAAC,CAAA;IAEF,OAAO,aAAa,CAAA;AACtB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function printWarnings(warning: string, affectedFiles: string[]): void;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.printWarnings = printWarnings;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
function printWarnings(warning, affectedFiles) {
|
|
6
|
+
if (affectedFiles.length > 0) {
|
|
7
|
+
devkit_1.logger.warn(warning);
|
|
8
|
+
devkit_1.logger.warn(`Found in:`);
|
|
9
|
+
affectedFiles.forEach((file) => {
|
|
10
|
+
devkit_1.logger.warn(` - ${file}`);
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=print-warnings.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"print-warnings.js","sourceRoot":"","sources":["../../../../../../libs/nx-migration-utils/src/lib/utils/print-warnings.ts"],"names":[],"mappings":";;AACA,sCAQC;AATD,uCAAmC;AACnC,SAAgB,aAAa,CAAC,OAAe,EAAE,aAAuB;IAClE,IAAI,aAAa,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC3B,eAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;QACpB,eAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAA;QACxB,aAAa,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;YAC7B,eAAM,CAAC,IAAI,CAAC,OAAO,IAAI,EAAE,CAAC,CAAA;QAC5B,CAAC,CAAC,CAAA;IACJ,CAAC;AACP,CAAC"}
|