Skip to content

Commit

Permalink
Minor refactor to getSupportedFilesGlob (#15319)
Browse files Browse the repository at this point in the history
  • Loading branch information
fisker committed Aug 29, 2023
1 parent f6c9e9b commit 941c6b3
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions src/cli/expand-patterns.js
Expand Up @@ -128,20 +128,19 @@ async function* expandPatternsInternal(context) {
}

function getSupportedFilesGlob() {
if (!supportedFilesGlob) {
const extensions = context.languages.flatMap(
(lang) => lang.extensions || [],
);
const filenames = context.languages.flatMap(
(lang) => lang.filenames || [],
);
supportedFilesGlob = [
...extensions.map((ext) => "*" + (ext[0] === "." ? ext : "." + ext)),
...filenames,
];
}
supportedFilesGlob ??= [...getSupportedFilesGlobWithoutCache()];
return supportedFilesGlob;
}

function* getSupportedFilesGlobWithoutCache() {
for (const { extensions = [], filenames = [] } of context.languages) {
yield* filenames;

for (const extension of extensions) {
yield `*${extension.startsWith(".") ? extension : `.${extension}`}`;
}
}
}
}

const errorMessages = {
Expand Down

0 comments on commit 941c6b3

Please sign in to comment.