diff --git a/.github/workflows/validate-dts-against-old-typescript.yaml b/.github/workflows/validate-dts-against-old-typescript.yaml new file mode 100644 index 0000000000..8604ec13b4 --- /dev/null +++ b/.github/workflows/validate-dts-against-old-typescript.yaml @@ -0,0 +1,25 @@ +name: 'validate-dts-against-old-typescript' +permissions: + contents: read +on: + pull_request: + branches: + - main + workflow_dispatch: +jobs: + validate-dts-against-old-typescript: + runs-on: ubuntu-latest + env: + CI_JOB_NUMBER: 1 + steps: + - uses: actions/checkout@v5 + - uses: pnpm/action-setup@v4 + - name: Use Node.js 24 + uses: actions/setup-node@v6 + with: + node-version: 24 + cache: 'pnpm' + - name: Install dependencies + run: pnpm install + - name: Validates that livekit-client can be parsed in a typescript 4.8 project + run: pnpm validate-dts-against-old-typescript 4.8 diff --git a/.gitignore b/.gitignore index fa07350e35..1b836bb010 100644 --- a/.gitignore +++ b/.gitignore @@ -113,4 +113,7 @@ pkg/ bin/ examples/**/build/ -.env.local \ No newline at end of file +# dts validation task working directory +dts-validation/ + +.env.local diff --git a/package.json b/package.json index 3fa231d8fb..307914ed68 100644 --- a/package.json +++ b/package.json @@ -51,6 +51,7 @@ "format:check": "prettier --check src examples/**/*.ts", "ci:publish": "pnpm build:clean && pnpm compat && changeset publish", "downlevel-dts": "downlevel-dts ./dist/src ./dist/ts4.2 --to=4.2", + "validate-dts-against-old-typescript": "./validate-dts-against-old-typescript.sh", "compat": "eslint --config ./eslint.config.dist.mjs --no-inline-config ./dist/livekit-client.esm.mjs", "size-limit": "size-limit" }, diff --git a/validate-dts-against-old-typescript.sh b/validate-dts-against-old-typescript.sh new file mode 100755 index 0000000000..09cd68166a --- /dev/null +++ b/validate-dts-against-old-typescript.sh @@ -0,0 +1,68 @@ +#!/bin/bash +# Runs a check to make sure that a given version of livekit-client can be used in a downstream project +# which is configured with an older version typescript. +# +# In theory, downlevel-dts should handle this, but there has been at least one breaking typing +# change in the past which downlevel-dts has been unable to patch over +# (more info: https://github.com/livekit/client-sdk-js/pull/1668) so this serves as a mechanism to +# catch cases like this in the future before they are reported by users. + +TYPESCRIPT_VERSION=${1:-"4.8"} + +echo "# Performing clean build of livekit-client library..." +pnpm build:clean + +echo "# Instantiating dts-validation working directory..." +rm -rf dts-validation +mkdir dts-validation +cd dts-validation + +pnpm init +pnpm install typescript@${TYPESCRIPT_VERSION} +pnpm install ../ + +echo "import 'livekit-client';" > index.ts +cat < tsconfig.json +{ + "compilerOptions": { + "types": ["sdp-transform", "ua-parser-js", "events", "dom-mediacapture-record"], + "target": "ES2015" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */, + "module": "ES2020" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */, + "lib": [ + "DOM", + "DOM.Iterable", + "ES2017", + "ES2018.Promise", + "ES2018.AsyncGenerator", + "ES2020.BigInt", + "ES2021.WeakRef", + "ESNext.AsyncIterable" + ], + "rootDir": "./", + "outDir": "dist", + "declaration": true, + "declarationMap": true, + "sourceMap": true, + "strict": true /* Enable all strict type-checking options. */, + "esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */, + "skipLibCheck": false /* Skip type checking of declaration files. */, + "noUnusedLocals": true, + "forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */, + "moduleResolution": "node", + "resolveJsonModule": true + }, + "include": ["index.ts"] +} +EOF + +echo "# Running tsc against dts-validation working directory..." +npx tsc +result="$?" + +if [[ "${result}" -eq "0" ]]; then + echo "# tsc ran successfully against demo typescript ${TYPESCRIPT_VERSION} project, PASS!" +else + echo "# tsc errored when ran against demo typescript ${TYPESCRIPT_VERSION} project, FAIL!" +fi + +exit ${result}