Skip to content

Commit

Permalink
chore: update tools and eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
Julusian committed Sep 23, 2024
1 parent 9d78a2e commit c25f43b
Show file tree
Hide file tree
Showing 24 changed files with 580 additions and 787 deletions.
4 changes: 0 additions & 4 deletions .eslintignore

This file was deleted.

3 changes: 0 additions & 3 deletions .eslintrc.cjs

This file was deleted.

5 changes: 5 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { generateEslintConfig } from '@companion-module/tools/eslint/config.mjs'

export default generateEslintConfig({
enableTypescript: true,
})
6 changes: 3 additions & 3 deletions lib/debounce-fn/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,17 @@ window.onresize = debounceFn(() => {
*/
declare function debounceFn<ArgumentsType extends unknown[], ReturnType>(
input: (...arguments: ArgumentsType) => ReturnType,
options: debounceFn.BeforeOptions
options: debounceFn.BeforeOptions,
): debounceFn.DebouncedFunction<ArgumentsType, ReturnType>

declare function debounceFn<ArgumentsType extends unknown[], ReturnType>(
input: (...arguments: ArgumentsType) => ReturnType,
options: debounceFn.NoBeforeNoAfterOptions
options: debounceFn.NoBeforeNoAfterOptions,
): debounceFn.DebouncedFunction<ArgumentsType, undefined>

declare function debounceFn<ArgumentsType extends unknown[], ReturnType>(
input: (...arguments: ArgumentsType) => ReturnType,
options?: debounceFn.Options
options?: debounceFn.Options,
): debounceFn.DebouncedFunction<ArgumentsType, ReturnType | undefined>

export = debounceFn
2 changes: 2 additions & 0 deletions lib/debounce-fn/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
'use strict'
// eslint-disable-next-line @typescript-eslint/no-require-imports
const mimicFn = require('mimic-fn')

module.exports = (inputFunction, options = {}) => {
Expand All @@ -17,6 +18,7 @@ module.exports = (inputFunction, options = {}) => {
let result

const debouncedFunction = function (...arguments_) {
// eslint-disable-next-line @typescript-eslint/no-this-alias
const context = this

const later = () => {
Expand Down
16 changes: 9 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"build:json-schema": "json2ts --input assets/manifest.schema.json --output generated/manifest.d.ts",
"build:ajv-validator": "ajv compile -s assets/manifest.schema.json -o generated/validate_manifest.js",
"docs:html": "typedoc --tsconfig tsconfig.build.json --entryPoints src/index.ts --excludePrivate --theme default --out docs",
"lint:raw": "./node_modules/.bin/eslint --ext .ts --ext .js",
"lint:raw": "eslint",
"lint": "yarn lint:raw .",
"unit": "jest"
},
Expand All @@ -32,28 +32,30 @@
"ajv": "^8.17.1",
"colord": "^2.9.3",
"ejson": "^2.2.3",
"eventemitter3": "^4.0.7",
"eventemitter3": "^5.0.1",
"mimic-fn": "^3.1.0",
"nanoid": "^3.3.7",
"p-queue": "^6.6.2",
"p-timeout": "^4.1.0",
"tslib": "^2.7.0"
},
"devDependencies": {
"@companion-module/tools": "^1.5.1",
"@companion-module/tools": "^2.1.0",
"@tsconfig/node18": "^18.2.4",
"@types/ejson": "^2.2.2",
"@types/jest": "^29.5.12",
"@types/node": "^18.19.45",
"@types/jest": "^29.5.13",
"@types/node": "^18.19.50",
"ajv-cli": "^5.0.0",
"eslint": "^9.11.1",
"jest": "^29.7.0",
"jest-extended": "^4.0.2",
"jest-mock-extended": "^3.0.7",
"json-schema-to-typescript": "^13.1.2",
"prettier": "^2.8.8",
"prettier": "^3.3.3",
"ts-jest": "^29.2.5",
"typedoc": "^0.25.13",
"typescript": "~5.1.6"
"typescript": "~5.1.6",
"typescript-eslint": "^8.7.0"
},
"packageManager": "[email protected]"
}
4 changes: 2 additions & 2 deletions src/__mocks__/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ export function createIpcWrapperMock<TOutbound extends { [key: string]: any }, T
sendWithCb?: jest.Mock<
ReturnType<IpcWrapper<TOutbound, TInbound>['sendWithCb']>,
Parameters<IpcWrapper<TOutbound, TInbound>['sendWithCb']>
>
>,
): IpcWrapper<TOutbound, TInbound> {
return mock<IpcWrapper<TOutbound, TInbound>>(
{
sendWithCb,
},
mockOptions
mockOptions,
)
}

Expand Down
11 changes: 5 additions & 6 deletions src/entrypoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export type InstanceConstructor<TConfig> = new (internal: unknown) => InstanceBa
*/
export function runEntrypoint<TConfig>(
factory: InstanceConstructor<TConfig>,
upgradeScripts: CompanionStaticUpgradeScript<TConfig>[]
upgradeScripts: CompanionStaticUpgradeScript<TConfig>[],
): void {
Promise.resolve()
.then(async () => {
Expand Down Expand Up @@ -69,7 +69,7 @@ export function runEntrypoint<TConfig>(
if (baseJson.name === '@companion-module/base') {
apiVersion = baseJson.version
}
} catch (e) {
} catch (_e) {
throw new Error('Failed to determine module api version')
}
}
Expand Down Expand Up @@ -116,10 +116,9 @@ export function runEntrypoint<TConfig>(
const ipcWrapper = new IpcWrapper<ModuleToHostEventsInit, HostToModuleEventsInit>(
{},
(msg) => {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
process.send!(msg)
},
5000
5000,
)
process.once('message', (msg: any) => {
ipcWrapper.receivedMessage(msg)
Expand All @@ -130,7 +129,7 @@ export function runEntrypoint<TConfig>(
id: connectionId,
upgradeScripts,
_isInstanceBaseProps: true,
})
}),
)

ipcWrapper.sendWithCb('register', { apiVersion, connectionId, verificationToken }).then(
Expand All @@ -142,7 +141,7 @@ export function runEntrypoint<TConfig>(

// Kill the process
process.exit(11)
}
},
)
})
.catch((e) => {
Expand Down
4 changes: 2 additions & 2 deletions src/helpers/udp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ export class UDPHelper extends EventEmitter<UDPHelperEvents> {

try {
this.#socket.bind(this.#options.bind_port || 0, this.#options.bind_ip)
} catch (e) {
} catch (_e) {
throw new Error(
`Unable to bind to ip/port: ${this.#options.bind_ip || '0.0.0.0'}:${this.#options.bind_port || 0}`
`Unable to bind to ip/port: ${this.#options.bind_ip || '0.0.0.0'}:${this.#options.bind_port || 0}`,
)
}

Expand Down
4 changes: 3 additions & 1 deletion src/host-api/__tests__/ipc-wrapper.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe('IpcWrapper', () => {
recvTest2: testRecv2Fn,
},
sendMessageFn,
100
100,
)
})

Expand Down Expand Up @@ -295,6 +295,7 @@ describe('IpcWrapper', () => {

test('throw error as string', async () => {
testRecv2Fn.mockImplementation(async () => {
// eslint-disable-next-line @typescript-eslint/only-throw-error
throw 'my error message'
})

Expand All @@ -321,6 +322,7 @@ describe('IpcWrapper', () => {

test('throw null', async () => {
testRecv2Fn.mockImplementation(async () => {
// eslint-disable-next-line @typescript-eslint/only-throw-error
throw null
})

Expand Down
11 changes: 5 additions & 6 deletions src/host-api/ipc-wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ const MAX_CALLBACK_ID = 1 << 28
*/
type HandlerFunction<T extends (...args: any) => any> = (data: Parameters<T>[0]) => HandlerReturnType<T>

type HandlerReturnType<T extends (...args: any) => any> = ReturnType<T> extends never
? Promise<void>
: Promise<ReturnType<T>>
type HandlerReturnType<T extends (...args: any) => any> =
ReturnType<T> extends never ? Promise<void> : Promise<ReturnType<T>>

type HandlerFunctionOrNever<T> = T extends (...args: any) => any ? HandlerFunction<T> : never

Expand Down Expand Up @@ -52,7 +51,7 @@ export class IpcWrapper<TOutbound extends { [key: string]: any }, TInbound exten
constructor(
handlers: IpcEventHandlers<TInbound>,
sendMessage: (message: IpcCallMessagePacket | IpcResponseMessagePacket) => void,
defaultTimeout: number
defaultTimeout: number,
) {
this.#handlers = handlers
this.#sendMessage = sendMessage
Expand All @@ -63,7 +62,7 @@ export class IpcWrapper<TOutbound extends { [key: string]: any }, TInbound exten
name: T,
msg: ParamsIfReturnIsValid<TOutbound[T]>[0],
defaultResponse?: () => Error,
timeout = 0
timeout = 0,
): Promise<ReturnType<TOutbound[T]>> {
if (timeout <= 0) timeout = this.#defaultTimeout

Expand Down Expand Up @@ -145,7 +144,7 @@ export class IpcWrapper<TOutbound extends { [key: string]: any }, TInbound exten
err instanceof Error ? JSON.stringify(err, Object.getOwnPropertyNames(err)) : ejson.stringify(err),
})
}
}
},
)

break
Expand Down
Loading

0 comments on commit c25f43b

Please sign in to comment.