@vizamodo/viza-cli 1.2.21 → 1.2.23
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 +16 -16
- package/package.json +1 -1
package/dist/src/core/version.js
CHANGED
|
@@ -98,27 +98,30 @@ function semverCompare(a, b) {
|
|
|
98
98
|
export async function checkForCliUpdateSoft() {
|
|
99
99
|
const cachePath = resolveUpdateCachePath();
|
|
100
100
|
const now = Date.now();
|
|
101
|
-
const ttl = 3 * 60 * 60 * 1000;
|
|
101
|
+
const ttl = 3 * 60 * 60 * 1000;
|
|
102
|
+
const current = getCliVersion();
|
|
102
103
|
try {
|
|
103
104
|
if (existsSync(cachePath)) {
|
|
104
105
|
const raw = readFileSync(cachePath, "utf8");
|
|
105
106
|
const cached = JSON.parse(raw);
|
|
106
|
-
//
|
|
107
|
-
|
|
108
|
-
if (cached.current && cached.
|
|
109
|
-
// ignore stale cache
|
|
110
|
-
}
|
|
111
|
-
else if (cached.checkedAt && (now - cached.checkedAt) < ttl) {
|
|
107
|
+
// FIX 1: Nếu version local hiện tại khác với version ghi trong cache,
|
|
108
|
+
// nghĩa là user vừa nâng cấp hoặc hạ cấp -> Bỏ qua cache để check mới.
|
|
109
|
+
if (cached.current === current && cached.checkedAt && (now - cached.checkedAt) < ttl) {
|
|
112
110
|
return cached;
|
|
113
111
|
}
|
|
114
112
|
}
|
|
115
113
|
}
|
|
116
114
|
catch {
|
|
117
|
-
// ignore
|
|
115
|
+
// ignore
|
|
118
116
|
}
|
|
119
|
-
const current = getCliVersion();
|
|
120
117
|
try {
|
|
121
|
-
|
|
118
|
+
// FIX 2: Thêm timestamp để đảm bảo lấy data mới nhất từ NPM,
|
|
119
|
+
// tránh trường hợp registry chưa cập nhật kịp edge node.
|
|
120
|
+
const registryUrl = `https://registry.npmjs.org/@vizamodo/viza-cli/latest?t=${now}`;
|
|
121
|
+
const res = await fetch(registryUrl, {
|
|
122
|
+
cache: "no-store",
|
|
123
|
+
headers: { 'Cache-Control': 'no-cache' }
|
|
124
|
+
});
|
|
122
125
|
if (!res.ok)
|
|
123
126
|
return null;
|
|
124
127
|
const json = await res.json();
|
|
@@ -126,7 +129,7 @@ export async function checkForCliUpdateSoft() {
|
|
|
126
129
|
if (!latest || typeof latest !== "string")
|
|
127
130
|
return null;
|
|
128
131
|
const cmp = semverCompare(latest, current);
|
|
129
|
-
const hasUpdate = cmp > 0;
|
|
132
|
+
const hasUpdate = cmp > 1 || (cmp > 0 && current !== "dev"); // "dev" không báo update
|
|
130
133
|
const info = {
|
|
131
134
|
current,
|
|
132
135
|
latest,
|
|
@@ -135,14 +138,11 @@ export async function checkForCliUpdateSoft() {
|
|
|
135
138
|
};
|
|
136
139
|
try {
|
|
137
140
|
const configDir = dirname(cachePath);
|
|
138
|
-
if (!existsSync(configDir))
|
|
141
|
+
if (!existsSync(configDir))
|
|
139
142
|
mkdirSync(configDir, { recursive: true });
|
|
140
|
-
}
|
|
141
143
|
writeFileSync(cachePath, JSON.stringify(info), "utf8");
|
|
142
144
|
}
|
|
143
|
-
catch {
|
|
144
|
-
// ignore write errors
|
|
145
|
-
}
|
|
145
|
+
catch { /* ignore */ }
|
|
146
146
|
return info;
|
|
147
147
|
}
|
|
148
148
|
catch {
|