Skip to content

Commit

Permalink
Add a workflow for build and publish (#2)
Browse files Browse the repository at this point in the history
Does exactly what it says on the tin.
  • Loading branch information
Cellivar committed Jan 29, 2024
1 parent 9dd8265 commit 70d99d8
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 3 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/build-npm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Build

permissions:
issues: write
pull-requests: write

on:
pull_request:
push:
branches:
- main

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- run: npm ci --ignore-scripts
- run: npm run build
- name: 'Test'
run: npx vitest --coverage.enabled true
- name: 'Report Coverage'
if: ${{ !cancelled() }}
uses: davelosert/vitest-coverage-report-action@v2
22 changes: 22 additions & 0 deletions .github/workflows/publish-npm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Publish Package to npmjs

on:
release:
types: [created]

jobs:
build:
runs-on: ubuntu-latest
environment: publish
steps:
- uses: actions/checkout@v4
# Setup .npmrc file to publish to npm
- uses: actions/setup-node@v4
with:
node-version: 20
registry-url: 'https://registry.npmjs.org'
- run: npm ci --ignore-scripts
- run: npm run build
- run: npm publish --ignore-scripts
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
18 changes: 18 additions & 0 deletions src/InputListener.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { test, expect, describe } from 'vitest';
import { InputMessageListener } from './InputListener.js';

describe('InputListener Disposes Cleanly', () => {
test('Dispose does not throw', () => {
const listener = new InputMessageListener<string>(
async () => {
await new Promise(resolve => setTimeout(resolve, 250));
return ['hello '];
},
// eslint-disable-next-line @typescript-eslint/no-unused-vars
async (_input) => { return {}}
);
listener.start();
listener.dispose();
expect(listener["_disposed"]).toEqual(true);
});
});
4 changes: 2 additions & 2 deletions src/InputListener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { DeviceCommunicationError } from "./Error.js";

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

// The handler determines if what we got was sufficient, or if we need more.
const handleResult = this._inputHandler(aggregate);
const handleResult = await this._inputHandler(aggregate);
if (handleResult.remainderData !== undefined && handleResult.remainderData.length !== 0) {
this.logIfDebug(`Input handler provided a ${handleResult.remainderData.length} length incomplete buffer.`);
}
Expand Down
3 changes: 2 additions & 1 deletion src/Usb/UsbDeviceChannel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ConnectionDirectionMode, type IDeviceChannel, type IDeviceCommunication
import type { IDeviceInformation } from "../Device.js";
import { DeviceCommunicationError, DeviceNotReadyError } from "../Error.js";


/** Device information extended with USB information. */
export interface IUSBDeviceInformation extends IDeviceInformation {
readonly deviceClass: number;
readonly deviceSubclass: number;
Expand All @@ -14,6 +14,7 @@ export interface IUSBDeviceInformation extends IDeviceInformation {
readonly deviceVersionSubminor: number;
}

/** Convert a USBDevice object to an IUSBDeviceInformation object. */
function deviceToInfo(device: USBDevice): IUSBDeviceInformation {
return {
deviceClass : device.deviceClass,
Expand Down

0 comments on commit 70d99d8

Please sign in to comment.