diff --git a/package.json b/package.json index ebd0c9cf..943f61e8 100644 --- a/package.json +++ b/package.json @@ -55,6 +55,7 @@ "@types/lodash": "^4.14.202", "@types/lodash.debounce": "^4", "@types/luxon": "^3.4.2", + "@types/mime-types": "^2.1.4", "@types/morgan": "^1.9.9", "@types/node": "18", "@types/react": "^18.2.66", diff --git a/src/renderer/src/App.tsx b/src/renderer/src/App.tsx index ebe0dfe5..a5a247b0 100644 --- a/src/renderer/src/App.tsx +++ b/src/renderer/src/App.tsx @@ -1687,7 +1687,7 @@ function App() { // first check if it is a single directory, and if so, read it recursively if (filePaths.length === 1) { - const firstFilePath = filePaths[0]; + const firstFilePath = filePaths[0]!; const firstFileStat = await lstat(firstFilePath); if (firstFileStat.isDirectory()) { console.log('Reading directory...'); diff --git a/src/renderer/src/edlStore.ts b/src/renderer/src/edlStore.ts index 6328cab4..7ea36ac4 100644 --- a/src/renderer/src/edlStore.ts +++ b/src/renderer/src/edlStore.ts @@ -1,6 +1,5 @@ import JSON5 from 'json5'; import i18n from 'i18next'; -import type { parse as CueParse } from 'cue-parser'; import invariant from 'tiny-invariant'; import { parseSrtToSegments, formatSrt, parseCuesheet, parseXmeml, parseFcpXml, parseCsv, parseCutlist, parsePbf, parseMplayerEdl, formatCsvHuman, formatTsv, formatCsvFrames, formatCsvSeconds, parseCsvTime, getFrameValParser, parseDvAnalyzerSummaryTxt } from './edlFormats'; @@ -9,7 +8,7 @@ import { getOutPath } from './util'; import { EdlExportType, EdlFileType, EdlImportType, Segment, StateSegment } from './types'; const { readFile, writeFile } = window.require('fs/promises'); -const cueParser: { parse: typeof CueParse } = window.require('cue-parser'); +const cueParser = window.require('cue-parser'); const { basename } = window.require('path'); const { dialog } = window.require('@electron/remote'); @@ -85,7 +84,7 @@ export async function saveLlcProject({ savePath, filePath, cutSegments }) { } export async function loadLlcProject(path: string) { - const parsed = JSON5.parse(await readFile(path)) as unknown; + const parsed = JSON5.parse(await readFile(path) as unknown as string) as unknown; if (parsed == null || typeof parsed !== 'object') throw new Error('Invalid LLC file'); let mediaFileName: string | undefined; if ('mediaFileName' in parsed && typeof parsed.mediaFileName === 'string') { diff --git a/src/renderer/src/hooks/useFrameCapture.ts b/src/renderer/src/hooks/useFrameCapture.ts index 41335e1c..f213ae1d 100644 --- a/src/renderer/src/hooks/useFrameCapture.ts +++ b/src/renderer/src/hooks/useFrameCapture.ts @@ -1,7 +1,6 @@ import dataUriToBuffer from 'data-uri-to-buffer'; import pMap from 'p-map'; import { useCallback } from 'react'; -import type * as FsPromises from 'node:fs/promises'; import { getSuffixedOutPath, getOutDir, transferTimestamps, getSuffixedFileName, getOutPath, escapeRegExp, fsOperationWithRetry } from '../util'; import { getNumDigits } from '../segments'; @@ -11,7 +10,7 @@ import { FormatTimecode } from '../types'; import { CaptureFormat } from '../../../../types'; const mime = window.require('mime-types'); -const { rename, readdir, writeFile }: typeof FsPromises = window.require('fs/promises'); +const { rename, readdir, writeFile } = window.require('fs/promises'); function getFrameFromVideo(video: HTMLVideoElement, format: CaptureFormat, quality: number) { diff --git a/src/renderer/src/index.tsx b/src/renderer/src/index.tsx index 14450b3d..000ad8fb 100644 --- a/src/renderer/src/index.tsx +++ b/src/renderer/src/index.tsx @@ -5,6 +5,12 @@ import { enableMapSet } from 'immer'; import * as Electron from 'electron'; import Remote from '@electron/remote'; import type path from 'node:path'; +import type fsPromises from 'node:fs/promises'; +import type fsExtraRaw from 'fs-extra'; +import type mimeTypes from 'mime-types'; +import type i18nextFsBackend from 'i18next-fs-backend'; +import type fileType from 'file-type'; +import type cueParser from 'cue-parser'; import '@fontsource/open-sans/300.css'; import '@fontsource/open-sans/300-italic.css'; @@ -29,6 +35,9 @@ import './main.css'; import './swal2.scss'; +// something wrong with the tyep +type FsExtra = typeof fsExtraRaw & { exists: (p: string) => Promise }; + type TypedRemote = Omit & { require: (module: T) => ( T extends './index.js' ? typeof main : @@ -43,9 +52,15 @@ declare global { T extends '@electron/remote' ? TypedRemote : T extends 'electron' ? typeof Electron : T extends 'path' ? typeof path : - // todo more - // eslint-disable-next-line @typescript-eslint/no-explicit-any - any + T extends 'node:path' ? typeof path : + T extends 'fs/promises' ? typeof fsPromises : + T extends 'node:fs/promises' ? typeof fsPromises : + T extends 'fs-extra' ? FsExtra : + T extends 'mime-types' ? typeof mimeTypes : + T extends 'i18next-fs-backend' ? typeof i18nextFsBackend : + T extends 'file-type' ? typeof fileType : + T extends 'cue-parser' ? typeof cueParser : + never ); } } diff --git a/src/renderer/src/util.ts b/src/renderer/src/util.ts index f19be996..bd444d91 100644 --- a/src/renderer/src/util.ts +++ b/src/renderer/src/util.ts @@ -5,18 +5,15 @@ import prettyBytes from 'pretty-bytes'; import sortBy from 'lodash/sortBy'; import pRetry, { Options } from 'p-retry'; import { ExecaError } from 'execa'; -import type * as FsPromises from 'node:fs/promises'; -import type * as FsExtra from 'fs-extra'; -import type { PlatformPath } from 'node:path'; import isDev from './isDev'; import Swal, { errorToast, toast } from './swal'; import { ffmpegExtractWindow } from './util/constants'; import { appName } from '../../main/common'; -const { dirname, parse: parsePath, join, extname, isAbsolute, resolve, basename }: PlatformPath = window.require('path'); -const fsExtra: typeof FsExtra = window.require('fs-extra'); -const { stat, lstat, readdir, utimes, unlink }: typeof FsPromises = window.require('fs/promises'); +const { dirname, parse: parsePath, join, extname, isAbsolute, resolve, basename } = window.require('path'); +const fsExtra = window.require('fs-extra'); +const { stat, lstat, readdir, utimes, unlink } = window.require('fs/promises'); const { ipcRenderer } = window.require('electron'); const remote = window.require('@electron/remote'); const { isWindows, isMac } = remote.require('./index.js'); diff --git a/yarn.lock b/yarn.lock index 7dc6e7f1..8b73d6a7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2089,6 +2089,13 @@ __metadata: languageName: node linkType: hard +"@types/mime-types@npm:^2.1.4": + version: 2.1.4 + resolution: "@types/mime-types@npm:2.1.4" + checksum: 10/f8c521c54ee0c0b9f90a65356a80b1413ed27ccdc94f5c7ebb3de5d63cedb559cd2610ea55b4100805c7349606a920d96e54f2d16b2f0afa6b7cd5253967ccc9 + languageName: node + linkType: hard + "@types/mime@npm:*": version: 3.0.4 resolution: "@types/mime@npm:3.0.4" @@ -7483,6 +7490,7 @@ __metadata: "@types/lodash": "npm:^4.14.202" "@types/lodash.debounce": "npm:^4" "@types/luxon": "npm:^3.4.2" + "@types/mime-types": "npm:^2.1.4" "@types/morgan": "npm:^1.9.9" "@types/node": "npm:18" "@types/react": "npm:^18.2.66"