Skip to content

Commit

Permalink
V2: Bump minimum supported TypeScript version to 4.9.5 (#1231)
Browse files Browse the repository at this point in the history
  • Loading branch information
timostamm authored Sep 13, 2024
1 parent ab1b7c2 commit ed4b0e5
Show file tree
Hide file tree
Showing 18 changed files with 512 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
.wrangler
node_modules
/packages/*/dist
/packages/typescript-compat/*/dist
/packages/connect-web/conformance/logs/*
packages/connect-web/local.log
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ be more than happy to chat!
- [@connectrpc/connect-express](https://www.npmjs.com/package/@connectrpc/connect-express):
Adds your services to an [Express](https://expressjs.com/) server.

The libraries and the generated code are compatible with ES2017 and TypeScript 4.1.
The libraries and the generated code are compatible with ES2017 and TypeScript 4.9.5.

## Ecosystem

Expand Down
252 changes: 251 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"packages/example",
"packages/connect-migrate",
"packages/connect-conformance",
"packages/connect-cloudflare"
"packages/connect-cloudflare",
"packages/typescript-compat/*"
],
"scripts": {
"all": "turbo run --ui tui build format test conformance bundle-size lint attw license-header",
Expand Down
2 changes: 1 addition & 1 deletion packages/example/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import type {
ConverseRequest,
} from "./gen/eliza_pb.js";
import * as esbuild from "esbuild";
import http2 from "http2";
import * as http2 from "http2";
import { readFileSync } from "fs";
import { stdout } from "process";

Expand Down
47 changes: 47 additions & 0 deletions packages/typescript-compat/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# TypeScript compatibility tests

Each package in this directory tests compatibility with a TypeScript version.

Our compatibility tests use the default settings for `tsconfig.json` that are
generated by running `tsc --init` (with a few minor exceptions). As a result,
for any version we support, we inherently support the default settings
respective to that version of TypeScript.

### Which versions are tested

- the earliest TypeScript version we support
- the latest patch release of all minor versions up to the current release

### Adding a new version

To add a new minor or major version of TypeScript to the tests, copy the directory
with the latest version, and make the following updates:

#### package.json

- Set an appropriate "name" field, for example `"ts5.2.x"`.
- Set the version constraint for the `typescript` dependency, for example `"5.2.x"`.
- Set the version for the `@types/node` dependency. The package uses dist-tags
to tag releases for older TypeScript versions. You have to look up the
corresponding version number on https://www.npmjs.com/package/@types/node?activeTab=versions.

Delete the `node_modules` directory in the package if it exists, and run `npm install`
from the repository root.

#### tsconfig.json

Generate a new `tsconfig.json` with default values with `node_modules/.bin/tsc --init`,
and merge it with the existing one:
- We want to use the default target, module, and other settings.
- We have to include the test sources.
- We explicitly want to emit declaration and declaration maps, because some
transpilation issues only occur when emitting them.
- We explicitly want to check libs.

### Running and maintaining the tests

Run `npx turbo run test -F './packages/typescript-compat/*'` to run all tests.

Unfortunately, `npm` has no mechanism to pin to a dist-tag for `@types/node`,
but the actual version is a moving target. It is necessary to manually verify
that we still use appropriate versions.
12 changes: 12 additions & 0 deletions packages/typescript-compat/v4.9.x/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "ts4.9",
"scripts": {
"test": "node_modules/.bin/tsc --outDir dist"
},
"dependencies": {
"@connectrpc/connect-conformance": "*",
"@connectrpc/example": "*",
"@types/node": "22.5.4",
"typescript": "4.9.x"
}
}
24 changes: 24 additions & 0 deletions packages/typescript-compat/v4.9.x/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"include": [
"../../connect-conformance/src/index.ts",
"../../example/src/**/*.ts"
],
// These are the default compiler options for TypeScript v4.9.x, created
// with `tsc --init` (except where noted in comments below)
"compilerOptions": {
// By default, target is es5. For iterables, we need target 2015 or higher,
// or downLevelIteration.
"target": "es2015",
"module": "commonjs",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
// To guard against regression and ensure we are remaining backwards
// compatible, set the skipLibCheck flag to false explicitly.
"skipLibCheck": false,
// Certain errors are only triggered by actually emitting declaration files,
// see https://github.com/bufbuild/protobuf-es/pull/398
"declaration": true,
"declarationMap": true
}
}
Loading

0 comments on commit ed4b0e5

Please sign in to comment.