[pkg] Update prettier to version 2.0.5
This commit is contained in:
@@ -2,3 +2,4 @@ arrowParens: always
|
||||
endOfLine: lf
|
||||
proseWrap: always
|
||||
singleQuote: true
|
||||
trailingComma: none
|
||||
|
||||
@@ -10,7 +10,8 @@ os:
|
||||
- osx
|
||||
- windows
|
||||
script:
|
||||
- if [ "${TRAVIS_NODE_VERSION}" == "14" ] && [ "${TRAVIS_OS_NAME}" == linux ]; then npm run lint; fi
|
||||
- if [ "${TRAVIS_NODE_VERSION}" == "14" ] && [ "${TRAVIS_OS_NAME}" == linux ];
|
||||
then npm run lint; fi
|
||||
- npm test
|
||||
after_success:
|
||||
- nyc report --reporter=text-lcov | coveralls
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = function() {
|
||||
module.exports = function () {
|
||||
throw new Error(
|
||||
'ws does not work in the browser. Browser clients must use the native ' +
|
||||
'WebSocket object'
|
||||
|
||||
@@ -26,7 +26,7 @@ const sessionParser = session({
|
||||
app.use(express.static('public'));
|
||||
app.use(sessionParser);
|
||||
|
||||
app.post('/login', function(req, res) {
|
||||
app.post('/login', function (req, res) {
|
||||
//
|
||||
// "Log in" user and set userId to session.
|
||||
//
|
||||
@@ -37,11 +37,11 @@ app.post('/login', function(req, res) {
|
||||
res.send({ result: 'OK', message: 'Session updated' });
|
||||
});
|
||||
|
||||
app.delete('/logout', function(request, response) {
|
||||
app.delete('/logout', function (request, response) {
|
||||
const ws = map.get(request.session.userId);
|
||||
|
||||
console.log('Destroying session');
|
||||
request.session.destroy(function() {
|
||||
request.session.destroy(function () {
|
||||
if (ws) ws.close();
|
||||
|
||||
response.send({ result: 'OK', message: 'Session destroyed' });
|
||||
@@ -54,7 +54,7 @@ app.delete('/logout', function(request, response) {
|
||||
const server = http.createServer(app);
|
||||
const wss = new WebSocket.Server({ clientTracking: false, noServer: true });
|
||||
|
||||
server.on('upgrade', function(request, socket, head) {
|
||||
server.on('upgrade', function (request, socket, head) {
|
||||
console.log('Parsing session from request...');
|
||||
|
||||
sessionParser(request, {}, () => {
|
||||
@@ -65,25 +65,25 @@ server.on('upgrade', function(request, socket, head) {
|
||||
|
||||
console.log('Session is parsed!');
|
||||
|
||||
wss.handleUpgrade(request, socket, head, function(ws) {
|
||||
wss.handleUpgrade(request, socket, head, function (ws) {
|
||||
wss.emit('connection', ws, request);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
wss.on('connection', function(ws, request) {
|
||||
wss.on('connection', function (ws, request) {
|
||||
const userId = request.session.userId;
|
||||
|
||||
map.set(userId, ws);
|
||||
|
||||
ws.on('message', function(message) {
|
||||
ws.on('message', function (message) {
|
||||
//
|
||||
// Here we can now use session parameters.
|
||||
//
|
||||
console.log(`Received message ${message} from user ${userId}`);
|
||||
});
|
||||
|
||||
ws.on('close', function() {
|
||||
ws.on('close', function () {
|
||||
map.delete(userId);
|
||||
});
|
||||
});
|
||||
@@ -91,6 +91,6 @@ wss.on('connection', function(ws, request) {
|
||||
//
|
||||
// Start the server.
|
||||
//
|
||||
server.listen(8080, function() {
|
||||
server.listen(8080, function () {
|
||||
console.log('Listening on http://localhost:8080');
|
||||
});
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
(function() {
|
||||
(function () {
|
||||
const messages = document.querySelector('#messages');
|
||||
const wsButton = document.querySelector('#wsButton');
|
||||
const wsSendButton = document.querySelector('#wsSendButton');
|
||||
@@ -16,46 +16,46 @@
|
||||
: Promise.reject(new Error('Unexpected response'));
|
||||
}
|
||||
|
||||
login.onclick = function() {
|
||||
login.onclick = function () {
|
||||
fetch('/login', { method: 'POST', credentials: 'same-origin' })
|
||||
.then(handleResponse)
|
||||
.then(showMessage)
|
||||
.catch(function(err) {
|
||||
.catch(function (err) {
|
||||
showMessage(err.message);
|
||||
});
|
||||
};
|
||||
|
||||
logout.onclick = function() {
|
||||
logout.onclick = function () {
|
||||
fetch('/logout', { method: 'DELETE', credentials: 'same-origin' })
|
||||
.then(handleResponse)
|
||||
.then(showMessage)
|
||||
.catch(function(err) {
|
||||
.catch(function (err) {
|
||||
showMessage(err.message);
|
||||
});
|
||||
};
|
||||
|
||||
let ws;
|
||||
|
||||
wsButton.onclick = function() {
|
||||
wsButton.onclick = function () {
|
||||
if (ws) {
|
||||
ws.onerror = ws.onopen = ws.onclose = null;
|
||||
ws.close();
|
||||
}
|
||||
|
||||
ws = new WebSocket(`ws://${location.host}`);
|
||||
ws.onerror = function() {
|
||||
ws.onerror = function () {
|
||||
showMessage('WebSocket error');
|
||||
};
|
||||
ws.onopen = function() {
|
||||
ws.onopen = function () {
|
||||
showMessage('WebSocket connection established');
|
||||
};
|
||||
ws.onclose = function() {
|
||||
ws.onclose = function () {
|
||||
showMessage('WebSocket connection closed');
|
||||
ws = null;
|
||||
};
|
||||
};
|
||||
|
||||
wsSendButton.onclick = function() {
|
||||
wsSendButton.onclick = function () {
|
||||
if (!ws) {
|
||||
showMessage('No WebSocket connection');
|
||||
return;
|
||||
|
||||
@@ -12,9 +12,9 @@ app.use(express.static(path.join(__dirname, '/public')));
|
||||
const server = createServer(app);
|
||||
const wss = new WebSocket.Server({ server });
|
||||
|
||||
wss.on('connection', function(ws) {
|
||||
const id = setInterval(function() {
|
||||
ws.send(JSON.stringify(process.memoryUsage()), function() {
|
||||
wss.on('connection', function (ws) {
|
||||
const id = setInterval(function () {
|
||||
ws.send(JSON.stringify(process.memoryUsage()), function () {
|
||||
//
|
||||
// Ignore errors.
|
||||
//
|
||||
@@ -22,12 +22,12 @@ wss.on('connection', function(ws) {
|
||||
}, 100);
|
||||
console.log('started client interval');
|
||||
|
||||
ws.on('close', function() {
|
||||
ws.on('close', function () {
|
||||
console.log('stopping client interval');
|
||||
clearInterval(id);
|
||||
});
|
||||
});
|
||||
|
||||
server.listen(8080, function() {
|
||||
server.listen(8080, function () {
|
||||
console.log('Listening on http://localhost:8080');
|
||||
});
|
||||
|
||||
@@ -89,7 +89,7 @@ function createWebSocketStream(ws, options) {
|
||||
duplex.push(null);
|
||||
});
|
||||
|
||||
duplex._destroy = function(err, callback) {
|
||||
duplex._destroy = function (err, callback) {
|
||||
if (ws.readyState === ws.CLOSED) {
|
||||
callback(err);
|
||||
process.nextTick(emitClose, duplex);
|
||||
@@ -110,7 +110,7 @@ function createWebSocketStream(ws, options) {
|
||||
ws.terminate();
|
||||
};
|
||||
|
||||
duplex._final = function(callback) {
|
||||
duplex._final = function (callback) {
|
||||
if (ws.readyState === ws.CONNECTING) {
|
||||
ws.once('open', function open() {
|
||||
duplex._final(callback);
|
||||
@@ -138,14 +138,14 @@ function createWebSocketStream(ws, options) {
|
||||
}
|
||||
};
|
||||
|
||||
duplex._read = function() {
|
||||
duplex._read = function () {
|
||||
if (ws.readyState === ws.OPEN && !resumeOnReceiverDrain) {
|
||||
resumeOnReceiverDrain = true;
|
||||
if (!ws._receiver._writableState.needDrain) ws._socket.resume();
|
||||
}
|
||||
};
|
||||
|
||||
duplex._write = function(chunk, encoding, callback) {
|
||||
duplex._write = function (chunk, encoding, callback) {
|
||||
if (ws.readyState === ws.CONNECTING) {
|
||||
ws.once('open', function open() {
|
||||
duplex._write(chunk, encoding, callback);
|
||||
|
||||
@@ -51,7 +51,7 @@
|
||||
"eslint-plugin-prettier": "^3.0.1",
|
||||
"mocha": "^7.0.0",
|
||||
"nyc": "^15.0.0",
|
||||
"prettier": "^1.17.0",
|
||||
"prettier": "^2.0.5",
|
||||
"utf-8-validate": "^5.0.2"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,7 +112,7 @@ describe('WebSocketServer', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('uses a precreated http server listening on unix socket', function(done) {
|
||||
it('uses a precreated http server listening on unix socket', function (done) {
|
||||
//
|
||||
// Skip this test on Windows as it throws errors for obvious reasons.
|
||||
//
|
||||
|
||||
@@ -26,7 +26,7 @@ describe('WebSocket', () => {
|
||||
);
|
||||
});
|
||||
|
||||
it('accepts `url.URL` objects as url', function(done) {
|
||||
it('accepts `url.URL` objects as url', function (done) {
|
||||
const agent = new CustomAgent();
|
||||
|
||||
agent.addRequest = (req, opts) => {
|
||||
@@ -1345,9 +1345,7 @@ describe('WebSocket', () => {
|
||||
'Invalid WebSocket frame: MASK must be set'
|
||||
);
|
||||
assert.ok(
|
||||
Buffer.concat(chunks)
|
||||
.slice(0, 2)
|
||||
.equals(Buffer.from('8102', 'hex'))
|
||||
Buffer.concat(chunks).slice(0, 2).equals(Buffer.from('8102', 'hex'))
|
||||
);
|
||||
|
||||
ws.on('close', (code, reason) => {
|
||||
|
||||
Reference in New Issue
Block a user