vite-plugin-deploy-ftp 3.2.0 → 3.3.0

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/dist/index.js CHANGED
@@ -6,7 +6,6 @@ import cliProgress from "cli-progress";
6
6
  import dayjs from "dayjs";
7
7
  import fs2 from "fs";
8
8
  import { stat } from "fs/promises";
9
- import os2 from "os";
10
9
  import path2 from "path";
11
10
  import ora from "ora";
12
11
  import { normalizePath as normalizePath2 } from "vite";
@@ -33,10 +32,12 @@ function getAllFiles(dirPath, arrayOfFiles = [], relativePath = "") {
33
32
  }
34
33
  function createTempDir(basePath) {
35
34
  const tempBaseDir = os.tmpdir();
36
- const tempPath = path.join(tempBaseDir, "vite-plugin-deploy-ftp", basePath);
37
- if (!fs.existsSync(tempPath)) {
38
- fs.mkdirSync(tempPath, { recursive: true });
35
+ const tempParentDir = path.join(tempBaseDir, "vite-plugin-deploy-ftp");
36
+ const safeBasePath = basePath.replace(/[\\/]+/g, "-").replace(/[^a-zA-Z0-9._-]/g, "-") || "temp";
37
+ if (!fs.existsSync(tempParentDir)) {
38
+ fs.mkdirSync(tempParentDir, { recursive: true });
39
39
  }
40
+ const tempPath = fs.mkdtempSync(path.join(tempParentDir, `${safeBasePath}-`));
40
41
  return {
41
42
  path: tempPath,
42
43
  cleanup: () => {
@@ -706,8 +707,10 @@ function vitePluginDeployFtp(option) {
706
707
  elapsed: formatDuration(elapsedSeconds).replace(/s$/, "")
707
708
  });
708
709
  progressBar.stop();
710
+ } else if (failed > 0) {
711
+ console.log(`${getLogSymbol("warning")} \u6587\u4EF6\u4E0A\u4F20\u7ED3\u675F\uFF0C\u6210\u529F ${completed - failed}/${totalFiles}\uFF0C\u5931\u8D25 ${failed}`);
709
712
  } else {
710
- console.log(`${getLogSymbol("success")} \u6240\u6709\u6587\u4EF6\u4E0A\u4F20\u5B8C\u6210 (${totalFiles}/${totalFiles})`);
713
+ console.log(`${getLogSymbol("success")} \u6587\u4EF6\u4E0A\u4F20\u5B8C\u6210 (${totalFiles}/${totalFiles})`);
711
714
  }
712
715
  debugEntries.push(
713
716
  {
@@ -1035,9 +1038,8 @@ ${getLogSymbol("danger")} \u4E0A\u4F20\u8FC7\u7A0B\u4E2D\u53D1\u751F\u9519\u8BEF
1035
1038
  clearScreen();
1036
1039
  const validationErrors = validateOptions();
1037
1040
  if (validationErrors.length > 0) {
1038
- console.log(`${chalk5.red("\u2717 \u914D\u7F6E\u9519\u8BEF:")}
1041
+ throw new Error(`\u914D\u7F6E\u9519\u8BEF:
1039
1042
  ${validationErrors.map((err) => ` - ${err}`).join("\n")}`);
1040
- return;
1041
1043
  }
1042
1044
  upload = true;
1043
1045
  return config;
@@ -1101,13 +1103,10 @@ async function createBackupFile(client, dir, alias, showBackFile = false, useSpi
1101
1103
  const targetUrl = resolveDisplayUrl(alias, dir);
1102
1104
  const backupSpinner = useSpinner ? ora(`\u521B\u5EFA\u5907\u4EFD\u6587\u4EF6\u4E2D ${chalk5.yellow(`==> ${targetUrl}`)}`).start() : null;
1103
1105
  const fileName = `backup_${dayjs().format("YYYYMMDD_HHmmss")}.zip`;
1104
- const tempDir = createTempDir("backup-zip");
1105
- const zipFilePath = path2.join(os2.tmpdir(), "vite-plugin-deploy-ftp", fileName);
1106
+ const tempDir = createTempDir("backup-download");
1107
+ const zipTempDir = createTempDir("backup-zip");
1108
+ const zipFilePath = path2.join(zipTempDir.path, fileName);
1106
1109
  try {
1107
- const zipDir = path2.dirname(zipFilePath);
1108
- if (!fs2.existsSync(zipDir)) {
1109
- fs2.mkdirSync(zipDir, { recursive: true });
1110
- }
1111
1110
  if (backupSpinner) {
1112
1111
  backupSpinner.text = `\u4E0B\u8F7D\u8FDC\u7A0B\u6587\u4EF6\u4E2D ${chalk5.yellow(`==> ${targetUrl}`)}`;
1113
1112
  }
@@ -1147,6 +1146,7 @@ async function createBackupFile(client, dir, alias, showBackFile = false, useSpi
1147
1146
  throw error;
1148
1147
  } finally {
1149
1148
  tempDir.cleanup();
1149
+ zipTempDir.cleanup();
1150
1150
  try {
1151
1151
  if (fs2.existsSync(zipFilePath)) {
1152
1152
  fs2.rmSync(zipFilePath);
@@ -1162,12 +1162,10 @@ async function createSingleBackup(client, dir, alias, singleBackFiles, showBackF
1162
1162
  const tempDir = createTempDir("single-backup");
1163
1163
  let backupProgressSpinner;
1164
1164
  try {
1165
- const remoteFiles = await client.list(dir);
1166
- const normalizedSingleBackFiles = singleBackFiles.map((fileName) => normalizeSelectionPath(fileName)).filter(Boolean);
1167
- const backupTasks = normalizedSingleBackFiles.map((fileName) => {
1168
- const remoteFile = remoteFiles.find((file) => file.name === fileName);
1169
- return remoteFile ? { fileName, exists: true } : { fileName, exists: false };
1170
- }).filter((task) => task.exists);
1165
+ const normalizedSingleBackFiles = singleBackFiles.map((fileName) => normalizeSelectionPath(fileName)).map(
1166
+ (fileName) => fileName.split("/").filter((segment) => segment && segment !== ".").join("/")
1167
+ ).filter((fileName) => !fileName.split("/").includes("..")).filter(Boolean);
1168
+ const backupTasks = normalizedSingleBackFiles.map((fileName) => ({ fileName }));
1171
1169
  if (backupTasks.length === 0) {
1172
1170
  if (backupSpinner) {
1173
1171
  backupSpinner.warn("\u672A\u627E\u5230\u9700\u8981\u5907\u4EFD\u7684\u6587\u4EF6");
@@ -1185,31 +1183,31 @@ async function createSingleBackup(client, dir, alias, singleBackFiles, showBackF
1185
1183
  if (useSpinner) {
1186
1184
  backupProgressSpinner = ora("\u6B63\u5728\u5907\u4EFD\u6587\u4EF6...").start();
1187
1185
  }
1188
- const concurrencyLimit = 3;
1189
1186
  let backedUpCount = 0;
1190
1187
  const backedUpFiles = [];
1191
- for (let i = 0; i < backupTasks.length; i += concurrencyLimit) {
1192
- const batch = backupTasks.slice(i, i + concurrencyLimit);
1193
- const promises = batch.map(async ({ fileName }) => {
1194
- try {
1195
- const localTempPath = path2.join(tempDir.path, fileName);
1196
- const extIndex = fileName.lastIndexOf(".");
1197
- const name = extIndex > -1 ? fileName.slice(0, extIndex) : fileName;
1198
- const ext = extIndex > -1 ? fileName.slice(extIndex) : "";
1199
- const backupFileName = `${name}.${timestamp}${ext}`;
1200
- const sourceRemotePath = normalizeRemotePath(dir, fileName);
1201
- const backupRemotePath = normalizeRemotePath(dir, backupFileName);
1202
- await client.downloadTo(localTempPath, sourceRemotePath);
1203
- await client.uploadFrom(localTempPath, backupRemotePath);
1204
- backedUpFiles.push(resolveDisplayUrl(alias, backupRemotePath));
1205
- return true;
1206
- } catch (error) {
1207
- console.warn(chalk5.yellow(`\u5907\u4EFD\u6587\u4EF6 ${fileName} \u5931\u8D25:`), error instanceof Error ? error.message : error);
1208
- return false;
1188
+ for (const { fileName } of backupTasks) {
1189
+ try {
1190
+ const localTempPath = path2.join(tempDir.path, fileName);
1191
+ const localTempDir = path2.dirname(localTempPath);
1192
+ if (!fs2.existsSync(localTempDir)) {
1193
+ fs2.mkdirSync(localTempDir, { recursive: true });
1209
1194
  }
1210
- });
1211
- const results = await Promise.all(promises);
1212
- backedUpCount += results.filter(Boolean).length;
1195
+ const fileDir = path2.posix.dirname(fileName);
1196
+ const fileBaseName = path2.posix.basename(fileName);
1197
+ const extIndex = fileBaseName.lastIndexOf(".");
1198
+ const name = extIndex > -1 ? fileBaseName.slice(0, extIndex) : fileBaseName;
1199
+ const ext = extIndex > -1 ? fileBaseName.slice(extIndex) : "";
1200
+ const backupFileName = `${name}.${timestamp}${ext}`;
1201
+ const backupRelativePath = fileDir === "." ? backupFileName : normalizeRemotePath(fileDir, backupFileName);
1202
+ const sourceRemotePath = normalizeRemotePath(dir, fileName);
1203
+ const backupRemotePath = normalizeRemotePath(dir, backupRelativePath);
1204
+ await client.downloadTo(localTempPath, sourceRemotePath);
1205
+ await client.uploadFrom(localTempPath, backupRemotePath);
1206
+ backedUpFiles.push(resolveDisplayUrl(alias, backupRemotePath));
1207
+ backedUpCount++;
1208
+ } catch (error) {
1209
+ console.warn(chalk5.yellow(`\u5907\u4EFD\u6587\u4EF6 ${fileName} \u5931\u8D25:`), error instanceof Error ? error.message : error);
1210
+ }
1213
1211
  }
1214
1212
  if (backedUpCount > 0) {
1215
1213
  backupProgressSpinner?.stop();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-deploy-ftp",
3
- "version": "3.2.0",
3
+ "version": "3.3.0",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "type": "module",
@@ -32,25 +32,25 @@
32
32
  "description": "将dist目录下的文件上传到ftp服务器",
33
33
  "devDependencies": {
34
34
  "@types/cli-progress": "^3.11.6",
35
- "@types/node": "^22.15.32",
36
- "@types/yazl": "^3.3.0",
37
- "prettier": "3.8.1",
38
- "tsup": "^8.5.0",
39
- "typescript": "^5.8.3"
35
+ "@types/node": "^25.7.0",
36
+ "@types/yazl": "^3.3.1",
37
+ "prettier": "3.8.3",
38
+ "tsup": "^8.5.1",
39
+ "typescript": "^5.9.3"
40
40
  },
41
41
  "peerDependencies": {
42
42
  "vite": "^6.0.3 || ^7 || ^8"
43
43
  },
44
44
  "dependencies": {
45
- "@inquirer/prompts": "^7.5.3",
46
- "basic-ftp": "^5.0.5",
47
- "chalk": "^5.4.1",
45
+ "@inquirer/prompts": "^8.4.3",
46
+ "basic-ftp": "^6.0.1",
47
+ "chalk": "^5.6.2",
48
48
  "cli-progress": "^3.12.0",
49
- "cli-truncate": "^5.2.0",
50
- "dayjs": "^1.11.13",
49
+ "cli-truncate": "^6.0.0",
50
+ "dayjs": "^1.11.20",
51
51
  "log-symbols": "^7.0.1",
52
- "ora": "^8.2.0",
53
- "string-width": "^8.2.0",
52
+ "ora": "^9.4.0",
53
+ "string-width": "^8.2.1",
54
54
  "yazl": "^3.3.1"
55
55
  },
56
56
  "scripts": {
@@ -0,0 +1,2 @@
1
+ allowBuilds:
2
+ esbuild: false