viza 1.7.37 → 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.
@@ -121,32 +121,34 @@ 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
- const meta = {
125
- cliVersion,
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
- const handle = await dispatchIntent(input, mode);
130
- // Non-blocking update check (utility only)
131
- void checkForCliUpdateSoft()
132
- .then((updateInfo) => {
133
- if (!updateInfo?.hasUpdate)
134
- return;
135
- const title = chalk.gray.bold("\n⬆️ Update available");
136
- const ver = chalk.yellow(`${updateInfo.current} → ${updateInfo.latest}`);
137
- const cmd = chalk.cyan("npm i -g viza");
138
- console.log(`\n${title} ${ver}\n${chalk.dim(" Run:")} ${cmd}\n`);
139
- })
140
- .catch(() => {
141
- // best-effort only — never affect dispatch flow
142
- });
143
128
  try {
144
- const result = await handle.wait();
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
145
143
  stopSpinner(spinner, result.status === "success" ? "✅ Done" : "❌ Failed");
144
+ // 5. Render log và thông báo update
146
145
  maybeRenderLog(result, policy);
147
146
  if (result.status !== "success") {
148
147
  throw new Error(`Dispatch failed: ${result.status}`);
149
148
  }
149
+ if (updateInfo?.hasUpdate) {
150
+ renderUpdateHint(updateInfo);
151
+ }
150
152
  return result;
151
153
  }
152
154
  catch (err) {
@@ -154,3 +156,12 @@ export async function dispatchIntentAndWait(input, opts = {}) {
154
156
  throw err;
155
157
  }
156
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
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "viza",
3
- "version": "1.7.37",
3
+ "version": "1.7.41",
4
4
  "type": "module",
5
5
  "description": "Viza unified command line interface",
6
6
  "bin": {