viza 1.7.39 → 1.7.41
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/dist/src/core/dispatch.js +28 -14
- package/package.json +1 -1
|
@@ -121,28 +121,33 @@ export async function dispatchIntentAndWait(input, opts = {}) {
|
|
|
121
121
|
const policy = opts.log ?? "hide";
|
|
122
122
|
const mode = resolveExecutionMode(opts);
|
|
123
123
|
const cliVersion = getCliVersion();
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
showDispatchBanner(input, meta, opts.status);
|
|
124
|
+
showDispatchBanner(input, { cliVersion }, opts.status);
|
|
125
|
+
// 1. Khởi tạo các Promise nhưng CHƯA await ngay
|
|
126
|
+
const updateCheckPromise = checkForCliUpdateSoft().catch(() => null);
|
|
128
127
|
const spinner = startSpinner("Waiting for dispatch session");
|
|
129
|
-
// Start update check in parallel (do not block dispatch)
|
|
130
|
-
const updateCheck = checkForCliUpdateSoft().catch(() => null);
|
|
131
|
-
const handle = await dispatchIntent(input, mode);
|
|
132
128
|
try {
|
|
133
|
-
|
|
129
|
+
// 2. Định nghĩa một hàm async để gộp toàn bộ quá trình dispatch
|
|
130
|
+
const dispatchFlow = async () => {
|
|
131
|
+
const handle = await dispatchIntent(input, mode); // Khởi tạo
|
|
132
|
+
return await handle.wait(); // Đợi kết quả
|
|
133
|
+
};
|
|
134
|
+
// Trong block try:
|
|
135
|
+
const [result, updateInfo] = await Promise.all([
|
|
136
|
+
dispatchFlow(),
|
|
137
|
+
Promise.race([
|
|
138
|
+
updateCheckPromise,
|
|
139
|
+
new Promise(res => setTimeout(() => res(null), 3000))
|
|
140
|
+
]) // Ép kiểu tại đây
|
|
141
|
+
]);
|
|
142
|
+
// 4. Dừng spinner và in kết quả dispatch trước
|
|
134
143
|
stopSpinner(spinner, result.status === "success" ? "✅ Done" : "❌ Failed");
|
|
144
|
+
// 5. Render log và thông báo update
|
|
135
145
|
maybeRenderLog(result, policy);
|
|
136
146
|
if (result.status !== "success") {
|
|
137
147
|
throw new Error(`Dispatch failed: ${result.status}`);
|
|
138
148
|
}
|
|
139
|
-
// Render update hint if available (spinner already stopped)
|
|
140
|
-
const updateInfo = await updateCheck;
|
|
141
149
|
if (updateInfo?.hasUpdate) {
|
|
142
|
-
|
|
143
|
-
const ver = chalk.yellow(`${updateInfo.current} → ${updateInfo.latest}`);
|
|
144
|
-
const cmd = chalk.cyan("npm i -g viza");
|
|
145
|
-
console.log(`\n${title} ${ver}\n${chalk.dim(" Run:")} ${cmd}\n`);
|
|
150
|
+
renderUpdateHint(updateInfo);
|
|
146
151
|
}
|
|
147
152
|
return result;
|
|
148
153
|
}
|
|
@@ -151,3 +156,12 @@ export async function dispatchIntentAndWait(input, opts = {}) {
|
|
|
151
156
|
throw err;
|
|
152
157
|
}
|
|
153
158
|
}
|
|
159
|
+
/**
|
|
160
|
+
* Render thông báo cập nhật tách biệt để dễ bảo trì
|
|
161
|
+
*/
|
|
162
|
+
function renderUpdateHint(info) {
|
|
163
|
+
const title = chalk.gray.bold("\n⬆️ Update available");
|
|
164
|
+
const ver = chalk.yellow(`${info.current} → ${info.latest}`);
|
|
165
|
+
const cmd = chalk.cyan("npm i -g viza");
|
|
166
|
+
console.log(`${title} ${ver}\n${chalk.dim(" Run:")} ${cmd}\n`);
|
|
167
|
+
}
|