Skip to content

Commit 70d99d8

Browse files
authored
Add a workflow for build and publish (#2)
Does exactly what it says on the tin.
1 parent 9dd8265 commit 70d99d8

5 files changed

Lines changed: 71 additions & 3 deletions

File tree

.github/workflows/build-npm.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Build
2+
3+
permissions:
4+
issues: write
5+
pull-requests: write
6+
7+
on:
8+
pull_request:
9+
push:
10+
branches:
11+
- main
12+
13+
jobs:
14+
build:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v4
18+
- uses: actions/setup-node@v4
19+
with:
20+
node-version: 20
21+
- run: npm ci --ignore-scripts
22+
- run: npm run build
23+
- name: 'Test'
24+
run: npx vitest --coverage.enabled true
25+
- name: 'Report Coverage'
26+
if: ${{ !cancelled() }}
27+
uses: davelosert/vitest-coverage-report-action@v2

.github/workflows/publish-npm.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Publish Package to npmjs
2+
3+
on:
4+
release:
5+
types: [created]
6+
7+
jobs:
8+
build:
9+
runs-on: ubuntu-latest
10+
environment: publish
11+
steps:
12+
- uses: actions/checkout@v4
13+
# Setup .npmrc file to publish to npm
14+
- uses: actions/setup-node@v4
15+
with:
16+
node-version: 20
17+
registry-url: 'https://registry.npmjs.org'
18+
- run: npm ci --ignore-scripts
19+
- run: npm run build
20+
- run: npm publish --ignore-scripts
21+
env:
22+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

src/InputListener.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { test, expect, describe } from 'vitest';
2+
import { InputMessageListener } from './InputListener.js';
3+
4+
describe('InputListener Disposes Cleanly', () => {
5+
test('Dispose does not throw', () => {
6+
const listener = new InputMessageListener<string>(
7+
async () => {
8+
await new Promise(resolve => setTimeout(resolve, 250));
9+
return ['hello '];
10+
},
11+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
12+
async (_input) => { return {}}
13+
);
14+
listener.start();
15+
listener.dispose();
16+
expect(listener["_disposed"]).toEqual(true);
17+
});
18+
});

src/InputListener.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import { DeviceCommunicationError } from "./Error.js";
44

55
export type DataProvider<TInput> = () => Promise<TInput[] | DeviceCommunicationError>;
6-
export type InputHandler<TInput> = (input: TInput[]) => IHandlerResponse<TInput>;
6+
export type InputHandler<TInput> = (input: TInput[]) => Promise<IHandlerResponse<TInput>>;
77
export interface IHandlerResponse<TInput> {
88
remainderData?: TInput[];
99
}
@@ -33,7 +33,7 @@ export class InputMessageListener<TInput> {
3333
this.logIfDebug(`Got data from provider, now has ${aggregate.length} items in receive buffer. Data: `, data);
3434

3535
// The handler determines if what we got was sufficient, or if we need more.
36-
const handleResult = this._inputHandler(aggregate);
36+
const handleResult = await this._inputHandler(aggregate);
3737
if (handleResult.remainderData !== undefined && handleResult.remainderData.length !== 0) {
3838
this.logIfDebug(`Input handler provided a ${handleResult.remainderData.length} length incomplete buffer.`);
3939
}

src/Usb/UsbDeviceChannel.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { ConnectionDirectionMode, type IDeviceChannel, type IDeviceCommunication
22
import type { IDeviceInformation } from "../Device.js";
33
import { DeviceCommunicationError, DeviceNotReadyError } from "../Error.js";
44

5-
5+
/** Device information extended with USB information. */
66
export interface IUSBDeviceInformation extends IDeviceInformation {
77
readonly deviceClass: number;
88
readonly deviceSubclass: number;
@@ -14,6 +14,7 @@ export interface IUSBDeviceInformation extends IDeviceInformation {
1414
readonly deviceVersionSubminor: number;
1515
}
1616

17+
/** Convert a USBDevice object to an IUSBDeviceInformation object. */
1718
function deviceToInfo(device: USBDevice): IUSBDeviceInformation {
1819
return {
1920
deviceClass : device.deviceClass,

0 commit comments

Comments
 (0)