@snap/valdi 1.0.1 → 1.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/.bootstrap/apps/cli_application/AGENTS.md.template +76 -0
  2. package/.bootstrap/apps/ui_application/AGENTS.md.template +79 -3
  3. package/.bootstrap/modules/cpp_bridge_module/BUILD.bazel.template +3 -3
  4. package/.bootstrap/modules/cpp_bridge_module/cpp/CalculatorModuleFactory.cpp.template +18 -19
  5. package/.bootstrap/modules/cpp_bridge_module/src/Calculator.d.ts +3 -0
  6. package/.github/README.md +164 -0
  7. package/.metadata/.cursorrules.template +53 -0
  8. package/.metadata/.editorconfig.template +37 -0
  9. package/LINUX_COMPATIBILITY.md +248 -0
  10. package/README.md +99 -15
  11. package/dist/commands/bootstrap.js +79 -19
  12. package/dist/commands/doctor.js +361 -54
  13. package/dist/commands/newModule.js +15 -12
  14. package/dist/core/constants.js +2 -0
  15. package/dist/setup/DevSetupHelper.js +81 -6
  16. package/dist/setup/linuxSetup.js +149 -11
  17. package/dist/setup/macOSSetup.js +96 -8
  18. package/dist/utils/githubUtils.js +74 -2
  19. package/dist/utils/linuxDistro.js +255 -0
  20. package/dist/utils/linuxDistro.spec.js +170 -0
  21. package/dist/utils/stringUtils.js +60 -0
  22. package/dist/utils/stringUtils.spec.js +63 -0
  23. package/package.json +11 -3
  24. package/scripts/sync-agents-md.sh +44 -0
  25. package/scripts/update-agents-templates.ts +170 -0
  26. package/src/commands/bootstrap.ts +117 -25
  27. package/src/commands/doctor.ts +469 -59
  28. package/src/commands/newModule.ts +18 -19
  29. package/src/core/constants.ts +2 -0
  30. package/src/setup/DevSetupHelper.ts +108 -6
  31. package/src/setup/linuxSetup.ts +235 -12
  32. package/src/setup/macOSSetup.ts +122 -8
  33. package/src/utils/githubUtils.ts +98 -2
  34. package/src/utils/linuxDistro.spec.ts +219 -0
  35. package/src/utils/linuxDistro.ts +326 -0
  36. package/src/utils/stringUtils.spec.ts +77 -1
  37. package/src/utils/stringUtils.ts +88 -0
  38. package/test/ValdiSmokeTest.ts +5 -4
  39. package/test/helpers/TypeScriptClient.ts +2 -2
@@ -1,6 +1,102 @@
1
1
  import { runCliCommand } from './cliUtils';
2
2
 
