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/relative-link-resolution", ["require", "exports", "@angular-devkit/schematics", "path", "@angular/core/schematics/utils/project_tsconfig_paths", "@angular/core/schematics/utils/typescript/compiler_host", "@angular/core/schematics/migrations/relative-link-resolution/collector", "@angular/core/schematics/migrations/relative-link-resolution/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 project_tsconfig_paths_1 = require("@angular/core/schematics/utils/project_tsconfig_paths");
|
---|
22 | const compiler_host_1 = require("@angular/core/schematics/utils/typescript/compiler_host");
|
---|
23 | const collector_1 = require("@angular/core/schematics/migrations/relative-link-resolution/collector");
|
---|
24 | const transform_1 = require("@angular/core/schematics/migrations/relative-link-resolution/transform");
|
---|
25 | /** Entry point for the v11 "relativeLinkResolution RouterModule options" schematic. */
|
---|
26 | function default_1() {
|
---|
27 | return (tree) => {
|
---|
28 | const { buildPaths, testPaths } = project_tsconfig_paths_1.getProjectTsConfigPaths(tree);
|
---|
29 | const basePath = process.cwd();
|
---|
30 | if (!buildPaths.length && !testPaths.length) {
|
---|
31 | throw new schematics_1.SchematicsException('Could not find any tsconfig file. Cannot update the "relativeLinkResolution" option for RouterModule');
|
---|
32 | }
|
---|
33 | for (const tsconfigPath of [...buildPaths, ...testPaths]) {
|
---|
34 | runRelativeLinkResolutionMigration(tree, tsconfigPath, basePath);
|
---|
35 | }
|
---|
36 | };
|
---|
37 | }
|
---|
38 | exports.default = default_1;
|
---|
39 | function runRelativeLinkResolutionMigration(tree, tsconfigPath, basePath) {
|
---|
40 | const { program } = compiler_host_1.createMigrationProgram(tree, tsconfigPath, basePath);
|
---|
41 | const typeChecker = program.getTypeChecker();
|
---|
42 | const relativeLinkResolutionCollector = new collector_1.RelativeLinkResolutionCollector(typeChecker);
|
---|
43 | const sourceFiles = program.getSourceFiles().filter(sourceFile => compiler_host_1.canMigrateFile(basePath, sourceFile, program));
|
---|
44 | // Analyze source files by detecting all modules.
|
---|
45 | sourceFiles.forEach(sourceFile => relativeLinkResolutionCollector.visitNode(sourceFile));
|
---|
46 | const { forRootCalls, extraOptionsLiterals } = relativeLinkResolutionCollector;
|
---|
47 | const transformer = new transform_1.RelativeLinkResolutionTransform(getUpdateRecorder);
|
---|
48 | const updateRecorders = new Map();
|
---|
49 | transformer.migrateRouterModuleForRootCalls(forRootCalls);
|
---|
50 | transformer.migrateObjectLiterals(extraOptionsLiterals);
|
---|
51 | // Walk through each update recorder and commit the update. We need to commit the
|
---|
52 | // updates in batches per source file as there can be only one recorder per source
|
---|
53 | // file in order to avoid shift character offsets.
|
---|
54 | updateRecorders.forEach(recorder => recorder.commitUpdate());
|
---|
55 | /** Gets the update recorder for the specified source file. */
|
---|
56 | function getUpdateRecorder(sourceFile) {
|
---|
57 | if (updateRecorders.has(sourceFile)) {
|
---|
58 | return updateRecorders.get(sourceFile);
|
---|
59 | }
|
---|
60 | const treeRecorder = tree.beginUpdate(path_1.relative(basePath, sourceFile.fileName));
|
---|
61 | const recorder = {
|
---|
62 | updateNode(node, newText) {
|
---|
63 | treeRecorder.remove(node.getStart(), node.getWidth());
|
---|
64 | treeRecorder.insertRight(node.getStart(), newText);
|
---|
65 | },
|
---|
66 | commitUpdate() {
|
---|
67 | tree.commitUpdate(treeRecorder);
|
---|
68 | }
|
---|
69 | };
|
---|
70 | updateRecorders.set(sourceFile, recorder);
|
---|
71 | return recorder;
|
---|
72 | }
|
---|
73 | }
|
---|
74 | });
|
---|
75 | //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi8uLi8uLi8uLi9wYWNrYWdlcy9jb3JlL3NjaGVtYXRpY3MvbWlncmF0aW9ucy9yZWxhdGl2ZS1saW5rLXJlc29sdXRpb24vaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUE7Ozs7OztHQU1HOzs7Ozs7Ozs7Ozs7SUFFSCwyREFBMkU7SUFDM0UsK0JBQThCO0lBRTlCLGtHQUEyRTtJQUMzRSwyRkFBNEY7SUFDNUYsc0dBQTREO0lBQzVELHNHQUE0RDtJQUc1RCx1RkFBdUY7SUFDdkY7UUFDRSxPQUFPLENBQUMsSUFBVSxFQUFFLEVBQUU7WUFDcEIsTUFBTSxFQUFDLFVBQVUsRUFBRSxTQUFTLEVBQUMsR0FBRyxnREFBdUIsQ0FBQyxJQUFJLENBQUMsQ0FBQztZQUM5RCxNQUFNLFFBQVEsR0FBRyxPQUFPLENBQUMsR0FBRyxFQUFFLENBQUM7WUFFL0IsSUFBSSxDQUFDLFVBQVUsQ0FBQyxNQUFNLElBQUksQ0FBQyxTQUFTLENBQUMsTUFBTSxFQUFFO2dCQUMzQyxNQUFNLElBQUksZ0NBQW1CLENBQ3pCLHNHQUFzRyxDQUFDLENBQUM7YUFDN0c7WUFFRCxLQUFLLE1BQU0sWUFBWSxJQUFJLENBQUMsR0FBRyxVQUFVLEVBQUUsR0FBRyxTQUFTLENBQUMsRUFBRTtnQkFDeEQsa0NBQWtDLENBQUMsSUFBSSxFQUFFLFlBQVksRUFBRSxRQUFRLENBQUMsQ0FBQzthQUNsRTtRQUNILENBQUMsQ0FBQztJQUNKLENBQUM7SUFkRCw0QkFjQztJQUV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