-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Expand file tree
/
Copy pathissue-descriptions.ts
More file actions
54 lines (45 loc) · 1.32 KB
/
issue-descriptions.ts
File metadata and controls
54 lines (45 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import * as fs from 'node:fs';
import * as path from 'node:path';
const DESCRIPTIONS_PATH = path.join(
import.meta.dirname,
'../node_modules/chrome-devtools-frontend/front_end/models/issues_manager/descriptions',
);
let issueDescriptions: Record<string, string> = {};
/**
* Reads all issue descriptions from the filesystem into memory.
*/
export async function loadIssueDescriptions(): Promise<void> {
if (Object.keys(issueDescriptions).length > 0) {
return;
}
const files = await fs.promises.readdir(DESCRIPTIONS_PATH);
const descriptions: Record<string, string> = {};
for (const file of files) {
if (!file.endsWith('.md')) {
continue;
}
const content = await fs.promises.readFile(
path.join(DESCRIPTIONS_PATH, file),
'utf-8',
);
descriptions[file] = content;
}
issueDescriptions = descriptions;
}
/**
* Gets an issue description from the in-memory cache.
* @param fileName The file name of the issue description.
* @returns The description of the issue, or null if it doesn't exist.
*/
export function getIssueDescription(fileName: string): string | null {
return issueDescriptions[fileName] ?? null;
}
export const ISSUE_UTILS = {
loadIssueDescriptions,
getIssueDescription,
};