@zjex/git-workflow 0.5.1 → 0.5.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/CHANGELOG.md +5 -0
- package/dist/index.js +7 -16
- package/package.json +1 -1
- package/src/update-notifier.ts +3 -19
- package/tests/update-notifier.test.ts +6 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [v0.5.1](https://github.com/iamzjt-front-end/git-workflow/compare/v0.5.0...v0.5.1) (2026-02-06)
|
|
4
|
+
|
|
5
|
+
- 🔖 chore(release): 发布 v0.5.1 ([88c2089](https://github.com/iamzjt-front-end/git-workflow/commit/88c2089))
|
|
6
|
+
- feat(release): 优化发布脚本,自动同步更新 CHANGELOG 和 README 版本号 ([89af235](https://github.com/iamzjt-front-end/git-workflow/commit/89af235))
|
|
7
|
+
|
|
3
8
|
## [v0.5.0](https://github.com/iamzjt-front-end/git-workflow/compare/v0.4.7...v0.5.0) (2026-02-06)
|
|
4
9
|
|
|
5
10
|
- 🔖 chore(release): 发布 v0.5.0 ([51c5740](https://github.com/iamzjt-front-end/git-workflow/commit/51c5740))
|
package/dist/index.js
CHANGED
|
@@ -182,12 +182,11 @@ import { join as join4 } from "path";
|
|
|
182
182
|
import boxen2 from "boxen";
|
|
183
183
|
import { select as select7 } from "@inquirer/prompts";
|
|
184
184
|
import ora5 from "ora";
|
|
185
|
-
import semver from "semver";
|
|
186
185
|
async function checkForUpdates(currentVersion, packageName = "@zjex/git-workflow", interactive = false) {
|
|
187
186
|
try {
|
|
188
187
|
const cache = readCache();
|
|
189
188
|
const now = Date.now();
|
|
190
|
-
if (cache?.latestVersion &&
|
|
189
|
+
if (cache?.latestVersion && cache.latestVersion !== currentVersion) {
|
|
191
190
|
const isDismissed = cache.lastDismiss && now - cache.lastDismiss < DISMISS_INTERVAL;
|
|
192
191
|
if (!isDismissed) {
|
|
193
192
|
if (interactive) {
|
|
@@ -214,20 +213,13 @@ async function checkForUpdates(currentVersion, packageName = "@zjex/git-workflow
|
|
|
214
213
|
}
|
|
215
214
|
}
|
|
216
215
|
function backgroundCheck(currentVersion, packageName) {
|
|
217
|
-
const cache = readCache();
|
|
218
|
-
const now = Date.now();
|
|
219
|
-
const isUpToDate = cache?.latestVersion && !semver.gt(cache.latestVersion, currentVersion);
|
|
220
|
-
const recentlyChecked = cache?.lastCheck && now - cache.lastCheck < CHECK_INTERVAL;
|
|
221
|
-
if (isUpToDate && recentlyChecked) {
|
|
222
|
-
return;
|
|
223
|
-
}
|
|
224
216
|
setImmediate(async () => {
|
|
225
217
|
try {
|
|
226
218
|
const latestVersion = await getLatestVersion(packageName);
|
|
227
219
|
if (latestVersion) {
|
|
228
|
-
const
|
|
220
|
+
const cache = readCache() || {};
|
|
229
221
|
writeCache({
|
|
230
|
-
...
|
|
222
|
+
...cache,
|
|
231
223
|
lastCheck: Date.now(),
|
|
232
224
|
latestVersion,
|
|
233
225
|
checkedVersion: currentVersion
|
|
@@ -393,13 +385,12 @@ function writeCache(cache) {
|
|
|
393
385
|
} catch {
|
|
394
386
|
}
|
|
395
387
|
}
|
|
396
|
-
var DISMISS_INTERVAL,
|
|
388
|
+
var DISMISS_INTERVAL, CACHE_FILE;
|
|
397
389
|
var init_update_notifier = __esm({
|
|
398
390
|
"src/update-notifier.ts"() {
|
|
399
391
|
"use strict";
|
|
400
392
|
init_utils();
|
|
401
393
|
DISMISS_INTERVAL = 1e3 * 60 * 60 * 24;
|
|
402
|
-
CHECK_INTERVAL = 1e3 * 60 * 60 * 1;
|
|
403
394
|
CACHE_FILE = ".gw-update-check";
|
|
404
395
|
}
|
|
405
396
|
});
|
|
@@ -2820,7 +2811,7 @@ init_utils();
|
|
|
2820
2811
|
import { execSync as execSync4, spawn as spawn3 } from "child_process";
|
|
2821
2812
|
import ora6 from "ora";
|
|
2822
2813
|
import boxen3 from "boxen";
|
|
2823
|
-
import
|
|
2814
|
+
import semver from "semver";
|
|
2824
2815
|
import { existsSync as existsSync4, unlinkSync as unlinkSync3 } from "fs";
|
|
2825
2816
|
import { homedir as homedir4 } from "os";
|
|
2826
2817
|
import { join as join5 } from "path";
|
|
@@ -2881,7 +2872,7 @@ async function update(currentVersion) {
|
|
|
2881
2872
|
return;
|
|
2882
2873
|
}
|
|
2883
2874
|
spinner.stop();
|
|
2884
|
-
if (
|
|
2875
|
+
if (semver.gte(currentVersion, latestVersion)) {
|
|
2885
2876
|
console.log(
|
|
2886
2877
|
boxen3(
|
|
2887
2878
|
[
|
|
@@ -4210,7 +4201,7 @@ process.on("SIGTERM", () => {
|
|
|
4210
4201
|
console.log("");
|
|
4211
4202
|
process.exit(0);
|
|
4212
4203
|
});
|
|
4213
|
-
var version = true ? "0.5.
|
|
4204
|
+
var version = true ? "0.5.2" : "0.0.0-dev";
|
|
4214
4205
|
async function mainMenu() {
|
|
4215
4206
|
console.log(
|
|
4216
4207
|
colors.green(`
|
package/package.json
CHANGED
package/src/update-notifier.ts
CHANGED
|
@@ -5,11 +5,9 @@ import { join } from "path";
|
|
|
5
5
|
import boxen from "boxen";
|
|
6
6
|
import { select } from "@inquirer/prompts";
|
|
7
7
|
import ora from "ora";
|
|
8
|
-
import semver from "semver";
|
|
9
8
|
import { colors } from "./utils.js";
|
|
10
9
|
|
|
11
10
|
const DISMISS_INTERVAL = 1000 * 60 * 60 * 24; // 24 小时后再次提示
|
|
12
|
-
const CHECK_INTERVAL = 1000 * 60 * 60 * 1; // 已是最新版本时,1 小时检查一次
|
|
13
11
|
const CACHE_FILE = ".gw-update-check";
|
|
14
12
|
|
|
15
13
|
interface UpdateCache {
|
|
@@ -35,10 +33,10 @@ export async function checkForUpdates(
|
|
|
35
33
|
const cache = readCache();
|
|
36
34
|
const now = Date.now();
|
|
37
35
|
|
|
38
|
-
// 1.
|
|
36
|
+
// 1. 先用缓存的结果提示用户(如果版本不一致)
|
|
39
37
|
if (
|
|
40
38
|
cache?.latestVersion &&
|
|
41
|
-
|
|
39
|
+
cache.latestVersion !== currentVersion
|
|
42
40
|
) {
|
|
43
41
|
// 检查用户是否在 24 小时内关闭过提示
|
|
44
42
|
const isDismissed =
|
|
@@ -76,23 +74,9 @@ export async function checkForUpdates(
|
|
|
76
74
|
|
|
77
75
|
/**
|
|
78
76
|
* 后台异步检查更新(不阻塞)
|
|
79
|
-
*
|
|
80
|
-
* - 已是最新版本时:1 小时检查一次
|
|
77
|
+
* 每次运行命令时都异步检查一次
|
|
81
78
|
*/
|
|
82
79
|
function backgroundCheck(currentVersion: string, packageName: string): void {
|
|
83
|
-
const cache = readCache();
|
|
84
|
-
const now = Date.now();
|
|
85
|
-
|
|
86
|
-
// 如果已是最新版本,且距离上次检查不到 1 小时,跳过
|
|
87
|
-
const isUpToDate =
|
|
88
|
-
cache?.latestVersion && !semver.gt(cache.latestVersion, currentVersion);
|
|
89
|
-
const recentlyChecked =
|
|
90
|
-
cache?.lastCheck && now - cache.lastCheck < CHECK_INTERVAL;
|
|
91
|
-
|
|
92
|
-
if (isUpToDate && recentlyChecked) {
|
|
93
|
-
return;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
80
|
// 使用 setImmediate 确保不阻塞主流程
|
|
97
81
|
setImmediate(async () => {
|
|
98
82
|
try {
|
|
@@ -153,7 +153,7 @@ describe("Update Notifier 模块测试", () => {
|
|
|
153
153
|
consoleSpy.mockRestore();
|
|
154
154
|
});
|
|
155
155
|
|
|
156
|
-
it("
|
|
156
|
+
it("每次运行都应该后台检查最新版本", async () => {
|
|
157
157
|
const mockCache = {
|
|
158
158
|
lastCheck: Date.now(),
|
|
159
159
|
latestVersion: "1.0.0",
|
|
@@ -167,14 +167,13 @@ describe("Update Notifier 模块测试", () => {
|
|
|
167
167
|
await checkForUpdates("1.0.0");
|
|
168
168
|
await vi.runAllTimersAsync();
|
|
169
169
|
|
|
170
|
-
//
|
|
171
|
-
expect(writeFileSync).
|
|
170
|
+
// 每次运行都应该后台检查
|
|
171
|
+
expect(writeFileSync).toHaveBeenCalled();
|
|
172
172
|
});
|
|
173
173
|
|
|
174
|
-
it("
|
|
175
|
-
const oneHourAgo = Date.now() - 2 * 60 * 60 * 1000; // 2小时前
|
|
174
|
+
it("后台检查应该更新缓存中的最新版本", async () => {
|
|
176
175
|
const mockCache = {
|
|
177
|
-
lastCheck:
|
|
176
|
+
lastCheck: Date.now() - 2 * 60 * 60 * 1000,
|
|
178
177
|
latestVersion: "1.0.0",
|
|
179
178
|
checkedVersion: "1.0.0",
|
|
180
179
|
};
|
|
@@ -311,7 +310,7 @@ describe("Update Notifier 模块测试", () => {
|
|
|
311
310
|
{ current: "1.0.0", latest: "1.0.1", shouldShow: true },
|
|
312
311
|
{ current: "1.0.0", latest: "1.1.0", shouldShow: true },
|
|
313
312
|
{ current: "1.0.0", latest: "2.0.0", shouldShow: true },
|
|
314
|
-
{ current: "1.0.1", latest: "1.0.0", shouldShow:
|
|
313
|
+
{ current: "1.0.1", latest: "1.0.0", shouldShow: true }, // 回滚场景也应该提示
|
|
315
314
|
{ current: "1.0.0", latest: "1.0.0", shouldShow: false },
|
|
316
315
|
];
|
|
317
316
|
|