Skip to content

Commit abf6476

Browse files
committed
Remove lowercase options and properly define .path (#898)
1 parent 5784722 commit abf6476

File tree

6 files changed

+45
-40
lines changed

6 files changed

+45
-40
lines changed

packages/serialport-util/packages/node-serialport/.travis.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ before_install:
7171
- if [[ $TRAVIS_BRANCH == `git describe --tags --always HEAD` ]]; then PUBLISH_BINARY=true; fi;
7272
- echo "Publishing native platform Binary Package? ->" $PUBLISH_BINARY
7373

74+
# Cleanup the output of npm
75+
- npm config set progress false
76+
- npm config set spin false
77+
7478
install:
7579
# ensure source install works
7680
- npm install --build-from-source

packages/serialport-util/packages/node-serialport/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,12 @@ Enjoy and do cool things with this code.
294294
### SerialPort ⏏
295295
**Kind**: Exported class
296296
**Emits**: <code>[open](#module_serialport--SerialPort+event_open)</code>, <code>[data](#module_serialport--SerialPort+event_data)</code>, <code>[close](#module_serialport--SerialPort+event_close)</code>, <code>[error](#module_serialport--SerialPort+event_error)</code>, <code>[disconnect](#module_serialport--SerialPort+event_disconnect)</code>
297+
**Properties**
298+
299+
| Name | Type | Description |
300+
| --- | --- | --- |
301+
| path | <code>string</code> | The system path or name of the serial port. Read Only. |
302+
297303

298304
-
299305

packages/serialport-util/packages/node-serialport/appveyor.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ install:
6262
}
6363
true;
6464
65+
# Cleanup the output of npm
66+
- ps: >
67+
npm config set progress false
68+
npm config set spin false
69+
6570
# We don't currently have a port to test on windows
6671
# - ps: $env:TEST_PORT = "COM1";
6772

packages/serialport-util/packages/node-serialport/lib/serialport.js

Lines changed: 12 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -56,27 +56,6 @@ var defaultSetFlags = {
5656
rts: true
5757
};
5858

59-
// deprecate the lowercase version of these options next major release
60-
var LOWERCASE_OPTIONS = [
61-
'baudRate',
62-
'dataBits',
63-
'stopBits',
64-
'bufferSize',
65-
'platformOptions'
66-
];
67-
68-
function correctOptions(options) {
69-
LOWERCASE_OPTIONS.forEach(function(name) {
70-
var lowerName = name.toLowerCase();
71-
if (options.hasOwnProperty(lowerName)) {
72-
var value = options[lowerName];
73-
delete options[lowerName];
74-
options[name] = value;
75-
}
76-
});
77-
return options;
78-
}
79-
8059
/**
8160
* A callback called with an error or null.
8261
* @typedef {function} errorCallback
@@ -110,6 +89,7 @@ function correctOptions(options) {
11089
* @param {module:serialport~openOptions=} options - Port configuration options
11190
* @param {module:serialport~errorCallback=} openCallback - Called when a connection has been opened. If this is not provided and an error occurs, it will be emitted on the ports `error` event. The callback will NOT be called if autoOpen is set to false in the openOptions as the open will not be performed.
11291
* @throws {TypeError} When given invalid arguments a TypeError will be thrown.
92+
* @property {string} path The system path or name of the serial port. Read Only.
11393
* @emits module:serialport#open
11494
* @emits module:serialport#data
11595
* @emits module:serialport#close
@@ -122,6 +102,8 @@ function SerialPort(path, options, callback) {
122102
return new SerialPort(path, options, callback);
123103
}
124104

105+
stream.Stream.call(this);
106+
125107
if (typeof callback === 'boolean') {
126108
throw new TypeError('`openImmediately` is now called `autoOpen` and is a property of options');
127109
}
@@ -131,19 +113,19 @@ function SerialPort(path, options, callback) {
131113
options = {};
132114
}
133115

134-
options = options || {};
116+
var settings = assign({}, defaultSettings, options);
135117

136-
stream.Stream.call(this);
118+
Object.defineProperty(this, 'path', {
119+
enumerable: true,
120+
writable: false,
121+
value: path
122+
});
137123

138-
if (!path) {
124+
125+
if (!this.path) {
139126
throw new TypeError('No path specified');
140127
}
141128

142-
this.path = path;
143-
144-
var correctedOptions = correctOptions(options);
145-
var settings = assign({}, defaultSettings, correctedOptions);
146-
147129
if (typeof settings.baudRate !== 'number') {
148130
throw new TypeError('Invalid "baudRate" must be a number got: ' + settings.baudRate);
149131
}
@@ -269,8 +251,7 @@ SerialPort.prototype.update = function(options, callback) {
269251
return this._error(new Error('Port is not open'), callback);
270252
}
271253

272-
var correctedOptions = correctOptions(options);
273-
var settings = assign({}, defaultSettings, correctedOptions);
254+
var settings = assign({}, defaultSettings, options);
274255
this.options.baudRate = settings.baudRate;
275256

276257
SerialPortBinding.update(this.fd, this.options, function(err) {

packages/serialport-util/packages/node-serialport/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@
9494
"stress": "mocha --no-timeouts test/arduinoTest/stress.js",
9595
"lint": "eslint *.js lib/**/*.js test/**/*.js bin/**/*.js examples/**/*.js",
9696
"test": "istanbul cover ./node_modules/mocha/bin/_mocha test/*.js test/arduinoTest/integration.js test/integration-lite.js",
97+
"test:unit": "mocha test/*.js test/arduinoTest/integration.js test/integration-lite.js",
9798
"report-coverage": "cat ./coverage/lcov.info | coveralls",
9899
"valgrind": "valgrind --leak-check=full --show-possibly-lost=no node --expose-gc --trace-gc node_modules/.bin/grunt test"
99100
},

