-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Skip indexing large files above 1mb, add option
--max-file-byte-size
(
#271) * Add configurable option to skip large files Previously, scip-typescript indexed all files regardless of file size. This could result in scip-typescript stalling progress to index very large files that were (frequently) auto-generated. This commit changes the default behavior to skip indexing files that are larger than 1mb, and makes this threshold configurable via the new `--max-file-byte-size` flag. * Print out when large files are skipped
- Loading branch information
Showing
4 changed files
with
110 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { test } from 'uvu' | ||
import * as assert from 'uvu/assert' | ||
|
||
import { parseHumanByteSizeIntoNumber } from './parseHumanByteSizeIntoNumber' | ||
|
||
function checkHumanByteSize( | ||
humanInput: string, | ||
expectedByteNumber: number | ||
): void { | ||
test(humanInput, () => { | ||
const obtained = parseHumanByteSizeIntoNumber(humanInput) | ||
assert.equal(obtained, expectedByteNumber) | ||
}) | ||
} | ||
|
||
// Invalid formats | ||
checkHumanByteSize('invalid', NaN) | ||
checkHumanByteSize('15tb', NaN) | ||
checkHumanByteSize('15b', NaN) | ||
|
||
// All numeral | ||
checkHumanByteSize('1001', 1001) | ||
|
||
// All lowercase | ||
checkHumanByteSize('1.2kb', 1_200) | ||
checkHumanByteSize('1.2mb', 1_200_000) | ||
checkHumanByteSize('1.2gb', 1_200_000_000) | ||
|
||
// All uppercase | ||
checkHumanByteSize('1.2KB', 1_200) | ||
checkHumanByteSize('1.2MB', 1_200_000) | ||
checkHumanByteSize('1.2GB', 1_200_000_000) | ||
|
||
// Mixed case | ||
checkHumanByteSize('1.2Kb', 1_200) | ||
checkHumanByteSize('1.2Mb', 1_200_000) | ||
checkHumanByteSize('1.2Gb', 1_200_000_000) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
const kilo = 1_000 | ||
const mega = 1_000_000 | ||
const giga = 1_000_000_000 | ||
|
||
export function parseHumanByteSizeIntoNumber(humanByteSize: string): number { | ||
let value = humanByteSize.toLowerCase() | ||
let multiplier = 1 | ||
if (value.endsWith('kb')) { | ||
multiplier = kilo | ||
value = value.slice(0, -2) | ||
} else if (value.endsWith('mb')) { | ||
multiplier = mega | ||
value = value.slice(0, -2) | ||
} else if (value.endsWith('gb')) { | ||
multiplier = giga | ||
value = value.slice(0, -2) | ||
} | ||
return Number.parseFloat(value) * multiplier | ||
} | ||
|
||
export function formatByteSizeAsHumanReadable(byteSize: number): string { | ||
if (byteSize > giga) { | ||
return `${byteSize / giga}gb` | ||
} | ||
if (byteSize > mega) { | ||
return `${byteSize / mega}mb` | ||
} | ||
if (byteSize > kilo) { | ||
return `${byteSize / kilo}kb` | ||
} | ||
return byteSize.toString() | ||
} |