@shipstatic/drop 2.16.1-beta.7 → 2.16.1-beta.9

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
@@ -1,4 +1,4 @@
1
- import { pluralize, validateFiles, optimizeDeployPaths, sitePaths, unreadable } from '@shipstatic/ship';
1
+ import { pluralize, validateFiles, unreadable, optimizeDeployPaths, sitePaths } from '@shipstatic/ship';
2
2
  import ignore from 'ignore';
3
3
  import { useState, useRef, useMemo, useCallback } from 'react';
4
4
 
@@ -115,7 +115,7 @@ function setRelativePath(file, path) {
115
115
  });
116
116
  }
117
117
  function filePath(file) {
118
- return file.webkitRelativePath?.trim() || file.name;
118
+ return file.webkitRelativePath || file.name;
119
119
  }
120
120
  function createProcessedFile(file, options) {
121
121
  const path = options?.path || filePath(file);
@@ -815,34 +815,34 @@ function unzip(data, opts, cb) {
815
815
 
816
816
  // src/zip.ts
817
817
  async function extractZipToFiles(zipFile) {
818
- try {
819
- const bytes = new Uint8Array(await zipFile.arrayBuffer());
820
- const entries = await new Promise((resolve, reject) => {
821
- unzip(bytes, (err2, data) => err2 ? reject(err2) : resolve(data));
822
- });
823
- const files = [];
824
- const errors = [];
825
- for (const [path, data] of Object.entries(entries)) {
826
- if (path.endsWith("/") && data.length === 0) continue;
827
- const sanitizedPath = normalizePath(path);
828
- if (!sanitizedPath) {
829
- errors.push(`Skipped invalid path: ${path}`);
830
- continue;
831
- }
832
- const filename = sanitizedPath.split("/").pop() || sanitizedPath;
833
- const file = new File([new Uint8Array(data)], filename);
834
- setRelativePath(file, sanitizedPath);
835
- files.push(file);
818
+ const bytes = new Uint8Array(
819
+ await zipFile.arrayBuffer().catch(() => {
820
+ throw new Error(unreadable(zipFile.name));
821
+ })
822
+ );
823
+ const entries = await new Promise((resolve, reject) => {
824
+ unzip(
825
+ bytes,
826
+ (err2, data) => err2 ? reject(
827
+ new Error(`We couldn't open ${zipFile.name}. It may be damaged, or not a ZIP file.`)
828
+ ) : resolve(data)
829
+ );
830
+ });
831
+ const files = [];
832
+ const errors = [];
833
+ for (const [path, data] of Object.entries(entries)) {
834
+ if (path.endsWith("/") && data.length === 0) continue;
835
+ const sanitizedPath = normalizePath(path);
836
+ if (!sanitizedPath) {
837
+ errors.push(`Skipped invalid path: ${path}`);
838
+ continue;
836
839
  }
837
- return { files, errors };
838
- } catch (error) {
839
- return {
840
- files: [],
841
- errors: [
842
- `Failed to load ZIP file: ${error instanceof Error ? error.message : String(error)}`
843
- ]
844
- };
840
+ const filename = sanitizedPath.split("/").pop() || sanitizedPath;
841
+ const file = new File([new Uint8Array(data)], filename);
842
+ setRelativePath(file, sanitizedPath);
843
+ files.push(file);
845
844
  }
845
+ return { files, errors };
846
846
  }
847
847
  function normalizePath(path) {
848
848
  const normalized = [];
@@ -1101,7 +1101,7 @@ function useDrop({ ship }) {
1101
1101
  setState((prev) => prev.isDragging ? { ...prev, isDragging: false } : prev);
1102
1102
  const files = [];
1103
1103
  const directories = [];
1104
- let unreadable2 = false;
1104
+ let unreadable3 = false;
1105
1105
  for (const item of Array.from(e.dataTransfer.items)) {
1106
1106
  if (item.kind !== "file") continue;
1107
1107
  let entry;
@@ -1118,12 +1118,12 @@ function useDrop({ ship }) {
1118
1118
  setRelativePath(file, file.name);
1119
1119
  files.push(file);
1120
1120
  } else {
1121
- unreadable2 = true;
1121
+ unreadable3 = true;
1122
1122
  }
1123
1123
  }
1124
- if (directories.length === 0 && files.length === 0 && !unreadable2) return;
1124
+ if (directories.length === 0 && files.length === 0 && !unreadable3) return;
1125
1125
  await prepare(async () => {
1126
- if (unreadable2) throw new Error(UNREADABLE_DROP);
1126
+ if (unreadable3) throw new Error(UNREADABLE_DROP);
1127
1127
  await Promise.all(directories.map((d) => traverseFileTree(d.entry, files, d.path)));
1128
1128
  return files;
1129
1129
  });