@shipstatic/drop 2.12.2-beta.0 → 2.13.0-beta.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.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { filterJunk, pluralize, validateFiles, optimizeDeployPaths } from '@shipstatic/ship';
2
+ import ignore from 'ignore';
2
3
  import { useState, useRef, useMemo, useCallback } from 'react';
3
4
 
4
5
  // src/process.ts
@@ -85,9 +86,6 @@ var CLIENT_ONLY_ERROR_TYPES = /* @__PURE__ */ new Set([
85
86
  ErrorType.Config
86
87
  ]);
87
88
  new Set(Object.values(ErrorType).filter((t) => !CLIENT_ONLY_ERROR_TYPES.has(t)));
88
- function isShipError(error) {
89
- return error !== null && typeof error === "object" && "name" in error && error.name === "ShipError" && "status" in error;
90
- }
91
89
  var WEB_FILE_EXTENSIONS = [
92
90
  // Markup & documents
93
91
  "html",
@@ -177,8 +175,8 @@ var UNBUILT_PROJECT_MARKERS = /* @__PURE__ */ new Set([
177
175
  "package.json"
178
176
  ]);
179
177
  function hasUnbuiltMarker(filePath2) {
180
- const segments = filePath2.replace(/\\/g, "/").split("/").filter(Boolean);
181
- return segments.some((s) => UNBUILT_PROJECT_MARKERS.has(s));
178
+ const segments2 = filePath2.replace(/\\/g, "/").split("/").filter(Boolean);
179
+ return segments2.some((s) => UNBUILT_PROJECT_MARKERS.has(s));
182
180
  }
183
181
  var BILLING_RETURNS = {
184
182
  checkout: ["upgrading", "true"],
@@ -266,6 +264,35 @@ function applyStatus(files, status, statusMessage) {
266
264
  ...statusMessage === void 0 ? {} : { statusMessage }
267
265
  }));
268
266
  }
267
+ function segments(file) {
268
+ return filePath(file).replace(/\\/g, "/").split("/").filter(Boolean);
269
+ }
270
+ function rebase(line, base) {
271
+ const pattern = line.replace(/(\\ )? *$/, (_, escaped) => escaped ?? "");
272
+ if (pattern === "" || pattern.startsWith("#")) return null;
273
+ if (base === "") return pattern;
274
+ const negated = pattern.startsWith("!");
275
+ let body = negated ? pattern.slice(1) : pattern;
276
+ const directoryOnly = body.endsWith("/");
277
+ if (directoryOnly) body = body.slice(0, -1);
278
+ const rebased = body.includes("/") ? `${base}/${body.replace(/^\//, "")}` : `${base}/**/${body}`;
279
+ return `${negated ? "!" : ""}${rebased}${directoryOnly ? "/" : ""}`;
280
+ }
281
+ async function projectSource(files) {
282
+ const source = files.filter((file) => !segments(file).includes("node_modules"));
283
+ const rules = source.map((file) => ({ file, parts: segments(file) })).filter(({ parts }) => parts.at(-1) === ".gitignore").sort((a, b) => a.parts.length - b.parts.length);
284
+ if (rules.length === 0) return source;
285
+ const matcher = ignore({ allowRelativePaths: true });
286
+ for (const { file, parts } of rules) {
287
+ const base = parts.slice(0, -1).join("/");
288
+ const text = (await file.text()).replace(/^\uFEFF/, "");
289
+ for (const line of text.split(/\r?\n/)) {
290
+ const pattern = rebase(line, base);
291
+ if (pattern !== null) matcher.add(pattern);
292
+ }
293
+ }
294
+ return source.filter((file) => !matcher.ignores(segments(file).join("/")));
295
+ }
269
296
 
270
297
  // node_modules/.pnpm/fflate@0.8.3/node_modules/fflate/esm/browser.js
271
298
  var ch2 = {};
@@ -977,11 +1004,7 @@ async function processFiles(input, { limits, onStatus }) {
977
1004
  files = input;
978
1005
  }
979
1006
  const needsBuild = files.some((f) => hasUnbuiltMarker(filePath(f)));
980
- if (needsBuild) {
981
- files = files.filter(
982
- (f) => !filePath(f).replace(/\\/g, "/").split("/").includes("node_modules")
983
- );
984
- }
1007
+ if (needsBuild) files = await projectSource(files);
985
1008
  const kept = new Set(filterJunk(files.map(filePath), { allowUnbuilt: needsBuild }));
986
1009
  const finalFiles = stripCommonPrefix(
987
1010
  files.filter((f) => kept.has(filePath(f))).map((f) => createProcessedFile(f))
@@ -1000,7 +1023,7 @@ async function processFiles(input, { limits, onStatus }) {
1000
1023
  };
1001
1024
  }
1002
1025
  if (finalFiles.length > 0 && !finalFiles.some((f) => f.path === "index.html")) {
1003
- const details = "No index.html at root \u2014 the entry point must be in the top-level directory";
1026
+ const details = "There's no index.html at the top of what you dropped. It's the page visitors see first, so your site needs one there.";
1004
1027
  return failure({
1005
1028
  title: CANT_DEPLOY,
1006
1029
  details,
@@ -1051,10 +1074,9 @@ async function processFiles(input, { limits, onStatus }) {
1051
1074
  };
1052
1075
  } catch (error) {
1053
1076
  const message = error instanceof Error ? error.message : String(error);
1054
- const isValidation = isShipError(error);
1055
1077
  return failure({
1056
- title: isValidation ? CANT_DEPLOY : COULDNT_PREPARE,
1057
- details: isValidation ? message : `Failed to process files: ${message}`,
1078
+ title: COULDNT_PREPARE,
1079
+ details: `Failed to process files: ${message}`,
1058
1080
  sourceName
1059
1081
  });
1060
1082
  }