Skip to content

Commit

Permalink
Refactor imports to use 'type' keyword for TypeScript types and updat…
Browse files Browse the repository at this point in the history
…e tsconfig settings
  • Loading branch information
Sandakan committed Mar 4, 2025
1 parent 21e122a commit 0d7246c
Show file tree
Hide file tree
Showing 37 changed files with 58 additions and 51 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
"prettier-check": "prettier --check .",
"prettier-write": "prettier --write .",
"format": "prettier --write .",
"lint": "eslint . && tsc --noEmit",
"lint": "eslint .",
"eslint-inspector": "npx @eslint/config-inspector@latest",
"typecheck:node": "tsc --noEmit -p tsconfig.node.json --composite false",
"typecheck:web": "tsc --noEmit -p tsconfig.web.json --composite false",
Expand Down
2 changes: 1 addition & 1 deletion src/main/auth/manageLastFmAuth.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { setUserData } from '../filesystem';
import { LastFMSessionGetResponse } from '../../types/last_fm_api';
import type { LastFMSessionGetResponse } from '../../types/last_fm_api';
import hashText from '../utils/hashText';
import { encrypt } from '../utils/safeStorage';
import { sendMessageToRenderer } from '../main';
Expand Down
2 changes: 1 addition & 1 deletion src/main/core/exportAppData.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import fs from 'fs/promises';
import path from 'path';
import { OpenDialogOptions, app } from 'electron';
import { type OpenDialogOptions, app } from 'electron';

import {
getAlbumsData,
Expand Down
2 changes: 1 addition & 1 deletion src/main/core/exportPlaylist.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { writeFile } from 'fs/promises';
import { basename } from 'path';
import { SaveDialogOptions } from 'electron';
import type { SaveDialogOptions } from 'electron';

import logger from '../logger';
import { getPlaylistData, getSongsData } from '../filesystem';
Expand Down
2 changes: 1 addition & 1 deletion src/main/core/fetchSongInfoFromLastFM.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logger from '../logger';
import { checkIfConnectedToInternet } from '../main';
import { LastFMTrackInfoApi } from '../../types/last_fm_api';
import type { LastFMTrackInfoApi } from '../../types/last_fm_api';

const LAST_FM_BASE_URL = 'http://ws.audioscrobbler.com/2.0/';

Expand Down
4 changes: 2 additions & 2 deletions src/main/core/getArtistInfoFromNet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import { checkIfConnectedToInternet, dataUpdateEvent } from '../main';
import { getArtistArtworkPath } from '../fs/resolveFilePaths';
import getArtistInfoFromLastFM from '../other/lastFm/getArtistInfoFromLastFM';

import { DeezerArtistInfo, DeezerArtistInfoApi } from '../../types/deezer_api';
import { SimilarArtist } from '../../types/last_fm_artist_info_api';
import type { DeezerArtistInfo, DeezerArtistInfoApi } from '../../types/deezer_api';
import type { SimilarArtist } from '../../types/last_fm_artist_info_api';

const DEEZER_BASE_URL = 'https://api.deezer.com/';

Expand Down
2 changes: 1 addition & 1 deletion src/main/core/importAppData.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import fs from 'fs/promises';
import path from 'path';
import { OpenDialogOptions } from 'electron';
import type { OpenDialogOptions } from 'electron';

import { restartApp, sendMessageToRenderer, showOpenDialog } from '../main';
import logger from '../logger';
Expand Down
2 changes: 1 addition & 1 deletion src/main/core/importPlaylist.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { readFile } from 'fs/promises';
import path from 'path';
import { OpenDialogOptions } from 'electron';
import type { OpenDialogOptions } from 'electron';

import { sendMessageToRenderer, showOpenDialog } from '../main';
import logger from '../logger';
Expand Down
2 changes: 1 addition & 1 deletion src/main/core/saveArtworkToSystem.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SaveDialogOptions } from 'electron';
import type { SaveDialogOptions } from 'electron';
import sharp from 'sharp';

