mirror of
https://github.com/siemens-mobile-hacks/node-serialport-bindings-cpp.git
synced 2026-11-25 18:37:19 +00:00
chore: upgrade ts and fix type warnings (#91)
This commit is contained in:
parent
0df32592eb
commit
b3cb9c98f3
11 changed files with 49 additions and 27 deletions
|
|
@ -1,3 +1,5 @@
|
|||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
||||
import { assert, shouldReject } from '../test/assert'
|
||||
import { makeTestFeature } from '../test/makeTestFeature'
|
||||
import { BindingInterface, OpenOptions, PortInfo, SetOptions } from '@serialport/bindings-interface'
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import nodeGypBuild from 'node-gyp-build'
|
|||
import { promisify } from 'util'
|
||||
import { join } from 'path'
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const binding = nodeGypBuild(join(__dirname, '../')) as any
|
||||
|
||||
export const asyncClose = binding.close ? promisify(binding.close) : async () => { throw new Error('"binding.close" Method not implemented')}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
// Mocks fs.read for listLinux
|
||||
|
||||
import { EventEmitter } from 'events'
|
||||
|
|
|
|||
|
|
@ -1,32 +1,37 @@
|
|||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
import { Poller } from './poller'
|
||||
import { assert } from '../test/assert'
|
||||
|
||||
class MockPollerBindings {
|
||||
fd: number
|
||||
callback: any
|
||||
lastPollFlag: string
|
||||
lastPollFlag: number
|
||||
constructor(fd: number, callback: any) {
|
||||
this.fd = fd
|
||||
this.callback = callback
|
||||
}
|
||||
poll(flag: string) {
|
||||
poll(flag: number) {
|
||||
this.lastPollFlag = flag
|
||||
setImmediate(() => this.callback(null, flag))
|
||||
}
|
||||
stop() {}
|
||||
destroy() {}
|
||||
}
|
||||
|
||||
class ErrorPollerBindings {
|
||||
fd: number
|
||||
callback: any
|
||||
lastPollFlag: string
|
||||
lastPollFlag: number
|
||||
constructor(fd: number, callback: any) {
|
||||
this.fd = fd
|
||||
this.callback = callback
|
||||
}
|
||||
poll(flag: string) {
|
||||
poll(flag: number) {
|
||||
this.lastPollFlag = flag
|
||||
setImmediate(() => this.callback(new Error('oh no!'), flag))
|
||||
}
|
||||
stop() {}
|
||||
destroy() {}
|
||||
}
|
||||
|
||||
describe('Poller', () => {
|
||||
|
|
@ -37,7 +42,7 @@ describe('Poller', () => {
|
|||
const poller = new Poller(1, MockPollerBindings)
|
||||
poller.once('readable', err => {
|
||||
assert.equal(err, null)
|
||||
assert.equal(poller.poller.lastPollFlag, 1)
|
||||
assert.equal((poller.poller as MockPollerBindings).lastPollFlag, 1)
|
||||
done(err)
|
||||
})
|
||||
})
|
||||
|
|
@ -45,7 +50,7 @@ describe('Poller', () => {
|
|||
const poller = new Poller(1, MockPollerBindings)
|
||||
poller.once('writable', err => {
|
||||
assert.equal(err, null)
|
||||
assert.equal(poller.poller.lastPollFlag, 2)
|
||||
assert.equal((poller.poller as MockPollerBindings).lastPollFlag, 2)
|
||||
done(err)
|
||||
})
|
||||
})
|
||||
|
|
@ -53,7 +58,7 @@ describe('Poller', () => {
|
|||
const poller = new Poller(1, MockPollerBindings)
|
||||
poller.once('disconnect', err => {
|
||||
assert.equal(err, null)
|
||||
assert.equal(poller.poller.lastPollFlag, 4)
|
||||
assert.equal((poller.poller as MockPollerBindings).lastPollFlag, 4)
|
||||
done(err)
|
||||
})
|
||||
})
|
||||
|
|
|
|||
|
|
@ -4,9 +4,19 @@ import { join } from 'path'
|
|||
import nodeGypBuild from 'node-gyp-build'
|
||||
import { BindingsError } from './errors'
|
||||
|
||||
const { Poller: PollerBindings } = nodeGypBuild(join(__dirname, '../')) as any
|
||||
const { Poller: PollerBindings } = nodeGypBuild(join(__dirname, '../')) as { Poller: PollerClass }
|
||||
const logger = debug('serialport/bindings-cpp/poller')
|
||||
|
||||
interface PollerClass {
|
||||
new(fd: number, cb: (err: Error, flag: number)=> void): PollerInstance
|
||||
}
|
||||
|
||||
interface PollerInstance {
|
||||
poll(flag: number): void
|
||||
stop(): void
|
||||
destroy(): void
|
||||
}
|
||||
|
||||
export const EVENTS = {
|
||||
UV_READABLE: 0b0001,
|
||||
UV_WRITABLE: 0b0010,
|
||||
|
|
@ -39,8 +49,8 @@ function handleEvent(error: Error, eventFlag: number) {
|
|||
* Polls unix systems for readable or writable states of a file or serialport
|
||||
*/
|
||||
export class Poller extends EventEmitter {
|
||||
poller: any
|
||||
constructor(fd: number, FDPoller = PollerBindings) {
|
||||
poller: PollerInstance
|
||||
constructor(fd: number, FDPoller: PollerClass = PollerBindings) {
|
||||
logger('Creating poller')
|
||||
super()
|
||||
this.poller = new FDPoller(fd, handleEvent.bind(this))
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
import { BindingsError } from '.'
|
||||
import { assert, shouldReject } from '../test/assert'
|
||||
import { LinuxPortBinding } from './linux'
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
import { assert, shouldReject } from '../test/assert'
|
||||
import { unixWrite } from './unix-write'
|
||||
import { randomBytes } from 'crypto'
|
||||
|
|
|
|||
28
package-lock.json
generated
28
package-lock.json
generated
|
|
@ -23,7 +23,7 @@
|
|||
"@types/chai-subset": "1.3.3",
|
||||
"@types/debug": "4.1.7",
|
||||
"@types/mocha": "10.0.0",
|
||||
"@types/node": "17.0.15",
|
||||
"@types/node": "18.11.9",
|
||||
"@typescript-eslint/eslint-plugin": "5.43.0",
|
||||
"@typescript-eslint/parser": "5.43.0",
|
||||
"cc": "3.0.1",
|
||||
|
|
@ -41,7 +41,7 @@
|
|||
"semantic-release": "19.0.5",
|
||||
"shx": "0.3.4",
|
||||
"sinon": "14.0.2",
|
||||
"typescript": "4.6.3"
|
||||
"typescript": "4.9.3"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=12.17.0 <13.0 || >=14.0.0"
|
||||
|
|
@ -1162,9 +1162,9 @@
|
|||
"dev": true
|
||||
},
|
||||
"node_modules/@types/node": {
|
||||
"version": "17.0.15",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-17.0.15.tgz",
|
||||
"integrity": "sha512-zWt4SDDv1S9WRBNxLFxFRHxdD9tvH8f5/kg5/IaLFdnSNXsDY4eL3Q3XXN+VxUnWIhyVFDwcsmAprvwXoM/ClA==",
|
||||
"version": "18.11.9",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-18.11.9.tgz",
|
||||
"integrity": "sha512-CRpX21/kGdzjOpFsZSkcrXMGIBWMGNIHXXBVFSH+ggkftxg+XYP20TESbh+zFvFj3EQOl5byk0HTRn1IL6hbqg==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/@types/normalize-package-data": {
|
||||
|
|
@ -12716,9 +12716,9 @@
|
|||
}
|
||||
},
|
||||
"node_modules/typescript": {
|
||||
"version": "4.6.3",
|
||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-4.6.3.tgz",
|
||||
"integrity": "sha512-yNIatDa5iaofVozS/uQJEl3JRWLKKGJKh6Yaiv0GLGSuhpFJe7P3SbHZ8/yjAHRQwKRoA6YZqlfjXWmVzoVSMw==",
|
||||
"version": "4.9.3",
|
||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-4.9.3.tgz",
|
||||
"integrity": "sha512-CIfGzTelbKNEnLpLdGFgdyKhG23CKdKgQPOBc+OUNrkJ2vr+KSzsSV5kq5iWhEQbok+quxgGzrAtGWCyU7tHnA==",
|
||||
"dev": true,
|
||||
"bin": {
|
||||
"tsc": "bin/tsc",
|
||||
|
|
@ -14063,9 +14063,9 @@
|
|||
"dev": true
|
||||
},
|
||||
"@types/node": {
|
||||
"version": "17.0.15",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-17.0.15.tgz",
|
||||
"integrity": "sha512-zWt4SDDv1S9WRBNxLFxFRHxdD9tvH8f5/kg5/IaLFdnSNXsDY4eL3Q3XXN+VxUnWIhyVFDwcsmAprvwXoM/ClA==",
|
||||
"version": "18.11.9",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-18.11.9.tgz",
|
||||
"integrity": "sha512-CRpX21/kGdzjOpFsZSkcrXMGIBWMGNIHXXBVFSH+ggkftxg+XYP20TESbh+zFvFj3EQOl5byk0HTRn1IL6hbqg==",
|
||||
"dev": true
|
||||
},
|
||||
"@types/normalize-package-data": {
|
||||
|
|
@ -22824,9 +22824,9 @@
|
|||
}
|
||||
},
|
||||
"typescript": {
|
||||
"version": "4.6.3",
|
||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-4.6.3.tgz",
|
||||
"integrity": "sha512-yNIatDa5iaofVozS/uQJEl3JRWLKKGJKh6Yaiv0GLGSuhpFJe7P3SbHZ8/yjAHRQwKRoA6YZqlfjXWmVzoVSMw==",
|
||||
"version": "4.9.3",
|
||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-4.9.3.tgz",
|
||||
"integrity": "sha512-CIfGzTelbKNEnLpLdGFgdyKhG23CKdKgQPOBc+OUNrkJ2vr+KSzsSV5kq5iWhEQbok+quxgGzrAtGWCyU7tHnA==",
|
||||
"dev": true
|
||||
},
|
||||
"uglify-js": {
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@
|
|||
"@types/chai-subset": "1.3.3",
|
||||
"@types/debug": "4.1.7",
|
||||
"@types/mocha": "10.0.0",
|
||||
"@types/node": "17.0.15",
|
||||
"@types/node": "18.11.9",
|
||||
"@typescript-eslint/eslint-plugin": "5.43.0",
|
||||
"@typescript-eslint/parser": "5.43.0",
|
||||
"cc": "3.0.1",
|
||||
|
|
@ -49,7 +49,7 @@
|
|||
"semantic-release": "19.0.5",
|
||||
"shx": "0.3.4",
|
||||
"sinon": "14.0.2",
|
||||
"typescript": "4.6.3"
|
||||
"typescript": "4.9.3"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=12.17.0 <13.0 || >=14.0.0"
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import { assert, use } from 'chai'
|
|||
import chaiSubset from 'chai-subset'
|
||||
use(chaiSubset)
|
||||
|
||||
export const shouldReject = async (promise: Promise<any>, errType = Error, message = 'Should have rejected') => {
|
||||
export const shouldReject = async (promise: Promise<unknown>, errType = Error, message = 'Should have rejected') => {
|
||||
try {
|
||||
await promise
|
||||
} catch (err) {
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
import testConfig from './config.json'
|
||||
|
||||
export const makeTestFeature = (envName: string, testPort?: string) => {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue