Skip to content

Commit 98f2f0b

Browse files
committed
Update bundling/packaging to have 2 entrypoints
1 parent 4863442 commit 98f2f0b

File tree

8 files changed

+3246
-4312
lines changed

8 files changed

+3246
-4312
lines changed

.eslintrc.cjs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
/* eslint-disable @typescript-eslint/no-var-requires, @typescript-eslint/no-require-imports, @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-call */
2+
const xoTypescript = require('eslint-config-xo-typescript');
3+
14
/** @type {import('eslint').Linter.Config} */
25
module.exports = {
36
extends: [
@@ -8,6 +11,24 @@ module.exports = {
811
project: './tsconfig.eslint.json',
912
extraFileExtensions: ['.cjs'],
1013
},
14+
rules: {
15+
'@typescript-eslint/naming-convention': [
16+
// Allow for OBS in class/interface name
17+
...xoTypescript.rules['@typescript-eslint/naming-convention'].map(
18+
options => {
19+
console.log({options});
20+
if (options.selector === 'typeLike' || options.selector === 'interface') {
21+
return {
22+
...options,
23+
format: ['PascalCase'],
24+
};
25+
}
26+
27+
return options;
28+
},
29+
),
30+
],
31+
},
1132
overrides: [
1233
{
1334
files: ['test/**/*.{js,ts}'],

package-lock.json

Lines changed: 3153 additions & 4254 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 47 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -14,31 +14,44 @@
1414
"node.js"
1515
],
1616
"type": "module",
17-
"main": "dist/obs-ws.cjs",
18-
"module": "dist/obs-ws.module.js",
19-
"unpkg": "dist/obs-ws.min.js",
20-
"exports": "./dist/obs-ws.modern.js",
21-
"source": "src/index.ts",
22-
"types": "dist/index.d.ts",
17+
"exports": {
18+
".": {
19+
"require": "./dist/json.cjs",
20+
"browser": "./dist/json.modern.js",
21+
"default": "./dist/msgpack.modern.js"
22+
},
23+
"./json": {
24+
"require": "./dist/json.cjs",
25+
"default": "./dist/json.modern.js"
26+
},
27+
"./msgpack": {
28+
"require": "./dist/msgpack.cjs",
29+
"default": "./dist/msgpack.modern.js"
30+
}
31+
},
32+
"main": "dist/json.cjs",
33+
"module": "dist/json.module.js",
34+
"amdName": "OBSWebSocket",
35+
"unpkg": "dist/obs-ws.min.cjs",
36+
"types": "dist/json.d.ts",
37+
"engines": {
38+
"node": ">12.0"
39+
},
2340
"files": [
2441
"dist"
2542
],
2643
"scripts": {
27-
"build": "npm-run-all clean build:bundle build:unpkg",
28-
"build:bundle": "microbundle -f modern,esm,cjs --no-compress",
29-
"build:unpkg": "microbundle -f iife src/JsonOBSWebSocket.ts -o dist/obs-ws.min.js --external none",
30-
"build:obs-types": "cross-env-shell TS_NODE_PROJECT=tsconfig.json \"node $NODE_DEBUG_OPTION -r ts-node/register scripts/build-types-v2.ts\"",
31-
"postbuild:obs-types": "npm run lint",
44+
"build": "npm-run-all clean build:*",
45+
"build:bundle": "microbundle -f modern,esm,cjs --no-compress src/{json,msgpack}.ts",
46+
"build:unpkg": "microbundle -f iife src/json.ts -o dist/obs-ws.min.js --external none",
3247
"clean": "rimraf dist",
3348
"dev": "npm run build:bundle -- --watch",
3449
"lint": "eslint . --ext .cjs,.js,.ts",
35-
"test": "npm-run-all test:*",
36-
"test:static": "npm run lint",
37-
"test:ava": "npm run ava",
38-
"test:types": "dtslint types",
39-
"report": "nyc report --reporter=text-lcov",
40-
"node-coveralls": "npm run report | coveralls",
41-
"ava": "nyc ava --verbose"
50+
"test": "nyc ava",
51+
"test:watch": "ava --watch",
52+
"obs-types": "cross-env-shell TS_NODE_PROJECT=tsconfig.json \"node $NODE_DEBUG_OPTION -r ts-node/register scripts/build-types-v2.ts\"",
53+
"postobs-types": "npm run lint",
54+
"report": "nyc report --reporter=text-lcov"
4255
},
4356
"dependencies": {
4457
"@msgpack/msgpack": "^2.7.1",
@@ -53,36 +66,37 @@
5366
"@types/crypto-js": "^4.0.1",
5467
"@types/debug": "^4.1.5",
5568
"@types/node-fetch": "^2.5.10",
56-
"@types/ws": "^7.4.4",
57-
"@typescript-eslint/eslint-plugin": "^4.28.0",
58-
"@typescript-eslint/parser": "^4.28.0",
59-
"ava": "^3.15.0",
69+
"@types/ws": "^8.2.0",
70+
"@typescript-eslint/eslint-plugin": "^5.4.0",
71+
"@typescript-eslint/parser": "^5.4.0",
72+
"ava": "^4.0.0-rc.1",
6073
"coveralls": "^3.1.0",
6174
"cross-env": "^7.0.3",
62-
"eslint": "^7.28.0",
63-
"eslint-config-xo": "^0.38.0",
64-
"eslint-config-xo-typescript": "^0.44.0",
65-
"eslint-plugin-ava": "^12.0.0",
75+
"eslint": "^8.2.0",
76+
"eslint-config-xo": "^0.39.0",
77+
"eslint-config-xo-typescript": "^0.47.1",
78+
"eslint-plugin-ava": "^13.1.0",
6679
"lodash.deburr": "^4.1.0",
67-
"microbundle": "^0.13.3",
80+
"microbundle": "^0.14.2",
6881
"node-fetch": "^2.6.1",
6982
"npm-run-all": "^4.1.5",
7083
"nyc": "^15.1.0",
7184
"rimraf": "^3.0.2",
72-
"ts-node": "^10.2.1",
85+
"ts-node": "^10.4.0",
7386
"typescript": "^4.4.3"
7487
},
7588
"bugs": {
7689
"url": "https://github.com/obs-websocket-community-projects/obs-websocket-js/issues"
7790
},
7891
"homepage": "https://github.com/obs-websocket-community-projects/obs-websocket-js#readme",
7992
"ava": {
80-
"files": [
81-
"test/*.spec.js",
82-
"!setup/environment.js"
93+
"extensions": {
94+
"ts": "module"
95+
},
96+
"nodeArguments": [
97+
"--loader=ts-node/esm",
98+
"--experimental-specifier-resolution=node"
8399
],
84-
"concurrency": 1,
85-
"timeout": "10s",
86100
"verbose": true
87101
}
88102
}

src/BaseOBSWebSocket.ts renamed to src/base.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,15 @@ IncomingMessageTypes[OpCode.Identified]
3737
export abstract class BaseOBSWebSocket extends EventEmitter<MapValueToArgsArray<EventTypes>> {
3838
protected static requestCounter = 0;
3939

40+
protected static generateMessageId(): string {
41+
return String(BaseOBSWebSocket.requestCounter++);
42+
}
43+
4044
protected _identified = false;
4145
protected internalListeners = new EventEmitter();
4246
protected socket?: WebSocket;
4347
protected abstract protocol: string;
4448

45-
protected static generateMessageId(): string {
46-
return String(BaseOBSWebSocket.requestCounter++);
47-
}
48-
4949
public get identified() {
5050
return this._identified;
5151
}
@@ -68,15 +68,15 @@ export abstract class BaseOBSWebSocket extends EventEmitter<MapValueToArgsArray<
6868
}
6969

7070
try {
71-
const ConnectionClosedPromise = this.internalEventPromise<CloseEvent>('ConnectionClosed');
71+
const connectionClosedPromise = this.internalEventPromise<CloseEvent>('ConnectionClosed');
7272

7373
return await Promise.race([
7474
(async () => {
7575
const hello = await this.createConnection(url);
7676
this.emit('Hello', hello);
7777
return this.identify(hello, password, identificationParams);
7878
})(),
79-
ConnectionClosedPromise.then(e => {
79+
connectionClosedPromise.then(e => {
8080
throw new OBSWebSocketError(e.code, e.reason);
8181
}),
8282
]);
@@ -94,9 +94,9 @@ export abstract class BaseOBSWebSocket extends EventEmitter<MapValueToArgsArray<
9494
return;
9595
}
9696

97-
const ConnectionClosedPromise = this.internalEventPromise('ConnectionClosed');
97+
const connectionClosedPromise = this.internalEventPromise('ConnectionClosed');
9898
this.socket.close();
99-
await ConnectionClosedPromise;
99+
await connectionClosedPromise;
100100
}
101101

102102
/**
@@ -106,9 +106,9 @@ export abstract class BaseOBSWebSocket extends EventEmitter<MapValueToArgsArray<
106106
* @returns Identified message data
107107
*/
108108
async reidentify(data: OutgoingMessageTypes[OpCode.Reidentify]) {
109-
const IdentifiedPromise = this.internalEventPromise<IncomingMessageTypes[OpCode.Identified]>(`op:${OpCode.Identified}`);
109+
const identifiedPromise = this.internalEventPromise<IncomingMessageTypes[OpCode.Identified]>(`op:${OpCode.Identified}`);
110110
await this.message(OpCode.Reidentify, data);
111-
return IdentifiedPromise;
111+
return identifiedPromise;
112112
}
113113

114114
/**
@@ -119,13 +119,13 @@ export abstract class BaseOBSWebSocket extends EventEmitter<MapValueToArgsArray<
119119
*/
120120
async call<Type extends keyof OBSRequestTypes>(requestType: Type, requestData: OBSRequestTypes[Type]): Promise<OBSResponseTypes[Type]> {
121121
const requestId = BaseOBSWebSocket.generateMessageId();
122-
const ResponsePromise = this.internalEventPromise<ResponseMessage<Type>>(`res:${requestId}`);
122+
const responsePromise = this.internalEventPromise<ResponseMessage<Type>>(`res:${requestId}`);
123123
await this.message(OpCode.Request, {
124124
requestId,
125125
requestType,
126126
requestData,
127127
} as RequestMessage<Type>);
128-
const {requestStatus, responseData} = await ResponsePromise;
128+
const {requestStatus, responseData} = await responsePromise;
129129

130130
if (!requestStatus.result) {
131131
throw new OBSWebSocketError(requestStatus.code, requestStatus.comment);
@@ -159,16 +159,16 @@ export abstract class BaseOBSWebSocket extends EventEmitter<MapValueToArgsArray<
159159
* @param url Websocket address
160160
*/
161161
protected async createConnection(url: string) {
162-
const ConnectionOpenedPromise = this.internalEventPromise('ConnectionOpened');
163-
const HelloPromise = this.internalEventPromise<IncomingMessageTypes[OpCode.Hello]>(`op:${OpCode.Hello}`);
162+
const connectionOpenedPromise = this.internalEventPromise('ConnectionOpened');
163+
const helloPromise = this.internalEventPromise<IncomingMessageTypes[OpCode.Hello]>(`op:${OpCode.Hello}`);
164164

165165
this.socket = new WebSocketIpml(url, this.protocol) as unknown as WebSocket;
166166
this.socket.onopen = this.onOpen.bind(this);
167167
this.socket.onmessage = this.onMessage.bind(this);
168168
this.socket.onerror = this.onError.bind(this);
169169
this.socket.onclose = this.onClose.bind(this);
170170

171-
await ConnectionOpenedPromise;
171+
await connectionOpenedPromise;
172172
const protocol = this.socket?.protocol;
173173
if (!protocol) {
174174
throw new OBSWebSocketError(-1, 'Missing socket protocol (server must be v5 or newer)');
@@ -178,7 +178,7 @@ export abstract class BaseOBSWebSocket extends EventEmitter<MapValueToArgsArray<
178178
throw new OBSWebSocketError(-2, `Unknown socket protocol (${protocol})`);
179179
}
180180

181-
return HelloPromise;
181+
return helloPromise;
182182
}
183183

184184
/**
@@ -208,9 +208,9 @@ export abstract class BaseOBSWebSocket extends EventEmitter<MapValueToArgsArray<
208208
data.authentication = authenticationHashing(authentication.salt, authentication.challenge, password);
209209
}
210210

211-
const IdentifiedPromise = this.internalEventPromise<IncomingMessageTypes[OpCode.Identified]>(`op:${OpCode.Identified}`);
211+
const identifiedPromise = this.internalEventPromise<IncomingMessageTypes[OpCode.Identified]>(`op:${OpCode.Identified}`);
212212
await this.message(OpCode.Identify, data);
213-
const identified = await IdentifiedPromise;
213+
const identified = await identifiedPromise;
214214
this._identified = true;
215215
this.emit('Identified', identified);
216216

src/index.ts

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

src/JsonOBSWebSocket.ts renamed to src/json.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
import {BaseOBSWebSocket} from './BaseOBSWebSocket.js';
1+
import {BaseOBSWebSocket} from './base.js';
2+
export {OBSWebSocketError} from './base.js';
23
import {IncomingMessage, OutgoingMessage} from './types.js';
4+
export * from './types.js';
35

46
export default class JsonOBSWebSocket extends BaseOBSWebSocket {
57
protocol = 'obswebsocket.json';

src/MsgpackOBSWebSocket.ts renamed to src/msgpack.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import {decode, encode} from '@msgpack/msgpack';
2-
import {BaseOBSWebSocket} from './BaseOBSWebSocket.js';
2+
import {BaseOBSWebSocket} from './base.js';
3+
export {OBSWebSocketError} from './base.js';
34
import {IncomingMessage, OutgoingMessage} from './types.js';
5+
export * from './types.js';
46

57
export default class MsgpackOBSWebSocket extends BaseOBSWebSocket {
68
protocol = 'obswebsocket.msgpack';

src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// This file is manually updated while obs-websocket doesn't have
2-
// comments.json in 5.x branch.
2+
// docs/comments.json in 5.x branch.
33

44
import {JsonObject, JsonPrimitive, JsonValue} from 'type-fest';
55

0 commit comments

Comments
 (0)