Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 2x 2x 2x 2x 2x 2x 2x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x | import type { ObjectLiteralExpression, Project, SourceFile } from "ts-morph"; import { SyntaxKind } from "ts-morph"; import type { CliOptions } from "../../../types/cli-options"; import { saveFileChanges } from "../../utils/log-utils"; export const migrateBootstrapApplication = async ( project: Project, cliOptions: CliOptions, ) => { const sourceFile = project .getSourceFiles() .find((sourceFile) => sourceFile.getFilePath().endsWith("src/main.ts")); if (sourceFile === undefined) { return; } const bootstrapApplicationCallExpression = sourceFile .getDescendantsOfKind(SyntaxKind.CallExpression) .find((callExpression) => { const identifier = callExpression.getFirstChildByKind( SyntaxKind.Identifier, ); return ( identifier !== undefined && identifier.getText() === "bootstrapApplication" ); }); if (bootstrapApplicationCallExpression === undefined) { return; } const bootstrapApplicationCallExpressionArguments = bootstrapApplicationCallExpression.getArguments(); if (bootstrapApplicationCallExpressionArguments.length === 0) { return; } const bootstrapApplicationOptionsArgument = bootstrapApplicationCallExpressionArguments[1]; if (bootstrapApplicationOptionsArgument === undefined) { return; } if ( bootstrapApplicationOptionsArgument.isKind( SyntaxKind.ObjectLiteralExpression, ) ) { const objectLiteralExpression = bootstrapApplicationOptionsArgument as ObjectLiteralExpression; const providersPropertyAssignment = objectLiteralExpression.getProperty("providers"); if (providersPropertyAssignment === undefined) { return; } const providersArray = providersPropertyAssignment.getFirstChildByKind( SyntaxKind.ArrayLiteralExpression, ); if (providersArray === undefined) { return; } const importProvidersFromFunctionCall = providersArray.getFirstChildByKind( SyntaxKind.CallExpression, ); if (importProvidersFromFunctionCall === undefined) { return; } const importProvidersFromFunctionCallIdentifier = importProvidersFromFunctionCall.getFirstChildByKind( SyntaxKind.Identifier, ); if (importProvidersFromFunctionCallIdentifier === undefined) { return; } if ( importProvidersFromFunctionCallIdentifier.getText() !== "importProvidersFrom" ) { return; } const importProvidersFromFunctionCallArguments = importProvidersFromFunctionCall.getArguments(); if (importProvidersFromFunctionCallArguments.length === 0) { return; } const importProvidersFromFunctionCallIonicModuleForRootCallExpression = importProvidersFromFunctionCallArguments.find((argument) => { return argument.getText().includes("IonicModule.forRoot"); }); if ( importProvidersFromFunctionCallIonicModuleForRootCallExpression === undefined ) { return; } if ( importProvidersFromFunctionCallIonicModuleForRootCallExpression.isKind( SyntaxKind.CallExpression, ) ) { const importProvidersFromFunctionCallIonicModuleForRootCallExpressionArguments = importProvidersFromFunctionCallIonicModuleForRootCallExpression.getArguments(); const ionicConfigObjectLiteralExpression = importProvidersFromFunctionCallIonicModuleForRootCallExpressionArguments[0]; providersArray.addElement( `provideIonicAngular(${ionicConfigObjectLiteralExpression.getText()})`, ); // Remove the IonicModule.forRoot from the importProvidersFrom function call. importProvidersFromFunctionCall.removeArgument( importProvidersFromFunctionCallIonicModuleForRootCallExpression, ); if (importProvidersFromFunctionCall.getArguments().length === 0) { // If there are no remaining arguments, remove the importProvidersFrom function call. providersArray.removeElement(importProvidersFromFunctionCall); } providersArray.formatText(); migrateIonicAngularImportDeclarations(sourceFile); return await saveFileChanges(sourceFile, cliOptions); } } }; function migrateIonicAngularImportDeclarations(sourceFile: SourceFile) { const importDeclaration = sourceFile.getImportDeclaration("@ionic/angular"); if (!importDeclaration) { // If the @ionic/angular import does not exist, then this is not an @ionic/angular application. // This migration only applies to @ionic/angular applications. return; } // Update the import statement to import from @ionic/angular/standalone importDeclaration.setModuleSpecifier("@ionic/angular/standalone"); const namedImports = importDeclaration.getNamedImports(); const importSpecifier = namedImports.find( (n) => n.getName() === "IonicModule", ); if (importSpecifier) { // Remove the IonicModule import specifier importSpecifier.remove(); } // Add the provideIonicAngular import specifier importDeclaration.addNamedImport("provideIonicAngular"); } |