Skip to content

Commit e59c79a

Browse files
author
Peter Bengtsson
authored
speed up repository reference checks (#23178)
* speed up repository reference checks Part of #1246 * feedbacked * microoptimization
1 parent 1125b8a commit e59c79a

1 file changed

Lines changed: 29 additions & 6 deletions

File tree

tests/meta/repository-references.js

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
import fs from 'fs'
2+
13
import walkSync from 'walk-sync'
2-
import readFileAsync from '../../lib/readfile-async.js'
34
import minimatch from 'minimatch'
45

56
/*
@@ -75,6 +76,7 @@ const REPO_REGEXP = /\/\/github\.com\/github\/(?!docs[/'"\n])([\w-.]+)/gi
7576
const IGNORE_PATHS = [
7677
'.git',
7778
'.next',
79+
'.vscode', // Not part of the repo but could be for a developer locally
7880
'node_modules',
7981
'translations',
8082
'**/*.png', // Do not check images or font files.
@@ -83,25 +85,46 @@ const IGNORE_PATHS = [
8385
'**/*.pdf',
8486
'**/*.ico',
8587
'**/*.woff',
88+
'**/*.csv',
89+
'**/*.br', // E.g. the search index .json.br files
90+
'**/*.graphql', // E.g. data/graphql/ghec/schema.docs.graphql
91+
'package-lock.json', // At the time of writing it's 1.5MB!
92+
'.linkinator/full.log', // Only present if you've run linkinator
93+
'lib/search/popular-pages.json', // used to build search indexes
94+
'tests/**/*.json',
8695

8796
'content/early-access', // Not committed to public repository.
8897
'data/early-access', // Not committed to public repository.
8998
'data/release-notes', // These include links to many internal issues in Liquid comments.
99+
'lib/redirects/.redirects-cache*',
90100
]
91101

92102
describe('check if a GitHub-owned private repository is referenced', () => {
93103
const filenames = walkSync(process.cwd(), {
94104
directories: false,
95105
ignore: IGNORE_PATHS,
96-
})
106+
}).filter(
107+
(filename) =>
108+
// Skip the large static json files because they're not code.
109+
!(
110+
filename.includes('static') &&
111+
(filename.endsWith('.json') || filename.endsWith('.json.br'))
112+
)
113+
)
97114

98-
test.each(filenames)('in file %s', async (filename) => {
99-
const file = await readFileAsync(filename, 'utf8')
100-
const allowDocs = ALLOW_DOCS_PATHS.some((path) => minimatch(filename, path))
115+
test.each(filenames)('in file %s', (filename) => {
116+
// When you're reading many small files, it's faster to do it
117+
// *synchronously* because the event-loop overhead is less since
118+
// the disk I/O is sufficiently small.
119+
const file = fs.readFileSync(filename, 'utf8')
101120
const matches = Array.from(file.matchAll(REPO_REGEXP))
102121
.map(([, repoName]) => repoName)
103122
.filter((repoName) => !PUBLIC_REPOS.has(repoName))
104-
.filter((repoName) => !(allowDocs && repoName.startsWith('docs')))
123+
.filter((repoName) => {
124+
return !(
125+
repoName.startsWith('docs') && ALLOW_DOCS_PATHS.some((path) => minimatch(filename, path))
126+
)
127+
})
105128
expect(
106129
matches,
107130
`Please edit ${filename} to remove references to ${matches.join(', ')}`

0 commit comments

Comments
 (0)