@shipstatic/drop 2.16.1-beta.1 → 2.16.1-beta.10

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/README.md CHANGED
@@ -186,22 +186,25 @@ import { FileValidationStatus } from '@shipstatic/ship';
186
186
  const ready = drop.files.filter(f => f.status === FileValidationStatus.READY);
187
187
  ```
188
188
 
189
- ## Build on upload
189
+ ## A project that isn't built
190
190
 
191
191
  Drop recognises an unbuilt project (source files with `package.json` / `node_modules`) and sets `needsBuild`. `node_modules` stays behind (it is skipped during traversal and stripped from folder-picker selections), and so does whatever the project's `.gitignore` lists, read the way git reads it, so an old `dist/` the project ignores never rides along. A project's source isn't the site, so the deploy rules, the `index.html` at the top among them, don't apply to it: Astro, Next.js, SvelteKit and Eleventy have no `index.html` until they are built, and the rules judge what the build makes. Every file goes straight to `ready`, and the build gives the verdict.
192
192
 
193
- Pass the signal through to the SDK:
193
+ ShipStatic's API publishes the files you send and doesn't build them, so check the signal before you deploy, and ask for the built folder instead:
194
194
 
195
195
  ```tsx
196
- await ship.deployments.upload(drop.getFilesForUpload(), {
197
- build: drop.needsBuild,
198
- prerender: drop.needsBuild,
199
- });
196
+ if (drop.needsBuild) {
197
+ showMessage("This project isn't built yet. Build it, then drop the folder the build makes, like dist.");
198
+ } else {
199
+ await ship.deployments.upload(drop.getFilesForUpload());
200
+ }
200
201
  ```
201
202
 
203
+ ShipStatic's own apps send a project to be built. That isn't part of the public API.
204
+
202
205
  ## ZIP handling
203
206
 
204
- A **single** dropped ZIP is extracted and its contents deployed. ZIPs among several files are treated as ordinary files. Archive paths are sanitized against directory traversal (`../../config.json` → `config.json`).
207
+ A **single** dropped ZIP is extracted and its contents deployed. ZIPs among several files are treated as ordinary files. Archive paths are sanitized against directory traversal (`../../config.json` → `config.json`). A ZIP that can't be read or opened is an error that names it.
205
208
 
206
209
  ## Without React
207
210
 
@@ -213,11 +216,13 @@ import { FileValidationStatus } from '@shipstatic/ship';
213
216
 
214
217
  const outcome = await processFiles(files, { limits: await ship.getLimits() });
215
218
 
216
- if (outcome.phase === 'ready') {
219
+ if (outcome.phase === 'error') {
220
+ console.error(outcome.status.title, outcome.status.details);
221
+ } else if (outcome.needsBuild) {
222
+ console.error("This project isn't built yet. Build it, then drop the folder the build makes.");
223
+ } else {
217
224
  const ready = outcome.files.filter(f => f.status === FileValidationStatus.READY);
218
225
  await ship.deployments.upload(ready.map(f => f.file));
219
- } else {
220
- console.error(outcome.status.title, outcome.status.details);
221
226
  }
222
227
  ```
223
228
 
package/dist/index.cjs CHANGED
@@ -121,7 +121,7 @@ function setRelativePath(file, path) {
121
121
  });
122
122
  }
123
123
  function filePath(file) {
124
- return file.webkitRelativePath?.trim() || file.name;
124
+ return file.webkitRelativePath || file.name;
125
125
  }
