Skip to content

Commit aa181c0

Browse files
committed
refactor: rename dlx and releases helpers for clarity
Renamed functions for better descriptiveness: - isCacheValid() → isBinaryCacheValid() - writeMetadata() → writeBinaryCacheMetadata() - getMetadataPath() → getBinaryCacheMetadataPath() - createMatcher() → createAssetMatcher() All call sites and JSDoc references updated. Build and tests verified passing.
1 parent 6861fcb commit aa181c0

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

src/dlx/binary.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ export async function cleanDlxCache(
201201

202202
for (const entry of entries) {
203203
const entryPath = path.join(cacheDir, entry)
204-
const metaPath = getMetadataPath(entryPath)
204+
const metaPath = getBinaryCacheMetadataPath(entryPath)
205205

206206
try {
207207
// eslint-disable-next-line no-await-in-loop
@@ -287,11 +287,11 @@ export async function dlxBinary(
287287
if (
288288
!force &&
289289
fs.existsSync(cacheEntryDir) &&
290-
(await isCacheValid(cacheEntryDir, cacheTtl))
290+
(await isBinaryCacheValid(cacheEntryDir, cacheTtl))
291291
) {
292292
// Binary is cached and valid, read the integrity from metadata.
293293
try {
294-
const metaPath = getMetadataPath(cacheEntryDir)
294+
const metaPath = getBinaryCacheMetadataPath(cacheEntryDir)
295295
const metadata = await readJson(metaPath, { throws: false })
296296
if (
297297
metadata &&
@@ -350,7 +350,7 @@ export async function dlxBinary(
350350

351351
// Get file size for metadata.
352352
const stats = await fs.promises.stat(binaryPath)
353-
await writeMetadata(
353+
await writeBinaryCacheMetadata(
354354
cacheEntryDir,
355355
cacheKey,
356356
url,
@@ -431,7 +431,7 @@ export async function downloadBinary(
431431
if (
432432
!force &&
433433
fs.existsSync(cacheEntryDir) &&
434-
(await isCacheValid(cacheEntryDir, cacheTtl))
434+
(await isBinaryCacheValid(cacheEntryDir, cacheTtl))
435435
) {
436436
// Binary is cached and valid.
437437
downloaded = false
@@ -470,7 +470,7 @@ export async function downloadBinary(
470470

471471
// Get file size for metadata.
472472
const stats = await fs.promises.stat(binaryPath)
473-
await writeMetadata(
473+
await writeBinaryCacheMetadata(
474474
cacheEntryDir,
475475
cacheKey,
476476
url,
@@ -622,20 +622,20 @@ export function getDlxCachePath(): string {
622622
/**
623623
* Get metadata file path for a cached binary.
624624
*/
625-
export function getMetadataPath(cacheEntryPath: string): string {
625+
export function getBinaryCacheMetadataPath(cacheEntryPath: string): string {
626626
return getPath().join(cacheEntryPath, '.dlx-metadata.json')
627627
}
628628

629629
/**
630630
* Check if a cached binary is still valid.
631631
*/
632-
export async function isCacheValid(
632+
export async function isBinaryCacheValid(
633633
cacheEntryPath: string,
634634
cacheTtl: number,
635635
): Promise<boolean> {
636636
const fs = getFs()
637637
try {
638-
const metaPath = getMetadataPath(cacheEntryPath)
638+
const metaPath = getBinaryCacheMetadataPath(cacheEntryPath)
639639
if (!fs.existsSync(metaPath)) {
640640
return false
641641
}
@@ -693,7 +693,7 @@ export async function listDlxCache(): Promise<
693693
continue
694694
}
695695

696-
const metaPath = getMetadataPath(entryPath)
696+
const metaPath = getBinaryCacheMetadataPath(entryPath)
697697
// eslint-disable-next-line no-await-in-loop
698698
const metadata = await readJson(metaPath, { throws: false })
699699
if (
@@ -741,14 +741,14 @@ export async function listDlxCache(): Promise<
741741
* Uses unified schema shared with C++ decompressor and CLI dlxBinary.
742742
* Schema documentation: See DlxMetadata interface in this file (exported).
743743
*/
744-
export async function writeMetadata(
744+
export async function writeBinaryCacheMetadata(
745745
cacheEntryPath: string,
746746
cacheKey: string,
747747
url: string,
748748
integrity: string,
749749
size: number,
750750
): Promise<void> {
751-
const metaPath = getMetadataPath(cacheEntryPath)
751+
const metaPath = getBinaryCacheMetadataPath(cacheEntryPath)
752752
const metadata: DlxMetadata = {
753753
version: '1.0.0',
754754
cache_key: cacheKey,

src/releases/github.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ function getPath() {
140140
* @param pattern - Pattern to match (string glob, prefix/suffix object, or RegExp)
141141
* @returns Function that tests if a string matches the pattern
142142
*/
143-
export function createMatcher(
143+
export function createAssetMatcher(
144144
pattern: string | { prefix: string; suffix: string } | RegExp,
145145
): (input: string) => boolean {
146146
if (typeof pattern === 'string') {
@@ -353,7 +353,7 @@ export async function getLatestRelease(
353353
const { owner, repo } = repoConfig
354354

355355
// Create matcher function if pattern provided.
356-
const isMatch = assetPattern ? createMatcher(assetPattern) : undefined
356+
const isMatch = assetPattern ? createAssetMatcher(assetPattern) : undefined
357357

358358
return await pRetry(
359359
async () => {
@@ -464,7 +464,7 @@ export async function getReleaseAssetUrl(
464464
!assetPattern.includes('*') &&
465465
!assetPattern.includes('{')
466466
? (input: string) => input === assetPattern
467-
: createMatcher(assetPattern as AssetPattern)
467+
: createAssetMatcher(assetPattern as AssetPattern)
468468

469469
return await pRetry(
470470
async () => {

0 commit comments

Comments
 (0)