|
4 | 4 | * @author René Fermann |
5 | 5 | */ |
6 | 6 |
|
7 | | -import Exports, { recursivePatternCapture } from '../ExportMap'; |
8 | 7 | import { getFileExtensions } from 'eslint-module-utils/ignore'; |
9 | 8 | import resolve from 'eslint-module-utils/resolve'; |
10 | 9 | import visit from 'eslint-module-utils/visit'; |
11 | | -import docsUrl from '../docsUrl'; |
12 | 10 | import { dirname, join } from 'path'; |
13 | 11 | import readPkgUp from 'eslint-module-utils/readPkgUp'; |
14 | 12 | import values from 'object.values'; |
15 | 13 | import includes from 'array-includes'; |
| 14 | +import flatMap from 'array.prototype.flatmap'; |
| 15 | + |
| 16 | +import Exports, { recursivePatternCapture } from '../ExportMap'; |
| 17 | +import docsUrl from '../docsUrl'; |
16 | 18 |
|
17 | 19 | let FileEnumerator; |
18 | 20 | let listFilesToProcess; |
|
40 | 42 | const { listFilesToProcess: originalListFilesToProcess } = require('eslint/lib/util/glob-util'); |
41 | 43 |
|
42 | 44 | listFilesToProcess = function (src, extensions) { |
43 | | - const patterns = src.reduce( |
44 | | - (carry, pattern) => carry.concat( |
45 | | - extensions.map((extension) => (/\*\*|\*\./).test(pattern) ? pattern : `${pattern}/**/*${extension}`), |
46 | | - ), |
47 | | - src, |
48 | | - ); |
| 45 | + const patterns = src.concat(flatMap(src, (pattern) => extensions.map((extension) => (/\*\*|\*\./).test(pattern) ? pattern : `${pattern}/**/*${extension}`))); |
49 | 46 |
|
50 | 47 | return originalListFilesToProcess(patterns); |
51 | 48 | }; |
@@ -171,18 +168,17 @@ const isNodeModule = (path) => (/\/(node_modules)\//).test(path); |
171 | 168 | const resolveFiles = (src, ignoreExports, context) => { |
172 | 169 | const extensions = Array.from(getFileExtensions(context.settings)); |
173 | 170 |
|
174 | | - const srcFiles = new Set(); |
175 | 171 | const srcFileList = listFilesToProcess(src, extensions); |
176 | 172 |
|
177 | 173 | // prepare list of ignored files |
178 | | - const ignoredFilesList = listFilesToProcess(ignoreExports, extensions); |
| 174 | + const ignoredFilesList = listFilesToProcess(ignoreExports, extensions); |
179 | 175 | ignoredFilesList.forEach(({ filename }) => ignoredFiles.add(filename)); |
180 | 176 |
|
181 | 177 | // prepare list of source files, don't consider files from node_modules |
182 | | - srcFileList.filter(({ filename }) => !isNodeModule(filename)).forEach(({ filename }) => { |
183 | | - srcFiles.add(filename); |
184 | | - }); |
185 | | - return srcFiles; |
| 178 | + |
| 179 | + return new Set( |
| 180 | + srcFileList.filter(({ filename }) => !isNodeModule(filename)).map(({ filename }) => filename), |
| 181 | + ); |
186 | 182 | }; |
187 | 183 |
|
188 | 184 | /** |
|
0 commit comments