Skip to content

Commit

Permalink
feature: make serialport an optional depedency (#1130)
Browse files Browse the repository at this point in the history
  • Loading branch information
sbender9 authored Sep 15, 2020
1 parent f8722ad commit c734b58
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@
"@signalk/signalk-schema": "1.5.0",
"@signalk/streams": "1.15.x",
"@types/debug": "^4.1.5",
"@types/serialport": "^8.0.1",
"baconjs": "^1.0.1",
"bcryptjs": "^2.4.3",
"body-parser": "^1.14.1",
Expand Down Expand Up @@ -112,7 +111,6 @@
"pem": "^1.14.3",
"primus": "^7.0.0",
"semver": "^7.1.1",
"serialport": "^9.0.1",
"spdy": "^4.0.0",
"split": "^1.0.0",
"stat-mode": "^1.0.0",
Expand All @@ -129,14 +127,16 @@
"@signalk/signalk-to-nmea0183": "^1.0.0",
"@signalk/simplegauges": "^1.0.1",
"@signalk/zones": "^1.0.0",
"mdns": "^2.5.1"
"mdns": "^2.5.1",
"serialport": "^9.0.1"
},
"devDependencies": {
"@signalk/github-create-release": "^1.0.0",
"@types/express": "^4.17.1",
"@types/lodash": "^4.14.139",
"@types/node-fetch": "^2.5.3",
"@types/semver": "^7.1.0",
"@types/serialport": "^8.0.1",
"@types/split": "^1.0.0",
"chai": "^4.0.0",
"chai-json-equal": "0.0.1",
Expand Down
9 changes: 6 additions & 3 deletions src/serialports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,12 @@
*/

import fs from 'fs'
import SerialPort from 'serialport'

export interface Ports {
byId: string[]
byPath: string[]
byOpenPlotter: string[]
serialports: SerialPort.PortInfo[]
serialports: any
}

export const listAllSerialPorts = (): Promise<Ports> => {
Expand All @@ -40,7 +39,11 @@ export const listAllSerialPorts = (): Promise<Ports> => {
}

function listSerialPorts() {
return SerialPort.list()
try {
return require('serialport').list()
} catch ( err ) {
return Promise.resolve([])
}
}

function listSafeSerialPortsDevSerialById() {
Expand Down

0 comments on commit c734b58

Please sign in to comment.