Skip to content

Commit

Permalink
chore(NODE-4153): make type fixes for ts 4.7 (#3185)
Browse files Browse the repository at this point in the history
  • Loading branch information
nbbeeken authored Apr 4, 2022
1 parent 0ed7cbf commit 43f748c
Show file tree
Hide file tree
Showing 24 changed files with 804 additions and 636 deletions.
102 changes: 92 additions & 10 deletions .evergreen/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -213,14 +213,60 @@ functions:
NO_EXIT=${NO_EXIT|1} \
LOAD_BALANCER="${LOAD_BALANCER}" \
bash ${PROJECT_DIRECTORY}/.evergreen/run-tests.sh
run checks:
- command: shell.exec
type: test
run lint checks:
- command: subprocess.exec
params:
working_dir: src
script: |
${PREPARE_SHELL}
bash ${PROJECT_DIRECTORY}/.evergreen/run-checks.sh
timeout_secs: 60
env:
PROJECT_DIRECTORY: ${PROJECT_DIRECTORY}
binary: bash
args:
- ${PROJECT_DIRECTORY}/.evergreen/run-lint-checks.sh
run unit tests:
- command: subprocess.exec
params:
working_dir: src
timeout_secs: 60
env:
PROJECT_DIRECTORY: ${PROJECT_DIRECTORY}
binary: bash
args:
- ${PROJECT_DIRECTORY}/.evergreen/run-unit-tests.sh
run typescript next:
- command: subprocess.exec
params:
working_dir: src
timeout_secs: 60
env:
PROJECT_DIRECTORY: ${PROJECT_DIRECTORY}
TS_VERSION: next
binary: bash
args:
- ${PROJECT_DIRECTORY}/.evergreen/run-typescript.sh
run typescript oldest:
- command: subprocess.exec
params:
working_dir: src
timeout_secs: 60
env:
PROJECT_DIRECTORY: ${PROJECT_DIRECTORY}
TS_VERSION: 4.1.6
TRY_COMPILING_DRIVER: 'false'
binary: bash
args:
- ${PROJECT_DIRECTORY}/.evergreen/run-typescript.sh
run typescript current:
- command: subprocess.exec
params:
working_dir: src
timeout_secs: 60
env:
PROJECT_DIRECTORY: ${PROJECT_DIRECTORY}
TS_VERSION: ''
binary: bash
args:
- ${PROJECT_DIRECTORY}/.evergreen/run-typescript.sh
run mongosh integration tests:
- command: shell.exec
type: test
Expand Down Expand Up @@ -1734,14 +1780,46 @@ tasks:
- func: add aws auth variables to file
- func: setup aws env
- func: run aws ECS auth test
- name: run-checks
- name: run-unit-tests
tags:
- run-unit-tests
commands:
- func: install dependencies
vars:
NODE_LTS_NAME: erbium
- func: run unit tests
- name: run-lint-checks
tags:
- run-lint-checks
commands:
- func: install dependencies
vars:
NODE_LTS_NAME: erbium
- func: run lint checks
- name: run-typescript-next
tags:
- run-typescript-next
commands:
- func: install dependencies
vars:
NODE_LTS_NAME: erbium
- func: run typescript next
- name: run-typescript-current
tags:
- run-typescript-current
commands:
- func: install dependencies
vars:
NODE_LTS_NAME: erbium
- func: run typescript current
- name: run-typescript-oldest
tags:
- run-checks
- run-typescript-oldest
commands:
- func: install dependencies
vars:
NODE_LTS_NAME: erbium
- func: run checks
- func: run typescript oldest
- name: run-mongosh-integration-tests
tags:
- run-mongosh-integration-tests
Expand Down Expand Up @@ -2307,7 +2385,11 @@ buildvariants:
display_name: lint
run_on: ubuntu1804-large
tasks:
- run-checks
- run-unit-tests
- run-lint-checks
- run-typescript-current
- run-typescript-oldest
- run-typescript-next
- name: mongosh_integration_tests
display_name: mongosh integration tests
run_on: ubuntu1804-test
Expand Down
62 changes: 56 additions & 6 deletions .evergreen/config.yml.in
Original file line number Diff line number Diff line change
Expand Up @@ -238,14 +238,64 @@ functions:
LOAD_BALANCER="${LOAD_BALANCER}" \
bash ${PROJECT_DIRECTORY}/.evergreen/run-tests.sh

"run checks":
- command: shell.exec
type: test
"run lint checks":
- command: subprocess.exec
params:
working_dir: "src"
script: |
${PREPARE_SHELL}
bash ${PROJECT_DIRECTORY}/.evergreen/run-checks.sh
timeout_secs: 60
env:
PROJECT_DIRECTORY: ${PROJECT_DIRECTORY}
binary: bash
args:
- "${PROJECT_DIRECTORY}/.evergreen/run-lint-checks.sh"

"run unit tests":
- command: subprocess.exec
params:
working_dir: "src"
timeout_secs: 60
env:
PROJECT_DIRECTORY: ${PROJECT_DIRECTORY}
binary: bash
args:
- "${PROJECT_DIRECTORY}/.evergreen/run-unit-tests.sh"

"run typescript next":
- command: subprocess.exec
params:
working_dir: "src"
timeout_secs: 60
env:
PROJECT_DIRECTORY: ${PROJECT_DIRECTORY}
TS_VERSION: "next"
binary: bash
args:
- "${PROJECT_DIRECTORY}/.evergreen/run-typescript.sh"

"run typescript oldest":
- command: subprocess.exec
params:
working_dir: "src"
timeout_secs: 60
env:
PROJECT_DIRECTORY: ${PROJECT_DIRECTORY}
TS_VERSION: "4.1.6"
TRY_COMPILING_DRIVER: "false" # 4.1.6 can consume the public API but not compile the driver
binary: bash
args:
- "${PROJECT_DIRECTORY}/.evergreen/run-typescript.sh"

"run typescript current":
- command: subprocess.exec
params:
working_dir: "src"
timeout_secs: 60
env:
PROJECT_DIRECTORY: ${PROJECT_DIRECTORY}
TS_VERSION: "" # leaving this empty will use the version in package-lock.json
binary: bash
args:
- "${PROJECT_DIRECTORY}/.evergreen/run-typescript.sh"

"run mongosh integration tests":
- command: shell.exec
Expand Down
84 changes: 73 additions & 11 deletions .evergreen/generate_evergreen_tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -578,25 +578,87 @@ OPERATING_SYSTEMS.forEach(
);

// singleton build variant for linting
SINGLETON_TASKS.push({
name: 'run-checks',
tags: ['run-checks'],
commands: [
SINGLETON_TASKS.push(
...[
{
func: 'install dependencies',
vars: {
NODE_LTS_NAME: LOWEST_LTS
}
name: 'run-unit-tests',
tags: ['run-unit-tests'],
commands: [
{
func: 'install dependencies',
vars: {
NODE_LTS_NAME: LOWEST_LTS
}
},
{ func: 'run unit tests' }
]
},
{
name: 'run-lint-checks',
tags: ['run-lint-checks'],
commands: [
{
func: 'install dependencies',
vars: {
NODE_LTS_NAME: LOWEST_LTS
}
},
{ func: 'run lint checks' }
]
},
{
name: 'run-typescript-next',
tags: ['run-typescript-next'],
commands: [
{
func: 'install dependencies',
vars: {
NODE_LTS_NAME: LOWEST_LTS
}
},
{ func: 'run typescript next' }
]
},
{
name: 'run-typescript-current',
tags: ['run-typescript-current'],
commands: [
{
func: 'install dependencies',
vars: {
NODE_LTS_NAME: LOWEST_LTS
}
},
{ func: 'run typescript current' }
]
},
{ func: 'run checks' }
{
name: 'run-typescript-oldest',
tags: ['run-typescript-oldest'],
commands: [
{
func: 'install dependencies',
vars: {
NODE_LTS_NAME: LOWEST_LTS
}
},
{ func: 'run typescript oldest' }
]
}
]
});
);

BUILD_VARIANTS.push({
name: 'lint',
display_name: 'lint',
run_on: DEFAULT_OS,
tasks: ['run-checks']
tasks: [
'run-unit-tests',
'run-lint-checks',
'run-typescript-current',
'run-typescript-oldest',
'run-typescript-next'
]
});

// TODO NODE-3897 - generate combined coverage report
Expand Down
16 changes: 0 additions & 16 deletions .evergreen/run-checks.sh → .evergreen/run-lint-checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,3 @@ set -o xtrace

## Checks typescript, eslint, and prettier
npm run check:lint

npx nyc npm run check:unit

export TSC="./node_modules/typescript/bin/tsc"

echo "Typescript $($TSC -v)"
# check resolution uses the default latest types
echo "import * as mdb from '.'" > file.ts && $TSC --noEmit --traceResolution file.ts | grep 'mongodb.d.ts' && rm file.ts

npm i --no-save [email protected]
echo "Typescript $($TSC -v)"
$TSC --noEmit mongodb.ts34.d.ts
# check that resolution uses the downleveled types
echo "import * as mdb from '.'" > file.ts && $TSC --noEmit --traceResolution file.ts | grep 'mongodb.ts34.d.ts' && rm file.ts

rm -f file.ts
29 changes: 29 additions & 0 deletions .evergreen/run-typescript.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash
set -o errexit # Exit the script with error if any of the commands fail

source "${PROJECT_DIRECTORY}/.evergreen/init-nvm.sh"

set -o xtrace

function get_current_ts_version {
node -e "console.log(require('./package-lock.json').dependencies.typescript.version)"
}

CURRENT_TS_VERSION=$(get_current_ts_version)

export TSC="./node_modules/typescript/bin/tsc"
export TS_VERSION=${TS_VERSION:=$CURRENT_TS_VERSION}

npm install --no-save --force typescript@"$TS_VERSION"

echo "Typescript $($TSC -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

# check compilation
node $TSC mongodb.d.ts

if [[ $TRY_COMPILING_DRIVER != "false" ]]; then
npm run build:ts
fi
7 changes: 7 additions & 0 deletions .evergreen/run-unit-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash
set -o errexit # Exit the script with error if any of the commands fail

source "${PROJECT_DIRECTORY}/.evergreen/init-nvm.sh"
set -o xtrace

npx nyc npm run check:unit
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,10 @@ For version compatibility matrices, please refer to the following links:

#### Typescript Version

We recommend using the latest version of typescript, however we do provide a [downleveled](https:/sandersn/downlevel-dts#readme) version of the type definitions that we test compiling against `[email protected]`.
We recommend using the latest version of typescript, however we currently ensure the driver's public types compile against `[email protected]`.
This is the lowest typescript version guaranteed to work with our driver: older versions may or may not work - use at your own risk.
Since typescript [does not restrict breaking changes to major versions](https:/Microsoft/TypeScript/wiki/Breaking-Changes) we consider this support best effort.
If you run into any unexpected compiler failures please let us know and we will do our best to correct it.
If you run into any unexpected compiler failures against our supported TypeScript versions please let us know by filing an issue on our [JIRA](https://jira.mongodb.org/browse/NODE).

## Installation

Expand Down
Loading

0 comments on commit 43f748c

Please sign in to comment.