Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Convert to Typescript (#388) #393

Merged
merged 1 commit into from
Sep 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
dist/
node_modules/
docs/
types/
33 changes: 0 additions & 33 deletions .eslintrc

This file was deleted.

43 changes: 43 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"root": true,
"extends": [
"eslint:recommended",
"plugin:prettier/recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"prettier/@typescript-eslint"
],
"env": {
"node": true
},
"globals": {
"Promise": true,
"Uint8Array": true,
"ArrayBuffer": true,
"Set": true,
"Map": false
},
"parserOptions": {
"ecmaVersion": 2017
},
"plugins": [
"prettier"
],
"rules": {
"prettier/prettier": "error",
"no-console": "off",
"eqeqeq": [
"error",
"always",
{
"null": "ignore"
}
],
"strict": [
"error",
"global"
],
"@typescript-eslint/ban-types": "off",
"@typescript-eslint/no-var-requires": "off"
}
}
24 changes: 24 additions & 0 deletions .evergreen/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,16 @@ functions:
${PREPARE_SHELL}
echo "NODE_VERSION=${NODE_VERSION} TEST_TARGET=${TEST_TARGET}"
NODE_VERSION=${NODE_VERSION} ${PROJECT_DIRECTORY}/.evergreen/run-tests.sh ${TEST_TARGET}
run checks:
- command: shell.exec
type: test
params:
working_dir: src
script: |
${PREPARE_SHELL}
echo "NODE_VERSION=${NODE_VERSION} TEST_TARGET=${TEST_TARGET}"
bash ${PROJECT_DIRECTORY}/.evergreen/run-checks.sh


tasks:
- name: node-tests-v6
Expand Down Expand Up @@ -133,6 +143,15 @@ tasks:
- func: run tests
vars:
TEST_TARGET: browser
- name: run-checks
tags:
- run-checks
commands:
- func: fetch source
vars:
NODE_MAJOR_VERSION: 12
- func: install dependencies
- func: run checks

buildvariants:
- name: linux
Expand All @@ -147,3 +166,8 @@ buildvariants:
display_name: Windows 64
run_on: windows-64-vsMulti-small
tasks: [".node"]
- name: lint
display_name: lint
run_on: rhel70
tasks:
- run-checks
7 changes: 5 additions & 2 deletions .evergreen/install-dependencies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,16 @@ path: $NVM_SYMLINK
EOT

nvm install ${NODE_VERSION}
nvm install 10.22.0 # install lts for compilation only
nvm on
else
curl -o- $NVM_URL | bash
[ -s "${NVM_DIR}/nvm.sh" ] && \. "${NVM_DIR}/nvm.sh"

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

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

# install node dependencies
npm install
npm install # npm prepare runs after install and will compile the library
nvm use ${NODE_VERSION} # Switch to the node version we want to test against
9 changes: 9 additions & 0 deletions .evergreen/run-checks.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash
set -o errexit # Exit the script with error if any of the commands fail

export PROJECT_DIRECTORY="$(pwd)"
NODE_ARTIFACTS_PATH="${PROJECT_DIRECTORY}/node-artifacts"
export NVM_DIR="${NODE_ARTIFACTS_PATH}/nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"

npm run lint
4 changes: 2 additions & 2 deletions .evergreen/run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ fi

case $1 in
"node")
npm run lint && npm run test-node
npm run test-node
;;
"browser")
npm run lint && npm run test-browser
npm run test-browser
;;
*)
npm test
Expand Down
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,11 @@ builderror.log

bson.sublime-project
bson.sublime-workspace

lib
types/
.nyc_output/
coverage/
*.d.ts
*.tgz
docs/public
13 changes: 13 additions & 0 deletions .mocharc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"extension": [
"js"
],
"require": [
"ts-node/register",
"chai/register-expect",
"source-map-support/register"
],
"timeout": 10000,
"throw-deprecation": true,
"parallel": false
}
5 changes: 5 additions & 0 deletions .nycrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"extends": "@istanbuljs/nyc-config-typescript",
"include": ["src/**/*.ts"],
"reporter": ["lcovonly", "text-summary"]
}
7 changes: 7 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"singleQuote": true,
"tabWidth": 2,
"printWidth": 100,
"arrowParens": "avoid",
"trailingComma": "none"
}
51 changes: 51 additions & 0 deletions api-extractor.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
"mainEntryPointFilePath": "<projectFolder>/lib/bson.d.ts",
"apiReport": {
"enabled": false
},
"docModel": {
"enabled": false
},
"dtsRollup": {
"enabled": true,
"untrimmedFilePath": "<projectFolder>/<unscopedPackageName>.d.ts"
},
"tsdocMetadata": {
"enabled": false
},
"newlineKind": "lf",
"messages": {
"compilerMessageReporting": {
"default": {
"logLevel": "error"
}
},
"extractorMessageReporting": {
"default": {
"logLevel": "warning"
},
"ae-internal-missing-underscore": {
"logLevel": "none",
"addToApiReportFile": false
},
"ae-missing-release-tag": {
"logLevel": "none",
"addToApiReportFile": false
},
"ae-incompatible-release-tags": {
"logLevel": "none",
"addToApiReportFile": false
},
"ae-unresolved-link": {
"addToApiReportFile": false,
"logLevel": "none"
}
},
"tsdocMessageReporting": {
"default": {
"logLevel": "none"
}
}
}
}
11 changes: 2 additions & 9 deletions bower.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
{
"name": "bson",
"description": "A bson parser for node.js and the browser",
"keywords": [
"mongodb",
"bson",
"parser"
],
"keywords": ["mongodb", "bson", "parser"],
"author": "Christian Amor Kvalheim <[email protected]>",
"main": "./dist/bson.js",
"license": "Apache-2.0",
"moduleType": [
"globals",
"node"
],
"moduleType": ["globals", "node"],
"ignore": [
"**/.*",
"alternate_parsers",
Expand Down
19 changes: 19 additions & 0 deletions etc/prepare.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#! /usr/bin/env node
var cp = require('child_process');
var fs = require('fs');

var nodeMajorVersion = +process.version.match(/^v(\d+)\.\d+/)[1];

if (fs.existsSync('src') && nodeMajorVersion >= 10) {
cp.spawnSync('npm', ['run', 'build'], { stdio: 'inherit', shell: true });
} else {
if (!fs.existsSync('lib')) {
console.warn('BSON: No compiled javascript present, the library is not installed correctly.');
if (nodeMajorVersion < 10) {
console.warn(
'This library can only be compiled in nodejs version 10 or later, currently running: ' +
nodeMajorVersion
);
}
}
}
Loading