126
126
  function createProcessedFile(file, options) {
127
127
  const path = options?.path || filePath(file);
@@ -149,7 +149,7 @@ function siteFiles(files) {
149
149
  }
150
150
  function stripCommonPrefix(files) {
151
151
  const paths = ship.optimizeDeployPaths(files.map((f) => f.path));
152
- return files.map((file, i) => published(file, paths[i].path));
152
+ return files.map((file, i) => published(file, paths[i]));
153
153
  }
154
154
  function applyStatus(files, status, statusMessage) {
155
155
  return files.map((f) => ({
@@ -821,34 +821,34 @@ function unzip(data, opts, cb) {
821
821
 
822
822
  // src/zip.ts
823
823
  async function extractZipToFiles(zipFile) {
824
- try {
825
- const bytes = new Uint8Array(await zipFile.arrayBuffer());
826
- const entries = await new Promise((resolve, reject) => {
827
- unzip(bytes, (err2, data) => err2 ? reject(err2) : resolve(data));
828
- });
829
- const files = [];
830
- const errors = [];
831
- for (const [path, data] of Object.entries(entries)) {
832
- if (path.endsWith("/") && data.length === 0) continue;
833
- const sanitizedPath = normalizePath(path);
834
- if (!sanitizedPath) {
835
- errors.push(`Skipped invalid path: ${path}`);
836
- continue;
837
- }
838
- const filename = sanitizedPath.split("/").pop() || sanitizedPath;
839
- const file = new File([new Uint8Array(data)], filename);
840
- setRelativePath(file, sanitizedPath);
841
- files.push(file);
824
+ const bytes = new Uint8Array(
825
+ await zipFile.arrayBuffer().catch(() => {
826
+ throw new Error(ship.unreadable(zipFile.name));
827
+ })
828
+ );
829
+ const entries = await new Promise((resolve, reject) => {
830
+ unzip(
831
+ bytes,
832
+ (err2, data) => err2 ? reject(
833
+ new Error(`We couldn't open ${zipFile.name}. It may be damaged, or not a ZIP file.`)
834
+ ) : resolve(data)
835
+ );
836
+ });
837
+ const files = [];
838
+ const errors = [];
839
+ for (const [path, data] of Object.entries(entries)) {
840
+ if (path.endsWith("/") && data.length === 0) continue;
841
+ const sanitizedPath = normalizePath(path);
842
+ if (!sanitizedPath) {
843
+ errors.push(`Skipped invalid path: ${path}`);
844
+ continue;
842
845
  }
843
- return { files, errors };
844
- } catch (error) {
845
- return {
846
- files: [],
847
- errors: [
848
- `Failed to load ZIP file: ${error instanceof Error ? error.message : String(error)}`
849
- ]
850
- };
846
+ const filename = sanitizedPath.split("/").pop() || sanitizedPath;
847
+ const file = new File([new Uint8Array(data)], filename);
848
+ setRelativePath(file, sanitizedPath);
849
+ files.push(file);
851
850
  }
851
+ return { files, errors };
852
852
  }
853
853
  function normalizePath(path) {
854
854
  const normalized = [];
@@ -1107,7 +1107,7 @@ function useDrop({ ship }) {
1107
1107
  setState((prev) => prev.isDragging ? { ...prev, isDragging: false } : prev);
1108
1108
  const files = [];
1109
1109
  const directories = [];
1110
- let unreadable2 = false;
1110
+ let unreadable3 = false;
1111
1111
  for (const item of Array.from(e.dataTransfer.items)) {
1112
1112
  if (item.kind !== "file") continue;
1113
1113
  let entry;
@@ -1124,12 +1124,12 @@ function useDrop({ ship }) {
1124
1124
  setRelativePath(file, file.name);
1125
1125
  files.push(file);
1126
1126
  } else {
1127
- unreadable2 = true;
1127
+ unreadable3 = true;
1128
1128
  }
1129
1129
  }
1130
- if (directories.length === 0 && files.length === 0 && !unreadable2) return;
1130
+ if (directories.length === 0 && files.length === 0 && !unreadable3) return;
1131
1131
  await prepare(async () => {
1132
- if (unreadable2) throw new Error(UNREADABLE_DROP);
1132
+ if (unreadable3) throw new Error(UNREADABLE_DROP);
1133
1133
  await Promise.all(directories.map((d) => traverseFileTree(d.entry, files, d.path)));
1134
1134
  return files;
1135
1135
  });