Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(build): import 'subresources' after setting puppeteer env #186

Merged
merged 6 commits into from
May 29, 2024
Merged
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
10 changes: 6 additions & 4 deletions src/build.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import * as path from "path";
import { copyFile, mkdir, readFile, writeFile, unlink } from "fs/promises";
import fetch from "node-fetch";
import { getAllSubResources, ResourceType } from "subresources";
import { env, exit, setOutput, sh, unique } from "./utils.js";
import { deepEqual, StaticServer } from "./utils.js";
import { PUPPETEER_ENV } from "./constants.js";
import type { ResourceType } from "subresources";

import { BasicBuildOptions as BasicBuildOptions_ } from "./prepare-build.js";
import { ProcessedInput } from "./prepare.js";
Expand Down Expand Up @@ -172,16 +172,18 @@ async function findAssetsToCopy(source: Input["source"]) {
let localAssets: string[] = [];
let remoteAssets: URL[] = [];

Object.assign(process.env, PUPPETEER_ENV);
const {
getAllSubResources,
}: typeof import("subresources") = require("subresources");

const server = await new StaticServer().start();

const isLocalAsset = (url: URL) => url.origin === server.url.origin;
const remoteAssetRules: ((url: URL, type: ResourceType) => boolean)[] = [
(url: URL) => url.origin === "https://user-images.githubusercontent.com",
];

process.env["PUPPETEER_EXECUTABLE_PATH"] =
PUPPETEER_ENV.PUPPETEER_EXECUTABLE_PATH;

const mainPage = urlToPage(new URL(tmpOutputFile(source), server.url));
const pages = new Set([mainPage]);
for (const page of pages) {
Expand Down