Skip to content

Commit

Permalink
Merge branch 'main' into renovate/typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
emmercm authored Feb 12, 2025
2 parents 18e8904 + 799315f commit b730c69
Show file tree
Hide file tree
Showing 29 changed files with 348 additions and 288 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
# Run test coverage
- run: npm run test:coverage
- uses: codecov/codecov-action@v4
- uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: true
Expand Down
463 changes: 251 additions & 212 deletions package-lock.json

Large diffs are not rendered by default.

26 changes: 13 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,17 @@
"@fast-csv/format": "5.0.2",
"@fast-csv/parse": "5.0.2",
"@gplane/cue": "0.2.0",
"@node-rs/crc32": "1.10.4",
"@node-rs/crc32": "1.10.6",
"7zip-min": "1.4.5",
"archiver": "7.0.1",
"async": "3.2.6",
"async-mutex": "0.5.0",
"chalk": "5.3.0",
"chalk": "5.4.1",
"chdman": "0.269.2",
"class-transformer": "0.5.1",
"cli-progress": "3.12.0",
"fast-glob": "3.3.2",
"fast-xml-parser": "4.5.0",
"fast-glob": "3.3.3",
"fast-xml-parser": "4.5.1",
"figlet": "1.8.0",
"graceful-fs": "4.2.11",
"is-admin": "4.0.0",
Expand All @@ -92,7 +92,7 @@
"node-disk-info": "1.3.0",
"node-unrar-js": "2.0.2",
"reflect-metadata": "0.2.2",
"semver": "7.6.3",
"semver": "7.7.0",
"simple-statistics": "7.8.7",
"strip-ansi": "7.1.0",
"tar": "6.2.1",
Expand All @@ -113,23 +113,23 @@
"@types/figlet": "1.7.0",
"@types/jest": "29.5.14",
"@types/micromatch": "4.0.9",
"@types/node": "20.17.10",
"@types/node": "22.13.1",
"@types/semver": "7.5.8",
"@types/tar": "6.1.13",
"@types/unzipper": "0.10.10",
"@types/which": "3.0.4",
"@types/xml2js": "0.4.14",
"@types/yargs": "17.0.33",
"@typescript-eslint/eslint-plugin": "8.18.2",
"@typescript-eslint/parser": "8.18.2",
"@typescript-eslint/eslint-plugin": "8.22.0",
"@typescript-eslint/parser": "8.22.0",
"auto-changelog": "2.5.0",
"caxa": "3.0.1",
"eslint": "9.9.1",
"eslint": "9.19.0",
"eslint-config-prettier": "9.1.0",
"eslint-plugin-import": "2.31.0",
"eslint-plugin-jest": "28.10.0",
"eslint-plugin-jsdoc": "50.6.1",
"eslint-plugin-prettier": "5.2.1",
"eslint-plugin-jest": "28.11.0",
"eslint-plugin-jsdoc": "50.6.3",
"eslint-plugin-prettier": "5.2.3",
"eslint-plugin-simple-import-sort": "12.1.1",
"eslint-plugin-unicorn": "56.0.1",
"husky": "9.1.7",
Expand All @@ -155,6 +155,6 @@
"node": ">=16.7.0"
},
"volta": {
"node": "22.12.0"
"node": "22.13.1"
}
}
8 changes: 4 additions & 4 deletions src/igir.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ export default class Igir {
dir2DatPath ? `dir2dat: ${dir2DatPath}` : undefined,
fixdatPath ? `Fixdat: ${fixdatPath}` : undefined,
]
.filter((line) => line)
.filter((line) => line !== undefined && line.length > 0)
.join('\n'),
);

Expand Down Expand Up @@ -275,7 +275,7 @@ export default class Igir {
path.join(os.homedir(), defaultFileName),
path.join(process.cwd(), defaultFileName),
]
.filter((filePath) => filePath && !filePath.startsWith(os.tmpdir()))
.filter((filePath) => filePath.length > 0 && !filePath.startsWith(os.tmpdir()))
.reduce(ArrayPoly.reduceUnique(), []);

