@exchanet/enet 1.0.18 → 1.0.19

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 (2) hide show
  1. package/package.json +1 -1
  2. package/src/index.js +25 -19
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@exchanet/enet",
3
- "version": "1.0.18",
3
+ "version": "1.0.19",
4
4
  "description": "enet — exchanet methods manager. Install, scaffold and manage AI coding methods.",
5
5
  "bin": {
6
6
  "enet": "src/index.js"
package/src/index.js CHANGED
@@ -17,36 +17,42 @@ const require = createRequire(import.meta.url)
17
17
  const pkg = require('../package.json')
18
18
  const VERSION = pkg.version
19
19
 
20
- // ── Version check ─────────────────────────────────────────────────────────────
21
- // Runs in background never blocks the command, never crashes if offline
20
+ function isNewerVersion (latest, current) {
21
+ const parts = (v) => String(v).replace(/^v/, '').split('.').map(Number)
22
+ const a = parts(latest)
23
+ const b = parts(current)
24
+ for (let i = 0; i < Math.max(a.length, b.length); i++) {
25
+ const x = a[i] || 0
26
+ const y = b[i] || 0
27
+ if (x > y) return true
28
+ if (x < y) return false
29
+ }
30
+ return false
31
+ }
32
+
33
+ // ── Version check (every command) ─────────────────────────────────────────────
34
+ // Shows warning if a newer enet is on npm; never blocks, never crashes if offline
22
35
 
23
- async function checkForUpdate() {
36
+ async function checkForUpdate () {
24
37
  try {
25
- const res = await fetch(
26
- 'https://registry.npmjs.org/@exchanet/enet/latest',
27
- { signal: AbortSignal.timeout(3000) }
28
- )
38
+ const res = await fetch('https://registry.npmjs.org/@exchanet/enet/latest', { signal: AbortSignal.timeout(3000) })
29
39
  if (!res.ok) return
30
40
  const data = await res.json()
31
- const latest = data.version
32
- if (latest && latest !== VERSION) {
41
+ const latest = data?.version
42
+ if (latest && isNewerVersion(latest, VERSION)) {
33
43
  console.log(
34
- chalk.yellow(' ⚠ Update available: ') +
35
- chalk.dim(`v${VERSION}`) +
36
- chalk.white(' ') +
37
- chalk.green(`v${latest}`) + '\n' +
38
- chalk.dim(' Run ') +
39
- chalk.white('npm install -g @exchanet/enet') +
40
- chalk.dim(' to update.\n')
44
+ chalk.yellow(' ⚠ Warning: a newer version of enet is available.\n') +
45
+ chalk.dim(` Current: v${VERSION} → Latest: v${latest}\n`) +
46
+ chalk.dim(' Update: ') +
47
+ chalk.white('npm install -g @exchanet/enet\n')
41
48
  )
42
49
  }
43
50
  } catch {
44
- // Offline or npm unreachable — silently skip
51
+ // Offline or timeoutskip silently
45
52
  }
46
53
  }
47
54
 
48
- // Fire in background without await — command runs immediately
49
- checkForUpdate()
55
+ await checkForUpdate()
50
56
 
51
57
  // ── Header ────────────────────────────────────────────────────────────────────
52
58