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.io/license
|
---|
7 | */
|
---|
8 | import * as ts from 'typescript';
|
---|
9 | import { ResolvedResource } from './component-resource-collector';
|
---|
10 | import { FileSystem, WorkspacePath } from './file-system';
|
---|
11 | import { UpdateLogger } from './logger';
|
---|
12 | import { TargetVersion } from './target-version';
|
---|
13 | import { LineAndCharacter } from './utils/line-mappings';
|
---|
14 | export interface MigrationFailure {
|
---|
15 | filePath: WorkspacePath;
|
---|
16 | message: string;
|
---|
17 | position?: LineAndCharacter;
|
---|
18 | }
|
---|
19 | export declare type PostMigrationAction = void | {
|
---|
20 | /** Whether the package manager should run upon migration completion. */
|
---|
21 | runPackageManager: boolean;
|
---|
22 | };
|
---|
23 | /** Creates a constructor type for the specified type. */
|
---|
24 | export declare type Constructor<T> = (new (...args: any[]) => T);
|
---|
25 | /** Gets a constructor type for the passed migration data. */
|
---|
26 | export declare type MigrationCtor<Data, Context = any> = Constructor<Migration<Data, Context>>;
|
---|
27 | export declare abstract class Migration<Data, Context = any> {
|
---|
28 | /** TypeScript program for the migration. */
|
---|
29 | program: ts.Program;
|
---|
30 | /** TypeChecker instance for the analysis program. */
|
---|
31 | typeChecker: ts.TypeChecker;
|
---|
32 | /** Version for which the migration rule should run. */
|
---|
33 | targetVersion: TargetVersion;
|
---|
34 | /** Context data for the migration. */
|
---|
35 | context: Context;
|
---|
36 | /** Upgrade data passed to the migration. */
|
---|
37 | upgradeData: Data;
|
---|
38 | /** File system that can be used for modifying files. */
|
---|
39 | fileSystem: FileSystem;
|
---|
40 | /** Logger that can be used to print messages as part of the migration. */
|
---|
41 | logger: UpdateLogger;
|
---|
42 | /** List of migration failures that need to be reported. */
|
---|
43 | failures: MigrationFailure[];
|
---|
44 | /** Whether the migration is enabled or not. */
|
---|
45 | abstract enabled: boolean;
|
---|
46 | constructor(
|
---|
47 | /** TypeScript program for the migration. */
|
---|
48 | program: ts.Program,
|
---|
49 | /** TypeChecker instance for the analysis program. */
|
---|
50 | typeChecker: ts.TypeChecker,
|
---|
51 | /** Version for which the migration rule should run. */
|
---|
52 | targetVersion: TargetVersion,
|
---|
53 | /** Context data for the migration. */
|
---|
54 | context: Context,
|
---|
55 | /** Upgrade data passed to the migration. */
|
---|
56 | upgradeData: Data,
|
---|
57 | /** File system that can be used for modifying files. */
|
---|
58 | fileSystem: FileSystem,
|
---|
59 | /** Logger that can be used to print messages as part of the migration. */
|
---|
60 | logger: UpdateLogger);
|
---|
61 | /** Method can be used to perform global analysis of the program. */
|
---|
62 | init(): void;
|
---|
63 | /**
|
---|
64 | * Method that will be called once all nodes, templates and stylesheets
|
---|
65 | * have been visited.
|
---|
66 | */
|
---|
67 | postAnalysis(): void;
|
---|
68 | /**
|
---|
69 | * Method that will be called for each node in a given source file. Unlike tslint, this
|
---|
70 | * function will only retrieve TypeScript nodes that need to be casted manually. This
|
---|
71 | * allows us to only walk the program source files once per program and not per
|
---|
72 | * migration rule (significant performance boost).
|
---|
73 | */
|
---|
74 | visitNode(node: ts.Node): void;
|
---|
75 | /** Method that will be called for each Angular template in the program. */
|
---|
76 | visitTemplate(template: ResolvedResource): void;
|
---|
77 | /** Method that will be called for each stylesheet in the program. */
|
---|
78 | visitStylesheet(stylesheet: ResolvedResource): void;
|
---|
79 | /** Creates a failure with a specified message at the given node location. */
|
---|
80 | protected createFailureAtNode(node: ts.Node, message: string): void;
|
---|
81 | }
|
---|