From f4c5e4394ef4aefe792dad3f69c93c5a790c282d Mon Sep 17 00:00:00 2001 From: Luke Rogers <8382642+luke-rogers@users.noreply.github.com> Date: Wed, 6 Dec 2023 14:55:22 +0000 Subject: [PATCH 1/3] fix: expected the module specifier to be a string literal --- .../migrations/standalone/0004-migrate-import-statements.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/cli/src/angular/migrations/standalone/0004-migrate-import-statements.ts b/packages/cli/src/angular/migrations/standalone/0004-migrate-import-statements.ts index f3a9dbe..5e2ec43 100644 --- a/packages/cli/src/angular/migrations/standalone/0004-migrate-import-statements.ts +++ b/packages/cli/src/angular/migrations/standalone/0004-migrate-import-statements.ts @@ -10,6 +10,10 @@ export const migrateImportStatements = async ( ) => { // Get all typescript source files in the project and update any @ionic/angular imports to @ionic/angular/standalone for (const sourceFile of project.getSourceFiles()) { + if (sourceFile.getFilePath().endsWith(".html")) { + continue; + } + let hasChanges = false; const importDeclarations = sourceFile.getImportDeclarations(); From 20d63f7e4b49355c53fcc74256945ca187486050 Mon Sep 17 00:00:00 2001 From: Luke Rogers <8382642+luke-rogers@users.noreply.github.com> Date: Mon, 11 Dec 2023 09:11:39 +0000 Subject: [PATCH 2/3] fix: allow only ts files --- .../0004-migrate-import-statements.ts | 60 +++++++++---------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/packages/cli/src/angular/migrations/standalone/0004-migrate-import-statements.ts b/packages/cli/src/angular/migrations/standalone/0004-migrate-import-statements.ts index 5e2ec43..432cefc 100644 --- a/packages/cli/src/angular/migrations/standalone/0004-migrate-import-statements.ts +++ b/packages/cli/src/angular/migrations/standalone/0004-migrate-import-statements.ts @@ -8,42 +8,42 @@ export const migrateImportStatements = async ( project: Project, cliOptions: CliOptions, ) => { - // Get all typescript source files in the project and update any @ionic/angular imports to @ionic/angular/standalone - for (const sourceFile of project.getSourceFiles()) { - if (sourceFile.getFilePath().endsWith(".html")) { - continue; - } + // Get all typescript source files in the project and update any @ionic/angular imports to @ionic/angular/standalone + for (const sourceFile of project.getSourceFiles()) { + if (!sourceFile.getFilePath().endsWith('.ts')) { + continue; + } - let hasChanges = false; + let hasChanges = false; - const importDeclarations = sourceFile.getImportDeclarations(); - importDeclarations.forEach((importDeclaration) => { - const moduleSpecifier = importDeclaration.getModuleSpecifierValue(); - if (moduleSpecifier === "@ionic/angular") { - importDeclaration.setModuleSpecifier("@ionic/angular/standalone"); + const importDeclarations = sourceFile.getImportDeclarations(); + importDeclarations.forEach((importDeclaration) => { + const moduleSpecifier = importDeclaration.getModuleSpecifierValue(); + if (moduleSpecifier === "@ionic/angular") { + importDeclaration.setModuleSpecifier("@ionic/angular/standalone"); - const namedImports = importDeclaration.getNamedImports(); - const importSpecifier = namedImports.find( + const namedImports = importDeclaration.getNamedImports(); + const importSpecifier = namedImports.find( (n) => n.getName() === "IonicModule", ); - if (importSpecifier) { - if (namedImports.length > 1) { - // Remove the IonicModule import specifier. - importSpecifier.remove(); - } else { - // If this is the only import specifier, remove the entire import declaration. - importDeclaration.remove(); - } - removeImportFromNgModuleDecorator(sourceFile, "IonicModule"); + if (importSpecifier) { + if (namedImports.length > 1) { + // Remove the IonicModule import specifier. + importSpecifier.remove(); + } else { + // If this is the only import specifier, remove the entire import declaration. + importDeclaration.remove(); + } + removeImportFromNgModuleDecorator(sourceFile, "IonicModule"); + } + + hasChanges = true; + } + }); + + if (hasChanges) { + await saveFileChanges(sourceFile, cliOptions); } - - hasChanges = true; - } - }); - - if (hasChanges) { - await saveFileChanges(sourceFile, cliOptions); } - } }; From dd0a74dde69aa4ab18d0b600f7eec648710a92e6 Mon Sep 17 00:00:00 2001 From: Luke Rogers <8382642+luke-rogers@users.noreply.github.com> Date: Mon, 11 Dec 2023 09:12:29 +0000 Subject: [PATCH 3/3] fix: formatting... --- .../0004-migrate-import-statements.ts | 60 +++++++++---------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/packages/cli/src/angular/migrations/standalone/0004-migrate-import-statements.ts b/packages/cli/src/angular/migrations/standalone/0004-migrate-import-statements.ts index 432cefc..f63dd46 100644 --- a/packages/cli/src/angular/migrations/standalone/0004-migrate-import-statements.ts +++ b/packages/cli/src/angular/migrations/standalone/0004-migrate-import-statements.ts @@ -8,42 +8,42 @@ export const migrateImportStatements = async ( project: Project, cliOptions: CliOptions, ) => { - // Get all typescript source files in the project and update any @ionic/angular imports to @ionic/angular/standalone - for (const sourceFile of project.getSourceFiles()) { - if (!sourceFile.getFilePath().endsWith('.ts')) { - continue; - } + // Get all typescript source files in the project and update any @ionic/angular imports to @ionic/angular/standalone + for (const sourceFile of project.getSourceFiles()) { + if (!sourceFile.getFilePath().endsWith(".ts")) { + continue; + } - let hasChanges = false; + let hasChanges = false; - const importDeclarations = sourceFile.getImportDeclarations(); - importDeclarations.forEach((importDeclaration) => { - const moduleSpecifier = importDeclaration.getModuleSpecifierValue(); - if (moduleSpecifier === "@ionic/angular") { - importDeclaration.setModuleSpecifier("@ionic/angular/standalone"); + const importDeclarations = sourceFile.getImportDeclarations(); + importDeclarations.forEach((importDeclaration) => { + const moduleSpecifier = importDeclaration.getModuleSpecifierValue(); + if (moduleSpecifier === "@ionic/angular") { + importDeclaration.setModuleSpecifier("@ionic/angular/standalone"); - const namedImports = importDeclaration.getNamedImports(); - const importSpecifier = namedImports.find( + const namedImports = importDeclaration.getNamedImports(); + const importSpecifier = namedImports.find( (n) => n.getName() === "IonicModule", ); - if (importSpecifier) { - if (namedImports.length > 1) { - // Remove the IonicModule import specifier. - importSpecifier.remove(); - } else { - // If this is the only import specifier, remove the entire import declaration. - importDeclaration.remove(); - } - removeImportFromNgModuleDecorator(sourceFile, "IonicModule"); - } - - hasChanges = true; - } - }); - - if (hasChanges) { - await saveFileChanges(sourceFile, cliOptions); + if (importSpecifier) { + if (namedImports.length > 1) { + // Remove the IonicModule import specifier. + importSpecifier.remove(); + } else { + // If this is the only import specifier, remove the entire import declaration. + importDeclaration.remove(); + } + removeImportFromNgModuleDecorator(sourceFile, "IonicModule"); } + + hasChanges = true; + } + }); + + if (hasChanges) { + await saveFileChanges(sourceFile, cliOptions); } + } };