imcp 0.1.1 → 0.1.3

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 (111) hide show
  1. package/dist/cli/index.js +1 -45
  2. package/dist/core/installers/clients/BaseClientInstaller.d.ts +1 -5
  3. package/dist/core/installers/clients/BaseClientInstaller.js +40 -38
  4. package/dist/core/installers/clients/ClientInstaller.d.ts +9 -9
  5. package/dist/core/installers/clients/ClientInstaller.js +105 -99
  6. package/dist/core/installers/requirements/BaseInstaller.d.ts +9 -1
  7. package/dist/core/installers/requirements/CommandInstaller.d.ts +9 -1
  8. package/dist/core/installers/requirements/CommandInstaller.js +46 -12
  9. package/dist/core/installers/requirements/GeneralInstaller.d.ts +11 -1
  10. package/dist/core/installers/requirements/GeneralInstaller.js +46 -10
  11. package/dist/core/installers/requirements/InstallerFactory.d.ts +3 -1
  12. package/dist/core/installers/requirements/InstallerFactory.js +3 -2
  13. package/dist/core/installers/requirements/NpmInstaller.d.ts +4 -2
  14. package/dist/core/installers/requirements/NpmInstaller.js +38 -22
  15. package/dist/core/installers/requirements/PipInstaller.d.ts +3 -1
  16. package/dist/core/installers/requirements/PipInstaller.js +58 -36
  17. package/dist/core/installers/requirements/RequirementInstaller.d.ts +4 -1
  18. package/dist/core/loaders/InstallOperationManager.d.ts +115 -0
  19. package/dist/core/loaders/InstallOperationManager.js +311 -0
  20. package/dist/core/loaders/SystemSettingsManager.d.ts +54 -0
  21. package/dist/core/loaders/SystemSettingsManager.js +257 -0
  22. package/dist/core/metadatas/recordingConstants.d.ts +44 -0
  23. package/dist/core/metadatas/recordingConstants.js +45 -0
  24. package/dist/core/metadatas/types.d.ts +21 -0
  25. package/dist/core/onboard/InstallOperationManager.d.ts +23 -0
  26. package/dist/core/onboard/InstallOperationManager.js +144 -0
  27. package/dist/core/onboard/OnboardStatusManager.js +2 -1
  28. package/dist/core/validators/StdioServerValidator.js +4 -3
  29. package/dist/services/InstallationService.d.ts +2 -37
  30. package/dist/services/InstallationService.js +45 -313
  31. package/dist/services/MCPManager.d.ts +1 -1
  32. package/dist/services/MCPManager.js +4 -58
  33. package/dist/services/RequirementService.d.ts +85 -12
  34. package/dist/services/RequirementService.js +488 -49
  35. package/dist/services/ServerService.d.ts +0 -6
  36. package/dist/services/ServerService.js +0 -74
  37. package/dist/utils/adoUtils.js +6 -3
  38. package/dist/utils/logger.js +1 -1
  39. package/dist/utils/macroExpressionUtils.js +3 -25
  40. package/dist/utils/osUtils.d.ts +22 -1
  41. package/dist/utils/osUtils.js +92 -1
  42. package/dist/utils/versionUtils.d.ts +20 -1
  43. package/dist/utils/versionUtils.js +51 -4
  44. package/dist/web/public/css/modal.css +292 -1
  45. package/dist/web/public/css/serverDetails.css +14 -1
  46. package/dist/web/public/index.html +122 -20
  47. package/dist/web/public/js/flights/flights.js +1 -0
  48. package/dist/web/public/js/modal/index.js +8 -14
  49. package/dist/web/public/js/modal/installModal.js +3 -4
  50. package/dist/web/public/js/modal/installation.js +122 -137
  51. package/dist/web/public/js/modal/loadingModal.js +155 -25
  52. package/dist/web/public/js/modal/messageQueue.js +45 -101
  53. package/dist/web/public/js/modal/modalSetup.js +125 -43
  54. package/dist/web/public/js/modal/modalUtils.js +0 -12
  55. package/dist/web/public/js/modal.js +23 -10
  56. package/dist/web/public/js/onboard/publishHandler.js +22 -20
  57. package/dist/web/public/js/serverCategoryDetails.js +60 -11
  58. package/dist/web/public/js/serverCategoryList.js +2 -2
  59. package/dist/web/public/js/settings.js +314 -0
  60. package/dist/web/public/settings.html +135 -0
  61. package/dist/web/public/styles.css +32 -0
  62. package/dist/web/server.js +82 -0
  63. package/memory-bank/activeContext.md +13 -1
  64. package/memory-bank/decisionLog.md +63 -0
  65. package/memory-bank/progress.md +30 -0
  66. package/memory-bank/systemPatterns.md +7 -0
  67. package/package.json +1 -1
  68. package/src/cli/index.ts +1 -48
  69. package/src/core/installers/clients/BaseClientInstaller.ts +64 -50
  70. package/src/core/installers/clients/ClientInstaller.ts +130 -130
  71. package/src/core/installers/requirements/BaseInstaller.ts +9 -1
  72. package/src/core/installers/requirements/CommandInstaller.ts +47 -13
  73. package/src/core/installers/requirements/GeneralInstaller.ts +48 -10
  74. package/src/core/installers/requirements/InstallerFactory.ts +4 -3
  75. package/src/core/installers/requirements/NpmInstaller.ts +90 -68
  76. package/src/core/installers/requirements/PipInstaller.ts +81 -55
  77. package/src/core/installers/requirements/RequirementInstaller.ts +4 -3
  78. package/src/core/loaders/InstallOperationManager.ts +367 -0
  79. package/src/core/loaders/SystemSettingsManager.ts +278 -0
  80. package/src/core/metadatas/recordingConstants.ts +62 -0
  81. package/src/core/metadatas/types.ts +23 -0
  82. package/src/core/onboard/OnboardStatusManager.ts +2 -1
  83. package/src/core/validators/StdioServerValidator.ts +4 -3
  84. package/src/services/InstallationService.ts +54 -399
  85. package/src/services/MCPManager.ts +4 -77
  86. package/src/services/RequirementService.ts +564 -67
  87. package/src/services/ServerService.ts +0 -90
  88. package/src/utils/adoUtils.ts +6 -4
  89. package/src/utils/logger.ts +1 -1
  90. package/src/utils/macroExpressionUtils.ts +4 -21
  91. package/src/utils/osUtils.ts +92 -1
  92. package/src/utils/versionUtils.ts +71 -19
  93. package/src/web/public/css/modal.css +292 -1
  94. package/src/web/public/css/serverDetails.css +14 -1
  95. package/src/web/public/index.html +122 -20
  96. package/src/web/public/js/flights/flights.js +1 -1
  97. package/src/web/public/js/modal/index.js +8 -14
  98. package/src/web/public/js/modal/installModal.js +3 -4
  99. package/src/web/public/js/modal/installation.js +122 -137
  100. package/src/web/public/js/modal/loadingModal.js +155 -25
  101. package/src/web/public/js/modal/modalSetup.js +125 -43
  102. package/src/web/public/js/modal/modalUtils.js +0 -12
  103. package/src/web/public/js/modal.js +23 -10
  104. package/src/web/public/js/onboard/publishHandler.js +22 -20
  105. package/src/web/public/js/serverCategoryDetails.js +60 -11
  106. package/src/web/public/js/serverCategoryList.js +5 -5
  107. package/src/web/public/js/settings.js +314 -0
  108. package/src/web/public/settings.html +135 -0
  109. package/src/web/public/styles.css +32 -0
  110. package/src/web/server.ts +85 -0
  111. package/src/web/public/js/modal/messageQueue.js +0 -112
