index.d.ts 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /**
  2. * @license
  3. * Copyright Google LLC All Rights Reserved.
  4. *
  5. * Use of this source code is governed by an MIT-style license that can be
  6. * found in the LICENSE file at https://angular.dev/license
  7. */
  8. import * as ts from 'typescript';
  9. import { FileSystem, WorkspacePath } from './file-system';
  10. import { UpdateLogger } from './logger';
  11. import { MigrationCtor } from './migration';
  12. import { TargetVersion } from './target-version';
  13. /**
  14. * An update project that can be run against individual migrations. An update project
  15. * accepts a TypeScript program and a context that is provided to all migrations. The
  16. * context is usually not used by migrations, but in some cases migrations rely on
  17. * specifics from the tool that performs the update (e.g. the Angular CLI). In those cases,
  18. * the context can provide the necessary specifics to the migrations in a type-safe way.
  19. */
  20. export declare class UpdateProject<Context> {
  21. /** Context provided to all migrations. */
  22. private _context;
  23. /** TypeScript program using workspace paths. */
  24. private _program;
  25. /** File system used for reading, writing and editing files. */
  26. private _fileSystem;
  27. /**
  28. * Set of analyzed files. Used for avoiding multiple migration runs if
  29. * files overlap between targets.
  30. */
  31. private _analyzedFiles;
  32. /** Logger used for printing messages. */
  33. private _logger;
  34. private readonly _typeChecker;
  35. constructor(
  36. /** Context provided to all migrations. */
  37. _context: Context,
  38. /** TypeScript program using workspace paths. */
  39. _program: ts.Program,
  40. /** File system used for reading, writing and editing files. */
  41. _fileSystem: FileSystem,
  42. /**
  43. * Set of analyzed files. Used for avoiding multiple migration runs if
  44. * files overlap between targets.
  45. */
  46. _analyzedFiles?: Set<WorkspacePath>,
  47. /** Logger used for printing messages. */
  48. _logger?: UpdateLogger);
  49. /**
  50. * Migrates the project to the specified target version.
  51. * @param migrationTypes Migrations that should be run.
  52. * @param target Version the project should be updated to. Can be `null` if the set of
  53. * specified migrations runs regardless of a target version.
  54. * @param data Upgrade data that is passed to all migration rules.
  55. * @param additionalStylesheetPaths Additional stylesheets that should be migrated, if not
  56. * referenced in an Angular component. This is helpful for global stylesheets in a project.
  57. * @param limitToDirectory If specified, changes will be limited to the given directory.
  58. */
  59. migrate<Data>(migrationTypes: MigrationCtor<Data, Context>[], target: TargetVersion | null, data: Data, additionalStylesheetPaths?: string[], limitToDirectory?: string): {
  60. hasFailures: boolean;
  61. };
  62. /**
  63. * Creates instances of the given migrations with the specified target
  64. * version and data.
  65. */
  66. private _createMigrations;
  67. /**
  68. * Creates a program from the specified tsconfig and patches the host
  69. * to read files and directories through the given file system.
  70. *
  71. * @throws {TsconfigParseError} If the tsconfig could not be parsed.
  72. */
  73. static createProgramFromTsconfig(tsconfigPath: WorkspacePath, fs: FileSystem): ts.Program;
  74. }