@shipstatic/drop 2.12.1 → 2.13.0-beta.0
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 +2 -2
- package/dist/index.cjs +48 -22
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +44 -22
- package/dist/index.js.map +1 -1
- package/package.json +3 -2
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,
|
|
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
|
|
|
@@ -221,7 +221,7 @@ if (outcome.phase === 'ready') {
|
|
|
221
221
|
}
|
|
222
222
|
```
|
|
223
223
|
|
|
224
|
-
It never throws
|
|
224
|
+
It never throws: a missing entry point, an oversized file, and an unexpected failure all come back as an `error` outcome. Pass `onStatus` to report progress during extraction.
|
|
225
225
|
|
|
226
226
|
## Testing your components
|
|
227
227
|
|
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
|
/**
|
|
@@ -179,8 +184,8 @@ var UNBUILT_PROJECT_MARKERS = /* @__PURE__ */ new Set([
|
|
|
179
184
|
"package.json"
|
|
180
185
|
]);
|
|
181
186
|
function hasUnbuiltMarker(filePath2) {
|
|
182
|
-
const
|
|
183
|
-
return
|
|
187
|
+
const segments2 = filePath2.replace(/\\/g, "/").split("/").filter(Boolean);
|
|
188
|
+
return segments2.some((s) => UNBUILT_PROJECT_MARKERS.has(s));
|
|
184
189
|
}
|
|
185
190
|
var BILLING_RETURNS = {
|
|
186
191
|
checkout: ["upgrading", "true"],
|
|
@@ -268,6 +273,35 @@ function applyStatus(files, status, statusMessage) {
|
|
|
268
273
|
...statusMessage === void 0 ? {} : { statusMessage }
|
|
269
274
|
}));
|
|
270
275
|
}
|
|
276
|
+
function segments(file) {
|
|
277
|
+
return filePath(file).replace(/\\/g, "/").split("/").filter(Boolean);
|
|
278
|
+
}
|
|
279
|
+
function rebase(line, base) {
|
|
280
|
+
const pattern = line.replace(/(?<!\\) +$/, "");
|
|
281
|
+
if (pattern === "" || pattern.startsWith("#")) return null;
|
|
282
|
+
if (base === "") return pattern;
|
|
283
|
+
const negated = pattern.startsWith("!");
|
|
284
|
+
let body = negated ? pattern.slice(1) : pattern;
|
|
285
|
+
const directoryOnly = body.endsWith("/");
|
|
286
|
+
if (directoryOnly) body = body.slice(0, -1);
|
|
287
|
+
const rebased = body.includes("/") ? `${base}/${body.replace(/^\//, "")}` : `${base}/**/${body}`;
|
|
288
|
+
return `${negated ? "!" : ""}${rebased}${directoryOnly ? "/" : ""}`;
|
|
289
|
+
}
|
|
290
|
+
async function projectSource(files) {
|
|
291
|
+
const source = files.filter((file) => !segments(file).includes("node_modules"));
|
|
292
|
+
const rules = source.map((file) => ({ file, parts: segments(file) })).filter(({ parts }) => parts.at(-1) === ".gitignore").sort((a, b) => a.parts.length - b.parts.length);
|
|
293
|
+
if (rules.length === 0) return source;
|
|
294
|
+
const matcher = ignore__default.default({ allowRelativePaths: true });
|
|
295
|
+
for (const { file, parts } of rules) {
|
|
296
|
+
const base = parts.slice(0, -1).join("/");
|
|
297
|
+
const text = (await file.text()).replace(/^\uFEFF/, "");
|
|
298
|
+
for (const line of text.split(/\r?\n/)) {
|
|
299
|
+
const pattern = rebase(line, base);
|
|
300
|
+
if (pattern !== null) matcher.add(pattern);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
return source.filter((file) => !matcher.ignores(segments(file).join("/")));
|
|
304
|
+
}
|
|
271
305
|
|
|
272
306
|
// node_modules/.pnpm/fflate@0.8.3/node_modules/fflate/esm/browser.js
|
|
273
307
|
var ch2 = {};
|
|
@@ -953,12 +987,12 @@ function detectSourceName(files) {
|
|
|
953
987
|
return path.includes("/") ? path.split("/")[0] : first.name;
|
|
954
988
|
}
|
|
955
989
|
function failure(params) {
|
|
956
|
-
const { title, details, errors, files = [], sourceName
|
|
990
|
+
const { title, details, errors, files = [], sourceName } = params;
|
|
957
991
|
return {
|
|
958
992
|
phase: "error",
|
|
959
993
|
files,
|
|
960
994
|
sourceName,
|
|
961
|
-
needsBuild,
|
|
995
|
+
needsBuild: false,
|
|
962
996
|
// `details` carries the single user-facing message; `errors` is for per-item
|
|
963
997
|
// breakdowns. Omitted when empty, otherwise consumers that render both
|
|
964
998
|
// fields show the message twice.
|
|
@@ -979,28 +1013,11 @@ async function processFiles(input, { limits, onStatus }) {
|
|
|
979
1013
|
files = input;
|
|
980
1014
|
}
|
|
981
1015
|
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
|
-
}
|
|
1016
|
+
if (needsBuild) files = await projectSource(files);
|
|
987
1017
|
const kept = new Set(ship.filterJunk(files.map(filePath), { allowUnbuilt: needsBuild }));
|
|
988
1018
|
const finalFiles = stripCommonPrefix(
|
|
989
1019
|
files.filter((f) => kept.has(filePath(f))).map((f) => createProcessedFile(f))
|
|
990
1020
|
);
|
|
991
|
-
if (finalFiles.length > 0) {
|
|
992
|
-
const hasIndex = needsBuild ? finalFiles.some((f) => f.path === "index.html" || f.path.endsWith("/index.html")) : finalFiles.some((f) => f.path === "index.html");
|
|
993
|
-
if (!hasIndex) {
|
|
994
|
-
const details = needsBuild ? "No index.html found \u2014 every web project needs an index.html entry point" : "No index.html at root \u2014 the entry point must be in the top-level directory";
|
|
995
|
-
return failure({
|
|
996
|
-
title: CANT_DEPLOY,
|
|
997
|
-
details,
|
|
998
|
-
sourceName,
|
|
999
|
-
needsBuild,
|
|
1000
|
-
files: applyStatus(finalFiles, FileValidationStatus.VALIDATION_FAILED, details)
|
|
1001
|
-
});
|
|
1002
|
-
}
|
|
1003
|
-
}
|
|
1004
1021
|
if (needsBuild) {
|
|
1005
1022
|
const ready = applyStatus(finalFiles, FileValidationStatus.READY);
|
|
1006
1023
|
return {
|
|
@@ -1014,6 +1031,15 @@ async function processFiles(input, { limits, onStatus }) {
|
|
|
1014
1031
|
}
|
|
1015
1032
|
};
|
|
1016
1033
|
}
|
|
1034
|
+
if (finalFiles.length > 0 && !finalFiles.some((f) => f.path === "index.html")) {
|
|
1035
|
+
const details = "No index.html at root \u2014 the entry point must be in the top-level directory";
|
|
1036
|
+
return failure({
|
|
1037
|
+
title: CANT_DEPLOY,
|
|
1038
|
+
details,
|
|
1039
|
+
sourceName,
|
|
1040
|
+
files: applyStatus(finalFiles, FileValidationStatus.VALIDATION_FAILED, details)
|
|
1041
|
+
});
|
|
1042
|
+
}
|
|
1017
1043
|
const validation = ship.validateFiles(finalFiles.map(toValidatable), limits);
|
|
1018
1044
|
const validated = finalFiles.map((file, i) => ({
|
|
1019
1045
|
...file,
|