3
+ /**
4
+ * Parses a GitHub repo URL (e.g. https://github.com/Snapchat/Valdi or .git variant)
5
+ * into "owner/repo" for the GitHub API.
6
+ */
7
+ function parseGitHubRepoSlug(repoUrl: string): string {
8
+ const normalized = repoUrl.replace(/\.git$/u, '').trim();
9
+ const match = normalized.match(/github\.com[/:]([^/]+)\/([^/]+?)(?:[/]?$)/u);
10
+ if (!match) {
11
+ throw new Error(`Invalid GitHub URL: ${repoUrl}`);
12
+ }
13
+ return `${match[1]}/${match[2]}`;
14
+ }
15
+
16
+ const LATEST_RELEASE_HINT =
17
+ 'Use --valdiVersion=latest to retry, or --valdiVersion=<tag> (e.g. main or v1.0.0) to pin a version.';
18
+
19
+ /**
20
+ * Returns the tag name of the release marked as "Latest" on GitHub (releases UI).
21
+ * Uses only the GitHub Releases API so the result matches what GitHub shows.
22
+ * Falls back to git ls-remote only when the repo has no releases (404).
23
+ */
24
+ export async function getLatestReleaseTag(repoUrl: string): Promise<string> {
25
+ const slug = parseGitHubRepoSlug(repoUrl);
26
+ let response: Response;
27
+ try {
28
+ response = await fetch(`https://api.github.com/repos/${slug}/releases/latest`, {
29
+ headers: { 'User-Agent': 'Valdi-CLI' },
30
+ });
31
+ } catch (error) {
32
+ const message = error instanceof Error ? error.message : String(error);
33
+ throw new Error(
34
+ `Could not fetch latest release from GitHub (${message}). ${LATEST_RELEASE_HINT}`,
35
+ );
36
+ }
37
+ if (!response.ok) {
38
+ if (response.status === 404) {
39
+ // No releases or no "latest" release – fall back to git ls-remote
40
+ return getLatestReleaseTagFromGit(repoUrl);
41
+ }
42
+ throw new Error(
43
+ `GitHub API returned ${response.status} (rate limit or server error). ${LATEST_RELEASE_HINT}`,
44
+ );
45
+ }
46
+ const data = (await response.json()) as { tag_name?: string };
47
+ if (typeof data?.tag_name !== 'string') {
48
+ throw new Error(`Invalid response: missing tag_name. ${LATEST_RELEASE_HINT}`);
49
+ }
50
+ return data.tag_name;
51
+ }
52
+
53
+ /** Matches semver-like tags (e.g. v1.0.0, 2.3.1, beta-0.0.1). Captures major, minor, patch. */
54
+ const SEMVER_TAG_REGEX = /^(?:\w+-)?v?(\d+)\.(\d+)\.(\d+)(?:[-.]\S+)?$/u;
55
+
56
+ function parseSemverTag(tag: string): [number, number, number] | null {
57
+ const m = tag.match(SEMVER_TAG_REGEX);
58
+ if (!m) return null;
59
+ return [Number.parseInt(m[1]!, 10), Number.parseInt(m[2]!, 10), Number.parseInt(m[3]!, 10)];
60
+ }
61
+
62
+ function compareSemverTags(a: string, b: string): number {
63
+ const va = parseSemverTag(a);
64
+ const vb = parseSemverTag(b);
65
+ if (va && vb) {
66
+ return va[0] - vb[0] || va[1] - vb[1] || va[2] - vb[2];
67
+ }
68
+ if (va) return 1; // non-semver (b) sorts before semver (a)
69
+ if (vb) return -1; // non-semver (a) sorts before semver (b)
70
+ return a.localeCompare(b, undefined, { numeric: true });
71
+ }
72
+
73
+ /**
74
+ * Fallback: resolve tag refs via git ls-remote and return the latest tag by semver.
75
+ * git ls-remote returns refs sorted by refname (alphabetically), so we parse all tags
76
+ * and pick the highest semantic version.
77
+ */
78
+ async function getLatestReleaseTagFromGit(repoUrl: string): Promise<string> {
79
+ const gitUrl = repoUrl.includes('.git') ? repoUrl : `${repoUrl}.git`;
80
+ const result = await runCliCommand(`git ls-remote --tags --refs ${gitUrl}`, undefined, true);
81
+ const lines = result.stdout.trim().split('\n').filter(Boolean);
82
+ const tags: string[] = [];
83
+ for (const line of lines) {
84
+ const ref = line.split(/\s+/)[1];
85
+ if (ref?.startsWith('refs/tags/')) {
86
+ const tag = ref.slice('refs/tags/'.length);
87
+ if (tag) tags.push(tag);
88
+ }
89
+ }
90
+ if (tags.length === 0) {
91
+ throw new Error('No tags found in repository');
92
+ }
93
+ tags.sort(compareSemverTags);
94
+ return tags[tags.length - 1]!;
95
+ }
96
+
97
+ /** @deprecated Use getLatestReleaseTag for the GitHub "Latest" release; this returns an arbitrary tag from git ls-remote. */
3
98
  export async function resolveLatestReleaseRef(repoUrl: string): Promise<string> {
4
- const result = await runCliCommand(`git ls-remote --tags --refs ${repoUrl}`, undefined, true);
5
- return result.stdout.trim().split(/\s+/)[1]!;
99
+ const tag = await getLatestReleaseTagFromGit(repoUrl);
100
+ // Template expects either ref (refs/tags/X) or tag name for archive URL; we use tag name.
101
+ return tag;
6
102
  }
