Skip to content

Commit bdc046f

Browse files
authored
NODE-2716, NODE-2718, NODE-2719, NODE-2721: Convert to Typescript (#388)
This is the first stage of converting the entire codebase over to TypeScript. The goals of this step were to preserve history as well as functional output of the compilation step. Here is a summary of the commits involved: - move all files to `src`, preserving history this also maintains a copy of the original js source in the `lib` folder (without history) so we can compare the transpiled output for potential issues - add type information to all types - move entry point `bson.ts` to `src` folder for ease of future testing - run tests against transpiled module code - fix all linting issues with ts conversion - fix running manual tests with ts codebase - ensure we run the ts pipeline before publish - bump typescript version, fix last outstanding issue - `prepublishOnly` => `prepare` NODE-2716, NODE-2718, NODE-2719, NODE-2721
1 parent 415cb49 commit bdc046f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+6094
-6365
lines changed

.eslintignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
dist/
2+
node_modules/
3+
docs/
4+
types/

.eslintrc

Lines changed: 0 additions & 33 deletions
This file was deleted.

.eslintrc.json

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{
2+
"root": true,
3+
"extends": [
4+
"eslint:recommended",
5+
"plugin:prettier/recommended",
6+
"plugin:@typescript-eslint/eslint-recommended",
7+
"plugin:@typescript-eslint/recommended",
8+
"prettier/@typescript-eslint"
9+
],
10+
"env": {
11+
"node": true
12+
},
13+
"globals": {
14+
"Promise": true,
15+
"Uint8Array": true,
16+
"ArrayBuffer": true,
17+
"Set": true,
18+
"Map": false
19+
},
20+
"parserOptions": {
21+
"ecmaVersion": 2017
22+
},
23+
"plugins": [
24+
"prettier"
25+
],
26+
"rules": {
27+
"prettier/prettier": "error",
28+
"no-console": "off",
29+
"eqeqeq": [
30+
"error",
31+
"always",
32+
{
33+
"null": "ignore"
34+
}
35+
],
36+
"strict": [
37+
"error",
38+
"global"
39+
],
40+
"@typescript-eslint/ban-types": "off",
41+
"@typescript-eslint/no-var-requires": "off"
42+
}
43+
}

.evergreen/config.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,16 @@ functions:
7171
${PREPARE_SHELL}
7272
echo "NODE_VERSION=${NODE_VERSION} TEST_TARGET=${TEST_TARGET}"
7373
NODE_VERSION=${NODE_VERSION} ${PROJECT_DIRECTORY}/.evergreen/run-tests.sh ${TEST_TARGET}
74+
run checks:
75+
- command: shell.exec
76+
type: test
77+
params:
78+
working_dir: src
79+
script: |
80+
${PREPARE_SHELL}
81+
echo "NODE_VERSION=${NODE_VERSION} TEST_TARGET=${TEST_TARGET}"
82+
bash ${PROJECT_DIRECTORY}/.evergreen/run-checks.sh
83+
7484
7585
tasks:
7686
- name: node-tests-v6
@@ -133,6 +143,15 @@ tasks:
133143
- func: run tests
134144
vars:
135145
TEST_TARGET: browser
146+
- name: run-checks
147+
tags:
148+
- run-checks
149+
commands:
150+
- func: fetch source
151+
vars:
152+
NODE_MAJOR_VERSION: 12
153+
- func: install dependencies
154+
- func: run checks
136155

137156
buildvariants:
138157
- name: linux
@@ -147,3 +166,8 @@ buildvariants:
147166
display_name: Windows 64
148167
run_on: windows-64-vsMulti-small
149168
tasks: [".node"]
169+
- name: lint
170+
display_name: lint
171+
run_on: rhel70
172+
tasks:
173+
- run-checks

.evergreen/install-dependencies.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,16 @@ path: $NVM_SYMLINK
4141
EOT
4242

4343
nvm install ${NODE_VERSION}
44+
nvm install 10.22.0 # install lts for compilation only
4445
nvm on
4546
else
4647
curl -o- $NVM_URL | bash
4748
[ -s "${NVM_DIR}/nvm.sh" ] && \. "${NVM_DIR}/nvm.sh"
4849

4950
nvm install --no-progress ${NODE_VERSION}
51+
nvm install --no-progress 10.22.0 # install lts for compilation only
5052
fi
51-
nvm use ${NODE_VERSION}
53+
nvm use 10.22.0 # use lts for setup, runtime node can be different
5254

5355
# setup npm cache in a local directory
5456
cat <<EOT > .npmrc
@@ -60,4 +62,5 @@ registry=https://registry.npmjs.org
6062
EOT
6163

6264
# install node dependencies
63-
npm install
65+
npm install # npm prepare runs after install and will compile the library
66+
nvm use ${NODE_VERSION} # Switch to the node version we want to test against

.evergreen/run-checks.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/bash
2+
set -o errexit # Exit the script with error if any of the commands fail
3+
4+
export PROJECT_DIRECTORY="$(pwd)"
5+
NODE_ARTIFACTS_PATH="${PROJECT_DIRECTORY}/node-artifacts"
6+
export NVM_DIR="${NODE_ARTIFACTS_PATH}/nvm"
7+
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
8+
9+
npm run lint

.evergreen/run-tests.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ fi
1818

1919
case $1 in
2020
"node")
21-
npm run lint && npm run test-node
21+
npm run test-node
2222
;;
2323
"browser")
24-
npm run lint && npm run test-browser
24+
npm run test-browser
2525
;;
2626
*)
2727
npm test

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,11 @@ builderror.log
1515

1616
bson.sublime-project
1717
bson.sublime-workspace
18+
19+
lib
20+
types/
21+
.nyc_output/
22+
coverage/
23+
*.d.ts
24+
*.tgz
25+
docs/public

.mocharc.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"extension": [
3+
"js"
4+
],
5+
"require": [
6+
"ts-node/register",
7+
"chai/register-expect",
8+
"source-map-support/register"
9+
],
10+
"timeout": 10000,
11+
"throw-deprecation": true,
12+
"parallel": false
13+
}

.nycrc.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"extends": "@istanbuljs/nyc-config-typescript",
3+
"include": ["src/**/*.ts"],
4+
"reporter": ["lcovonly", "text-summary"]
5+
}

0 commit comments

Comments
 (0)