@snap/valdi 1.0.1 → 1.0.7

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 (41) hide show
  1. package/.bootstrap/modules/cpp_bridge_module/BUILD.bazel.template +3 -3
  2. package/.bootstrap/modules/cpp_bridge_module/cpp/CalculatorModuleFactory.cpp.template +18 -19
  3. package/.bootstrap/modules/cpp_bridge_module/src/Calculator.d.ts +3 -0
  4. package/.github/README.md +164 -0
  5. package/.metadata/.cursorrules.template +60 -0
  6. package/.metadata/.editorconfig.template +37 -0
  7. package/{.bootstrap/apps/ui_application → .metadata}/AGENTS.md.template +84 -4
  8. package/LINUX_COMPATIBILITY.md +248 -0
  9. package/README.md +110 -23
  10. package/dist/commands/bootstrap.js +80 -19
  11. package/dist/commands/doctor.js +361 -54
  12. package/dist/commands/newModule.js +15 -12
  13. package/dist/core/constants.js +3 -0
  14. package/dist/index.js +5 -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 +118 -25
  27. package/src/commands/doctor.ts +469 -59
  28. package/src/commands/newModule.ts +18 -19
  29. package/src/core/constants.ts +3 -0
  30. package/src/index.ts +5 -0
  31. package/src/setup/DevSetupHelper.ts +108 -6
  32. package/src/setup/linuxSetup.ts +235 -12
  33. package/src/setup/macOSSetup.ts +122 -8
  34. package/src/utils/githubUtils.ts +98 -2
  35. package/src/utils/linuxDistro.spec.ts +219 -0
  36. package/src/utils/linuxDistro.ts +326 -0
  37. package/src/utils/stringUtils.spec.ts +77 -1
  38. package/src/utils/stringUtils.ts +88 -0
  39. package/test/ValdiSmokeTest.ts +5 -4
  40. package/test/helpers/TypeScriptClient.ts +2 -2
  41. package/.bootstrap/apps/cli_application/AGENTS.md.template +0 -215
@@ -12,8 +12,16 @@ const tempDir_1 = require("../utils/tempDir");
12
12
  const zipUtils_1 = require("../utils/zipUtils");
13
13
  const versions_1 = require("./versions");
14
14
  exports.HOME_DIR = process.env['HOME'] ?? '';
