Skip to content

Commit 55f6de3

Browse files
authored
[2.0] Major package upgrades, better TypeScript support, smaller build (#413)
* Add full types for pusher and socketio * Update index.ts * enforce importsNotUsedAsValues * remove .idea files * major upgrades * add external Compatible packages not included in the bundle to rollup * Update package.json * Styleci * fix test & styleci
1 parent 85f7c11 commit 55f6de3

32 files changed

+455
-273
lines changed

.eslintrc.js

Lines changed: 0 additions & 16 deletions
This file was deleted.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ dist/
33
build/
44
npm-debug.log
55
package-lock.json
6+
.idea

.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
20

eslint.config.mjs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import tsParser from "@typescript-eslint/parser";
2+
import tsPlugin from "@typescript-eslint/eslint-plugin";
3+
4+
const config = [
5+
{
6+
files: [
7+
"typings/**/*.ts",
8+
"src/**/*.ts"
9+
],
10+
languageOptions: {
11+
parser: tsParser, // Use the imported parser object
12+
parserOptions: {
13+
ecmaVersion: "latest",
14+
sourceType: "module",
15+
project: "./tsconfig.json", // Path to your TypeScript configuration file
16+
},
17+
},
18+
plugins: {
19+
"@typescript-eslint": tsPlugin,
20+
},
21+
rules: {
22+
...tsPlugin.configs.recommended.rules,
23+
...tsPlugin.configs["recommended-requiring-type-checking"].rules,
24+
"@typescript-eslint/ban-types": "off",
25+
"@typescript-eslint/no-empty-object-type": "off",
26+
"@typescript-eslint/no-explicit-any": "off",
27+
"@typescript-eslint/no-floating-promises": "error",
28+
"@typescript-eslint/no-unsafe-argument": "warn",
29+
"@typescript-eslint/no-unsafe-assignment": "warn",
30+
"@typescript-eslint/no-unsafe-call": "warn",
31+
"@typescript-eslint/no-unsafe-function-type": "off",
32+
"@typescript-eslint/no-unsafe-member-access": "warn",
33+
"@typescript-eslint/no-unsafe-return": "warn",
34+
"@typescript-eslint/no-unused-vars": ["warn", { argsIgnorePattern: "^_" }],
35+
"no-console": "warn",
36+
"prefer-const": "off",
37+
},
38+
},
39+
];
40+
41+
export default config;

jest.config.cjs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module.exports = {
2+
transform: {
3+
"^.+\\.tsx?$": [
4+
"ts-jest",
5+
{
6+
isolatedModules: true
7+
}
8+
],
9+
},
10+
extensionsToTreatAsEsm: [".ts"],
11+
testEnvironment: "node",
12+
};

jest.config.js

Lines changed: 0 additions & 6 deletions
This file was deleted.

package.json

Lines changed: 42 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "laravel-echo",
3-
"version": "1.19.0",
3+
"version": "2.0.0",
44
"description": "Laravel Echo library for beautiful Pusher and Socket.IO integration",
55
"keywords": [
66
"laravel",
@@ -16,41 +16,59 @@
1616
"author": {
1717
"name": "Taylor Otwell"
1818
},
19+
"type": "module",
1920
"main": "dist/echo.common.js",
2021
"module": "dist/echo.js",
2122
"types": "dist/echo.d.ts",
2223
"scripts": {
2324
"build": "npm run compile && npm run declarations",
24-
"compile": "./node_modules/.bin/rollup -c",
25-
"declarations": "./node_modules/.bin/tsc --emitDeclarationOnly",
26-
"lint": "eslint --ext .js,.ts ./src ./tests",
25+
"compile": "rollup -c",
26+
"declarations": "tsc --emitDeclarationOnly",
27+
"lint": "eslint --config eslint.config.mjs",
2728
"prepublish": "npm run build",
2829
"release": "npm run test && standard-version && git push --follow-tags && npm publish",
2930
"test": "jest"
3031
},
3132
"devDependencies": {
32-
"@babel/plugin-proposal-decorators": "^7.17.2",
33-
"@babel/plugin-proposal-export-namespace-from": "^7.16.7",
34-
"@babel/plugin-proposal-function-sent": "^7.16.7",
35-
"@babel/plugin-proposal-numeric-separator": "^7.16.7",
36-
"@babel/plugin-proposal-throw-expressions": "^7.16.7",
37-
"@babel/plugin-transform-object-assign": "^7.16.7",
38-
"@babel/preset-env": "^7.16.11",
39-
"@rollup/plugin-babel": "^5.3.1",
40-
"@types/jest": "^27.4.1",
41-
"@types/node": "^18.11.9",
42-
"@typescript-eslint/eslint-plugin": "^5.14.0",
43-
"@typescript-eslint/parser": "^5.14.0",
44-
"eslint": "^8.11.0",
45-
"jest": "^27.5.1",
46-
"rollup": "^2.70.1",
47-
"rollup-plugin-typescript2": "^0.31.2",
33+
"@babel/core": "^7.26.7",
34+
"@babel/plugin-proposal-decorators": "^7.25.9",
35+
"@babel/plugin-proposal-function-sent": "^7.25.9",
36+
"@babel/plugin-proposal-throw-expressions": "^7.25.9",
37+
"@babel/plugin-transform-export-namespace-from": "^7.25.9",
38+
"@babel/plugin-transform-numeric-separator": "^7.25.9",
39+
"@babel/plugin-transform-object-assign": "^7.25.9",
40+
"@babel/preset-env": "^7.26.7",
41+
"@rollup/plugin-babel": "^6.0.0",
42+
"@rollup/plugin-node-resolve": "^16.0.0",
43+
"@rollup/plugin-typescript": "^12.1.2",
44+
"@types/jest": "^29.5",
45+
"@types/node": "^20.0.0",
46+
"@typescript-eslint/eslint-plugin": "^8.21.0",
47+
"@typescript-eslint/parser": "^8.21.0",
48+
"eslint": "^9.0.0",
49+
"jest": "^29.7.0",
50+
"pusher-js": "^8.0",
51+
"rollup": "^3.0.0",
52+
"socket.io-client": "^4.0",
4853
"standard-version": "^9.3.2",
49-
"ts-jest": "^27.1.3",
50-
"tslib": "^2.3.1",
51-
"typescript": "^4.6.2"
54+
"ts-jest": "^29.2.5",
55+
"typescript": "^5.7.0"
5256
},
5357
"engines": {
54-
"node": ">=10"
58+
"node": ">=20"
59+
},
60+
"exports": {
61+
".": {
62+
"import": "./dist/echo.js",
63+
"require": "./dist/echo.common.js",
64+
"types": "./dist/echo.d.ts"
65+
},
66+
"./iife": "./dist/echo.iife.js"
67+
},
68+
"overrides": {
69+
"glob": "^9.0.0"
70+
},
71+
"dependencies": {
72+
"tslib": "^2.8.1"
5573
}
5674
}

rollup.config.js

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,6 @@
11
import babel from '@rollup/plugin-babel';
2-
import typescript from 'rollup-plugin-typescript2';
3-
4-
const plugins = [
5-
typescript(),
6-
babel({
7-
babelHelpers: 'bundled',
8-
exclude: 'node_modules/**',
9-
extensions: ['.ts'],
10-
presets: ['@babel/preset-env'],
11-
plugins: [
12-
['@babel/plugin-proposal-decorators', { legacy: true }],
13-
'@babel/plugin-proposal-function-sent',
14-
'@babel/plugin-proposal-export-namespace-from',
15-
'@babel/plugin-proposal-numeric-separator',
16-
'@babel/plugin-proposal-throw-expressions',
17-
'@babel/plugin-transform-object-assign',
18-
],
19-
}),
20-
];
2+
import typescript from '@rollup/plugin-typescript';
3+
import resolve from '@rollup/plugin-node-resolve';
214

225
export default [
236
{
@@ -26,11 +9,42 @@ export default [
269
{ file: './dist/echo.js', format: 'esm' },
2710
{ file: './dist/echo.common.js', format: 'cjs' },
2811
],
29-
plugins,
12+
plugins: [
13+
resolve(),
14+
typescript({
15+
tsconfig: './tsconfig.json', // Ensures Rollup aligns with your TS settings
16+
}),
17+
babel({
18+
babelHelpers: 'bundled',
19+
extensions: ['.ts'],
20+
exclude: 'node_modules/**',
21+
presets: ['@babel/preset-env'],
22+
plugins: [
23+
'@babel/plugin-transform-numeric-separator',
24+
'@babel/plugin-transform-export-namespace-from',
25+
['@babel/plugin-proposal-decorators', { legacy: true }],
26+
'@babel/plugin-proposal-function-sent',
27+
'@babel/plugin-proposal-throw-expressions',
28+
'@babel/plugin-transform-object-assign',
29+
],
30+
}),
31+
],
32+
external: ['jquery', 'axios', 'vue', '@hotwired/turbo', 'tslib'], // Compatible packages not included in the bundle
3033
},
3134
{
3235
input: './src/index.iife.ts',
3336
output: [{ file: './dist/echo.iife.js', format: 'iife', name: 'Echo' }],
34-
plugins,
37+
plugins: [
38+
resolve(),
39+
typescript({
40+
tsconfig: './tsconfig.json',
41+
}),
42+
babel({
43+
babelHelpers: 'bundled',
44+
extensions: ['.ts'],
45+
exclude: 'node_modules/**',
46+
}),
47+
],
48+
external: ['jquery', 'axios', 'vue', '@hotwired/turbo', 'tslib'], // Compatible packages not included in the bundle
3549
},
3650
];

src/channel/channel.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,53 @@
1+
import type { EchoOptionsWithDefaults } from '../connector';
2+
import type { BroadcastDriver } from '../echo';
3+
14
/**
25
* This class represents a basic channel.
36
*/
47
export abstract class Channel {
58
/**
69
* The Echo options.
710
*/
8-
options: any;
11+
options: EchoOptionsWithDefaults<BroadcastDriver>;
912

1013
/**
1114
* Listen for an event on the channel instance.
1215
*/
13-
abstract listen(event: string, callback: Function): this;
16+
abstract listen(event: string, callback: CallableFunction): this;
1417

1518
/**
1619
* Listen for a whisper event on the channel instance.
1720
*/
18-
listenForWhisper(event: string, callback: Function): this {
21+
listenForWhisper(event: string, callback: CallableFunction): this {
1922
return this.listen('.client-' + event, callback);
2023
}
2124

2225
/**
2326
* Listen for an event on the channel instance.
2427
*/
25-
notification(callback: Function): this {
28+
notification(callback: CallableFunction): this {
2629
return this.listen('.Illuminate\\Notifications\\Events\\BroadcastNotificationCreated', callback);
2730
}
2831

2932
/**
3033
* Stop listening to an event on the channel instance.
3134
*/
32-
abstract stopListening(event: string, callback?: Function): this;
35+
abstract stopListening(event: string, callback?: CallableFunction): this;
3336

3437
/**
3538
* Stop listening for a whisper event on the channel instance.
3639
*/
37-
stopListeningForWhisper(event: string, callback?: Function): this {
40+
stopListeningForWhisper(event: string, callback?: CallableFunction): this {
3841
return this.stopListening('.client-' + event, callback);
3942
}
4043

4144
/**
4245
* Register a callback to be called anytime a subscription succeeds.
4346
*/
44-
abstract subscribed(callback: Function): this;
47+
abstract subscribed(callback: CallableFunction): this;
4548

4649
/**
4750
* Register a callback to be called anytime an error occurs.
4851
*/
49-
abstract error(callback: Function): this;
52+
abstract error(callback: CallableFunction): this;
5053
}

src/channel/null-channel.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export class NullChannel extends Channel {
77
/**
88
* Subscribe to a channel.
99
*/
10-
subscribe(): any {
10+
subscribe(): void {
1111
//
1212
}
1313

@@ -21,42 +21,42 @@ export class NullChannel extends Channel {
2121
/**
2222
* Listen for an event on the channel instance.
2323
*/
24-
listen(event: string, callback: Function): this {
24+
listen(_event: string, _callback: CallableFunction): this {
2525
return this;
2626
}
2727

2828
/**
2929
* Listen for all events on the channel instance.
3030
*/
31-
listenToAll(callback: Function): this {
31+
listenToAll(_callback: CallableFunction): this {
3232
return this;
3333
}
3434

3535
/**
3636
* Stop listening for an event on the channel instance.
3737
*/
38-
stopListening(event: string, callback?: Function): this {
38+
stopListening(_event: string, _callback?: CallableFunction): this {
3939
return this;
4040
}
4141

4242
/**
4343
* Register a callback to be called anytime a subscription succeeds.
4444
*/
45-
subscribed(callback: Function): this {
45+
subscribed(_callback: CallableFunction): this {
4646
return this;
4747
}
4848

4949
/**
5050
* Register a callback to be called anytime an error occurs.
5151
*/
52-
error(callback: Function): this {
52+
error(_callback: CallableFunction): this {
5353
return this;
5454
}
5555

5656
/**
5757
* Bind a channel to an event.
5858
*/
59-
on(event: string, callback: Function): this {
59+
on(_event: string, _callback: CallableFunction): this {
6060
return this;
6161
}
6262
}

src/channel/null-encrypted-private-channel.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export class NullEncryptedPrivateChannel extends NullChannel {
77
/**
88
* Send a whisper event to other clients in the channel.
99
*/
10-
whisper(eventName: string, data: any): this {
10+
whisper(_eventName: string, _data: Record<any, any>): this {
1111
return this;
1212
}
1313
}

0 commit comments

Comments
 (0)