|
| 1 | +import fs from 'fs' |
| 2 | + |
1 | 3 | import walkSync from 'walk-sync' |
2 | | -import readFileAsync from '../../lib/readfile-async.js' |
3 | 4 | import minimatch from 'minimatch' |
4 | 5 |
|
5 | 6 | /* |
@@ -75,33 +76,56 @@ const REPO_REGEXP = /\/\/github\.com\/github\/(?!docs[/'"\n])([\w-.]+)/gi |
75 | 76 | const IGNORE_PATHS = [ |
76 | 77 | '.git', |
77 | 78 | '.next', |
| 79 | + '.vscode', // Not part of the repo but could be for a developer locally |
78 | 80 | 'node_modules', |
79 | 81 | 'translations', |
| 82 | + '.linkinator', |
80 | 83 | '**/*.png', // Do not check images or font files. |
81 | 84 | '**/*.jpg', // We could just put all of assets/* here, but that would prevent any |
82 | 85 | '**/*.gif', // READMEs or other text-based files from being checked. |
83 | 86 | '**/*.pdf', |
84 | 87 | '**/*.ico', |
85 | 88 | '**/*.woff', |
| 89 | + '**/*.csv', |
| 90 | + '**/*.br', // E.g. the search index .json.br files |
| 91 | + '**/*.graphql', // E.g. data/graphql/ghec/schema.docs.graphql |
| 92 | + 'package-lock.json', // At the time of writing it's 1.5MB! |
| 93 | + '.linkinator/full.log', // Only present if you've run linkinator |
| 94 | + 'lib/search/popular-pages.json', // used to build search indexes |
| 95 | + 'tests/**/*.json', |
86 | 96 |
|
87 | 97 | 'content/early-access', // Not committed to public repository. |
88 | 98 | 'data/early-access', // Not committed to public repository. |
89 | 99 | 'data/release-notes', // These include links to many internal issues in Liquid comments. |
| 100 | + 'lib/redirects/.redirects-cache*', |
90 | 101 | ] |
91 | 102 |
|
92 | 103 | describe('check if a GitHub-owned private repository is referenced', () => { |
93 | 104 | const filenames = walkSync(process.cwd(), { |
94 | 105 | directories: false, |
95 | 106 | ignore: IGNORE_PATHS, |
96 | | - }) |
| 107 | + }).filter( |
| 108 | + (filename) => |
| 109 | + // Skip the large static json files because they're not code. |
| 110 | + !( |
| 111 | + filename.includes('static') && |
| 112 | + (filename.endsWith('.json') || filename.endsWith('.json.br')) |
| 113 | + ) |
| 114 | + ) |
97 | 115 |
|
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)) |
| 116 | + test.each(filenames)('in file %s', (filename) => { |
| 117 | + // When you're reading many small files, it's faster to do it |
| 118 | + // *synchronously* because the event-loop overhead is less since |
| 119 | + // the disk I/O is sufficiently small. |
| 120 | + const file = fs.readFileSync(filename, 'utf8') |
101 | 121 | const matches = Array.from(file.matchAll(REPO_REGEXP)) |
102 | 122 | .map(([, repoName]) => repoName) |
103 | 123 | .filter((repoName) => !PUBLIC_REPOS.has(repoName)) |
104 | | - .filter((repoName) => !(allowDocs && repoName.startsWith('docs'))) |
| 124 | + .filter((repoName) => { |
| 125 | + return !( |
| 126 | + repoName.startsWith('docs') && ALLOW_DOCS_PATHS.some((path) => minimatch(filename, path)) |
| 127 | + ) |
| 128 | + }) |
105 | 129 | expect( |
106 | 130 | matches, |
107 | 131 | `Please edit ${filename} to remove references to ${matches.join(', ')}` |
|
0 commit comments