15
- const ANDROID_HOME_DIR_SUFFIX = '.valdi/android_home';
16
- const ANDROID_HOME_TARET_DIR = path_1.default.join(exports.HOME_DIR, ANDROID_HOME_DIR_SUFFIX);
15
+ function getAndroidHomeDir() {
16
+ const platform = process.platform;
17
+ if (platform === 'darwin') {
18
+ return path_1.default.join(exports.HOME_DIR, 'Library', 'Android', 'sdk');
19
+ }
20
+ else {
21
+ return path_1.default.join(exports.HOME_DIR, 'Android', 'Sdk');
22
+ }
23
+ }
24
+ const ANDROID_HOME_TARGET_DIR = getAndroidHomeDir();
17
25
  class DevSetupHelper {
18
26
  async download(url) {
19
27
  return new LoadingIndicator_1.LoadingIndicator(async () => {
@@ -90,6 +98,67 @@ class DevSetupHelper {
90
98
  suffix += ` Please run ${(0, logUtils_1.wrapInColor)(`source ${rcFile}`, constants_1.ANSI_COLORS.YELLOW_COLOR)} or restart your terminal.`;
91
99
  }
92
100
  console.log(`${(0, logUtils_1.wrapInColor)('Dev setup completed!', constants_1.ANSI_COLORS.GREEN_COLOR)}.${suffix}`);
101
+ console.log();
102
+ console.log((0, logUtils_1.wrapInColor)('📝 Next steps:', constants_1.ANSI_COLORS.BLUE_COLOR));
103
+ console.log(' 1. Restart your terminal or source your shell configuration');
104
+ console.log(' 2. Install VSCode/Cursor extensions for the best development experience:');
105
+ console.log(` ${(0, logUtils_1.wrapInColor)('https://github.com/Snapchat/Valdi/blob/main/docs/INSTALL.md#vscodecursor-setup-optional-but-recommended', constants_1.ANSI_COLORS.BLUE_COLOR)}`);
106
+ console.log(' 3. Run `valdi doctor` to verify your setup');
107
+ console.log(' 4. Create your first project with `valdi bootstrap`');
108
+ }
109
+ async setupGitLfs() {
110
+ await this.runShell('Initializing git-lfs', ['git lfs install']);
111
+ }
112
+ async setupShellAutoComplete() {
113
+ const rcFile = this.getRcFile();
114
+ if (!rcFile) {
115
+ console.log((0, logUtils_1.wrapInColor)('Could not determine shell configuration file, skipping autocomplete setup...', constants_1.ANSI_COLORS.YELLOW_COLOR));
116
+ return;
117
+ }
118
+ const shell = process.env['SHELL'] ?? '';
119
+ let autoCompleteLines = [];
120
+ if (shell.endsWith('/zsh')) {
121
+ autoCompleteLines = ['autoload -U compinit && compinit', 'autoload -U bashcompinit && bashcompinit'];
122
+ }
123
+ else if (shell.endsWith('/bash')) {
124
+ autoCompleteLines = ['# Bash completion is enabled'];
125
+ }
126
+ if (autoCompleteLines.length === 0 || autoCompleteLines[0] === '# Bash completion is enabled') {
127
+ if (shell.endsWith('/bash')) {
128
+ console.log((0, logUtils_1.wrapInColor)('Shell autocomplete setup complete (bash)', constants_1.ANSI_COLORS.GREEN_COLOR));
129
+ }
130
+ return;
131
+ }
132
+ return new LoadingIndicator_1.LoadingIndicator(async () => {
133
+ let originalRcLines = [];
134
+ let rcLines = [];
135
+ if (fs_1.default.existsSync(rcFile)) {
136
+ const fileBody = await fs_1.default.promises.readFile(rcFile, 'utf8');
137
+ originalRcLines = fileBody.split('\n');
138
+ rcLines = [...originalRcLines];
139
+ }
140
+ let needsUpdate = false;
141
+ for (const line of autoCompleteLines) {
142
+ if (!rcLines.includes(line)) {
143
+ needsUpdate = true;
144
+ break;
145
+ }
146
+ }
147
+ if (needsUpdate) {
148
+ const valdiConfBegin = rcLines.indexOf('# Valdi configuration begin');
149
+ const insertIndex = valdiConfBegin >= 0 ? valdiConfBegin : 0;
150
+ for (let i = autoCompleteLines.length - 1; i >= 0; i--) {
151
+ const line = autoCompleteLines[i];
152
+ if (line && !rcLines.includes(line)) {
153
+ rcLines.splice(insertIndex, 0, line);
154
+ }
155
+ }
156
+ const content = rcLines.join('\n');
157
+ await fs_1.default.promises.writeFile(rcFile, content, 'utf8');
158
+ }
159
+ })
160
+ .setText((0, logUtils_1.wrapInColor)('Setting up shell autocomplete...', constants_1.ANSI_COLORS.YELLOW_COLOR))
161
+ .show();
93
162
  }
94
163
  async setupAndroidSDK(commandLineToolsURL, javaHomeOverride) {
95
164
  console.log((0, logUtils_1.wrapInColor)('Setting up Android SDK...', constants_1.ANSI_COLORS.YELLOW_COLOR));
@@ -97,7 +166,7 @@ class DevSetupHelper {
97
166
  await (0, tempDir_1.withTempDir)(async (tempDir) => {
98
167
  const filename = path_1.default.join(tempDir, path_1.default.basename(commandLineToolsURL));
99
168
  await this.downloadToPath(commandLineToolsURL, filename);
100
- const targetDir = path_1.default.join(ANDROID_HOME_TARET_DIR, 'cmdline-tools');
169
+ const targetDir = path_1.default.join(ANDROID_HOME_TARGET_DIR, 'cmdline-tools');
101
170
  await (0, zipUtils_1.decompressTo)(filename, targetDir);
102
171
  const target = path_1.default.join(targetDir, 'latest');
103
172
  if (fs_1.default.existsSync(target)) {
@@ -105,8 +174,11 @@ class DevSetupHelper {
105
174
  }
106
175
  fs_1.default.renameSync(path_1.default.join(targetDir, 'cmdline-tools'), target);
107
176
  });
108
- process.env['ANDROID_HOME'] = path_1.default.join(exports.HOME_DIR, ANDROID_HOME_DIR_SUFFIX);
109
- await this.writeEnvVariablesToRcFile([{ name: 'ANDROID_HOME', value: `"$HOME/${ANDROID_HOME_DIR_SUFFIX}"` }]);
177
+ process.env['ANDROID_HOME'] = ANDROID_HOME_TARGET_DIR;
178
+ const androidHomeValue = process.platform === 'darwin'
179
+ ? '"$HOME/Library/Android/sdk"'
180
+ : '"$HOME/Android/Sdk"';
181
+ await this.writeEnvVariablesToRcFile([{ name: 'ANDROID_HOME', value: androidHomeValue }]);
110
182
  }
111
183
  const androidHome = process.env['ANDROID_HOME'] ?? '';
112
184
  const sdkManagerBin = path_1.default.join(androidHome, 'cmdline-tools/latest/bin/sdkmanager');
@@ -121,7 +193,10 @@ class DevSetupHelper {
121
193
  if (!fs_1.default.existsSync(ndkBundle)) {
122
194
  fs_1.default.symlinkSync(`ndk/${versions_1.ANDROID_NDK_VERSION}`, ndkBundle);
123
195
  }
124
- await this.writeEnvVariablesToRcFile([{ name: 'ANDROID_NDK_HOME', value: `"$ANDROID_HOME/ndk-bundle"` }]);
196
+ await this.writeEnvVariablesToRcFile([
197
+ { name: 'ANDROID_NDK_HOME', value: `"$ANDROID_HOME/ndk-bundle"` },
198
+ { name: 'PATH', value: `"$ANDROID_HOME/platform-tools:$PATH"` },
199
+ ]);
125
200
  }
126
201
  getRcFile() {
127
202
  const homeDir = process.env['HOME'] ?? '';
@@ -2,29 +2,167 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.linuxSetup = linuxSetup;
4
4
  const tslib_1 = require("tslib");
5
+ const child_process_1 = require("child_process");
5
6
  const fs_1 = tslib_1.__importDefault(require("fs"));
7
+ const os_1 = tslib_1.__importDefault(require("os"));
6
8
  const path_1 = tslib_1.__importDefault(require("path"));
9
+ const constants_1 = require("../core/constants");
7
10
  const cliUtils_1 = require("../utils/cliUtils");
11
+ const linuxDistro_1 = require("../utils/linuxDistro");
12
+ const logUtils_1 = require("../utils/logUtils");
8
13
  const DevSetupHelper_1 = require("./DevSetupHelper");
9
14
  const versions_1 = require("./versions");
10
15
  const BAZELISK_URL = 'https://github.com/bazelbuild/bazelisk/releases/download/v1.26.0/bazelisk-linux-amd64';
16
+ function getDebianArchitecture() {
17
+ const nodeArch = os_1.default.arch();
18
+ switch (nodeArch) {
19
+ case 'x64': {
20
+ return 'amd64';
21
+ }
22
+ case 'arm64': {
23
+ return 'arm64';
24
+ }
25
+ case 'arm': {
26
+ return 'armhf';
27
+ }
28
+ case 'ia32': {
29
+ return 'i386';
30
+ }
31
+ default: {
32
+ console.log((0, logUtils_1.wrapInColor)(`Warning: Unknown architecture '${nodeArch}', defaulting to amd64`, constants_1.ANSI_COLORS.YELLOW_COLOR));
33
+ return 'amd64';
34
+ }
35
+ }
36
+ }
11
37
  async function linuxSetup() {
12
38
  const devSetup = new DevSetupHelper_1.DevSetupHelper();
13
- await devSetup.runShell('Installing dependencies from apt', [
14
- `sudo apt-get install zlib1g-dev git-lfs watchman libfontconfig-dev adb`,
15
- ]);
16
- await devSetup.runShell('Installing libtinfo5', [
17
- `wget http://security.ubuntu.com/ubuntu/pool/universe/n/ncurses/libtinfo5_6.3-2ubuntu0.1_amd64.deb`,
18
- `sudo apt install ./libtinfo5_6.3-2ubuntu0.1_amd64.deb`,
19
- ]);
39
+ const distro = (0, linuxDistro_1.detectLinuxDistro)();
40
+ console.log((0, logUtils_1.wrapInColor)(`Detected distribution: ${distro.name} (${distro.packageManager.name})`, constants_1.ANSI_COLORS.BLUE_COLOR));
41
+ if (distro.type === linuxDistro_1.LinuxDistroType.UNKNOWN) {
42
+ console.log();
43
+ console.log((0, logUtils_1.wrapInColor)('Unable to detect Linux distribution.', constants_1.ANSI_COLORS.YELLOW_COLOR));
44
+ console.log((0, logUtils_1.wrapInColor)('Please manually install the following dependencies and re-run this command:', constants_1.ANSI_COLORS.YELLOW_COLOR));
45
+ console.log(' - git');
46
+ console.log(' - git-lfs');
47
+ console.log(' - npm (Node.js)');
48
+ console.log(' - openjdk-17-jdk (or equivalent Java 17 JDK)');
49
+ console.log(' - watchman');
50
+ console.log(' - adb (Android Debug Bridge)');
51
+ console.log(' - fontconfig development libraries');
52
+ console.log(' - zlib development libraries');
53
+ console.log();
54
+ console.log((0, logUtils_1.wrapInColor)('For manual installation instructions, see: https://github.com/Snapchat/Valdi/blob/main/docs/INSTALL.md', constants_1.ANSI_COLORS.BLUE_COLOR));
55
+ throw new Error('Unable to proceed with automatic setup on unknown Linux distribution');
56
+ }
57
+ const packageMappings = (0, linuxDistro_1.getCommonPackageMappings)();
58
+ const repoSetupCommand = (0, linuxDistro_1.getGitLfsRepoSetupCommand)(distro);
59
+ if (repoSetupCommand && (0, linuxDistro_1.needsGitLfsRepoSetup)(distro)) {
60
+ try {
61
+ await devSetup.runShell('Setting up git-lfs repository', [repoSetupCommand]);
62
+ }
63
+ catch {
64
+ console.log((0, logUtils_1.wrapInColor)(`Warning: git-lfs repository setup failed. Will try to install git-lfs from standard repositories.`, constants_1.ANSI_COLORS.YELLOW_COLOR));
65
+ }
66
+ }
67
+ const packagesToInstall = [];
68
+ if (!(0, cliUtils_1.checkCommandExists)('npm')) {
69
+ packagesToInstall.push((0, linuxDistro_1.getPackageName)(packageMappings['npm'], distro));
70
+ }
20
71
  if (!(0, cliUtils_1.checkCommandExists)('java')) {
21
- await devSetup.runShell('Installing Java Runtime Environment', ['sudo apt install default-jre']);
72
+ packagesToInstall.push((0, linuxDistro_1.getPackageName)(packageMappings['openjdk-17'], distro));
73
+ }
74
+ if (!(0, cliUtils_1.checkCommandExists)('git-lfs')) {
75
+ packagesToInstall.push((0, linuxDistro_1.getPackageName)(packageMappings['git-lfs'], distro));
76
+ }
77
+ if (!(0, cliUtils_1.checkCommandExists)('watchman')) {
78
+ packagesToInstall.push((0, linuxDistro_1.getPackageName)(packageMappings['watchman'], distro));
79
+ }
80
+ if (!(0, cliUtils_1.checkCommandExists)('adb')) {
81
+ packagesToInstall.push((0, linuxDistro_1.getPackageName)(packageMappings['adb'], distro));
82
+ }
83
+ packagesToInstall.push((0, linuxDistro_1.getPackageName)(packageMappings['fontconfig'], distro), (0, linuxDistro_1.getPackageName)(packageMappings['zlib'], distro));
84
+ if (packagesToInstall.length > 0) {
85
+ const installCommand = (0, linuxDistro_1.buildInstallCommand)(packagesToInstall, distro);
86
+ try {
87
+ await devSetup.runShell(`Installing dependencies via ${distro.packageManager.name}`, [installCommand]);
88
+ }
89
+ catch {
90
+ console.log();
91
+ console.log((0, logUtils_1.wrapInColor)('Some packages failed to install.', constants_1.ANSI_COLORS.YELLOW_COLOR));
92
+ console.log((0, logUtils_1.wrapInColor)('Common issues:', constants_1.ANSI_COLORS.YELLOW_COLOR));
93
+ if (distro.type === linuxDistro_1.LinuxDistroType.REDHAT) {
94
+ console.log(' - watchman may require EPEL repository on RHEL-based systems');
95
+ console.log(' Run: sudo dnf install epel-release (or sudo yum install epel-release)');
96
+ }
97
+ else if (distro.type === linuxDistro_1.LinuxDistroType.ARCH) {
98
+ console.log(' - Some packages may be in the AUR');
99
+ console.log(' Consider using an AUR helper like yay or paru');
100
+ }
101
+ console.log();
102
+ console.log((0, logUtils_1.wrapInColor)('Continuing with setup...', constants_1.ANSI_COLORS.YELLOW_COLOR));
103
+ }
104
+ }
105
+ else {
106
+ console.log((0, logUtils_1.wrapInColor)('All required packages are already installed.', constants_1.ANSI_COLORS.GREEN_COLOR));
107
+ }
108
+ await devSetup.setupGitLfs();
109
+ await devSetup.setupShellAutoComplete();
110
+ if (distro.type === linuxDistro_1.LinuxDistroType.DEBIAN) {
111
+ const libtinfoInstalled = (0, cliUtils_1.checkCommandExists)('dpkg') &&
112
+ (() => {
113
+ try {
114
+ (0, child_process_1.execSync)('dpkg -l libtinfo5', { stdio: 'ignore' });
115
+ return true;
116
+ }
117
+ catch {
118
+ return false;
119
+ }
120
+ })();
121
+ if (!libtinfoInstalled) {
122
+ try {
123
+ const arch = getDebianArchitecture();
124
+ const version = '6.3-2ubuntu0.1';
125
+ const packageName = `libtinfo5_${version}_${arch}.deb`;
126
+ const packageUrl = `https://security.ubuntu.com/ubuntu/pool/universe/n/ncurses/${packageName}`;
127
+ const tempPath = path_1.default.join(DevSetupHelper_1.HOME_DIR, `.valdi/tmp/${packageName}`);
128
+ const tempDir = path_1.default.dirname(tempPath);
129
+ if (!fs_1.default.existsSync(tempDir)) {
130
+ fs_1.default.mkdirSync(tempDir, { recursive: true });
131
+ }
132
+ console.log((0, logUtils_1.wrapInColor)(`Downloading libtinfo5 for ${arch} architecture...`, constants_1.ANSI_COLORS.BLUE_COLOR));
133
+ await devSetup.downloadToPath(packageUrl, tempPath);
134
+ await devSetup.runShell('Installing libtinfo5 (required for Android tools)', [
135
+ `sudo apt install -y ${tempPath}`,
136
+ ]);
137
+ fs_1.default.unlinkSync(tempPath);
138
+ }
139
+ catch (error) {
140
+ console.log((0, logUtils_1.wrapInColor)('Warning: libtinfo5 installation failed. Some Android command-line tools may not work.', constants_1.ANSI_COLORS.YELLOW_COLOR));
141
+ console.log((0, logUtils_1.wrapInColor)(`Details: ${error instanceof Error ? error.message : 'Unknown error'}`, constants_1.ANSI_COLORS.YELLOW_COLOR));
142
+ console.log((0, logUtils_1.wrapInColor)('You may need to install it manually if you encounter issues.', constants_1.ANSI_COLORS.YELLOW_COLOR));
143
+ }
144
+ }
145
+ }
146
+ else if (distro.type === linuxDistro_1.LinuxDistroType.REDHAT) {
147
+ try {
148
+ await devSetup.runShell('Installing ncurses compatibility libraries (for Android tools)', [
149
+ (0, linuxDistro_1.buildInstallCommand)(['ncurses-compat-libs'], distro),
150
+ ]);
151
+ }
152
+ catch {
153
+ console.log((0, logUtils_1.wrapInColor)('Warning: ncurses-compat-libs installation failed. Some Android command-line tools may not work.', constants_1.ANSI_COLORS.YELLOW_COLOR));
154
+ }
22
155
  }
23
156
  const bazeliskPathSuffix = '.valdi/bin/bazelisk';
24
157
  const bazeliskTargetPath = path_1.default.join(DevSetupHelper_1.HOME_DIR, bazeliskPathSuffix);
25
- await devSetup.downloadToPath(BAZELISK_URL, bazeliskTargetPath);
26
- const stats = fs_1.default.statSync(bazeliskTargetPath);
27
- fs_1.default.chmodSync(bazeliskTargetPath, stats.mode | 0o111);
158
+ if (fs_1.default.existsSync(bazeliskTargetPath)) {
159
+ console.log((0, logUtils_1.wrapInColor)('Bazelisk already installed.', constants_1.ANSI_COLORS.GREEN_COLOR));
160
+ }
161
+ else {
162
+ await devSetup.downloadToPath(BAZELISK_URL, bazeliskTargetPath);
163
+ const stats = fs_1.default.statSync(bazeliskTargetPath);
164
+ fs_1.default.chmodSync(bazeliskTargetPath, stats.mode | 0o111);
165
+ }
28
166
  await devSetup.writeEnvVariablesToRcFile([{ name: 'PATH', value: `"$HOME/.valdi/bin:$PATH"` }]);
29
167
  await devSetup.setupAndroidSDK(versions_1.ANDROID_LINUX_COMMANDLINE_TOOLS);
30
168
  devSetup.onComplete();
@@ -10,24 +10,112 @@ const versions_1 = require("./versions");
10
10
  async function macOSSetup() {
11
11
  const devSetup = new DevSetupHelper_1.DevSetupHelper();
12
12
  if (!(0, cliUtils_1.checkCommandExists)('xcode-select')) {
13
- throw new errors_1.CliError('Xcode is not installed. Please install Xcode from the App Store as setup requires Xcode command line tools');
13
+ throw new errors_1.CliError('Xcode command line tools are not installed.\n\n' +
14
+ 'Please install Xcode from the App Store, then run:\n' +
15
+ ' sudo xcode-select -s /Applications/Xcode.app\n\n' +
16
+ 'After installation, run valdi dev_setup again.');
17
+ }
18
+ try {
19
+ const xcodePathResult = await (0, cliUtils_1.runCliCommand)('xcode-select -p');
20
+ const xcodePath = xcodePathResult.stdout.trim();
21
+ if (!xcodePath || !fs_1.default.existsSync(xcodePath)) {
22
+ throw new errors_1.CliError('Xcode command line tools path is not configured correctly.\n\n' +
23
+ 'Please run:\n' +
24
+ ' sudo xcode-select -s /Applications/Xcode.app\n\n' +
25
+ 'Or if you have Xcode with a different name (e.g., beta versions):\n' +
26
+ ' sudo xcode-select -s /Applications/YourXcode.app\n\n' +
27
+ 'After configuration, run valdi dev_setup again.');
28
+ }
29
+ const xcodeAppPath = xcodePath.replace(/\/Contents\/Developer\/?$/, '');
30
+ if (!fs_1.default.existsSync(xcodeAppPath) || !xcodeAppPath.includes('Xcode')) {
31
+ throw new errors_1.CliError('Xcode installation not found.\n\n' +
32
+ `xcode-select points to ${xcodePath}\n` +
33
+ `but Xcode app not found at ${xcodeAppPath}\n\n` +
34
+ 'Please install Xcode from the App Store:\n' +
35
+ ' https://apps.apple.com/us/app/xcode/id497799835\n\n' +
36
+ 'Then configure it with:\n' +
37
+ ' sudo xcode-select -s /Applications/Xcode.app\n\n' +
38
+ 'After installation, run valdi dev_setup again.');
39
+ }
40
+ }
41
+ catch (error) {
42
+ if (error instanceof errors_1.CliError) {
43
+ throw error;
44
+ }
45
+ throw new errors_1.CliError('Failed to verify Xcode installation.\n\n' +
46
+ 'Please ensure Xcode is installed from the App Store and properly configured:\n' +
47
+ ' sudo xcode-select -s /Applications/Xcode.app\n\n' +
48
+ 'After setup, run valdi dev_setup again.');
14
49
  }
15
50
  if (!(0, cliUtils_1.checkCommandExists)('brew')) {
16
51
  await devSetup.runShell('Homebrew not found. Installing', [
17
52
  '/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"',
18
53
  ]);
54
+ const homeDir = process.env['HOME'] ?? '';
55
+ const zprofilePath = `${homeDir}/.zprofile`;
56
+ const brewShellenvLine = 'eval "$(/opt/homebrew/bin/brew shellenv)"';
57
+ try {
58
+ let zprofileContent = '';
59
+ if (fs_1.default.existsSync(zprofilePath)) {
60
+ zprofileContent = fs_1.default.readFileSync(zprofilePath, 'utf8');
61
+ }
62
+ if (!zprofileContent.includes(brewShellenvLine)) {
63
+ const newContent = zprofileContent + '\n' + brewShellenvLine + '\n';
64
+ fs_1.default.writeFileSync(zprofilePath, newContent, 'utf8');
65
+ console.log('Added Homebrew to PATH in .zprofile');
66
+ }
67
+ }
68
+ catch {
69
+ console.log('Note: Could not automatically configure Homebrew PATH in .zprofile');
70
+ }
19
71
  }
20
- await devSetup.runShell('Installing dependencies from Homebrew', [
21
- 'brew install npm bazelisk openjdk@11 temurin git-lfs watchman ios-webkit-debug-proxy',
22
- ]);
23
- if (!fs_1.default.existsSync('/Library/Java/JavaVirtualMachines/openjdk-11.jdk')) {
72
+ const packages = ['npm', 'bazelisk', 'openjdk@17', 'temurin', 'git-lfs', 'watchman', 'ios-webkit-debug-proxy'];
73
+ const packagesToInstall = [];
74
+ for (const pkg of packages) {
75
+ try {
76
+ const result = await (0, cliUtils_1.runCliCommand)(`brew list ${pkg}`);
77
+ if (result.returnCode !== 0) {
78
+ packagesToInstall.push(pkg);
79
+ }
80
+ }
81
+ catch {
82
+ packagesToInstall.push(pkg);
83
+ }
84
+ }
85
+ if (packagesToInstall.length > 0) {
86
+ await devSetup.runShell(`Installing dependencies from Homebrew (${packagesToInstall.length}/${packages.length})`, [`brew install ${packagesToInstall.join(' ')}`]);
87
+ }
88
+ else {
89
+ console.log('All Homebrew dependencies are already installed');
90
+ }
91
+ await devSetup.setupGitLfs();
92
+ await devSetup.setupShellAutoComplete();
93
+ const jdkSymlinkPath = '/Library/Java/JavaVirtualMachines/openjdk-17.jdk';
94
+ const jdkSourcePath = '/opt/homebrew/opt/openjdk@17/libexec/openjdk.jdk';
95
+ let needsJdkSymlink = false;
96
+ if (fs_1.default.existsSync(jdkSymlinkPath)) {
97
+ try {
98
+ const linkTarget = fs_1.default.readlinkSync(jdkSymlinkPath);
99
+ if (linkTarget !== jdkSourcePath) {
100
+ needsJdkSymlink = true;
101
+ }
102
+ }
103
+ catch {
104
+ needsJdkSymlink = true;
105
+ }
106
+ }
107
+ else {
108
+ needsJdkSymlink = true;
109
+ }
110
+ if (needsJdkSymlink) {
111
+ console.log('\nSetting up JDK symlink (requires admin password)...');
24
112
  await devSetup.runShell('Setting up JDK', [
25
- 'sudo ln -sfn /opt/homebrew/opt/openjdk@11/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk-11.jdk',
113
+ 'sudo ln -sfn /opt/homebrew/opt/openjdk@17/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk-17.jdk',
26
114
  ]);
27
115
  }
28
116
  await devSetup.writeEnvVariablesToRcFile([
29
- { name: 'PATH', value: '"/opt/homebrew/opt/openjdk@11/bin:$PATH"' },
30
- { name: 'JAVA_HOME', value: '`/usr/libexec/java_home -v 11`' },
117
+ { name: 'PATH', value: '"/opt/homebrew/opt/openjdk@17/bin:$PATH"' },
118
+ { name: 'JAVA_HOME', value: '`/usr/libexec/java_home -v 17`' },
31
119
  ]);
32
120
  const javaHome = await (0, cliUtils_1.runCliCommand)('/usr/libexec/java_home');
33
121
  await devSetup.setupAndroidSDK(versions_1.ANDROID_MACOS_COMMANDLINE_TOOLS, javaHome.stdout.trim());
@@ -1,8 +1,80 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getLatestReleaseTag = getLatestReleaseTag;
3
4
  exports.resolveLatestReleaseRef = resolveLatestReleaseRef;
4
5
  const cliUtils_1 = require("./cliUtils");
6
+ function parseGitHubRepoSlug(repoUrl) {
7
+ const normalized = repoUrl.replace(/\.git$/u, '').trim();
8
+ const match = normalized.match(/github\.com[/:]([^/]+)\/([^/]+?)(?:[/]?$)/u);
9
+ if (!match) {
10
+ throw new Error(`Invalid GitHub URL: ${repoUrl}`);
11
+ }
12
+ return `${match[1]}/${match[2]}`;
13
+ }
14
+ const LATEST_RELEASE_HINT = 'Use --valdiVersion=latest to retry, or --valdiVersion=<tag> (e.g. main or v1.0.0) to pin a version.';
15
+ async function getLatestReleaseTag(repoUrl) {
16
+ const slug = parseGitHubRepoSlug(repoUrl);
17
+ let response;
18
+ try {
19
+ response = await fetch(`https://api.github.com/repos/${slug}/releases/latest`, {
20
+ headers: { 'User-Agent': 'Valdi-CLI' },
21
+ });
22
+ }
23
+ catch (error) {
24
+ const message = error instanceof Error ? error.message : String(error);
25
+ throw new Error(`Could not fetch latest release from GitHub (${message}). ${LATEST_RELEASE_HINT}`);
26
+ }
27
+ if (!response.ok) {
28
+ if (response.status === 404) {
29
+ return getLatestReleaseTagFromGit(repoUrl);
30
+ }
31
+ throw new Error(`GitHub API returned ${response.status} (rate limit or server error). ${LATEST_RELEASE_HINT}`);
32
+ }
33
+ const data = (await response.json());
34
+ if (typeof data?.tag_name !== 'string') {
35
+ throw new Error(`Invalid response: missing tag_name. ${LATEST_RELEASE_HINT}`);
36
+ }
37
+ return data.tag_name;
38
+ }
39
+ const SEMVER_TAG_REGEX = /^(?:\w+-)?v?(\d+)\.(\d+)\.(\d+)(?:[-.]\S+)?$/u;
40
+ function parseSemverTag(tag) {
41
+ const m = tag.match(SEMVER_TAG_REGEX);
42
+ if (!m)
43
+ return null;
44
+ return [Number.parseInt(m[1], 10), Number.parseInt(m[2], 10), Number.parseInt(m[3], 10)];
45
+ }
46
+ function compareSemverTags(a, b) {
47
+ const va = parseSemverTag(a);
48
+ const vb = parseSemverTag(b);
49
+ if (va && vb) {
50
+ return va[0] - vb[0] || va[1] - vb[1] || va[2] - vb[2];
51
+ }
52
+ if (va)
53
+ return 1;
54
+ if (vb)
55
+ return -1;
56
+ return a.localeCompare(b, undefined, { numeric: true });
57
+ }
58
+ async function getLatestReleaseTagFromGit(repoUrl) {
59
+ const gitUrl = repoUrl.includes('.git') ? repoUrl : `${repoUrl}.git`;
60
+ const result = await (0, cliUtils_1.runCliCommand)(`git ls-remote --tags --refs ${gitUrl}`, undefined, true);
61
+ const lines = result.stdout.trim().split('\n').filter(Boolean);
62
+ const tags = [];
63
+ for (const line of lines) {
64
+ const ref = line.split(/\s+/)[1];
65
+ if (ref?.startsWith('refs/tags/')) {
66
+ const tag = ref.slice('refs/tags/'.length);
67
+ if (tag)
68
+ tags.push(tag);
69
+ }
70
+ }
71
+ if (tags.length === 0) {
72
+ throw new Error('No tags found in repository');
73
+ }
74
+ tags.sort(compareSemverTags);
75
+ return tags[tags.length - 1];
76
+ }
5
77
  async function resolveLatestReleaseRef(repoUrl) {
6
- const result = await (0, cliUtils_1.runCliCommand)(`git ls-remote --tags --refs ${repoUrl}`, undefined, true);
7
- return result.stdout.trim().split(/\s+/)[1];
78
+ const tag = await getLatestReleaseTagFromGit(repoUrl);
79
+ return tag;
8
80
  }