Skip to content

Commit 5da1a86

Browse files
committed
modernize package and dependencies
1 parent 7098ba3 commit 5da1a86

File tree

7 files changed

+485
-3281
lines changed

7 files changed

+485
-3281
lines changed

package.json

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "cache-cmd",
33
"version": "0.2.0",
4-
"description": "Cache a command based on various factors",
4+
"description": "Run and cache a command based on various factors",
55
"keywords": [
66
"cache",
77
"debounce",
@@ -23,39 +23,39 @@
2323
"dist",
2424
"src"
2525
],
26-
"bin": "dist/cli.cjs",
26+
"bin": "dist/cli.js",
2727
"type": "module",
2828
"source": "src/cli.ts",
2929
"repository": {
3030
"type": "git",
3131
"url": "https://github.com/dcastil/cache-cmd.git"
3232
},
3333
"scripts": {
34-
"cache-cmd": "node ./dist/cli.cjs",
35-
"build": "rm -rf dist/* && microbundle --strict --target node --output dist/cli.ts --format cjs --generateTypes false",
34+
"cache-cmd": "node ./dist/cli.js",
35+
"build": "rm -rf dist/* && esbuild src/cli.ts --bundle --platform=node --target=node20 --packages=external --format=esm --sourcemap --outfile=dist/cli.js",
3636
"type-check": "tsc --build",
3737
"preversion": "if [ -n \"$DANYS_MACHINE\" ]; then git checkout main && git pull; fi",
3838
"postversion": "if [ -n \"$DANYS_MACHINE\" ]; then git push --follow-tags && open https://github.com/dcastil/cache-cmd/releases; fi"
3939
},
4040
"dependencies": {
41-
"date-fns": "^2.25.0",
42-
"del": "^6.0.0",
41+
"date-fns": "^4.1.0",
42+
"del": "^8.0.0",
4343
"exec-sh": "^0.4.0",
44-
"find-cache-dir": "^3.3.2",
45-
"flat-cache": "^3.0.4",
44+
"find-cache-dir": "^5.0.0",
45+
"flat-cache": "^6.1.3",
4646
"hard-rejection": "^2.1.0",
47-
"hasha": "^5.2.2",
48-
"lodash": "^4.17.21",
49-
"make-dir": "^3.1.0",
50-
"sade": "^1.7.4"
47+
"hasha": "^6.0.0",
48+
"lodash-es": "^4.17.21",
49+
"sade": "^1.8.1"
5150
},
5251
"devDependencies": {
53-
"@types/find-cache-dir": "^3.2.1",
54-
"@types/flat-cache": "^2.0.0",
55-
"@types/lodash": "^4.14.175",
56-
"@types/sade": "^1.7.3",
57-
"microbundle": "^0.14.1",
58-
"prettier": "^2.4.1",
59-
"typescript": "^4.4.4"
52+
"@types/find-cache-dir": "^5.0.2",
53+
"@types/flat-cache": "^2.0.2",
54+
"@types/lodash-es": "^4.17.12",
55+
"@types/node": "^22.10.1",
56+
"@types/sade": "^1.8.0",
57+
"esbuild": "^0.24.0",
58+
"prettier": "^3.4.2",
59+
"typescript": "^5.7.2"
6060
}
6161
}

src/cache-clear.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import del from 'del'
1+
import { deleteSync } from 'del'
22

33
import { getCacheDirectoryPath } from './utils/get-cache-dir'
44

