@muwi/core 0.10.1 → 0.10.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.
- package/package.json +1 -1
- package/src/events.js +4 -3
- package/src/update.js +54 -20
package/package.json
CHANGED
package/src/events.js
CHANGED
|
@@ -77,10 +77,11 @@ export function guideUpdate(dir , key , env = p
|
|
|
77
77
|
|
|
78
78
|
/**
|
|
79
79
|
* 새 판이 나왔으면 이 세션에 한 번 알릴 말 (세션이 시작될 때나 사람이 말할 때). 캐시만 보고 훅을 늦추지 않는다 (update.ts).
|
|
80
|
+
* 세션이 시작될 때(start)는 30초 뒤에 npm에 묻게 해서, 그 뒤에 말할 때와 그래프 칸에 새 판이 보인다.
|
|
80
81
|
* 같은 판은 세션마다 한 번만 알린다
|
|
81
82
|
*/
|
|
82
|
-
function updateNotice(dir , key , root , env ) {
|
|
83
|
-
const newer = newerKnown({ current: versionOf(root), root, plugins: [...views().map(v => v.package), terminals().package], env });
|
|
83
|
+
function updateNotice(dir , key , root , env , start = false) {
|
|
84
|
+
const newer = newerKnown({ current: versionOf(root), root, plugins: [...views().map(v => v.package), terminals().package], env, start });
|
|
84
85
|
if (!newer || readSession(dir, key)?.toldUpdate === newer.latest) return undefined;
|
|
85
86
|
touchSession(dir, key, { toldUpdate: newer.latest }, env);
|
|
86
87
|
return updateLine(newer);
|
|
@@ -241,7 +242,7 @@ export function handleEvent(h , dir , env = p
|
|
|
241
242
|
appendEvent(dir, session.work, { type: 'session', what: 'compact' }, key);
|
|
242
243
|
}
|
|
243
244
|
const text = [inFile ? '' : guide, adoptSpawn(dir, key, env)].filter(Boolean).join('\n\n');
|
|
244
|
-
const notice = agent ? undefined : updateNotice(dir, key, root, env);
|
|
245
|
+
const notice = agent ? undefined : updateNotice(dir, key, root, env, true);
|
|
245
246
|
return { ...(text ? { say: text } : {}), ...(notice ? { notice } : {}) };
|
|
246
247
|
}
|
|
247
248
|
|
package/src/update.js
CHANGED
|
@@ -3,8 +3,9 @@
|
|
|
3
3
|
// 2. 대화 자리: 세션이 시작될 때와 사람이 말할 때 (newerKnown → 훅의 답. 도구 화면에 바로 띄우거나 AI가 전한다. events.ts, hook.ts)
|
|
4
4
|
// 3. 보기 (muwi board의 update. 그래프 칸의 배너)
|
|
5
5
|
// 업데이트는 muwi update 하나로 한다: 지금 도는 muwi가 깔린 자리에 최신판을 받고, 새 판으로 muwi setup을 다시 해서 훅·보기·커넥터를 맞춘다 (updateTarget)
|
|
6
|
-
// - 명령을 늦추지 않는다: 알릴지는 캐시만 보고 정한다. npm에 묻는 일은
|
|
7
|
-
// -
|
|
6
|
+
// - 명령을 늦추지 않는다: 알릴지는 캐시만 보고 정한다. npm에 묻는 일은 따로 띄운 프로세스가 하고, 결과는 다음에 쓴다
|
|
7
|
+
// - npm에 묻는 때 (VS Code처럼): 세션이 시작되고 30초 뒤, 그 밖에는 마지막으로 물은 지 1시간이 지났을 때.
|
|
8
|
+
// 하루에 여러 번 나오는 판도 그날 안에 알아챈다. 알림이 잦아지지는 않는다 (대화 자리는 세션마다, 배너는 [나중에]까지, 터미널은 하루에 판마다 한 번)
|
|
8
9
|
// - npm으로 깐 판(.js)에서만 묻는다. 저장소에서 .ts로 돌릴 때는 하지 않는다
|
|
9
10
|
// - 끄기: MUWI_NO_UPDATE_CHECK=1 (NO_UPDATE_NOTIFIER나 CI가 있어도 끈다)
|
|
10
11
|
// npm에는 패키지 이름만 묻는다 (https://registry.npmjs.org/-/package/<이름>/dist-tags)
|
|
@@ -14,12 +15,17 @@ import os from 'node:os';
|
|
|
14
15
|
import path from 'node:path';
|
|
15
16
|
import { olderThan } from './setup.js';
|
|
16
17
|
|
|
17
|
-
const
|
|
18
|
+
const HOUR = 60 * 60 * 1000;
|
|
19
|
+
const DAY = 24 * HOUR;
|
|
20
|
+
/** npm에 다시 묻는 간격 */
|
|
21
|
+
const EVERY = HOUR;
|
|
22
|
+
/** 세션이 시작되고 npm에 묻기까지 */
|
|
23
|
+
export const START_DELAY = 30 * 1000;
|
|
18
24
|
const REGISTRY = 'https://registry.npmjs.org';
|
|
19
25
|
const RELEASES = 'https://github.com/Ssoon-m/muwi/releases/tag';
|
|
20
26
|
|
|
21
|
-
/** 마지막으로 npm에 물어본
|
|
22
|
-
|
|
27
|
+
/** 마지막으로 npm에 물어본 결과와, 터미널에서 알린 판과 때 */
|
|
28
|
+
|
|
23
29
|
|
|
24
30
|
export const cacheFile = (env ) =>
|
|
25
31
|
path.join(env.XDG_CACHE_HOME || path.join(env.HOME || os.homedir(), '.cache'), 'muwi', 'update.json');
|
|
@@ -64,9 +70,10 @@ export function installedPackage(root , plugins =
|
|
|
64
70
|
/** 캐시만 보고 정한다: 알릴 새 버전(tell)과, npm에 다시 물어볼지(refresh) */
|
|
65
71
|
export function decide(c , name , current , now ) {
|
|
66
72
|
const same = c?.name === name ? c : null;
|
|
67
|
-
const refresh = !same?.checkedAt || now - same.checkedAt >=
|
|
73
|
+
const refresh = !same?.checkedAt || now - same.checkedAt >= EVERY;
|
|
68
74
|
const latest = same?.latest;
|
|
69
|
-
|
|
75
|
+
// 같은 판은 하루 한 번. 그사이 더 새 판이 나오면 다시 알린다
|
|
76
|
+
const toldRecently = Boolean(same?.toldAt && now - same.toldAt < DAY && same.told === latest);
|
|
70
77
|
return { tell: latest && olderThan(current, latest) && !toldRecently ? latest : undefined, refresh };
|
|
71
78
|
}
|
|
72
79
|
|
|
@@ -84,11 +91,15 @@ const off = (env ) => Boolean(env.MUWI_NO_UPDATE_CHECK || env.
|
|
|
84
91
|
|
|
85
92
|
|
|
86
93
|
|
|
94
|
+
/** npm에 물을 프로세스를 띄운다. delay를 주면 그만큼 기다렸다 묻는다 (시험에서는 바꾼다) */
|
|
95
|
+
|
|
96
|
+
|
|
87
97
|
/**
|
|
88
98
|
* 대화 자리와 보기에서 알릴 새 판. 캐시만 본다 (훅과 보기를 늦추지 않는다).
|
|
89
|
-
*
|
|
99
|
+
* npm에 묻는 프로세스는 따로 띄우고, 그 결과는 다음에 쓴다: 세션이 시작될 때(start)는 30초 뒤에 묻고,
|
|
100
|
+
* 그 밖에는 마지막으로 물은 지 1시간이 지났을 때 바로 묻는다. 끈 경우와 npm으로 깐 판이 아니면 null
|
|
90
101
|
*/
|
|
91
|
-
export function newerKnown(o
|
|
102
|
+
export function newerKnown(o ) {
|
|
92
103
|
const env = o.env ?? process.env;
|
|
93
104
|
try {
|
|
94
105
|
if (off(env)) return null;
|
|
@@ -98,7 +109,9 @@ export function newerKnown(o
|
|
|
98
109
|
const c = readCache(file);
|
|
99
110
|
const same = c?.name === name ? c : null;
|
|
100
111
|
const now = o.now ?? Date.now();
|
|
101
|
-
|
|
112
|
+
const check = o.check ?? spawnCheck(o.root);
|
|
113
|
+
if (o.start) check(name, file, START_DELAY);
|
|
114
|
+
else if (!same?.checkedAt || now - same.checkedAt >= EVERY) check(name, file);
|
|
102
115
|
return same?.latest && olderThan(o.current, same.latest) ? { name, current: o.current, latest: same.latest } : null;
|
|
103
116
|
} catch {
|
|
104
117
|
return null;
|
|
@@ -143,8 +156,7 @@ export function updateTarget(root , plugins = [],
|
|
|
143
156
|
|
|
144
157
|
|
|
145
158
|
|
|
146
|
-
|
|
147
|
-
|
|
159
|
+
|
|
148
160
|
|
|
149
161
|
|
|
150
162
|
/** 명령이 끝난 뒤 부른다. 무엇이 잘못돼도 명령은 실패하지 않는다 */
|
|
@@ -163,7 +175,7 @@ export function afterCommand(o ) {
|
|
|
163
175
|
const d = decide(c, name, o.current, now);
|
|
164
176
|
if (d.tell) {
|
|
165
177
|
(o.write ?? (t => process.stderr.write(t)))(notice(name, o.current, d.tell));
|
|
166
|
-
writeCache(file, { ...(c?.name === name ? c : { name }), toldAt: now });
|
|
178
|
+
writeCache(file, { ...(c?.name === name ? c : { name }), told: d.tell, toldAt: now });
|
|
167
179
|
}
|
|
168
180
|
if (d.refresh) (o.check ?? spawnCheck(o.root))(name, file);
|
|
169
181
|
} catch {
|
|
@@ -172,8 +184,8 @@ export function afterCommand(o ) {
|
|
|
172
184
|
}
|
|
173
185
|
|
|
174
186
|
/** npm에 묻는 일은 명령과 따로 돈다 (명령은 기다리지 않고 끝난다) */
|
|
175
|
-
const spawnCheck = (root )
|
|
176
|
-
const child = spawn(process.execPath, [path.join(root, 'src', 'update.js'), '--check', name, file], {
|
|
187
|
+
const spawnCheck = (root ) => (name, file, delay) => {
|
|
188
|
+
const child = spawn(process.execPath, [path.join(root, 'src', 'update.js'), '--check', name, file, ...(delay ? [String(delay)] : [])], {
|
|
177
189
|
detached: true,
|
|
178
190
|
stdio: 'ignore',
|
|
179
191
|
windowsHide: true,
|
|
@@ -181,7 +193,7 @@ const spawnCheck = (root ) => (name , file ) => {
|
|
|
181
193
|
child.unref();
|
|
182
194
|
};
|
|
183
195
|
|
|
184
|
-
/** npm의 latest 버전을 물어 캐시에 적는다. 실패해도(오프라인) 물어본 때는 적어서
|
|
196
|
+
/** npm의 latest 버전을 물어 캐시에 적는다. 실패해도(오프라인) 물어본 때는 적어서 한동안 다시 묻지 않는다 */
|
|
185
197
|
export async function checkLatest(name , file , registry = REGISTRY, now = Date.now()) {
|
|
186
198
|
let latest ;
|
|
187
199
|
try {
|
|
@@ -192,11 +204,33 @@ export async function checkLatest(name , file , registry =
|
|
|
192
204
|
}
|
|
193
205
|
const prev = readCache(file);
|
|
194
206
|
const same = prev?.name === name ? prev : null;
|
|
195
|
-
writeCache(file, { name, latest: latest ?? same?.latest, checkedAt: now
|
|
207
|
+
writeCache(file, { ...same, name, latest: latest ?? same?.latest, checkedAt: now });
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* 세션이 시작될 때: delay만큼 기다렸다 묻는다. 그사이 다른 쪽이 이미 물었으면 묻지 않는다
|
|
212
|
+
* (세션 여럿이 한꺼번에 시작해도 npm에는 한 번 묻는다)
|
|
213
|
+
*/
|
|
214
|
+
export async function checkAfter(delay , name , file , registry = REGISTRY, wait = (ms ) => new Promise (r => setTimeout(r, ms))) {
|
|
215
|
+
const since = Date.now();
|
|
216
|
+
await wait(delay);
|
|
217
|
+
const c = readCache(file);
|
|
218
|
+
if (c?.name === name && (c.checkedAt ?? 0) >= since) return;
|
|
219
|
+
await checkLatest(name, file, registry);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/** 이 파일을 직접 실행했나. import.meta.main은 Node 24.2부터라 쓰지 않는다 (muwi는 Node 24.0부터 돈다) */
|
|
223
|
+
function runDirectly() {
|
|
224
|
+
try {
|
|
225
|
+
return Boolean(process.argv[1]) && fs.realpathSync(process.argv[1]) === fs.realpathSync(import.meta.filename);
|
|
226
|
+
} catch {
|
|
227
|
+
return false;
|
|
228
|
+
}
|
|
196
229
|
}
|
|
197
230
|
|
|
198
|
-
if (
|
|
199
|
-
const [name, file] = process.argv.slice(3);
|
|
231
|
+
if (process.argv[2] === '--check' && runDirectly()) {
|
|
232
|
+
const [name, file, delay] = process.argv.slice(3);
|
|
200
233
|
// MUWI_UPDATE_REGISTRY: 시험에서 npm 대신 쓸 주소
|
|
201
|
-
|
|
234
|
+
const registry = process.env.MUWI_UPDATE_REGISTRY || REGISTRY;
|
|
235
|
+
if (name && file) await (Number(delay) > 0 ? checkAfter(Number(delay), name, file, registry) : checkLatest(name, file, registry));
|
|
202
236
|
}
|