Alan Agius a042290726 fix(@schematics/angular): update to tslib 2.0.0
TypeScript 3.9 requires tslib 2.0.0, with this change we;
- Update tslib existing and new workspaces to use tslib 2.0.0
- Update new and existing libraries to use tslib 2.0.0 as a direct depedency.

Tslib version is bound to the TypeScript version used to compile the library. Thus, we shouldn't list `tslib` as a `peerDependencies`. This is because, a user can install libraries which have been compiled with older versions of TypeScript and thus require multiple `tslib` versions to be installed.

Closes: #17753

Reference: TOOL-1374
2020-05-20 11:25:31 +01:00

43 lines
1.3 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 { join, normalize } from '@angular-devkit/core';
import { Rule } from '@angular-devkit/schematics';
import { NodeDependencyType, addPackageJsonDependency, removePackageJsonDependency } from '../../utility/dependencies';
import { getWorkspace } from '../../utility/workspace';
import { ProjectType } from '../../utility/workspace-models';
export default function (): Rule {
return async host => {
const workspace = await getWorkspace(host);
for (const [, project] of workspace.projects) {
if (project.extensions.projectType !== ProjectType.Library) {
// Only interested in library projects
continue;
}
const packageJsonPath = join(normalize(project.root), 'package.json');
if (!host.exists(packageJsonPath)) {
continue;
}
// Remove tslib from any type of dependency
removePackageJsonDependency(host, 'tslib', packageJsonPath);
// Add tslib as a direct dependency
addPackageJsonDependency(host, {
name: 'tslib',
version: '^2.0.0',
type: NodeDependencyType.Default,
}, packageJsonPath);
}
};
}