From 08fa6a604a8b1e9ff68005c8a5f4af6970e0549d Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Tue, 18 Jan 2022 00:08:58 +0100 Subject: [PATCH] bump typescript to 4.5 Signed-off-by: Patrik Oldsberg --- .changeset/clever-olives-shake.md | 40 ++++++++++++++++++ .changeset/stupid-baboons-hug.md | 42 +++++++++++++++++++ package.json | 2 +- packages/cli/package.json | 1 - .../templates/default-app/package.json.hbs | 3 +- tsconfig.json | 3 +- yarn.lock | 15 +++---- 7 files changed, 92 insertions(+), 14 deletions(-) create mode 100644 .changeset/clever-olives-shake.md create mode 100644 .changeset/stupid-baboons-hug.md diff --git a/.changeset/clever-olives-shake.md b/.changeset/clever-olives-shake.md new file mode 100644 index 0000000000..cc4aae4c3e --- /dev/null +++ b/.changeset/clever-olives-shake.md @@ -0,0 +1,40 @@ +--- +'@backstage/cli': minor +--- + +Removed the `typescript` dependency from the Backstage CLI in order to decouple the TypeScript version in Backstage projects. To keep using a specific TypeScript version, be sure to add an explicit dependency in your root `package.json`: + +```json + "dependencies": { + ... + "typescript": "~4.5.4", + } +``` + +We recommend using a `~` version range since TypeScript releases do not adhere to semver. + +It may be the case that you end up with errors if upgrade the TypeScript version. This is because there was a change to TypeScript not long ago that defaulted the type of errors caught in `catch` blocks to `unknown`. You can work around this by adding `"useUnknownInCatchVariables": false` to the `"compilerOptions"` in your `tsconfig.json`: + +```json + "compilerOptions": { + ... + "useUnknownInCatchVariables": false + } +``` + +Another option is to use the utilities from `@backstage/errors` to assert the type of errors caught in `catch` blocks: + +```ts +import { assertError, isError } from '@backstage/errors'; + +try { + ... +} catch (error) { + assertError(error); + ... + // OR + if (isError(error)) { + ... + } +} +``` diff --git a/.changeset/stupid-baboons-hug.md b/.changeset/stupid-baboons-hug.md new file mode 100644 index 0000000000..bd9afd2552 --- /dev/null +++ b/.changeset/stupid-baboons-hug.md @@ -0,0 +1,42 @@ +--- +'@backstage/create-app': patch +--- + +The app template has been updated to add an explicit dependency on `typescript` in the root `package.json`. This is because it was removed as a dependency of `@backstage/cli` in order to decouple the TypeScript versioning in Backstage projects. + +To apply this change in an existing app, add a `typescript` dependency to your `package.json` in the project root: + +```json + "dependencies": { + ... + "typescript": "~4.5.4", + } +``` + +We recommend using a `~` version range since TypeScript releases do not adhere to semver. + +It may be the case that you end up with errors if upgrade the TypeScript version. This is because there was a change to TypeScript not long ago that defaulted the type of errors caught in `catch` blocks to `unknown`. You can work around this by adding `"useUnknownInCatchVariables": false` to the `"compilerOptions"` in your `tsconfig.json`: + +```json + "compilerOptions": { + ... + "useUnknownInCatchVariables": false + } +``` + +Another option is to use the utilities from `@backstage/errors` to assert the type of errors caught in `catch` blocks: + +```ts +import { assertError, isError } from '@backstage/errors'; + +try { + ... +} catch (error) { + assertError(error); + ... + // OR + if (isError(error)) { + ... + } +} +``` diff --git a/package.json b/package.json index fe5876dd97..74a6c8bd50 100644 --- a/package.json +++ b/package.json @@ -79,7 +79,7 @@ "prettier": "^2.2.1", "shx": "^0.3.2", "ts-node": "^10.4.0", - "typescript": "~4.3.5", + "typescript": "~4.5.4", "yarn-lock-check": "^1.0.5" }, "prettier": "@spotify/prettier-config", diff --git a/packages/cli/package.json b/packages/cli/package.json index 95cb4f70de..a3f49028b3 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -105,7 +105,6 @@ "sucrase": "^3.20.2", "tar": "^6.1.2", "terser-webpack-plugin": "^5.1.3", - "typescript": "^4.0.3", "util": "^0.12.3", "webpack": "^5.48.0", "webpack-dev-server": "4.3.1", diff --git a/packages/create-app/templates/default-app/package.json.hbs b/packages/create-app/templates/default-app/package.json.hbs index a73045c050..e7c39add25 100644 --- a/packages/create-app/templates/default-app/package.json.hbs +++ b/packages/create-app/templates/default-app/package.json.hbs @@ -34,7 +34,8 @@ "@spotify/prettier-config": "^12.0.0", "concurrently": "^6.0.0", "lerna": "^4.0.0", - "prettier": "^2.3.2" + "prettier": "^2.3.2", + "typescript": "~4.5.4" }, "prettier": "@spotify/prettier-config", "lint-staged": { diff --git a/tsconfig.json b/tsconfig.json index d6cb6f4c96..789743363d 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -8,6 +8,7 @@ ], "compilerOptions": { "outDir": "dist-types", - "rootDir": "." + "rootDir": ".", + "useUnknownInCatchVariables": false } } diff --git a/yarn.lock b/yarn.lock index c8b506927b..a2ba33360a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -27648,21 +27648,16 @@ typescript-json-schema@^0.52.0: typescript "~4.4.4" yargs "^17.1.1" -typescript@^4.0.3, typescript@~4.5.2: - version "4.5.4" - resolved "https://registry.npmjs.org/typescript/-/typescript-4.5.4.tgz#a17d3a0263bf5c8723b9c52f43c5084edf13c2e8" - integrity sha512-VgYs2A2QIRuGphtzFV7aQJduJ2gyfTljngLzjpfW9FoYZF6xuw1W0vW9ghCKLfcWrCFxK81CSGRAvS1pn4fIUg== - -typescript@~4.3.5: - version "4.3.5" - resolved "https://registry.npmjs.org/typescript/-/typescript-4.3.5.tgz#4d1c37cc16e893973c45a06886b7113234f119f4" - integrity sha512-DqQgihaQ9cUrskJo9kIyW/+g0Vxsk8cDtZ52a3NGh0YNTfpUSArXSohyUGnvbPazEPLu398C0UxmKSOrPumUzA== - typescript@~4.4.4: version "4.4.4" resolved "https://registry.npmjs.org/typescript/-/typescript-4.4.4.tgz#2cd01a1a1f160704d3101fd5a58ff0f9fcb8030c" integrity sha512-DqGhF5IKoBl8WNf8C1gu8q0xZSInh9j1kJJMqT3a94w1JzVaBU4EXOSMrz9yDqMT0xt3selp83fuFMQ0uzv6qA== +typescript@~4.5.2, typescript@~4.5.4: + version "4.5.4" + resolved "https://registry.npmjs.org/typescript/-/typescript-4.5.4.tgz#a17d3a0263bf5c8723b9c52f43c5084edf13c2e8" + integrity sha512-VgYs2A2QIRuGphtzFV7aQJduJ2gyfTljngLzjpfW9FoYZF6xuw1W0vW9ghCKLfcWrCFxK81CSGRAvS1pn4fIUg== + ua-parser-js@^0.7.18: version "0.7.28" resolved "https://registry.npmjs.org/ua-parser-js/-/ua-parser-js-0.7.28.tgz#8ba04e653f35ce210239c64661685bf9121dec31"