Alan Agius c9f531d703 feat(@schematics/angular): add migration to replace deprecated --prod
With this change we add migration to replace the deprecated `--prod` with `--configuration production` in the scripts section of the package.json.

Closes #21036
2021-06-16 08:00:33 -04:00

31 lines
895 B
TypeScript

/**
* @license
* Copyright Google LLC 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 { Rule } from '@angular-devkit/schematics';
import { JSONFile } from '../../utility/json-file';
export default function (): Rule {
return (tree) => {
const file = new JSONFile(tree, 'package.json');
const scripts = file.get(['scripts']);
if (!scripts || typeof scripts !== 'object') {
return;
}
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const updatedScripts = Object.entries(scripts!).map(([key, value]) => [
key,
typeof value === 'string'
? value.replace(/ --prod(?!\w)/g, ' --configuration production')
: value,
]);
file.modify(['scripts'], Object.fromEntries(updatedScripts));
};
}