@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.
- package/package.json +1 -1
- package/src/index.js +25 -19
package/package.json
CHANGED
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
|
-
|
|
21
|
-
|
|
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
|
|
32
|
-
if (latest && latest
|
|
41
|
+
const latest = data?.version
|
|
42
|
+
if (latest && isNewerVersion(latest, VERSION)) {
|
|
33
43
|
console.log(
|
|
34
|
-
chalk.yellow(' ⚠
|
|
35
|
-
chalk.dim(`v${VERSION}`) +
|
|
36
|
-
chalk.
|
|
37
|
-
chalk.
|
|
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
|
|
51
|
+
// Offline or timeout — skip silently
|
|
45
52
|
}
|
|
46
53
|
}
|
|
47
54
|
|
|
48
|
-
|
|
49
|
-
checkForUpdate()
|
|
55
|
+
await checkForUpdate()
|
|
50
56
|
|
|
51
57
|
// ── Header ────────────────────────────────────────────────────────────────────
|
|
52
58
|
|