aweshare 0.3.0 → 0.3.1

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/README.md CHANGED
@@ -14,7 +14,7 @@
14
14
  <a href="https://ko-fi.com/mugpeng"><img src="https://img.shields.io/badge/Ko--fi-Buy%20me%20a%20coffee-FF5E5B?style=flat-square&logo=ko-fi&logoColor=white" alt="Ko-fi"></a>
15
15
  </p>
16
16
  <p>
17
- <a href="https://github.com/wehuman01/aweshare-source/releases"><img src="https://img.shields.io/badge/version-0.3.0-7C3AED?style=flat-square" alt="Version"></a>
17
+ <a href="https://github.com/wehuman01/aweshare-source/releases"><img src="https://img.shields.io/badge/version-0.3.1-7C3AED?style=flat-square" alt="Version"></a>
18
18
  <a href="https://github.com/wehuman01/aweshare"><img src="https://img.shields.io/badge/node-%E2%89%A522-0EA5E9?style=flat-square" alt="Node"></a>
19
19
  <a href="https://github.com/wehuman01/aweshare/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-proprietary-E34F26?style=flat-square" alt="License"></a>
20
20
  <a href="https://www.npmjs.com/package/aweshare"><img src="https://img.shields.io/badge/npm-aweshare-7C3AED?style=flat-square" alt="npm package"></a>
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aweshare/hub",
3
- "version": "0.2.0",
3
+ "version": "0.3.1",
4
4
  "private": true,
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -15,6 +15,22 @@ const VERSION = JSON.parse(readFileSync(new URL('../package.json', import.meta.u
15
15
 
16
16
  const CHECK_INTERVAL_MS = 24 * 60 * 60 * 1000
17
17
  const REMIND_INTERVAL_MS = 24 * 60 * 60 * 1000
18
+ const RETRY_INTERVAL_MS = 6 * 60 * 60 * 1000
19
+
20
+ /** Numeric comparison tolerant of prefixes/suffixes ("v1.2.3", prerelease tags). */
21
+ function parseVersion(value) {
22
+ const parts = String(value).match(/\d+/g)
23
+ return parts ? parts.slice(0, 3).map(Number) : [0]
24
+ }
25
+
26
+ export function versionGte(current, latest) {
27
+ const a = parseVersion(current)
28
+ const b = parseVersion(latest)
29
+ for (let i = 0; i < 3; i++) {
30
+ if ((a[i] ?? 0) !== (b[i] ?? 0)) return (a[i] ?? 0) > (b[i] ?? 0)
31
+ }
32
+ return true
33
+ }
18
34
 
19
35
  function runCommand(command, args, { cwd, timeout = 120_000 } = {}) {
20
36
  return new Promise((resolve, reject) => {
@@ -67,7 +83,7 @@ export async function runSelfUpdate(args, { run = runCommand, confirmFn = confir
67
83
  console.log(`current version: ${VERSION}`)
68
84
  console.log(`latest version: ${latest}`)
69
85
 
70
- if (VERSION === latest) {
86
+ if (versionGte(VERSION, latest)) {
71
87
  console.log('already up to date')
72
88
  return
73
89
  }
@@ -131,23 +147,26 @@ export async function maybeCheckForUpdate(argv, { run = runCommand, cacheFile, n
131
147
  let cache = await readJson(cacheFile)
132
148
 
133
149
  let latest = null
134
- if (cache && now - Date.parse(cache.lastChecked) < CHECK_INTERVAL_MS) {
150
+ if (cache && now < Date.parse(cache.nextCheckAt)) {
135
151
  latest = cache.latestVersion
136
152
  } else {
137
153
  try {
138
154
  latest = await getNpmLatestVersion(run)
155
+ cache = {
156
+ nextCheckAt: new Date(now + CHECK_INTERVAL_MS).toISOString(),
157
+ latestVersion: latest,
158
+ lastReminded: cache?.lastReminded ?? '',
159
+ }
139
160
  } catch {
161
+ // back off for a few hours so an offline machine does not retry on every command
162
+ cache = { ...cache, nextCheckAt: new Date(now + RETRY_INTERVAL_MS).toISOString(), latestVersion: null }
163
+ await writeJson(cacheFile, cache)
140
164
  return null
141
165
  }
142
- cache = {
143
- lastChecked: new Date(now).toISOString(),
144
- latestVersion: latest,
145
- lastReminded: cache?.lastReminded ?? '',
146
- }
147
166
  await writeJson(cacheFile, cache)
148
167
  }
149
168
 
150
- if (!latest || latest === VERSION) return null
169
+ if (!latest || versionGte(VERSION, latest)) return null
151
170
 
152
171
  const lastRemindedMs = cache.lastReminded ? Date.parse(cache.lastReminded) : 0
153
172
  if (now - lastRemindedMs < REMIND_INTERVAL_MS) return null
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aweshare",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "type": "module",
5
5
  "description": "Open-source, local-first AI capability relay",
6
6
  "license": "UNLICENSED",