Alan Agius 28f87cb312 refactor(@angular/cli): remove deprecated typescriptMismatch
BREAKING CHANGE:
Removed deprecated `typescriptMismatch` warning option. Users will be migrated off this option automatically. Users wishing to disable TypeScript version checks should use the Angular compiler option `disableTypeScriptVersionCheck`, see https://angular.io/guide/angular-compiler-options#disabletypescriptversioncheck for more information.
2020-05-07 10:37:48 -07:00

123 lines
3.2 KiB
TypeScript

/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import { JsonObject, JsonValue, isJsonObject, workspaces } from '@angular-devkit/core';
import { Rule } from '@angular-devkit/schematics';
import { updateWorkspace } from '../../utility/workspace';
import { Builders, ProjectType } from '../../utility/workspace-models';
export default function (): Rule {
return updateWorkspace(workspace => {
// Remove deprecated CLI root level options
removeDeprecatedCLIOptions(workspace.extensions);
for (const [, project] of workspace.projects) {
// Project level
removeDeprecatedCLIOptions(project.extensions);
if (project.extensions.projectType !== ProjectType.Application) {
// Only interested in application projects since these changes only effects application builders
continue;
}
for (const [, target] of project.targets) {
// Only interested in Angular Devkit builders
if (!target?.builder.startsWith('@angular-devkit/build-angular')) {
continue;
}
let extraOptionsToRemove = {};
if (target.builder === Builders.Server) {
extraOptionsToRemove = {
vendorChunk: undefined,
commonChunk: undefined,
};
}
// Check options
if (target.options) {
target.options = {
...updateVendorSourceMap(target.options),
evalSourceMap: undefined,
skipAppShell: undefined,
profile: undefined,
...extraOptionsToRemove,
};
}
// Go through each configuration entry
if (!target.configurations) {
continue;
}
for (const configurationName of Object.keys(target.configurations)) {
target.configurations[configurationName] = {
...updateVendorSourceMap(target.configurations[configurationName]),
evalSourceMap: undefined,
skipAppShell: undefined,
profile: undefined,
...extraOptionsToRemove,
};
}
}
}
});
}
type TargetOptions = workspaces.TargetDefinition['options'];
function updateVendorSourceMap(options: TargetOptions): TargetOptions {
if (!options) {
return {};
}
const { vendorSourceMap: vendor, sourceMap = true } = options;
if (vendor === undefined) {
return options;
}
if (sourceMap === true) {
return {
...options,
sourceMap: {
styles: true,
scripts: true,
vendor,
},
vendorSourceMap: undefined,
};
}
if (typeof sourceMap === 'object') {
return {
...options,
sourceMap: {
...sourceMap,
vendor,
},
vendorSourceMap: undefined,
};
}
return {
...options,
vendorSourceMap: undefined,
};
}
function removeDeprecatedCLIOptions(extensions: Record<string, JsonValue | undefined>) {
const cliOptions = extensions?.cli;
if (cliOptions && isJsonObject(cliOptions) && isJsonObject(cliOptions.warnings)) {
(cliOptions.warnings as Partial<JsonObject>) = {
...cliOptions.warnings,
typescriptMismatch: undefined,
};
}
}