import logger from '../logger';
Expand Down
2 changes: 1 addition & 1 deletion src/main/filesystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
userDataMigrations
} from './migrations';
import { encrypt } from './utils/safeStorage';
import { LastFMSessionData } from '../types/last_fm_api';
import type { LastFMSessionData } from '../types/last_fm_api';
import { DEFAULT_SONG_PALETTE } from './other/generatePalette';
import isPathADir from './utils/isPathADir';
import { clearDiscordRpcActivity } from './other/discordRPC';
Expand Down
2 changes: 1 addition & 1 deletion src/main/fs/addWatchersToFolders.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import path from 'path';
import fs from 'fs/promises';
import fsSync, { WatchEventType } from 'fs';
import fsSync, { type WatchEventType } from 'fs';
import { getUserData, supportedMusicExtensions } from '../filesystem';
import logger from '../logger';
import checkFolderForUnknownModifications from './checkFolderForUnknownContentModifications';
Expand Down
2 changes: 1 addition & 1 deletion src/main/fs/addWatchersToParentFolders.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import fsSync, { WatchEventType } from 'fs';
import fsSync, { type WatchEventType } from 'fs';
import path from 'path';
import { getUserData } from '../filesystem';
import logger from '../logger';
Expand Down
8 changes: 4 additions & 4 deletions src/main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ import {
Tray,
Menu,
nativeImage,
OpenDialogOptions,
powerMonitor,
SaveDialogOptions,
net,
powerSaveBlocker,
screen,
Display
type OpenDialogOptions,
type SaveDialogOptions,
type Display
} from 'electron';

