Skip to content

Commit

Permalink
feat: Typescript everything (#2406)
Browse files Browse the repository at this point in the history
This is a huge change, trying to get anything to convert to typescript piecemeal was very very frustrating and most of the conversions are straight copies.

However
- Big changes to @serialport/stream
- Big resultant downstream changes to serialport
- Hardware tests now only require a loopback port and they all pass (from bindings-cpp up to stream, still working on serialport)

Full change log

- Typescript types are now available for all packages
- Serialport no longer supports Node 10
- bindings-abstract is now bindings-interface and it's in it's own repo (bindings-cpp relies on it and having a cyclic dependency on the monorepo was hard)
- baudRate on serialport and @serialport/stream packages is no longer defaulted to 9600
- All packages now have named exports
- Bindings have moved from @serialport/bindings to @serialport/bindings-cpp they are shipped with - prebuildify and no longer require a download.
- @serialport/bindings-cpp now leverages N-API and shouldn't need to be upgraded for every node release.
- baudRate is now required
- bindings and mock bindings now have a new interface with bindings-cpp
- stream no longer has a list method
- serialport package no longer has a static bindings property on it's class (now a subsclass of SerialPortStream)
  • Loading branch information
reconbot authored Feb 3, 2022
1 parent d8dda09 commit 7ae6e51
Show file tree
Hide file tree
Showing 159 changed files with 3,540 additions and 2,820 deletions.
112 changes: 54 additions & 58 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,65 +1,61 @@
module.exports = {
"extends": [
"eslint:recommended",
"plugin:node/recommended",
"plugin:mocha/recommended",
"plugin:@typescript-eslint/recommended",
],
"parser": "@typescript-eslint/parser",
"plugins": [
"prettier",
"node",
"mocha",
"@typescript-eslint",
],
"env": {
"node": true,
"mocha": true,
"es6": true
extends: ['eslint:recommended', 'plugin:node/recommended', 'plugin:mocha/recommended', 'plugin:@typescript-eslint/recommended'],
parser: '@typescript-eslint/parser',
plugins: ['prettier', 'node', 'mocha', '@typescript-eslint'],
env: {
node: true,
mocha: true,
es6: true,
},
"parserOptions": {
"ecmaVersion": 12,
parserOptions: {
ecmaVersion: 12,
},
"globals": {
"assert": false,
"makeTestFeature": false,
"shouldReject": false
globals: {
assert: false,
makeTestFeature: false,
shouldReject: false,
},
"rules": {
"no-extra-semi": "off",
"no-process-exit": "off",
"no-var": "error",
"node/no-extraneous-require": "off",
"node/no-missing-import": "off",
"node/no-missing-require": "off",
"node/no-unpublished-import": "off",
"node/no-unpublished-require": "off",
"node/no-unsupported-features/es-builtins": "error",
"node/no-unsupported-features/es-syntax": "off",
"node/no-unsupported-features/node-builtins": "error",
"node/shebang": "off",
"object-shorthand": "error",
"prefer-arrow-callback": "error",
"prefer-const": "error",
"prefer-template": "error",
"prettier/prettier": [
"error",
rules: {
'no-extra-semi': 'off', //prettier does this
'@typescript-eslint/no-extra-semi': 'off', //prettier does this
'no-process-exit': 'off',
'no-var': 'error',
'node/no-extraneous-import': [
'error',
{
"singleQuote": true,
"trailingComma": "es5",
"semi": false,
"printWidth": 150,
"arrowParens": "avoid"
}
allowModules: ['sinon', 'chai'], //this gets pulled from monorepo root where the tests are run
},
],
"mocha/no-exclusive-tests": "error",
"mocha/no-hooks-for-single-case": "off",
"mocha/no-mocha-arrows": "off",
"mocha/no-pending-tests": "error",
"mocha/no-setup-in-describe": "off",
"strict": ["error", "never"],
"valid-jsdoc": "off",
"@typescript-eslint/no-var-requires": "off", // until we get all js ported over
"@typescript-eslint/no-empty-function": "off",
}
'node/no-missing-import': 'off',
'node/no-missing-require': 'off',
'node/no-unpublished-import': 'off',
'node/no-unpublished-require': 'off',
'node/no-unsupported-features/es-builtins': 'error',
'node/no-unsupported-features/es-syntax': 'off',
'node/no-unsupported-features/node-builtins': 'error',
'node/shebang': 'off',
'object-shorthand': 'error',
'prefer-arrow-callback': 'error',
'prefer-const': 'error',
'prefer-template': 'error',
'prettier/prettier': [
'error',
{
singleQuote: true,
trailingComma: 'es5',
semi: false,
printWidth: 150,
arrowParens: 'avoid',
},
],
'mocha/no-exclusive-tests': 'error',
'mocha/no-hooks-for-single-case': 'off',
'mocha/no-mocha-arrows': 'off',
'mocha/no-pending-tests': 'error',
'mocha/no-setup-in-describe': 'off',
strict: ['error', 'never'],
'valid-jsdoc': 'off',
'@typescript-eslint/no-var-requires': 'off', // until we get all js ported over
'@typescript-eslint/no-empty-function': 'off',
},
}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ lerna-debug.log
node_modules
npm-debug.log
/packages/**/dist
tsconfig-build.tsbuildinfo
tsconfig.tsbuildinfo
5 changes: 2 additions & 3 deletions .mocharc.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
module.exports = {
bail: true,
require: [
'esbuild-register',
'./test/initializers'
'esbuild-register'
],
'spec': ['packages/**/*.test.js'],
'spec': ['packages/**/*.test.ts'],
}
20 changes: 20 additions & 0 deletions UPGRADE_GUIDE.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
Upgading from 9x to 10x
-------------

- Typscript types are now available for all packages
- Serialport no longer supports Node 10
- SerialPort stream (from npm `serialport` and `@serialport/stream`) now take an options object with a required `path` and `baudRate`. They no longer default to a `baudRate` of 9600 as that's slow and usually not what's needed.
- All packages now have named exports. They export their types and all relevant classes.
- The package `serialport` no longer exports `serialport/test` but instead who classes `{ SerialPort, SerialPortMock }` where the mock is pre-configured with a mock binding.
- Bindings have moved from `@serialport/bindings` to `@serialport/bindings-cpp` they are shipped with `prebuildify` and no longer require a post install download.
- `@serialport/bindings-cpp` leverages N-API and shouldn't need to be upgraded for every node release or rebuild for electron
- Bindings in general now have a new interface with the `@serialport/bindings-interface` type package that replaces `@serialport/bindings-abstract`
- `SerialPortStream` from `@serialport/stream` no longer has a `list()` method as that was a direct call to the bindings.
- `SerialPort` class from the `serialport` package no longer has a static `Bindings` property as it provides the OS specific bindings from `@serialport/bindings-cpp` if you need control of the bindings use `SerialPortStream`.
- `SerialPortStream` methods (and by extension `SerialPort` methods) no longer throw when called with invalid input, their callbacks or the error event will convey input errors. This is because the binding layer now handles input validation as it's different on each platform.
- `SerialPort` is now delivering a few more parsers

TODO
- stop bits are incorrect


Upgrading from 8.x to 9.x
-------------
- Serialport no longer supports Node 8
Expand Down
6 changes: 3 additions & 3 deletions bin/find-arduino.js → bin/find-arduino.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/usr/bin/env node
#!/usr/bin/env node -r esbuild-register

// outputs the path to an Arduino to stdout or an error to stderror

const SerialPort = require('../packages/serialport')
SerialPort.list().then(ports => {
import { autoDetect } from '@serialport/bindings-cpp'
autoDetect().list().then(ports => {
const port = ports.find(port => /arduino/i.test(port.manufacturer))
if (!port) {
console.error('Arduino Not found')
Expand Down
40 changes: 0 additions & 40 deletions bin/write-a-lot.js

This file was deleted.

120 changes: 120 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 7ae6e51

Please sign in to comment.