Skip to content

Commit

Permalink
Ignore implementation files when .flow.js file exists during type t…
Browse files Browse the repository at this point in the history
…ranslation (#49039)

Summary:
Pull Request resolved: #49039

Changelog: [Internal]

Reviewed By: huntie

Differential Revision: D68774523

fbshipit-source-id: 07776e7e0d551e3bad5a30eff1de8a76769e5761
  • Loading branch information
j-piasecki authored and facebook-github-bot committed Jan 29, 2025
1 parent df6be9f commit 8058aab
Showing 1 changed file with 28 additions and 4 deletions.
32 changes: 28 additions & 4 deletions scripts/build/build-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,12 @@ async function main() {
return;
}

const files = SOURCE_PATTERNS.flatMap(srcPath =>
glob.sync(path.join(srcPath, ''), {
nodir: true,
}),
const files = ignoreShadowedFiles(
SOURCE_PATTERNS.flatMap(srcPath =>
glob.sync(path.join(srcPath, ''), {
nodir: true,
}),
),
);

console.log(
Expand Down Expand Up @@ -117,6 +119,28 @@ function getBuildPath(file /*: string */) /*: string */ {
);
}

function ignoreShadowedFiles(files /*: Array<string> */) /*: Array<string> */ {
const shadowedPrefixes /*: Record<string, boolean> */ = {};
const result /*: Array<string> */ = [];

// Find all flow definition files that shadow other files
for (const file of files) {
if (/\.flow\.js$/.test(file)) {
shadowedPrefixes[file.substring(0, file.length - 8)] = true;
}
}

// Filter out all files shadowed by flow definition files
for (const file of files) {
const prefix = file.split('.')[0];
if (/\.flow\.js$/.test(file) || !shadowedPrefixes[prefix]) {
result.push(file);
}
}

return result;
}

if (require.main === module) {
// eslint-disable-next-line no-void
void main();
Expand Down

0 comments on commit 8058aab

Please sign in to comment.