Skip to content

Commit

Permalink
chore: enforce min TS version (#1194)
Browse files Browse the repository at this point in the history
  • Loading branch information
igalklebanov authored Nov 4, 2024
1 parent 93b6ee2 commit ccc2f0a
Show file tree
Hide file tree
Showing 9 changed files with 4,126 additions and 6 deletions.
29 changes: 26 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -205,11 +205,34 @@ jobs:
- name: Run build with newer TypeScript
run: npm run build

- name: Install older TypeScript
run: npm i -D typescript@${{ matrix.typescript-version }} tsd@${{ fromJson('{ "^4.6":"0.20.0", "^4.7":"0.22.0", "^4.8":"0.24.1", "^4.9":"0.27.0", "^5.0":"0.28.1", "^5.2":"0.29.0", "^5.3":"0.30.7", "^5.4":"0.31.2" }')[matrix.typescript-version] }}
- run: |
echo "TS_VERSION=${{ matrix.typescript-version }}" >> $GITHUB_ENV
echo "TSD_VERSION=${{ fromJson('{ "^4.6":"0.20.0", "^4.7":"0.22.0", "^4.8":"0.24.1", "^4.9":"0.27.0", "^5.0":"0.28.1", "^5.2":"0.29.0", "^5.3":"0.30.7", "^5.4":"0.31.2" }')[env.TS_VERSION] }} >> $GITHUB_ENV"
- name: Install Typescript (${{ env.TS_VERSION }}) and TSD (${{ env.TSD_VERSION }})
run: npm i -D typescript@${{ env.TS_VERSION }} tsd@${{ env.TSD_VERSION }}

- name: Exclude non-backward compatible tests
run: npx tsx ./scripts/exclude-test-files-for-backwards-compat.mts

- name: Run tests with older TypeScript
- name: Run tests with older TypeScript version
run: npm run test:typings && npm run test:node:build

outdated-typescript-version:
name: Outdated TypeScript version (<4.6)
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: 18.x
cache: 'npm'

- name: Install dependencies
run: npm ci

- name: Test outdated TypeScript version
run: npm run test:outdatedts && echo "Outdated TypeScript version users are required to upgrade!"
2 changes: 1 addition & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ package-lock.json
tsconfig-base.json
tsconfig-cjs.json
tsconfig.json

CONTRIBUTING.md
5 changes: 5 additions & 0 deletions outdated-typescript.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type { KyselyTypeError } from './dist/cjs/util/type-error'

declare const Kysely: KyselyTypeError<'The installed TypeScript version is outdated and cannot guarantee type-safety with Kysely. Please upgrade to version 4.6 or newer.'>
declare const RawBuilder: KyselyTypeError<'The installed TypeScript version is outdated and cannot guarantee type-safety with Kysely. Please upgrade to version 4.6 or newer.'>
declare const sql: KyselyTypeError<'The installed TypeScript version is outdated and cannot guarantee type-safety with Kysely. Please upgrade to version 4.6 or newer.'>
2 changes: 1 addition & 1 deletion package-lock.json

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

10 changes: 9 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,17 @@
"url": "git://github.com/kysely-org/kysely.git"
},
"engines": {
"node": ">=14.0.0"
"node": ">=18.0.0"
},
"main": "dist/cjs/index.js",
"module": "dist/esm/index.js",
"typesVersions": {
"<4.6": {
"*": [
"outdated-typescript.d.ts"
]
}
},
"exports": {
".": {
"import": "./dist/esm/index.js",
Expand Down Expand Up @@ -53,6 +60,7 @@
"test:esmimports": "node scripts/check-esm-imports.js",
"test:esbuild": "esbuild --bundle --platform=node --external:pg-native dist/esm/index.js --outfile=/dev/null",
"test:exports": "attw --pack . && node scripts/check-exports.js",
"test:outdatedts": "npm run build && cd test/outdated-ts && npm ci && npm test",
"prettier": "prettier --write 'src/**/*.ts' 'test/**/*.ts'",
"build": "npm run clean && (npm run build:esm & npm run build:cjs) && npm run script:module-fixup && npm run script:copy-interface-doc",
"build:esm": "tsc -p tsconfig.json && npm run script:add-deno-type-references",
Expand Down
10 changes: 10 additions & 0 deletions test/outdated-ts/outdated-ts.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Kysely, RawBuilder, sql } from 'kysely'
import { KyselyTypeError } from '../../src/util/type-error'

function expectOutdatedTSError(
_: KyselyTypeError<'The installed TypeScript version is outdated and cannot guarantee type-safety with Kysely. Please upgrade to version 4.6 or newer.'>,
): void {}

expectOutdatedTSError(Kysely)
expectOutdatedTSError(RawBuilder)
expectOutdatedTSError(sql)
Loading

0 comments on commit ccc2f0a

Please sign in to comment.