From ecbffdf88593438f153f826fc7e394d5122c1f92 Mon Sep 17 00:00:00 2001 From: Ward Peeters Date: Thu, 25 Feb 2021 12:09:22 +0100 Subject: [PATCH 1/2] chore(gatsby): upgrade socket.io --- packages/gatsby/package.json | 7 +- packages/gatsby/src/commands/develop.ts | 8 +- .../src/utils/__tests__/websocket-manager.ts | 33 ++- .../gatsby/src/utils/websocket-manager.ts | 29 +-- yarn.lock | 217 ++++++++---------- 5 files changed, 142 insertions(+), 152 deletions(-) diff --git a/packages/gatsby/package.json b/packages/gatsby/package.json index d70650a604f1e..6886bf54abc91 100644 --- a/packages/gatsby/package.json +++ b/packages/gatsby/package.json @@ -138,8 +138,8 @@ "shallow-compare": "^1.2.2", "signal-exit": "^3.0.3", "slugify": "^1.4.4", - "socket.io": "2.3.0", - "socket.io-client": "2.3.0", + "socket.io": "3.1.1", + "socket.io-client": "3.1.1", "source-map": "^0.7.3", "source-map-support": "^0.5.19", "st": "^2.0.0", @@ -175,7 +175,6 @@ "@types/reach__router": "^1.3.5", "@types/semver": "^7.1.0", "@types/signal-exit": "^3.0.0", - "@types/socket.io": "^2.1.4", "@types/string-similarity": "^3.0.0", "@types/tmp": "^0.2.0", "@types/webpack-virtual-modules": "^0.1.0", @@ -261,4 +260,4 @@ "yargs": { "boolean-negation": false } -} +} \ No newline at end of file diff --git a/packages/gatsby/src/commands/develop.ts b/packages/gatsby/src/commands/develop.ts index 6d55698be9f88..8915cb6451a7d 100644 --- a/packages/gatsby/src/commands/develop.ts +++ b/packages/gatsby/src/commands/develop.ts @@ -344,7 +344,13 @@ module.exports = async (program: IProgram): Promise => { : http.createServer() statusServer.listen(statusServerPort) - const io = socket(statusServer) + const io = socket(statusServer, { + // whitelist all (https://github.com/expressjs/cors#configuration-options) + cors: { + origin: true, + }, + cookie: true, + }) const handleChildProcessIPC = (msg): void => { if (msg.type === `HEARTBEAT`) return diff --git a/packages/gatsby/src/utils/__tests__/websocket-manager.ts b/packages/gatsby/src/utils/__tests__/websocket-manager.ts index c1894c0081efe..3bc382c81ad4c 100644 --- a/packages/gatsby/src/utils/__tests__/websocket-manager.ts +++ b/packages/gatsby/src/utils/__tests__/websocket-manager.ts @@ -19,6 +19,11 @@ jest.mock(`fs-extra`, () => { } }) +// we mock it to make tests faster +jest.mock(`gatsby-cli/lib/reporter`, () => { + return {} +}) + const INTERVAL_TIMEOUT = 500 const TEST_TIMEOUT = 30000 @@ -49,9 +54,13 @@ describe(`websocket-manager`, () => { let websocketManager: WebsocketManager let httpServerAddr - async function getClientSocket(): Promise { + function getClientSocket(): typeof io.Socket { + return io.default(`http://127.0.0.1:${httpServerAddr.port}`) + } + + function getClientSocketAndWaitForConnect(): Promise { return new Promise(resolve => { - const clientSocket = io.default(`http://127.0.0.1:${httpServerAddr.port}`) + const clientSocket = getClientSocket() clientSocket.on(`connect`, () => { resolve(clientSocket) }) @@ -149,7 +158,7 @@ describe(`websocket-manager`, () => { `Can connect`, async () => { expect.assertions(1) - const clientSocket = await getClientSocket() + const clientSocket = await getClientSocketAndWaitForConnect() expect(clientSocket.connected).toBe(true) clientSocket.disconnect() }, @@ -170,7 +179,7 @@ describe(`websocket-manager`, () => { async () => { expect.assertions(3) - const clientSocket = await getClientSocket() + const clientSocket = await getClientSocketAndWaitForConnect() expect(websocketManager.activePaths).toEqual(new Set()) @@ -202,8 +211,8 @@ describe(`websocket-manager`, () => { `track individual clients`, async () => { expect.assertions(5) - const clientSocket1 = await getClientSocket() - const clientSocket2 = await getClientSocket() + const clientSocket1 = await getClientSocketAndWaitForConnect() + const clientSocket2 = await getClientSocketAndWaitForConnect() expect(websocketManager.activePaths).toEqual(new Set()) let activePathAdjustedPromise = waitUntil(done => { @@ -261,7 +270,7 @@ describe(`websocket-manager`, () => { async function registerPathnameAndGetPath( pathname: string ): Promise { - const clientSocket = await getClientSocket() + const clientSocket = await getClientSocketAndWaitForConnect() if (websocketManager.activePaths.size > 0) { throw new Error(`There was client connected already`) @@ -465,7 +474,7 @@ describe(`websocket-manager`, () => { `Client can receive page query update`, async () => { expect.assertions(1) - const clientSocket = await getClientSocket() + const clientSocket = await getClientSocketAndWaitForConnect() const pageQueryId = `/blog/` const result = { @@ -512,7 +521,7 @@ describe(`websocket-manager`, () => { `Client can receive static query update`, async () => { expect.assertions(1) - const clientSocket = await getClientSocket() + const clientSocket = await getClientSocketAndWaitForConnect() const staticQueryId = `12345` const result = { @@ -553,7 +562,7 @@ describe(`websocket-manager`, () => { it(`Emits errors to display by clients`, async done => { expect.assertions(1) - const clientSocket = await getClientSocket() + const clientSocket = await getClientSocketAndWaitForConnect() function handler(msg): void { if ( @@ -575,7 +584,7 @@ describe(`websocket-manager`, () => { it(`Emits stored errors to new clients`, async done => { expect.assertions(1) - const clientSocket = await getClientSocket() + const clientSocket = getClientSocket() function handler(msg): void { if ( @@ -597,7 +606,7 @@ describe(`websocket-manager`, () => { it(`Can clear errors by emitting empty "overlayError" msg`, async done => { expect.assertions(1) - const clientSocket = await getClientSocket() + const clientSocket = await getClientSocketAndWaitForConnect() function handler(msg): void { if ( diff --git a/packages/gatsby/src/utils/websocket-manager.ts b/packages/gatsby/src/utils/websocket-manager.ts index 760f8735ac8ce..f77669ce5c29f 100644 --- a/packages/gatsby/src/utils/websocket-manager.ts +++ b/packages/gatsby/src/utils/websocket-manager.ts @@ -10,7 +10,7 @@ import telemetry from "gatsby-telemetry" import url from "url" import { createHash } from "crypto" import { findPageByPath } from "./find-page-by-path" -import socketIO from "socket.io" +import io from "socket.io" export interface IPageQueryResult { id: string @@ -31,7 +31,7 @@ function hashPaths(paths: Array): Array { interface IClientInfo { activePath: string | null - socket: socketIO.Socket + socket: io.Socket } export class WebsocketManager { @@ -40,19 +40,22 @@ export class WebsocketManager { errors: Map = new Map() pageResults: PageResultsMap = new Map() staticQueryResults: QueryResultsMap = new Map() - websocket: socketIO.Server | undefined - - init = ({ - server, - }: { - server: HTTPSServer | HTTPServer - }): socketIO.Server => { - this.websocket = socketIO(server, { + websocket: io.Server | undefined + + init = ({ server }: { server: HTTPSServer | HTTPServer }): io.Server => { + // make typescript happy, else it complained about this.websocket being undefined + const websocket = io(server, { // we see ping-pong timeouts on gatsby-cloud when socket.io is running for a while // increasing it should help // @see https://github.com/socketio/socket.io/issues/3259#issuecomment-448058937 pingTimeout: 30000, + // whitelist all (https://github.com/expressjs/cors#configuration-options) + cors: { + origin: true, + }, + cookie: true, }) + this.websocket = websocket const updateServerActivePaths = (): void => { const serverActivePaths = new Set() @@ -64,7 +67,7 @@ export class WebsocketManager { this.activePaths = serverActivePaths } - this.websocket.on(`connection`, socket => { + websocket.on(`connection`, socket => { const clientInfo: IClientInfo = { activePath: null, socket, @@ -148,10 +151,10 @@ export class WebsocketManager { this.emitStalePageDataPathsFromStaticQueriesAssignment.bind(this) ) - return this.websocket + return websocket } - getSocket = (): socketIO.Server | undefined => this.websocket + getSocket = (): io.Server | undefined => this.websocket emitStaticQueryData = (data: IStaticQueryResult): void => { this.staticQueryResults.set(data.id, data) diff --git a/yarn.lock b/yarn.lock index acd781289470b..6a09322d5eea8 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4977,6 +4977,11 @@ resolved "https://registry.yarnpkg.com/@types/common-tags/-/common-tags-1.8.0.tgz#79d55e748d730b997be5b7fce4b74488d8b26a6b" integrity sha512-htRqZr5qn8EzMelhX/Xmx142z218lLyGaeZ3YR8jlze4TATRU9huKKvuBmAJEW4LCC4pnY1N6JAm6p85fMHjhg== +"@types/component-emitter@^1.2.10": + version "1.2.10" + resolved "https://registry.yarnpkg.com/@types/component-emitter/-/component-emitter-1.2.10.tgz#ef5b1589b9f16544642e473db5ea5639107ef3ea" + integrity sha512-bsjleuRKWmGqajMerkzox19aGbscQX5rmmvvXl3wlIp5gMG1HgkiwPxsN5p070fBDKTNSPgojVbuY1+HWMbFhg== + "@types/configstore@^2.1.1": version "2.1.1" resolved "https://registry.yarnpkg.com/@types/configstore/-/configstore-2.1.1.tgz#cd1e8553633ad3185c3f2f239ecff5d2643e92b6" @@ -4998,6 +5003,11 @@ resolved "https://registry.yarnpkg.com/@types/cookie/-/cookie-0.4.0.tgz#14f854c0f93d326e39da6e3b6f34f7d37513d108" integrity sha512-y7mImlc/rNkvCRmg8gC3/lj87S7pTUIJ6QGjwHR9WQJcFs+ZMTOaoPrkdFA/YdbuqVEmEbb5RdhVxMkAcgOnpg== +"@types/cors@^2.8.8": + version "2.8.10" + resolved "https://registry.yarnpkg.com/@types/cors/-/cors-2.8.10.tgz#61cc8469849e5bcdd0c7044122265c39cec10cf4" + integrity sha512-C7srjHiVG3Ey1nR6d511dtDkCEjxuN9W1HWAEjGq8kpcwmNM6JJkpC0xvabM7BXTG2wDq8Eu33iH9aQKa7IvLQ== + "@types/debug@^0.0.30": version "0.0.30" resolved "https://registry.yarnpkg.com/@types/debug/-/debug-0.0.30.tgz#dc1e40f7af3b9c815013a7860e6252f6352a84df" @@ -5272,6 +5282,11 @@ resolved "https://registry.yarnpkg.com/@types/node/-/node-12.19.12.tgz#04793c2afa4ce833a9972e4c476432e30f9df47b" integrity sha512-UwfL2uIU9arX/+/PRcIkT08/iBadGN2z6ExOROA2Dh5mAuWTBj6iJbQX4nekiV5H8cTrEG569LeX+HRco9Cbxw== +"@types/node@^14.14.10": + version "14.14.31" + resolved "https://registry.yarnpkg.com/@types/node/-/node-14.14.31.tgz#72286bd33d137aa0d152d47ec7c1762563d34055" + integrity sha512-vFHy/ezP5qI0rFgJ7aQnjDXwAMrG0KqqIH7tQG5PPv3BWBayOPIQNBjVc/P6hhdZfMx51REc6tfDNXHUio893g== + "@types/node@^8.5.7": version "8.10.59" resolved "https://registry.yarnpkg.com/@types/node/-/node-8.10.59.tgz#9e34261f30183f9777017a13d185dfac6b899e04" @@ -5417,13 +5432,6 @@ resolved "https://registry.yarnpkg.com/@types/socket.io-client/-/socket.io-client-1.4.35.tgz#9f3d38b2f548d64beab4510b4eddc5a526b81724" integrity sha512-MI8YmxFS+jMkIziycT5ickBWK1sZwDwy16mgH/j99Mcom6zRG/NimNGQ3vJV0uX5G6g/hEw0FG3w3b3sT5OUGw== -"@types/socket.io@^2.1.4": - version "2.1.4" - resolved "https://registry.yarnpkg.com/@types/socket.io/-/socket.io-2.1.4.tgz#674e7bc193c5ccdadd4433f79f3660d31759e9ac" - integrity sha512-cI98INy7tYnweTsUlp8ocveVdAxENUThO0JsLSCs51cjOP2yV5Mqo5QszMDPckyRRA+PO6+wBgKvGvHUCc23TQ== - dependencies: - "@types/node" "*" - "@types/source-list-map@*": version "0.1.2" resolved "https://registry.yarnpkg.com/@types/source-list-map/-/source-list-map-0.1.2.tgz#0078836063ffaf17412349bba364087e0ac02ec9" @@ -7389,7 +7397,7 @@ babylon@^6.18.0: version "6.18.0" resolved "https://registry.yarnpkg.com/babylon/-/babylon-6.18.0.tgz#af2f3b88fa6f5c1e4c634d1a0f8eac4f55b395e3" -backo2@1.0.2, backo2@^1.0.2: +backo2@1.0.2, backo2@^1.0.2, backo2@~1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/backo2/-/backo2-1.0.2.tgz#31ab1ac8b129363463e35b3ebb69f4dfcfba7947" @@ -7401,6 +7409,11 @@ balanced-match@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.0.tgz#89b4d199ab2bee49de164ea02b89ce462d71b767" +base64-arraybuffer@0.1.4: + version "0.1.4" + resolved "https://registry.yarnpkg.com/base64-arraybuffer/-/base64-arraybuffer-0.1.4.tgz#9818c79e059b1355f97e0428a017c838e90ba812" + integrity sha1-mBjHngWbE1X5fgQooBfIOOkLqBI= + base64-arraybuffer@0.1.5: version "0.1.5" resolved "https://registry.yarnpkg.com/base64-arraybuffer/-/base64-arraybuffer-0.1.5.tgz#73926771923b5a19747ad666aa5cd4bf9c6e9ce8" @@ -7409,7 +7422,7 @@ base64-js@^1.0.2, base64-js@^1.1.2: version "1.3.0" resolved "https://registry.yarnpkg.com/base64-js/-/base64-js-1.3.0.tgz#cab1e6118f051095e58b5281aea8c1cd22bfc0e3" -base64id@2.0.0: +base64id@2.0.0, base64id@~2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/base64id/-/base64id-2.0.0.tgz#2770ac6bc47d312af97a8bf9a634342e0cd25cb6" integrity sha512-lGe34o6EHj9y3Kts9R4ZYs/Gr+6N7MCaMlIFA3F1R2O5/m7K06AxfSeO5530PEERE6/WyEg3lsuyw4GHlPZHog== @@ -7445,12 +7458,6 @@ before-after-hook@^2.0.0: resolved "https://registry.yarnpkg.com/before-after-hook/-/before-after-hook-2.1.0.tgz#b6c03487f44e24200dd30ca5e6a1979c5d2fb635" integrity sha512-IWIbu7pMqyw3EAJHzzHbWa85b6oud/yfKYg5rqB5hNE8CeMi3nX+2C2sj0HswfblST86hpVEOAb9x34NZd6P7A== -better-assert@~1.0.0: - version "1.0.2" - resolved "https://registry.yarnpkg.com/better-assert/-/better-assert-1.0.2.tgz#40866b9e1b9e0b55b481894311e68faffaebc522" - dependencies: - callsite "1.0.0" - better-opn@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/better-opn/-/better-opn-2.0.0.tgz#c70d198e51164bdc220306a28a885d9ac7a14c44" @@ -8132,10 +8139,6 @@ caller-path@^2.0.0: dependencies: caller-callsite "^2.0.0" -callsite@1.0.0: - version "1.0.0" - resolved "https://registry.yarnpkg.com/callsite/-/callsite-1.0.0.tgz#280398e5d664bd74038b6f0905153e6e8af1bc20" - callsites@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/callsites/-/callsites-2.0.0.tgz#06eb84f00eea413da86affefacbffb36093b3c50" @@ -9351,16 +9354,12 @@ cookie-signature@1.0.6: version "1.0.6" resolved "https://registry.yarnpkg.com/cookie-signature/-/cookie-signature-1.0.6.tgz#e303a882b342cc3ee8ca513a79999734dab3ae2c" -cookie@0.3.1: - version "0.3.1" - resolved "https://registry.yarnpkg.com/cookie/-/cookie-0.3.1.tgz#e7e0a1f9ef43b4c8ba925c5c5a96e806d16873bb" - cookie@0.4.0: version "0.4.0" resolved "https://registry.yarnpkg.com/cookie/-/cookie-0.4.0.tgz#beb437e7022b3b6d49019d088665303ebe9c14ba" integrity sha512-+Hp8fLp57wnUSt0tY0tHEXh4voZRDnoIrZPqlo3DPiI4y9lwg/jqx+1Om94/W6ZaPDOUbnjOt/99w66zk+l1Xg== -cookie@^0.4.1: +cookie@^0.4.1, cookie@~0.4.1: version "0.4.1" resolved "https://registry.yarnpkg.com/cookie/-/cookie-0.4.1.tgz#afd713fe26ebd21ba95ceb61f9a8116e50a537d1" integrity sha512-ZwrFkGJxUR3EIoXtO+yVE69Eb7KlixbaeAWfBQB9vVsNn/o+Yw69gBWSSDK825hQNdN+wF8zELf3dFNl/kxkUA== @@ -9456,7 +9455,7 @@ core-util-is@1.0.2, core-util-is@~1.0.0: version "1.0.2" resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.2.tgz#b5fd54220aa2bc5ab57aab7140c940754503c1a7" -cors@2.8.5, cors@^2.8.5: +cors@2.8.5, cors@^2.8.5, cors@~2.8.5: version "2.8.5" resolved "https://registry.yarnpkg.com/cors/-/cors-2.8.5.tgz#eac11da51592dd86b9f06f6e7ac293b3df875d29" dependencies: @@ -10151,7 +10150,7 @@ debug@3.1.0, debug@~3.1.0: dependencies: ms "2.0.0" -debug@4, debug@^4.0.0, debug@^4.0.1, debug@^4.1.0, debug@^4.1.1, debug@^4.2.0, debug@^4.3.0, debug@^4.3.1: +debug@4, debug@^4.0.0, debug@^4.0.1, debug@^4.1.0, debug@^4.1.1, debug@^4.2.0, debug@^4.3.0, debug@^4.3.1, debug@~4.3.1: version "4.3.1" resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.1.tgz#f0d229c505e0c6d8c49ac553d1b13dc183f6b2ee" integrity sha512-doEwdvm4PCeK4K3RQN2ZC2BYUBaxwLARCqZmMjtF8a51J2Rb0xpVloFRnCODwqjpwnAoao4pelN8l3RJdv3gRQ== @@ -10165,13 +10164,6 @@ debug@^3.0.0, debug@^3.1.0, debug@^3.1.1, debug@^3.2.6, debug@^3.2.7: dependencies: ms "^2.1.1" -debug@~4.1.0: - version "4.1.1" - resolved "https://registry.yarnpkg.com/debug/-/debug-4.1.1.tgz#3b72260255109c6b589cee050f1d516139664791" - integrity sha512-pYAIzeRo8J6KPEaJ0VWOh5Pzkbw/RetuzehGM7QRRX5he4fPHx2rdKMB256ehJCkX+XRQm16eZLqLNS8RSZXZw== - dependencies: - ms "^2.1.1" - debuglog@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/debuglog/-/debuglog-1.0.1.tgz#aa24ffb9ac3df9a2351837cfb2d279360cd78492" @@ -11150,23 +11142,6 @@ end-of-stream@^1.0.0, end-of-stream@^1.1.0, end-of-stream@^1.4.1: dependencies: once "^1.4.0" -engine.io-client@~3.4.0: - version "3.4.0" - resolved "https://registry.yarnpkg.com/engine.io-client/-/engine.io-client-3.4.0.tgz#82a642b42862a9b3f7a188f41776b2deab643700" - integrity sha512-a4J5QO2k99CM2a0b12IznnyQndoEvtA4UAldhGzKqnHf42I3Qs2W5SPnDvatZRcMaNZs4IevVicBPayxYt6FwA== - dependencies: - component-emitter "1.2.1" - component-inherit "0.0.3" - debug "~4.1.0" - engine.io-parser "~2.2.0" - has-cors "1.1.0" - indexof "0.0.1" - parseqs "0.0.5" - parseuri "0.0.5" - ws "~6.1.0" - xmlhttprequest-ssl "~1.5.4" - yeast "0.1.2" - engine.io-client@~3.5.0: version "3.5.0" resolved "https://registry.yarnpkg.com/engine.io-client/-/engine.io-client-3.5.0.tgz#fc1b4d9616288ce4f2daf06dcf612413dec941c7" @@ -11184,6 +11159,22 @@ engine.io-client@~3.5.0: xmlhttprequest-ssl "~1.5.4" yeast "0.1.2" +engine.io-client@~4.1.0: + version "4.1.1" + resolved "https://registry.yarnpkg.com/engine.io-client/-/engine.io-client-4.1.1.tgz#109942705079f15a4fcf1090bc86d3a1341c0a61" + integrity sha512-iYasV/EttP/2pLrdowe9G3zwlNIFhwny8VSIh+vPlMnYZqSzLsTzSLa9hFy015OrH1s4fzoYxeHjVkO8hSFKwg== + dependencies: + base64-arraybuffer "0.1.4" + component-emitter "~1.3.0" + debug "~4.3.1" + engine.io-parser "~4.0.1" + has-cors "1.1.0" + parseqs "0.0.6" + parseuri "0.0.6" + ws "~7.4.2" + xmlhttprequest-ssl "~1.5.4" + yeast "0.1.2" + engine.io-parser@~2.2.0: version "2.2.0" resolved "https://registry.yarnpkg.com/engine.io-parser/-/engine.io-parser-2.2.0.tgz#312c4894f57d52a02b420868da7b5c1c84af80ed" @@ -11195,17 +11186,25 @@ engine.io-parser@~2.2.0: blob "0.0.5" has-binary2 "~1.0.2" -engine.io@~3.4.0: - version "3.4.0" - resolved "https://registry.yarnpkg.com/engine.io/-/engine.io-3.4.0.tgz#3a962cc4535928c252759a00f98519cb46c53ff3" - integrity sha512-XCyYVWzcHnK5cMz7G4VTu2W7zJS7SM1QkcelghyIk/FmobWBtXE7fwhBusEKvCSqc3bMh8fNFMlUkCKTFRxH2w== +engine.io-parser@~4.0.0, engine.io-parser@~4.0.1: + version "4.0.2" + resolved "https://registry.yarnpkg.com/engine.io-parser/-/engine.io-parser-4.0.2.tgz#e41d0b3fb66f7bf4a3671d2038a154024edb501e" + integrity sha512-sHfEQv6nmtJrq6TKuIz5kyEKH/qSdK56H/A+7DnAuUPWosnIZAS2NHNcPLmyjtY3cGS/MqJdZbUjW97JU72iYg== + dependencies: + base64-arraybuffer "0.1.4" + +engine.io@~4.1.0: + version "4.1.1" + resolved "https://registry.yarnpkg.com/engine.io/-/engine.io-4.1.1.tgz#9a8f8a5ac5a5ea316183c489bf7f5b6cf91ace5b" + integrity sha512-t2E9wLlssQjGw0nluF6aYyfX8LwYU8Jj0xct+pAhfWfv/YrBn6TSNtEYsgxHIfaMqfrLx07czcMg9bMN6di+3w== dependencies: accepts "~1.3.4" base64id "2.0.0" - cookie "0.3.1" - debug "~4.1.0" - engine.io-parser "~2.2.0" - ws "^7.1.2" + cookie "~0.4.1" + cors "~2.8.5" + debug "~4.3.1" + engine.io-parser "~4.0.0" + ws "~7.4.2" enhanced-resolve@^4.1.1, enhanced-resolve@^4.2.0, enhanced-resolve@^4.5.0: version "4.5.0" @@ -19524,10 +19523,6 @@ object-assign@^4, object-assign@^4.0.1, object-assign@^4.1.0, object-assign@^4.1 version "4.1.1" resolved "https://registry.yarnpkg.com/object-assign/-/object-assign-4.1.1.tgz#2109adc7965887cfc05cbbd442cac8bfbb360863" -object-component@0.0.3: - version "0.0.3" - resolved "https://registry.yarnpkg.com/object-component/-/object-component-0.0.3.tgz#f0c69aa50efc95b866c186f400a33769cb2f1291" - object-copy@^0.1.0: version "0.1.0" resolved "https://registry.yarnpkg.com/object-copy/-/object-copy-0.1.0.tgz#7e7d858b781bd7c991a41ba975ed3812754e998c" @@ -20339,23 +20334,11 @@ parse5@^6.0.0: resolved "https://registry.yarnpkg.com/parse5/-/parse5-6.0.1.tgz#e1a1c085c569b3dc08321184f19a39cc27f7c30b" integrity sha512-Ofn/CTFzRGTTxwpNEs9PP93gXShHcTq255nzRYSKe8AkVpZY7e1fpmTfOyoIvjP5HG7Z2ZM7VS9PPhQGW2pOpw== -parseqs@0.0.5: - version "0.0.5" - resolved "https://registry.yarnpkg.com/parseqs/-/parseqs-0.0.5.tgz#d5208a3738e46766e291ba2ea173684921a8b89d" - dependencies: - better-assert "~1.0.0" - parseqs@0.0.6: version "0.0.6" resolved "https://registry.yarnpkg.com/parseqs/-/parseqs-0.0.6.tgz#8e4bb5a19d1cdc844a08ac974d34e273afa670d5" integrity sha512-jeAGzMDbfSHHA091hr0r31eYfTig+29g3GKKE/PPbEQ65X0lmMwlEoqmhzu0iztID5uJpZsFlUPDP8ThPL7M8w== -parseuri@0.0.5: - version "0.0.5" - resolved "https://registry.yarnpkg.com/parseuri/-/parseuri-0.0.5.tgz#80204a50d4dbb779bfdc6ebe2778d90e4bce320a" - dependencies: - better-assert "~1.0.0" - parseuri@0.0.6: version "0.0.6" resolved "https://registry.yarnpkg.com/parseuri/-/parseuri-0.0.6.tgz#e1496e829e3ac2ff47f39a4dd044b32823c4a25a" @@ -24654,29 +24637,10 @@ snapdragon@^0.8.1: source-map-resolve "^0.5.0" use "^3.1.0" -socket.io-adapter@~1.1.0: - version "1.1.1" - resolved "https://registry.yarnpkg.com/socket.io-adapter/-/socket.io-adapter-1.1.1.tgz#2a805e8a14d6372124dd9159ad4502f8cb07f06b" - -socket.io-client@2.3.0: - version "2.3.0" - resolved "https://registry.yarnpkg.com/socket.io-client/-/socket.io-client-2.3.0.tgz#14d5ba2e00b9bcd145ae443ab96b3f86cbcc1bb4" - integrity sha512-cEQQf24gET3rfhxZ2jJ5xzAOo/xhZwK+mOqtGRg5IowZsMgwvHwnf/mCRapAAkadhM26y+iydgwsXGObBB5ZdA== - dependencies: - backo2 "1.0.2" - base64-arraybuffer "0.1.5" - component-bind "1.0.0" - component-emitter "1.2.1" - debug "~4.1.0" - engine.io-client "~3.4.0" - has-binary2 "~1.0.2" - has-cors "1.1.0" - indexof "0.0.1" - object-component "0.0.3" - parseqs "0.0.5" - parseuri "0.0.5" - socket.io-parser "~3.3.0" - to-array "0.1.4" +socket.io-adapter@~2.1.0: + version "2.1.0" + resolved "https://registry.yarnpkg.com/socket.io-adapter/-/socket.io-adapter-2.1.0.tgz#edc5dc36602f2985918d631c1399215e97a1b527" + integrity sha512-+vDov/aTsLjViYTwS9fPy5pEtTkrbEKsw2M+oVSoFGw6OD1IpvlV1VPhUzNbofCQ8oyMbdYJqDtGdmHQK6TdPg== socket.io-client@2.4.0: version "2.4.0" @@ -24695,6 +24659,19 @@ socket.io-client@2.4.0: socket.io-parser "~3.3.0" to-array "0.1.4" +socket.io-client@3.1.1: + version "3.1.1" + resolved "https://registry.yarnpkg.com/socket.io-client/-/socket.io-client-3.1.1.tgz#43dfc3feddbb675b274a724f685d6b6af319b3e3" + integrity sha512-BLgIuCjI7Sf3mDHunKddX9zKR/pbkP7IACM3sJS3jha+zJ6/pGKRV6Fz5XSBHCfUs9YzT8kYIqNwOOuFNLtnYA== + dependencies: + "@types/component-emitter" "^1.2.10" + backo2 "~1.0.2" + component-emitter "~1.3.0" + debug "~4.3.1" + engine.io-client "~4.1.0" + parseuri "0.0.6" + socket.io-parser "~4.0.4" + socket.io-parser@~3.3.0: version "3.3.0" resolved "https://registry.yarnpkg.com/socket.io-parser/-/socket.io-parser-3.3.0.tgz#2b52a96a509fdf31440ba40fed6094c7d4f1262f" @@ -24704,26 +24681,29 @@ socket.io-parser@~3.3.0: debug "~3.1.0" isarray "2.0.1" -socket.io-parser@~3.4.0: - version "3.4.0" - resolved "https://registry.yarnpkg.com/socket.io-parser/-/socket.io-parser-3.4.0.tgz#370bb4a151df2f77ce3345ff55a7072cc6e9565a" - integrity sha512-/G/VOI+3DBp0+DJKW4KesGnQkQPFmUCbA/oO2QGT6CWxU7hLGWqU3tyuzeSK/dqcyeHsQg1vTe9jiZI8GU9SCQ== +socket.io-parser@~4.0.3, socket.io-parser@~4.0.4: + version "4.0.4" + resolved "https://registry.yarnpkg.com/socket.io-parser/-/socket.io-parser-4.0.4.tgz#9ea21b0d61508d18196ef04a2c6b9ab630f4c2b0" + integrity sha512-t+b0SS+IxG7Rxzda2EVvyBZbvFPBCjJoyHuE0P//7OAsN23GItzDRdWa6ALxZI/8R5ygK7jAR6t028/z+7295g== dependencies: - component-emitter "1.2.1" - debug "~4.1.0" - isarray "2.0.1" + "@types/component-emitter" "^1.2.10" + component-emitter "~1.3.0" + debug "~4.3.1" -socket.io@2.3.0: - version "2.3.0" - resolved "https://registry.yarnpkg.com/socket.io/-/socket.io-2.3.0.tgz#cd762ed6a4faeca59bc1f3e243c0969311eb73fb" - integrity sha512-2A892lrj0GcgR/9Qk81EaY2gYhCBxurV0PfmmESO6p27QPrUK1J3zdns+5QPqvUYK2q657nSj0guoIil9+7eFg== +socket.io@3.1.1: + version "3.1.1" + resolved "https://registry.yarnpkg.com/socket.io/-/socket.io-3.1.1.tgz#905e3d4a3b37d8e7970e67a4a6eb81110a5778ba" + integrity sha512-7cBWdsDC7bbyEF6WbBqffjizc/H4YF1wLdZoOzuYfo2uMNSFjJKuQ36t0H40o9B20DO6p+mSytEd92oP4S15bA== dependencies: - debug "~4.1.0" - engine.io "~3.4.0" - has-binary2 "~1.0.2" - socket.io-adapter "~1.1.0" - socket.io-client "2.3.0" - socket.io-parser "~3.4.0" + "@types/cookie" "^0.4.0" + "@types/cors" "^2.8.8" + "@types/node" "^14.14.10" + accepts "~1.3.4" + base64id "~2.0.0" + debug "~4.3.1" + engine.io "~4.1.0" + socket.io-adapter "~2.1.0" + socket.io-parser "~4.0.3" socketerrors@^0.3.0: version "0.3.0" @@ -28413,18 +28393,11 @@ ws@^6.1.2, ws@^6.2.1: dependencies: async-limiter "~1.0.0" -ws@^7, ws@^7.0.0, ws@^7.1.2, ws@^7.2.3, ws@^7.2.5, ws@^7.3.0, ws@~7.4.2: +ws@^7, ws@^7.0.0, ws@^7.2.3, ws@^7.2.5, ws@^7.3.0, ws@~7.4.2: version "7.4.2" resolved "https://registry.yarnpkg.com/ws/-/ws-7.4.2.tgz#782100048e54eb36fe9843363ab1c68672b261dd" integrity sha512-T4tewALS3+qsrpGI/8dqNMLIVdq/g/85U98HPMa6F0m6xTbvhXU6RCQLqPH3+SlomNV/LdY6RXEbBpMH6EOJnA== -ws@~6.1.0: - version "6.1.4" - resolved "https://registry.yarnpkg.com/ws/-/ws-6.1.4.tgz#5b5c8800afab925e94ccb29d153c8d02c1776ef9" - integrity sha512-eqZfL+NE/YQc1/ZynhojeV8q+H050oR8AZ2uIev7RU10svA9ZnJUddHcOUZTJLinZ9yEfdA2kSATS2qZK5fhJA== - dependencies: - async-limiter "~1.0.0" - x-is-string@^0.1.0: version "0.1.0" resolved "https://registry.yarnpkg.com/x-is-string/-/x-is-string-0.1.0.tgz#474b50865af3a49a9c4657f05acd145458f77d82" From aa5f08470264c2a7637bd21e972300bfab58918e Mon Sep 17 00:00:00 2001 From: Ward Peeters Date: Thu, 25 Feb 2021 13:06:58 +0100 Subject: [PATCH 2/2] fix types --- packages/gatsby/src/commands/develop.ts | 4 ++-- packages/gatsby/src/utils/websocket-manager.ts | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/gatsby/src/commands/develop.ts b/packages/gatsby/src/commands/develop.ts index 8915cb6451a7d..dee3dc8be92bf 100644 --- a/packages/gatsby/src/commands/develop.ts +++ b/packages/gatsby/src/commands/develop.ts @@ -8,7 +8,7 @@ import execa from "execa" import chokidar from "chokidar" import getRandomPort from "detect-port" import { detectPortInUseAndPrompt } from "../utils/detect-port-in-use-and-prompt" -import socket from "socket.io" +import { Server as SocketIO } from "socket.io" import fs from "fs-extra" import onExit from "signal-exit" import { @@ -344,7 +344,7 @@ module.exports = async (program: IProgram): Promise => { : http.createServer() statusServer.listen(statusServerPort) - const io = socket(statusServer, { + const io = new SocketIO(statusServer, { // whitelist all (https://github.com/expressjs/cors#configuration-options) cors: { origin: true, diff --git a/packages/gatsby/src/utils/websocket-manager.ts b/packages/gatsby/src/utils/websocket-manager.ts index f77669ce5c29f..752b663a9e829 100644 --- a/packages/gatsby/src/utils/websocket-manager.ts +++ b/packages/gatsby/src/utils/websocket-manager.ts @@ -10,7 +10,7 @@ import telemetry from "gatsby-telemetry" import url from "url" import { createHash } from "crypto" import { findPageByPath } from "./find-page-by-path" -import io from "socket.io" +import { Server as SocketIO, Socket } from "socket.io" export interface IPageQueryResult { id: string @@ -31,7 +31,7 @@ function hashPaths(paths: Array): Array { interface IClientInfo { activePath: string | null - socket: io.Socket + socket: Socket } export class WebsocketManager { @@ -40,11 +40,11 @@ export class WebsocketManager { errors: Map = new Map() pageResults: PageResultsMap = new Map() staticQueryResults: QueryResultsMap = new Map() - websocket: io.Server | undefined + websocket: SocketIO | undefined - init = ({ server }: { server: HTTPSServer | HTTPServer }): io.Server => { + init = ({ server }: { server: HTTPSServer | HTTPServer }): SocketIO => { // make typescript happy, else it complained about this.websocket being undefined - const websocket = io(server, { + const websocket = new SocketIO(server, { // we see ping-pong timeouts on gatsby-cloud when socket.io is running for a while // increasing it should help // @see https://github.com/socketio/socket.io/issues/3259#issuecomment-448058937 @@ -154,7 +154,7 @@ export class WebsocketManager { return websocket } - getSocket = (): io.Server | undefined => this.websocket + getSocket = (): SocketIO | undefined => this.websocket emitStaticQueryData = (data: IStaticQueryResult): void => { this.staticQueryResults.set(data.id, data)