@shipstatic/drop 0.3.7 → 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/dist/index.cjs CHANGED
@@ -9384,7 +9384,7 @@ var require_mime_db = __commonJS({
9384
9384
  }
9385
9385
  });
9386
9386
 
9387
- // node_modules/.pnpm/@shipstatic+types@0.9.8/node_modules/@shipstatic/types/dist/index.js
9387
+ // node_modules/.pnpm/@shipstatic+types@1.0.0/node_modules/@shipstatic/types/dist/index.js
9388
9388
  var ErrorType = {
9389
9389
  /** Validation failed (400). Input shape is wrong. */
9390
9390
  Validation: "validation_failed",
@@ -9910,71 +9910,18 @@ function getMimeType(path) {
9910
9910
  const extension = path.includes(".") ? path.substring(path.lastIndexOf(".") + 1).toLowerCase() : "";
9911
9911
  return extensionToMimeMap[extension] || "";
9912
9912
  }
9913
-
9914
- // src/utils/zipExtractor.ts
9915
- async function extractZipToFiles(zipFile) {
9916
- try {
9917
- const arrayBuffer = await zipFile.arrayBuffer();
9918
- const entries = unzipSync(new Uint8Array(arrayBuffer));
9919
- const files = [];
9920
- const errors = [];
9921
- for (const [path, data] of Object.entries(entries)) {
9922
- if (path.endsWith("/") && data.length === 0) continue;
9923
- const sanitizedPath = normalizePath(path);
9924
- if (!sanitizedPath) {
9925
- errors.push(`Skipped invalid path: ${path}`);
9926
- continue;
9927
- }
9928
- const mimeType = getMimeType(sanitizedPath);
9929
- const filename = sanitizedPath.split("/").pop() || sanitizedPath;
9930
- const file = new File([new Uint8Array(data)], filename, {
9931
- type: mimeType
9932
- });
9933
- Object.defineProperty(file, "webkitRelativePath", {
9934
- value: sanitizedPath,
9935
- writable: false,
9936
- configurable: true
9937
- });
9938
- files.push(file);
9939
- }
9940
- return { files, errors };
9941
- } catch (error) {
9942
- return {
9943
- files: [],
9944
- errors: [`Failed to load ZIP file: ${error instanceof Error ? error.message : String(error)}`]
9945
- };
9946
- }
9947
- }
9948
- function normalizePath(path) {
9949
- const segments = path.split("/");
9950
- const normalized = [];
9951
- for (const segment of segments) {
9952
- if (segment === "" || segment === ".") {
9953
- continue;
9954
- }
9955
- if (segment === "..") {
9956
- if (normalized.length > 0) {
9957
- normalized.pop();
9958
- }
9959
- continue;
9960
- }
9961
- normalized.push(segment);
9962
- }
9963
- return normalized.join("/");
9964
- }
9965
- function isZipFile(file) {
9966
- return file.type === "application/zip" || file.type === "application/x-zip-compressed" || file.name.toLowerCase().endsWith(".zip");
9913
+ function setRelativePath(file, path) {
9914
+ Object.defineProperty(file, "webkitRelativePath", {
9915
+ value: path,
9916
+ writable: false,
9917
+ configurable: true
9918
+ });
9967
9919
  }
9968
- var formatFileSize = ship.formatFileSize;
9969
9920
  function createProcessedFile(file, options) {
9970
- const webkitPath = file.webkitRelativePath || "";
9971
- const path = options?.path || (webkitPath && webkitPath.trim() ? webkitPath : file.name);
9972
- const mimeFromDb = getMimeType(path);
9973
- const mimeFromBrowser = file.type;
9974
- const type = mimeFromDb || mimeFromBrowser;
9921
+ const path = options?.path || file.webkitRelativePath?.trim() || file.name;
9922
+ const type = getMimeType(path) || file.type;
9975
9923
  return {
9976
- // ProcessedFile properties
9977
- // Note: md5 is intentionally undefined - Ship SDK will calculate it during deployment
9924
+ // md5 is intentionally undefined — Ship SDK calculates it during deployment.
9978
9925
  id: crypto.randomUUID(),
9979
9926
  file,
9980
9927
  path,
@@ -9987,32 +9934,11 @@ function createProcessedFile(file, options) {
9987
9934
  }
9988
9935
  function stripCommonPrefix(files) {
9989
9936
  if (files.length === 0) return files;
9990
- const paths = files.map((f) => f.path);
9991
- const segments = paths[0].split("/");
9992
- let commonDepth = 0;
9993
- for (let i = 0; i < segments.length - 1; i++) {
9994
- const segment = segments[i];
9995
- if (paths.every((p) => p.split("/")[i] === segment)) {
9996
- commonDepth = i + 1;
9997
- } else {
9998
- break;
9999
- }
10000
- }
10001
- if (commonDepth === 0) return files;
10002
- const prefix = segments.slice(0, commonDepth).join("/") + "/";
10003
- return files.map((f) => {
10004
- const newPath = f.path.startsWith(prefix) ? f.path.slice(prefix.length) : f.path;
10005
- if (f.file) {
10006
- Object.defineProperty(f.file, "webkitRelativePath", {
10007
- value: newPath,
10008
- writable: false,
10009
- configurable: true
10010
- });
10011
- }
10012
- return {
10013
- ...f,
10014
- path: newPath
10015
- };
9937
+ const deployFiles = ship.optimizeDeployPaths(files.map((f) => f.path));
9938
+ return files.map((f, i) => {
9939
+ const newPath = deployFiles[i].path;
9940
+ setRelativePath(f.file, newPath);
9941
+ return { ...f, path: newPath };
10016
9942
  });
10017
9943
  }
10018
9944
  async function traverseFileTree(entry, files, currentPath = "") {
@@ -10022,11 +9948,7 @@ async function traverseFileTree(entry, files, currentPath = "") {
10022
9948
  entry.file(resolve, reject);
10023
9949
  });
10024
9950
  const relativePath = currentPath ? `${currentPath}/${file.name}` : file.name;
10025
- Object.defineProperty(file, "webkitRelativePath", {
10026
- value: relativePath,
10027
- writable: false,
10028
- configurable: true
10029
- });
9951
+ setRelativePath(file, relativePath);
10030
9952
  files.push(file);
10031
9953
  } else if (entry.isDirectory) {
10032
9954
  const dirReader = entry.createReader();
@@ -10055,6 +9977,57 @@ async function traverseFileTree(entry, files, currentPath = "") {
10055
9977
  console.warn(`Error traversing file tree for entry ${entry.name}:`, error);
10056
9978
  }
10057
9979
  }
9980
+
9981
+ // src/utils/zipExtractor.ts
9982
+ async function extractZipToFiles(zipFile) {
9983
+ try {
9984
+ const arrayBuffer = await zipFile.arrayBuffer();
9985
+ const entries = unzipSync(new Uint8Array(arrayBuffer));
9986
+ const files = [];
9987
+ const errors = [];
9988
+ for (const [path, data] of Object.entries(entries)) {
9989
+ if (path.endsWith("/") && data.length === 0) continue;
9990
+ const sanitizedPath = normalizePath(path);
9991
+ if (!sanitizedPath) {
9992
+ errors.push(`Skipped invalid path: ${path}`);
9993
+ continue;
9994
+ }
9995
+ const mimeType = getMimeType(sanitizedPath);
9996
+ const filename = sanitizedPath.split("/").pop() || sanitizedPath;
9997
+ const file = new File([new Uint8Array(data)], filename, {
9998
+ type: mimeType
9999
+ });
10000
+ setRelativePath(file, sanitizedPath);
10001
+ files.push(file);
10002
+ }
10003
+ return { files, errors };
10004
+ } catch (error) {
10005
+ return {
10006
+ files: [],
10007
+ errors: [`Failed to load ZIP file: ${error instanceof Error ? error.message : String(error)}`]
10008
+ };
10009
+ }
10010
+ }
10011
+ function normalizePath(path) {
10012
+ const segments = path.split("/");
10013
+ const normalized = [];
10014
+ for (const segment of segments) {
10015
+ if (segment === "" || segment === ".") {
10016
+ continue;
10017
+ }
10018
+ if (segment === "..") {
10019
+ if (normalized.length > 0) {
10020
+ normalized.pop();
10021
+ }
10022
+ continue;
10023
+ }
10024
+ normalized.push(segment);
10025
+ }
10026
+ return normalized.join("/");
10027
+ }
10028
+ function isZipFile(file) {
10029
+ return file.type === "application/zip" || file.type === "application/x-zip-compressed" || file.name.toLowerCase().endsWith(".zip");
10030
+ }
10058
10031
  var initialState = {
10059
10032
  value: "idle",
10060
10033
  files: [],
@@ -10124,10 +10097,7 @@ function useDrop(options) {
10124
10097
  } else {
10125
10098
  allFiles.push(...newFiles);
10126
10099
  }
10127
- const getFilePath = (f) => {
10128
- const webkitPath = f.webkitRelativePath;
10129
- return webkitPath && webkitPath.trim() ? webkitPath : f.name;
10130
- };
10100
+ const getFilePath = (f) => f.webkitRelativePath?.trim() || f.name;
10131
10101
  let filePaths = allFiles.map(getFilePath);
10132
10102
  const needsBuild = filePaths.some((p) => hasUnbuiltMarker(p));
10133
10103
  if (needsBuild) {
@@ -10183,7 +10153,7 @@ function useDrop(options) {
10183
10153
  files: filesWithStatus2,
10184
10154
  sourceName: detectedSourceName,
10185
10155
  needsBuild: true,
10186
- status: { title: "Ready", details: `${filesWithStatus2.length} file(s) ready \u2014 project will be built` }
10156
+ status: { title: "Ready", details: `${ship.pluralize(filesWithStatus2.length, "file", "files", true)} ready \u2014 project will be built` }
10187
10157
  });
10188
10158
  onFilesReady?.(filesWithStatus2);
10189
10159
  return;
@@ -10211,20 +10181,20 @@ function useDrop(options) {
10211
10181
  needsBuild: false,
10212
10182
  status: {
10213
10183
  title: "Validation Failed",
10214
- details: `${validation.errors.length} file(s) failed validation`,
10184
+ details: `${ship.pluralize(validation.errors.length, "file", "files", true)} failed validation`,
10215
10185
  errors: errorMessages
10216
10186
  }
10217
10187
  });
10218
10188
  onValidationError?.({
10219
10189
  error: "Validation Failed",
10220
- details: `${validation.errors.length} error(s)`,
10190
+ details: ship.pluralize(validation.errors.length, "error", "errors", true),
10221
10191
  errors: errorMessages,
10222
10192
  isClientError: true
10223
10193
  });
10224
10194
  } else if (validation.validFiles.length > 0) {
10225
- let details = `${validation.validFiles.length} file(s) ready`;
10195
+ let details = `${ship.pluralize(validation.validFiles.length, "file", "files", true)} ready`;
10226
10196
  if (validation.warnings.length > 0) {
10227
- details += ` (${validation.warnings.length} empty file(s) excluded)`;
10197
+ details += ` (${ship.pluralize(validation.warnings.length, "empty file", "empty files", true)} excluded)`;
10228
10198
  }
10229
10199
  setState({
10230
10200
  value: "ready",
@@ -10250,7 +10220,7 @@ function useDrop(options) {
10250
10220
  needsBuild: false,
10251
10221
  status: {
10252
10222
  title: "All files excluded",
10253
- details: `${validation.warnings.length} file(s) excluded (empty files cannot be deployed)`,
10223
+ details: `${ship.pluralize(validation.warnings.length, "file", "files", true)} excluded (empty files cannot be deployed)`,
10254
10224
  warnings: validation.warnings.map((w) => `${w.file}: ${w.message}`)
10255
10225
  }
10256
10226
  });
@@ -10277,7 +10247,7 @@ function useDrop(options) {
10277
10247
  const clientError = {
10278
10248
  error: isValidation ? "Validation Failed" : "Processing Failed",
10279
10249
  details: isValidation ? message : `Failed to process files: ${message}`,
10280
- errors: isValidation ? [message] : [],
10250
+ errors: [],
10281
10251
  isClientError: true
10282
10252
  };
10283
10253
  setState({
@@ -10287,8 +10257,7 @@ function useDrop(options) {
10287
10257
  needsBuild: false,
10288
10258
  status: {
10289
10259
  title: clientError.error,
10290
- details: clientError.details,
10291
- ...clientError.errors.length > 0 && { errors: clientError.errors }
10260
+ details: clientError.details
10292
10261
  }
10293
10262
  });
10294
10263
  onValidationError?.(clientError);
@@ -10340,11 +10309,7 @@ function useDrop(options) {
10340
10309
  } else {
10341
10310
  const file = item.getAsFile();
10342
10311
  if (file) {
10343
- Object.defineProperty(file, "webkitRelativePath", {
10344
- value: file.name,
10345
- writable: false,
10346
- configurable: true
10347
- });
10312
+ setRelativePath(file, file.name);
10348
10313
  files.push(file);
10349
10314
  }
10350
10315
  }
@@ -10432,13 +10397,17 @@ mime-db/index.js:
10432
10397
  *)
10433
10398
  */
10434
10399
 
10400
+ Object.defineProperty(exports, "formatFileSize", {
10401
+ enumerable: true,
10402
+ get: function () { return ship.formatFileSize; }
10403
+ });
10435
10404
  exports.FILE_STATUSES = FILE_STATUSES;
10436
10405
  exports.createProcessedFile = createProcessedFile;
10437
10406
  exports.extractZipToFiles = extractZipToFiles;
10438
- exports.formatFileSize = formatFileSize;
10439
10407
  exports.getMimeType = getMimeType;
10440
10408
  exports.isZipFile = isZipFile;
10441
10409
  exports.normalizePath = normalizePath;
10410
+ exports.setRelativePath = setRelativePath;
10442
10411
  exports.stripCommonPrefix = stripCommonPrefix;
10443
10412
  exports.traverseFileTree = traverseFileTree;
10444
10413
  exports.useDrop = useDrop;