Skip to content

Commit

Permalink
chore: add types to extra-files.js
Browse files Browse the repository at this point in the history
  • Loading branch information
lishaduck committed Jun 27, 2024
1 parent 2e2fa9f commit f378dd6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
17 changes: 13 additions & 4 deletions lib/extra-files.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ const OsHelpers = require('./os-helpers');
*/
async function collect(requests) {
const {globby} = await import('globby');
const files = await Promise.all(
const files2D = await Promise.all(
requests.map((request) => getFiles(globby, request))
).then((files) => unique(files.flat()));
);
const flatFiles = files2D.flat();
const files = unique(flatFiles);

const filesAndContents = await Promise.all(
files.map(async (filePath) => {
Expand All @@ -32,7 +34,7 @@ async function collect(requests) {
return filesAndContents.reduce((dict, {path, content}) => {
dict[path] = content;
return dict;
}, {});
}, /** @type {NonElmFiles} */ ({}));
}

/**
Expand All @@ -44,7 +46,9 @@ function getFiles(globby, request) {
return globby(
request.files.map(
(file) =>
(file.included ? '' : '!') + OsHelpers.makePathOsAgnostic(file.pattern)
`${file.included ? '' : '!'}${OsHelpers.makePathOsAgnostic(
file.pattern
)}`
),
{
ignore: request.excludedDirectories,
Expand All @@ -58,6 +62,11 @@ function getFiles(globby, request) {
);
}

/**
* @template T
* @param {T[]} array
* @returns {T[]}
*/
function unique(array) {
return [...new Set(array)];
}
Expand Down
1 change: 1 addition & 0 deletions tsconfig.no-implicit-any.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"lib/debug.js",
"lib/elm-communication.js",
"lib/elm-files.js",
"lib/extra-files.js",
"lib/sync-get.js",
"lib/sync-get-worker.js",
"lib/error-message.js",
Expand Down

0 comments on commit f378dd6

Please sign in to comment.