@onecx/nx-migration-utils 5.46.0 → 5.47.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 (31) hide show
  1. package/package.json +1 -1
  2. package/src/index.d.ts +2 -0
  3. package/src/index.js +2 -0
  4. package/src/index.js.map +1 -1
  5. package/src/lib/angular/model/provider.model.d.ts +4 -0
  6. package/src/lib/angular/model/provider.model.js +3 -0
  7. package/src/lib/angular/model/provider.model.js.map +1 -0
  8. package/src/lib/utils/add-new-import.utils.d.ts +8 -0
  9. package/src/lib/utils/add-new-import.utils.js +14 -0
  10. package/src/lib/utils/add-new-import.utils.js.map +1 -0
  11. package/src/lib/utils/add-provider-import-in-file.utils.d.ts +8 -0
  12. package/src/lib/utils/add-provider-import-in-file.utils.js +25 -0
  13. package/src/lib/utils/add-provider-import-in-file.utils.js.map +1 -0
  14. package/src/lib/utils/add-to-first-import.utils.d.ts +8 -0
  15. package/src/lib/utils/add-to-first-import.utils.js +21 -0
  16. package/src/lib/utils/add-to-first-import.utils.js.map +1 -0
  17. package/src/lib/utils/is-import-in-content.utils.d.ts +7 -0
  18. package/src/lib/utils/is-import-in-content.utils.js +16 -0
  19. package/src/lib/utils/is-import-in-content.utils.js.map +1 -0
  20. package/src/lib/utils/is-namespace-import-in-content.utils.d.ts +7 -0
  21. package/src/lib/utils/is-namespace-import-in-content.utils.js +17 -0
  22. package/src/lib/utils/is-namespace-import-in-content.utils.js.map +1 -0
  23. package/src/lib/utils/patterns.utils.d.ts +31 -0
  24. package/src/lib/utils/patterns.utils.js +51 -0
  25. package/src/lib/utils/patterns.utils.js.map +1 -0
  26. package/src/lib/utils/remove-import-specifier.utils.d.ts +9 -0
  27. package/src/lib/utils/remove-import-specifier.utils.js +33 -0
  28. package/src/lib/utils/remove-import-specifier.utils.js.map +1 -0
  29. package/src/test-setup.d.ts +1 -0
  30. package/src/test-setup.js +6 -0
  31. package/src/test-setup.js.map +1 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onecx/nx-migration-utils",
3
- "version": "5.46.0",
3
+ "version": "5.47.0",
4
4
  "license": "Apache-2.0",
