Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"puppeteer": "^24",
"serve-static": "^2.2.0",
"split2": "^4.2.0",
"subresources": "^2.1.0",
"subresources": "^3.0.1",
"yaml": "^2.8.2"
},
"pnpm": {
Expand Down
10 changes: 5 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 20 additions & 3 deletions src/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import * as path from "node:path";
import { copyFile, mkdir, readFile, writeFile, unlink } from "node:fs/promises";
import { Readable } from "node:stream";
import type { ReadableStream } from "node:stream/web";
import { getAllSubResources, type ResourceType } from "subresources";
import type { ResourceType } from "subresources/types";
import { getAllSubResources as domSubResources } from "subresources/dom";
import { getAllSubResources as networkSubResources } from "subresources/network";
import { env, exit, setOutput, sh, unique } from "./utils.ts";
import { deepEqual, StaticServer } from "./utils.ts";
import { PUPPETEER_ENV } from "./constants.ts";
Expand Down Expand Up @@ -195,13 +197,19 @@ async function findAssetsToCopy(source: Input["source"]) {
continue;
}

const allSubResources = getAllSubResources(rootUrl, {
const options = {
links: true,
puppeteerOptions: {
executablePath: PUPPETEER_ENV.PUPPETEER_EXECUTABLE_PATH,
args: ["--no-sandbox"],
},
});
};
// Merge results from both DOM- and network-based collectors
// so we don't miss anything.
const allSubResources = mergeAsyncIterables(
domSubResources(rootUrl, options),
networkSubResources(rootUrl, options),
);
for await (const res of allSubResources) {
const url = new URL(res.url);
if (isLocalAsset(url) && res.type === "link") {
Expand Down Expand Up @@ -308,3 +316,12 @@ function trimList(list: string[], len = 8) {
function urlToPage(url: URL) {
return new URL(url.pathname, url.origin).href;
}

// merge multiple async iterables into a single async iterable.
async function* mergeAsyncIterables<T>(...iters: AsyncIterable<T>[]) {
for (const it of iters) {
for await (const v of it) {
yield v;
}
}
}