don't stat() all input files
As part of transpilation we might receive directories as input
files. To check, we tested each file for whether it was a
directory or not. This disk access evaded our various caches.
To fix:
1. only check for directories in transpilation;
2. when checking for directories, assume names ending in
sourc file extensions like ".js" are not directories.
PiperOrigin-RevId: 296473783
diff --git a/internal/tsc_wrapped/tsc_wrapped.ts b/internal/tsc_wrapped/tsc_wrapped.ts
index 24e2e6e..077a948 100644
--- a/internal/tsc_wrapped/tsc_wrapped.ts
+++ b/internal/tsc_wrapped/tsc_wrapped.ts
@@ -177,11 +177,14 @@
* them to their .js or .ts contents.
*/
function expandSourcesFromDirectories(fileList: string[], filePath: string) {
+ if (filePath.endsWith('.ts') || filePath.endsWith('.tsx') ||
+ filePath.endsWith('.js')) {
+ fileList.push(filePath);
+ return;
+ }
+
if (!fs.statSync(filePath).isDirectory()) {
- if (filePath.endsWith('.ts') || filePath.endsWith('.tsx') ||
- filePath.endsWith('.js')) {
- fileList.push(filePath);
- }
+ // subdirectories may also contain e.g. .java files, which we ignore.
return;
}
const entries = fs.readdirSync(filePath);
@@ -223,10 +226,14 @@
angularCompilerOptions
} = parsed;
- const sourceFiles: string[] = [];
- for (let i = 0; i < files.length; i++) {
- const filePath = files[i];
- expandSourcesFromDirectories(sourceFiles, filePath);
+ let sourceFiles: string[] = [];
+ if (bazelOpts.isJsTranspilation) {
+ // Under JS transpilations, some inputs might be directories.
+ for (const filePath of files) {
+ expandSourcesFromDirectories(sourceFiles, filePath);
+ }
+ } else {
+ sourceFiles = files;
}
if (bazelOpts.maxCacheSizeMb !== undefined) {