// Next, try to use an already existing path
Expand Down Expand Up @@ -381,7 +381,7 @@ export default class Igir {
)
.filter((bitmask) => !(matchChecksum & ChecksumBitmask[bitmask]))
// Should be enabled for this DAT
.filter((bitmask) => datMinimumRomBitmask & ChecksumBitmask[bitmask])
.filter((bitmask) => (datMinimumRomBitmask & ChecksumBitmask[bitmask]) > 0)
.forEach((bitmask) => {
matchChecksum |= ChecksumBitmask[bitmask];
this.logger.trace(
Expand All @@ -403,7 +403,7 @@ export default class Igir {
)
.filter((bitmask) => !(matchChecksum & ChecksumBitmask[bitmask]))
// Should be enabled for this DAT
.filter((bitmask) => datMinimumDiskBitmask & ChecksumBitmask[bitmask])
.filter((bitmask) => (datMinimumDiskBitmask & ChecksumBitmask[bitmask]) > 0)
.forEach((bitmask) => {
matchChecksum |= ChecksumBitmask[bitmask];
this.logger.trace(
Expand Down
8 changes: 5 additions & 3 deletions src/modules/argumentsParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ export default class ArgumentsParser {
})
.check((checkArgv) => {
const needClean = ['clean-exclude', 'clean-backup', 'clean-dry-run'].filter(
(option) => checkArgv[option],
(option) => checkArgv[option] !== undefined,
);
if (!checkArgv._.includes('clean') && needClean.length > 0) {
// TODO(cememr): print help message
Expand All @@ -533,7 +533,9 @@ export default class ArgumentsParser {
type: 'boolean',
})
.check((checkArgv) => {
const needZip = ['zip-exclude', 'zip-dat-name'].filter((option) => checkArgv[option]);
const needZip = ['zip-exclude', 'zip-dat-name'].filter(
(option) => checkArgv[option] !== undefined,
);
if (!checkArgv._.includes('zip') && needZip.length > 0) {
throw new ExpectedError(
`Missing required command for option${needZip.length !== 1 ? 's' : ''} ${needZip.join(', ')}: zip`,
Expand All @@ -554,7 +556,7 @@ export default class ArgumentsParser {
implies: 'symlink',
})
.check((checkArgv) => {
const needLinkCommand = ['symlink'].filter((option) => checkArgv[option]);
const needLinkCommand = ['symlink'].filter((option) => checkArgv[option] !== undefined);
if (!checkArgv._.includes('link') && needLinkCommand.length > 0) {
throw new ExpectedError(
`Missing required command for option${needLinkCommand.length !== 1 ? 's' : ''} ${needLinkCommand.join(', ')}: link`,
Expand Down
2 changes: 1 addition & 1 deletion src/modules/candidates/candidateGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ export default class CandidateGenerator extends Module {
) {
return new Map(
romsAndInputFiles
.filter(([, inputFiles]) => inputFiles.length)
.filter(([, inputFiles]) => inputFiles.length > 0)
.map(([rom, inputFiles]) => [rom, inputFiles[0]]),
);
}
Expand Down
6 changes: 3 additions & 3 deletions src/modules/candidates/candidateMergeSplitValidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export default class CandidateMergeSplitValidator extends Module {

const releaseCandidatesIndexed = [...parentsToCandidates.values()]
.flat()
.filter((releaseCandidate) => releaseCandidate.getRomsWithFiles().length)
.filter((releaseCandidate) => releaseCandidate.getRomsWithFiles().length > 0)
.reduce((map, releaseCandidate) => {
map.set(releaseCandidate.getGame().getName(), releaseCandidate);
return map;
Expand All @@ -51,7 +51,7 @@ export default class CandidateMergeSplitValidator extends Module {
// For every Game that has ReleaseCandidate(s) with files
const missingGames = [...parentsToCandidates.values()]
.flat()
.filter((releaseCandidate) => releaseCandidate.getRomsWithFiles().length)
.filter((releaseCandidate) => releaseCandidate.getRomsWithFiles().length > 0)
.map((releaseCandidate) => releaseCandidate.getGame())
.reduce(ArrayPoly.reduceUnique(), [])
.flatMap((game) => {
Expand All @@ -73,7 +73,7 @@ export default class CandidateMergeSplitValidator extends Module {
.map((deviceRef) => datGamesIndexed.get(deviceRef.getName()))
.filter((deviceGame) => deviceGame !== undefined)
// Dependent device has ROM files
.filter((deviceGame) => deviceGame.getRoms().length)
.filter((deviceGame) => deviceGame.getRoms().length > 0)
.map((deviceGame) => {
const deviceReleaseCandidate = releaseCandidatesIndexed.get(deviceGame.getName());
if (deviceReleaseCandidate) {
Expand Down
6 changes: 4 additions & 2 deletions src/modules/candidates/candidateWriter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,12 @@ export default class CandidateWriter extends Module {
const parentsToWritableCandidates = new Map(
[...parentsToCandidates.entries()]
// The parent has candidates
.filter(([, releaseCandidates]) => releaseCandidates.length)
.filter(([, releaseCandidates]) => releaseCandidates.length > 0)
// At least some candidates have files
.filter(([, releaseCandidates]) =>
releaseCandidates.some((releaseCandidate) => releaseCandidate.getRomsWithFiles().length),
releaseCandidates.some(
(releaseCandidate) => releaseCandidate.getRomsWithFiles().length > 0,
),
),
);

Expand Down
2 changes: 1 addition & 1 deletion src/modules/dats/datFilter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export default class DATFilter extends Module {
this.options.getOnlyUnverified() && game.isVerified(),
this.options.getNoBad() && game.isBad(),
this.options.getOnlyBad() && !game.isBad(),
].filter((val) => val).length === 0
].filter((val) => val === true).length === 0
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/modules/dats/datGameInferrer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ export default class DATGameInferrer extends Module {
const gdiContents = `${cueData
.toString()
.split(/\r?\n/)
.filter((line) => line)
.filter((line) => line.length > 0)
// Replace the chdman-generated track files with TOSEC-style track filenames
.map((line) => line.replace(filePrefix, 'track').replace(/"/g, ''))
.join('\r\n')}\r\n`;
Expand Down
2 changes: 1 addition & 1 deletion src/modules/dats/datMergerSplitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export default class DATMergerSplitter extends Module {
// the child.
if (!biosGame.isBios()) {
biosGame = biosGame.withProps({
rom: biosGame.getRoms().filter((rom) => rom.getBios()),
rom: biosGame.getRoms().filter((rom) => rom.getBios() !== undefined),
});
}

Expand Down
4 changes: 3 additions & 1 deletion src/modules/directoryCleaner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,9 @@ export default class DirectoryCleaner extends Module {
existSemaphore.runExclusive(async () => fsPoly.exists(filePath)),
),
);
const existingFilePaths = filePaths.filter((filePath, idx) => existingFilePathsCheck.at(idx));
const existingFilePaths = filePaths.filter(
(filePath, idx) => existingFilePathsCheck.at(idx) === true,
);
if (existingFilePaths.length > 0) {
this.progressBar.setSymbol(ProgressBarSymbol.DELETING);
}
Expand Down
4 changes: 2 additions & 2 deletions src/modules/movedRomDeleter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ export default class MovedROMDeleter extends Module {
existSemaphore.runExclusive(async () => fsPoly.exists(filePath)),
),
);
const existingFilePaths = filePathsToDelete.filter((filePath, idx) =>
existingFilePathsCheck.at(idx),
const existingFilePaths = filePathsToDelete.filter(
(filePath, idx) => existingFilePathsCheck.at(idx) === true,
);

this.progressBar.setSymbol(ProgressBarSymbol.DELETING);
Expand Down
6 changes: 4 additions & 2 deletions src/modules/reportGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export default class ReportGenerator extends Module {
.map(async (datsStatus) => datsStatus.toCsv(this.options)),
)
)
.filter((csv) => csv)
.filter((csv) => csv.length > 0)
.map((csv, idx) => {
// Strip the CSV header from everything except the first file
if (idx === 0) {
Expand Down Expand Up @@ -86,7 +86,9 @@ export default class ReportGenerator extends Module {
if (!(await FsPoly.exists(reportPathDir))) {
await FsPoly.mkdir(reportPathDir, { recursive: true });
}
const rows = [...matchedFileCsvs, duplicateCsv, unusedCsv, cleanedCsv].filter((csv) => csv);
const rows = [...matchedFileCsvs, duplicateCsv, unusedCsv, cleanedCsv].filter(
(csv) => csv.length > 0,
);
await FsPoly.writeFile(reportPath, rows.join('\n'));
this.progressBar.logTrace(
`wrote ${datStatuses.length.toLocaleString()} CSV row${datStatuses.length !== 1 ? 's' : ''}: ${reportPath}`,
Expand Down
4 changes: 3 additions & 1 deletion src/modules/roms/romHeaderProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ export default class ROMHeaderProcessor extends Module {
}),
);

const headeredRomsCount = parsedFiles.filter((romFile) => romFile.getFileHeader()).length;
const headeredRomsCount = parsedFiles.filter(
(romFile) => romFile.getFileHeader() !== undefined,
).length;
this.progressBar.logTrace(
`found headers in ${headeredRomsCount.toLocaleString()} ROM${headeredRomsCount !== 1 ? 's' : ''}`,
);
Expand Down
2 changes: 1 addition & 1 deletion src/types/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export default class Cache<V> {
public async delete(key: string | RegExp): Promise<void> {
let keysToDelete: string[];
if (key instanceof RegExp) {
keysToDelete = [...this.keys().keys()].filter((k) => k.match(key));
keysToDelete = [...this.keys().keys()].filter((k) => k.match(key) !== null);
} else {
keysToDelete = [key];
}
Expand Down
11 changes: 7 additions & 4 deletions src/types/datStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ export default class DATStatus {

private readonly allRomTypesToGames = new Map<ROMType, Game[]>();

// eslint-disable-next-line no-spaced-func
private readonly foundRomTypesToReleaseCandidates = new Map<
ROMType,
(ReleaseCandidate | undefined)[]
Expand Down Expand Up @@ -183,7 +182,11 @@ export default class DATStatus {
*/
toConsole(options: Options): string {
return `${DATStatus.getAllowedTypes(options)
.filter((type) => this.allRomTypesToGames.get(type)?.length)
.filter(
(type) =>
this.allRomTypesToGames.has(type) &&
(this.allRomTypesToGames.get(type) as Game[]).length > 0,
)
.map((type) => {
const found = this.foundRomTypesToReleaseCandidates.get(type) ?? [];
const all = (this.allRomTypesToGames.get(type) ?? [])
Expand Down Expand Up @@ -217,7 +220,7 @@ export default class DATStatus {
return `${color(found.length.toLocaleString())}/${all.length.toLocaleString()} ${type}`;
})
.filter((str) => str)
.filter((str) => str.length > 0)
.join(', ')} ${options.shouldWrite() ? 'written' : 'found'}`;
}

Expand Down Expand Up @@ -253,7 +256,7 @@ export default class DATStatus {
}

const foundReleaseCandidate = foundReleaseCandidates.find(
(rc) => rc && rc.getGame().equals(game),
(rc) => rc !== undefined && rc.getGame().equals(game),
);
if (foundReleaseCandidate !== undefined || game.getRoms().length === 0) {
status = GameStatus.FOUND;
Expand Down
2 changes: 1 addition & 1 deletion src/types/dats/logiqx/header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export default class Header implements HeaderOptions {
author: this.author,
url: this.url,
comment: this.comment,
}).filter(([, val]) => val),
}).filter(([, val]) => val !== undefined),
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/types/files/archives/chd/chdGdiParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export default class ChdGdiParser {
const gdiContents = `${gdiExtractedContents
.toString()
.split(/\r?\n/)
.filter((line) => line)
.filter((line) => line.length > 0)
// Replace the chdman-generated track files with TOSEC-style track filenames
.map((line) => line.replace(filePrefix, 'track').replace(/"/g, ''))
.join('\r\n')}\r\n`;
Expand Down
2 changes: 1 addition & 1 deletion src/types/files/archives/sevenZip/sevenZip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export default class SevenZip extends Archive {
} else {
// https://github.com/onikienko/7zip-min/issues/70
// If `7zip-min.list()` failed to parse the entry name then ignore it
resolve(result.filter((entry) => entry.name));
resolve(result.filter((entry) => entry.name !== undefined && entry.name.length > 0));
}
});
}),
Expand Down
2 changes: 1 addition & 1 deletion src/types/files/archives/zip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ export default class Zip extends Archive {

// Finalize writing the zip file
await zipFile.finalize();
await new Promise((resolve) => {
await new Promise<void>((resolve) => {
// We are writing to a file, so we want to wait on the 'close' event which indicates the file
// descriptor has been closed. 'finished' will also fire before 'close' does.
writeStream.on('close', resolve);
Expand Down
4 changes: 3 additions & 1 deletion src/types/files/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ export default class File implements FileProps {
readonly patch?: Patch;

protected constructor(fileProps: FileProps) {
this.filePath = path.normalize(fileProps.filePath);
this.filePath = URLPoly.canParse(fileProps.filePath)
? fileProps.filePath
: path.normalize(fileProps.filePath);
this.size = fileProps.size ?? 0;
this.checksumBitmask = fileProps.checksumBitmask;
this.crc32 = fileProps.crc32?.toLowerCase().replace(/^0x/, '').padStart(8, '0');
Expand Down
10 changes: 5 additions & 5 deletions src/types/files/fileCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export default class FileCache {
.filter((cacheKey) => cacheKey.endsWith(`|${ValueType.INODE}`))
.map((cacheKey) => [cacheKey, cacheKey.split('|')[1]])
// Don't delete the key if it's for a disk that isn't mounted right now
.filter(([, filePath]) => FsPoly.diskResolved(filePath))
.filter(([, filePath]) => FsPoly.diskResolved(filePath) !== undefined)
// Only process a reasonably sized subset of the keys
.sort(() => Math.random() - 0.5)
.slice(0, Defaults.MAX_FS_THREADS);
Expand Down Expand Up @@ -180,10 +180,10 @@ export default class FileCache {

const cachedEntries = cached.value as ArchiveEntryProps<T>[];
const existingBitmask =
(cachedEntries.every((props) => props.crc32) ? ChecksumBitmask.CRC32 : 0) |
(cachedEntries.every((props) => props.md5) ? ChecksumBitmask.MD5 : 0) |
(cachedEntries.every((props) => props.sha1) ? ChecksumBitmask.SHA1 : 0) |
(cachedEntries.every((props) => props.sha256) ? ChecksumBitmask.SHA256 : 0);
(cachedEntries.every((props) => props.crc32 !== undefined) ? ChecksumBitmask.CRC32 : 0) |
(cachedEntries.every((props) => props.md5 !== undefined) ? ChecksumBitmask.MD5 : 0) |
(cachedEntries.every((props) => props.sha1 !== undefined) ? ChecksumBitmask.SHA1 : 0) |
(cachedEntries.every((props) => props.sha256 !== undefined) ? ChecksumBitmask.SHA256 : 0);
const remainingBitmask = checksumBitmask - (checksumBitmask & existingBitmask);
// We need checksums that haven't been cached yet
return remainingBitmask > 0;
Expand Down
Loading

0 comments on commit b730c69

Please sign in to comment.