diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 701cb21..ce407a4 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -24,8 +24,10 @@ jobs: run: corepack enable - name: Install Deps run: yarn install + - name: Build package + run: yarn g:build-package - name: Typecheck - run: yarn lint + run: yarn lint-all cypress: runs-on: ubuntu-latest @@ -39,7 +41,7 @@ jobs: node-version-file: '.nvmrc' - name: Enable Corepack run: corepack enable - - name: Dev Server Setup + - name: Install Deps run: yarn install - name: Build package run: yarn g:build-package diff --git a/demos/vite-spa/package.json b/demos/vite-spa/package.json index 090ffb1..4daf084 100644 --- a/demos/vite-spa/package.json +++ b/demos/vite-spa/package.json @@ -6,6 +6,7 @@ "type": "module", "scripts": { "dev": "vite --port 1234", + "lint": "tsc --project ./tsconfig.app.json", "g:demo-vite-start": "yarn --cwd $PROJECT_CWD/demos/vite-spa dev" }, "dependencies": { diff --git a/demos/vite-spa/src/GlobalAudioSource/SoundLibrary/index.tsx b/demos/vite-spa/src/GlobalAudioSource/SoundLibrary/index.tsx index 892fa64..c538c43 100644 --- a/demos/vite-spa/src/GlobalAudioSource/SoundLibrary/index.tsx +++ b/demos/vite-spa/src/GlobalAudioSource/SoundLibrary/index.tsx @@ -1,4 +1,3 @@ -import React from "react" import { useGlobalAudioPlayer } from "react-use-audio-player" import "./styles.scss" diff --git a/demos/vite-spa/src/Streaming/index.tsx b/demos/vite-spa/src/Streaming/index.tsx index 086633d..ab3eb7e 100644 --- a/demos/vite-spa/src/Streaming/index.tsx +++ b/demos/vite-spa/src/Streaming/index.tsx @@ -1,4 +1,4 @@ -import React, { useEffect } from "react" +import { useEffect } from "react" import { useAudioPlayer } from "react-use-audio-player" import "./styles.scss" diff --git a/demos/vite-spa/tsconfig.app.json b/demos/vite-spa/tsconfig.app.json index 358ca9b..f545592 100644 --- a/demos/vite-spa/tsconfig.app.json +++ b/demos/vite-spa/tsconfig.app.json @@ -1,4 +1,7 @@ { + "extends": "../../tsconfig.json", + "include": ["./src"], + // compilerOptions were generated by Vite init "compilerOptions": { "tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo", "target": "ES2020", @@ -21,6 +24,5 @@ "noUnusedParameters": true, "noFallthroughCasesInSwitch": true, "noUncheckedSideEffectImports": true - }, - "include": ["src"] + } } diff --git a/package.json b/package.json index e5b737f..c0621ca 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "url": "https://github.com/E-Kuerschner/useAudioPlayer" }, "scripts": { - "lint": "tsc --noEmit", + "lint-all": "yarn workspaces foreach --all run lint", "prepublishOnly": "echo 'TODO prepare'", "preversion": "yarn packages/react-use-audio-player/test && yarn build", "release": "yarn version && yarn publish --non-interactive && echo 'Remember to push new commit/tags to Github'" @@ -24,7 +24,7 @@ }, "husky": { "hooks": { - "pre-commit": "yarn lint" + "pre-commit": "yarn lint-all" } }, "prettier": { diff --git a/packages/react-use-audio-player/package.json b/packages/react-use-audio-player/package.json index 6d5a0a2..9396581 100644 --- a/packages/react-use-audio-player/package.json +++ b/packages/react-use-audio-player/package.json @@ -35,6 +35,7 @@ ], "scripts": { "build": "tsup ./src/index.ts --format esm,cjs --dts --sourcemap --minify --target es6", + "lint": "tsc", "g:build-package": "yarn --cwd $PROJECT_CWD/packages/react-use-audio-player build", "prepublishOnly": "echo 'TODO prepare'", "preversion": "yarn test && yarn build", diff --git a/packages/react-use-audio-player/src/HowlInstanceManager.ts b/packages/react-use-audio-player/src/HowlInstanceManager.ts index 26d8f0d..9247f69 100644 --- a/packages/react-use-audio-player/src/HowlInstanceManager.ts +++ b/packages/react-use-audio-player/src/HowlInstanceManager.ts @@ -1,7 +1,7 @@ -import { Howl, HowlOptions } from "howler" +import { Howl, type HowlOptions } from "howler" -import { AudioLoadOptions } from "./types" -import { Action, ActionTypes } from "./audioPlayerState" +import type { AudioLoadOptions } from "./types" +import { type Action, ActionTypes } from "./audioPlayerState" export type AudioActionCallback = (action: Action) => void @@ -33,12 +33,8 @@ export class HowlInstanceManager { this.destroyHowl() this.options = options - const { - initialVolume, - initialRate, - initialMute, - ...rest - } = this.options + const { initialVolume, initialRate, initialMute, ...rest } = + this.options const newHowl = new Howl({ mute: initialMute, volume: initialVolume, @@ -46,7 +42,7 @@ export class HowlInstanceManager { ...rest } as HowlOptions) - this.callbacks.forEach(cb => + this.callbacks.forEach((cb) => cb({ type: ActionTypes.START_LOAD, howl: newHowl }) ) this.howl = newHowl @@ -78,7 +74,7 @@ export class HowlInstanceManager { } public broadcast(action: Action) { - this.callbacks.forEach(cb => cb(action)) + this.callbacks.forEach((cb) => cb(action)) } } diff --git a/packages/react-use-audio-player/src/audioPlayerState.ts b/packages/react-use-audio-player/src/audioPlayerState.ts index 4c4f210..292727b 100644 --- a/packages/react-use-audio-player/src/audioPlayerState.ts +++ b/packages/react-use-audio-player/src/audioPlayerState.ts @@ -1,4 +1,4 @@ -import { Howl } from "howler" +import { type Howl } from "howler" export enum ActionTypes { START_LOAD = "START_LOAD", diff --git a/packages/react-use-audio-player/src/types.ts b/packages/react-use-audio-player/src/types.ts index 0afacc0..c84fc12 100644 --- a/packages/react-use-audio-player/src/types.ts +++ b/packages/react-use-audio-player/src/types.ts @@ -1,4 +1,4 @@ -import { AudioPlayerState } from "./audioPlayerState" +import { type AudioPlayerState } from "./audioPlayerState" export interface AudioPlayer extends AudioPlayerState { play: () => void @@ -33,4 +33,4 @@ export interface AudioLoadOptions extends UserListeners { html5?: boolean } -export type LoadArguments = [src: string, options?: AudioLoadOptions] \ No newline at end of file +export type LoadArguments = [src: string, options?: AudioLoadOptions] diff --git a/packages/react-use-audio-player/src/useAudioPlayer.ts b/packages/react-use-audio-player/src/useAudioPlayer.ts index 3caeea1..74cd23c 100644 --- a/packages/react-use-audio-player/src/useAudioPlayer.ts +++ b/packages/react-use-audio-player/src/useAudioPlayer.ts @@ -6,7 +6,7 @@ import { } from "./audioPlayerState" import { useHowlEventSync } from "./useHowlEventSync" import { HowlInstanceManager } from "./HowlInstanceManager" -import { AudioPlayer, LoadArguments } from "./types" +import type { AudioPlayer, LoadArguments } from "./types" export const useAudioPlayer = (): AudioPlayer & { cleanup: VoidFunction diff --git a/packages/react-use-audio-player/src/useGlobalAudioPlayer.ts b/packages/react-use-audio-player/src/useGlobalAudioPlayer.ts index a1d87d8..a86755f 100644 --- a/packages/react-use-audio-player/src/useGlobalAudioPlayer.ts +++ b/packages/react-use-audio-player/src/useGlobalAudioPlayer.ts @@ -1,13 +1,13 @@ import { useCallback, useEffect, useReducer, useRef } from "react" import { - Action, + type Action, ActionTypes, initStateFromHowl, reducer as audioStateReducer } from "./audioPlayerState" import { useHowlEventSync } from "./useHowlEventSync" import { HowlInstanceManagerSingleton } from "./HowlInstanceManager" -import { AudioPlayer, LoadArguments } from "./types" +import type { AudioPlayer, LoadArguments } from "./types" export function useGlobalAudioPlayer(): AudioPlayer { const howlManager = useRef(HowlInstanceManagerSingleton.getInstance()) diff --git a/packages/react-use-audio-player/src/useHowlEventSync.ts b/packages/react-use-audio-player/src/useHowlEventSync.ts index 473c20c..ea61b27 100644 --- a/packages/react-use-audio-player/src/useHowlEventSync.ts +++ b/packages/react-use-audio-player/src/useHowlEventSync.ts @@ -1,19 +1,19 @@ import { - Dispatch, - ReducerAction, - ReducerState, + type Dispatch, + type ReducerAction, + type ReducerState, useCallback, useEffect, useRef } from "react" +import { type HowlErrorCallback } from "howler" import { - Action, + type Action, ActionTypes, - AudioPlayerState, + type AudioPlayerState, reducer } from "./audioPlayerState" import { HowlInstanceManager } from "./HowlInstanceManager" -import { HowlErrorCallback } from "howler" export function useHowlEventSync( howlManager: HowlInstanceManager, diff --git a/packages/react-use-audio-player/tsconfig.json b/packages/react-use-audio-player/tsconfig.json new file mode 100644 index 0000000..d931072 --- /dev/null +++ b/packages/react-use-audio-player/tsconfig.json @@ -0,0 +1,11 @@ +{ + "extends": "../../tsconfig.json", + "include": ["./src"], + "compilerOptions": { + "target": "ES6", + // tsup handles the module resolution and outputs so can use full modern features in TS + "module": "esnext", + "moduleResolution": "Bundler", + "verbatimModuleSyntax": true + } +} \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index 88a38e6..cb31e33 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,27 +1,21 @@ { - "include": [ - "packages/react-use-audio-player/src" - ], + // this config is only for extending in child apps/packages + // in the future we could consider including Typescript Project References + "files": [], "compilerOptions": { "noEmit": true, - "target": "es5", - "module": "esnext", - "lib": ["dom", "esnext"], - "declaration": true, - "sourceMap": true, + "declaration": false, + "esModuleInterop": true, + "alwaysStrict": true, "strict": true, "noImplicitAny": true, "strictNullChecks": true, "strictFunctionTypes": true, "strictPropertyInitialization": true, "noImplicitThis": true, - "alwaysStrict": true, "noUnusedLocals": true, "noUnusedParameters": true, "noImplicitReturns": true, - "noFallthroughCasesInSwitch": true, - "moduleResolution": "node", - "jsx": "react", - "esModuleInterop": true + "noFallthroughCasesInSwitch": true } }