diff --git a/.evergreen/config.in.yml b/.evergreen/config.in.yml index b4d1c00ac7b..5fc5e408d8e 100644 --- a/.evergreen/config.in.yml +++ b/.evergreen/config.in.yml @@ -348,6 +348,7 @@ functions: PROJECT_DIRECTORY: ${PROJECT_DIRECTORY} TS_VERSION: ${TS_VERSION} TS_CHECK: CHECK_TYPES + TYPES_VERSION: ${TYPES_VERSION} binary: bash args: - "${PROJECT_DIRECTORY}/.evergreen/run-typescript.sh" @@ -362,6 +363,7 @@ functions: PROJECT_DIRECTORY: ${PROJECT_DIRECTORY} TS_VERSION: ${TS_VERSION} TS_CHECK: COMPILE_DRIVER + TYPES_VERSION: ${TYPES_VERSION} binary: bash args: - "${PROJECT_DIRECTORY}/.evergreen/run-typescript.sh" diff --git a/.evergreen/config.yml b/.evergreen/config.yml index 184828452b9..22c138bec3d 100644 --- a/.evergreen/config.yml +++ b/.evergreen/config.yml @@ -312,6 +312,7 @@ functions: PROJECT_DIRECTORY: ${PROJECT_DIRECTORY} TS_VERSION: ${TS_VERSION} TS_CHECK: CHECK_TYPES + TYPES_VERSION: ${TYPES_VERSION} binary: bash args: - ${PROJECT_DIRECTORY}/.evergreen/run-typescript.sh @@ -325,6 +326,7 @@ functions: PROJECT_DIRECTORY: ${PROJECT_DIRECTORY} TS_VERSION: ${TS_VERSION} TS_CHECK: COMPILE_DRIVER + TYPES_VERSION: ${TYPES_VERSION} binary: bash args: - ${PROJECT_DIRECTORY}/.evergreen/run-typescript.sh @@ -3459,7 +3461,7 @@ tasks: - {key: NPM_VERSION, value: '9'} - func: install dependencies - func: run lint checks - - name: check-types-typescript-next + - name: check-types-typescript-next-node-types-18.19.39 tags: - check-types-typescript-next - typescript-compilation @@ -3471,11 +3473,12 @@ tasks: - {key: NODE_LTS_VERSION, value: '16'} - {key: NPM_VERSION, value: '9'} - {key: TS_VERSION, value: next} + - {key: TYPES_VERSION, value: 18.19.39} - func: install dependencies - func: check types - - name: compile-driver-typescript-current + - name: check-types-typescript-current-node-types-18.19.39 tags: - - compile-driver-typescript-current + - check-types-typescript-current - typescript-compilation commands: - command: expansions.update @@ -3485,9 +3488,25 @@ tasks: - {key: NODE_LTS_VERSION, value: '16'} - {key: NPM_VERSION, value: '9'} - {key: TS_VERSION, value: current} + - {key: TYPES_VERSION, value: 18.19.39} - func: install dependencies - - func: compile driver - - name: check-types-typescript-current + - func: check types + - name: check-types-typescript-next-node-types-16.x + tags: + - check-types-typescript-next + - typescript-compilation + commands: + - command: expansions.update + type: setup + params: + updates: + - {key: NODE_LTS_VERSION, value: '16'} + - {key: NPM_VERSION, value: '9'} + - {key: TS_VERSION, value: next} + - {key: TYPES_VERSION, value: 16.x} + - func: install dependencies + - func: check types + - name: check-types-typescript-current-node-types-16.x tags: - check-types-typescript-current - typescript-compilation @@ -3499,9 +3518,10 @@ tasks: - {key: NODE_LTS_VERSION, value: '16'} - {key: NPM_VERSION, value: '9'} - {key: TS_VERSION, value: current} + - {key: TYPES_VERSION, value: 16.x} - func: install dependencies - func: check types - - name: check-types-typescript-4.4 + - name: check-types-typescript-4.4-node-types-18.11.9 tags: - check-types-typescript-4.4 - typescript-compilation @@ -3513,8 +3533,39 @@ tasks: - {key: NODE_LTS_VERSION, value: '16'} - {key: NPM_VERSION, value: '9'} - {key: TS_VERSION, value: '4.4'} + - {key: TYPES_VERSION, value: 18.11.9} - func: install dependencies - func: check types + - name: compile-driver-typescript-current-node-types-18.19.39 + tags: + - compile-driver-typescript-current + - typescript-compilation + commands: + - command: expansions.update + type: setup + params: + updates: + - {key: NODE_LTS_VERSION, value: '16'} + - {key: NPM_VERSION, value: '9'} + - {key: TS_VERSION, value: current} + - {key: TYPES_VERSION, value: 18.19.39} + - func: install dependencies + - func: compile driver + - name: compile-driver-typescript-current-node-types-16.x + tags: + - compile-driver-typescript-current + - typescript-compilation + commands: + - command: expansions.update + type: setup + params: + updates: + - {key: NODE_LTS_VERSION, value: '16'} + - {key: NPM_VERSION, value: '9'} + - {key: TS_VERSION, value: current} + - {key: TYPES_VERSION, value: 16.x} + - func: install dependencies + - func: compile driver - name: download-and-merge-coverage tags: [] commands: diff --git a/.evergreen/generate_evergreen_tasks.js b/.evergreen/generate_evergreen_tasks.js index 5d2d2b366c5..d59f1a09ddc 100644 --- a/.evergreen/generate_evergreen_tasks.js +++ b/.evergreen/generate_evergreen_tasks.js @@ -497,51 +497,51 @@ SINGLETON_TASKS.push( ); function* makeTypescriptTasks() { - for (const TS_VERSION of ['next', 'current', '4.4']) { - // We don't compile on next, because compilation errors are likely. We do expect - // that the drivers types continue to work with next though. - if (TS_VERSION !== '4.4' && TS_VERSION !== 'next') { - yield { - name: `compile-driver-typescript-${TS_VERSION}`, - tags: [`compile-driver-typescript-${TS_VERSION}`, 'typescript-compilation'], - commands: [ - updateExpansions({ - NODE_LTS_VERSION: LOWEST_LTS, - NPM_VERSION: 9, - TS_VERSION - }), - { func: 'install dependencies' }, - { func: 'compile driver' } - ] - }; + function makeCompileTask(TS_VERSION, TYPES_VERSION) { + return { + name: `compile-driver-typescript-${TS_VERSION}-node-types-${TYPES_VERSION}`, + tags: [`compile-driver-typescript-${TS_VERSION}`, 'typescript-compilation'], + commands: [ + updateExpansions({ + NODE_LTS_VERSION: LOWEST_LTS, + NPM_VERSION: 9, + TS_VERSION, + TYPES_VERSION + }), + { func: 'install dependencies' }, + { func: 'compile driver' } + ] } - - yield { - name: `check-types-typescript-${TS_VERSION}`, + } + function makeCheckTypesTask(TS_VERSION, TYPES_VERSION) { + return { + name: `check-types-typescript-${TS_VERSION}-node-types-${TYPES_VERSION}`, tags: [`check-types-typescript-${TS_VERSION}`, 'typescript-compilation'], commands: [ updateExpansions({ NODE_LTS_VERSION: LOWEST_LTS, NPM_VERSION: 9, - TS_VERSION + TS_VERSION, + TYPES_VERSION }), { func: 'install dependencies' }, { func: 'check types' } ] - }; + } } - return { - name: 'run-typescript-next', - tags: ['run-typescript-next', 'typescript-compilation'], - commands: [ - updateExpansions({ - NODE_LTS_VERSION: LOWEST_LTS, - NPM_VERSION: 9 - }), - { func: 'install dependencies' }, - { func: 'run typescript next' } - ] - }; + + const typesVersion = require('../package.json').devDependencies['@types/node'].slice(1) + yield makeCheckTypesTask('next', typesVersion); + yield makeCheckTypesTask('current', typesVersion); + + yield makeCheckTypesTask('next', '16.x'); + yield makeCheckTypesTask('current', '16.x'); + + // typescript 4.4 only compiles our types with this particular version + yield makeCheckTypesTask('4.4', '18.11.9'); + + yield makeCompileTask('current', typesVersion); + yield makeCompileTask('current', '16.x'); } BUILD_VARIANTS.push({ diff --git a/.evergreen/run-typescript.sh b/.evergreen/run-typescript.sh index 87d47a559b6..9bd212eb705 100644 --- a/.evergreen/run-typescript.sh +++ b/.evergreen/run-typescript.sh @@ -3,8 +3,6 @@ set -o errexit # Exit the script with error if any of the commands fail source "${PROJECT_DIRECTORY}/.evergreen/init-node-and-npm-env.sh" -set -o xtrace - case $TS_CHECK in COMPILE_DRIVER|CHECK_TYPES) # Ok ;; @@ -14,6 +12,7 @@ case $TS_CHECK in esac if [ -z "$TS_VERSION" ]; then echo "TS_VERSION must be set"; exit 1; fi +if [ -z "$TYPES_VERSION" ]; then echo "TYPES_VERSION must be set"; exit 1; fi if [ ! -f "mongodb.d.ts" ]; then echo "mongodb.d.ts should always exist because of the installation in prior steps but in case it doesn't, build it" @@ -31,10 +30,11 @@ function get_ts_version() { export TSC="./node_modules/typescript/bin/tsc" export TS_VERSION=$(get_ts_version) -# On old versions of TS we need to put the node types back to 18.11.19 -npm install --no-save --force typescript@"$TS_VERSION" "$(if [[ $TS_VERSION == '4.4' ]]; then echo "@types/node@18.11.19"; else echo ""; fi)" +npm install --no-save --force "typescript@$TS_VERSION" "@types/node@$TYPES_VERSION" echo "Typescript $($TSC -v)" +echo "Types: $(cat node_modules/@types/node/package.json | jq -r .version)" +echo "Nodejs: $(node -v)" # check resolution uses the default latest types echo "import * as mdb from '.'" > file.ts && node $TSC --noEmit --traceResolution file.ts | grep 'mongodb.d.ts' && rm file.ts