in packages/flow-upgrade/src/findFlowFiles.js [118:160]
function processJavaScriptFilePath(filePath: string, fileByteSize: number) {
// If `all` was configured then we don't need to check for the Flow
// header pragma.
if (options.all) {
filePaths.push(filePath);
return;
}
// If we were rejected then we should not continue.
if (rejected === true) {
return;
}
// We are now waiting on this asynchronous task.
waiting++;
// Open the file path.
fs.open(filePath, 'r', (error, file) => {
if (error) {
return reject(error);
}
// Get the smaller of our pragma chars constant and the file byte size.
const bytes = Math.min(PRAGMA_BYTES, fileByteSize);
// Create the buffer we will read to.
const buffer = new Buffer(bytes);
// Read a set number of bytes from the file.
fs.read(file, buffer, 0, bytes, 0, error => {
if (error) {
return reject(error);
}
// If the buffer has the @flow pragma then add the file path to our
// final file paths array.
if (buffer.includes('@flow')) {
filePaths.push(filePath);
}
// Close the file.
fs.close(file, error => {
if (error) {
return reject(error);
}
// We are done with this async task
done();
});
});
});
}