source: trip-planner-front/node_modules/@schematics/angular/migrations/update-9/ivy-libraries.js@ 6a3a178

Last change on this file since 6a3a178 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 3.2 KB
Line 
1"use strict";
2/**
3 * @license
4 * Copyright Google LLC All Rights Reserved.
5 *
6 * Use of this source code is governed by an MIT-style license that can be
7 * found in the LICENSE file at https://angular.io/license
8 */
9Object.defineProperty(exports, "__esModule", { value: true });
10exports.updateLibraries = void 0;
11const core_1 = require("@angular-devkit/core");
12const schematics_1 = require("@angular-devkit/schematics");
13const json_file_1 = require("../../utility/json-file");
14const workspace_1 = require("../../utility/workspace");
15const workspace_models_1 = require("../../utility/workspace-models");
16/**
17 * Updates a pre version 9 library to version 9 Ivy library.
18 *
19 * The main things that this migrations does are:
20 * - Creates a production configuration for VE compilations.
21 * - Create a prod tsconfig for which disables Ivy and enables VE compilations.
22 */
23function updateLibraries() {
24 return workspace_1.updateWorkspace((workspace) => {
25 const followupRules = [];
26 for (const [, project] of workspace.projects) {
27 if (typeof project.root !== 'string') {
28 continue;
29 }
30 for (const [, target] of project.targets) {
31 if (target.builder !== workspace_models_1.Builders.DeprecatedNgPackagr) {
32 continue;
33 }
34 const tsConfig = core_1.join(core_1.normalize(project.root), 'tsconfig.lib.prod.json');
35 if (!target.configurations || !target.configurations.production) {
36 // Production configuration does not exist
37 target.configurations = { ...target.configurations, production: { tsConfig } };
38 followupRules.push((tree) => createTsConfig(tree, tsConfig));
39 continue;
40 }
41 const existingTsconfig = target.configurations.production.tsConfig;
42 if (!existingTsconfig || typeof existingTsconfig !== 'string') {
43 // Production configuration TS configuration does not exist or malformed
44 target.configurations.production.tsConfig = tsConfig;
45 followupRules.push((tree) => createTsConfig(tree, tsConfig));
46 continue;
47 }
48 followupRules.push(updateTsConfig(existingTsconfig));
49 }
50 }
51 return schematics_1.chain(followupRules);
52 });
53}
54exports.updateLibraries = updateLibraries;
55function createTsConfig(tree, tsConfigPath) {
56 const tsConfigContent = {
57 extends: './tsconfig.lib.json',
58 angularCompilerOptions: {
59 enableIvy: false,
60 },
61 };
62 if (!tree.exists(tsConfigPath)) {
63 tree.create(tsConfigPath, JSON.stringify(tsConfigContent, undefined, 2));
64 }
65}
66function updateTsConfig(tsConfigPath) {
67 return (tree, { logger }) => {
68 let json;
69 try {
70 json = new json_file_1.JSONFile(tree, tsConfigPath);
71 }
72 catch {
73 logger.warn(`Cannot find file: ${tsConfigPath}`);
74 return;
75 }
76 const enableIvyPath = ['angularCompilerOptions', 'enableIvy'];
77 if (json.get(enableIvyPath) === false) {
78 return;
79 }
80 json.modify(enableIvyPath, false);
81 };
82}
Note: See TracBrowser for help on using the repository browser.