prpm 0.1.9 → 0.1.11

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.
@@ -10,6 +10,7 @@ const registry_client_1 = require("@pr-pm/registry-client");
10
10
  const user_config_1 = require("../core/user-config");
11
11
  const lockfile_1 = require("../core/lockfile");
12
12
  const telemetry_1 = require("../core/telemetry");
13
+ const errors_1 = require("../core/errors");
13
14
  /**
14
15
  * Check for outdated packages
15
16
  */
@@ -91,8 +92,7 @@ async function handleOutdated() {
91
92
  }
92
93
  catch (err) {
93
94
  error = err instanceof Error ? err.message : String(err);
94
- console.error(`\n❌ Failed to check for updates: ${error}`);
95
- process.exit(1);
95
+ throw new errors_1.CLIError(`\n❌ Failed to check for updates: ${error}`, 1);
96
96
  }
97
97
  finally {
98
98
  await telemetry_1.telemetry.track({
@@ -126,6 +126,5 @@ function createOutdatedCommand() {
126
126
  .description('Check for package updates')
127
127
  .action(async () => {
128
128
  await handleOutdated();
129
- process.exit(0);
130
129
  });
131
130
  }
@@ -42,6 +42,7 @@ const commander_1 = require("commander");
42
42
  const user_config_1 = require("../core/user-config");
43
43
  const telemetry_1 = require("../core/telemetry");
44
44
  const readline = __importStar(require("readline"));
45
+ const errors_1 = require("../core/errors");
45
46
  /**
46
47
  * Create a readline interface for user input
47
48
  */
@@ -252,7 +253,7 @@ async function runSingle(packageName, input, options) {
252
253
  console.log(' - Subscribe to PRPM+: prpm subscribe');
253
254
  console.log(' - Check balance: prpm credits');
254
255
  }
255
- process.exit(1);
256
+ throw new errors_1.CLIError(`\n❌ Error: ${error instanceof Error ? error.message : String(error)}`, 1);
256
257
  }
257
258
  }
258
259
  /**
@@ -269,7 +270,7 @@ async function handlePlayground(packageName, input, options) {
269
270
  console.error('❌ Authentication required');
270
271
  console.log('\n💡 Please login first:');
271
272
  console.log(' prpm login');
272
- process.exit(1);
273
+ throw new errors_1.CLIError('❌ Authentication required', 1);
273
274
  }
274
275
  // Interactive mode or single query
275
276
  if (options.interactive || !input) {
@@ -285,7 +286,7 @@ async function handlePlayground(packageName, input, options) {
285
286
  catch (err) {
286
287
  error = err instanceof Error ? err.message : String(err);
287
288
  console.error(`\n❌ Playground execution failed: ${error}`);
288
- process.exit(1);
289
+ throw new errors_1.CLIError(`\n❌ Playground execution failed: ${error}`, 1);
289
290
  }
290
291
  finally {
291
292
  await telemetry_1.telemetry.track({
@@ -345,7 +346,6 @@ Note: Playground usage requires credits. Run 'prpm credits' to check balance.
345
346
  `)
346
347
  .action(async (packageName, input, options) => {
347
348
  await handlePlayground(packageName, input, options);
348
- process.exit(0);
349
349
  });
350
350
  return command;
351
351
  }
@@ -29,6 +29,5 @@ function createPopularCommand() {
29
29
  .option('--subtype <subtype>', 'Filter by subtype (rule, agent, skill, slash-command, prompt, workflow, tool, template, collection)')
30
30
  .action(async (options) => {
31
31
  await handlePopular(options);
32
- process.exit(0);
33
32
  });
34
33
  }
@@ -47,6 +47,7 @@ const crypto_1 = require("crypto");
47
47
  const registry_client_1 = require("@pr-pm/registry-client");
48
48
  const user_config_1 = require("../core/user-config");
49
49
  const telemetry_1 = require("../core/telemetry");
50
+ const errors_1 = require("../core/errors");
50
51
  const marketplace_converter_1 = require("../core/marketplace-converter");
51
52
  const schema_validator_1 = require("../core/schema-validator");
52
53
  const license_extractor_1 = require("../utils/license-extractor");
@@ -65,6 +66,7 @@ async function findAndLoadManifests() {
65
66
  let prpmJsonError = null;
66
67
  try {
67
68
  const content = await (0, promises_1.readFile)(prpmJsonPath, 'utf-8');
69
+ prpmJsonExists = true; // Mark file as found after successful read
68
70
  const manifest = JSON.parse(content);
69
71
  // Extract collections if present
70
72
  const collections = [];
@@ -254,6 +256,28 @@ function normalizeFilePaths(files) {
254
256
  }
255
257
  });
256
258
  }
259
+ /**
260
+ * Predict what the scoped package name will be after publishing
261
+ * This matches the server-side logic in packages.ts
262
+ */
263
+ function predictScopedPackageName(manifestName, username, organization) {
264
+ const usernameLowercase = username.toLowerCase();
265
+ // If organization is specified, use @org-name/
266
+ if (organization) {
267
+ const orgNameLowercase = organization.toLowerCase();
268
+ const expectedPrefix = `@${orgNameLowercase}/`;
269
+ if (!manifestName.startsWith(expectedPrefix)) {
270
+ return `${expectedPrefix}${manifestName}`;
271
+ }
272
+ return manifestName;
273
+ }
274
+ // If package name doesn't already have a scope, add @username/
275
+ if (!manifestName.startsWith('@')) {
276
+ return `@${usernameLowercase}/${manifestName}`;
277
+ }
278
+ // Package already has a scope, return as-is
279
+ return manifestName;
280
+ }
257
281
  /**
258
282
  * Create tarball from current directory
259
283
  */
@@ -327,8 +351,7 @@ async function handlePublish(options) {
327
351
  const config = await (0, user_config_1.getConfig)();
328
352
  // Check if logged in
329
353
  if (!config.token) {
330
- console.error('❌ Not logged in. Run "prpm login" first.');
331
- process.exit(1);
354
+ throw new errors_1.CLIError('❌ Not logged in. Run "prpm login" first.', 1);
332
355
  }
333
356
  console.log('📦 Publishing package...\n');
334
357
  // Read and validate manifests
@@ -442,6 +465,7 @@ async function handlePublish(options) {
442
465
  console.log('');
443
466
  }
444
467
  let selectedOrgId;
468
+ let selectedOrgName;
445
469
  // Check if organization is specified in manifest
446
470
  if (manifest.organization && userInfo) {
447
471
  const orgFromManifest = userInfo.organizations?.find((org) => org.name === manifest.organization || org.id === manifest.organization);
@@ -454,9 +478,12 @@ async function handlePublish(options) {
454
478
  `Your role: ${orgFromManifest.role}. Required: owner, admin, or maintainer`);
455
479
  }
456
480
  selectedOrgId = orgFromManifest.id;
481
+ selectedOrgName = orgFromManifest.name;
457
482
  }
483
+ // Predict what the scoped package name will be
484
+ const scopedPackageName = predictScopedPackageName(manifest.name, userInfo?.username || config.username || 'unknown', selectedOrgName || manifest.organization);
458
485
  console.log(` Source: ${source}`);
459
- console.log(` Package: ${manifest.name}@${manifest.version}`);
486
+ console.log(` Package: ${scopedPackageName}@${manifest.version}`);
460
487
  console.log(` Format: ${manifest.format} | Subtype: ${manifest.subtype}`);
461
488
  console.log(` Description: ${manifest.description}`);
462
489
  console.log(` Access: ${manifest.private ? 'private' : 'public'}`);
@@ -480,7 +507,7 @@ async function handlePublish(options) {
480
507
  manifest.license_url = licenseInfo.url || undefined;
481
508
  }
482
509
  // Validate and warn about license (optional - will extract if present)
483
- (0, license_extractor_1.validateLicenseInfo)(licenseInfo, manifest.name);
510
+ (0, license_extractor_1.validateLicenseInfo)(licenseInfo, scopedPackageName);
484
511
  console.log('');
485
512
  // Extract content snippet
486
513
  console.log('📝 Extracting content snippet...');
@@ -488,7 +515,7 @@ async function handlePublish(options) {
488
515
  if (snippet) {
489
516
  manifest.snippet = snippet;
490
517
  }
491
- (0, snippet_extractor_1.validateSnippet)(snippet, manifest.name);
518
+ (0, snippet_extractor_1.validateSnippet)(snippet, scopedPackageName);
492
519
  console.log('');
493
520
  // Create tarball
494
521
  console.log('📦 Creating package tarball...');
@@ -509,7 +536,7 @@ async function handlePublish(options) {
509
536
  if (options.dryRun) {
510
537
  console.log('✅ Dry run successful! Package is ready to publish.');
511
538
  publishedPackages.push({
512
- name: manifest.name,
539
+ name: scopedPackageName,
513
540
  version: manifest.version,
514
541
  url: ''
515
542
  });
@@ -537,7 +564,8 @@ async function handlePublish(options) {
537
564
  // Default to registry URL for unknown environments
538
565
  webappUrl = registryUrl;
539
566
  }
540
- const packageUrl = `${webappUrl}/packages/${encodeURIComponent(manifest.name)}`;
567
+ // Use the name returned from the API (which includes auto-prefixed scope)
568
+ const packageUrl = `${webappUrl}/packages/${encodeURIComponent(result.name)}`;
541
569
  console.log('');
542
570
  console.log('✅ Package published successfully!');
543
571
  console.log('');
@@ -545,16 +573,20 @@ async function handlePublish(options) {
545
573
  console.log(` Install: prpm install ${result.name}`);
546
574
  console.log('');
547
575
  publishedPackages.push({
548
- name: manifest.name,
576
+ name: result.name, // Use scoped name from server
549
577
  version: result.version,
550
578
  url: packageUrl
551
579
  });
552
580
  }
553
581
  catch (err) {
554
582
  const pkgError = err instanceof Error ? err.message : String(err);
555
- console.error(`\n❌ Failed to publish ${manifest.name}: ${pkgError}\n`);
583
+ // Try to use scoped name if we have user info, otherwise fall back to manifest name
584
+ const displayName = userInfo
585
+ ? predictScopedPackageName(manifest.name, userInfo.username, manifest.organization)
586
+ : manifest.name;
587
+ console.error(`\n❌ Failed to publish ${displayName}: ${pkgError}\n`);
556
588
  failedPackages.push({
557
- name: manifest.name,
589
+ name: displayName,
558
590
  error: pkgError
559
591
  });
560
592
  }
@@ -681,41 +713,41 @@ async function handlePublish(options) {
681
713
  // Success if we published any packages OR collections
682
714
  success = publishedPackages.length > 0 || publishedCollections.length > 0;
683
715
  if (failedPackages.length > 0 && publishedPackages.length === 0 && publishedCollections.length === 0) {
684
- process.exit(1);
716
+ // Use the first failed package's error for telemetry
717
+ const firstError = failedPackages[0]?.error || 'Unknown error';
718
+ throw new errors_1.CLIError(firstError, 1);
685
719
  }
686
720
  }
687
721
  catch (err) {
688
722
  error = err instanceof Error ? err.message : String(err);
689
- console.error(`\n❌ Failed to publish package: ${error}\n`);
723
+ if (err instanceof errors_1.CLIError) {
724
+ throw err;
725
+ }
726
+ let errorMsg = `\n❌ Failed to publish package: ${error}\n`;
690
727
  // Provide helpful hints based on error type
691
728
  if (error.includes('Manifest validation failed')) {
692
- console.log('💡 Common validation issues:');
693
- console.log(' - Missing required fields (name, version, description, format)');
694
- console.log(' - Invalid format or subtype values');
695
- console.log(' - Description too short (min 10 chars) or too long (max 500 chars)');
696
- console.log(' - Package name must be lowercase with hyphens only');
697
- console.log('');
698
- console.log('💡 For Claude skills specifically:');
699
- console.log(' - Add "subtype": "skill" to your prpm.json');
700
- console.log(' - Ensure files include a SKILL.md file');
701
- console.log(' - Package name must be max 64 characters');
702
- console.log('');
703
- console.log('💡 View the schema: prpm schema');
704
- console.log('');
729
+ errorMsg += '\n💡 Common validation issues:\n';
730
+ errorMsg += ' - Missing required fields (name, version, description, format)\n';
731
+ errorMsg += ' - Invalid format or subtype values\n';
732
+ errorMsg += ' - Description too short (min 10 chars) or too long (max 500 chars)\n';
733
+ errorMsg += ' - Package name must be lowercase with hyphens only\n';
734
+ errorMsg += '\n💡 For Claude skills specifically:\n';
735
+ errorMsg += ' - Add "subtype": "skill" to your prpm.json\n';
736
+ errorMsg += ' - Ensure files include a SKILL.md file\n';
737
+ errorMsg += ' - Package name must be max 64 characters\n';
738
+ errorMsg += '\n💡 View the schema: prpm schema\n';
705
739
  }
706
740
  else if (error.includes('SKILL.md')) {
707
- console.log('💡 Claude skills require:');
708
- console.log(' - A file named SKILL.md (all caps) in your package');
709
- console.log(' - "format": "claude" and "subtype": "skill" in prpm.json');
710
- console.log('');
741
+ errorMsg += '\n💡 Claude skills require:\n';
742
+ errorMsg += ' - A file named SKILL.md (all caps) in your package\n';
743
+ errorMsg += ' - "format": "claude" and "subtype": "skill" in prpm.json\n';
711
744
  }
712
745
  else if (error.includes('No manifest file found')) {
713
- console.log('💡 Create a manifest file:');
714
- console.log(' - Run: prpm init');
715
- console.log(' - Or create prpm.json manually');
716
- console.log('');
746
+ errorMsg += '\n💡 Create a manifest file:\n';
747
+ errorMsg += ' - Run: prpm init\n';
748
+ errorMsg += ' - Or create prpm.json manually\n';
717
749
  }
718
- process.exit(1);
750
+ throw new errors_1.CLIError(errorMsg, 1);
719
751
  }
720
752
  finally {
721
753
  // Track telemetry
@@ -746,6 +778,5 @@ function createPublishCommand() {
746
778
  .option('--collection <id>', 'Publish only a specific collection from manifest')
747
779
  .action(async (options) => {
748
780
  await handlePublish(options);
749
- process.exit(0);
750
781
  });
751
782
  }
@@ -7,6 +7,7 @@ exports.handleSchema = handleSchema;
7
7
  exports.createSchemaCommand = createSchemaCommand;
8
8
  const commander_1 = require("commander");
9
9
  const schema_validator_1 = require("../core/schema-validator");
10
+ const errors_1 = require("../core/errors");
10
11
  /**
11
12
  * Handle the schema command
12
13
  */
@@ -14,15 +15,16 @@ async function handleSchema() {
14
15
  try {
15
16
  const schema = (0, schema_validator_1.getManifestSchema)();
16
17
  if (!schema) {
17
- console.error('❌ Schema not available');
18
- process.exit(1);
18
+ throw new errors_1.CLIError('❌ Schema not available', 1);
19
19
  }
20
20
  // Output the schema as pretty-printed JSON
21
21
  console.log(JSON.stringify(schema, null, 2));
22
22
  }
23
23
  catch (error) {
24
- console.error(`❌ Failed to export schema: ${error}`);
25
- process.exit(1);
24
+ if (error instanceof errors_1.CLIError) {
25
+ throw error;
26
+ }
27
+ throw new errors_1.CLIError(`❌ Failed to export schema: ${error}`, 1);
26
28
  }
27
29
  }
28
30
  /**
@@ -34,7 +36,6 @@ function createSchemaCommand() {
34
36
  .description('Display the PRPM manifest JSON schema')
35
37
  .action(async () => {
36
38
  await handleSchema();
37
- process.exit(0);
38
39
  });
39
40
  return command;
40
41
  }
@@ -43,6 +43,7 @@ const registry_client_1 = require("@pr-pm/registry-client");
43
43
  const user_config_1 = require("../core/user-config");
44
44
  const telemetry_1 = require("../core/telemetry");
45
45
  const readline = __importStar(require("readline"));
46
+ const errors_1 = require("../core/errors");
46
47
  /**
47
48
  * Get icon for package format and subtype
48
49
  */
@@ -377,7 +378,7 @@ async function handleSearch(query, options) {
377
378
  console.log(`\n💡 Tip: You're using a local registry. Make sure it's running or update ~/.prpmrc`);
378
379
  console.log(` To use the production registry, remove the registryUrl from ~/.prpmrc`);
379
380
  }
380
- process.exit(1);
381
+ throw new errors_1.CLIError(`\n❌ Search failed: ${error}`, 1);
381
382
  }
382
383
  finally {
383
384
  await telemetry_1.telemetry.track({
@@ -424,7 +425,7 @@ function createSearchCommand() {
424
425
  const validSubtypes = ['rule', 'agent', 'skill', 'slash-command', 'prompt', 'collection', 'chatmode'];
425
426
  if (options.format && !validFormats.includes(format)) {
426
427
  console.error(`❌ Format must be one of: ${validFormats.join(', ')}`);
427
- process.exit(1);
428
+ throw new errors_1.CLIError(`❌ Format must be one of: ${validFormats.join(', ')}`, 1);
428
429
  }
429
430
  if (options.subtype && !validSubtypes.includes(subtype)) {
430
431
  console.error(`❌ Subtype must be one of: ${validSubtypes.join(', ')}`);
@@ -437,10 +438,9 @@ function createSearchCommand() {
437
438
  console.log(` prpm search --subtype skill # List all skills`);
438
439
  console.log(` prpm search --format claude # List all Claude packages`);
439
440
  console.log(` prpm search --author prpm # List packages by @prpm`);
440
- process.exit(1);
441
+ throw new errors_1.CLIError(`❌ Subtype must be one of: ${validSubtypes.join(', ')}`, 1);
441
442
  }
442
443
  await handleSearch(query || '', { format, subtype, author, language: options.language, framework: options.framework, limit, page, interactive: options.interactive });
443
- process.exit(0);
444
444
  });
445
445
  return command;
446
446
  }
@@ -11,6 +11,7 @@ const telemetry_1 = require("../core/telemetry");
11
11
  const child_process_1 = require("child_process");
12
12
  const util_1 = require("util");
13
13
  const webapp_url_1 = require("../utils/webapp-url");
14
+ const errors_1 = require("../core/errors");
14
15
  const execAsync = (0, util_1.promisify)(child_process_1.exec);
15
16
  /**
16
17
  * Make authenticated API call
@@ -102,7 +103,7 @@ async function handleSubscribe() {
102
103
  console.error('❌ Authentication required');
103
104
  console.log('\n💡 Please login first:');
104
105
  console.log(' prpm login');
105
- process.exit(1);
106
+ throw new errors_1.CLIError('❌ Authentication required', 1);
106
107
  }
107
108
  // Get current status
108
109
  console.log('🔍 Checking current subscription status...');
@@ -115,7 +116,7 @@ async function handleSubscribe() {
115
116
  console.log(` 🚀 Early access to new features`);
116
117
  console.log('\n💡 Manage your subscription at:');
117
118
  console.log(' https://prpm.dev/settings/billing');
118
- process.exit(0);
119
+ return;
119
120
  }
120
121
  console.log('\n✨ Subscribe to PRPM+ and get:');
121
122
  console.log(' 💰 100 monthly playground credits');
@@ -154,7 +155,7 @@ async function handleSubscribe() {
154
155
  catch (err) {
155
156
  error = err instanceof Error ? err.message : String(err);
156
157
  console.error(`\n❌ Subscription failed: ${error}`);
157
- process.exit(1);
158
+ throw new errors_1.CLIError(`\n❌ Subscription failed: ${error}`, 1);
158
159
  }
159
160
  finally {
160
161
  await telemetry_1.telemetry.track({
@@ -205,7 +206,6 @@ Note: You can cancel anytime from https://prpm.dev/settings/billing
205
206
  `)
206
207
  .action(async () => {
207
208
  await handleSubscribe();
208
- process.exit(0);
209
209
  });
210
210
  return command;
211
211
  }
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createTelemetryCommand = createTelemetryCommand;
4
4
  const commander_1 = require("commander");
5
5
  const telemetry_1 = require("../core/telemetry");
6
+ const errors_1 = require("../core/errors");
6
7
  function createTelemetryCommand() {
7
8
  return new commander_1.Command('telemetry')
8
9
  .description('Manage telemetry and analytics settings')
@@ -16,7 +17,7 @@ function createStatusCommand() {
16
17
  return new commander_1.Command('status')
17
18
  .description('Show current telemetry status')
18
19
  .action(async () => {
19
- const enabled = telemetry_1.telemetry.isEnabled();
20
+ const enabled = await telemetry_1.telemetry.isEnabled();
20
21
  const stats = await telemetry_1.telemetry.getStats();
21
22
  console.log('📊 Telemetry Status:');
22
23
  console.log(` Status: ${enabled ? '✅ Enabled' : '❌ Disabled'}`);
@@ -33,7 +34,6 @@ function createStatusCommand() {
33
34
  else {
34
35
  console.log('\n💡 Telemetry is disabled. Run "prpm telemetry enable" to help improve the tool.');
35
36
  }
36
- process.exit(0);
37
37
  });
38
38
  }
39
39
  function createEnableCommand() {
@@ -43,7 +43,6 @@ function createEnableCommand() {
43
43
  await telemetry_1.telemetry.enable();
44
44
  console.log('✅ Telemetry enabled');
45
45
  console.log('📊 Anonymous usage data will be collected to help improve the tool.');
46
- process.exit(0);
47
46
  });
48
47
  }
49
48
  function createDisableCommand() {
@@ -53,7 +52,6 @@ function createDisableCommand() {
53
52
  await telemetry_1.telemetry.disable();
54
53
  console.log('❌ Telemetry disabled');
55
54
  console.log('📊 No usage data will be collected.');
56
- process.exit(0);
57
55
  });
58
56
  }
59
57
  function createStatsCommand() {
@@ -66,7 +64,6 @@ function createStatsCommand() {
66
64
  if (stats.lastEvent) {
67
65
  console.log(` Last event: ${stats.lastEvent}`);
68
66
  }
69
- process.exit(0);
70
67
  });
71
68
  }
72
69
  function createTestCommand() {
@@ -101,9 +98,7 @@ function createTestCommand() {
101
98
  console.log('4. Events may take 1-2 minutes to appear');
102
99
  }
103
100
  catch (error) {
104
- console.error('❌ Failed to send test event:', error);
105
- process.exit(1);
101
+ throw new errors_1.CLIError(`❌ Failed to send test event: ${error}`, 1);
106
102
  }
107
- process.exit(0);
108
103
  });
109
104
  }
@@ -9,6 +9,7 @@ const commander_1 = require("commander");
9
9
  const registry_client_1 = require("@pr-pm/registry-client");
10
10
  const user_config_1 = require("../core/user-config");
11
11
  const telemetry_1 = require("../core/telemetry");
12
+ const errors_1 = require("../core/errors");
12
13
  async function handleTrending(options) {
13
14
  const startTime = Date.now();
14
15
  let success = false;
@@ -41,7 +42,7 @@ async function handleTrending(options) {
41
42
  error = err instanceof Error ? err.message : String(err);
42
43
  console.error(`\n❌ Failed to fetch trending packages: ${error}`);
43
44
  console.log(`\n💡 Tip: Check your internet connection`);
44
- process.exit(1);
45
+ throw new errors_1.CLIError(`\n❌ Failed to fetch trending packages: ${error}`, 1);
45
46
  }
46
47
  finally {
47
48
  await telemetry_1.telemetry.track({
@@ -73,14 +74,13 @@ function createTrendingCommand() {
73
74
  const validSubtypes = ['rule', 'agent', 'skill', 'slash-command', 'prompt', 'workflow', 'tool', 'template', 'collection'];
74
75
  if (options.format && !validFormats.includes(format)) {
75
76
  console.error(`❌ Format must be one of: ${validFormats.join(', ')}`);
76
- process.exit(1);
77
+ throw new errors_1.CLIError(`❌ Format must be one of: ${validFormats.join(', ')}`, 1);
77
78
  }
78
79
  if (options.subtype && !validSubtypes.includes(subtype)) {
79
80
  console.error(`❌ Subtype must be one of: ${validSubtypes.join(', ')}`);
80
- process.exit(1);
81
+ throw new errors_1.CLIError(`❌ Subtype must be one of: ${validSubtypes.join(', ')}`, 1);
81
82
  }
82
83
  await handleTrending({ format, subtype, limit });
83
- process.exit(0);
84
84
  });
85
85
  return command;
86
86
  }
@@ -9,6 +9,7 @@ const commander_1 = require("commander");
9
9
  const lockfile_1 = require("../core/lockfile");
10
10
  const filesystem_1 = require("../core/filesystem");
11
11
  const fs_1 = require("fs");
12
+ const errors_1 = require("../core/errors");
12
13
  /**
13
14
  * Handle the uninstall command
14
15
  */
@@ -18,8 +19,7 @@ async function handleUninstall(name) {
18
19
  // Remove from lockfile and get package info
19
20
  const pkg = await (0, lockfile_1.removePackage)(name);
20
21
  if (!pkg) {
21
- console.error(`❌ Package "${name}" not found`);
22
- process.exit(1);
22
+ throw new errors_1.CLIError(`❌ Package "${name}" not found`, 1);
23
23
  }
24
24
  // Get destination directory using format and subtype
25
25
  const format = pkg.format || 'generic';
@@ -75,11 +75,12 @@ async function handleUninstall(name) {
75
75
  }
76
76
  }
77
77
  console.log(`✅ Successfully uninstalled ${name}`);
78
- process.exit(0);
79
78
  }
80
79
  catch (error) {
81
- console.error(`❌ Failed to uninstall package: ${error}`);
82
- process.exit(1);
80
+ if (error instanceof errors_1.CLIError) {
81
+ throw error;
82
+ }
83
+ throw new errors_1.CLIError(`❌ Failed to uninstall package: ${error}`, 1);
83
84
  }
84
85
  }
85
86
  /**
@@ -11,6 +11,7 @@ const user_config_1 = require("../core/user-config");
11
11
  const lockfile_1 = require("../core/lockfile");
12
12
  const install_1 = require("./install");
13
13
  const telemetry_1 = require("../core/telemetry");
14
+ const errors_1 = require("../core/errors");
14
15
  /**
15
16
  * Update packages to latest minor/patch versions
16
17
  */
@@ -76,8 +77,7 @@ async function handleUpdate(packageName, options = {}) {
76
77
  }
77
78
  catch (err) {
78
79
  error = err instanceof Error ? err.message : String(err);
79
- console.error(`\n❌ Update failed: ${error}`);
80
- process.exit(1);
80
+ throw new errors_1.CLIError(`\n❌ Update failed: ${error}`, 1);
81
81
  }
82
82
  finally {
83
83
  await telemetry_1.telemetry.track({
@@ -117,6 +117,5 @@ function createUpdateCommand() {
117
117
  .option('--all', 'Update all packages')
118
118
  .action(async (packageName, options) => {
119
119
  await handleUpdate(packageName, options);
120
- process.exit(0);
121
120
  });
122
121
  }
@@ -11,6 +11,7 @@ const user_config_1 = require("../core/user-config");
11
11
  const lockfile_1 = require("../core/lockfile");
12
12
  const install_1 = require("./install");
13
13
  const telemetry_1 = require("../core/telemetry");
14
+ const errors_1 = require("../core/errors");
14
15
  /**
15
16
  * Upgrade packages to latest versions (including major updates)
16
17
  */
@@ -75,8 +76,7 @@ async function handleUpgrade(packageName, options = {}) {
75
76
  }
76
77
  catch (err) {
77
78
  error = err instanceof Error ? err.message : String(err);
78
- console.error(`\n❌ Upgrade failed: ${error}`);
79
- process.exit(1);
79
+ throw new errors_1.CLIError(`\n❌ Upgrade failed: ${error}`, 1);
80
80
  }
81
81
  finally {
82
82
  await telemetry_1.telemetry.track({
@@ -117,6 +117,5 @@ function createUpgradeCommand() {
117
117
  .option('--force', 'Skip warning for major version upgrades')
118
118
  .action(async (packageName, options) => {
119
119
  await handleUpgrade(packageName, options);
120
- process.exit(0);
121
120
  });
122
121
  }
@@ -9,6 +9,7 @@ const commander_1 = require("commander");
9
9
  const user_config_1 = require("../core/user-config");
10
10
  const registry_client_1 = require("@pr-pm/registry-client");
11
11
  const telemetry_1 = require("../core/telemetry");
12
+ const errors_1 = require("../core/errors");
12
13
  /**
13
14
  * Show current logged-in user
14
15
  */
@@ -57,8 +58,7 @@ async function handleWhoami() {
57
58
  }
58
59
  catch (err) {
59
60
  error = err instanceof Error ? err.message : String(err);
60
- console.error(`❌ Error: ${error}`);
61
- process.exit(1);
61
+ throw new errors_1.CLIError(`❌ Error: ${error}`, 1);
62
62
  }
63
63
  finally {
64
64
  // Track telemetry
@@ -79,6 +79,5 @@ function createWhoamiCommand() {
79
79
  .description('Show current logged-in user')
80
80
  .action(async () => {
81
81
  await handleWhoami();
82
- process.exit(0);
83
82
  });
84
83
  }
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CLIError = void 0;
4
+ exports.createError = createError;
5
+ exports.createSuccess = createSuccess;
6
+ /**
7
+ * Custom error class for CLI commands
8
+ * Allows commands to throw errors with exit codes instead of calling process.exit()
9
+ */
10
+ class CLIError extends Error {
11
+ constructor(message, exitCode = 1) {
12
+ super(message);
13
+ this.name = 'CLIError';
14
+ this.exitCode = exitCode;
15
+ }
16
+ }
17
+ exports.CLIError = CLIError;
18
+ /**
19
+ * Creates a CLIError with exit code 1 (general error)
20
+ */
21
+ function createError(message) {
22
+ return new CLIError(message, 1);
23
+ }
24
+ /**
25
+ * Creates a CLIError with exit code 0 (success, used for early termination)
26
+ */
27
+ function createSuccess(message) {
28
+ return new CLIError(message || '', 0);
29
+ }