Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
30 lines
1.1 KiB
Plaintext
30 lines
1.1 KiB
Plaintext
import path from 'path';
|
|
|
|
class SourceFileFilter {
|
|
static EXTENSIONS = ['ts', 'tsx', 'js', 'jsx'];
|
|
|
|
// Will not be entered, except if explicitly asked for
|
|
// TODO: At some point we should infer these from .gitignore
|
|
static IGNORED_DIRECTORIES = ['node_modules', '.next', '.git'];
|
|
static isSourceFile(filePath) {
|
|
const ext = path.extname(filePath);
|
|
return SourceFileFilter.EXTENSIONS.map(cur => '.' + cur).includes(ext);
|
|
}
|
|
static shouldEnterDirectory(dirPath, srcPaths) {
|
|
const dirName = path.basename(dirPath);
|
|
if (SourceFileFilter.IGNORED_DIRECTORIES.includes(dirName)) {
|
|
return SourceFileFilter.isIgnoredDirectoryExplicitlyIncluded(dirPath, srcPaths);
|
|
}
|
|
return true;
|
|
}
|
|
static isIgnoredDirectoryExplicitlyIncluded(ignoredDirPath, srcPaths) {
|
|
return srcPaths.some(srcPath => SourceFileFilter.isWithinPath(srcPath, ignoredDirPath));
|
|
}
|
|
static isWithinPath(targetPath, basePath) {
|
|
const relativePath = path.relative(basePath, targetPath);
|
|
return relativePath === '' || !relativePath.startsWith('..');
|
|
}
|
|
}
|
|
|
|
export { SourceFileFilter as default };
|