Skip to content

Commit 7ae6e51

Browse files
authored
feat: Typescript everything (#2406)
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)
1 parent d8dda09 commit 7ae6e51

File tree

159 files changed

+3540
-2820
lines changed

Some content is hidden

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

159 files changed

+3540
-2820
lines changed

.eslintrc.js

Lines changed: 54 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,61 @@
11
module.exports = {
2-
"extends": [
3-
"eslint:recommended",
4-
"plugin:node/recommended",
5-
"plugin:mocha/recommended",
6-
"plugin:@typescript-eslint/recommended",
7-
],
8-
"parser": "@typescript-eslint/parser",
9-
"plugins": [
10-
"prettier",
11-
"node",
12-
"mocha",
13-
"@typescript-eslint",
14-
],
15-
"env": {
16-
"node": true,
17-
"mocha": true,
18-
"es6": true
2+
extends: ['eslint:recommended', 'plugin:node/recommended', 'plugin:mocha/recommended', 'plugin:@typescript-eslint/recommended'],
3+
parser: '@typescript-eslint/parser',
4+
plugins: ['prettier', 'node', 'mocha', '@typescript-eslint'],
5+
env: {
6+
node: true,
7+
mocha: true,
8+
es6: true,
199
},
20-
"parserOptions": {
21-
"ecmaVersion": 12,
10+
parserOptions: {
11+
ecmaVersion: 12,
2212
},
23-
"globals": {
24-
"assert": false,
25-
"makeTestFeature": false,
26-
"shouldReject": false
13+
globals: {
14+
assert: false,
15+
makeTestFeature: false,
16+
shouldReject: false,
2717
},
28-
"rules": {
29-
"no-extra-semi": "off",
30-
"no-process-exit": "off",
31-
"no-var": "error",
32-
"node/no-extraneous-require": "off",
33-
"node/no-missing-import": "off",
34-
"node/no-missing-require": "off",
35-
"node/no-unpublished-import": "off",
36-
"node/no-unpublished-require": "off",
37-
"node/no-unsupported-features/es-builtins": "error",
38-
"node/no-unsupported-features/es-syntax": "off",
39-
"node/no-unsupported-features/node-builtins": "error",
40-
"node/shebang": "off",
41-
"object-shorthand": "error",
42-
"prefer-arrow-callback": "error",
43-
"prefer-const": "error",
44-
"prefer-template": "error",
45-
"prettier/prettier": [
46-
"error",
18+
rules: {
19+
'no-extra-semi': 'off', //prettier does this
20+
'@typescript-eslint/no-extra-semi': 'off', //prettier does this
21+
'no-process-exit': 'off',
22+
'no-var': 'error',
23+
'node/no-extraneous-import': [
24+
'error',
4725
{
48-
"singleQuote": true,
49-
"trailingComma": "es5",
50-
"semi": false,
51-
"printWidth": 150,
52-
"arrowParens": "avoid"
53-
}
26+
allowModules: ['sinon', 'chai'], //this gets pulled from monorepo root where the tests are run
27+
},
5428
],
55-
"mocha/no-exclusive-tests": "error",
56-
"mocha/no-hooks-for-single-case": "off",
57-
"mocha/no-mocha-arrows": "off",
58-
"mocha/no-pending-tests": "error",
59-
"mocha/no-setup-in-describe": "off",
60-
"strict": ["error", "never"],
61-
"valid-jsdoc": "off",
62-
"@typescript-eslint/no-var-requires": "off", // until we get all js ported over
63-
"@typescript-eslint/no-empty-function": "off",
64-
}
29+
'node/no-missing-import': 'off',
30+
'node/no-missing-require': 'off',
31+
'node/no-unpublished-import': 'off',
32+
'node/no-unpublished-require': 'off',
33+
'node/no-unsupported-features/es-builtins': 'error',
34+
'node/no-unsupported-features/es-syntax': 'off',
35+
'node/no-unsupported-features/node-builtins': 'error',
36+
'node/shebang': 'off',
37+
'object-shorthand': 'error',
38+
'prefer-arrow-callback': 'error',
39+
'prefer-const': 'error',
40+
'prefer-template': 'error',
41+
'prettier/prettier': [
42+
'error',
43+
{
44+
singleQuote: true,
45+
trailingComma: 'es5',
46+
semi: false,
47+
printWidth: 150,
48+
arrowParens: 'avoid',
49+
},
50+
],
51+
'mocha/no-exclusive-tests': 'error',
52+
'mocha/no-hooks-for-single-case': 'off',
53+
'mocha/no-mocha-arrows': 'off',
54+
'mocha/no-pending-tests': 'error',
55+
'mocha/no-setup-in-describe': 'off',
56+
strict: ['error', 'never'],
57+
'valid-jsdoc': 'off',
58+
'@typescript-eslint/no-var-requires': 'off', // until we get all js ported over
59+
'@typescript-eslint/no-empty-function': 'off',
60+
},
6561
}

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ lerna-debug.log
44
node_modules
55
npm-debug.log
66
/packages/**/dist
7+
tsconfig-build.tsbuildinfo
8+
tsconfig.tsbuildinfo

.mocharc.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
module.exports = {
44
bail: true,
55
require: [
6-
'esbuild-register',
7-
'./test/initializers'
6+
'esbuild-register'
87
],
9-
'spec': ['packages/**/*.test.js'],
8+
'spec': ['packages/**/*.test.ts'],
109
}

UPGRADE_GUIDE.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,23 @@
1+
Upgading from 9x to 10x
2+
-------------
3+
4+
- Typscript types are now available for all packages
5+
- Serialport no longer supports Node 10
6+
- 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.
7+
- All packages now have named exports. They export their types and all relevant classes.
8+
- The package `serialport` no longer exports `serialport/test` but instead who classes `{ SerialPort, SerialPortMock }` where the mock is pre-configured with a mock binding.
9+
- Bindings have moved from `@serialport/bindings` to `@serialport/bindings-cpp` they are shipped with `prebuildify` and no longer require a post install download.
10+
- `@serialport/bindings-cpp` leverages N-API and shouldn't need to be upgraded for every node release or rebuild for electron
11+
- Bindings in general now have a new interface with the `@serialport/bindings-interface` type package that replaces `@serialport/bindings-abstract`
12+
- `SerialPortStream` from `@serialport/stream` no longer has a `list()` method as that was a direct call to the bindings.
13+
- `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`.
14+
- `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.
15+
- `SerialPort` is now delivering a few more parsers
16+
17+
TODO
18+
- stop bits are incorrect
19+
20+
121
Upgrading from 8.x to 9.x
222
-------------
323
- Serialport no longer supports Node 8

bin/find-arduino.js renamed to bin/find-arduino.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
#!/usr/bin/env node
1+
#!/usr/bin/env node -r esbuild-register
22

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

5-
const SerialPort = require('../packages/serialport')
6-
SerialPort.list().then(ports => {
5+
import { autoDetect } from '@serialport/bindings-cpp'
6+
autoDetect().list().then(ports => {
77
const port = ports.find(port => /arduino/i.test(port.manufacturer))
88
if (!port) {
99
console.error('Arduino Not found')

bin/write-a-lot.js

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

package-lock.json

Lines changed: 120 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)