Skip to content

Commit

Permalink
use built-in fs.readdir instead of @folder/readdir
Browse files Browse the repository at this point in the history
only supported for node >= 20.1.0
  • Loading branch information
pirxpilot committed Oct 16, 2023
1 parent b18154b commit cdd9b82
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 'lts/*'
node-version: 'current'
- run: yarn install
- run: make check
12 changes: 8 additions & 4 deletions lib/hash-store.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const readdir = require('@folder/readdir');
const fs = require('node:fs/promises');
const path = require('node:path');
const debug = require('debug')('connect:cachify-static');
const calculateHash = require('./hash');

Expand All @@ -21,9 +22,7 @@ async function hashStore(root, match, formatPathFn) {

debug('Calculating hashes for files in %s.', root);
const files = await readdir(root, {
absolute: true,
recursive: true,
filter: match
filter: makeFilter(match)
});
const tasks = files.map(async file => {
const path = file.slice(root.length);
Expand Down Expand Up @@ -92,3 +91,8 @@ function makeFilter(value = true) {
return () => value;
}
}

async function readdir(root, { filter }) {
const files = await fs.readdir(root, { recursive: true });
return files.map(n => path.resolve(root, n)).filter(filter);
}
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@
"bugs": {
"url": "https://github.com/pirxpilot/connect-cachify-static/issues"
},
"engines": {
"node": ">= 20.1.0"
},
"dependencies": {
"@folder/readdir": "^3.1.0",
"debug": "~2||~3||~4",
"on-headers": "^1.0.0",
"parseurl": "~1"
Expand All @@ -40,4 +42,4 @@
"bin",
"lib"
]
}
}

0 comments on commit cdd9b82

Please sign in to comment.