@@ -0,0 +1,219 @@
1
+ import 'jasmine';
2
+ import {
3
+ type LinuxDistroInfo,
4
+ LinuxDistroType,
5
+ buildInstallCommand,
6
+ getCommonPackageMappings,
7
+ getGitLfsRepoSetupCommand,
8
+ getPackageName,
9
+ needsGitLfsRepoSetup,
10
+ } from './linuxDistro';
11
+
12
+ describe('linuxDistro', () => {
13
+ describe('getPackageName', () => {
14
+ it('returns Debian package name for Debian distribution', () => {
15
+ const packageMap = {
16
+ debian: 'openjdk-17-jdk',
17
+ redhat: 'java-17-openjdk-devel',
18
+ unknown: 'openjdk-17',
19
+ };
20
+
21
+ const distro: LinuxDistroInfo = {
22
+ type: LinuxDistroType.DEBIAN,
23
+ name: 'Ubuntu',
24
+ packageManager: { name: 'apt', installCommand: 'apt-get install', requiresSudo: true },
25
+ };
26
+
27
+ const result = getPackageName(packageMap, distro);
28
+
29
+ expect(result).toBe('openjdk-17-jdk');
30
+ });
31
+
32
+ it('returns RedHat package name for RedHat distribution', () => {
33
+ const packageMap = {
34
+ debian: 'openjdk-17-jdk',
35
+ redhat: 'java-17-openjdk-devel',
36
+ unknown: 'openjdk-17',
37
+ };
38
+
39
+ const distro: LinuxDistroInfo = {
40
+ type: LinuxDistroType.REDHAT,
41
+ name: 'Fedora',
42
+ packageManager: { name: 'dnf', installCommand: 'dnf install', requiresSudo: true },
43
+ };
44
+
45
+ const result = getPackageName(packageMap, distro);
46
+
47
+ expect(result).toBe('java-17-openjdk-devel');
48
+ });
49
+
50
+ it('returns unknown fallback for distributions without specific mapping', () => {
51
+ const packageMap = {
52
+ debian: 'openjdk-17-jdk',
53
+ unknown: 'openjdk-17',
54
+ };
55
+
56
+ const distro: LinuxDistroInfo = {
57
+ type: LinuxDistroType.ARCH,
58
+ name: 'Arch Linux',
59
+ packageManager: { name: 'pacman', installCommand: 'pacman -S', requiresSudo: true },
60
+ };
61
+
62
+ const result = getPackageName(packageMap, distro);
63
+
64
+ expect(result).toBe('openjdk-17');
65
+ });
66
+ });
67
+
68
+ describe('buildInstallCommand', () => {
69
+ it('builds install command for Debian', () => {
70
+ const distro: LinuxDistroInfo = {
71
+ type: LinuxDistroType.DEBIAN,
72
+ name: 'Ubuntu',
73
+ packageManager: { name: 'apt', installCommand: 'apt-get install', requiresSudo: true },
74
+ };
75
+
76
+ const result = buildInstallCommand(['git', 'npm', 'watchman'], distro);
77
+
78
+ expect(result).toBe('sudo apt-get install git npm watchman');
79
+ });
80
+
81
+ it('builds install command for RedHat', () => {
82
+ const distro: LinuxDistroInfo = {
83
+ type: LinuxDistroType.REDHAT,
84
+ name: 'Fedora',
85
+ packageManager: { name: 'dnf', installCommand: 'dnf install', requiresSudo: true },
86
+ };
87
+
88
+ const result = buildInstallCommand(['git', 'npm'], distro);
89
+
90
+ expect(result).toBe('sudo dnf install git npm');
91
+ });
92
+
93
+ it('builds install command for Arch', () => {
94
+ const distro: LinuxDistroInfo = {
95
+ type: LinuxDistroType.ARCH,
96
+ name: 'Arch Linux',
97
+ packageManager: { name: 'pacman', installCommand: 'pacman -S', requiresSudo: true },
98
+ };
99
+
100
+ const result = buildInstallCommand(['git', 'npm'], distro);
101
+
102
+ expect(result).toBe('sudo pacman -S git npm');
103
+ });
104
+
105
+ it('returns comment for unknown distribution', () => {
106
+ const distro: LinuxDistroInfo = {
107
+ type: LinuxDistroType.UNKNOWN,
108
+ name: 'Unknown',
109
+ packageManager: { name: 'unknown', installCommand: '', requiresSudo: true },
110
+ };
111
+
112
+ const result = buildInstallCommand(['git', 'npm'], distro);
113
+
114
+ expect(result).toContain('Unable to determine package manager');
115
+ expect(result).toContain('git, npm');
116
+ });
117
+ });
118
+
119
+ describe('needsGitLfsRepoSetup', () => {
120
+ it('returns true for Debian distributions', () => {
121
+ const distro: LinuxDistroInfo = {
122
+ type: LinuxDistroType.DEBIAN,
123
+ name: 'Ubuntu',
124
+ packageManager: { name: 'apt', installCommand: 'apt-get install', requiresSudo: true },
125
+ };
126
+
127
+ expect(needsGitLfsRepoSetup(distro)).toBe(true);
128
+ });
129
+
130
+ it('returns false for Arch distributions', () => {
131
+ const distro: LinuxDistroInfo = {
132
+ type: LinuxDistroType.ARCH,
133
+ name: 'Arch Linux',
134
+ packageManager: { name: 'pacman', installCommand: 'pacman -S', requiresSudo: true },
135
+ };
136
+
137
+ expect(needsGitLfsRepoSetup(distro)).toBe(false);
138
+ });
139
+ });
140
+
141
+ describe('getGitLfsRepoSetupCommand', () => {
142
+ it('returns Debian script for Debian distributions', () => {
143
+ const distro: LinuxDistroInfo = {
144
+ type: LinuxDistroType.DEBIAN,
145
+ name: 'Ubuntu',
146
+ packageManager: { name: 'apt', installCommand: 'apt-get install', requiresSudo: true },
147
+ };
148
+
149
+ const result = getGitLfsRepoSetupCommand(distro);
150
+
151
+ expect(result).toContain('script.deb.sh');
152
+ });
153
+
154
+ it('returns RPM script for RedHat distributions', () => {
155
+ const distro: LinuxDistroInfo = {
156
+ type: LinuxDistroType.REDHAT,
157
+ name: 'Fedora',
158
+ packageManager: { name: 'dnf', installCommand: 'dnf install', requiresSudo: true },
159
+ };
160
+
161
+ const result = getGitLfsRepoSetupCommand(distro);
162
+
163
+ expect(result).toContain('script.rpm.sh');
164
+ });
165
+
166
+ it('returns null for distributions with git-lfs in standard repos', () => {
167
+ const distro: LinuxDistroInfo = {
168
+ type: LinuxDistroType.ARCH,
169
+ name: 'Arch Linux',
170
+ packageManager: { name: 'pacman', installCommand: 'pacman -S', requiresSudo: true },
171
+ };
172
+
173
+ const result = getGitLfsRepoSetupCommand(distro);
174
+
175
+ expect(result).toBeNull();
176
+ });
177
+ });
178
+
179
+ describe('getCommonPackageMappings', () => {
180
+ it('returns package mappings for common dependencies', () => {
181
+ const mappings = getCommonPackageMappings();
182
+
183
+ expect(mappings['git']).toBeDefined();
184
+ expect(mappings['git-lfs']).toBeDefined();
185
+ expect(mappings['npm']).toBeDefined();
186
+ expect(mappings['openjdk-17']).toBeDefined();
187
+ expect(mappings['watchman']).toBeDefined();
188
+ expect(mappings['adb']).toBeDefined();
189
+ expect(mappings['fontconfig']).toBeDefined();
190
+ expect(mappings['zlib']).toBeDefined();
191
+ });
192
+
193
+ it('has platform-specific mappings for Java', () => {
194
+ const mappings = getCommonPackageMappings();
195
+ const javaMappings = mappings['openjdk-17'];
196
+
197
+ expect(javaMappings).toBeDefined();
198
+ if (javaMappings) {
199
+ expect(javaMappings.debian).toBe('openjdk-17-jdk');
200
+ expect(javaMappings.redhat).toBe('java-17-openjdk-devel');
201
+ expect(javaMappings.arch).toBe('jdk17-openjdk');
202
+ expect(javaMappings.suse).toBe('java-17-openjdk-devel');
203
+ }
204
+ });
205
+
206
+ it('has platform-specific mappings for adb', () => {
207
+ const mappings = getCommonPackageMappings();
208
+ const adbMappings = mappings['adb'];
209
+
210
+ expect(adbMappings).toBeDefined();
211
+ if (adbMappings) {
212
+ expect(adbMappings.debian).toBe('adb');
213
+ expect(adbMappings.redhat).toBe('android-tools');
214
+ expect(adbMappings.arch).toBe('android-tools');
215
+ expect(adbMappings.suse).toBe('android-tools');
216
+ }
217
+ });
218
+ });
219
+ });
@@ -0,0 +1,326 @@
1
+ import fs from 'fs';
2
+ import { checkCommandExists } from './cliUtils';
3
+
4
+ /**
5
+ * Detected Linux distribution type
6
+ */
7
+ export enum LinuxDistroType {
8
+ DEBIAN = 'debian', // Debian, Ubuntu, Mint, Pop!_OS, etc.
9
+ REDHAT = 'redhat', // RHEL, Fedora, CentOS, Rocky Linux, etc.
10
+ ARCH = 'arch', // Arch Linux, Manjaro, EndeavourOS, etc.
11
+ SUSE = 'suse', // openSUSE, SLES, etc.
12
+ UNKNOWN = 'unknown',
13
+ }
14
+
15
+ /**
16
+ * Package manager information for a Linux distribution
17
+ */
18
+ export interface PackageManager {
19
+ /** Name of the package manager */
20
+ name: string;
21
+ /** Command to install packages (without sudo) */
22
+ installCommand: string;
23
+ /** Whether this package manager requires sudo */
24
+ requiresSudo: boolean;
25
+ /** Command to update package database */
26
+ updateCommand?: string;
27
+ }
28
+
29
+ /**
30
+ * Linux distribution information
31
+ */
32
+ export interface LinuxDistroInfo {
33
+ /** Distribution type */
34
+ type: LinuxDistroType;
35
+ /** Distribution name (e.g., "Ubuntu", "Fedora") */
36
+ name: string;
37
+ /** Distribution version (if available) */
38
+ version?: string;
39
+ /** Package manager information */
40
+ packageManager: PackageManager;
41
+ }
42
+
43
+ /**
44
+ * Infer distribution keys from the enum, excluding 'unknown'
45
+ */
46
+ type Distros = Exclude<`${LinuxDistroType}`, 'unknown'>;
47
+
48
+ /**
49
+ * Package name mappings for different distributions
50
+ * Keys are automatically inferred from LinuxDistroType enum
51
+ */
52
+ export type PackageNameMap = {
53
+ [K in Distros]?: string;
54
+ } & {
55
+ unknown: string; // Fallback for unknown distributions
56
+ };
57
+
58
+ /**
59
+ * Detects the current Linux distribution and package manager
60
+ */
61
+ export function detectLinuxDistro(): LinuxDistroInfo {
62
+ // Try to read /etc/os-release (most modern distributions)
63
+ if (fs.existsSync('/etc/os-release')) {
64
+ try {
65
+ const osRelease = fs.readFileSync('/etc/os-release', 'utf8');
66
+ const lines = osRelease.split('\n');
67
+ const info: { [key: string]: string } = {};
68
+
69
+ for (const line of lines) {
70
+ const match = line.match(/^([^=]+)=(.*)$/);
71
+ if (match && match[1] && match[2]) {
72
+ // Remove quotes from value
73
+ info[match[1]] = match[2].replaceAll(/^["']|["']$/g, '');
74
+ }
75
+ }
76
+
77
+ const id = info['ID']?.toLowerCase() ?? '';
78
+ const idLike = info['ID_LIKE']?.toLowerCase() ?? '';
79
+ const name = info['NAME'] ?? 'Linux';
80
+ const version = info['VERSION_ID'];
81
+
82
+ // Detect distribution type based on ID and ID_LIKE
83
+ if (id.includes('debian') || id.includes('ubuntu') || idLike.includes('debian') || idLike.includes('ubuntu')) {
84
+ const result: LinuxDistroInfo = {
85
+ type: LinuxDistroType.DEBIAN,
86
+ name,
87
+ packageManager: getPackageManager(LinuxDistroType.DEBIAN),
88
+ };
89
+ if (version) result.version = version;
90
+ return result;
91
+ } else if (
92
+ id.includes('fedora') ||
93
+ id.includes('rhel') ||
94
+ id.includes('centos') ||
95
+ id.includes('rocky') ||
96
+ idLike.includes('fedora') ||
97
+ idLike.includes('rhel')
98
+ ) {
99
+ const result: LinuxDistroInfo = {
100
+ type: LinuxDistroType.REDHAT,
101
+ name,
102
+ packageManager: getPackageManager(LinuxDistroType.REDHAT),
103
+ };
104
+ if (version) result.version = version;
105
+ return result;
106
+ } else if (id.includes('arch') || id.includes('manjaro') || idLike.includes('arch')) {
107
+ const result: LinuxDistroInfo = {
108
+ type: LinuxDistroType.ARCH,
109
+ name,
110
+ packageManager: getPackageManager(LinuxDistroType.ARCH),
111
+ };
112
+ if (version) result.version = version;
113
+ return result;
114
+ } else if (id.includes('suse') || idLike.includes('suse')) {
115
+ const result: LinuxDistroInfo = {
116
+ type: LinuxDistroType.SUSE,
117
+ name,
118
+ packageManager: getPackageManager(LinuxDistroType.SUSE),
119
+ };
120
+ if (version) result.version = version;
121
+ return result;
122
+ }
123
+ } catch {
124
+ // Fall through to legacy detection
125
+ }
126
+ }
127
+
128
+ // Legacy detection methods
129
+ if (checkCommandExists('apt-get')) {
130
+ return {
131
+ type: LinuxDistroType.DEBIAN,
132
+ name: 'Debian/Ubuntu',
133
+ packageManager: getPackageManager(LinuxDistroType.DEBIAN),
134
+ };
135
+ } else if (checkCommandExists('dnf')) {
136
+ return {
137
+ type: LinuxDistroType.REDHAT,
138
+ name: 'Fedora/RHEL',
139
+ packageManager: getPackageManager(LinuxDistroType.REDHAT),
140
+ };
141
+ } else if (checkCommandExists('yum')) {
142
+ return {
143
+ type: LinuxDistroType.REDHAT,
144
+ name: 'RHEL/CentOS',
145
+ packageManager: getPackageManager(LinuxDistroType.REDHAT),
146
+ };
147
+ } else if (checkCommandExists('pacman')) {
148
+ return {
149
+ type: LinuxDistroType.ARCH,
150
+ name: 'Arch Linux',
151
+ packageManager: getPackageManager(LinuxDistroType.ARCH),
152
+ };
153
+ } else if (checkCommandExists('zypper')) {
154
+ return {
155
+ type: LinuxDistroType.SUSE,
156
+ name: 'openSUSE/SLES',
157
+ packageManager: getPackageManager(LinuxDistroType.SUSE),
158
+ };
159
+ }
160
+
161
+ // Unknown distribution
162
+ return {
163
+ type: LinuxDistroType.UNKNOWN,
164
+ name: 'Unknown Linux',
165
+ packageManager: {
166
+ name: 'unknown',
167
+ installCommand: '',
168
+ requiresSudo: true,
169
+ },
170
+ };
171
+ }
172
+
173
+ /**
174
+ * Gets the package manager for a specific distribution type
175
+ */
176
+ function getPackageManager(distroType: LinuxDistroType): PackageManager {
177
+ switch (distroType) {
178
+ case LinuxDistroType.DEBIAN: {
179
+ return {
180
+ name: 'apt',
181
+ installCommand: 'apt-get install',
182
+ requiresSudo: true,
183
+ updateCommand: 'apt-get update',
184
+ };
185
+ }
186
+ case LinuxDistroType.REDHAT: {
187
+ // Prefer dnf over yum
188
+ if (checkCommandExists('dnf')) {
189
+ return {
190
+ name: 'dnf',
191
+ installCommand: 'dnf install',
192
+ requiresSudo: true,
193
+ };
194
+ } else {
195
+ return {
196
+ name: 'yum',
197
+ installCommand: 'yum install',
198
+ requiresSudo: true,
199
+ };
200
+ }
201
+ }
202
+ case LinuxDistroType.ARCH: {
203
+ return {
204
+ name: 'pacman',
205
+ installCommand: 'pacman -S',
206
+ requiresSudo: true,
207
+ updateCommand: 'pacman -Sy',
208
+ };
209
+ }
210
+ case LinuxDistroType.SUSE: {
211
+ return {
212
+ name: 'zypper',
213
+ installCommand: 'zypper install',
214
+ requiresSudo: true,
215
+ };
216
+ }
217
+ default: {
218
+ return {
219
+ name: 'unknown',
220
+ installCommand: '',
221
+ requiresSudo: true,
222
+ };
223
+ }
224
+ }
225
+ }
226
+
227
+ /**
228
+ * Gets the appropriate package name for the current distribution
229
+ * Uses type-safe indexing based on the LinuxDistroType enum
230
+ */
231
+ export function getPackageName(packageMap: PackageNameMap, distro = detectLinuxDistro()): string {
232
+ return packageMap[distro.type] ?? packageMap.unknown;
233
+ }
234
+
235
+ /**
236
+ * Builds an install command for packages on the current distribution
237
+ */
238
+ export function buildInstallCommand(packages: string[], distro = detectLinuxDistro()): string {
239
+ if (distro.type === LinuxDistroType.UNKNOWN) {
240
+ return `# Unable to determine package manager. Please install manually: ${packages.join(', ')}`;
241
+ }
242
+
243
+ const { packageManager } = distro;
244
+ const sudo = packageManager.requiresSudo ? 'sudo ' : '';
245
+
246
+ return `${sudo}${packageManager.installCommand} ${packages.join(' ')}`;
247
+ }
248
+
249
+ /**
250
+ * Gets the package name mappings for common dependencies
251
+ */
252
+ export function getCommonPackageMappings(): { [key: string]: PackageNameMap } {
253
+ return {
254
+ git: {
255
+ unknown: 'git',
256
+ },
257
+ 'git-lfs': {
258
+ unknown: 'git-lfs',
259
+ },
260
+ npm: {
261
+ unknown: 'npm',
262
+ },
263
+ 'openjdk-17': {
264
+ debian: 'openjdk-17-jdk',
265
+ redhat: 'java-17-openjdk-devel',
266
+ arch: 'jdk17-openjdk',
267
+ suse: 'java-17-openjdk-devel',
268
+ unknown: 'openjdk-17-jdk',
269
+ },
270
+ watchman: {
271
+ debian: 'watchman',
272
+ redhat: 'watchman', // May need EPEL repository
273
+ arch: 'watchman',
274
+ suse: 'watchman',
275
+ unknown: 'watchman',
276
+ },
277
+ adb: {
278
+ debian: 'adb',
279
+ redhat: 'android-tools',
280
+ arch: 'android-tools',
281
+ suse: 'android-tools',
282
+ unknown: 'adb',
283
+ },
284
+ fontconfig: {
285
+ debian: 'libfontconfig1-dev',
286
+ redhat: 'fontconfig-devel',
287
+ arch: 'fontconfig',
288
+ suse: 'fontconfig-devel',
289
+ unknown: 'fontconfig',
290
+ },
291
+ zlib: {
292
+ debian: 'zlib1g-dev',
293
+ redhat: 'zlib-devel',
294
+ arch: 'zlib',
295
+ suse: 'zlib-devel',
296
+ unknown: 'zlib',
297
+ },
298
+ };
299
+ }
300
+
301
+ /**
302
+ * Checks if git-lfs can be installed directly or needs repository setup
303
+ */
304
+ export function needsGitLfsRepoSetup(distro = detectLinuxDistro()): boolean {
305
+ // Only Debian/Ubuntu-based systems need the packagecloud repository setup
306
+ // Other distributions usually have git-lfs in their standard repos
307
+ return distro.type === LinuxDistroType.DEBIAN;
308
+ }
309
+
310
+ /**
311
+ * Gets the shell command to setup git-lfs repository for the current distribution
312
+ */
313
+ export function getGitLfsRepoSetupCommand(distro = detectLinuxDistro()): string | null {
314
+ switch (distro.type) {
315
+ case LinuxDistroType.DEBIAN: {
316
+ return 'curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | sudo bash';
317
+ }
318
+ case LinuxDistroType.REDHAT: {
319
+ return 'curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.rpm.sh | sudo bash';
320
+ }
321
+ default: {
322
+ // Most other distributions have git-lfs in their standard repositories
323
+ return null;
324
+ }
325
+ }
326
+ }