vite-plugin-deploy-oss 3.3.0 → 3.3.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/.prettierignore +5 -0
- package/.prettierrc.json +12 -0
- package/README.md +11 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +91 -4
- package/package.json +6 -2
package/.prettierignore
ADDED
package/.prettierrc.json
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json.schemastore.org/prettierrc",
|
|
3
|
+
"arrowParens": "always",
|
|
4
|
+
"bracketSameLine": false,
|
|
5
|
+
"jsxSingleQuote": true,
|
|
6
|
+
"printWidth": 120,
|
|
7
|
+
"quoteProps": "as-needed",
|
|
8
|
+
"semi": false,
|
|
9
|
+
"singleQuote": true,
|
|
10
|
+
"tabWidth": 2,
|
|
11
|
+
"endOfLine": "lf"
|
|
12
|
+
}
|
package/README.md
CHANGED
|
@@ -12,6 +12,14 @@
|
|
|
12
12
|
pnpm add vite-plugin-deploy-oss -D
|
|
13
13
|
```
|
|
14
14
|
|
|
15
|
+
## 调试模式
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
pnpm run build:test:debug
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
这会进入带调试信息的上传模式,构建结束后额外输出每个关键步骤花了多久。
|
|
22
|
+
|
|
15
23
|
## 使用
|
|
16
24
|
|
|
17
25
|
```ts
|
|
@@ -26,6 +34,8 @@ export default {
|
|
|
26
34
|
vitePluginDeployOss({
|
|
27
35
|
// 建议按环境变量开关上传,避免本地/CI误上传
|
|
28
36
|
open: process.env.DEPLOY_OSS === '1',
|
|
37
|
+
// 输出调试耗时信息,方便排查慢在哪里
|
|
38
|
+
debug: process.env.DEPLOY_OSS_DEBUG === '1',
|
|
29
39
|
// 终端实时动效进度面板(默认 true)
|
|
30
40
|
fancy: true,
|
|
31
41
|
|
|
@@ -53,6 +63,7 @@ export default {
|
|
|
53
63
|
|
|
54
64
|
- 当前版本仅支持 ESM(`import`),不再提供 CommonJS(`require`)入口。
|
|
55
65
|
- `open` 默认 `true`,建议通过环境变量控制开关(例如 `DEPLOY_OSS=1` 时再上传)。
|
|
66
|
+
- `debug` 默认关闭。开启后会在结束时额外输出每个关键步骤花了多久,方便排查慢点和卡点。
|
|
56
67
|
- `fancy` 默认 `true`,TTY 终端下会显示实时动效进度(速度、预计剩余、并发、当前文件)。
|
|
57
68
|
- `failOnError` 默认 `true`,上传有失败会抛错,适合 CI 场景保证发布质量。
|
|
58
69
|
- `manifest` 默认关闭。开启后会在构建目录生成并上传 `oss-manifest.json`。
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -179,6 +179,18 @@ ${body}
|
|
|
179
179
|
${bottom}`;
|
|
180
180
|
};
|
|
181
181
|
var renderInlineStats = (items) => items.filter(Boolean).join(chalk2.gray(" \xB7 "));
|
|
182
|
+
var getPanelDot = (tone = "success") => {
|
|
183
|
+
switch (tone) {
|
|
184
|
+
case "info":
|
|
185
|
+
return chalk2.green("\u25CF");
|
|
186
|
+
case "success":
|
|
187
|
+
return chalk2.green("\u25CF");
|
|
188
|
+
case "warning":
|
|
189
|
+
return chalk2.yellow("\u25CF");
|
|
190
|
+
case "danger":
|
|
191
|
+
return chalk2.red("\u25CF");
|
|
192
|
+
}
|
|
193
|
+
};
|
|
182
194
|
var getLogSymbol = (tone) => {
|
|
183
195
|
switch (tone) {
|
|
184
196
|
case "success":
|
|
@@ -191,6 +203,20 @@ var getLogSymbol = (tone) => {
|
|
|
191
203
|
};
|
|
192
204
|
|
|
193
205
|
// src/index.ts
|
|
206
|
+
var formatTimingDuration = (durationMs) => {
|
|
207
|
+
if (durationMs < 1e3) return `${durationMs}ms`;
|
|
208
|
+
const seconds = durationMs / 1e3;
|
|
209
|
+
return `${seconds.toFixed(seconds >= 10 ? 1 : 2)}s`;
|
|
210
|
+
};
|
|
211
|
+
var renderDebugPanel = (entries) => {
|
|
212
|
+
const rows = entries.map((entry) => ({
|
|
213
|
+
label: `${entry.label}:`,
|
|
214
|
+
value: chalk3.cyan(
|
|
215
|
+
entry.detail ? `${formatTimingDuration(entry.durationMs)} \xB7 ${truncateTerminalText(entry.detail, 24)}` : formatTimingDuration(entry.durationMs)
|
|
216
|
+
)
|
|
217
|
+
}));
|
|
218
|
+
return renderPanel(`${getPanelDot("success")} \u8C03\u8BD5\u8017\u65F6`, rows, "info");
|
|
219
|
+
};
|
|
194
220
|
var createManifestPayload = async (results, configBase, alias) => {
|
|
195
221
|
const successfulResults = results.filter((result) => result.success);
|
|
196
222
|
const files = await Promise.all(
|
|
@@ -223,6 +249,7 @@ function vitePluginDeployOss(option) {
|
|
|
223
249
|
autoDelete = false,
|
|
224
250
|
alias,
|
|
225
251
|
open = true,
|
|
252
|
+
debug = false,
|
|
226
253
|
fancy = true,
|
|
227
254
|
noCache = false,
|
|
228
255
|
failOnError = true,
|
|
@@ -334,12 +361,14 @@ function vitePluginDeployOss(option) {
|
|
|
334
361
|
};
|
|
335
362
|
const uploadFilesInBatches = async (client, files, windowSize = concurrency) => {
|
|
336
363
|
const results = [];
|
|
364
|
+
const debugEntries = [];
|
|
337
365
|
const totalFiles = files.length;
|
|
338
366
|
const tasks = [];
|
|
339
367
|
let completed = 0;
|
|
340
368
|
let failed = 0;
|
|
341
369
|
let uploadedBytes = 0;
|
|
342
370
|
let retries = 0;
|
|
371
|
+
const taskPrepareStartedAt = Date.now();
|
|
343
372
|
const taskCandidates = await Promise.all(
|
|
344
373
|
files.map(async (relativeFilePath) => {
|
|
345
374
|
const filePath = normalizePath(resolve2(outDir, relativeFilePath));
|
|
@@ -352,6 +381,11 @@ function vitePluginDeployOss(option) {
|
|
|
352
381
|
}
|
|
353
382
|
})
|
|
354
383
|
);
|
|
384
|
+
debugEntries.push({
|
|
385
|
+
label: "\u751F\u6210\u4E0A\u4F20\u4EFB\u52A1",
|
|
386
|
+
durationMs: Date.now() - taskPrepareStartedAt,
|
|
387
|
+
detail: `${files.length} \u4E2A\u6587\u4EF6`
|
|
388
|
+
});
|
|
355
389
|
for (const candidate of taskCandidates) {
|
|
356
390
|
if (candidate.task) {
|
|
357
391
|
tasks.push(candidate.task);
|
|
@@ -453,7 +487,12 @@ function vitePluginDeployOss(option) {
|
|
|
453
487
|
} else {
|
|
454
488
|
console.log(`${getLogSymbol("success")} \u6240\u6709\u6587\u4EF6\u4E0A\u4F20\u5B8C\u6210 (${totalFiles}/${totalFiles})`);
|
|
455
489
|
}
|
|
456
|
-
|
|
490
|
+
debugEntries.push({
|
|
491
|
+
label: "\u4E0A\u4F20\u6587\u4EF6",
|
|
492
|
+
durationMs: Date.now() - startAt,
|
|
493
|
+
detail: `${tasks.length} \u4E2A\u6210\u529F\u5019\u9009 \xB7 \u5E76\u53D1 ${safeWindowSize}`
|
|
494
|
+
});
|
|
495
|
+
return { results, debugEntries };
|
|
457
496
|
};
|
|
458
497
|
return {
|
|
459
498
|
name: "vite-plugin-deploy-oss",
|
|
@@ -484,13 +523,20 @@ ${validationErrors.map((err) => ` - ${err}`).join("\n")}`);
|
|
|
484
523
|
async handler() {
|
|
485
524
|
if (!open || !upload || buildFailed || !resolvedConfig) return;
|
|
486
525
|
const startTime = Date.now();
|
|
526
|
+
const debugEntries = [];
|
|
487
527
|
const client = new oss({ region, accessKeyId, accessKeySecret, secure, bucket, ...props });
|
|
488
528
|
const manifestFileName = resolveManifestFileName(manifest);
|
|
529
|
+
const collectFilesStartedAt = Date.now();
|
|
489
530
|
const files = globSync("**/*", {
|
|
490
531
|
cwd: outDir,
|
|
491
532
|
nodir: true,
|
|
492
533
|
ignore: Array.isArray(skip) ? skip : [skip]
|
|
493
534
|
}).map((file) => normalizePath(file)).filter((file) => file !== manifestFileName);
|
|
535
|
+
debugEntries.push({
|
|
536
|
+
label: "\u626B\u63CF\u672C\u5730\u6587\u4EF6",
|
|
537
|
+
durationMs: Date.now() - collectFilesStartedAt,
|
|
538
|
+
detail: `${files.length} \u4E2A\u6587\u4EF6`
|
|
539
|
+
});
|
|
494
540
|
if (files.length === 0) {
|
|
495
541
|
console.log(`${getLogSymbol("warning")} \u6CA1\u6709\u627E\u5230\u9700\u8981\u4E0A\u4F20\u7684\u6587\u4EF6`);
|
|
496
542
|
return;
|
|
@@ -498,7 +544,7 @@ ${validationErrors.map((err) => ` - ${err}`).join("\n")}`);
|
|
|
498
544
|
clearViewport();
|
|
499
545
|
console.log(
|
|
500
546
|
renderPanel(
|
|
501
|
-
"\u51C6\u5907\u90E8\u7F72
|
|
547
|
+
`${getPanelDot("success")} \u51C6\u5907\u90E8\u7F72`,
|
|
502
548
|
[
|
|
503
549
|
{ label: "\u4F4D\u7F6E:", value: chalk3.green(`${bucket} \xB7 ${region}`) },
|
|
504
550
|
{
|
|
@@ -519,7 +565,11 @@ ${validationErrors.map((err) => ` - ${err}`).join("\n")}`);
|
|
|
519
565
|
)
|
|
520
566
|
);
|
|
521
567
|
try {
|
|
522
|
-
const
|
|
568
|
+
const uploadExecution = await uploadFilesInBatches(client, files, concurrency);
|
|
569
|
+
const { results, debugEntries: uploadDebugEntries } = uploadExecution;
|
|
570
|
+
if (debug) {
|
|
571
|
+
debugEntries.push(...uploadDebugEntries);
|
|
572
|
+
}
|
|
523
573
|
const successCount = results.filter((r) => r.success).length;
|
|
524
574
|
const failedCount = results.length - successCount;
|
|
525
575
|
const durationSeconds = (Date.now() - startTime) / 1e3;
|
|
@@ -531,13 +581,22 @@ ${validationErrors.map((err) => ` - ${err}`).join("\n")}`);
|
|
|
531
581
|
const manifestRelativeFilePath = manifestFileName;
|
|
532
582
|
const manifestFilePath = normalizePath(resolve2(outDir, manifestRelativeFilePath));
|
|
533
583
|
const manifestObjectKey = normalizeObjectKey(normalizedUploadDir, manifestRelativeFilePath);
|
|
584
|
+
const manifestStartedAt = Date.now();
|
|
534
585
|
await mkdir(dirname(manifestFilePath), { recursive: true });
|
|
535
586
|
await writeFile(
|
|
536
587
|
manifestFilePath,
|
|
537
588
|
JSON.stringify(await createManifestPayload(results, normalizedConfigBase, normalizedAlias), null, 2),
|
|
538
589
|
"utf8"
|
|
539
590
|
);
|
|
591
|
+
if (debug) {
|
|
592
|
+
debugEntries.push({
|
|
593
|
+
label: "\u751F\u6210\u6E05\u5355\u6587\u4EF6",
|
|
594
|
+
durationMs: Date.now() - manifestStartedAt,
|
|
595
|
+
detail: manifestRelativeFilePath
|
|
596
|
+
});
|
|
597
|
+
}
|
|
540
598
|
const manifestStats = await stat(manifestFilePath);
|
|
599
|
+
const manifestUploadStartedAt = Date.now();
|
|
541
600
|
const manifestResult = await uploadSingleTask(client, {
|
|
542
601
|
filePath: manifestFilePath,
|
|
543
602
|
relativeFilePath: manifestRelativeFilePath,
|
|
@@ -548,6 +607,13 @@ ${validationErrors.map((err) => ` - ${err}`).join("\n")}`);
|
|
|
548
607
|
if (!manifestResult.success) {
|
|
549
608
|
throw manifestResult.error || new Error(`Failed to upload manifest: ${manifestRelativeFilePath}`);
|
|
550
609
|
}
|
|
610
|
+
if (debug) {
|
|
611
|
+
debugEntries.push({
|
|
612
|
+
label: "\u4E0A\u4F20\u6E05\u5355\u6587\u4EF6",
|
|
613
|
+
durationMs: Date.now() - manifestUploadStartedAt,
|
|
614
|
+
detail: manifestRelativeFilePath
|
|
615
|
+
});
|
|
616
|
+
}
|
|
551
617
|
const manifestUrl = resolveUploadedFileUrl(
|
|
552
618
|
manifestRelativeFilePath,
|
|
553
619
|
manifestObjectKey,
|
|
@@ -557,7 +623,14 @@ ${validationErrors.map((err) => ` - ${err}`).join("\n")}`);
|
|
|
557
623
|
manifestSummary = truncateTerminalText(manifestUrl || manifestObjectKey, 20);
|
|
558
624
|
}
|
|
559
625
|
try {
|
|
626
|
+
const cleanupStartedAt = Date.now();
|
|
560
627
|
await removeEmptyDirectories(outDir);
|
|
628
|
+
if (debug) {
|
|
629
|
+
debugEntries.push({
|
|
630
|
+
label: "\u6E05\u7406\u7A7A\u76EE\u5F55",
|
|
631
|
+
durationMs: Date.now() - cleanupStartedAt
|
|
632
|
+
});
|
|
633
|
+
}
|
|
561
634
|
} catch (error) {
|
|
562
635
|
console.warn(`${getLogSymbol("warning")} \u6E05\u7406\u7A7A\u76EE\u5F55\u5931\u8D25: ${error}`);
|
|
563
636
|
}
|
|
@@ -596,11 +669,18 @@ ${validationErrors.map((err) => ` - ${err}`).join("\n")}`);
|
|
|
596
669
|
}
|
|
597
670
|
console.log(
|
|
598
671
|
renderPanel(
|
|
599
|
-
failedCount === 0 ? `${
|
|
672
|
+
failedCount === 0 ? `${getPanelDot("success")} \u90E8\u7F72\u5B8C\u6210` : `${getPanelDot("warning")} \u90E8\u7F72\u5B8C\u6210`,
|
|
600
673
|
resultRows,
|
|
601
674
|
failedCount === 0 ? "success" : "warning"
|
|
602
675
|
)
|
|
603
676
|
);
|
|
677
|
+
if (debug) {
|
|
678
|
+
debugEntries.push({
|
|
679
|
+
label: "\u603B\u8017\u65F6",
|
|
680
|
+
durationMs: Date.now() - startTime
|
|
681
|
+
});
|
|
682
|
+
console.log(renderDebugPanel(debugEntries));
|
|
683
|
+
}
|
|
604
684
|
if (failedCount > 0 && failOnError) {
|
|
605
685
|
throw new Error(`Failed to upload ${failedCount} of ${results.length} files`);
|
|
606
686
|
}
|
|
@@ -608,6 +688,13 @@ ${validationErrors.map((err) => ` - ${err}`).join("\n")}`);
|
|
|
608
688
|
console.log(`
|
|
609
689
|
${getLogSymbol("danger")} \u4E0A\u4F20\u8FC7\u7A0B\u4E2D\u53D1\u751F\u9519\u8BEF: ${error}
|
|
610
690
|
`);
|
|
691
|
+
if (debug && debugEntries.length > 0) {
|
|
692
|
+
debugEntries.push({
|
|
693
|
+
label: "\u5931\u8D25\u524D\u8017\u65F6",
|
|
694
|
+
durationMs: Date.now() - startTime
|
|
695
|
+
});
|
|
696
|
+
console.log(renderDebugPanel(debugEntries));
|
|
697
|
+
}
|
|
611
698
|
if (failOnError) {
|
|
612
699
|
throw error instanceof Error ? error : new Error(String(error));
|
|
613
700
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-plugin-deploy-oss",
|
|
3
|
-
"version": "3.3.
|
|
3
|
+
"version": "3.3.1",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"types": "./dist/index.d.ts",
|
|
6
6
|
"type": "module",
|
|
@@ -33,6 +33,7 @@
|
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@types/ali-oss": "^6.23.3",
|
|
35
35
|
"@types/node": "^22.19.13",
|
|
36
|
+
"prettier": "3.8.1",
|
|
36
37
|
"tsup": "^8.5.1",
|
|
37
38
|
"typescript": "^5.9.3"
|
|
38
39
|
},
|
|
@@ -53,7 +54,10 @@
|
|
|
53
54
|
"build": "tsup",
|
|
54
55
|
"typecheck": "tsc -p tsconfig.json",
|
|
55
56
|
"pack": "pnpm run build && pnpm pack",
|
|
57
|
+
"format": "prettier --write .",
|
|
58
|
+
"format:check": "prettier --check .",
|
|
56
59
|
"build:test": "cd playground && vite build",
|
|
57
|
-
"build:test:deploy": "cd playground && vite build --mode deploy"
|
|
60
|
+
"build:test:deploy": "cd playground && vite build --mode deploy",
|
|
61
|
+
"build:test:debug": "cd playground && vite build --mode deploy-debug"
|
|
58
62
|
}
|
|
59
63
|
}
|