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 | (function (factory) {
|
---|
9 | if (typeof module === "object" && typeof module.exports === "object") {
|
---|
10 | var v = factory(require, exports);
|
---|
11 | if (v !== undefined) module.exports = v;
|
---|
12 | }
|
---|
13 | else if (typeof define === "function" && define.amd) {
|
---|
14 | define("@angular/core/schematics/migrations/undecorated-classes-with-decorated-fields", ["require", "exports", "@angular-devkit/schematics", "path", "typescript", "@angular/core/schematics/utils/project_tsconfig_paths", "@angular/core/schematics/utils/typescript/compiler_host", "@angular/core/schematics/migrations/undecorated-classes-with-decorated-fields/transform"], factory);
|
---|
15 | }
|
---|
16 | })(function (require, exports) {
|
---|
17 | "use strict";
|
---|
18 | Object.defineProperty(exports, "__esModule", { value: true });
|
---|
19 | const schematics_1 = require("@angular-devkit/schematics");
|
---|
20 | const path_1 = require("path");
|
---|
21 | const ts = require("typescript");
|
---|
22 | const project_tsconfig_paths_1 = require("@angular/core/schematics/utils/project_tsconfig_paths");
|
---|
23 | const compiler_host_1 = require("@angular/core/schematics/utils/typescript/compiler_host");
|
---|
24 | const transform_1 = require("@angular/core/schematics/migrations/undecorated-classes-with-decorated-fields/transform");
|
---|
25 | /**
|
---|
26 | * Migration that adds an Angular decorator to classes that have Angular field decorators.
|
---|
27 | * https://hackmd.io/vuQfavzfRG6KUCtU7oK_EA
|
---|
28 | */
|
---|
29 | function default_1() {
|
---|
30 | return (tree, ctx) => {
|
---|
31 | const { buildPaths, testPaths } = project_tsconfig_paths_1.getProjectTsConfigPaths(tree);
|
---|
32 | const basePath = process.cwd();
|
---|
33 | const allPaths = [...buildPaths, ...testPaths];
|
---|
34 | const failures = [];
|
---|
35 | if (!allPaths.length) {
|
---|
36 | throw new schematics_1.SchematicsException('Could not find any tsconfig file. Cannot add an Angular decorator to undecorated classes.');
|
---|
37 | }
|
---|
38 | for (const tsconfigPath of allPaths) {
|
---|
39 | failures.push(...runUndecoratedClassesMigration(tree, tsconfigPath, basePath));
|
---|
40 | }
|
---|
41 | if (failures.length) {
|
---|
42 | ctx.logger.info('Could not migrate all undecorated classes that use Angular features.');
|
---|
43 | ctx.logger.info('Please manually fix the following failures:');
|
---|
44 | failures.forEach(message => ctx.logger.warn(`⮑ ${message}`));
|
---|
45 | }
|
---|
46 | };
|
---|
47 | }
|
---|
48 | exports.default = default_1;
|
---|
49 | function runUndecoratedClassesMigration(tree, tsconfigPath, basePath) {
|
---|
50 | const failures = [];
|
---|
51 | const { program } = compiler_host_1.createMigrationProgram(tree, tsconfigPath, basePath);
|
---|
52 | const typeChecker = program.getTypeChecker();
|
---|
53 | const sourceFiles = program.getSourceFiles().filter(sourceFile => compiler_host_1.canMigrateFile(basePath, sourceFile, program));
|
---|
54 | const updateRecorders = new Map();
|
---|
55 | const transform = new transform_1.UndecoratedClassesWithDecoratedFieldsTransform(typeChecker, getUpdateRecorder);
|
---|
56 | // Migrate all source files in the project.
|
---|
57 | transform.migrate(sourceFiles).forEach(({ node, message }) => {
|
---|
58 | const nodeSourceFile = node.getSourceFile();
|
---|
59 | const relativeFilePath = path_1.relative(basePath, nodeSourceFile.fileName);
|
---|
60 | const { line, character } = ts.getLineAndCharacterOfPosition(node.getSourceFile(), node.getStart());
|
---|
61 | failures.push(`${relativeFilePath}@${line + 1}:${character + 1}: ${message}`);
|
---|
62 | });
|
---|
63 | // Record the changes collected in the import manager.
|
---|
64 | transform.recordChanges();
|
---|
65 | // Walk through each update recorder and commit the update. We need to commit the
|
---|
66 | // updates in batches per source file as there can be only one recorder per source
|
---|
67 | // file in order to avoid shifted character offsets.
|
---|
68 | updateRecorders.forEach(recorder => recorder.commitUpdate());
|
---|
69 | return failures;
|
---|
70 | /** Gets the update recorder for the specified source file. */
|
---|
71 | function getUpdateRecorder(sourceFile) {
|
---|
72 | if (updateRecorders.has(sourceFile)) {
|
---|
73 | return updateRecorders.get(sourceFile);
|
---|
74 | }
|
---|
75 | const treeRecorder = tree.beginUpdate(path_1.relative(basePath, sourceFile.fileName));
|
---|
76 | const recorder = {
|
---|
77 | addClassTodo(node, message) {
|
---|
78 | treeRecorder.insertRight(node.getStart(), `// TODO: ${message}\n`);
|
---|
79 | },
|
---|
80 | addClassDecorator(node, text) {
|
---|
81 | // New imports should be inserted at the left while decorators should be inserted
|
---|
82 | // at the right in order to ensure that imports are inserted before the decorator
|
---|
83 | // if the start position of import and decorator is the source file start.
|
---|
84 | treeRecorder.insertRight(node.getStart(), `${text}\n`);
|
---|
85 | },
|
---|
86 | addNewImport(start, importText) {
|
---|
87 | // New imports should be inserted at the left while decorators should be inserted
|
---|
88 | // at the right in order to ensure that imports are inserted before the decorator
|
---|
89 | // if the start position of import and decorator is the source file start.
|
---|
90 | treeRecorder.insertLeft(start, importText);
|
---|
91 | },
|
---|
92 | updateExistingImport(namedBindings, newNamedBindings) {
|
---|
93 | treeRecorder.remove(namedBindings.getStart(), namedBindings.getWidth());
|
---|
94 | treeRecorder.insertRight(namedBindings.getStart(), newNamedBindings);
|
---|
95 | },
|
---|
96 | commitUpdate() {
|
---|
97 | tree.commitUpdate(treeRecorder);
|
---|
98 | }
|
---|
99 | };
|
---|
100 | updateRecorders.set(sourceFile, recorder);
|
---|
101 | return recorder;
|
---|
102 | }
|
---|
103 | }
|
---|
104 | });
|
---|
105 | //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi8uLi8uLi8uLi9wYWNrYWdlcy9jb3JlL3NjaGVtYXRpY3MvbWlncmF0aW9ucy91bmRlY29yYXRlZC1jbGFzc2VzLXdpdGgtZGVjb3JhdGVkLWZpZWxkcy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQTs7Ozs7O0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