Skip to content

Commit

Permalink
Revamp TS setup with child configs extending root with common properties
Browse files Browse the repository at this point in the history
  • Loading branch information
E-Kuerschner committed Jan 5, 2025
1 parent 7756bf6 commit 3fdf11d
Show file tree
Hide file tree
Showing 15 changed files with 50 additions and 44 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions demos/vite-spa/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import React from "react"
import { useGlobalAudioPlayer } from "react-use-audio-player"
import "./styles.scss"

Expand Down
2 changes: 1 addition & 1 deletion demos/vite-spa/src/Streaming/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect } from "react"
import { useEffect } from "react"
import { useAudioPlayer } from "react-use-audio-player"
import "./styles.scss"

Expand Down
6 changes: 4 additions & 2 deletions demos/vite-spa/tsconfig.app.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -21,6 +24,5 @@
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true,
"noUncheckedSideEffectImports": true
},
"include": ["src"]
}
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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'"
Expand All @@ -24,7 +24,7 @@
},
"husky": {
"hooks": {
"pre-commit": "yarn lint"
"pre-commit": "yarn lint-all"
}
},
"prettier": {
Expand Down
1 change: 1 addition & 0 deletions packages/react-use-audio-player/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
18 changes: 7 additions & 11 deletions packages/react-use-audio-player/src/HowlInstanceManager.ts
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -33,20 +33,16 @@ 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,
rate: initialRate,
...rest
} as HowlOptions)

this.callbacks.forEach(cb =>
this.callbacks.forEach((cb) =>
cb({ type: ActionTypes.START_LOAD, howl: newHowl })
)
this.howl = newHowl
Expand Down Expand Up @@ -78,7 +74,7 @@ export class HowlInstanceManager {
}

public broadcast(action: Action) {
this.callbacks.forEach(cb => cb(action))
this.callbacks.forEach((cb) => cb(action))
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/react-use-audio-player/src/audioPlayerState.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Howl } from "howler"
import { type Howl } from "howler"

export enum ActionTypes {
START_LOAD = "START_LOAD",
Expand Down
4 changes: 2 additions & 2 deletions packages/react-use-audio-player/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AudioPlayerState } from "./audioPlayerState"
import { type AudioPlayerState } from "./audioPlayerState"

export interface AudioPlayer extends AudioPlayerState {
play: () => void
Expand Down Expand Up @@ -33,4 +33,4 @@ export interface AudioLoadOptions extends UserListeners {
html5?: boolean
}

export type LoadArguments = [src: string, options?: AudioLoadOptions]
export type LoadArguments = [src: string, options?: AudioLoadOptions]
2 changes: 1 addition & 1 deletion packages/react-use-audio-player/src/useAudioPlayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions packages/react-use-audio-player/src/useGlobalAudioPlayer.ts
Original file line number Diff line number Diff line change
@@ -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())
Expand Down
12 changes: 6 additions & 6 deletions packages/react-use-audio-player/src/useHowlEventSync.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
11 changes: 11 additions & 0 deletions packages/react-use-audio-player/tsconfig.json
Original file line number Diff line number Diff line change
@@ -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
}
}
20 changes: 7 additions & 13 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -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
}
}

0 comments on commit 3fdf11d

Please sign in to comment.