@@ -13,8 +13,6 @@ import {
13
13
  } from '../core/metadatas/types.js';
14
14
  import { mcpManager } from './MCPManager.js';
15
15
  import { OperationStatus } from '../core/onboard/OnboardStatus.js';
16
- import { UPDATE_CHECK_INTERVAL_MS } from '../core/metadatas/constants.js';
17
- import { updateCheckTracker } from '../utils/UpdateCheckTracker.js';
18
16
 
19
17
  const __dirname = path.dirname(fileURLToPath(import.meta.url));
20
18
 
@@ -36,97 +34,9 @@ export class ServerService {
36
34
  async getServerCategory(categoryName: string): Promise<MCPServerCategory | undefined> {
37
35
  const serverCategories = await this.listServerCategories();
38
36
  const serverCategory = serverCategories.find(s => s.name === categoryName);
39
-
40
- // Start async check for requirement updates if one isn't already in progress
41
- if (serverCategory && serverCategory.feedConfiguration && serverCategory.name) {
42
- // Check if update is already in progress using the tracker
43
- const shouldCheckForUpdates = await updateCheckTracker.startOperation(serverCategory.name);
44
-
45
- if (shouldCheckForUpdates) {
46
- this.checkRequirementsForUpdate(serverCategory).catch(error => {
47
- // Ensure we mark the operation as complete on error
48
- if (serverCategory.name) {
49
- updateCheckTracker.endOperation(serverCategory.name)
50
- .catch(lockError => console.error(`Failed to mark update check as complete: ${lockError.message}`));
51
- }
52
- Logger.error(`Error checking requirements for updates: ${error.message}`);
53
- });
54
- } else {
55
- Logger.debug(`Update check already in progress for ${serverCategory.name}, skipping`);
56
- }
57
- }
58
-
59
37
  return serverCategory;
60
38
  }
61
39
 
62
- /**
63
- * Check for updates to requirements for a server category
64
- * @param serverCategory The server category to check
65
- * @private
66
- */
67
- private async checkRequirementsForUpdate(serverCategory: MCPServerCategory): Promise<void> {
68
- if (!serverCategory.name || !serverCategory.feedConfiguration?.requirements?.length) {
69
- return;
70
- }
71
-
72
- try {
73
- const { requirementService } = await import('./RequirementService.js');
74
- const { configProvider } = await import('../core/loaders/ConfigurationProvider.js');
75
-
76
- for (const requirement of serverCategory.feedConfiguration.requirements) {
77
- if (requirement.version.includes('latest')) {
78
- // Get current status if available
79
- const currentStatus = serverCategory.installationStatus?.requirementsStatus[requirement.name];
80
- if (!currentStatus) continue;
81
-
82
- // Skip update check if last check was less than UPDATE_CHECK_INTERVAL_MS ago
83
- if (currentStatus.lastCheckTime) {
84
- const lastCheckTime = new Date(currentStatus.lastCheckTime);
85
- const currentTime = new Date();
86
- const timeSinceLastCheck = currentTime.getTime() - lastCheckTime.getTime();
87
-
88
- if (timeSinceLastCheck < UPDATE_CHECK_INTERVAL_MS) {
89
- Logger.debug(`Skipping update check for ${requirement.name}, last check was ${Math.round(timeSinceLastCheck / 1000)} seconds ago`);
90
- continue;
91
- }
92
- }
93
-
94
- // Check for updates
95
- const updatedStatus = await requirementService.checkRequirementForUpdates(requirement, currentStatus);
96
-
97
- // If update information is found, update the configuration
98
- if (updatedStatus.availableUpdate && serverCategory.name) {
99
- await configProvider.updateRequirementStatus(
100
- serverCategory.name,
101
- requirement.name,
102
- updatedStatus
103
- );
104
-
105
- // Also update the in-memory status for immediate use
106
- if (serverCategory.installationStatus?.requirementsStatus) {
107
- serverCategory.installationStatus.requirementsStatus[requirement.name] = updatedStatus;
108
- }
109
- }
110
- currentStatus.lastCheckTime = new Date().toISOString();
111
- await configProvider.updateRequirementStatus(
112
- serverCategory.name,
113
- requirement.name,
114
- currentStatus
115
- );
116
- if (serverCategory.installationStatus?.requirementsStatus) {
117
- serverCategory.installationStatus.requirementsStatus[requirement.name] = updatedStatus;
118
- }
119
- }
120
- }
121
- } finally {
122
- // Always mark the operation as complete when done, even if there was an error
123
- if (serverCategory.name) {
124
- await updateCheckTracker.endOperation(serverCategory.name)
125
- .catch(error => console.error(`Failed to mark update check as complete: ${error.message}`));
126
- }
127
- }
128
- }
129
-
130
40
  /**
131
41
  * Gets the schema for a specific server in a category
132
42
  */
@@ -124,13 +124,12 @@ export async function handleArtifact(
124
124
  if (!registry) {
125
125
  throw new Error('Azure DevOps artifacts registry configuration is required.');
126
126
  }
127
- if (!registry.registryName || !registry.registryUrl) {
128
- throw new Error('Registry name and URL are required for Azure DevOps artifacts.');
129
- }
130
-
131
127
  Logger.debug(`Handling ADO artifact for requirement: ${requirement.name}, type: ${requirement.type}`);
132
128
 
133
129
  if (requirement.type === 'npm') {
130
+ if (!registry.registryName || !registry.registryUrl) {
131
+ throw new Error('Registry name and URL are required for NPM source in Azure DevOps artifacts.');
132
+ }
134
133
  const requirementDir = targetDir || path.join(SETTINGS_DIR, 'requirements', requirement.name, requirement.version);
135
134
  await fs.mkdir(requirementDir, { recursive: true });
136
135
  Logger.debug(`Ensured directory for npm requirement: ${requirementDir}`);
@@ -153,6 +152,9 @@ export async function handleArtifact(
153
152
  }
154
153
 
155
154
  } else if (requirement.type === 'pip') {
155
+ if (!registry.registryUrl) {
156
+ throw new Error('Registry URL are required for PIP source in Azure DevOps artifacts.');
157
+ }
156
158
  await _installPipRequirements(pythonCommand);
157
159
 
158
160
  const packageName = requirement.version.toLowerCase().includes('latest')
@@ -24,7 +24,7 @@ export class Logger {
24
24
  private static fileLoggingEnabled = true;
25
25
  private static logsDir = path.join(SETTINGS_DIR, 'logs');
26
26
  private static isTestEnvironment: boolean = false;
27
- private static packageVersion = getPackageVersion();
27
+ private static packageVersion = getPackageVersion().packageVersion;
28
28
 
29
29
  static setVerbose(isVerbose: boolean): void {
30
30
  this.verbose = isVerbose;
@@ -1,6 +1,7 @@
1
1
  import { Logger } from './logger.js';
2
- import { getPythonPackagePath, getSystemPythonPackageDirectory, GetBrowserPath } from './osUtils.js';
2
+ import { getPythonPackagePath, getSystemPythonPackageDirectory, getBrowserPath, getGlobalNPMPackagePath } from './osUtils.js';
3
3
  import { ServerInstallOptions } from '../core/metadatas/types.js'; // Adjusted path
4
+ import { SystemSettingsManager } from '../core/loaders/SystemSettingsManager.js';
4
5
  import * as fsSync from 'fs';
5
6
  import * as path from 'path';
6
7
  import { execSync } from 'child_process';
@@ -64,25 +65,7 @@ export function resolveNpmModulePath(providedNpmPath: string | undefined): strin
64
65
  return `${providedNpmPath}/node_modules`;
65
66
  }
66
67
 
67
- const nvmHome = process.env.NVM_HOME;
68
- if (nvmHome) {
69
- try {
70
- const nodeVersion = execSync('node -v').toString().trim();
71
- const nvmNodePath = path.join(nvmHome, nodeVersion);
72
- // Check if this path exists
73
- try {
74
- fsSync.accessSync(nvmNodePath);
75
- Logger.debug(`Resolved ${MACRO_EXPRESSIONS.NPMPATH} via NVM to: ${nvmNodePath}`);
76
- return nvmNodePath;
77
- } catch (error) {
78
- Logger.debug(`NVM controlled path doesn't exist: ${nvmNodePath}, will try global npm`);
79
- }
80
- } catch (error) {
81
- Logger.debug(`Error determining Node version for NVM: ${error}, will use global npm`);
82
- }
83
- }
84
-
85
- const globalNpmPath = execSync('npm root -g').toString().trim();
68
+ const globalNpmPath = getGlobalNPMPackagePath();
86
69
  Logger.debug(`Resolved ${MACRO_EXPRESSIONS.NPMPATH} via global npm to: ${globalNpmPath}`);
87
70
  return globalNpmPath;
88
71
  }
@@ -111,7 +94,7 @@ export async function resolveNpmPathMacro(_finalConfig: any, options: ServerInst
111
94
  export async function resolveBrowserPathMacro(): Promise<string | undefined> {
112
95
  Logger.debug(`Resolving ${MACRO_EXPRESSIONS.BROWSER_PATH}`);
113
96
  try {
114
- const browserPath = await GetBrowserPath();
97
+ const browserPath = await getBrowserPath();
115
98
  Logger.debug(`Resolved ${MACRO_EXPRESSIONS.BROWSER_PATH} to: ${browserPath}`);
116
99
  return browserPath;
117
100
  } catch (error) {
@@ -5,6 +5,8 @@ import util from 'util';
5
5
  import { Logger } from './logger.js';
6
6
  import fs from 'fs';
7
7
  import path from 'path';
8
+ import { execSync } from 'child_process';
9
+ import * as fsSync from 'fs';
8
10
 
9
11
  const execAsync = util.promisify(exec);
10
12
 
@@ -421,8 +423,40 @@ export async function getSystemPythonPackageDirectory(): Promise<string | null>
421
423
  return null;
422
424
  }
423
425
  }
426
+ /**
427
+ * Get the system Python executable path.
428
+ * This function returns the absolute path to the system Python executable (e.g., /Users/penwa/miniconda3/envs/browser-use-temp/bin/python).
429
+ * It uses 'which python' (Unix) or 'where python' (Windows) to locate the executable.
430
+ * @returns {Promise<string | null>} The path to the Python executable, or null if not found.
431
+ */
432
+ export async function getSystemPythonExecutablePath(): Promise<string | null> {
433
+ const command = process.platform === 'win32' ? 'where python' : 'which python';
434
+
435
+ Logger.debug({
436
+ action: 'get_system_python_executable_path',
437
+ command
438
+ });
439
+
440
+ try {
441
+ const { stdout } = await execAsync(command);
442
+ // Use the first path found, trim whitespace
443
+ const pythonPath = stdout.split('\n')[0].trim();
444
+ if (pythonPath) {
445
+ Logger.debug({
446
+ action: 'get_system_python_executable_path_success',
447
+ pythonPath
448
+ });
449
+ return pythonPath;
450
+ }
451
+ Logger.debug('No Python executable found');
452
+ return null;
453
+ } catch (error) {
454
+ Logger.debug(`Could not find system python using "${command}": ${error}`);
455
+ return null;
456
+ }
457
+ }
424
458
 
425
- export async function GetBrowserPath(): Promise<string> {
459
+ export async function getBrowserPath(): Promise<string> {
426
460
  const osType = getOSType();
427
461
  Logger.debug({
428
462
  action: 'get_system_browser_path',
@@ -503,4 +537,61 @@ export async function GetBrowserPath(): Promise<string> {
503
537
  Logger.error('Failed to get browser path', error);
504
538
  throw error;
505
539
  }
540
+ }
541
+
542
+ /**
543
+ * Get the global NPM path
544
+ * This function checks if NVM is installed and retrieves the global NPM path accordingly.
545
+ * If NVM is not installed, it falls back to the global NPM path.
546
+ * @returns The global NPM path as a string.
547
+ * @throws Error if the NPM path cannot be determined.
548
+ * */
549
+ export function getGlobalNPMPackagePath(): string {
550
+ const nvmHome = process.env.NVM_HOME;
551
+ if (nvmHome) {
552
+ try {
553
+ const nodeVersion = execSync('node -v').toString().trim();
554
+ const nvmNodePath = path.join(nvmHome, nodeVersion);
555
+ // Check if this path exists
556
+ try {
557
+ fsSync.accessSync(nvmNodePath);
558
+ return nvmNodePath;
559
+ } catch (error) {
560
+ Logger.debug(`NVM controlled path doesn't exist: ${nvmNodePath}, will try global npm`);
561
+ }
562
+ } catch (error) {
563
+ Logger.debug(`Error determining Node version for NVM: ${error}, will use global npm`);
564
+ }
565
+ }
566
+
567
+ const globalNpmPath = execSync('npm root -g').toString().trim();
568
+ return globalNpmPath;
569
+ }
570
+
571
+
572
+ /**
573
+ * Get the NPM executable path on the current platform (Windows, macOS, Linux).
574
+ * On Windows, uses PowerShell to locate npm. On macOS/Linux, uses 'which' to locate npm.
575
+ * Returns the directory containing the npm executable, or a platform-appropriate default if not found.
576
+ */
577
+ export async function getNpmExecutablePath(): Promise<string> {
578
+ try {
579
+ if (process.platform === 'win32') {
580
+ const { stdout } = await execAsync('powershell -Command "get-command npm | Select-Object -ExpandProperty Source"');
581
+ return stdout.trim().replace(/\\npm\.cmd$/, '');
582
+ } else {
583
+ // macOS or Linux
584
+ const { stdout } = await execAsync('which npm');
585
+ // Remove the trailing '/npm' to get the directory
586
+ return stdout.trim().replace(/\/npm$/, '');
587
+ }
588
+ } catch (error) {
589
+ Logger.error('Error getting npm path:', error);
590
+ if (process.platform === 'win32') {
591
+ return 'C:\\Program Files\\nodejs';
592
+ } else {
593
+ // Common default for Unix systems
594
+ return '/usr/local/bin';
595
+ }
596
+ }
506
597
  }
@@ -1,33 +1,43 @@
1
1
  import fs from 'fs';
2
2
  import path from 'path';
3
3
  import { fileURLToPath } from 'url';
4
+ import axios from 'axios';
5
+ import { Logger } from './logger.js'; // Assuming logger.js is in the same directory
4
6
 
5
- export function getPackageVersion(): string {
7
+ // ANSI color codes
8
+ const COLORS = {
9
+ reset: '\x1b[0m',
10
+ yellow: '\x1b[33m'
11
+ };
12
+
13
+ const PACKAGE_NAME = 'imcp'; // Default package name
14
+
15
+ export function getPackageVersion(): { packageName: string, packageVersion: string } {
6
16
  try {
7
17
  // First try npm environment variable (available during npm scripts)
8
18
  if (process.env.npm_package_version) {
9
- return process.env.npm_package_version;
19
+ return { packageName: PACKAGE_NAME, packageVersion: process.env.npm_package_version };
10
20
  }
11
21
 
12
22
  // Fall back to reading package.json
13
23
  // Get directory name of current module
14
24
  const __dirname = path.dirname(fileURLToPath(import.meta.url));
15
-
25
+
16
26
  // Traverse up to find package.json (max 3 levels up)
17
27
  let currentDir = __dirname;
18
28
  for (let i = 0; i < 3; i++) {
19
29
  const packagePath = path.join(currentDir, 'package.json');
20
30
  if (fs.existsSync(packagePath)) {
21
31
  const packageJson = JSON.parse(fs.readFileSync(packagePath, 'utf8'));
22
- return packageJson.version;
32
+ return { packageName: PACKAGE_NAME, packageVersion: packageJson.version };
23
33
  }
24
34
  currentDir = path.join(currentDir, '..');
25
35
  }
26
36
 
27
- return 'unknown';
37
+ return { packageName: PACKAGE_NAME, packageVersion: 'unknown' };
28
38
  } catch (error) {
29
39
  console.error('Failed to get package version:', error);
30
- return 'unknown';
40
+ return { packageName: PACKAGE_NAME, packageVersion: 'unknown' };
31
41
  }
32
42
  }
33
43
 
@@ -44,19 +54,61 @@ export function getPackageVersion(): string {
44
54
  * a positive number if v1 > v2, 0 if equal)
45
55
  */
46
56
  export function compareVersions(v1: string, v2: string): number {
47
- const v1Parts = v1.split('.').map(Number);
48
- const v2Parts = v2.split('.').map(Number);
49
-
50
- for (let i = 0; i < Math.max(v1Parts.length, v2Parts.length); i++) {
51
- const v1Part = i < v1Parts.length ? v1Parts[i] : 0;
52
- const v2Part = i < v2Parts.length ? v2Parts[i] : 0;
53
-
54
- if (v1Part !== v2Part) {
55
- // This returns the actual difference, which is:
56
- // negative if v1Part < v2Part, positive if v1Part > v2Part
57
- return v1Part - v2Part;
58
- }
57
+ const v1Parts = v1.split('.').map(Number);
58
+ const v2Parts = v2.split('.').map(Number);
59
+
60
+ for (let i = 0; i < Math.max(v1Parts.length, v2Parts.length); i++) {
61
+ const v1Part = i < v1Parts.length ? v1Parts[i] : 0;
62
+ const v2Part = i < v2Parts.length ? v2Parts[i] : 0;
63
+
64
+ if (v1Part !== v2Part) {
65
+ // This returns the actual difference, which is:
66
+ // negative if v1Part < v2Part, positive if v1Part > v2Part
67
+ return v1Part - v2Part;
68
+ }
69
+ }
70
+
71
+ return 0;
72
+ }
73
+
74
+ /**
75
+ * Check if there's a newer version of the package available
76
+ */
77
+ export async function checkForUpdates(): Promise<void> {
78
+ Logger.debug(`Checking for updates...`);
79
+ try {
80
+ const version = await getAppVersion();
81
+ if (version.availableUpdate) {
82
+ console.log(`${COLORS.yellow}Update available for ${version.name}: ${version.version} → ${version.availableUpdate.latestVersion}${COLORS.reset}`);
83
+ console.log(`${COLORS.yellow}Relaunch with \`npx -y ${version.name}@latest serve\` or update package with \`npm install -g ${version.name}@latest\`${COLORS.reset}`);
59
84
  }
60
85
 
61
- return 0;
86
+ } catch (error) {
87
+ // Log the npm error
88
+ Logger.debug(`Failed to check npm registry: ${error instanceof Error ? error.message : String(error)}`);
89
+ }
90
+ }
91
+
92
+ /**
93
+ * Retrieves the application version and information about available updates.
94
+ * @returns A promise that resolves to an object containing the current packageVersion and any availableUpdates.
95
+ */
96
+ export async function getAppVersion(): Promise<{ name: string, version: string; availableUpdate?: { latestVersion: string; message: string} }> {
97
+ let availableUpdate: { latestVersion: string; message: string } | undefined = undefined;
98
+
99
+ const { packageName, packageVersion } = getPackageVersion();
100
+ // Check for updates from npm registry
101
+ try {
102
+ const npmResponse = await axios.get(`https://registry.npmjs.org/${packageName}`);
103
+ if (npmResponse.data && npmResponse.data['dist-tags'] && npmResponse.data['dist-tags'].latest) {
104
+ const latestVersion = npmResponse.data['dist-tags'].latest;
105
+ if (compareVersions(latestVersion, packageVersion) > 0) {
106
+ availableUpdate = { latestVersion, message: `New version (${latestVersion}) is available. Relaunch with \`npx -y ${packageName}@latest serve\`` };
107
+ }
108
+ }
109
+ } catch (npmError) {
110
+ Logger.debug(`Failed to fetch latest version from npm for ${packageName}: ${npmError instanceof Error ? npmError.message : String(npmError)}`);
111
+ }
112
+
113
+ return { name: packageName, version: packageVersion, availableUpdate };
62
114
  }