vite-plugin-multiversion 1.0.0 → 1.0.1

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
@@ -83,8 +83,9 @@ VITE_APP_ENV=prod
83
83
  |------|------|--------|------|
84
84
  | outDir | string | 'dist-prod' | 输出目录 |
85
85
  | days | number | 2 | 保留天数 |
86
- | now | number | Date.now() | 当前时间戳(用于测试) |
87
- | minVersions | number | 1 | 最少保留版本数 |
86
+ | now | number | Date.now() | 版本目录名(如时间戳) |
87
+
88
+ > 删除超过指定天数的旧版本,最少保留1个旧版本
88
89
 
89
90
  ## 目录结构
90
91
 
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",
@@ -101,11 +101,10 @@ function cleanOldVersions(options) {
101
101
  }
102
102
  }
103
103
  let deletedCount = 0;
104
- const maxDeletable = oldVersions.length - minVersions;
105
104
  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}`);
105
+ const { dirPath, entryName } = item;
106
+ if (oldVersions.length - deletedCount <= 1) {
107
+ console.log(`[clean-old-versions] \u89E6\u53D1\u6700\u5C11\u4FDD\u7559\u8D85\u8FC71\u5929\u7684\u4E00\u4E2A\u65E7\u5386\u53F2: ${entryName}`);
109
108
  return;
110
109
  }
111
110
  import_node_fs2.default.rmSync(dirPath, { recursive: true, force: true });
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",
@@ -64,11 +64,10 @@ function cleanOldVersions(options) {
64
64
  }
65
65
  }
66
66
  let deletedCount = 0;
67
- const maxDeletable = oldVersions.length - minVersions;
68
67
  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}`);
68
+ const { dirPath, entryName } = item;
69
+ if (oldVersions.length - deletedCount <= 1) {
70
+ console.log(`[clean-old-versions] \u89E6\u53D1\u6700\u5C11\u4FDD\u7559\u8D85\u8FC71\u5929\u7684\u4E00\u4E2A\u65E7\u5386\u53F2: ${entryName}`);
72
71
  return;
73
72
  }
74
73
  fs2.rmSync(dirPath, { recursive: true, force: true });
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.1",
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',
@@ -53,13 +52,12 @@ export function cleanOldVersions(options: CleanOldVersionsOptions): Plugin {
53
52
  }
54
53
 
55
54
  let deletedCount = 0
56
- const maxDeletable = oldVersions.length - minVersions
57
55
 
58
56
  oldVersions.forEach(item => {
59
- const { dirPath, timestamp, entryName } = item
57
+ const { dirPath, entryName } = item
60
58
 
61
- if (deletedCount >= maxDeletable) {
62
- console.log(`[clean-old-versions] 触发最少保留 ${minVersions} 个旧历史: ${entryName}`)
59
+ if (oldVersions.length - deletedCount <= 1) {
60
+ console.log(`[clean-old-versions] 触发最少保留超过1天的一个旧历史: ${entryName}`)
63
61
  return
64
62
  }
65
63