5
5
  "peerDependencies": {
6
6
  "tslib": "^2.3.0",
package/src/index.d.ts CHANGED
@@ -1,2 +1,4 @@
1
1
  export * from './lib/utils/detect-method-calls-in-files';
2
2
  export * from './lib/utils/print-warnings';
3
+ export * from './lib/utils/remove-import-specifier.utils';
4
+ export * from './lib/utils/add-provider-import-in-file.utils';
package/src/index.js CHANGED
@@ -4,4 +4,6 @@ const tslib_1 = require("tslib");
4
4
  // General purpose and framework-agnostic utilities for NX migrations
5
5
  tslib_1.__exportStar(require("./lib/utils/detect-method-calls-in-files"), exports);
6
6
  tslib_1.__exportStar(require("./lib/utils/print-warnings"), exports);
7
+ tslib_1.__exportStar(require("./lib/utils/remove-import-specifier.utils"), exports);
8
+ tslib_1.__exportStar(require("./lib/utils/add-provider-import-in-file.utils"), exports);
7
9
  //# sourceMappingURL=index.js.map
package/src/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../libs/nx-migration-utils/src/index.ts"],"names":[],"mappings":";;;AAAA,qEAAqE;AACrE,mFAAwD;AACxD,qEAA0C"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../libs/nx-migration-utils/src/index.ts"],"names":[],"mappings":";;;AAAA,qEAAqE;AACrE,mFAAwD;AACxD,qEAA0C;AAC1C,oFAAyD;AACzD,wFAA6D"}
@@ -0,0 +1,4 @@
1
+ export interface Provider {
2
+ name: string;
3
+ importPath: string;
4
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=provider.model.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider.model.js","sourceRoot":"","sources":["../../../../../../../libs/nx-migration-utils/src/lib/angular/model/provider.model.ts"],"names":[],"mappings":""}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Creates new import statement with given import specifiers.
3
+ * @param fileContent - the content of the file to modify
4
+ * @param importPath - import path to create
5
+ * @param importSpecifiers - import specifiers to add, e.g. "myFunctionName"
6
+ * @returns {string} new file content after modification
7
+ */
8
+ export declare function addNewImport(fileContent: string, importPath: string, importSpecifiers: string[]): string;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.addNewImport = addNewImport;
4
+ /**
5
+ * Creates new import statement with given import specifiers.
6
+ * @param fileContent - the content of the file to modify
7
+ * @param importPath - import path to create
8
+ * @param importSpecifiers - import specifiers to add, e.g. "myFunctionName"
9
+ * @returns {string} new file content after modification
10
+ */
11
+ function addNewImport(fileContent, importPath, importSpecifiers) {
12
+ return `import {${importSpecifiers.join(',')}} from '${importPath}'\n${fileContent}`;
13
+ }
14
+ //# sourceMappingURL=add-new-import.utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"add-new-import.utils.js","sourceRoot":"","sources":["../../../../../../libs/nx-migration-utils/src/lib/utils/add-new-import.utils.ts"],"names":[],"mappings":";;AAOA,oCAEC;AATD;;;;;;GAMG;AACH,SAAgB,YAAY,CAAC,WAAmB,EAAE,UAAkB,EAAE,gBAA0B;IAC9F,OAAO,WAAW,gBAAgB,CAAC,IAAI,CAAC,GAAG,CAAC,WAAW,UAAU,MAAM,WAAW,EAAE,CAAA;AACtF,CAAC"}
@@ -0,0 +1,8 @@
1
+ import { Provider } from './../angular/model/provider.model';
2
+ /**
3
+ * Add the import for Angular provider in the file.
4
+ * @param fileContent - the path to a file to modify
5
+ * @param provider - angular provider to add
6
+ * @returns {string} modified content of the file with provider imported
7
+ */
8
+ export declare function addProviderImportInFile(fileContent: string, provider: Provider): string;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.addProviderImportInFile = addProviderImportInFile;
4
+ const add_new_import_utils_1 = require("./add-new-import.utils");
5
+ const add_to_first_import_utils_1 = require("./add-to-first-import.utils");
6
+ const is_import_in_content_utils_1 = require("./is-import-in-content.utils");
7
+ const is_namespace_import_in_content_utils_1 = require("./is-namespace-import-in-content.utils");
8
+ /**
9
+ * Add the import for Angular provider in the file.
10
+ * @param fileContent - the path to a file to modify
11
+ * @param provider - angular provider to add
12
+ * @returns {string} modified content of the file with provider imported
13
+ */
14
+ function addProviderImportInFile(fileContent, provider) {
15
+ if ((0, is_namespace_import_in_content_utils_1.isNamespaceImportInContent)(fileContent, provider.importPath)) {
16
+ return fileContent;
17
+ }
18
+ else if ((0, is_import_in_content_utils_1.isImportInContent)(fileContent, provider.importPath)) {
19
+ return (0, add_to_first_import_utils_1.addToFirstImport)(fileContent, provider.importPath, provider.name);
20
+ }
21
+ else {
22
+ return (0, add_new_import_utils_1.addNewImport)(fileContent, provider.importPath, [provider.name]);
23
+ }
24
+ }
25
+ //# sourceMappingURL=add-provider-import-in-file.utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"add-provider-import-in-file.utils.js","sourceRoot":"","sources":["../../../../../../libs/nx-migration-utils/src/lib/utils/add-provider-import-in-file.utils.ts"],"names":[],"mappings":";;AAYA,0DAQC;AApBD,iEAAqD;AACrD,2EAA8D;AAC9D,6EAAgE;AAChE,iGAAmF;AAGnF;;;;;GAKG;AACH,SAAgB,uBAAuB,CAAC,WAAmB,EAAE,QAAkB;IAC7E,IAAI,IAAA,iEAA0B,EAAC,WAAW,EAAE,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC;QACjE,OAAO,WAAW,CAAA;IACpB,CAAC;SAAM,IAAI,IAAA,8CAAiB,EAAC,WAAW,EAAE,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC;QAC/D,OAAO,IAAA,4CAAgB,EAAC,WAAW,EAAE,QAAQ,CAAC,UAAU,EAAE,QAAQ,CAAC,IAAI,CAAC,CAAA;IAC1E,CAAC;SAAM,CAAC;QACN,OAAO,IAAA,mCAAY,EAAC,WAAW,EAAE,QAAQ,CAAC,UAAU,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAA;IACxE,CAAC;AACH,CAAC"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Appends new importSpecifier to the named import (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import#named_import).
3
+ * @param fileContent - the content of the file to modify
4
+ * @param importPath - import path to modify
5
+ * @param importSpecifier - import specifier to add, e.g. "myFunctionName"
6
+ * @returns {string} new file content after modification
7
+ */
8
+ export declare function addToFirstImport(fileContent: string, importPath: string, importSpecifier: string): string;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.addToFirstImport = addToFirstImport;
4
+ const tsquery_1 = require("@phenomnomnominal/tsquery");
5
+ const typescript_1 = require("typescript");
6
+ const patterns_utils_1 = require("./patterns.utils");
7
+ /**
8
+ * Appends new importSpecifier to the named import (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import#named_import).
9
+ * @param fileContent - the content of the file to modify
10
+ * @param importPath - import path to modify
11
+ * @param importSpecifier - import specifier to add, e.g. "myFunctionName"
12
+ * @returns {string} new file content after modification
13
+ */
14
+ function addToFirstImport(fileContent, importPath, importSpecifier) {
15
+ return (0, tsquery_1.replace)(fileContent, `${(0, patterns_utils_1.importPattern)(importPath)} NamedImports`, (node) => {
16
+ const niNode = node;
17
+ const newSpecifiers = Array.from(new Set([...niNode.elements.map((namedImport) => namedImport.getText()), importSpecifier]));
18
+ return `{${newSpecifiers.join(',')}}`;
19
+ }, typescript_1.ScriptKind.TS);
20
+ }
21
+ //# sourceMappingURL=add-to-first-import.utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"add-to-first-import.utils.js","sourceRoot":"","sources":["../../../../../../libs/nx-migration-utils/src/lib/utils/add-to-first-import.utils.ts"],"names":[],"mappings":";;AAWA,4CAaC;AAxBD,uDAAmD;AACnD,2CAAqD;AACrD,qDAAgD;AAEhD;;;;;;GAMG;AACH,SAAgB,gBAAgB,CAAC,WAAmB,EAAE,UAAkB,EAAE,eAAuB;IAC/F,OAAO,IAAA,iBAAO,EACZ,WAAW,EACX,GAAG,IAAA,8BAAa,EAAC,UAAU,CAAC,eAAe,EAC3C,CAAC,IAAI,EAAE,EAAE;QACP,MAAM,MAAM,GAAG,IAAoB,CAAA;QACnC,MAAM,aAAa,GAAa,KAAK,CAAC,IAAI,CACxC,IAAI,GAAG,CAAC,CAAC,GAAG,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,WAAW,CAAC,OAAO,EAAE,CAAC,EAAE,eAAe,CAAC,CAAC,CAC3F,CAAA;QACD,OAAO,IAAI,aAAa,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAA;IACvC,CAAC,EACD,uBAAU,CAAC,EAAE,CACd,CAAA;AACH,CAAC"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Checks if file contains import.
3
+ * @param fileContent - the content of the file to check
4
+ * @param importPath - import path to look for
5
+ * @returns {boolean} if file contains the import
6
+ */
7
+ export declare function isImportInContent(fileContent: string, importPath: string): boolean;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isImportInContent = isImportInContent;
4
+ const tsquery_1 = require("@phenomnomnominal/tsquery");
5
+ /**
6
+ * Checks if file contains import.
7
+ * @param fileContent - the content of the file to check
8
+ * @param importPath - import path to look for
9
+ * @returns {boolean} if file contains the import
10
+ */
11
+ function isImportInContent(fileContent, importPath) {
12
+ const contentAst = (0, tsquery_1.ast)(fileContent);
13
+ const imports = (0, tsquery_1.query)(contentAst, `ImportDeclaration:has(StringLiteral[value=${importPath}])`);
14
+ return imports.length > 0;
15
+ }
16
+ //# sourceMappingURL=is-import-in-content.utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-import-in-content.utils.js","sourceRoot":"","sources":["../../../../../../libs/nx-migration-utils/src/lib/utils/is-import-in-content.utils.ts"],"names":[],"mappings":";;AAQA,8CAMC;AAdD,uDAAsD;AAEtD;;;;;GAKG;AACH,SAAgB,iBAAiB,CAAC,WAAmB,EAAE,UAAkB;IACvE,MAAM,UAAU,GAAG,IAAA,aAAG,EAAC,WAAW,CAAC,CAAA;IAEnC,MAAM,OAAO,GAAG,IAAA,eAAK,EAAoB,UAAU,EAAE,6CAA6C,UAAU,IAAI,CAAC,CAAA;IAEjH,OAAO,OAAO,CAAC,MAAM,GAAG,CAAC,CAAA;AAC3B,CAAC"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Checks if file contains namespace import (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import#namespace_import).
3
+ * @param fileContent - the content of the file to check
4
+ * @param importPath - import path to look for
5
+ * @returns {boolean} if file contains the namespace import
6
+ */
7
+ export declare function isNamespaceImportInContent(fileContent: string, importPath: string): boolean;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isNamespaceImportInContent = isNamespaceImportInContent;
4
+ const tsquery_1 = require("@phenomnomnominal/tsquery");
5
+ const patterns_utils_1 = require("./patterns.utils");
6
+ /**
7
+ * Checks if file contains namespace import (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import#namespace_import).
8
+ * @param fileContent - the content of the file to check
9
+ * @param importPath - import path to look for
10
+ * @returns {boolean} if file contains the namespace import
11
+ */
12
+ function isNamespaceImportInContent(fileContent, importPath) {
13
+ const contentAst = (0, tsquery_1.ast)(fileContent);
14
+ const namespaceImports = (0, tsquery_1.query)(contentAst, (0, patterns_utils_1.importNamespacePattern)(importPath));
15
+ return namespaceImports.length > 0;
16
+ }
17
+ //# sourceMappingURL=is-namespace-import-in-content.utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-namespace-import-in-content.utils.js","sourceRoot":"","sources":["../../../../../../libs/nx-migration-utils/src/lib/utils/is-namespace-import-in-content.utils.ts"],"names":[],"mappings":";;AAUA,gEAMC;AAhBD,uDAAsD;AACtD,qDAAyD;AAGzD;;;;;GAKG;AACH,SAAgB,0BAA0B,CAAC,WAAmB,EAAE,UAAkB;IAChF,MAAM,UAAU,GAAG,IAAA,aAAG,EAAC,WAAW,CAAC,CAAA;IAEnC,MAAM,gBAAgB,GAAG,IAAA,eAAK,EAAoB,UAAU,EAAE,IAAA,uCAAsB,EAAC,UAAU,CAAC,CAAC,CAAA;IAEjG,OAAO,gBAAgB,CAAC,MAAM,GAAG,CAAC,CAAA;AACpC,CAAC"}
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Creates a pattern to look for a variable containing the identifier
3
+ * @param identifierName - identifier to look for
4
+ * @returns {string} ast query pattern
5
+ */
6
+ export declare function variableContainingIdentifierPattern(identifierName: string): string;
7
+ /**
8
+ * Creates a pattern to look for import.
9
+ * @param importPath - import path to look for
10
+ * @returns {string} ast query pattern
11
+ */
12
+ export declare function importPattern(importPath: string): string;
13
+ /**
14
+ * Creates a pattern to look for namespace import (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import#namespace_import).
15
+ * @param importPath - import path to look for
16
+ * @returns {string} ast query pattern
17
+ */
18
+ export declare function importNamespacePattern(importPath: string): string;
19
+ /**
20
+ * Creates a pattern to look for named import (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import#named_import).
21
+ * @param importPath - import path to look for
22
+ * @returns {string} ast query pattern
23
+ */
24
+ export declare function importNamedImportsPattern(importPath: string): string;
25
+ /**
26
+ * Creates a pattern to look for import specifier.
27
+ * @param importPath - import path to look for
28
+ * @param specifier - specifier to look for, e.g., "MyClass"
29
+ * @returns {string} ast query pattern
30
+ */
31
+ export declare function importSpecifierPattern(importPath: string, specifier: string): string;
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ // General patterns
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.variableContainingIdentifierPattern = variableContainingIdentifierPattern;
5
+ exports.importPattern = importPattern;
6
+ exports.importNamespacePattern = importNamespacePattern;
7
+ exports.importNamedImportsPattern = importNamedImportsPattern;
8
+ exports.importSpecifierPattern = importSpecifierPattern;
9
+ /**
10
+ * Creates a pattern to look for a variable containing the identifier
11
+ * @param identifierName - identifier to look for
12
+ * @returns {string} ast query pattern
13
+ */
14
+ function variableContainingIdentifierPattern(identifierName) {
15
+ return `VariableDeclaration:has(Identifier[name=${identifierName}])`;
16
+ }
17
+ // Import patterns
18
+ /**
19
+ * Creates a pattern to look for import.
20
+ * @param importPath - import path to look for
21
+ * @returns {string} ast query pattern
22
+ */
23
+ function importPattern(importPath) {
24
+ return `ImportDeclaration:has(StringLiteral[value=${importPath}])`;
25
+ }
26
+ /**
27
+ * Creates a pattern to look for namespace import (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import#namespace_import).
28
+ * @param importPath - import path to look for
29
+ * @returns {string} ast query pattern
30
+ */
31
+ function importNamespacePattern(importPath) {
32
+ return `ImportDeclaration:has(StringLiteral[value=${importPath}]):has(NamespaceImport)`;
33
+ }
34
+ /**
35
+ * Creates a pattern to look for named import (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import#named_import).
36
+ * @param importPath - import path to look for
37
+ * @returns {string} ast query pattern
38
+ */
39
+ function importNamedImportsPattern(importPath) {
40
+ return `${importPattern(importPath)} NamedImports`;
41
+ }
42
+ /**
43
+ * Creates a pattern to look for import specifier.
44
+ * @param importPath - import path to look for
45
+ * @param specifier - specifier to look for, e.g., "MyClass"
46
+ * @returns {string} ast query pattern
47
+ */
48
+ function importSpecifierPattern(importPath, specifier) {
49
+ return `ImportDeclaration:has(StringLiteral[value=${importPath}]):has(ImportSpecifier:has(Identifier[name=${specifier}]))`;
50
+ }
51
+ //# sourceMappingURL=patterns.utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"patterns.utils.js","sourceRoot":"","sources":["../../../../../../libs/nx-migration-utils/src/lib/utils/patterns.utils.ts"],"names":[],"mappings":";AAAA,mBAAmB;;AAOnB,kFAEC;AASD,sCAEC;AAOD,wDAEC;AAOD,8DAEC;AAQD,wDAEC;AA9CD;;;;GAIG;AACH,SAAgB,mCAAmC,CAAC,cAAsB;IACxE,OAAO,2CAA2C,cAAc,IAAI,CAAA;AACtE,CAAC;AAED,kBAAkB;AAElB;;;;GAIG;AACH,SAAgB,aAAa,CAAC,UAAkB;IAC9C,OAAO,6CAA6C,UAAU,IAAI,CAAA;AACpE,CAAC;AAED;;;;GAIG;AACH,SAAgB,sBAAsB,CAAC,UAAkB;IACvD,OAAO,6CAA6C,UAAU,yBAAyB,CAAA;AACzF,CAAC;AAED;;;;GAIG;AACH,SAAgB,yBAAyB,CAAC,UAAkB;IAC1D,OAAO,GAAG,aAAa,CAAC,UAAU,CAAC,eAAe,CAAA;AACpD,CAAC;AAED;;;;;GAKG;AACH,SAAgB,sBAAsB,CAAC,UAAkB,EAAE,SAAiB;IAC1E,OAAO,6CAA6C,UAAU,8CAA8C,SAAS,KAAK,CAAA;AAC5H,CAAC"}
@@ -0,0 +1,9 @@
1
+ import { Tree } from "@nx/devkit";
2
+ /**
3
+ * Removes a named import from a specific file and module, and deletes the import statement if it becomes empty (AST-based).
4
+ * @param tree - The Nx virtual file system tree.
5
+ * @param filePath - Path to the TypeScript file to update.
6
+ * @param importPath - The module from which to remove the import.
7
+ * @param specifier - The named import to remove.
8
+ */
9
+ export declare function removeImportSpecifierFromImport(tree: Tree, filePath: string, importPath: string, specifier: string): void;
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.removeImportSpecifierFromImport = removeImportSpecifierFromImport;
4
+ const tsquery_1 = require("@phenomnomnominal/tsquery");
5
+ const typescript_1 = require("typescript");
6
+ /**
7
+ * Removes a named import from a specific file and module, and deletes the import statement if it becomes empty (AST-based).
8
+ * @param tree - The Nx virtual file system tree.
9
+ * @param filePath - Path to the TypeScript file to update.
10
+ * @param importPath - The module from which to remove the import.
11
+ * @param specifier - The named import to remove.
12
+ */
13
+ function removeImportSpecifierFromImport(tree, filePath, importPath, specifier) {
14
+ const fileContent = tree.read(filePath, 'utf-8');
15
+ if (!fileContent)
16
+ return;
17
+ // Remove only the ImportSpecifier for the given specifier from the given importPath
18
+ let updated = (0, tsquery_1.replace)(fileContent, `ImportDeclaration:has(StringLiteral[value="${importPath}"]) ImportSpecifier:has(Identifier[name="${specifier}"])`, () => '', tsquery_1.ScriptKind.TS);
19
+ // AST: Remove the entire import if it is now empty
20
+ const astSource = (0, tsquery_1.ast)(updated);
21
+ const importDecls = (0, tsquery_1.query)(astSource, `ImportDeclaration:has(StringLiteral[value="${importPath}"])`);
22
+ for (const decl of importDecls) {
23
+ const importDecl = decl;
24
+ const namedBindings = importDecl.importClause?.namedBindings;
25
+ if (namedBindings && (0, typescript_1.isNamedImports)(namedBindings) && namedBindings.elements.length === 0) {
26
+ updated = (0, tsquery_1.replace)(updated, `ImportDeclaration:has(StringLiteral[value="${importPath}"])`, () => '', tsquery_1.ScriptKind.TS);
27
+ }
28
+ }
29
+ if (updated !== fileContent) {
30
+ tree.write(filePath, updated);
31
+ }
32
+ }
33
+ //# sourceMappingURL=remove-import-specifier.utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"remove-import-specifier.utils.js","sourceRoot":"","sources":["../../../../../../libs/nx-migration-utils/src/lib/utils/remove-import-specifier.utils.ts"],"names":[],"mappings":";;AAWA,0EA+BC;AAzCD,uDAA4E;AAC5E,2CAA+D;AAE/D;;;;;;GAMG;AACH,SAAgB,+BAA+B,CAAC,IAAU,EAAE,QAAgB,EAAE,UAAkB,EAAE,SAAiB;IACjH,MAAM,WAAW,GAAG,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IACjD,IAAI,CAAC,WAAW;QAAE,OAAO;IAEzB,oFAAoF;IACpF,IAAI,OAAO,GAAG,IAAA,iBAAO,EACnB,WAAW,EACX,8CAA8C,UAAU,4CAA4C,SAAS,KAAK,EAClH,GAAG,EAAE,CAAC,EAAE,EACR,oBAAU,CAAC,EAAE,CACd,CAAC;IAEF,mDAAmD;IACnD,MAAM,SAAS,GAAG,IAAA,aAAG,EAAC,OAAO,CAAC,CAAC;IAC/B,MAAM,WAAW,GAAG,IAAA,eAAK,EAAC,SAAS,EAAE,8CAA8C,UAAU,KAAK,CAAC,CAAC;IACpG,KAAK,MAAM,IAAI,IAAI,WAAW,EAAE,CAAC;QACjC,MAAM,UAAU,GAAG,IAAyB,CAAC;QAC7C,MAAM,aAAa,GAAG,UAAU,CAAC,YAAY,EAAE,aAAa,CAAC;QAC7D,IAAI,aAAa,IAAI,IAAA,2BAAc,EAAC,aAAa,CAAC,IAAI,aAAa,CAAC,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC1F,OAAO,GAAG,IAAA,iBAAO,EACf,OAAO,EACP,8CAA8C,UAAU,KAAK,EAC7D,GAAG,EAAE,CAAC,EAAE,EACR,oBAAU,CAAC,EAAE,CACd,CAAC;QACJ,CAAC;IACH,CAAC;IAEC,IAAI,OAAO,KAAK,WAAW,EAAE,CAAC;QAC5B,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IAChC,CAAC;AACH,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const globals_1 = require("@jest/globals");
4
+ const matchers = require("jest-extended");
5
+ globals_1.expect.extend(matchers);
6
+ //# sourceMappingURL=test-setup.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"test-setup.js","sourceRoot":"","sources":["../../../../libs/nx-migration-utils/src/test-setup.ts"],"names":[],"mappings":";;AAAA,2CAAsC;AACtC,0CAAyC;AACzC,gBAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAA"}