@larkup/marketplace 0.1.13 → 0.1.15

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @larkup/marketplace
2
2
 
3
+ ## 0.1.15
4
+
5
+ ### Patch Changes
6
+
7
+ - f23cba6: Auto-install missing system dependencies (e.g. ffmpeg) during tool installation using the platform package manager (brew on macOS, apt/dnf/pacman/apk on Linux). Falls back to actionable error messages with the exact install command when auto-install is not possible.
8
+
9
+ ## 0.1.14
10
+
11
+ ### Patch Changes
12
+
13
+ - @larkup/core@0.3.1
14
+
3
15
  ## 0.1.13
4
16
 
5
17
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@larkup/marketplace",
3
- "version": "0.1.13",
3
+ "version": "0.1.15",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -14,7 +14,7 @@
14
14
  "./manifest": "./src/tool-manifest.schema.ts"
15
15
  },
16
16
  "dependencies": {
17
- "@larkup/core": "0.3.0"
17
+ "@larkup/core": "0.3.1"
18
18
  },
19
19
  "devDependencies": {
20
20
  "@types/node": "^24",
@@ -132,6 +132,112 @@ export async function getDownloadCounts(): Promise<Record<string, number>> {
132
132
  /* System dependency checks */
133
133
  /* ------------------------------------------------------------------ */
134
134
 
135
+ /** Known install commands per dependency per platform. */
136
+ const INSTALL_HINTS: Record<string, Record<string, string>> = {
137
+ ffmpeg: {
138
+ macos: 'brew install ffmpeg',
139
+ linux_apt: 'sudo apt-get install -y ffmpeg',
140
+ linux_dnf: 'sudo dnf install -y ffmpeg',
141
+ linux_pacman: 'sudo pacman -S --noconfirm ffmpeg',
142
+ linux_apk: 'sudo apk add --no-cache ffmpeg',
143
+ },
144
+ };
145
+
146
+ /**
147
+ * Detect the current platform for install commands.
148
+ */
149
+ function detectPlatform(): string {
150
+ if (process.platform === 'darwin') return 'macos';
151
+ return 'linux';
152
+ }
153
+
154
+ /**
155
+ * Attempt to auto-install a system dependency using the platform package manager.
156
+ * Returns true if the dependency is available after the attempt.
157
+ */
158
+ async function tryAutoInstallDep(
159
+ dep: string,
160
+ onProgress?: (message: string) => void,
161
+ ): Promise<boolean> {
162
+ const hints = INSTALL_HINTS[dep];
163
+ if (!hints) return false;
164
+
165
+ const platform = detectPlatform();
166
+ let installCmd: string | undefined;
167
+
168
+ if (platform === 'macos') {
169
+ // Check if Homebrew is available
170
+ try {
171
+ await execAsync('which brew');
172
+ installCmd = hints.macos;
173
+ } catch {
174
+ // No brew — cannot auto-install on macOS
175
+ return false;
176
+ }
177
+ } else {
178
+ // Linux — detect package manager
179
+ const managers = [
180
+ { cmd: 'apt-get', key: 'linux_apt' },
181
+ { cmd: 'dnf', key: 'linux_dnf' },
182
+ { cmd: 'pacman', key: 'linux_pacman' },
183
+ { cmd: 'apk', key: 'linux_apk' },
184
+ ];
185
+ for (const { cmd, key } of managers) {
186
+ try {
187
+ await execAsync(`which ${cmd}`);
188
+ installCmd = hints[key];
189
+ break;
190
+ } catch {
191
+ // Try next manager
192
+ }
193
+ }
194
+ }
195
+
196
+ if (!installCmd) return false;
197
+
198
+ onProgress?.(`Auto-installing ${dep}…`);
199
+ try {
200
+ await execAsync(installCmd, { timeout: 120_000 });
201
+ } catch {
202
+ return false;
203
+ }
204
+
205
+ // Verify the binary is now available
206
+ try {
207
+ await execAsync(`which ${dep}`);
208
+ return true;
209
+ } catch {
210
+ return false;
211
+ }
212
+ }
213
+
214
+ /**
215
+ * Build a user-friendly error message with platform-specific install instructions.
216
+ */
217
+ function buildMissingDepsMessage(deps: string[]): string {
218
+ const platform = detectPlatform();
219
+ const lines: string[] = [`Missing system dependencies: ${deps.join(', ')}.`];
220
+
221
+ for (const dep of deps) {
222
+ const hints = INSTALL_HINTS[dep];
223
+ if (!hints) {
224
+ lines.push(` • ${dep}: Please install it manually.`);
225
+ continue;
226
+ }
227
+
228
+ if (platform === 'macos' && hints.macos) {
229
+ lines.push(` • ${dep}: Run \`${hints.macos}\``);
230
+ } else if (platform === 'linux') {
231
+ const linuxHint = hints.linux_apt || hints.linux_dnf || hints.linux_pacman || hints.linux_apk;
232
+ if (linuxHint) {
233
+ lines.push(` • ${dep}: Run \`${linuxHint}\``);
234
+ }
235
+ }
236
+ }
237
+
238
+ return lines.join('\n');
239
+ }
240
+
135
241
  /**
136
242
  * Check if system dependencies for a tool are available.
137
243
  * Returns list of missing dependencies.
@@ -406,9 +512,25 @@ export async function installTool(
406
512
 
407
513
  // 2. Check system dependencies
408
514
  report('checking-deps', 15, 'Checking system dependencies…');
409
- const missing = (await checkSystemDeps(toolId)).filter((dependency) => dependency !== 'docker');
515
+ let missing = (await checkSystemDeps(toolId)).filter((dependency) => dependency !== 'docker');
516
+
517
+ // 2a. Attempt auto-install for known dependencies
518
+ if (missing.length > 0) {
519
+ const stillMissing: string[] = [];
520
+ for (const dep of missing) {
521
+ report('checking-deps', 18, `Attempting to install ${dep}…`);
522
+ const installed = await tryAutoInstallDep(dep, (msg) => report('checking-deps', 20, msg));
523
+ if (installed) {
524
+ report('checking-deps', 22, `${dep} installed successfully.`);
525
+ } else {
526
+ stillMissing.push(dep);
527
+ }
528
+ }
529
+ missing = stillMissing;
530
+ }
531
+
410
532
  if (missing.length > 0) {
411
- const msg = `Missing system dependencies: ${missing.join(', ')}. Please install them first.`;
533
+ const msg = buildMissingDepsMessage(missing);
412
534
  report('failed', 0, msg);
413
535
  throw new Error(msg);
414
536
  }