@dugararchit/cdk 0.0.0-dugararchit

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (206) hide show
  1. package/_index.scss +8 -0
  2. package/a11y/_index.import.scss +2 -0
  3. package/a11y/_index.scss +102 -0
  4. package/a11y/a11y-prebuilt.scss +3 -0
  5. package/fesm2022/stagefright5-cdk-a11y.mjs +2381 -0
  6. package/fesm2022/stagefright5-cdk-a11y.mjs.map +1 -0
  7. package/fesm2022/stagefright5-cdk-accordion.mjs +267 -0
  8. package/fesm2022/stagefright5-cdk-accordion.mjs.map +1 -0
  9. package/fesm2022/stagefright5-cdk-bidi.mjs +185 -0
  10. package/fesm2022/stagefright5-cdk-bidi.mjs.map +1 -0
  11. package/fesm2022/stagefright5-cdk-clipboard.mjs +250 -0
  12. package/fesm2022/stagefright5-cdk-clipboard.mjs.map +1 -0
  13. package/fesm2022/stagefright5-cdk-coercion.mjs +128 -0
  14. package/fesm2022/stagefright5-cdk-coercion.mjs.map +1 -0
  15. package/fesm2022/stagefright5-cdk-collections.mjs +472 -0
  16. package/fesm2022/stagefright5-cdk-collections.mjs.map +1 -0
  17. package/fesm2022/stagefright5-cdk-drag-drop.mjs +3690 -0
  18. package/fesm2022/stagefright5-cdk-drag-drop.mjs.map +1 -0
  19. package/fesm2022/stagefright5-cdk-keycodes.mjs +159 -0
  20. package/fesm2022/stagefright5-cdk-keycodes.mjs.map +1 -0
  21. package/fesm2022/stagefright5-cdk-layout.mjs +246 -0
  22. package/fesm2022/stagefright5-cdk-layout.mjs.map +1 -0
  23. package/fesm2022/stagefright5-cdk-observers.mjs +203 -0
  24. package/fesm2022/stagefright5-cdk-observers.mjs.map +1 -0
  25. package/fesm2022/stagefright5-cdk-overlay.mjs +3033 -0
  26. package/fesm2022/stagefright5-cdk-overlay.mjs.map +1 -0
  27. package/fesm2022/stagefright5-cdk-platform.mjs +375 -0
  28. package/fesm2022/stagefright5-cdk-platform.mjs.map +1 -0
  29. package/fesm2022/stagefright5-cdk-portal.mjs +672 -0
  30. package/fesm2022/stagefright5-cdk-portal.mjs.map +1 -0
  31. package/fesm2022/stagefright5-cdk-scrolling.mjs +1399 -0
  32. package/fesm2022/stagefright5-cdk-scrolling.mjs.map +1 -0
  33. package/fesm2022/stagefright5-cdk-stepper.mjs +624 -0
  34. package/fesm2022/stagefright5-cdk-stepper.mjs.map +1 -0
  35. package/fesm2022/stagefright5-cdk-table.mjs +2346 -0
  36. package/fesm2022/stagefright5-cdk-table.mjs.map +1 -0
  37. package/fesm2022/stagefright5-cdk-testing-protractor.mjs +324 -0
  38. package/fesm2022/stagefright5-cdk-testing-protractor.mjs.map +1 -0
  39. package/fesm2022/stagefright5-cdk-testing-selenium-webdriver.mjs +364 -0
  40. package/fesm2022/stagefright5-cdk-testing-selenium-webdriver.mjs.map +1 -0
  41. package/fesm2022/stagefright5-cdk-testing-testbed.mjs +806 -0
  42. package/fesm2022/stagefright5-cdk-testing-testbed.mjs.map +1 -0
  43. package/fesm2022/stagefright5-cdk-testing.mjs +740 -0
  44. package/fesm2022/stagefright5-cdk-testing.mjs.map +1 -0
  45. package/fesm2022/stagefright5-cdk-text-field.mjs +453 -0
  46. package/fesm2022/stagefright5-cdk-text-field.mjs.map +1 -0
  47. package/fesm2022/stagefright5-cdk-tree.mjs +945 -0
  48. package/fesm2022/stagefright5-cdk-tree.mjs.map +1 -0
  49. package/fesm2022/stagefright5-cdk.mjs +26 -0
  50. package/fesm2022/stagefright5-cdk.mjs.map +1 -0
  51. package/overlay/_index-deprecated.scss +13 -0
  52. package/overlay/_index.import.scss +13 -0
  53. package/overlay/_index.scss +148 -0
  54. package/overlay/overlay-prebuilt.scss +3 -0
  55. package/package.json +159 -0
  56. package/schematics/ng-update/test-cases/misc/global-stylesheets-test.scss +3 -0
  57. package/schematics/schematics/BUILD.bazel +104 -0
  58. package/schematics/schematics/README.md +4 -0
  59. package/schematics/schematics/collection.json +18 -0
  60. package/schematics/schematics/index.ts +22 -0
  61. package/schematics/schematics/migration.json +50 -0
  62. package/schematics/schematics/ng-add/index.spec.ts +50 -0
  63. package/schematics/schematics/ng-add/index.ts +39 -0
  64. package/schematics/schematics/ng-add/package-config.ts +62 -0
  65. package/schematics/schematics/ng-add/schema.json +16 -0
  66. package/schematics/schematics/ng-add/schema.ts +12 -0
  67. package/schematics/schematics/ng-generate/drag-drop/files/__path__/__name@dasherize@if-flat__/__name@dasherize__.component.__style__.template +53 -0
  68. package/schematics/schematics/ng-generate/drag-drop/files/__path__/__name@dasherize@if-flat__/__name@dasherize__.component.html.template +17 -0
  69. package/schematics/schematics/ng-generate/drag-drop/files/__path__/__name@dasherize@if-flat__/__name@dasherize__.component.spec.ts.template +29 -0
  70. package/schematics/schematics/ng-generate/drag-drop/files/__path__/__name@dasherize@if-flat__/__name@dasherize__.component.ts.template +43 -0
  71. package/schematics/schematics/ng-generate/drag-drop/index.spec.ts +205 -0
  72. package/schematics/schematics/ng-generate/drag-drop/index.ts +35 -0
  73. package/schematics/schematics/ng-generate/drag-drop/schema.json +93 -0
  74. package/schematics/schematics/ng-generate/drag-drop/schema.ts +11 -0
  75. package/schematics/schematics/ng-update/data/attribute-selectors.ts +29 -0
  76. package/schematics/schematics/ng-update/data/class-names.ts +50 -0
  77. package/schematics/schematics/ng-update/data/constructor-checks.ts +75 -0
  78. package/schematics/schematics/ng-update/data/css-selectors.ts +33 -0
  79. package/schematics/schematics/ng-update/data/element-selectors.ts +21 -0
  80. package/schematics/schematics/ng-update/data/index.ts +18 -0
  81. package/schematics/schematics/ng-update/data/input-names.ts +118 -0
  82. package/schematics/schematics/ng-update/data/method-call-checks.ts +63 -0
  83. package/schematics/schematics/ng-update/data/output-names.ts +42 -0
  84. package/schematics/schematics/ng-update/data/property-names.ts +151 -0
  85. package/schematics/schematics/ng-update/data/symbol-removal.ts +22 -0
  86. package/schematics/schematics/ng-update/devkit-file-system.ts +87 -0
  87. package/schematics/schematics/ng-update/devkit-migration-rule.ts +185 -0
  88. package/schematics/schematics/ng-update/devkit-migration.ts +47 -0
  89. package/schematics/schematics/ng-update/find-stylesheets.ts +43 -0
  90. package/schematics/schematics/ng-update/html-parsing/angular.ts +49 -0
  91. package/schematics/schematics/ng-update/html-parsing/elements.ts +66 -0
  92. package/schematics/schematics/ng-update/index.ts +113 -0
  93. package/schematics/schematics/ng-update/migrations/attribute-selectors.ts +83 -0
  94. package/schematics/schematics/ng-update/migrations/class-inheritance.ts +63 -0
  95. package/schematics/schematics/ng-update/migrations/class-names.ts +107 -0
  96. package/schematics/schematics/ng-update/migrations/constructor-signature.ts +170 -0
  97. package/schematics/schematics/ng-update/migrations/css-selectors.ts +83 -0
  98. package/schematics/schematics/ng-update/migrations/element-selectors.ts +75 -0
  99. package/schematics/schematics/ng-update/migrations/input-names.ts +83 -0
  100. package/schematics/schematics/ng-update/migrations/method-call-arguments.ts +70 -0
  101. package/schematics/schematics/ng-update/migrations/misc-template.ts +36 -0
  102. package/schematics/schematics/ng-update/migrations/output-names.ts +61 -0
  103. package/schematics/schematics/ng-update/migrations/property-names.ts +61 -0
  104. package/schematics/schematics/ng-update/migrations/symbol-removal.ts +51 -0
  105. package/schematics/schematics/ng-update/migrations/tilde-import-v13/tilde-import-migration.ts +40 -0
  106. package/schematics/schematics/ng-update/public-api.ts +18 -0
  107. package/schematics/schematics/ng-update/test-cases/index.spec.ts +18 -0
  108. package/schematics/schematics/ng-update/test-cases/misc/external-resource-resolution.spec.ts +32 -0
  109. package/schematics/schematics/ng-update/test-cases/misc/external-resource-resolution_input.ts +22 -0
  110. package/schematics/schematics/ng-update/test-cases/misc/global-stylesheets-test.scss +3 -0
  111. package/schematics/schematics/ng-update/test-cases/misc/global-stylesheets.spec.ts +50 -0
  112. package/schematics/schematics/ng-update/test-cases/misc/global-stylesheets_input.ts +8 -0
  113. package/schematics/schematics/ng-update/test-cases/misc/method-call-checks.spec.ts +20 -0
  114. package/schematics/schematics/ng-update/test-cases/misc/method-call-checks_input.ts +18 -0
  115. package/schematics/schematics/ng-update/test-cases/misc/module-resolution.spec.ts +27 -0
  116. package/schematics/schematics/ng-update/test-cases/v13/misc/tilde-import-v13.spec.ts +149 -0
  117. package/schematics/schematics/ng-update/test-cases/v6/attribute-selectors_expected_output.ts +36 -0
  118. package/schematics/schematics/ng-update/test-cases/v6/attribute-selectors_input.ts +36 -0
  119. package/schematics/schematics/ng-update/test-cases/v6/class-names_expected_output.ts +8 -0
  120. package/schematics/schematics/ng-update/test-cases/v6/class-names_input.ts +8 -0
  121. package/schematics/schematics/ng-update/test-cases/v6/input-names_expected_output.ts +22 -0
  122. package/schematics/schematics/ng-update/test-cases/v6/input-names_input.ts +22 -0
  123. package/schematics/schematics/ng-update/test-cases/v6/property-names_expected_output.ts +64 -0
  124. package/schematics/schematics/ng-update/test-cases/v6/property-names_input.ts +64 -0
  125. package/schematics/schematics/ng-update/test-cases/v7/property-names_expected_output.ts +28 -0
  126. package/schematics/schematics/ng-update/test-cases/v7/property-names_input.ts +28 -0
  127. package/schematics/schematics/ng-update/typescript/base-types.ts +22 -0
  128. package/schematics/schematics/ng-update/typescript/imports.ts +54 -0
  129. package/schematics/schematics/ng-update/typescript/literal.ts +32 -0
  130. package/schematics/schematics/ng-update/typescript/module-specifiers.ts +39 -0
  131. package/schematics/schematics/ng-update/update-schematic.md +209 -0
  132. package/schematics/schematics/ng-update/upgrade-data.ts +79 -0
  133. package/schematics/schematics/paths.ts +15 -0
  134. package/schematics/schematics/testing/BUILD.bazel +27 -0
  135. package/schematics/schematics/testing/file-content.ts +20 -0
  136. package/schematics/schematics/testing/index.ts +14 -0
  137. package/schematics/schematics/testing/post-scheduled-tasks.ts +45 -0
  138. package/schematics/schematics/testing/resolve-bazel-path.ts +46 -0
  139. package/schematics/schematics/testing/test-app.ts +21 -0
  140. package/schematics/schematics/testing/test-case-setup.ts +236 -0
  141. package/schematics/schematics/testing/test-library.ts +21 -0
  142. package/schematics/schematics/testing/test-project.ts +40 -0
  143. package/schematics/schematics/testing/tsconfig.json +7 -0
  144. package/schematics/schematics/tsconfig.json +28 -0
  145. package/schematics/schematics/update-tool/BUILD.bazel +19 -0
  146. package/schematics/schematics/update-tool/component-resource-collector.ts +195 -0
  147. package/schematics/schematics/update-tool/file-system.ts +78 -0
  148. package/schematics/schematics/update-tool/index.ts +191 -0
  149. package/schematics/schematics/update-tool/logger.ts +23 -0
  150. package/schematics/schematics/update-tool/migration.ts +88 -0
  151. package/schematics/schematics/update-tool/public-api.ts +16 -0
  152. package/schematics/schematics/update-tool/target-version.ts +31 -0
  153. package/schematics/schematics/update-tool/tsconfig.json +7 -0
  154. package/schematics/schematics/update-tool/update-recorder.ts +14 -0
  155. package/schematics/schematics/update-tool/utils/decorators.ts +54 -0
  156. package/schematics/schematics/update-tool/utils/functions.ts +18 -0
  157. package/schematics/schematics/update-tool/utils/imports.ts +128 -0
  158. package/schematics/schematics/update-tool/utils/line-mappings.ts +84 -0
  159. package/schematics/schematics/update-tool/utils/parse-tsconfig.ts +25 -0
  160. package/schematics/schematics/update-tool/utils/property-name.ts +28 -0
  161. package/schematics/schematics/update-tool/utils/virtual-host.ts +116 -0
  162. package/schematics/schematics/update-tool/version-changes.ts +49 -0
  163. package/schematics/schematics/utils/ast/ng-module-imports.spec.ts +43 -0
  164. package/schematics/schematics/utils/ast/ng-module-imports.ts +102 -0
  165. package/schematics/schematics/utils/ast.ts +88 -0
  166. package/schematics/schematics/utils/build-component.ts +252 -0
  167. package/schematics/schematics/utils/get-project.ts +27 -0
  168. package/schematics/schematics/utils/html-manipulation.ts +105 -0
  169. package/schematics/schematics/utils/index.ts +19 -0
  170. package/schematics/schematics/utils/parse5-element.ts +34 -0
  171. package/schematics/schematics/utils/project-index-file.ts +21 -0
  172. package/schematics/schematics/utils/project-main-file.ts +26 -0
  173. package/schematics/schematics/utils/project-style-file.ts +53 -0
  174. package/schematics/schematics/utils/project-targets.ts +43 -0
  175. package/schematics/schematics/utils/project-tsconfig-paths.spec.ts +91 -0
  176. package/schematics/schematics/utils/project-tsconfig-paths.ts +49 -0
  177. package/schematics/schematics/utils/schematic-options.ts +65 -0
  178. package/schematics/schematics/utils/vendored-ast-utils/index.ts +599 -0
  179. package/scrolling/virtual-scroll-viewport.scss +87 -0
  180. package/table/table.scss +3 -0
  181. package/text-field/_index.import.scss +2 -0
  182. package/text-field/_index.scss +89 -0
  183. package/text-field/text-field-prebuilt.scss +4 -0
  184. package/types/stagefright5-cdk-a11y.d.ts +1160 -0
  185. package/types/stagefright5-cdk-accordion.d.ts +95 -0
  186. package/types/stagefright5-cdk-bidi.d.ts +95 -0
  187. package/types/stagefright5-cdk-clipboard.d.ts +116 -0
  188. package/types/stagefright5-cdk-coercion.d.ts +101 -0
  189. package/types/stagefright5-cdk-collections.d.ts +405 -0
  190. package/types/stagefright5-cdk-drag-drop.d.ts +1471 -0
  191. package/types/stagefright5-cdk-keycodes.d.ts +142 -0
  192. package/types/stagefright5-cdk-layout.d.ts +96 -0
  193. package/types/stagefright5-cdk-observers.d.ts +91 -0
  194. package/types/stagefright5-cdk-overlay.d.ts +1258 -0
  195. package/types/stagefright5-cdk-platform.d.ts +130 -0
  196. package/types/stagefright5-cdk-portal.d.ts +327 -0
  197. package/types/stagefright5-cdk-scrolling.d.ts +631 -0
  198. package/types/stagefright5-cdk-stepper.d.ts +302 -0
  199. package/types/stagefright5-cdk-table.d.ts +1128 -0
  200. package/types/stagefright5-cdk-testing-protractor.d.ts +146 -0
  201. package/types/stagefright5-cdk-testing-selenium-webdriver.d.ts +161 -0
  202. package/types/stagefright5-cdk-testing-testbed.d.ts +168 -0
  203. package/types/stagefright5-cdk-testing.d.ts +735 -0
  204. package/types/stagefright5-cdk-text-field.d.ts +171 -0
  205. package/types/stagefright5-cdk-tree.d.ts +522 -0
  206. package/types/stagefright5-cdk.d.ts +14 -0
