@vizamodo/viza-cli 1.2.32 → 1.2.34
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/version.js +6 -20
- package/package.json +1 -1
package/dist/src/core/version.js
CHANGED
|
@@ -98,36 +98,22 @@ function semverCompare(a, b) {
|
|
|
98
98
|
export async function checkForCliUpdateSoft() {
|
|
99
99
|
const cachePath = resolveUpdateCachePath();
|
|
100
100
|
const now = Date.now();
|
|
101
|
-
const ttl = 10 * 60 * 1000;
|
|
101
|
+
const ttl = 10 * 60 * 1000; // 10 minutes (Fixed window)
|
|
102
102
|
const current = getCliVersion();
|
|
103
103
|
try {
|
|
104
104
|
if (existsSync(cachePath)) {
|
|
105
105
|
const raw = readFileSync(cachePath, "utf8");
|
|
106
106
|
const cached = JSON.parse(raw);
|
|
107
|
-
//
|
|
108
|
-
//
|
|
107
|
+
// Kiểm tra Version Mismatch HOẶC Cache Expired
|
|
108
|
+
// KHÔNG cập nhật checkedAt ở đây để đảm bảo đúng 10p sẽ check lại 1 lần
|
|
109
109
|
if (cached.current === current && cached.checkedAt && (now - cached.checkedAt) < ttl) {
|
|
110
|
-
// Sliding TTL: refresh checkedAt when serving cache
|
|
111
|
-
cached.checkedAt = now;
|
|
112
|
-
try {
|
|
113
|
-
const configDir = dirname(cachePath);
|
|
114
|
-
if (!existsSync(configDir))
|
|
115
|
-
mkdirSync(configDir, { recursive: true });
|
|
116
|
-
writeFileSync(cachePath, JSON.stringify(cached), "utf8");
|
|
117
|
-
}
|
|
118
|
-
catch {
|
|
119
|
-
// ignore
|
|
120
|
-
}
|
|
121
110
|
return cached;
|
|
122
111
|
}
|
|
123
112
|
}
|
|
124
113
|
}
|
|
125
|
-
catch {
|
|
126
|
-
|
|
127
|
-
}
|
|
114
|
+
catch { /* ignore */ }
|
|
115
|
+
// --- Bắt đầu Fetch mới khi cache hết hạn hoặc sai version ---
|
|
128
116
|
try {
|
|
129
|
-
// FIX 2: Thêm timestamp để đảm bảo lấy data mới nhất từ NPM,
|
|
130
|
-
// tránh trường hợp registry chưa cập nhật kịp edge node.
|
|
131
117
|
const registryUrl = `https://registry.npmjs.org/@vizamodo/viza-cli/latest?t=${now}`;
|
|
132
118
|
const res = await fetch(registryUrl, {
|
|
133
119
|
cache: "no-store",
|
|
@@ -145,7 +131,7 @@ export async function checkForCliUpdateSoft() {
|
|
|
145
131
|
current,
|
|
146
132
|
latest,
|
|
147
133
|
hasUpdate,
|
|
148
|
-
checkedAt: now,
|
|
134
|
+
checkedAt: now, // Chỉ cập nhật mốc thời gian tại đây
|
|
149
135
|
};
|
|
150
136
|
try {
|
|
151
137
|
const configDir = dirname(cachePath);
|