vite-plugin-multiversion 1.0.0 → 1.0.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/README.md CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  通过打包进行多版本控制的 Vite 插件
4
4
 
5
+
5
6
  ## 安装
6
7
 
7
8
  ```bash
@@ -77,14 +78,15 @@ VITE_APP_ENV=prod
77
78
 
78
79
  ### cleanOldVersions
79
80
 
80
- 删除超过指定天数的旧版本目录。
81
+ 删除超过指定天数的旧版本目录。超过指定天数的删除版本中,会保留至少一个版本,防止出现指定删除x天,x+1天再打包把前面的版本全删掉了(保证打包完除了当前版本,至少还有最后的一个线上版本(超过x天))
81
82
 
82
83
  | 参数 | 类型 | 默认值 | 说明 |
83
84
  |------|------|--------|------|
84
85
  | outDir | string | 'dist-prod' | 输出目录 |
85
86
  | days | number | 2 | 保留天数 |
86
- | now | number | Date.now() | 当前时间戳(用于测试) |
87
- | minVersions | number | 1 | 最少保留版本数 |
87
+ | now | number | Date.now() | 版本目录名(如时间戳) |
88
+
89
+ > 删除超过指定天数的旧版本,最少保留1个旧版本
88
90
 
89
91
  ## 目录结构
90
92
 
package/dist/index.d.mts CHANGED
@@ -10,7 +10,6 @@ interface CleanOldVersionsOptions {
10
10
  outDir?: string;
11
11
  days?: number;
12
12
  now?: number;
13
- minVersions?: number;
14
13
  }
15
14
  declare function cleanOldVersions(options: CleanOldVersionsOptions): Plugin;
16
15
 
package/dist/index.d.ts CHANGED
@@ -10,7 +10,6 @@ interface CleanOldVersionsOptions {
10
10
  outDir?: string;
11
11
  days?: number;
12
12
  now?: number;
13
- minVersions?: number;
14
13
  }
15
14
  declare function cleanOldVersions(options: CleanOldVersionsOptions): Plugin;
16
15
 
package/dist/index.js CHANGED
@@ -68,7 +68,7 @@ function versionLink(options) {
68
68
  var import_node_fs2 = __toESM(require("fs"));
69
69
  var import_node_path2 = __toESM(require("path"));
70
70
  function cleanOldVersions(options) {
71
- const { outDir = "dist-prod", days = 2, now, minVersions = 1 } = options;
71
+ const { outDir = "dist-prod", days = 2, now } = options;
72
72
  return {
73
73
  name: "clean-old-versions",
74
74
  apply: "build",
@@ -100,14 +100,11 @@ function cleanOldVersions(options) {
100
100
  });
101
101
  }
102
102
  }
103
+ const maxOldTimestamp = Math.max(...oldVersions.map((i) => i.timestamp));
104
+ console.log(`[clean-old-versions] \u8D85\u8FC7${days}\u5929\u6700\u5927\u4FDD\u7559\u5386\u53F2\u4E3A:${maxOldTimestamp}`);
103
105
  let deletedCount = 0;
104
- const maxDeletable = oldVersions.length - minVersions;
105
- oldVersions.forEach((item) => {
106
- const { dirPath, timestamp, entryName } = item;
107
- if (deletedCount >= maxDeletable) {
108
- console.log(`[clean-old-versions] \u89E6\u53D1\u6700\u5C11\u4FDD\u7559 ${minVersions} \u4E2A\u65E7\u5386\u53F2: ${entryName}`);
109
- return;
110
- }
106
+ oldVersions.filter((i) => i.timestamp !== maxOldTimestamp).forEach((item) => {
107
+ const { dirPath, entryName } = item;
111
108
  import_node_fs2.default.rmSync(dirPath, { recursive: true, force: true });
112
109
  console.log(`[clean-old-versions] \u5DF2\u5220\u9664: ${entryName}`);
113
110
  deletedCount++;
package/dist/index.mjs CHANGED
@@ -31,7 +31,7 @@ function versionLink(options) {
31
31
  import fs2 from "fs";
32
32
  import path2 from "path";
33
33
  function cleanOldVersions(options) {
34
- const { outDir = "dist-prod", days = 2, now, minVersions = 1 } = options;
34
+ const { outDir = "dist-prod", days = 2, now } = options;
35
35
  return {
36
36
  name: "clean-old-versions",
37
37
  apply: "build",
@@ -63,14 +63,11 @@ function cleanOldVersions(options) {
63
63
  });
64
64
  }
65
65
  }
66
+ const maxOldTimestamp = Math.max(...oldVersions.map((i) => i.timestamp));
67
+ console.log(`[clean-old-versions] \u8D85\u8FC7${days}\u5929\u6700\u5927\u4FDD\u7559\u5386\u53F2\u4E3A:${maxOldTimestamp}`);
66
68
  let deletedCount = 0;
67
- const maxDeletable = oldVersions.length - minVersions;
68
- oldVersions.forEach((item) => {
69
- const { dirPath, timestamp, entryName } = item;
70
- if (deletedCount >= maxDeletable) {
71
- console.log(`[clean-old-versions] \u89E6\u53D1\u6700\u5C11\u4FDD\u7559 ${minVersions} \u4E2A\u65E7\u5386\u53F2: ${entryName}`);
72
- return;
73
- }
69
+ oldVersions.filter((i) => i.timestamp !== maxOldTimestamp).forEach((item) => {
70
+ const { dirPath, entryName } = item;
74
71
  fs2.rmSync(dirPath, { recursive: true, force: true });
75
72
  console.log(`[clean-old-versions] \u5DF2\u5220\u9664: ${entryName}`);
76
73
  deletedCount++;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-multiversion",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "Vite plugin for multi-version control through building",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -6,11 +6,10 @@ export interface CleanOldVersionsOptions {
6
6
  outDir?: string
7
7
  days?: number
8
8
  now?: number
9
- minVersions?: number
10
9
  }
11
10
 
12
11
  export function cleanOldVersions(options: CleanOldVersionsOptions): Plugin {
13
- const { outDir = 'dist-prod', days = 2, now, minVersions = 1 } = options
12
+ const { outDir = 'dist-prod', days = 2, now } = options
14
13
 
15
14
  return {
16
15
  name: 'clean-old-versions',
@@ -51,18 +50,12 @@ export function cleanOldVersions(options: CleanOldVersionsOptions): Plugin {
51
50
  })
52
51
  }
53
52
  }
54
-
53
+ const maxOldTimestamp = Math.max(...oldVersions.map(i => i.timestamp))
54
+ console.log(`[clean-old-versions] 超过${days}天最大保留历史为:${maxOldTimestamp}`)
55
55
  let deletedCount = 0
56
- const maxDeletable = oldVersions.length - minVersions
57
-
58
- oldVersions.forEach(item => {
59
- const { dirPath, timestamp, entryName } = item
60
-
61
- if (deletedCount >= maxDeletable) {
62
- console.log(`[clean-old-versions] 触发最少保留 ${minVersions} 个旧历史: ${entryName}`)
63
- return
64
- }
65
56
 
57
+ oldVersions.filter(i => i.timestamp !== maxOldTimestamp).forEach(item => {
58
+ const { dirPath, entryName } = item
66
59
  fs.rmSync(dirPath, { recursive: true, force: true })
67
60
  console.log(`[clean-old-versions] 已删除: ${entryName}`)
68
61
  deletedCount++