diff --git a/packages/core/schematics/ng-generate/standalone-migration/index.ts b/packages/core/schematics/ng-generate/standalone-migration/index.ts index 2e58cf706c7..77a2331239f 100644 --- a/packages/core/schematics/ng-generate/standalone-migration/index.ts +++ b/packages/core/schematics/ng-generate/standalone-migration/index.ts @@ -79,15 +79,13 @@ function standaloneMigration(tree: Tree, tsconfigPath: string, basePath: string, let pendingChanges: ChangesByFile; let filesToRemove: Set|null = null; - if (options.mode === MigrationMode.toStandalone) { - pendingChanges = toStandalone(sourceFiles, program, printer); - } else if (options.mode === MigrationMode.pruneModules) { + if (options.mode === MigrationMode.pruneModules) { const result = pruneNgModules(program, host, basePath, rootNames, sourceFiles, printer); pendingChanges = result.pendingChanges; filesToRemove = result.filesToRemove; } else { - throw new SchematicsException( - `Unknown schematic mode ${options.mode}. Cannot run the standalone migration.`); + /** MigrationMode.toStandalone */ + pendingChanges = toStandalone(sourceFiles, program, printer); } for (const [file, changes] of pendingChanges.entries()) { diff --git a/packages/core/schematics/ng-generate/standalone-migration/schema.json b/packages/core/schematics/ng-generate/standalone-migration/schema.json index 512d08b6e8f..94e3bfc98e7 100644 --- a/packages/core/schematics/ng-generate/standalone-migration/schema.json +++ b/packages/core/schematics/ng-generate/standalone-migration/schema.json @@ -7,6 +7,7 @@ "mode": { "description": "Operation that should be performed by the migrator", "type": "string", + "enum": ["convert-to-standalone", "prune-ng-modules"], "default": "convert-to-standalone", "x-prompt": { "message": "Choose the type of migration:", diff --git a/packages/core/schematics/test/standalone_migration_spec.ts b/packages/core/schematics/test/standalone_migration_spec.ts index c5b6987a0ad..24cdba4b141 100644 --- a/packages/core/schematics/test/standalone_migration_spec.ts +++ b/packages/core/schematics/test/standalone_migration_spec.ts @@ -178,21 +178,6 @@ describe('standalone migration', () => { expect(error).toBe('Cannot run standalone migration outside of the current project.'); }); - it('should throw an error if an unknown mode is passed in', async () => { - let error: string|null = null; - - writeFile('dir.ts', 'console.log(123)'); - - try { - await runMigration('does-not-exist', './'); - } catch (e: any) { - error = e.message; - } - - expect(error).toBe( - 'Unknown schematic mode does-not-exist. Cannot run the standalone migration.'); - }); - it('should throw an error if the passed in path is a file', async () => { let error: string|null = null;