[6a3a178] | 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 | */
|
---|
| 9 | Object.defineProperty(exports, "__esModule", { value: true });
|
---|
| 10 | const core_1 = require("@angular-devkit/core");
|
---|
| 11 | const json_file_1 = require("../../utility/json-file");
|
---|
| 12 | function* visitExtendedJsonFiles(directory) {
|
---|
| 13 | for (const path of directory.subfiles) {
|
---|
| 14 | if (!path.endsWith('.json')) {
|
---|
| 15 | continue;
|
---|
| 16 | }
|
---|
| 17 | const entry = directory.file(path);
|
---|
| 18 | const content = entry === null || entry === void 0 ? void 0 : entry.content.toString();
|
---|
| 19 | if (content === null || content === void 0 ? void 0 : content.includes('tsconfig.base.json')) {
|
---|
| 20 | yield core_1.join(directory.path, path);
|
---|
| 21 | }
|
---|
| 22 | }
|
---|
| 23 | for (const path of directory.subdirs) {
|
---|
| 24 | if (path === 'node_modules' || path.startsWith('.')) {
|
---|
| 25 | continue;
|
---|
| 26 | }
|
---|
| 27 | yield* visitExtendedJsonFiles(directory.dir(path));
|
---|
| 28 | }
|
---|
| 29 | }
|
---|
| 30 | function default_1() {
|
---|
| 31 | return (host, context) => {
|
---|
| 32 | const logger = context.logger;
|
---|
| 33 | const tsConfigExists = host.exists('tsconfig.json');
|
---|
| 34 | if (tsConfigExists) {
|
---|
| 35 | const files = new json_file_1.JSONFile(host, 'tsconfig.json').get(['files']);
|
---|
| 36 | if (!(Array.isArray(files) && files.length === 0)) {
|
---|
| 37 | logger.info('Migration has already been executed.');
|
---|
| 38 | return;
|
---|
| 39 | }
|
---|
| 40 | }
|
---|
| 41 | if (host.exists('tsconfig.base.json')) {
|
---|
| 42 | if (tsConfigExists) {
|
---|
| 43 | host.overwrite('tsconfig.json', host.read('tsconfig.base.json') || '');
|
---|
| 44 | host.delete('tsconfig.base.json');
|
---|
| 45 | }
|
---|
| 46 | else {
|
---|
| 47 | host.rename('tsconfig.base.json', 'tsconfig.json');
|
---|
| 48 | }
|
---|
| 49 | }
|
---|
| 50 | // Iterate over all tsconfig files and change the extends from 'tsconfig.base.json' to 'tsconfig.json'.
|
---|
| 51 | const extendsJsonPath = ['extends'];
|
---|
| 52 | for (const path of visitExtendedJsonFiles(host.root)) {
|
---|
| 53 | try {
|
---|
| 54 | const tsConfigDir = core_1.dirname(core_1.normalize(path));
|
---|
| 55 | const tsConfigJson = new json_file_1.JSONFile(host, path);
|
---|
| 56 | const extendsValue = tsConfigJson.get(extendsJsonPath);
|
---|
| 57 | if (typeof extendsValue === 'string' &&
|
---|
| 58 | '/tsconfig.base.json' === core_1.resolve(tsConfigDir, core_1.normalize(extendsValue))) {
|
---|
| 59 | // tsconfig extends the workspace tsconfig path.
|
---|
| 60 | tsConfigJson.modify(extendsJsonPath, extendsValue.replace('tsconfig.base.json', 'tsconfig.json'));
|
---|
| 61 | }
|
---|
| 62 | }
|
---|
| 63 | catch (error) {
|
---|
| 64 | logger.warn(`${error.message || error}\n` +
|
---|
| 65 | 'If this is a TypeScript configuration file you will need to update the "extends" value manually.');
|
---|
| 66 | continue;
|
---|
| 67 | }
|
---|
| 68 | }
|
---|
| 69 | };
|
---|
| 70 | }
|
---|
| 71 | exports.default = default_1;
|
---|