import {
Expand Down Expand Up @@ -433,7 +433,7 @@ function addEventsToCache(dataType: DataUpdateEventTypes, data = [] as string[],
const handleFileProtocol = async (request: GlobalRequest): Promise<GlobalResponse> => {
try {
const urlWithQueries = decodeURI(request.url).replace(
/^(nora:[\/\\]{1,2}localfiles[\/\\]{1,2})|(\?ts\=\d+)?$/gm,
/(nora:[\/\\]{1,2}localfiles[\/\\]{1,2})|(\?ts\=\d+$)?/gm,
''
);
const [filePath] = urlWithQueries.split('?');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import hashText from '../../utils/hashText';
import {
import type {
AuthData,
LoveParams,
ScrobbleParams,
Expand Down
2 changes: 1 addition & 1 deletion src/main/other/lastFm/getAlbumInfoFromLastFM.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { checkIfConnectedToInternet } from '../../main';
import { getAlbumsData, getSongsData } from '../../filesystem';
import logger from '../../logger';
import {
import type {
LastFMAlbumInfoAPI,
AlbumInfo,
ParsedAlbumTrack,
Expand Down
2 changes: 1 addition & 1 deletion src/main/other/lastFm/getArtistInfoFromLastFM.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { LastFmArtistInfoAPI } from '../../../types/last_fm_artist_info_api';
import type { LastFmArtistInfoAPI } from '../../../types/last_fm_artist_info_api';
import logger from '../../logger';
import { checkIfConnectedToInternet } from '../../main';

Expand Down
2 changes: 1 addition & 1 deletion src/main/other/lastFm/getSimilarTracks.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logger from '../../logger';
import { getSongsData } from '../../filesystem';
import {
import type {
LastFMSimilarTracksAPI,
ParsedSimilarTrack,
SimilarTrack,
Expand Down
2 changes: 1 addition & 1 deletion src/main/other/lastFm/scrobbleSong.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getSongsData, getUserData } from '../../filesystem';
import logger from '../../logger';
import { LastFMScrobblePostResponse, ScrobbleParams } from '../../../types/last_fm_api';
import type { LastFMScrobblePostResponse, ScrobbleParams } from '../../../types/last_fm_api';
import { checkIfConnectedToInternet } from '../../main';
import { generateApiRequestBodyForLastFMPostRequests } from './generateApiRequestBodyForLastFMPostRequests';
import getLastFmAuthData from './getLastFMAuthData';
Expand Down
6 changes: 5 additions & 1 deletion src/main/other/lastFm/sendFavoritesDataToLastFM.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { getUserData } from '../../filesystem';
import logger from '../../logger';
import hashText from '../../utils/hashText';
import { AuthData, LastFMLoveUnlovePostResponse, LoveParams } from '../../../types/last_fm_api';
import type {
AuthData,
LastFMLoveUnlovePostResponse,
LoveParams
} from '../../../types/last_fm_api';
import { checkIfConnectedToInternet } from '../../main';
import getLastFmAuthData from './getLastFMAuthData';

Expand Down
5 changes: 4 additions & 1 deletion src/main/other/lastFm/sendNowPlayingSongDataToLastFM.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { getSongsData, getUserData } from '../../filesystem';
import logger from '../../logger';
import { LastFMScrobblePostResponse, updateNowPlayingParams } from '../../../types/last_fm_api';
import type {
LastFMScrobblePostResponse,
updateNowPlayingParams
} from '../../../types/last_fm_api';
import { checkIfConnectedToInternet, getSongsOutsideLibraryData } from '../../main';
import generateApiRequestBodyForLastFMPostRequests from './generateApiRequestBodyForLastFMPostRequests';
import getLastFmAuthData from './getLastFMAuthData';
Expand Down
2 changes: 1 addition & 1 deletion src/main/utils/fetchLyricsFromMusixmatch.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {
import type {
MusixmatchLyrics,
MusixmatchLyricsAPI,
MusixmatchLyricsLine,
Expand Down
2 changes: 1 addition & 1 deletion src/main/utils/fetchSongArtworksFromSpotify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// https://i.scdn.co/image/ ab6761670000 ecd483b611804e9de647b18110be

import logger from '../logger';
import { SpotifyEmbedApi } from '../../types/spotify_embed_api';
import type { SpotifyEmbedApi } from '../../types/spotify_embed_api';

const SPOTIFY_EMBED_BASE_URL =
'https://open.spotify.com/oembed?url=https://open.spotify.com/track/';
Expand Down
10 changes: 5 additions & 5 deletions src/main/utils/fetchSongMetadataFromInternet.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { AppleITunesMusicAPI } from '../../types/apple_itunes_music_api';
import type { AppleITunesMusicAPI } from '../../types/apple_itunes_music_api';
import logger from '../logger';
import { LastFMHitCache, LastFMTrackInfoApi } from '../../types/last_fm_api';
import type { LastFMHitCache, LastFMTrackInfoApi } from '../../types/last_fm_api';

import { GeniusLyricsAPI, GeniusSongMetadataResponse } from '../../types/genius_lyrics_api';
import { DeezerTrackDataAPI, DeezerTrackResultsAPI } from '../../types/deezer_api';
import { MusixmatchHitCache, MusixmatchLyricsAPI } from '../../types/musixmatch_lyrics_api';
import type { GeniusLyricsAPI, GeniusSongMetadataResponse } from '../../types/genius_lyrics_api';
import type { DeezerTrackDataAPI, DeezerTrackResultsAPI } from '../../types/deezer_api';
import type { MusixmatchHitCache, MusixmatchLyricsAPI } from '../../types/musixmatch_lyrics_api';
import parseSongMetadataFromMusixmatchApiData from './parseSongMetadataFromMusixmatchApiData';
import { parseMusicmatchDataFromLyrics } from './fetchLyricsFromMusixmatch';

Expand Down
2 changes: 1 addition & 1 deletion src/main/utils/getTranslatedLyrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
getLrcLyricLinesFromParsedLyrics,
getLrcLyricsMetadata
} from '../core/saveLyricsToLrcFile';
import { RawResponse } from '@vitalets/google-translate-api/dist/cjs/types';
import type { RawResponse } from '@vitalets/google-translate-api/dist/cjs/types';

const getTranslatedLyricLines = (raw: RawResponse, translatedLang: string) => {
if (translatedLang === raw.src) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/utils/hashText.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BinaryToTextEncoding, createHash } from 'crypto';
import { type BinaryToTextEncoding, createHash } from 'crypto';

type HashingAlgorithm = 'md5' | 'sha256' | 'sha512';

Expand Down
2 changes: 1 addition & 1 deletion src/main/utils/makeDir.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MakeDirectoryOptions, Mode, PathLike, mkdirSync } from 'fs';
import { type MakeDirectoryOptions, type Mode, type PathLike, mkdirSync } from 'fs';
import { mkdir } from 'fs/promises';
import { isAnErrorWithCode } from './isAnErrorWithCode';

Expand Down
5 changes: 4 additions & 1 deletion src/main/utils/parseSongMetadataFromMusixmatchApiData.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import logger from '../logger';
import { MusixmatchLyricsAPI, MusixmatchLyricsMetadata } from '../../types/musixmatch_lyrics_api';
import type {
MusixmatchLyricsAPI,
MusixmatchLyricsMetadata
} from '../../types/musixmatch_lyrics_api';
import fetchSongArtworksFromSpotify from './fetchSongArtworksFromSpotify';

async function parseSongMetadataFromMusixmatchApiData(
Expand Down
2 changes: 1 addition & 1 deletion src/preload/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ const utils = {
join: (...args: string[]) => args.join('/')
},
getExtension: (dir: string) => {
const regex = /(?<name>.+)\.(?<ext>\w+)(?<search>.+)$/;
const regex = /(?<name>.+)\.(?<ext>[\w\d]+)(?<search>\?.+)?$/;
const match = dir.match(regex);
const ext = match?.groups?.ext || '';
return ext;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import TitleContainer from '../TitleContainer';
import AlbumImgAndInfoContainer from './AlbumImgAndInfoContainer';
import OnlineAlbumInfoContainer from './OnlineAlbumInfoContainer';
import { songSortOptions } from '../SongsPage/SongOptions';
import { type LastFMAlbumInfo } from 'src/types/last_fm_album_info_api';
import type { LastFMAlbumInfo } from 'src/types/last_fm_album_info_api';
import VirtualizedList from '../VirtualizedList';
import { useStore } from '@tanstack/react-store';
import { store } from '../../store';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useTranslation } from 'react-i18next';
import Biography from '../Biography/Biography';
import TitleContainer from '../TitleContainer';
import UnAvailableTrack from '../SongInfoPage/UnAvailableTrack';
import { type LastFMAlbumInfo } from 'src/types/last_fm_album_info_api';
import type { LastFMAlbumInfo } from 'src/types/last_fm_album_info_api';
import { useStore } from '@tanstack/react-store';
import { store } from '../../store';

Expand Down
2 changes: 1 addition & 1 deletion src/renderer/src/components/Biography/Biography.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useMemo } from 'react';
import { Trans, useTranslation } from 'react-i18next';
import Hyperlink from '../Hyperlink';
import HashTag from './HashTag';
import { type Tag } from '../../../../types/last_fm_artist_info_api';
import type { Tag } from '../../../../types/last_fm_artist_info_api';
import { useStore } from '@tanstack/react-store';
import { store } from '@renderer/store';

Expand Down
2 changes: 1 addition & 1 deletion src/renderer/src/components/Biography/HashTag.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useTranslation } from 'react-i18next';
import { type Tag } from '../../../../types/last_fm_artist_info_api';
import type { Tag } from '../../../../types/last_fm_artist_info_api';
import Hyperlink from '../Hyperlink';

const HashTag = (props: Tag) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useCallback, useContext, useEffect, useMemo, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { AppUpdateContext } from '../../contexts/AppUpdateContext';
import { type SimilarTracksOutput } from 'src/types/last_fm_similar_tracks_api';
import type { SimilarTracksOutput } from 'src/types/last_fm_similar_tracks_api';
import UnAvailableTrack from './UnAvailableTrack';
import TitleContainer from '../TitleContainer';
import Song from '../SongsPage/Song';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Trans, useTranslation } from 'react-i18next';

import { AppUpdateContext } from '../../contexts/AppUpdateContext';

import { type ParsedSimilarTrack } from '../../../../types/last_fm_similar_tracks_api';
import type { ParsedSimilarTrack } from '../../../../types/last_fm_similar_tracks_api';

const OpenLinkConfirmPrompt = lazy(() => import('../OpenLinkConfirmPrompt'));

Expand Down
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"types": [ "electron-vite/node" ],
"allowJs": true,
"useUnknownInCatchVariables": true,
// "verbatimModuleSyntax": true,
// "erasableSyntaxOnly": true
"verbatimModuleSyntax": true,
"erasableSyntaxOnly": true
}
}
4 changes: 2 additions & 2 deletions tsconfig.node.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"@main/*": [ "./src/main/*" ], },
"noImplicitAny": true,
"useUnknownInCatchVariables": true,
// "verbatimModuleSyntax": true,
// "erasableSyntaxOnly": true
"verbatimModuleSyntax": true,
"erasableSyntaxOnly": true
}
}
7 changes: 2 additions & 5 deletions tsconfig.web.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,9 @@
"@renderer/*": [
"src/renderer/src/*"
],
"@types/*": [
"src/types/*"
]
},
"types": [ "vite/client" ],
// "verbatimModuleSyntax": true,
// "erasableSyntaxOnly": true
"verbatimModuleSyntax": true,
"erasableSyntaxOnly": true
}
}

0 comments on commit 0d7246c

Please sign in to comment.