Skip to content

Added codemods for socket.io 4.0 #459

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions docs/categories/07-Migrations/migrating-from-3-to-4.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,30 @@ Here is the complete list of changes:
- [`autoUnref` option](#autounref-option)
- [Known migration issues](#known-migration-issues)

## Codemods
### Socket.io v4 Codemods
To assist with the upgrade from Socket.io 3.x to 4.0, Codemod provides open-source codemods that automatically transform your code to many of the new APIs and patterns.

Run the following codemod to automatically update your code for Socket.io v4 migration:

```
npx codemod@latest socket.io/4/migration-recipe

```
This will run the following codemods from the Socket.io Codemod repository:
- **socket.io/4/ws-engine-format-update**
- **socket.io/4/removing-useless-broadcast-flag**

Each of these codemods automates the changes listed in the v4 migration guide.
For a complete list of available Fastify codemods and further details,
see the [codemod registry](https://codemod.com/registry?q=socket.io).

If you have any feedback for codemods run this command:

```
npx codemod feedback
```

### Breaking changes

#### `io.to()` is now immutable
Expand Down Expand Up @@ -79,6 +103,12 @@ const io = require("socket.io")(httpServer, {
});
```

> **Note**: Codemod updates the format of ws-engine:
>
> ```bash
> npx codemod@latest socket.io/4/ws-engine-format-update
> ```

### Configuration

#### Ensure compatibility with Swift v15 clients
Expand Down Expand Up @@ -322,3 +352,9 @@ socket.broadcast.to("room1").emit(/* ... */);
// INVALID
socket.to("room1").broadcast.emit(/* ... */);
```

> **Note**: Codemod removes `broadcast flag` with:
>
> ```bash
> npx codemod@latest socket.io/4/removing-useless-broadcast-flag
> ```