Skip to content

Commit 7fad37e

Browse files
committed
Upload index.html last
1 parent e9b6228 commit 7fad37e

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

src/index.ts

+18-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { readdirSync, readFileSync, statSync } from "fs";
2-
import { extname, join, resolve, sep } from "path";
2+
import { extname, join, resolve, sep, basename } from "path";
33
import { contentType } from "mime-types";
44
import {
55
S3Client,
@@ -94,16 +94,25 @@ async function walkDirectory(
9494
);
9595

9696
let p: Promise<unknown>;
97-
for (const filePath of filePathsToUpload) {
98-
p = q.push(filePath).catch((e) => {
99-
throw e;
100-
});
101-
if (q.length() > 0) {
102-
// backpressure
103-
await p;
97+
98+
// First upload all referenced files (e.g. JS, CSS), only then upload index.html
99+
for (const filter of [
100+
(p: string) => basename(p) !== "index.html", // 1: upload JS, CSS, etc.
101+
(p: string) => basename(p) === "index.html", // 2: upload index.html
102+
]) {
103+
for (const filePath of filePathsToUpload.filter(filter)) {
104+
p = q.push(filePath).catch((e) => {
105+
throw e;
106+
});
107+
if (q.length() > 0) {
108+
// backpressure
109+
await p;
110+
}
104111
}
112+
// await all uploads completed
113+
await q.drained();
105114
}
106-
await q.drained();
115+
107116
return uploadedS3Keys;
108117
}
109118

0 commit comments

Comments
 (0)