mirror of
https://github.com/angular/angular-cli.git
synced 2025-05-17 11:03:53 +08:00
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
59 lines
1.8 KiB
TypeScript
59 lines
1.8 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 { EmptyTree } from '@angular-devkit/schematics';
|
|
import { SchematicTestRunner, UnitTestTree } from '@angular-devkit/schematics/testing';
|
|
import { ProjectType, WorkspaceSchema } from '../../utility/workspace-models';
|
|
|
|
function createWorkSpaceConfig(tree: UnitTestTree) {
|
|
const angularConfig: WorkspaceSchema = {
|
|
version: 1,
|
|
projects: {
|
|
lib: {
|
|
root: '/project/lib',
|
|
sourceRoot: '/project/lib/src',
|
|
projectType: ProjectType.Library,
|
|
prefix: 'lib',
|
|
architect: {},
|
|
},
|
|
},
|
|
};
|
|
|
|
tree.create('/angular.json', JSON.stringify(angularConfig, undefined, 2));
|
|
}
|
|
|
|
describe(`Migration to add tslib as a direct dependency in library projects`, () => {
|
|
const schematicName = 'update-libraries-tslib';
|
|
|
|
const schematicRunner = new SchematicTestRunner(
|
|
'migrations',
|
|
require.resolve('../migration-collection.json'),
|
|
);
|
|
|
|
let tree: UnitTestTree;
|
|
beforeEach(() => {
|
|
tree = new UnitTestTree(new EmptyTree());
|
|
createWorkSpaceConfig(tree);
|
|
|
|
tree.create('/project/lib/package.json', JSON.stringify({
|
|
peerDependencies: {
|
|
'@angular/common': '^9.0.0',
|
|
'@angular/core': '^9.0.0',
|
|
'tslib': '1.0.0',
|
|
},
|
|
}, undefined, 2));
|
|
});
|
|
|
|
it(`should update tslib to version 2 as a direct dependency`, async () => {
|
|
const newTree = await schematicRunner.runSchematicAsync(schematicName, {}, tree).toPromise();
|
|
const { peerDependencies, dependencies } = JSON.parse(newTree.readContent('/project/lib/package.json'));
|
|
expect(peerDependencies['tslib']).toBeUndefined();
|
|
expect(dependencies['tslib']).toBe('^2.0.0');
|
|
});
|
|
});
|