Alan Agius 745670fa6a feat(@schematics/angular): remove dependency on tsickle (#15603)
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.
2019-09-18 14:50:29 +01:00

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;
};
}