@larkup/marketplace 0.1.14 → 0.1.16

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.16
4
+
5
+ ### Patch Changes
6
+
7
+ - 5da7a99: Replace deprecated fluent-ffmpeg with direct child_process.spawn calls. Eliminates npm deprecation warnings for fluent-ffmpeg and node-domexception. Increases auto-install timeout to 5min for large dependencies like ffmpeg.
8
+
9
+ ## 0.1.15
10
+
11
+ ### Patch Changes
12
+
13
+ - 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.
14
+
3
15
  ## 0.1.14
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.14",
3
+ "version": "0.1.16",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -132,6 +132,115 @@ 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} via "${installCmd}"…`);
199
+ try {
200
+ await execAsync(installCmd, { timeout: 300_000 });
201
+ onProgress?.(`${dep} installation command finished.`);
202
+ } catch (err: unknown) {
203
+ const message = err instanceof Error ? err.message : String(err);
204
+ onProgress?.(`Auto-install of ${dep} failed: ${message}`);
205
+ return false;
206
+ }
207
+
208
+ // Verify the binary is now available
209
+ try {
210
+ await execAsync(`which ${dep}`);
211
+ return true;
212
+ } catch {
213
+ return false;
214
+ }
215
+ }
216
+
217
+ /**
218
+ * Build a user-friendly error message with platform-specific install instructions.
219
+ */
220
+ function buildMissingDepsMessage(deps: string[]): string {
221
+ const platform = detectPlatform();
222
+ const lines: string[] = [`Missing system dependencies: ${deps.join(', ')}.`];
223
+
224
+ for (const dep of deps) {
225
+ const hints = INSTALL_HINTS[dep];
226
+ if (!hints) {
227
+ lines.push(` • ${dep}: Please install it manually.`);
228
+ continue;
229
+ }
230
+
231
+ if (platform === 'macos' && hints.macos) {
232
+ lines.push(` • ${dep}: Run \`${hints.macos}\``);
233
+ } else if (platform === 'linux') {
234
+ const linuxHint = hints.linux_apt || hints.linux_dnf || hints.linux_pacman || hints.linux_apk;
235
+ if (linuxHint) {
236
+ lines.push(` • ${dep}: Run \`${linuxHint}\``);
237
+ }
238
+ }
239
+ }
240
+
241
+ return lines.join('\n');
242
+ }
243
+
135
244
  /**
136
245
  * Check if system dependencies for a tool are available.
137
246
  * Returns list of missing dependencies.
@@ -406,9 +515,25 @@ export async function installTool(
406
515
 
407
516
  // 2. Check system dependencies
408
517
  report('checking-deps', 15, 'Checking system dependencies…');
409
- const missing = (await checkSystemDeps(toolId)).filter((dependency) => dependency !== 'docker');
518
+ let missing = (await checkSystemDeps(toolId)).filter((dependency) => dependency !== 'docker');
519
+
520
+ // 2a. Attempt auto-install for known dependencies
521
+ if (missing.length > 0) {
522
+ const stillMissing: string[] = [];
523
+ for (const dep of missing) {
524
+ report('checking-deps', 18, `Attempting to install ${dep}…`);
525
+ const installed = await tryAutoInstallDep(dep, (msg) => report('checking-deps', 20, msg));
526
+ if (installed) {
527
+ report('checking-deps', 22, `${dep} installed successfully.`);
528
+ } else {
529
+ stillMissing.push(dep);
530
+ }
531
+ }
532
+ missing = stillMissing;
533
+ }
534
+
410
535
  if (missing.length > 0) {
411
- const msg = `Missing system dependencies: ${missing.join(', ')}. Please install them first.`;
536
+ const msg = buildMissingDepsMessage(missing);
412
537
  report('failed', 0, msg);
413
538
  throw new Error(msg);
414
539
  }