From 1ccf733e8b2b1c1423d4820722dd1d26c7ff24cd Mon Sep 17 00:00:00 2001 From: Apteryx Date: Mon, 1 Jul 2024 17:45:22 +1200 Subject: [PATCH 1/4] Fix support for monorepos --- packages/cli/package.json | 22 ++- packages/cli/src/commands/patch.ts | 22 +-- packages/cli/src/commands/verify.ts | 4 +- packages/cli/src/helpers/next.ts | 15 ++ packages/cli/src/helpers/trace.ts | 7 +- packages/cli/src/helpers/workspace.ts | 59 ------ packages/cli/src/patches/patch-1.ts | 12 +- packages/cli/src/patches/patch-2.ts | 6 +- packages/cli/src/patches/patch-3.ts | 6 +- packages/cli/tsup.config.ts | 2 +- pnpm-lock.yaml | 271 ++++++-------------------- 11 files changed, 117 insertions(+), 309 deletions(-) create mode 100644 packages/cli/src/helpers/next.ts delete mode 100644 packages/cli/src/helpers/workspace.ts diff --git a/packages/cli/package.json b/packages/cli/package.json index 9fe90dd..85bc7ef 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -1,10 +1,18 @@ { "name": "next-ws-cli", "version": "1.1.0", - "type": "module", + "type": "commonjs", "description": "CLI tool for Next WS, a library for adding support for WebSockets to Next.js 13", "license": "MIT", - "keywords": ["next", "websocket", "ws", "server", "client", "cli", "patch"], + "keywords": [ + "next", + "websocket", + "ws", + "server", + "client", + "cli", + "patch" + ], "homepage": "https://github.com/apteryxxyz/next-ws#readme", "repository": { "type": "git", @@ -14,8 +22,10 @@ "bugs": { "url": "https://github.com/apteryxxyz/next-ws/issues" }, - "files": ["dist"], - "bin": "./dist/program.mjs", + "files": [ + "dist" + ], + "bin": "./dist/program.cjs", "scripts": { "lint": "biome lint . --write", "format": "biome format . --write", @@ -28,9 +38,9 @@ "@babel/parser": "^7.24.7", "@babel/template": "^7.24.7", "@babel/types": "^7.24.7", - "chalk": "^5.3.0", + "@inquirer/confirm": "^3.1.12", + "chalk": "^4", "commander": "^12.1.0", - "inquirer": "^9.3.1", "semver": "^7.6.2" }, "devDependencies": { diff --git a/packages/cli/src/commands/patch.ts b/packages/cli/src/commands/patch.ts index db2674c..6de98f7 100644 --- a/packages/cli/src/commands/patch.ts +++ b/packages/cli/src/commands/patch.ts @@ -1,8 +1,8 @@ +import confirm from '@inquirer/confirm'; import { Command } from 'commander'; -import inquirer from 'inquirer'; import logger from '~/helpers/logger'; +import { getNextVersion } from '~/helpers/next'; import { setTrace } from '~/helpers/trace'; -import { getCurrentNextVersion } from '~/helpers/workspace'; import patches from '~/patches'; import * as semver from '../helpers/semver'; @@ -13,7 +13,7 @@ export default new Command('patch') const supported = patches.map((p) => p.supported).join(' || '); const minimum = semver.minVersion(supported)?.version ?? supported; const maximum = semver.maxVersion(supported)?.version ?? supported; - const current = getCurrentNextVersion(); + const current = getNextVersion(); if (semver.ltr(current, minimum)) { logger.error(`Next.js v${current} is not supported, @@ -26,18 +26,14 @@ export default new Command('patch') logger.warn(`Next WS has not yet been tested with Next.js v${current}, it may or may not work, are you sure you want to continue?`); - const confirm = + const continueY = Boolean(options.yes) || - (await inquirer - .prompt<{ confirm: boolean }>({ - type: 'confirm', - name: 'confirm', - message: 'Continue?', - default: false, - }) - .then((a) => a.confirm)); + (await confirm({ + message: 'Continue?', + default: false, + })); - if (confirm) { + if (continueY) { patch = patches[patches.length - 1]; logger.info('Continuing with the latest patch'); logger.info(`If you encounter any issues please report them at diff --git a/packages/cli/src/commands/verify.ts b/packages/cli/src/commands/verify.ts index 4ca99c9..dac1e56 100644 --- a/packages/cli/src/commands/verify.ts +++ b/packages/cli/src/commands/verify.ts @@ -1,7 +1,7 @@ import { Command } from 'commander'; import logger from '~/helpers/logger'; +import { getNextVersion } from '~/helpers/next'; import { getTrace } from '~/helpers/trace'; -import { getCurrentNextVersion } from '~/helpers/workspace'; import patchCommand from './patch'; export default new Command('verify') @@ -25,7 +25,7 @@ export default new Command('verify') } } - const current = getCurrentNextVersion(); + const current = getNextVersion(); if (trace.version !== current) { logger.error( `Next.js version mismatch, expected v${trace.version} but found v${current}, try running \`npx next-ws-cli@latest patch\``, diff --git a/packages/cli/src/helpers/next.ts b/packages/cli/src/helpers/next.ts new file mode 100644 index 0000000..a766dd1 --- /dev/null +++ b/packages/cli/src/helpers/next.ts @@ -0,0 +1,15 @@ +import { readFileSync } from 'node:fs'; +import path from 'node:path'; + +export function findNextDirectory() { + return path.dirname( + require.resolve('next/package.json', { paths: [process.cwd()] }), + ); +} + +export function getNextVersion() { + const packagePath = path.join(findNextDirectory(), 'package.json'); + const packageContent = readFileSync(packagePath, 'utf8'); + const packageJson = JSON.parse(packageContent) as { version: string }; + return packageJson.version.split('-')[0]!; +} diff --git a/packages/cli/src/helpers/trace.ts b/packages/cli/src/helpers/trace.ts index 921cf76..9c7c116 100644 --- a/packages/cli/src/helpers/trace.ts +++ b/packages/cli/src/helpers/trace.ts @@ -1,11 +1,8 @@ import { readFileSync, writeFileSync } from 'node:fs'; import path from 'node:path'; -import { findWorkspaceRoot } from './workspace'; +import { findNextDirectory } from './next'; -const TracePath = path.join( - findWorkspaceRoot(), - 'node_modules/next/.next-ws-trace.json', -); +const TracePath = path.join(findNextDirectory(), '.next-ws-trace.json'); interface Trace { patch: string; diff --git a/packages/cli/src/helpers/workspace.ts b/packages/cli/src/helpers/workspace.ts deleted file mode 100644 index ba8282c..0000000 --- a/packages/cli/src/helpers/workspace.ts +++ /dev/null @@ -1,59 +0,0 @@ -import fs from 'node:fs'; -import path from 'node:path'; - -const cache = new Map(); - -export function findWorkspaceRoot(initialPath = process.cwd()) { - let currentPath = initialPath; - let lastPossiblePath = currentPath; - let isRoot: 'false' | 'maybe' | 'true' = 'maybe'; - - const isCurrentPathRoot = () => { - const files = fs.readdirSync(currentPath); - - const lockFiles = ['pnpm-lock.yaml', 'yarn.lock', 'package-lock.json']; - const hasLockFile = files.some((file) => lockFiles.includes(file)); - if (hasLockFile) return 'true'; - - const packageJson = files.find((file) => file === 'package.json'); - if (packageJson) { - const packageContent = fs.readFileSync( - path.resolve(currentPath, packageJson), - 'utf8', - ); - const packageObject = // - JSON.parse(packageContent) as { packageManager?: string }; - if (packageObject.packageManager) return 'true'; - return 'maybe'; - } - - return 'false'; - }; - - const shouldContinue = true; - while (shouldContinue) { - if (cache.has(currentPath)) return cache.get(currentPath)!; - - isRoot = isCurrentPathRoot(); - const nextPath = path.resolve(currentPath, '..'); - - if (isRoot === 'true' || nextPath === currentPath) break; - else if (isRoot === 'maybe') lastPossiblePath = currentPath; - - currentPath = nextPath; - } - - const finalPath = isRoot === 'true' ? currentPath : lastPossiblePath; - cache.set(initialPath, finalPath); - return finalPath; -} - -export function getCurrentNextVersion() { - const packagePath = path.join( - findWorkspaceRoot(), - 'node_modules/next/package.json', - ); - const packageContent = fs.readFileSync(packagePath, 'utf8'); - const packageJson = JSON.parse(packageContent) as { version: string }; - return packageJson.version.split('-')[0]!; -} diff --git a/packages/cli/src/patches/patch-1.ts b/packages/cli/src/patches/patch-1.ts index 4cc68f1..2102745 100644 --- a/packages/cli/src/patches/patch-1.ts +++ b/packages/cli/src/patches/patch-1.ts @@ -1,19 +1,19 @@ import fs from 'node:fs'; import path from 'node:path'; import generate from '@babel/generator'; -import parser from '@babel/parser'; +import * as parser from '@babel/parser'; import template from '@babel/template'; import type { ClassDeclaration, ClassMethod } from '@babel/types'; import logger from '~/helpers/logger'; -import { findWorkspaceRoot } from '~/helpers/workspace'; +import { findNextDirectory } from '~/helpers/next'; const NextServerFilePath = path.join( - findWorkspaceRoot(), - 'node_modules/next/dist/server/next-server.js', + findNextDirectory(), + 'dist/server/next-server.js', ); const NextTypesFilePath = path.join( - findWorkspaceRoot(), - 'node_modules/next/dist/build/webpack/plugins/next-types-plugin.js', + findNextDirectory(), + 'dist/build/webpack/plugins/next-types-plugin.js', ); // Add `require('next-ws/server').setupWebSocketServer(this)` to the diff --git a/packages/cli/src/patches/patch-2.ts b/packages/cli/src/patches/patch-2.ts index 1adb314..8c0adb4 100644 --- a/packages/cli/src/patches/patch-2.ts +++ b/packages/cli/src/patches/patch-2.ts @@ -1,12 +1,12 @@ import fs from 'node:fs'; import path from 'node:path'; import logger from '~/helpers/logger'; -import { findWorkspaceRoot } from '~/helpers/workspace'; import { patchNextNodeServer } from './patch-1'; +import { findNextDirectory } from '~/helpers/next'; const NextTypesFilePath = path.join( - findWorkspaceRoot(), - 'node_modules/next/dist/build/webpack/plugins/next-types-plugin/index.js', + findNextDirectory(), + 'dist/build/webpack/plugins/next-types-plugin/index.js', ); // Add `SOCKET?: Function` to the page module interface check field thing in diff --git a/packages/cli/src/patches/patch-3.ts b/packages/cli/src/patches/patch-3.ts index 39a005e..95c5fb4 100644 --- a/packages/cli/src/patches/patch-3.ts +++ b/packages/cli/src/patches/patch-3.ts @@ -1,13 +1,13 @@ import fs from 'node:fs'; import path from 'node:path'; import logger from '~/helpers/logger'; -import { findWorkspaceRoot } from '~/helpers/workspace'; +import { findNextDirectory } from '~/helpers/next'; import { patchNextNodeServer } from './patch-1'; import { patchNextTypesPlugin } from './patch-2'; const RouterServerFilePath = path.join( - findWorkspaceRoot(), - 'node_modules/next/dist/server/lib/router-server.js', + findNextDirectory(), + 'dist/server/lib/router-server.js', ); // If Next.js receives a WebSocket connection on a matched route, it will diff --git a/packages/cli/tsup.config.ts b/packages/cli/tsup.config.ts index 1605878..a50024d 100644 --- a/packages/cli/tsup.config.ts +++ b/packages/cli/tsup.config.ts @@ -2,7 +2,7 @@ import { defineConfig } from '@configs/tsup'; export default defineConfig({ entry: ['src/program.ts'], - format: ['esm'], + format: ['cjs'], dts: false, sourcemap: false, }); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index fbd65f6..2f98249 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -50,15 +50,15 @@ importers: '@babel/types': specifier: ^7.24.7 version: 7.24.7 + '@inquirer/confirm': + specifier: ^3.1.12 + version: 3.1.12 chalk: - specifier: ^5.3.0 - version: 5.3.0 + specifier: ^4 + version: 4.1.2 commander: specifier: ^12.1.0 version: 12.1.0 - inquirer: - specifier: ^9.3.1 - version: 9.3.1 semver: specifier: ^7.6.2 version: 7.6.2 @@ -329,10 +329,22 @@ packages: cpu: [x64] os: [win32] + '@inquirer/confirm@3.1.12': + resolution: {integrity: sha512-s5Sod79QsBBi5Qm7zxCq9DcAD0i7WRcjd/LzsiIAWqWZKW4+OJTGrCgVSLGIHTulwbZgdxM4AAxpCXe86hv4/Q==} + engines: {node: '>=18'} + + '@inquirer/core@9.0.0': + resolution: {integrity: sha512-y3q+fkCTGmvwk9Wf6yZlI3QGlLXbEm5M7Y7Eh8abaUbv+ffvmw2aB4FxSUrWaoaozwvEJSG60raHbCaUorXEzA==} + engines: {node: '>=18'} + '@inquirer/figures@1.0.3': resolution: {integrity: sha512-ErXXzENMH5pJt5/ssXV0DfWUZqly8nGzf0UcBV9xTnP+KyffE2mqyxIMBrZ8ijQck2nU0TQm40EQB53YreyWHw==} engines: {node: '>=18'} + '@inquirer/type@1.4.0': + resolution: {integrity: sha512-AjOqykVyjdJQvtfkNDGUyMYGF8xN50VUxftCQWsOyIo4DFRLr6VQhW0VItGI1JIyQGCGgIpKa7hMMwNhZb4OIw==} + engines: {node: '>=18'} + '@isaacs/cliui@8.0.2': resolution: {integrity: sha512-O8jcjabXaleOG9DQ0+ARXWZBTfnP4WNAqzuiJK7ll44AmxGKv/J2M4TPjxjY3znBCfvBXFzucm1twdyFybFqEA==} engines: {node: '>=12'} @@ -526,6 +538,9 @@ packages: '@types/inquirer@9.0.7': resolution: {integrity: sha512-Q0zyBupO6NxGRZut/JdmqYKOnN95Eg5V8Csg3PGKkP+FnvsUZx1jAyK7fztIszxxMuoBA6E3KXWvdZVXIpx60g==} + '@types/mute-stream@0.0.4': + resolution: {integrity: sha512-CPM9nzrCPPJHQNA9keH9CVkVI+WR5kMa+7XEs5jcGQ0VoAGnLv242w8lIVgwAEfmE4oufJRaTc9PNLQl0ioAow==} + '@types/node@20.14.9': resolution: {integrity: sha512-06OCtnTXtWOZBJlRApleWndH4JsRVs1pDCc8dLSQp+7PpUpX3ePdHyeNSFTeSe7FtKyQkrlPvHwJOW3SLd8Oyg==} @@ -541,6 +556,9 @@ packages: '@types/through@0.0.33': resolution: {integrity: sha512-HsJ+z3QuETzP3cswwtzt2vEIiHBk/dCcHGhbmG5X3ecnwFD/lPrMpliGXxSCg03L9AhrdwA4Oz/qfspkDW+xGQ==} + '@types/wrap-ansi@3.0.0': + resolution: {integrity: sha512-ltIpx+kM7g/MLRZfkbL7EsCEjfzCcScLpkg37eXEtx5kmrAKBkTJwd1GIAjDSL8wTpM6Hzn5YO4pSb91BEwu1g==} + '@types/ws@8.5.10': resolution: {integrity: sha512-vmQSUcfalpIq0R9q7uTo2lXs6eGIpt9wtnLdMv9LVpIjCA/+ufZRozlVoVelIYixx1ugCBKDhn89vnsEGOCx9A==} @@ -582,16 +600,10 @@ packages: balanced-match@1.0.2: resolution: {integrity: sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==} - base64-js@1.5.1: - resolution: {integrity: sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==} - binary-extensions@2.3.0: resolution: {integrity: sha512-Ceh+7ox5qe7LJuLHoY0feh3pHuUDHAcRUeyL2VYghZwfpkNIy/+8Ocg0a3UuSoYzavmylwuLWQOf3hl0jjMMIw==} engines: {node: '>=8'} - bl@4.1.0: - resolution: {integrity: sha512-1W07cM9gS6DcLperZfFSj+bWLtaPGSOHWhPiGzXmvVJbRLdG82sH/Kn8EtW1VqWVA54AKf2h5k5BbnIbwF3h6w==} - brace-expansion@2.0.1: resolution: {integrity: sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==} @@ -599,9 +611,6 @@ packages: resolution: {integrity: sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA==} engines: {node: '>=8'} - buffer@5.7.1: - resolution: {integrity: sha512-EHcyIPBQ4BSGlvjB16k5KgAJ27CIsHY/2JBmCRReo48y9rQ3MaUzWX3KVlBa4U7MyX02HdVj0K7C3WaB3ju7FQ==} - bundle-require@4.2.1: resolution: {integrity: sha512-7Q/6vkyYAwOmQNRw75x+4yRtZCZJXUDmHHlFdkiV0wgv/reNjtJwpu1jPJ0w2kbEpIM0uoKI3S4/f39dU7AjSA==} engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} @@ -627,21 +636,10 @@ packages: resolution: {integrity: sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==} engines: {node: '>=10'} - chalk@5.3.0: - resolution: {integrity: sha512-dLitG79d+GV1Nb/VYcCDFivJeK1hiukt9QjRNVOsUtTy1rR1YJsmpGGTZ3qJos+uw7WmWF4wUwBd9jxjocFC2w==} - engines: {node: ^12.17.0 || ^14.13 || >=16.0.0} - - chardet@0.7.0: - resolution: {integrity: sha512-mT8iDcrh03qDGRRmoA2hmBJnxpllMR+0/0qlzjqZES6NdiWDcZkCNAk4rPFZ9Q85r27unkiNNg8ZOiwZXBHwcA==} - chokidar@3.6.0: resolution: {integrity: sha512-7VT13fmjotKpGipCW9JEQAusEPE+Ei8nl6/g4FBAmIm0GOOLMua9NDDo/DWp0ZAxCr3cPq5ZpBqmPAQgDda2Pw==} engines: {node: '>= 8.10.0'} - cli-cursor@3.1.0: - resolution: {integrity: sha512-I/zHAwsKf9FqGoXM4WWRACob9+SNukZTd94DWF57E4toouRulbCxcUh6RKUEOQlYTHJnzkPMySvPNaaSLNfLZw==} - engines: {node: '>=8'} - cli-spinners@2.9.2: resolution: {integrity: sha512-ywqV+5MmyL4E7ybXgKys4DugZbX0FC6LnwrhjuykIjnK9k8OQacQ7axGKnjDXWNhns0xot3bZI5h55H8yo9cJg==} engines: {node: '>=6'} @@ -653,10 +651,6 @@ packages: client-only@0.0.1: resolution: {integrity: sha512-IV3Ou0jSMzZrd3pZ48nLkT9DA7Ag1pnPzaiQhpW7c3RbcqqzvzzVu+L8gfqMp/8IM2MQtSiqaCxrrcfu8I8rMA==} - clone@1.0.4: - resolution: {integrity: sha512-JQHZ2QMW6l3aH/j6xCqQThY/9OH4D/9ls34cgkUBiEeocRTU04tHfKPBsUK1PqZCUQM7GiA0IIXJSuXHI64Kbg==} - engines: {node: '>=0.8'} - color-convert@1.9.3: resolution: {integrity: sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==} @@ -694,9 +688,6 @@ packages: supports-color: optional: true - defaults@1.0.4: - resolution: {integrity: sha512-eFuaLoy/Rxalv2kr+lqMlUnrDWV+3j4pljOIJgLIhI058IQfWJ7vXhyEIHu+HtC738klGALYxOKDO0bQP3tg8A==} - dir-glob@3.0.1: resolution: {integrity: sha512-WkrWp9GR4KXfKGYzOLmTuGVi1UWFfws377n9cc55/tb6DuqyF6pcQ5AbiHEshaDpY9v6oaSr2XCDidGmMwdzIA==} engines: {node: '>=8'} @@ -723,10 +714,6 @@ packages: resolution: {integrity: sha512-8uSpZZocAZRBAPIEINJj3Lo9HyGitllczc27Eh5YYojjMFMn8yHMDMaUHE2Jqfq05D/wucwI4JGURyXt1vchyg==} engines: {node: '>=10'} - external-editor@3.1.0: - resolution: {integrity: sha512-hMQ4CX1p1izmuLYyZqLMO/qGNw10wSv9QDCPfzXfyFrOaCSSoRfqE1Kf1s5an66J5JZC62NewG+mK49jOCtQew==} - engines: {node: '>=4'} - fast-glob@3.3.2: resolution: {integrity: sha512-oX2ruAFQwf/Orj8m737Y5adxDQO0LAB7/S5MnxCdTNDd4p6BsyIVsv9JQsATbTSq8KHRpLwIHbVlUNatxd+1Ow==} engines: {node: '>=8.6.0'} @@ -782,24 +769,10 @@ packages: resolution: {integrity: sha512-B4FFZ6q/T2jhhksgkbEW3HBvWIfDW85snkQgawt07S7J5QXTk6BkNV+0yAeZrM5QpMAdYlocGoljn0sJ/WQkFw==} engines: {node: '>=10.17.0'} - iconv-lite@0.4.24: - resolution: {integrity: sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==} - engines: {node: '>=0.10.0'} - - ieee754@1.2.1: - resolution: {integrity: sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==} - ignore@5.3.1: resolution: {integrity: sha512-5Fytz/IraMjqpwfd34ke28PTVMjZjJG2MPn5t7OE4eUCUNf8BAa7b5WUS9/Qvr6mwOQS7Mk6vdsMno5he+T8Xw==} engines: {node: '>= 4'} - inherits@2.0.4: - resolution: {integrity: sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==} - - inquirer@9.3.1: - resolution: {integrity: sha512-A5IdVr1I04XqPlwrGgTJMKmzRg5ropqNpSeqo0vj1ZmluSCNSFaPZz4eazdPrhVcZfej7fCEYvD2NYa1KjkTJA==} - engines: {node: '>=18'} - is-binary-path@2.1.0: resolution: {integrity: sha512-ZMERYes6pDydyuGidse7OsHxtbI7WVeUEozgR/g7rd0xUimYNlvZRE/K2MgZTjWy725IfelLeVcEM97mmtRGXw==} engines: {node: '>=8'} @@ -816,10 +789,6 @@ packages: resolution: {integrity: sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg==} engines: {node: '>=0.10.0'} - is-interactive@1.0.0: - resolution: {integrity: sha512-2HvIEKRoqS62guEC+qBjpvRubdX910WCMuJTZ+I9yvqKU2/12eSL549HMwtabb4oupdj2sMP50k+XJfB/8JE6w==} - engines: {node: '>=8'} - is-number@7.0.0: resolution: {integrity: sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==} engines: {node: '>=0.12.0'} @@ -828,10 +797,6 @@ packages: resolution: {integrity: sha512-hFoiJiTl63nn+kstHGBtewWSKnQLpyb155KHheA1l39uvtO9nWIop1p3udqPcUd/xbF1VLMO4n7OI6p7RbngDg==} engines: {node: '>=8'} - is-unicode-supported@0.1.0: - resolution: {integrity: sha512-knxG2q4UC3u8stRGyAVJCOdxFmv5DZiRcdlIaAQXAbSfJya+OhopNotLQrstBhququ4ZpuKbDc/8S6mgXgPFPw==} - engines: {node: '>=10'} - isexe@2.0.0: resolution: {integrity: sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==} @@ -865,10 +830,6 @@ packages: lodash.sortby@4.7.0: resolution: {integrity: sha512-HDWXG8isMntAyRF5vZ7xKuEvOhT4AhlRt/3czTSjvGUxjYCBVRQY48ViDHyfYz9VIoBkW4TMGQNapx+l3RUwdA==} - log-symbols@4.1.0: - resolution: {integrity: sha512-8XPvpAA8uyhfteu8pIvQxpJZ7SYYdpUivZpGy6sFsBuKRY/7rQGavedeB8aK+Zkyq6upMFVL/9AW6vOYzfRyLg==} - engines: {node: '>=10'} - loose-envify@1.4.0: resolution: {integrity: sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q==} hasBin: true @@ -949,14 +910,6 @@ packages: resolution: {integrity: sha512-kbpaSSGJTWdAY5KPVeMOKXSrPtr8C8C7wodJbcsd51jRnmD+GZu8Y0VoU6Dm5Z4vWr0Ig/1NKuWRKf7j5aaYSg==} engines: {node: '>=6'} - ora@5.4.1: - resolution: {integrity: sha512-5b6Y85tPxZZ7QytO+BQzysW31HJku27cRIlkbAXaNx+BdcVi+LlRFmVXzeF6a7JCwJpyw5c4b+YSVImQIrBpuQ==} - engines: {node: '>=10'} - - os-tmpdir@1.0.2: - resolution: {integrity: sha512-D2FR03Vir7FIu45XBY20mTb+/ZSWB00sjU9jdQXt83gDrI4Ztz5Fs7/yy74g2N5SVQY4xY1qDr4rNddwYRVX0g==} - engines: {node: '>=0.10.0'} - package-json-from-dist@1.0.0: resolution: {integrity: sha512-dATvCeZN/8wQsGywez1mzHtTlP22H8OEfPrVMLNr4/eGa+ijtLn/6M5f0dY8UKNrC2O9UCU6SSoG3qRKnt7STw==} @@ -1019,10 +972,6 @@ packages: resolution: {integrity: sha512-wS+hAgJShR0KhEvPJArfuPVN1+Hz1t0Y6n5jLrGQbkb4urgPE/0Rve+1kMB1v/oWgHgm4WIcV+i7F2pTVj+2iQ==} engines: {node: '>=0.10.0'} - readable-stream@3.6.2: - resolution: {integrity: sha512-9u/sniCrY3D5WdsERHzHE4G2YCXqoG5FTHUiCC4SIbr6XcLZBY05ya9EKjYek9O5xOAwjGq+1JdGBAS7Q9ScoA==} - engines: {node: '>= 6'} - readdirp@3.6.0: resolution: {integrity: sha512-hOS089on8RduqdbhvQ5Z37A0ESjsqz6qnRcffsMU3495FuTdqSm+7bhJ29JvIOsBDEEnan5DPu9t3To9VRlMzA==} engines: {node: '>=8.10.0'} @@ -1034,10 +983,6 @@ packages: resolve-pkg-maps@1.0.0: resolution: {integrity: sha512-seS2Tj26TBVOC2NIc2rOe2y2ZO7efxITtLZcGSOnHHNOQ7CkiUBfw0Iw2ck6xkIhPwLhKNLS8BO+hEpngQlqzw==} - restore-cursor@3.1.0: - resolution: {integrity: sha512-l+sSefzHpj5qimhFSE5a8nufZYAM3sBSVMAPtYkmC+4EH2anSGaEMXSD0izRQbu9nfyQ9y5JrVmp7E8oZrUjvA==} - engines: {node: '>=8'} - reusify@1.0.4: resolution: {integrity: sha512-U9nH88a3fc/ekCF1l0/UP1IosiuIjyTh7hBvXVMHYgVcfGvt897Xguj2UOLDeI5BG2m7/uwyaLVT6fbtCwTyzw==} engines: {iojs: '>=1.0.0', node: '>=0.10.0'} @@ -1047,22 +992,12 @@ packages: engines: {node: '>=18.0.0', npm: '>=8.0.0'} hasBin: true - run-async@3.0.0: - resolution: {integrity: sha512-540WwVDOMxA6dN6We19EcT9sc3hkXPw5mzRNGM3FkdN/vtE9NFvj5lFAPNwUDmJjXidm3v7TC1cTE7t17Ulm1Q==} - engines: {node: '>=0.12.0'} - run-parallel@1.2.0: resolution: {integrity: sha512-5l4VyZR86LZ/lDxZTR6jqL8AFE2S0IFLMP26AbjsLVADxHdhB/c0GUsH+y39UfCi3dzz8OlQuPmnaJOMoDHQBA==} rxjs@7.8.1: resolution: {integrity: sha512-AA3TVj+0A2iuIoQkWEK/tqFjBq2j+6PO6Y0zJcvzLAFhEFIO3HL0vls9hWLncZbAAbK0mar7oZ4V079I/qPMxg==} - safe-buffer@5.2.1: - resolution: {integrity: sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==} - - safer-buffer@2.1.2: - resolution: {integrity: sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==} - scheduler@0.23.2: resolution: {integrity: sha512-UOShsPwz7NrMUqhR6t0hWjFduvOzbtv7toDH1/hIrfRNIDBnnBWd0CwJTGvTpngVlmwGCdP9/Zl/tVrDqcuYzQ==} @@ -1110,9 +1045,6 @@ packages: resolution: {integrity: sha512-HnLOCR3vjcY8beoNLtcjZ5/nxn2afmME6lhrDrebokqMap+XbeW8n9TXpPDOqdGK5qcI3oT0GKTW6wC7EMiVqA==} engines: {node: '>=12'} - string_decoder@1.3.0: - resolution: {integrity: sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==} - strip-ansi@6.0.1: resolution: {integrity: sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==} engines: {node: '>=8'} @@ -1158,10 +1090,6 @@ packages: thenify@3.3.1: resolution: {integrity: sha512-RVZSIV5IG10Hk3enotrhvz0T9em6cyHBLkH/YAZuKqd8hRkKhSfCGIcP2KUY0EPxndzANBmNllzWPwak+bheSw==} - tmp@0.0.33: - resolution: {integrity: sha512-jRCJlojKnZ3addtTOjdIqoRuPEKBvNXcGYqzO6zWZX8KfKEpnGY5jfggJQ3EjKuu8D4bJRr0y+cYJFmYbImXGw==} - engines: {node: '>=0.6.0'} - to-fast-properties@2.0.0: resolution: {integrity: sha512-/OaKK0xYrs3DmxRYqL/yDc+FxFUVYhDlXMhRmv3z915w2HF1tnN1omB354j8VUGO/hbRzyD6Y3sA7v7GS/ceog==} engines: {node: '>=4'} @@ -1253,12 +1181,6 @@ packages: undici-types@5.26.5: resolution: {integrity: sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==} - util-deprecate@1.0.2: - resolution: {integrity: sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==} - - wcwidth@1.0.1: - resolution: {integrity: sha512-XHPEwS0q6TaxcvG85+8EYkbiCux2XtWG2mkc47Ng2A77BQu9+DqIOJldST4HgPkuea7dvKSj5VgX3P1d4rW8Tg==} - webidl-conversions@4.0.2: resolution: {integrity: sha512-YQ+BmxuTgd6UXZW3+ICGfyqRyHXVlD5GtQr5+qjiNW7bF0cqrzX500HVXPBOvgXb5YnzDd+h0zqyv61KUD7+Sg==} @@ -1299,6 +1221,10 @@ packages: engines: {node: '>= 14'} hasBin: true + yoctocolors-cjs@2.1.1: + resolution: {integrity: sha512-c6T13b6qYcJZvck7QbEFXrFX/Mu2KOjvAGiKHmYMUg96jxNpfP6i+psGW72BOPxOIDUJrORG+Kyu7quMX9CQBQ==} + engines: {node: '>=18'} + snapshots: '@babel/code-frame@7.24.7': @@ -1444,8 +1370,33 @@ snapshots: '@esbuild/win32-x64@0.21.5': optional: true + '@inquirer/confirm@3.1.12': + dependencies: + '@inquirer/core': 9.0.0 + '@inquirer/type': 1.4.0 + + '@inquirer/core@9.0.0': + dependencies: + '@inquirer/figures': 1.0.3 + '@inquirer/type': 1.4.0 + '@types/mute-stream': 0.0.4 + '@types/node': 20.14.9 + '@types/wrap-ansi': 3.0.0 + ansi-escapes: 4.3.2 + cli-spinners: 2.9.2 + cli-width: 4.1.0 + mute-stream: 1.0.0 + signal-exit: 4.1.0 + strip-ansi: 6.0.1 + wrap-ansi: 6.2.0 + yoctocolors-cjs: 2.1.1 + '@inquirer/figures@1.0.3': {} + '@inquirer/type@1.4.0': + dependencies: + mute-stream: 1.0.0 + '@isaacs/cliui@8.0.2': dependencies: string-width: 5.1.2 @@ -1587,6 +1538,10 @@ snapshots: '@types/through': 0.0.33 rxjs: 7.8.1 + '@types/mute-stream@0.0.4': + dependencies: + '@types/node': 20.14.9 + '@types/node@20.14.9': dependencies: undici-types: 5.26.5 @@ -1604,6 +1559,8 @@ snapshots: dependencies: '@types/node': 20.14.9 + '@types/wrap-ansi@3.0.0': {} + '@types/ws@8.5.10': dependencies: '@types/node': 20.14.9 @@ -1637,16 +1594,8 @@ snapshots: balanced-match@1.0.2: {} - base64-js@1.5.1: {} - binary-extensions@2.3.0: {} - bl@4.1.0: - dependencies: - buffer: 5.7.1 - inherits: 2.0.4 - readable-stream: 3.6.2 - brace-expansion@2.0.1: dependencies: balanced-match: 1.0.2 @@ -1655,11 +1604,6 @@ snapshots: dependencies: fill-range: 7.1.1 - buffer@5.7.1: - dependencies: - base64-js: 1.5.1 - ieee754: 1.2.1 - bundle-require@4.2.1(esbuild@0.21.5): dependencies: esbuild: 0.21.5 @@ -1684,10 +1628,6 @@ snapshots: ansi-styles: 4.3.0 supports-color: 7.2.0 - chalk@5.3.0: {} - - chardet@0.7.0: {} - chokidar@3.6.0: dependencies: anymatch: 3.1.3 @@ -1700,18 +1640,12 @@ snapshots: optionalDependencies: fsevents: 2.3.3 - cli-cursor@3.1.0: - dependencies: - restore-cursor: 3.1.0 - cli-spinners@2.9.2: {} cli-width@4.1.0: {} client-only@0.0.1: {} - clone@1.0.4: {} - color-convert@1.9.3: dependencies: color-name: 1.1.3 @@ -1740,10 +1674,6 @@ snapshots: dependencies: ms: 2.1.2 - defaults@1.0.4: - dependencies: - clone: 1.0.4 - dir-glob@3.0.1: dependencies: path-type: 4.0.0 @@ -1794,12 +1724,6 @@ snapshots: signal-exit: 3.0.7 strip-final-newline: 2.0.0 - external-editor@3.1.0: - dependencies: - chardet: 0.7.0 - iconv-lite: 0.4.24 - tmp: 0.0.33 - fast-glob@3.3.2: dependencies: '@nodelib/fs.stat': 2.0.5 @@ -1860,31 +1784,8 @@ snapshots: human-signals@2.1.0: {} - iconv-lite@0.4.24: - dependencies: - safer-buffer: 2.1.2 - - ieee754@1.2.1: {} - ignore@5.3.1: {} - inherits@2.0.4: {} - - inquirer@9.3.1: - dependencies: - '@inquirer/figures': 1.0.3 - ansi-escapes: 4.3.2 - cli-width: 4.1.0 - external-editor: 3.1.0 - mute-stream: 1.0.0 - ora: 5.4.1 - picocolors: 1.0.1 - run-async: 3.0.0 - rxjs: 7.8.1 - string-width: 4.2.3 - strip-ansi: 6.0.1 - wrap-ansi: 6.2.0 - is-binary-path@2.1.0: dependencies: binary-extensions: 2.3.0 @@ -1897,14 +1798,10 @@ snapshots: dependencies: is-extglob: 2.1.1 - is-interactive@1.0.0: {} - is-number@7.0.0: {} is-stream@2.0.1: {} - is-unicode-supported@0.1.0: {} - isexe@2.0.0: {} jackspeak@3.4.0: @@ -1927,11 +1824,6 @@ snapshots: lodash.sortby@4.7.0: {} - log-symbols@4.1.0: - dependencies: - chalk: 4.1.2 - is-unicode-supported: 0.1.0 - loose-envify@1.4.0: dependencies: js-tokens: 4.0.0 @@ -2004,20 +1896,6 @@ snapshots: dependencies: mimic-fn: 2.1.0 - ora@5.4.1: - dependencies: - bl: 4.1.0 - chalk: 4.1.2 - cli-cursor: 3.1.0 - cli-spinners: 2.9.2 - is-interactive: 1.0.0 - is-unicode-supported: 0.1.0 - log-symbols: 4.1.0 - strip-ansi: 6.0.1 - wcwidth: 1.0.1 - - os-tmpdir@1.0.2: {} - package-json-from-dist@1.0.0: {} path-key@3.1.1: {} @@ -2069,12 +1947,6 @@ snapshots: dependencies: loose-envify: 1.4.0 - readable-stream@3.6.2: - dependencies: - inherits: 2.0.4 - string_decoder: 1.3.0 - util-deprecate: 1.0.2 - readdirp@3.6.0: dependencies: picomatch: 2.3.1 @@ -2083,11 +1955,6 @@ snapshots: resolve-pkg-maps@1.0.0: {} - restore-cursor@3.1.0: - dependencies: - onetime: 5.1.2 - signal-exit: 3.0.7 - reusify@1.0.4: {} rollup@4.18.0: @@ -2112,8 +1979,6 @@ snapshots: '@rollup/rollup-win32-x64-msvc': 4.18.0 fsevents: 2.3.3 - run-async@3.0.0: {} - run-parallel@1.2.0: dependencies: queue-microtask: 1.2.3 @@ -2122,10 +1987,6 @@ snapshots: dependencies: tslib: 2.6.3 - safe-buffer@5.2.1: {} - - safer-buffer@2.1.2: {} - scheduler@0.23.2: dependencies: loose-envify: 1.4.0 @@ -2164,10 +2025,6 @@ snapshots: emoji-regex: 9.2.2 strip-ansi: 7.1.0 - string_decoder@1.3.0: - dependencies: - safe-buffer: 5.2.1 - strip-ansi@6.0.1: dependencies: ansi-regex: 5.0.1 @@ -2209,10 +2066,6 @@ snapshots: dependencies: any-promise: 1.3.0 - tmp@0.0.33: - dependencies: - os-tmpdir: 1.0.2 - to-fast-properties@2.0.0: {} to-regex-range@5.0.1: @@ -2292,12 +2145,6 @@ snapshots: undici-types@5.26.5: {} - util-deprecate@1.0.2: {} - - wcwidth@1.0.1: - dependencies: - defaults: 1.0.4 - webidl-conversions@4.0.2: {} whatwg-url@7.1.0: @@ -2331,3 +2178,5 @@ snapshots: ws@8.17.1: {} yaml@2.4.5: {} + + yoctocolors-cjs@2.1.1: {} From 23a611c3c737ec94a1d71c1f0893d1dc7f084a70 Mon Sep 17 00:00:00 2001 From: Apteryx Date: Mon, 1 Jul 2024 17:46:31 +1200 Subject: [PATCH 2/4] Formatting --- packages/cli/package.json | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/packages/cli/package.json b/packages/cli/package.json index 85bc7ef..6ed7df6 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -4,15 +4,7 @@ "type": "commonjs", "description": "CLI tool for Next WS, a library for adding support for WebSockets to Next.js 13", "license": "MIT", - "keywords": [ - "next", - "websocket", - "ws", - "server", - "client", - "cli", - "patch" - ], + "keywords": ["next", "websocket", "ws", "server", "client", "cli", "patch"], "homepage": "https://github.com/apteryxxyz/next-ws#readme", "repository": { "type": "git", @@ -22,9 +14,7 @@ "bugs": { "url": "https://github.com/apteryxxyz/next-ws/issues" }, - "files": [ - "dist" - ], + "files": ["dist"], "bin": "./dist/program.cjs", "scripts": { "lint": "biome lint . --write", From c8ee2ed16c5bdd780170c41f504774fcb35781d2 Mon Sep 17 00:00:00 2001 From: Apteryx Date: Mon, 1 Jul 2024 18:16:10 +1200 Subject: [PATCH 3/4] Fix readme errors --- packages/cli/readme.md | 4 ++-- packages/core/readme.md | 4 ++-- readme.md | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/cli/readme.md b/packages/cli/readme.md index 4c488c8..90e87e5 100644 --- a/packages/cli/readme.md +++ b/packages/cli/readme.md @@ -69,7 +69,7 @@ export function SOCKET( In production, Next.js uses a worker process for routes, which can make it difficult to access the WebSocket server from outside a `SOCKET` handler, especially when the WebSocket server exists on the main process. For those needing to overcome this challenge or preferring a custom server setup, Next WS provides a solution. -The `next-ws/server` module offers functions for setting the HTTP and WebSocket servers. You use these functions to tell Next WS to use your server instances instead of creating its own. This allows you to then access the instances you created yourself from anywhere in your app. Refer to the [example below](#-using-a-custom-server). +The `next-ws/server` module offers functions for setting the HTTP and WebSocket servers. You use these functions to tell Next WS to use your server instances instead of creating its own. This allows you to then access the instances you created yourself from anywhere in your app. Refer to the [example below](#using-a-custom-server). ## 🌀 Examples @@ -143,7 +143,7 @@ app.prepare().then(() => { Along with setters, Next WS also provides getters for the HTTP and WebSocket servers. These functions can be used to access the servers from anywhere in your app. > [!IMPORTANT] -> In order to use the `getWebSocketServer` and `getHttpServer` functions, you must be using a [custom server](https://nextjs.org/docs/advanced-features/custom-server), this is due to a limitation in Next.js. Refer to the [With a Custom Server](#-with-a-custom-server). +> In order to use the `getWebSocketServer` and `getHttpServer` functions, you must be using a [custom server](https://nextjs.org/docs/advanced-features/custom-server), this is due to a limitation in Next.js. Refer to the [With a Custom Server](#with-a-custom-server). ```ts // app/api/stats/route.ts diff --git a/packages/core/readme.md b/packages/core/readme.md index 4c488c8..90e87e5 100644 --- a/packages/core/readme.md +++ b/packages/core/readme.md @@ -69,7 +69,7 @@ export function SOCKET( In production, Next.js uses a worker process for routes, which can make it difficult to access the WebSocket server from outside a `SOCKET` handler, especially when the WebSocket server exists on the main process. For those needing to overcome this challenge or preferring a custom server setup, Next WS provides a solution. -The `next-ws/server` module offers functions for setting the HTTP and WebSocket servers. You use these functions to tell Next WS to use your server instances instead of creating its own. This allows you to then access the instances you created yourself from anywhere in your app. Refer to the [example below](#-using-a-custom-server). +The `next-ws/server` module offers functions for setting the HTTP and WebSocket servers. You use these functions to tell Next WS to use your server instances instead of creating its own. This allows you to then access the instances you created yourself from anywhere in your app. Refer to the [example below](#using-a-custom-server). ## 🌀 Examples @@ -143,7 +143,7 @@ app.prepare().then(() => { Along with setters, Next WS also provides getters for the HTTP and WebSocket servers. These functions can be used to access the servers from anywhere in your app. > [!IMPORTANT] -> In order to use the `getWebSocketServer` and `getHttpServer` functions, you must be using a [custom server](https://nextjs.org/docs/advanced-features/custom-server), this is due to a limitation in Next.js. Refer to the [With a Custom Server](#-with-a-custom-server). +> In order to use the `getWebSocketServer` and `getHttpServer` functions, you must be using a [custom server](https://nextjs.org/docs/advanced-features/custom-server), this is due to a limitation in Next.js. Refer to the [With a Custom Server](#with-a-custom-server). ```ts // app/api/stats/route.ts diff --git a/readme.md b/readme.md index 4c488c8..90e87e5 100644 --- a/readme.md +++ b/readme.md @@ -69,7 +69,7 @@ export function SOCKET( In production, Next.js uses a worker process for routes, which can make it difficult to access the WebSocket server from outside a `SOCKET` handler, especially when the WebSocket server exists on the main process. For those needing to overcome this challenge or preferring a custom server setup, Next WS provides a solution. -The `next-ws/server` module offers functions for setting the HTTP and WebSocket servers. You use these functions to tell Next WS to use your server instances instead of creating its own. This allows you to then access the instances you created yourself from anywhere in your app. Refer to the [example below](#-using-a-custom-server). +The `next-ws/server` module offers functions for setting the HTTP and WebSocket servers. You use these functions to tell Next WS to use your server instances instead of creating its own. This allows you to then access the instances you created yourself from anywhere in your app. Refer to the [example below](#using-a-custom-server). ## 🌀 Examples @@ -143,7 +143,7 @@ app.prepare().then(() => { Along with setters, Next WS also provides getters for the HTTP and WebSocket servers. These functions can be used to access the servers from anywhere in your app. > [!IMPORTANT] -> In order to use the `getWebSocketServer` and `getHttpServer` functions, you must be using a [custom server](https://nextjs.org/docs/advanced-features/custom-server), this is due to a limitation in Next.js. Refer to the [With a Custom Server](#-with-a-custom-server). +> In order to use the `getWebSocketServer` and `getHttpServer` functions, you must be using a [custom server](https://nextjs.org/docs/advanced-features/custom-server), this is due to a limitation in Next.js. Refer to the [With a Custom Server](#with-a-custom-server). ```ts // app/api/stats/route.ts From 56e258ae3fece02444d54fb170de08110664b92a Mon Sep 17 00:00:00 2001 From: Apteryx Date: Mon, 1 Jul 2024 18:16:42 +1200 Subject: [PATCH 4/4] Convert `with-custom-server` server file to typescript --- .../src/{server.js => server.ts} | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) rename examples/with-custom-server/src/{server.js => server.ts} (61%) diff --git a/examples/with-custom-server/src/server.js b/examples/with-custom-server/src/server.ts similarity index 61% rename from examples/with-custom-server/src/server.js rename to examples/with-custom-server/src/server.ts index c6ce0e8..1b42b82 100644 --- a/examples/with-custom-server/src/server.js +++ b/examples/with-custom-server/src/server.ts @@ -1,25 +1,24 @@ -const { setHttpServer, setWebSocketServer } = require('next-ws/server'); -const { Server } = require('node:http'); -const { parse } = require('node:url'); -const next = require('next'); -const { WebSocketServer } = require('ws'); - -const dev = process.env.NODE_ENV !== 'production'; -const hostname = 'localhost'; -const port = 3000; +import { Server } from 'node:http'; +import { parse } from 'node:url'; +import next from 'next'; +import { setHttpServer, setWebSocketServer } from 'next-ws/server'; +import { WebSocketServer } from 'ws'; const httpServer = new Server(); setHttpServer(httpServer); const webSocketServer = new WebSocketServer({ noServer: true }); setWebSocketServer(webSocketServer); -const app = next({ dev, hostname, port, customServer: httpServer }); +const dev = process.env.NODE_ENV !== 'production'; +const hostname = 'localhost'; +const port = 3000; +const app = next({ dev, hostname, port, customServer: true }); const handle = app.getRequestHandler(); app.prepare().then(() => { httpServer .on('request', async (req, res) => { - const parsedUrl = parse(req.url, true); + const parsedUrl = parse(req.url!, true); await handle(req, res, parsedUrl); }) .listen(port, () => {