Skip to content

Commit

Permalink
POC
Browse files Browse the repository at this point in the history
  • Loading branch information
baileympearson committed Jul 16, 2024
1 parent 4b219d3 commit f113a2b
Show file tree
Hide file tree
Showing 17 changed files with 177 additions and 362 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,8 @@
{
// Settings for generated definition files
"files": [
"mongodb.d.ts"
"**/*.d.ts",
"lib/*.d.ts"
],
"parser": "@typescript-eslint/parser",
"rules": {
Expand Down
2 changes: 2 additions & 0 deletions .evergreen/config.in.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down
63 changes: 57 additions & 6 deletions .evergreen/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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-20.14.10
tags:
- check-types-typescript-next
- typescript-compilation
Expand All @@ -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: 20.14.10}
- func: install dependencies
- func: check types
- name: compile-driver-typescript-current
- name: check-types-typescript-current-node-types-20.14.10
tags:
- compile-driver-typescript-current
- check-types-typescript-current
- typescript-compilation
commands:
- command: expansions.update
Expand All @@ -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: 20.14.10}
- 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
Expand All @@ -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
Expand All @@ -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-20.14.10
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: 20.14.10}
- 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:
Expand Down
68 changes: 34 additions & 34 deletions .evergreen/generate_evergreen_tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
8 changes: 4 additions & 4 deletions .evergreen/run-typescript.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
;;
Expand All @@ -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"
Expand All @@ -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/[email protected]"; 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
Expand Down
3 changes: 2 additions & 1 deletion api-extractor.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"dtsRollup": {
"enabled": true,
"untrimmedFilePath": "",
"publicTrimmedFilePath": "<projectFolder>/<unscopedPackageName>.d.ts"
"publicTrimmedFilePath": "<projectFolder>/<unscopedPackageName>.d.ts",
"betaTrimmedFilePath": "<projectFolder>/lib/beta.d.ts"
},
"tsdocMetadata": {
"enabled": false
Expand Down
2 changes: 1 addition & 1 deletion etc/clean_definition_files.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ if (fs.existsSync(libPath)) {
const definitionFiles = Array.from(walk(libPath)).filter(filePath => {
return filePath.endsWith('.d.ts') || filePath.endsWith('.d.ts.map');
});
for (const definitionFile of definitionFiles) {
for (const definitionFile of definitionFiles.filter(file => !file.endsWith('beta.d.ts'))) {
fs.unlinkSync(definitionFile);
}
}
Loading

0 comments on commit f113a2b

Please sign in to comment.