@runloop/rl-cli 0.1.1 → 0.1.2

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,30 +10,26 @@ const VersionCheck = () => {
10
10
  React.useEffect(() => {
11
11
  const checkForUpdates = async () => {
12
12
  try {
13
- const currentVersion = process.env.npm_package_version || "0.0.1";
14
- const response = await fetch("https://registry.npmjs.org/@runloop/rl-cli/latest");
15
- if (response.ok) {
16
- const data = await response.json();
17
- const latestVersion = data.version;
18
- if (latestVersion && latestVersion !== currentVersion) {
19
- // Check if current version is older than latest
20
- const compareVersions = (version1, version2) => {
21
- const v1parts = version1.split('.').map(Number);
22
- const v2parts = version2.split('.').map(Number);
23
- for (let i = 0; i < Math.max(v1parts.length, v2parts.length); i++) {
24
- const v1part = v1parts[i] || 0;
25
- const v2part = v2parts[i] || 0;
26
- if (v1part > v2part)
27
- return 1;
28
- if (v1part < v2part)
29
- return -1;
30
- }
31
- return 0;
32
- };
33
- const isUpdateAvailable = compareVersions(latestVersion, currentVersion) > 0;
34
- if (isUpdateAvailable) {
35
- setUpdateAvailable(latestVersion);
36
- }
13
+ // Import the utility functions from config
14
+ const { checkForUpdates: checkForUpdatesUtil } = await import("../utils/config.js");
15
+ // Use the same logic as the non-interactive version
16
+ // We'll call the utility function and capture its output
17
+ const originalConsoleError = console.error;
18
+ let updateMessage = "";
19
+ // Capture the console.error output
20
+ console.error = (...args) => {
21
+ updateMessage = args.join(' ');
22
+ originalConsoleError(...args);
23
+ };
24
+ // Call the update check utility
25
+ await checkForUpdatesUtil(false);
26
+ // Restore original console.error
27
+ console.error = originalConsoleError;
28
+ // Parse the update message to extract the latest version
29
+ if (updateMessage.includes("Update available:")) {
30
+ const match = updateMessage.match(/Update available: .+ → (.+)/);
31
+ if (match && match[1]) {
32
+ setUpdateAvailable(match[1]);
37
33
  }
38
34
  }
39
35
  }
@@ -33,7 +33,7 @@ export function sshUrl() {
33
33
  export function getCacheDir() {
34
34
  return join(homedir(), ".cache", "rl-cli");
35
35
  }
36
- function getCurrentVersion() {
36
+ export function getCurrentVersion() {
37
37
  try {
38
38
  // First try environment variable (when installed via npm)
39
39
  if (process.env.npm_package_version) {
@@ -67,23 +67,42 @@ export function hasCachedUpdateInfo() {
67
67
  const cacheFile = join(cacheDir, "last_update_check");
68
68
  return existsSync(cacheFile);
69
69
  }
70
- export function updateCheckCache() {
70
+ export function updateCheckCache(latestVersion) {
71
71
  const cacheDir = getCacheDir();
72
72
  const cacheFile = join(cacheDir, "last_update_check");
73
73
  // Create cache directory if it doesn't exist
74
74
  if (!existsSync(cacheDir)) {
75
75
  mkdirSync(cacheDir, { recursive: true });
76
76
  }
77
- // Touch the cache file
78
- writeFileSync(cacheFile, "");
77
+ // Store the latest version in the cache file
78
+ writeFileSync(cacheFile, latestVersion);
79
+ }
80
+ export function getCachedLatestVersion() {
81
+ const cacheDir = getCacheDir();
82
+ const cacheFile = join(cacheDir, "last_update_check");
83
+ if (!existsSync(cacheFile)) {
84
+ return null;
85
+ }
86
+ try {
87
+ return readFileSync(cacheFile, 'utf-8').trim();
88
+ }
89
+ catch {
90
+ return null;
91
+ }
79
92
  }
80
93
  export async function checkForUpdates(force = false) {
81
94
  const currentVersion = getCurrentVersion();
82
95
  // Always show cached result if available and not forcing
83
96
  if (!force && hasCachedUpdateInfo() && !shouldCheckForUpdates()) {
84
- // Show cached update info (we know there's an update available)
85
- console.error(`\nšŸ”„ Update available: ${currentVersion} → 0.1.0\n` +
86
- ` Run: npm install -g @runloop/rl-cli@latest\n\n`);
97
+ const cachedLatestVersion = getCachedLatestVersion();
98
+ if (cachedLatestVersion && cachedLatestVersion !== currentVersion) {
99
+ // Check if current version is older than cached latest
100
+ const isUpdateAvailable = compareVersions(cachedLatestVersion, currentVersion) > 0;
101
+ if (isUpdateAvailable) {
102
+ console.error(`\nšŸ”„ Update available: ${currentVersion} → ${cachedLatestVersion}\n` +
103
+ ` Run: npm install -g @runloop/rl-cli@latest\n\n`);
104
+ }
105
+ }
87
106
  return;
88
107
  }
89
108
  // Only fetch from npm if cache is expired or forcing
@@ -118,8 +137,8 @@ export async function checkForUpdates(force = false) {
118
137
  else if (force) {
119
138
  console.error("āœ… You're running the latest version!\n");
120
139
  }
121
- // Update the cache to indicate we've checked
122
- updateCheckCache();
140
+ // Update the cache with the latest version
141
+ updateCheckCache(latestVersion);
123
142
  }
124
143
  catch (error) {
125
144
  if (force) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@runloop/rl-cli",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "Beautiful CLI for Runloop devbox management",
5
5
  "type": "module",
6
6
  "bin": {