|
| 1 | +# tslib Direct Dependency Migration |
| 2 | + |
| 3 | +## What does this migration do? |
| 4 | + |
| 5 | +If you have any libraries within your workspace, this migration will convert `tslib` peer dependencies to direct dependencies for the libraries. |
| 6 | +TypeScript uses the `tslib` package to provide common helper functions used in compiled TypeScript code. |
| 7 | +The `tslib` version is also updated to `2.0.0` to support TypeScript 3.9. |
| 8 | + |
| 9 | +Before: |
| 10 | +```json |
| 11 | +{ |
| 12 | + "name": "my-lib", |
| 13 | + "version": "0.0.1", |
| 14 | + "peerDependencies": { |
| 15 | + "@angular/common": "^9.0.0", |
| 16 | + "@angular/core": "^9.0.0", |
| 17 | + "tslib": "^1.12.0" |
| 18 | + } |
| 19 | +} |
| 20 | +``` |
| 21 | + |
| 22 | +After: |
| 23 | +```json |
| 24 | +{ |
| 25 | + "name": "my-lib", |
| 26 | + "version": "0.0.1", |
| 27 | + "peerDependencies": { |
| 28 | + "@angular/common": "^9.0.0", |
| 29 | + "@angular/core": "^9.0.0" |
| 30 | + }, |
| 31 | + "dependencies": { |
| 32 | + "tslib": "^2.0.0" |
| 33 | + } |
| 34 | +} |
| 35 | +``` |
| 36 | + |
| 37 | +## Why is this migration necessary? |
| 38 | + |
| 39 | +The [`tslib`](https://github.com/Microsoft/tslib) is a runtime library for Typescript. |
| 40 | +The version of this library is bound to the version of the TypeScript compiler used to compile a library. |
| 41 | +Peer dependencies do not accurately represent this relationship between the runtime and the compiler. |
| 42 | +If `tslib` remained declared as a library peer dependency, it would be possible for some Angular workspaces to get into a state where the workspace could not satisfy `tslib` peer dependency requirements for multiple libraries, resulting in build-time or run-time errors. |
| 43 | + |
| 44 | +As of TypeScript 3.9 (used by Angular v10), `tslib` version of 2.x is required to build new applications. |
| 45 | +However, older libraries built with previous version of TypeScript and already published to npm might need `tslib` 1.x. |
| 46 | +This migration makes it possible for code depending on incompatible versions of the `tslib` runtime library to remain interoperable. |
| 47 | + |
| 48 | + |
| 49 | +## Do I still need `tslib` as a dependency in my workspace `package.json`? |
| 50 | + |
| 51 | +Yes. |
| 52 | +The `tslib` dependency declared in the `package.json` file of the workspace is used to build applications within this workspace, as well as run unit tests for workspace libraries, and is required. |
0 commit comments