From e310fbbeae3f5aa4055a1d6b37191282909beed0 Mon Sep 17 00:00:00 2001 From: Augustin Mauroy Date: Sun, 17 Mar 2024 19:17:13 +0100 Subject: [PATCH] feat(cli): allow forcing --- README.md | 18 ++++++++++++++++-- packages/cli/src/commands/patch.ts | 2 +- packages/cli/tsconfig.json | 3 ++- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 4b93e51..93139c7 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,7 @@ This module is inspired by the now outdated `next-plugin-websocket`, if you are - [🤔 About](#-about) - [🏓 Table of Contents](#-table-of-contents) - [📦 Installation](#-installation) + - [Automated Patching](#automated-patching) - [🚀 Usage](#-usage) - [🚓 Verify Patch](#-verify-patch) - [🌀 Example](#-example) @@ -55,14 +56,27 @@ npm install next-ws ws # ws is a peer dependency, you must install it as well ``` +### Automated Patching + +If you would like to automate the patching process, you can add the following script to your `package.json` file. + +```json +{ + "scripts": { + "postinstall": "FORCE_NEXT_WS_PATCH=true npx next-ws-cli@latest patch" + } +} +``` + ### 🚓 Verify Patch (Optional) -It is recommended to add the following code to the top level of your `next.config.js`. +It is recommended to add the following code to the top level of your `next.config.mjs`. This will verify that Next WS has been patched correctly, and throw an error if it has not. Preventing you from accidentally deploying a broken setup. ```ts -require('next-ws/server').verifyPatch(); +import { verifyPatch } from 'next-ws/server'; +verifyPatch(); ``` --- diff --git a/packages/cli/src/commands/patch.ts b/packages/cli/src/commands/patch.ts index 9e52e50..d0e98b6 100644 --- a/packages/cli/src/commands/patch.ts +++ b/packages/cli/src/commands/patch.ts @@ -39,7 +39,7 @@ export default new Command('patch') default: false, }).then((answer) => answer.confirm)); - if (confirm) { + if (confirm || process.env.FORCE_NEXT_WS_PATCH) { patch = patches[patches.length - 1]; log.info('Continuing with the latest patch'); log.info(`If you encounter any issues please report them at diff --git a/packages/cli/tsconfig.json b/packages/cli/tsconfig.json index 85e7388..2f69a79 100644 --- a/packages/cli/tsconfig.json +++ b/packages/cli/tsconfig.json @@ -3,7 +3,8 @@ "compilerOptions": { "outDir": "./dist", "esModuleInterop": true, - "sourceMap": false + "sourceMap": false, + "noPropertyAccessFromIndexSignature": false, }, "exclude": ["./node_modules/", "*.d.ts"], "include": ["./src/**/*.ts"]