@shipstatic/drop 2.10.3 → 2.10.4-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/dist/index.cjs CHANGED
@@ -182,6 +182,35 @@ function hasUnbuiltMarker(filePath2) {
182
182
  const segments = filePath2.replace(/\\/g, "/").split("/").filter(Boolean);
183
183
  return segments.some((s) => UNBUILT_PROJECT_MARKERS.has(s));
184
184
  }
185
+ var BILLING_RETURNS = {
186
+ checkout: ["upgrading", "true"],
187
+ portal: ["billing", "returned"]
188
+ };
189
+ var marker = (kind) => BILLING_RETURNS[kind].join("=");
190
+ function consolePaths(account) {
191
+ const base = "";
192
+ const at = (path) => `${base}${path}`;
193
+ return {
194
+ dashboard: () => "/",
195
+ newSite: () => at("/new"),
196
+ deployments: Object.assign(() => at("/deployments"), {
197
+ upload: () => at("/deployments/upload")
198
+ }),
199
+ domains: Object.assign(() => at("/domains"), {
200
+ connect: (domain) => at(`/domains/${domain}/connect`),
201
+ deployment: (domain) => at(`/domains/${domain}/deployment`)
202
+ }),
203
+ settings: (fragment) => at(fragment ? `/settings#${fragment}` : "/settings"),
204
+ /** Settings, marked as the landing of a Stripe Customer Portal return. */
205
+ settingsAfterBilling: () => at(`/settings?${marker("portal")}`),
206
+ upgrade: (plan) => at(plan ? `/upgrade/${plan}` : "/upgrade"),
207
+ success: () => at("/success"),
208
+ /** The success page, marked as the landing of a Stripe Checkout return. */
209
+ successAfterCheckout: () => at(`/success?${marker("checkout")}`),
210
+ apiKey: () => at("/api-key")
211
+ };
212
+ }
213
+ `https://my.shipstatic.com${consolePaths().apiKey()}`;
185
214
  var FileValidationStatus = {
186
215
  /** File is pending validation */
187
216
  PENDING: "pending",
@@ -1081,7 +1110,7 @@ var initialState = {
1081
1110
  };
1082
1111
  function useDrop({ ship }) {
1083
1112
  const [state, setState] = react.useState(initialState);
1084
- const isProcessingRef = react.useRef(false);
1113
+ const runRef = react.useRef(null);
1085
1114
  const folderInputRef = react.useRef(null);
1086
1115
  const filesInputRef = react.useRef(null);
1087
1116
  const isProcessing = state.phase === "processing";
@@ -1092,24 +1121,40 @@ function useDrop({ ship }) {
1092
1121
  [state.files]
1093
1122
  );
1094
1123
  const getFilesForUpload = react.useCallback(() => validFiles.map((f) => f.file), [validFiles]);
1095
- const processFiles2 = react.useCallback(
1096
- async (newFiles) => {
1097
- if (isProcessingRef.current) {
1124
+ const prepare = react.useCallback(
1125
+ async (collect) => {
1126
+ if (runRef.current) {
1098
1127
  console.warn("File processing already in progress. Ignoring duplicate call.");
1099
1128
  return;
1100
1129
  }
1101
- if (!newFiles || newFiles.length === 0) return;
1102
- isProcessingRef.current = true;
1130
+ const run = new AbortController();
1131
+ runRef.current = run;
1103
1132
  setState({
1104
1133
  ...initialState,
1105
1134
  phase: "processing",
1106
1135
  status: { title: "Processing...", details: "Validating and preparing files." }
1107
1136
  });
1108
1137
  try {
1109
- const outcome = await processFiles(newFiles, {
1110
- limits: await ship.getLimits(),
1138
+ const [files, limits] = await Promise.all([
1139
+ collect(),
1140
+ ship.getLimits({ signal: run.signal })
1141
+ ]);
1142
+ if (run.signal.aborted) return;
1143
+ if (files.length === 0) {
1144
+ setState({
1145
+ ...initialState,
1146
+ phase: "error",
1147
+ status: { title: "Empty Folder", details: "It has no files to deploy." }
1148
+ });
1149
+ return;
1150
+ }
1151
+ const outcome = await processFiles(files, {
1152
+ limits,
1153
+ // The pipeline says its status before its first wait, so a
1154
+ // cancelled run has none left to say.
1111
1155
  onStatus: (status) => setState((prev) => ({ ...prev, status }))
1112
1156
  });
1157
+ if (run.signal.aborted) return;
1113
1158
  setState({
1114
1159
  phase: outcome.phase,
1115
1160
  isDragging: false,
@@ -1118,15 +1163,33 @@ function useDrop({ ship }) {
1118
1163
  status: outcome.status,
1119
1164
  needsBuild: outcome.needsBuild
1120
1165
  });
1166
+ } catch (error) {
1167
+ if (run.signal.aborted) return;
1168
+ setState({
1169
+ ...initialState,
1170
+ phase: "error",
1171
+ status: {
1172
+ title: "Processing Failed",
1173
+ details: error instanceof Error ? error.message : String(error)
1174
+ }
1175
+ });
1121
1176
  } finally {
1122
- isProcessingRef.current = false;
1177
+ if (runRef.current === run) runRef.current = null;
1123
1178
  }
1124
1179
  },
1125
1180
  [ship]
1126
1181
  );
1182
+ const processFiles2 = react.useCallback(
1183
+ async (newFiles) => {
1184
+ if (!newFiles || newFiles.length === 0) return;
1185
+ await prepare(async () => newFiles);
1186
+ },
1187
+ [prepare]
1188
+ );
1127
1189
  const reset = react.useCallback(() => {
1190
+ runRef.current?.abort();
1191
+ runRef.current = null;
1128
1192
  setState(initialState);
1129
- isProcessingRef.current = false;
1130
1193
  }, []);
1131
1194
  const handleDragOver = react.useCallback((e) => {
1132
1195
  e.preventDefault();
@@ -1161,13 +1224,13 @@ function useDrop({ ship }) {
1161
1224
  if (file) files.push(file);
1162
1225
  }
1163
1226
  }
1164
- await Promise.all(directories.map((d) => traverseFileTree(d.entry, files, d.path)));
1165
- if (files.length === 0 && e.dataTransfer.files.length > 0) {
1166
- files.push(...Array.from(e.dataTransfer.files));
1167
- }
1168
- if (files.length > 0) await processFiles2(files);
1227
+ if (directories.length === 0 && files.length === 0) return;
1228
+ await prepare(async () => {
1229
+ await Promise.all(directories.map((d) => traverseFileTree(d.entry, files, d.path)));
1230
+ return files;
1231
+ });
1169
1232
  },
1170
- [processFiles2]
1233
+ [prepare]
1171
1234
  );
1172
1235
  const handleInputChange = react.useCallback(
1173
1236
  (e) => {