easy-claude 0.2.3 → 0.2.4

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/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # 更新记录
2
2
 
3
+ ## 0.2.4 — 2026-10-19
4
+
5
+ ### 修复
6
+
7
+ - update先在线刷新latest并比较版本,按明确版本号安装,防止旧缓存降级;相同或更高的本地版本不安装,检查失败明确报错。
8
+ - 保留上一版新增的update、show自动重开和绿色时段延长至18:00。
9
+
10
+
3
11
  ## 0.2.3 — 2026-10-19
4
12
 
5
13
  ### 新增
package/README.md CHANGED
@@ -4,6 +4,11 @@
4
4
 
5
5
  需要 Node.js 22+ 与 Claude Code 订阅登录;不支持把 API Key 账单余额当作订阅额度。
6
6
 
7
+ ## v0.2.4 修复说明
8
+
9
+ - update先在线检查正式版本,再按明确版本号安装,避免npm旧缓存导致降级;已是最新或本地版本更高时不重复安装。
10
+ - 包含上一版update、show自动重开、09:00–18:00绿色时段,以及完整版本说明。
11
+
7
12
  ## v0.2.3 新增与调整
8
13
 
9
14
  - **命令更新**:新增 `easy-claude update`,从官方 npm 更新当前全局安装。
@@ -5,7 +5,7 @@
5
5
  <key>CFBundleIdentifier</key><string>com.unionschool.easy-claude.overlay</string>
6
6
  <key>CFBundleName</key><string>Easy Claude Overlay</string>
7
7
  <key>CFBundlePackageType</key><string>APPL</string>
8
- <key>CFBundleShortVersionString</key><string>0.2.3</string>
8
+ <key>CFBundleShortVersionString</key><string>0.2.4</string>
9
9
  <key>LSMinimumSystemVersion</key><string>14.0</string>
10
10
  <key>LSUIElement</key><true/>
11
11
  <key>NSHighResolutionCapable</key><true/>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "easy-claude",
3
- "version": "0.2.3",
3
+ "version": "0.2.4",
4
4
  "description": "Claude Code quota rings and transparent world clock for Claude desktop",
5
5
  "type": "module",
6
6
  "bin": {
package/src/update.js CHANGED
@@ -1,7 +1,10 @@
1
1
  import { access, realpath } from 'node:fs/promises';
2
+ import { readFileSync } from 'node:fs';
2
3
  import { dirname, basename, join, delimiter } from 'node:path';
3
4
  import { fileURLToPath } from 'node:url';
4
- import { spawn } from 'node:child_process';
5
+ import { spawn, execFile } from 'node:child_process';
6
+ import { promisify } from 'node:util';
7
+ const { version } = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8'));
5
8
 
6
9
  export function installedPrefix(root, platform = process.platform) {
7
10
  const modules = dirname(root.replace(/[\\/]$/, ''));
@@ -10,6 +13,15 @@ export function installedPrefix(root, platform = process.platform) {
10
13
  return basename(parent) === 'lib' ? dirname(parent) : platform === 'win32' ? parent : null;
11
14
  }
12
15
 
16
+ export function isNewer(latest, current) {
17
+ if (!/^\d+\.\d+\.\d+$/.test(latest) || !/^\d+\.\d+\.\d+(?:-[\w.-]+)?$/.test(current)) {
18
+ throw new Error('无法识别正式版本号,未执行更新。');
19
+ }
20
+ const a = latest.split('.').map(Number), b = current.split('-')[0].split('.').map(Number);
21
+ for (let i = 0; i < 3; i++) { if (a[i] !== b[i]) return a[i] > b[i]; }
22
+ return current.includes('-');
23
+ }
24
+
13
25
  async function findNpmCli() {
14
26
  const directories = [dirname(process.execPath), ...(process.env.PATH ?? '').split(delimiter)];
15
27
  for (const directory of directories.filter(Boolean)) {
@@ -22,6 +34,14 @@ async function findNpmCli() {
22
34
  throw new Error('未找到 npm,请先安装 Node.js/npm,再使用 npm i -g 更新。');
23
35
  }
24
36
 
37
+ async function readLatest(npmCli, name) {
38
+ try {
39
+ const { stdout } = await promisify(execFile)(process.execPath, [npmCli, 'view', name, 'dist-tags.latest',
40
+ '--json', '--prefer-online', '--registry=https://registry.npmjs.org'], { timeout: 30000, maxBuffer: 4096 });
41
+ return JSON.parse(stdout);
42
+ } catch { throw new Error('无法在线检查 npm 最新版本,请检查网络后重试。'); }
43
+ }
44
+
25
45
  function runNpm(command, args) {
26
46
  return new Promise((resolve, reject) => {
27
47
  const child = spawn(command, args, { stdio: 'inherit', shell: false });
@@ -34,12 +54,19 @@ function runNpm(command, args) {
34
54
  }
35
55
 
36
56
  export async function updatePackage(name, { root = fileURLToPath(new URL('../', import.meta.url)),
37
- getNpmCli = findNpmCli, run = runNpm, platform = process.platform } = {}) {
57
+ getNpmCli = findNpmCli, getLatest = readLatest, currentVersion = version,
58
+ run = runNpm, platform = process.platform } = {}) {
38
59
  if (!['easy-codex', 'easy-claude'].includes(name)) throw new Error('不支持的更新包名。');
39
60
  const npmCli = await getNpmCli();
61
+ const latest = await getLatest(npmCli, name);
62
+ if (!isNewer(latest, currentVersion)) {
63
+ console.log(`${name} 当前 ${currentVersion},npm 最新 ${latest},无需更新。`);
64
+ return;
65
+ }
40
66
  const prefix = installedPrefix(root, platform);
67
+ // 先在线检查再锁定版本,避免安装阶段复用旧 latest 缓存而降级。
41
68
  const args = [npmCli, 'install', '--global', ...(prefix ? ['--prefix', prefix] : []),
42
- '--registry=https://registry.npmjs.org', `${name}@latest`];
69
+ '--prefer-online', '--registry=https://registry.npmjs.org', `${name}@${latest}`];
43
70
  await run(process.execPath, args);
44
- console.log(`${name} 已更新;运行 ${name} show 自动重启浮窗。`);
71
+ console.log(`${name} 已更新到 ${latest};运行 ${name} show 自动重启浮窗。`);
45
72
  }