@@ -0,0 +1,191 @@
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
+
9
+ import * as ts from 'typescript';
10
+
11
+ import {ComponentResourceCollector} from './component-resource-collector';
12
+ import {FileSystem, WorkspacePath} from './file-system';
13
+ import {defaultLogger, UpdateLogger} from './logger';
14
+ import {Migration, MigrationCtor, MigrationFailure} from './migration';
15
+ import {TargetVersion} from './target-version';
16
+ import {parseTsconfigFile} from './utils/parse-tsconfig';
17
+ import {createFileSystemCompilerHost} from './utils/virtual-host';
18
+
19
+ /**
20
+ * An update project that can be run against individual migrations. An update project
21
+ * accepts a TypeScript program and a context that is provided to all migrations. The
22
+ * context is usually not used by migrations, but in some cases migrations rely on
23
+ * specifics from the tool that performs the update (e.g. the Angular CLI). In those cases,
24
+ * the context can provide the necessary specifics to the migrations in a type-safe way.
25
+ */
26
+ export class UpdateProject<Context> {
27
+ private readonly _typeChecker: ts.TypeChecker = this._program.getTypeChecker();
28
+
29
+ constructor(
30
+ /** Context provided to all migrations. */
31
+ private _context: Context,
32
+ /** TypeScript program using workspace paths. */
33
+ private _program: ts.Program,
34
+ /** File system used for reading, writing and editing files. */
35
+ private _fileSystem: FileSystem,
36
+ /**
37
+ * Set of analyzed files. Used for avoiding multiple migration runs if
38
+ * files overlap between targets.
39
+ */
40
+ private _analyzedFiles: Set<WorkspacePath> = new Set(),
41
+ /** Logger used for printing messages. */
42
+ private _logger: UpdateLogger = defaultLogger,
43
+ ) {}
44
+
45
+ /**
46
+ * Migrates the project to the specified target version.
47
+ * @param migrationTypes Migrations that should be run.
48
+ * @param target Version the project should be updated to.
49
+ * @param data Upgrade data that is passed to all migration rules.
50
+ * @param additionalStylesheetPaths Additional stylesheets that should be migrated, if not
51
+ * referenced in an Angular component. This is helpful for global stylesheets in a project.
52
+ */
53
+ migrate<Data>(
54
+ migrationTypes: MigrationCtor<Data, Context>[],
55
+ target: TargetVersion,
56
+ data: Data,
57
+ additionalStylesheetPaths?: string[],
58
+ ): {hasFailures: boolean} {
59
+ // Create instances of the specified migrations.
60
+ const migrations = this._createMigrations(migrationTypes, target, data);
61
+ // Creates the component resource collector. The collector can visit arbitrary
62
+ // TypeScript nodes and will find Angular component resources. Resources include
63
+ // templates and stylesheets. It also captures inline stylesheets and templates.
64
+ const resourceCollector = new ComponentResourceCollector(this._typeChecker, this._fileSystem);
65
+ // Collect all of the TypeScript source files we want to migrate. We don't
66
+ // migrate type definition files, or source files from external libraries.
67
+ const sourceFiles = this._program
68
+ .getSourceFiles()
69
+ .filter(f => !f.isDeclarationFile && !this._program.isSourceFileFromExternalLibrary(f));
70
+
71
+ // Helper function that visits a given TypeScript node and collects all referenced
72
+ // component resources (i.e. stylesheets or templates). Additionally, the helper
73
+ // visits the node in each instantiated migration.
74
+ const visitNodeAndCollectResources = (node: ts.Node) => {
75
+ migrations.forEach(r => r.visitNode(node));
76
+ ts.forEachChild(node, visitNodeAndCollectResources);
77
+ resourceCollector.visitNode(node);
78
+ };
79
+
80
+ // Walk through all source file, if it has not been visited before, and
81
+ // visit found nodes while collecting potential resources.
82
+ sourceFiles.forEach(sourceFile => {
83
+ const resolvedPath = this._fileSystem.resolve(sourceFile.fileName);
84
+ // Do not visit source files which have been checked as part of a
85
+ // previously migrated TypeScript project.
86
+ if (!this._analyzedFiles.has(resolvedPath)) {
87
+ visitNodeAndCollectResources(sourceFile);
88
+ this._analyzedFiles.add(resolvedPath);
89
+ }
90
+ });
91
+
92
+ // Walk through all resolved templates and visit them in each instantiated
93
+ // migration. Note that this can only happen after source files have been
94
+ // visited because we find templates through the TypeScript source files.
95
+ resourceCollector.resolvedTemplates.forEach(template => {
96
+ // Do not visit the template if it has been checked before. Inline
97
+ // templates cannot be referenced multiple times.
98
+ if (template.inline || !this._analyzedFiles.has(template.filePath)) {
99
+ migrations.forEach(m => m.visitTemplate(template));
100
+ this._analyzedFiles.add(template.filePath);
101
+ }
102
+ });
103
+
104
+ // Walk through all resolved stylesheets and visit them in each instantiated
105
+ // migration. Note that this can only happen after source files have been
106
+ // visited because we find stylesheets through the TypeScript source files.
107
+ resourceCollector.resolvedStylesheets.forEach(stylesheet => {
108
+ // Do not visit the stylesheet if it has been checked before. Inline
109
+ // stylesheets cannot be referenced multiple times.
110
+ if (stylesheet.inline || !this._analyzedFiles.has(stylesheet.filePath)) {
111
+ migrations.forEach(r => r.visitStylesheet(stylesheet));
112
+ this._analyzedFiles.add(stylesheet.filePath);
113
+ }
114
+ });
115
+
116
+ // In some applications, developers will have global stylesheets which are not
117
+ // specified in any Angular component. Therefore we allow for additional stylesheets
118
+ // being specified. We visit them in each migration unless they have been already
119
+ // discovered before as actual component resource.
120
+ if (additionalStylesheetPaths) {
121
+ additionalStylesheetPaths.forEach(filePath => {
122
+ const resolvedPath = this._fileSystem.resolve(filePath);
123
+ const stylesheet = resourceCollector.resolveExternalStylesheet(resolvedPath, null);
124
+ // Do not visit stylesheets which have been referenced from a component.
125
+ if (!this._analyzedFiles.has(resolvedPath) && stylesheet) {
126
+ migrations.forEach(r => r.visitStylesheet(stylesheet));
127
+ this._analyzedFiles.add(resolvedPath);
128
+ }
129
+ });
130
+ }
131
+
132
+ // Call the "postAnalysis" method for each migration.
133
+ migrations.forEach(r => r.postAnalysis());
134
+
135
+ // Collect all failures reported by individual migrations.
136
+ const failures = migrations.reduce(
137
+ (res, m) => res.concat(m.failures),
138
+ [] as MigrationFailure[],
139
+ );
140
+
141
+ // In case there are failures, print these to the CLI logger as warnings.
142
+ if (failures.length) {
143
+ failures.forEach(({filePath, message, position}) => {
144
+ const lineAndCharacter = position ? `@${position.line + 1}:${position.character + 1}` : '';
145
+ this._logger.warn(`${filePath}${lineAndCharacter} - ${message}`);
146
+ });
147
+ }
148
+
149
+ return {
150
+ hasFailures: !!failures.length,
151
+ };
152
+ }
153
+
154
+ /**
155
+ * Creates instances of the given migrations with the specified target
156
+ * version and data.
157
+ */
158
+ private _createMigrations<Data>(
159
+ types: MigrationCtor<Data, Context>[],
160
+ target: TargetVersion,
161
+ data: Data,
162
+ ): Migration<Data, Context>[] {
163
+ const result: Migration<Data, Context>[] = [];
164
+ for (const ctor of types) {
165
+ const instance = new ctor(
166
+ this._program,
167
+ this._typeChecker,
168
+ target,
169
+ this._context,
170
+ data,
171
+ this._fileSystem,
172
+ this._logger,
173
+ );
174
+ instance.init();
175
+ if (instance.enabled) {
176
+ result.push(instance);
177
+ }
178
+ }
179
+ return result;
180
+ }
181
+
182
+ /**
183
+ * Creates a program form the specified tsconfig and patches the host
184
+ * to read files and directories through the given file system.
185
+ */
186
+ static createProgramFromTsconfig(tsconfigPath: WorkspacePath, fs: FileSystem): ts.Program {
187
+ const parsed = parseTsconfigFile(fs.resolve(tsconfigPath), fs);
188
+ const host = createFileSystemCompilerHost(parsed.options, fs);
189
+ return ts.createProgram(parsed.fileNames, parsed.options, host);
190
+ }
191
+ }
@@ -0,0 +1,23 @@
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
+
9
+ export interface UpdateLogger {
10
+ debug(message: string): void;
11
+ error(message: string): void;
12
+ fatal(message: string): void;
13
+ info(message: string): void;
14
+ warn(message: string): void;
15
+ }
16
+
17
+ export const defaultLogger: UpdateLogger = {
18
+ debug: m => console.debug(m),
19
+ error: m => console.error(m),
20
+ fatal: m => console.error(m),
21
+ info: m => console.info(m),
22
+ warn: m => console.warn(m),
23
+ };
@@ -0,0 +1,88 @@
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
+
9
+ import * as ts from 'typescript';
10
+ import {ResolvedResource} from './component-resource-collector';
11
+ import {FileSystem, WorkspacePath} from './file-system';
12
+ import {UpdateLogger} from './logger';
13
+ import {TargetVersion} from './target-version';
14
+ import {LineAndCharacter} from './utils/line-mappings';
15
+
16
+ export interface MigrationFailure {
17
+ filePath: WorkspacePath;
18
+ message: string;
19
+ position?: LineAndCharacter;
20
+ }
21
+
22
+ export type PostMigrationAction = void | {
23
+ /** Whether the package manager should run upon migration completion. */
24
+ runPackageManager: boolean;
25
+ };
26
+
27
+ /** Creates a constructor type for the specified type. */
28
+ export type Constructor<T> = new (...args: any[]) => T;
29
+ /** Gets a constructor type for the passed migration data. */
30
+ export type MigrationCtor<Data, Context = any> = Constructor<Migration<Data, Context>>;
31
+
32
+ export abstract class Migration<Data, Context = any> {
33
+ /** List of migration failures that need to be reported. */
34
+ failures: MigrationFailure[] = [];
35
+
36
+ /** Whether the migration is enabled or not. */
37
+ abstract enabled: boolean;
38
+
39
+ constructor(
40
+ /** TypeScript program for the migration. */
41
+ public program: ts.Program,
42
+ /** TypeChecker instance for the analysis program. */
43
+ public typeChecker: ts.TypeChecker,
44
+ /** Version for which the migration rule should run. */
45
+ public targetVersion: TargetVersion,
46
+ /** Context data for the migration. */
47
+ public context: Context,
48
+ /** Upgrade data passed to the migration. */
49
+ public upgradeData: Data,
50
+ /** File system that can be used for modifying files. */
51
+ public fileSystem: FileSystem,
52
+ /** Logger that can be used to print messages as part of the migration. */
53
+ public logger: UpdateLogger,
54
+ ) {}
55
+
56
+ /** Method can be used to perform global analysis of the program. */
57
+ init(): void {}
58
+
59
+ /**
60
+ * Method that will be called once all nodes, templates and stylesheets
61
+ * have been visited.
62
+ */
63
+ postAnalysis(): void {}
64
+
65
+ /**
66
+ * Method that will be called for each node in a given source file. Unlike tslint, this
67
+ * function will only retrieve TypeScript nodes that need to be casted manually. This
68
+ * allows us to only walk the program source files once per program and not per
69
+ * migration rule (significant performance boost).
70
+ */
71
+ visitNode(node: ts.Node): void {}
72
+
73
+ /** Method that will be called for each Angular template in the program. */
74
+ visitTemplate(template: ResolvedResource): void {}
75
+
76
+ /** Method that will be called for each stylesheet in the program. */
77
+ visitStylesheet(stylesheet: ResolvedResource): void {}
78
+
79
+ /** Creates a failure with a specified message at the given node location. */
80
+ protected createFailureAtNode(node: ts.Node, message: string) {
81
+ const sourceFile = node.getSourceFile();
82
+ this.failures.push({
83
+ filePath: this.fileSystem.resolve(sourceFile.fileName),
84
+ position: ts.getLineAndCharacterOfPosition(sourceFile, node.getStart()),
85
+ message: message,
86
+ });
87
+ }
88
+ }
@@ -0,0 +1,16 @@
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
+
9
+ export * from './component-resource-collector';
10
+ export * from './file-system';
11
+ export * from './index';
12
+ export * from './migration';
13
+ export * from './target-version';
14
+ export * from './utils/decorators';
15
+ export * from './utils/imports';
16
+ export * from './version-changes';
@@ -0,0 +1,31 @@
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
+
9
+ /** Possible versions that can be automatically migrated by `ng update`. */
10
+ // Used in an `Object.keys` call below so it can't be `const enum`.
11
+ // tslint:disable-next-line:prefer-const-enum
12
+ export enum TargetVersion {
13
+ V6 = 'version 6',
14
+ V7 = 'version 7',
15
+ V8 = 'version 8',
16
+ V9 = 'version 9',
17
+ V10 = 'version 10',
18
+ V11 = 'version 11',
19
+ V12 = 'version 12',
20
+ V13 = 'version 13',
21
+ }
22
+
23
+ /**
24
+ * Returns all versions that are supported by "ng update". The versions are determined
25
+ * based on the "TargetVersion" enum.
26
+ */
27
+ export function getAllVersionNames(): string[] {
28
+ return Object.keys(TargetVersion).filter(enumValue => {
29
+ return typeof (TargetVersion as Record<string, string | undefined>)[enumValue] === 'string';
30
+ });
31
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "compilerOptions": {
3
+ "strict": true,
4
+ "lib": ["es2015"],
5
+ "types": ["node", "glob"]
6
+ }
7
+ }
@@ -0,0 +1,14 @@
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
+
9
+ /** Update recorder that can be used to apply changes to a source file. */
10
+ export interface UpdateRecorder {
11
+ insertLeft(index: number, content: string): UpdateRecorder;
12
+ insertRight(index: number, content: string): UpdateRecorder;
13
+ remove(index: number, length: number): UpdateRecorder;
14
+ }
@@ -0,0 +1,54 @@
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
+
9
+ import * as ts from 'typescript';
10
+
11
+ import {getImportOfIdentifier, Import} from './imports';
12
+
13
+ export type CallExpressionDecorator = ts.Decorator & {
14
+ expression: ts.CallExpression;
15
+ };
16
+
17
+ export interface NgDecorator {
18
+ name: string;
19
+ node: CallExpressionDecorator;
20
+ }
21
+
22
+ /**
23
+ * Gets all decorators which are imported from an Angular package
24
+ * (e.g. "@angular/core") from a list of decorators.
25
+ */
26
+ export function getAngularDecorators(
27
+ typeChecker: ts.TypeChecker,
28
+ decorators: readonly ts.Decorator[],
29
+ ): readonly NgDecorator[] {
30
+ return decorators
31
+ .map(node => ({node, importData: getCallDecoratorImport(typeChecker, node)}))
32
+ .filter(({importData}) => importData && importData.moduleName.startsWith('@angular/'))
33
+ .map(({node, importData}) => ({
34
+ node: node as CallExpressionDecorator,
35
+ name: importData!.symbolName,
36
+ }));
37
+ }
38
+
39
+ export function getCallDecoratorImport(
40
+ typeChecker: ts.TypeChecker,
41
+ decorator: ts.Decorator,
42
+ ): Import | null {
43
+ if (!ts.isCallExpression(decorator.expression)) {
44
+ return null;
45
+ }
46
+ const valueExpr = decorator.expression.expression;
47
+ let identifier: ts.Identifier | null = null;
48
+ if (ts.isIdentifier(valueExpr)) {
49
+ identifier = valueExpr;
50
+ } else if (ts.isPropertyAccessExpression(valueExpr) && ts.isIdentifier(valueExpr.name)) {
51
+ identifier = valueExpr.name;
52
+ }
53
+ return identifier ? getImportOfIdentifier(identifier, typeChecker) : null;
54
+ }
@@ -0,0 +1,18 @@
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
+
9
+ import * as ts from 'typescript';
10
+
11
+ /**
12
+ * Unwraps a given expression TypeScript node. Expressions can be wrapped within multiple
13
+ * parentheses. e.g. "(((({exp}))))()". The function should return the TypeScript node
14
+ * referring to the inner expression. e.g "exp".
15
+ */
16
+ export function unwrapExpression(node: ts.Expression | ts.ParenthesizedExpression): ts.Expression {
17
+ return ts.isParenthesizedExpression(node) ? unwrapExpression(node.expression) : node;
18
+ }
@@ -0,0 +1,128 @@
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
+
9
+ import * as ts from 'typescript';
10
+
11
+ /** Interface describing a resolved import. */
12
+ export interface Import {
13
+ /** Name of the imported symbol. */
14
+ symbolName: string;
15
+ /** Module name from which the symbol has been imported. */
16
+ moduleName: string;
17
+ }
18
+
19
+ /** Resolves the import of the specified identifier. */
20
+ export function getImportOfIdentifier(
21
+ node: ts.Identifier,
22
+ typeChecker: ts.TypeChecker,
23
+ ): Import | null {
24
+ // Free standing identifiers which resolve to an import will be handled
25
+ // as direct imports. e.g. "@Component()" where "Component" is an identifier
26
+ // referring to an import specifier.
27
+ const directImport = getSpecificImportOfIdentifier(node, typeChecker);
28
+ if (directImport !== null) {
29
+ return directImport;
30
+ } else if (ts.isQualifiedName(node.parent) && node.parent.right === node) {
31
+ // Determines the import of a qualified name. e.g. "let t: core.Component". In that
32
+ // case, the import of the most left identifier will be determined ("core").
33
+ const qualifierRoot = getQualifiedNameRoot(node.parent);
34
+ if (qualifierRoot) {
35
+ const moduleName = getImportOfNamespacedIdentifier(qualifierRoot, typeChecker);
36
+ if (moduleName) {
37
+ return {moduleName, symbolName: node.text};
38
+ }
39
+ }
40
+ } else if (ts.isPropertyAccessExpression(node.parent) && node.parent.name === node) {
41
+ // Determines the import of a property expression. e.g. "@core.Component". In that
42
+ // case, the import of the most left identifier will be determined ("core").
43
+ const rootIdentifier = getPropertyAccessRoot(node.parent);
44
+ if (rootIdentifier) {
45
+ const moduleName = getImportOfNamespacedIdentifier(rootIdentifier, typeChecker);
46
+ if (moduleName) {
47
+ return {moduleName, symbolName: node.text};
48
+ }
49
+ }
50
+ }
51
+ return null;
52
+ }
53
+
54
+ /**
55
+ * Resolves the import of the specified identifier. Expects the identifier to resolve
56
+ * to a fine-grained import declaration with import specifiers.
57
+ */
58
+ function getSpecificImportOfIdentifier(
59
+ node: ts.Identifier,
60
+ typeChecker: ts.TypeChecker,
61
+ ): Import | null {
62
+ const symbol = typeChecker.getSymbolAtLocation(node);
63
+ if (!symbol || !symbol.declarations || !symbol.declarations.length) {
64
+ return null;
65
+ }
66
+ const declaration = symbol.declarations[0];
67
+ if (!ts.isImportSpecifier(declaration)) {
68
+ return null;
69
+ }
70
+ // Since the declaration is an import specifier, we can walk up three times to get a reference
71
+ // to the import declaration node (NamedImports -> ImportClause -> ImportDeclaration).
72
+ const importDecl = declaration.parent.parent.parent;
73
+ if (!ts.isStringLiteral(importDecl.moduleSpecifier)) {
74
+ return null;
75
+ }
76
+ return {
77
+ moduleName: importDecl.moduleSpecifier.text,
78
+ symbolName: declaration.propertyName ? declaration.propertyName.text : declaration.name.text,
79
+ };
80
+ }
81
+
82
+ /**
83
+ * Resolves the import of the specified identifier. Expects the identifier to
84
+ * resolve to a namespaced import declaration. e.g. "import * as core from ...".
85
+ */
86
+ function getImportOfNamespacedIdentifier(
87
+ node: ts.Identifier,
88
+ typeChecker: ts.TypeChecker,
89
+ ): string | null {
90
+ const symbol = typeChecker.getSymbolAtLocation(node);
91
+ if (!symbol || !symbol.declarations || !symbol.declarations.length) {
92
+ return null;
93
+ }
94
+ const declaration = symbol.declarations[0];
95
+ if (!ts.isNamespaceImport(declaration)) {
96
+ return null;
97
+ }
98
+ // Since the declaration is a namespace import, we can walk up three times to get a reference
99
+ // to the import declaration node (NamespaceImport -> ImportClause -> ImportDeclaration).
100
+ const importDecl = declaration.parent.parent;
101
+ if (!ts.isStringLiteral(importDecl.moduleSpecifier)) {
102
+ return null;
103
+ }
104
+
105
+ return importDecl.moduleSpecifier.text;
106
+ }
107
+
108
+ /**
109
+ * Gets the root identifier of a qualified type chain. For example: "core.GestureConfig"
110
+ * will return the "core" identifier. Allowing us to find the import of "core".
111
+ */
112
+ function getQualifiedNameRoot(name: ts.QualifiedName): ts.Identifier | null {
113
+ while (ts.isQualifiedName(name.left)) {
114
+ name = name.left;
115
+ }
116
+ return ts.isIdentifier(name.left) ? name.left : null;
117
+ }
118
+
119
+ /**
120
+ * Gets the root identifier of a property access chain. For example: "core.GestureConfig"
121
+ * will return the "core" identifier. Allowing us to find the import of "core".
122
+ */
123
+ function getPropertyAccessRoot(node: ts.PropertyAccessExpression): ts.Identifier | null {
124
+ while (ts.isPropertyAccessExpression(node.expression)) {
125
+ node = node.expression;
126
+ }
127
+ return ts.isIdentifier(node.expression) ? node.expression : null;
128
+ }
@@ -0,0 +1,84 @@
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
+
9
+ /*
10
+ * Line mapping utilities which can be used to retrieve line and character based
11
+ * on an absolute character position in a given file. This functionality is similar
12
+ * to TypeScript's "ts.getLineAndCharacterFromPosition" utility, but we cannot leverage
13
+ * their logic for line mappings as it's internal and we need to generate line mappings
14
+ * for non-TypeScript files such as HTML templates or stylesheets.
15
+ *
16
+ * Line and character can be retrieved by splitting a given source text based on
17
+ * line breaks into line start entries. Later when a specific position is requested,
18
+ * the closest line-start position is determined based on the given position.
19
+ */
20
+
21
+ const LF_CHAR = 10;
22
+ const CR_CHAR = 13;
23
+ const LINE_SEP_CHAR = 8232;
24
+ const PARAGRAPH_CHAR = 8233;
25
+
26
+ export interface LineAndCharacter {
27
+ character: number;
28
+ line: number;
29
+ }
30
+
31
+ /** Gets the line and character for the given position from the line starts map. */
32
+ export function getLineAndCharacterFromPosition(lineStartsMap: number[], position: number) {
33
+ const lineIndex = findClosestLineStartPosition(lineStartsMap, position);
34
+ return {character: position - lineStartsMap[lineIndex], line: lineIndex};
35
+ }
36
+
37
+ /**
38
+ * Computes the line start map of the given text. This can be used in order to
39
+ * retrieve the line and character of a given text position index.
40
+ */
41
+ export function computeLineStartsMap(text: string): number[] {
42
+ const result: number[] = [0];
43
+ let pos = 0;
44
+ while (pos < text.length) {
45
+ const char = text.charCodeAt(pos++);
46
+ // Handles the "CRLF" line break. In that case we peek the character
47
+ // after the "CR" and check if it is a line feed.
48
+ if (char === CR_CHAR) {
49
+ if (text.charCodeAt(pos) === LF_CHAR) {
50
+ pos++;
51
+ }
52
+ result.push(pos);
53
+ } else if (char === LF_CHAR || char === LINE_SEP_CHAR || char === PARAGRAPH_CHAR) {
54
+ result.push(pos);
55
+ }
56
+ }
57
+ result.push(pos);
58
+ return result;
59
+ }
60
+
61
+ /** Finds the closest line start for the given position. */
62
+ function findClosestLineStartPosition<T>(
63
+ linesMap: T[],
64
+ position: T,
65
+ low = 0,
66
+ high = linesMap.length - 1,
67
+ ) {
68
+ while (low <= high) {
69
+ const pivotIndex = Math.floor((low + high) / 2);
70
+ const pivotEl = linesMap[pivotIndex];
71
+
72
+ if (pivotEl === position) {
73
+ return pivotIndex;
74
+ } else if (position > pivotEl) {
75
+ low = pivotIndex + 1;
76
+ } else {
77
+ high = pivotIndex - 1;
78
+ }
79
+ }
80
+
81
+ // In case there was no exact match, return the closest "lower" line index. We also
82
+ // subtract the index by one because want the index of the previous line start.
83
+ return low - 1;
84
+ }