vite-plugin-deploy-oss 3.2.0 → 3.2.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.
Files changed (3) hide show
  1. package/README.md +2 -1
  2. package/dist/index.js +32 -11
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -67,7 +67,8 @@ export default {
67
67
  {
68
68
  "file": "assets/index-abc123.js",
69
69
  "key": "H5/zz/test/assets/index-abc123.js",
70
- "url": "https://oss.eventnet.cn/H5/zz/test/assets/index-abc123.js"
70
+ "url": "https://oss.eventnet.cn/H5/zz/test/assets/index-abc123.js",
71
+ "md5": "d41d8cd98f00b204e9800998ecf8427e"
71
72
  }
72
73
  ]
73
74
  }
package/dist/index.js CHANGED
@@ -2,10 +2,21 @@
2
2
  import oss from "ali-oss";
3
3
  import chalk from "chalk";
4
4
  import { globSync } from "glob";
5
+ import { createHash } from "crypto";
6
+ import { createReadStream } from "fs";
5
7
  import { mkdir, readdir, rm, stat, unlink, writeFile } from "fs/promises";
6
8
  import { dirname, resolve } from "path";
7
9
  import ora from "ora";
8
10
  import { normalizePath } from "vite";
11
+ var getFileMd5 = (filePath) => {
12
+ return new Promise((resolve2, reject) => {
13
+ const hash = createHash("md5");
14
+ const stream = createReadStream(filePath);
15
+ stream.on("error", (err) => reject(err));
16
+ stream.on("data", (chunk) => hash.update(chunk));
17
+ stream.on("end", () => resolve2(hash.digest("hex")));
18
+ });
19
+ };
9
20
  var GARBAGE_FILE_REGEX = /(?:Thumbs\.db|\.DS_Store)$/i;
10
21
  var DEFAULT_MANIFEST_FILE_NAME = "oss-manifest.json";
11
22
  var removeEmptyDirectories = async (rootDir) => {
@@ -64,14 +75,24 @@ var resolveUploadedFileUrl = (relativeFilePath, objectKey, configBase, alias) =>
64
75
  if (alias) return joinUrlPath(alias, objectKey);
65
76
  return objectKey;
66
77
  };
67
- var createManifestPayload = (results, configBase, alias) => ({
68
- version: Date.now(),
69
- files: results.filter((result) => result.success).map((result) => ({
70
- file: result.relativeFilePath,
71
- key: result.name,
72
- url: resolveUploadedFileUrl(result.relativeFilePath, result.name, configBase, alias)
73
- }))
74
- });
78
+ var createManifestPayload = async (results, configBase, alias) => {
79
+ const successfulResults = results.filter((result) => result.success);
80
+ const files = await Promise.all(
81
+ successfulResults.map(async (result) => {
82
+ const md5 = await getFileMd5(result.file);
83
+ return {
84
+ file: result.relativeFilePath,
85
+ key: result.name,
86
+ url: resolveUploadedFileUrl(result.relativeFilePath, result.name, configBase, alias),
87
+ md5
88
+ };
89
+ })
90
+ );
91
+ return {
92
+ version: Date.now(),
93
+ files
94
+ };
95
+ };
75
96
  var formatBytes = (bytes) => {
76
97
  if (!Number.isFinite(bytes) || bytes <= 0) return "0 B";
77
98
  const units = ["B", "KB", "MB", "GB", "TB"];
@@ -162,7 +183,7 @@ function vitePluginDeployOss(option) {
162
183
  const headers = {
163
184
  "x-oss-storage-class": "Standard",
164
185
  "x-oss-object-acl": "default",
165
- "Cache-Control": task.cacheControl || (noCache ? "no-cache" : "public, max-age=86400, immutable"),
186
+ "Cache-Control": task.cacheControl || (noCache || task.name.endsWith(".html") ? "no-cache" : "public, max-age=86400, immutable"),
166
187
  "x-oss-forbid-overwrite": overwrite ? "false" : "true"
167
188
  };
168
189
  for (let attempt = 1; attempt <= maxRetries; attempt++) {
@@ -442,7 +463,7 @@ ${chalk.gray("\u7EDF\u8BA1:")}`);
442
463
  await mkdir(dirname(manifestFilePath), { recursive: true });
443
464
  await writeFile(
444
465
  manifestFilePath,
445
- JSON.stringify(createManifestPayload(results, configBase, alias), null, 2),
466
+ JSON.stringify(await createManifestPayload(results, configBase, alias), null, 2),
446
467
  "utf8"
447
468
  );
448
469
  const manifestStats = await stat(manifestFilePath);
@@ -451,7 +472,7 @@ ${chalk.gray("\u7EDF\u8BA1:")}`);
451
472
  relativeFilePath: manifestRelativeFilePath,
452
473
  name: manifestObjectKey,
453
474
  size: manifestStats.size,
454
- cacheControl: "no-cache"
475
+ cacheControl: "no-cache, no-store, must-revalidate"
455
476
  });
456
477
  if (!manifestResult.success) {
457
478
  throw manifestResult.error || new Error(`Failed to upload manifest: ${manifestRelativeFilePath}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-deploy-oss",
3
- "version": "3.2.0",
3
+ "version": "3.2.1",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "type": "module",