-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Expand file tree
/
Copy pathExtensionRegistry.ts
More file actions
53 lines (45 loc) · 1.18 KB
/
ExtensionRegistry.ts
File metadata and controls
53 lines (45 loc) · 1.18 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
/**
* @license
* Copyright 2026 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import fs from 'node:fs/promises';
import path from 'node:path';
export interface InstalledExtension {
id: string;
name: string;
version: string;
isEnabled: boolean;
path: string;
}
export class ExtensionRegistry {
#extensions = new Map<string, InstalledExtension>();
async registerExtension(
id: string,
extensionPath: string,
): Promise<InstalledExtension> {
const manifestPath = path.join(extensionPath, 'manifest.json');
const manifestContent = await fs.readFile(manifestPath, 'utf-8');
const manifest = JSON.parse(manifestContent);
const name = manifest.name ?? 'Unknown';
const version = manifest.version ?? 'Unknown';
const extension = {
id,
name,
version,
isEnabled: true,
path: extensionPath,
};
this.#extensions.set(extension.id, extension);
return extension;
}
remove(id: string): void {
this.#extensions.delete(id);
}
list(): InstalledExtension[] {
return Array.from(this.#extensions.values());
}
getById(id: string): InstalledExtension | undefined {
return this.#extensions.get(id);
}
}