@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/README.md CHANGED
@@ -188,7 +188,7 @@ const ready = drop.files.filter(f => f.status === FileValidationStatus.READY);
188
188
 
189
189
  ## Build on upload
190
190
 
191
- Drop recognises an unbuilt project (source files with `package.json` / `node_modules`) and sets `needsBuild`. `node_modules` is skipped during traversal and stripped from folder-picker selections. A project's source isn't the site, so neither the entry-point check nor deploy validation applies to it: Astro, Next.js, SvelteKit and Eleventy have no `index.html` until they are built. Every file goes straight to `ready`, and the build gives the verdict.
191
+ Drop recognises an unbuilt project (source files with `package.json` / `node_modules`) and sets `needsBuild`. The project is sent as its repository holds it: `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/` never rides along. A project's source isn't the site, so neither the entry-point check nor deploy validation applies to it: Astro, Next.js, SvelteKit and Eleventy have no `index.html` until they are built. Every file goes straight to `ready`, and the build gives the verdict.
192
192
 
193
193
  Pass the signal through to the SDK:
194
194
 
package/dist/index.cjs CHANGED
@@ -1,8 +1,13 @@
1
1
  'use strict';
2
2
 
3
3
  var ship = require('@shipstatic/ship');
4
+ var ignore = require('ignore');
4
5
  var react = require('react');
5
6
 
7
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
8
+
9
+ var ignore__default = /*#__PURE__*/_interopDefault(ignore);
10
+
6
11
  // src/process.ts
7
12
  var ErrorType = {
8
13
  /**
@@ -87,9 +92,6 @@ var CLIENT_ONLY_ERROR_TYPES = /* @__PURE__ */ new Set([
87
92
  ErrorType.Config
88
93
  ]);
89
94
  new Set(Object.values(ErrorType).filter((t) => !CLIENT_ONLY_ERROR_TYPES.has(t)));
90
- function isShipError(error) {
91
- return error !== null && typeof error === "object" && "name" in error && error.name === "ShipError" && "status" in error;
92
- }
93
95
  var WEB_FILE_EXTENSIONS = [
94
96
  // Markup & documents
95
97
  "html",
@@ -179,8 +181,8 @@ var UNBUILT_PROJECT_MARKERS = /* @__PURE__ */ new Set([
179
181
  "package.json"
180
182
  ]);
181
183
  function hasUnbuiltMarker(filePath2) {
182
- const segments = filePath2.replace(/\\/g, "/").split("/").filter(Boolean);
183
- return segments.some((s) => UNBUILT_PROJECT_MARKERS.has(s));
184
+ const segments2 = filePath2.replace(/\\/g, "/").split("/").filter(Boolean);
185
+ return segments2.some((s) => UNBUILT_PROJECT_MARKERS.has(s));
184
186
  }
185
187
  var BILLING_RETURNS = {
186
188
  checkout: ["upgrading", "true"],
@@ -268,6 +270,35 @@ function applyStatus(files, status, statusMessage) {
268
270
  ...statusMessage === void 0 ? {} : { statusMessage }
269
271
  }));
270
272
  }
273
+ function segments(file) {
274
+ return filePath(file).replace(/\\/g, "/").split("/").filter(Boolean);
275
+ }
276
+ function rebase(line, base) {
277
+ const pattern = line.replace(/(\\ )? *$/, (_, escaped) => escaped ?? "");
278
+ if (pattern === "" || pattern.startsWith("#")) return null;
279
+ if (base === "") return pattern;
280
+ const negated = pattern.startsWith("!");
281
+ let body = negated ? pattern.slice(1) : pattern;
282
+ const directoryOnly = body.endsWith("/");
283
+ if (directoryOnly) body = body.slice(0, -1);
284
+ const rebased = body.includes("/") ? `${base}/${body.replace(/^\//, "")}` : `${base}/**/${body}`;
285
+ return `${negated ? "!" : ""}${rebased}${directoryOnly ? "/" : ""}`;
286
+ }
287
+ async function projectSource(files) {
288
+ const source = files.filter((file) => !segments(file).includes("node_modules"));
289
+ const rules = source.map((file) => ({ file, parts: segments(file) })).filter(({ parts }) => parts.at(-1) === ".gitignore").sort((a, b) => a.parts.length - b.parts.length);
290
+ if (rules.length === 0) return source;
291
+ const matcher = ignore__default.default({ allowRelativePaths: true });
292
+ for (const { file, parts } of rules) {
293
+ const base = parts.slice(0, -1).join("/");
294
+ const text = (await file.text()).replace(/^\uFEFF/, "");
295
+ for (const line of text.split(/\r?\n/)) {
296
+ const pattern = rebase(line, base);
297
+ if (pattern !== null) matcher.add(pattern);
298
+ }
299
+ }
300
+ return source.filter((file) => !matcher.ignores(segments(file).join("/")));
301
+ }
271
302
 
272
303
  // node_modules/.pnpm/fflate@0.8.3/node_modules/fflate/esm/browser.js
273
304
  var ch2 = {};
@@ -979,11 +1010,7 @@ async function processFiles(input, { limits, onStatus }) {
979
1010
  files = input;
980
1011
  }
981
1012
  const needsBuild = files.some((f) => hasUnbuiltMarker(filePath(f)));
982
- if (needsBuild) {
983
- files = files.filter(
984
- (f) => !filePath(f).replace(/\\/g, "/").split("/").includes("node_modules")
985
- );
986
- }
1013
+ if (needsBuild) files = await projectSource(files);
987
1014
  const kept = new Set(ship.filterJunk(files.map(filePath), { allowUnbuilt: needsBuild }));
988
1015
  const finalFiles = stripCommonPrefix(
989
1016
  files.filter((f) => kept.has(filePath(f))).map((f) => createProcessedFile(f))
@@ -1002,7 +1029,7 @@ async function processFiles(input, { limits, onStatus }) {
1002
1029
  };
1003
1030
  }
1004
1031
  if (finalFiles.length > 0 && !finalFiles.some((f) => f.path === "index.html")) {
1005
- const details = "No index.html at root \u2014 the entry point must be in the top-level directory";
1032
+ 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.";
1006
1033
  return failure({
1007
1034
  title: CANT_DEPLOY,
1008
1035
  details,
@@ -1053,10 +1080,9 @@ async function processFiles(input, { limits, onStatus }) {
1053
1080
  };
1054
1081
  } catch (error) {
1055
1082
  const message = error instanceof Error ? error.message : String(error);
1056
- const isValidation = isShipError(error);
1057
1083
  return failure({
1058
- title: isValidation ? CANT_DEPLOY : COULDNT_PREPARE,
1059
- details: isValidation ? message : `Failed to process files: ${message}`,
1084
+ title: COULDNT_PREPARE,
1085
+ details: `Failed to process files: ${message}`,
1060
1086
  sourceName
1061
1087
  });
1062
1088
  }