Skip to content

Commit cd3e38c

Browse files
committed
Read directgories as stream
Also make use of some string consts
1 parent 146507e commit cd3e38c

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

src/pluginCore.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ const { results: cliReporter } = require('pa11y/lib/reporters/cli')
77
const readdirp = require('readdirp')
88

99
const EMPTY_ARRAY = []
10+
const ASTERISK = '*'
11+
const HTML_EXT = '.html'
12+
const GLOB_HTML = '*.html'
1013

1114
exports.runPa11y = async function ({ htmlFilePaths, pa11yOpts, build }) {
1215
let issueCount = 0
@@ -47,11 +50,17 @@ exports.generateFilePaths = async function ({
4750

4851
const findHtmlFiles = async function (fileAndDirPath, directoryFilter) {
4952
if (await isDirectory(fileAndDirPath)) {
50-
const fileInfos = await readdirp.promise(fileAndDirPath, {
51-
fileFilter: '*.html',
52-
directoryFilter: !!directoryFilter.length ? directoryFilter : '*',
53+
const filePaths = []
54+
const stream = readdirp(fileAndDirPath, {
55+
fileFilter: GLOB_HTML,
56+
directoryFilter: !!directoryFilter.length ? directoryFilter : ASTERISK,
5357
})
54-
return fileInfos.map(({ fullPath }) => fullPath)
58+
59+
for await (const { fullPath } of stream) {
60+
filePaths.push(fullPath)
61+
}
62+
63+
return filePaths
5564
}
5665

5766
if (!(await isFile(fileAndDirPath))) {
@@ -61,7 +70,7 @@ const findHtmlFiles = async function (fileAndDirPath, directoryFilter) {
6170
return EMPTY_ARRAY
6271
}
6372

64-
if (extname(fileAndDirPath) !== '.html') {
73+
if (extname(fileAndDirPath) !== HTML_EXT) {
6574
return EMPTY_ARRAY
6675
}
6776

0 commit comments

Comments
 (0)