mirror of
https://github.com/angular/angular-cli.git
synced 2025-05-22 15:02:11 +08:00
With this change we remove the requirement to add tsickle as a dependency when having a workspace library. Since the CTOR downlevel transformer which was previously provided via tsickle is now in ng-packagr version 5.5.1+ We migrate existing libraries to remove the need for tsickle.
54 lines
1.9 KiB
TypeScript
54 lines
1.9 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 { JsonParseMode, parseJsonAst } from '@angular-devkit/core';
|
|
import { Rule, Tree } from '@angular-devkit/schematics';
|
|
import { removePackageJsonDependency } from '../../utility/dependencies';
|
|
import { findPropertyInAstObject, removePropertyInAstObject } from '../../utility/json-utils';
|
|
import { Builders } from '../../utility/workspace-models';
|
|
import { getAllOptions, getTargets, getWorkspace } from './utils';
|
|
|
|
/**
|
|
* Remove tsickle from libraries
|
|
*/
|
|
export function removeTsickle(): Rule {
|
|
return (tree: Tree) => {
|
|
removePackageJsonDependency(tree, 'tsickle');
|
|
|
|
const workspace = getWorkspace(tree);
|
|
|
|
for (const { target } of getTargets(workspace, 'build', Builders.NgPackagr)) {
|
|
for (const options of getAllOptions(target)) {
|
|
const tsConfigOption = findPropertyInAstObject(options, 'tsConfig');
|
|
if (!tsConfigOption || tsConfigOption.kind !== 'string') {
|
|
continue;
|
|
}
|
|
|
|
const tsConfigContent = tree.read(tsConfigOption.value);
|
|
if (!tsConfigContent) {
|
|
continue;
|
|
}
|
|
|
|
const tsConfigAst = parseJsonAst(tsConfigContent.toString(), JsonParseMode.Loose);
|
|
if (!tsConfigAst || tsConfigAst.kind !== 'object') {
|
|
continue;
|
|
}
|
|
|
|
const ngCompilerOptions = findPropertyInAstObject(tsConfigAst, 'angularCompilerOptions');
|
|
if (ngCompilerOptions && ngCompilerOptions.kind === 'object') {
|
|
// remove annotateForClosureCompiler option
|
|
const recorder = tree.beginUpdate(tsConfigOption.value);
|
|
removePropertyInAstObject(recorder, ngCompilerOptions, 'annotateForClosureCompiler');
|
|
tree.commitUpdate(recorder);
|
|
}
|
|
}
|
|
}
|
|
|
|
return tree;
|
|
};
|
|
}
|