55
export function clearCacheDirectory(relativeCacheDirectory: string | undefined) {
6-
const deletedPaths = del.sync(getCacheDirectoryPath(relativeCacheDirectory))
6+
const deletedPaths = deleteSync(getCacheDirectoryPath(relativeCacheDirectory))
77

88
if (deletedPaths.length === 0) {
99
console.log('No cache to clear')

src/run.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { add, isAfter } from 'date-fns'
22
import execSh from 'exec-sh'
3-
import flatCache from 'flat-cache'
4-
import { isEqual } from 'lodash'
3+
import { create } from 'flat-cache'
4+
import { isEqual } from 'lodash-es'
55

6-
import { createCache } from './utils/get-cache-dir'
6+
import { getCacheDirectoryPath } from './utils/get-cache-dir'
77
import { getCacheKey } from './utils/get-cache-key'
88
import { getDuration } from './utils/get-duration'
99
import { getFileHashes } from './utils/get-file-hashes'
@@ -30,7 +30,11 @@ export async function runCommand({
3030
return
3131
}
3232

33-
const cache = flatCache.load('commands-cache.json', createCache(relativeCacheDirectory))
33+
const cache = create({
34+
cacheId: 'commands-cache.json',
35+
cacheDir: getCacheDirectoryPath(relativeCacheDirectory),
36+
lruSize: 10_000,
37+
})
3438
const filePaths = getFilePaths(cacheByFiles)
3539
const duration = cacheByTime ? getDuration(cacheByTime) : undefined
3640

@@ -63,7 +67,7 @@ export async function runCommand({
6367
[fileHashes && 'unchanged files', duration && 'being within cache time']
6468
.filter(Boolean)
6569
.join(' and '),
66-
].join(' ')
70+
].join(' '),
6771
)
6872
return
6973
}
@@ -74,7 +78,7 @@ export async function runCommand({
7478
[fileHashes && 'changed files', duration && 'cache time passing']
7579
.filter(Boolean)
7680
.join(' and '),
77-
].join(' ')
81+
].join(' '),
7882
)
7983
let execPromise = execSh.promise(command)
8084

src/utils/get-cache-dir.ts

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import path from 'path'
22

33
import findCacheDir from 'find-cache-dir'
4-
import makeDir from 'make-dir'
54

65
import { name } from '../../package.json'
76

@@ -18,19 +17,3 @@ export function getCacheDirectoryPath(relativeCacheDirectoryPath: string | undef
1817

1918
return resolvedCacheDirectory
2019
}
21-
22-
export function createCache(relativeCacheDirectoryPath: string | undefined) {
23-
if (relativeCacheDirectoryPath) {
24-
const absoluteCacheDirectoryPath = makeDir.sync(relativeCacheDirectoryPath)
25-
26-
return absoluteCacheDirectoryPath
27-
}
28-
29-
const resolvedCachePath = findCacheDir({ name, create: true })
30-
31-
if (!resolvedCachePath) {
32-
throw Error('Could not find cache directory. Please provide a cache directory manually.')
33-
}
34-
35-
return resolvedCachePath
36-
}

src/utils/get-file-hashes.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
import hasha from 'hasha'
1+
import { hashFile } from 'hasha'
22

33
export async function getFileHashes(filePaths: string[]) {
44
return Object.fromEntries(
55
await Promise.all(
66
filePaths.map((filePath) =>
7-
hasha
8-
.fromFile(filePath, { algorithm: 'md5' })
9-
.then((hash) => [filePath, hash] as const)
10-
)
11-
)
7+
hashFile(filePath, { algorithm: 'md5' }).then((hash) => [filePath, hash] as const),
8+
),
9+
),
1210
)
1311
}

tsconfig.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
"noUncheckedIndexedAccess": true,
99
"strict": true,
1010
// Modules
11-
"module": "CommonJS",
12-
"moduleResolution": "Node",
11+
"module": "ESNext",
12+
"moduleResolution": "bundler",
1313
// Emit
1414
"declaration": true,
1515
"noEmit": true,
@@ -19,7 +19,7 @@
1919
"esModuleInterop": true,
2020
"forceConsistentCasingInFileNames": true,
2121
// Language and Environment
22-
"target": "ES2020",
22+
"target": "ESNext",
2323
"resolveJsonModule": true
2424
},
2525
"include": ["src/**/*"]

0 commit comments

Comments
 (0)