packages/serialport-util/packages/node-serialport/test/serialport.js

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,6 @@ describe('SerialPort', function() {
3737
done();
3838
}
3939
});
40-
41-
it('takes lowercase options', function(done) {
42-
var port = new SerialPort.SerialPort('/dev/exists', { baudrate: 14400, autoOpen: false });
43-
assert.equal(port.options.baudRate, 14400);
44-
done();
45-
});
46-
4740
});
4841

4942
describe('Constructor', function() {
@@ -118,7 +111,7 @@ describe('SerialPort', function() {
118111

119112
it('errors with invalid databits', function(done) {
120113
try {
121-
this.port = new SerialPort('/dev/exists', { databits: 19 });
114+
this.port = new SerialPort('/dev/exists', { dataBits: 19 });
122115
} catch(err){
123116
assert.instanceOf(err, Error);
124117
done();
@@ -127,7 +120,7 @@ describe('SerialPort', function() {
127120

128121
it('errors with invalid stopbits', function(done) {
129122
try {
130-
this.port = new SerialPort('/dev/exists', { stopbits: 19 });
123+
this.port = new SerialPort('/dev/exists', { stopBits: 19 });
131124
} catch(err){
132125
assert.instanceOf(err, Error);
133126
done();
@@ -173,6 +166,21 @@ describe('SerialPort', function() {
173166
});
174167
});
175168

169+
describe('Properties', function() {
170+
describe('.path', function(){
171+
it('is a read only property set during construction', function(){
172+
var port = new SerialPort('/dev/exists', {autoOpen: false});
173+
assert.equal(port.path, '/dev/exists');
174+
try {
175+
port.path = 'foo';
176+
} catch(e) {
177+
assert.instanceOf(e, TypeError);
178+
}
179+
assert.equal(port.path, '/dev/exists');
180+
});
181+
});
182+
});
183+
176184
describe('Methods', function() {
177185
describe('#open', function() {
178186
it('passes the port to the bindings', function(done) {

0 commit comments

Comments
 (0)