Skip to content

Build your personal knowledge base with Trilium Notes

feat(ci/release): drop playwright

Elian Doran6091bffd3807
diff --git a/scripts/generate-flatpak-sources.mts b/scripts/generate-flatpak-sources.mts
index 3db51e6d70..0ec293d886 100644
--- a/scripts/generate-flatpak-sources.mts
+++ b/scripts/generate-flatpak-sources.mts
@@ -16,7 +16,7 @@
*/
import { execFileSync } from "node:child_process";
-import { mkdirSync, readFileSync } from "node:fs";
+import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
import { dirname, join, relative } from "node:path";
const ROOT = join(import.meta.dirname, "..");
@@ -29,10 +29,21 @@ const PNPM_MAJOR = 11;
// defaults to v10 (per-package JSON index files), which pnpm 11 would not find.
const STORE_VERSION = "v11";
+interface Source {
+ dest?: string;
+ url?: string;
+ [key: string]: unknown;
+}
+
export function main() {
checkPnpm(readFileSync(PACKAGE_JSON_PATH, "utf-8"));
generateSources();
- console.log(`Wrote ${relative(ROOT, OUTPUT_PATH)}`);
+
+ const sources: Source[] = JSON.parse(readFileSync(OUTPUT_PATH, "utf-8"));
+ const kept = filterSources(sources);
+ writeFileSync(OUTPUT_PATH, `${JSON.stringify(kept, null, 4)}\n`);
+ console.log(`Wrote ${relative(ROOT, OUTPUT_PATH)}: `
+ + `${kept.length} sources, ${sources.length - kept.length} dropped.`);
}
export function checkPnpm(packageJson: string) {
@@ -47,6 +58,36 @@ export function checkPnpm(packageJson: string) {
}
}
+/**
+ * Drops the Playwright browser archives (~500 MB). They are only reachable from the e2e
+ * suites, which the sandbox build never runs, and Playwright's install script -- the one
+ * reader of this cache -- never executes there either, since the offline store disables
+ * all lifecycle scripts. `--no-devel` is not the answer: the generator does not support
+ * it for pnpm lockfile v9, and the build needs the other devDependencies anyway (Vite,
+ * esbuild and tsx are the build toolchain).
+ *
+ * The generator is installed from its master branch, so the checks guard against its
+ * output drifting: a filter that no longer matches would quietly reship the archives,
+ * and a collapsed count or missing Electron zip would only fail the flatpak build much
+ * later, inside the sandbox.
+ */
+export function filterSources(sources: Source[]): Source[] {
+ const kept = sources.filter((s) => !s.dest?.startsWith("flatpak-node/cache/ms-playwright"));
+
+ if (kept.length === sources.length) {
+ throw new Error("Found no Playwright sources to drop. "
+ + "Did flatpak-node-generator change its cache paths?");
+ }
+ if (kept.length < 2000) {
+ throw new Error(`Only ${kept.length} sources left, expected around 2500.`);
+ }
+ if (!kept.some((s) => /electron-v[\d.]+-linux-x64\.zip$/.test(s.url ?? ""))) {
+ throw new Error("No linux-x64 Electron zip among the sources. "
+ + "The flatpak manifest unpacks it in place of the never-run Electron install script.");
+ }
+ return kept;
+}
+
function generateSources() {
mkdirSync(dirname(OUTPUT_PATH), { recursive: true });
try {
diff --git a/scripts/generate-flatpak-sources.spec.ts b/scripts/generate-flatpak-sources.spec.ts
index f0c3e6ce1f..fab605d6fb 100644
--- a/scripts/generate-flatpak-sources.spec.ts
+++ b/scripts/generate-flatpak-sources.spec.ts
@@ -1,6 +1,6 @@
import { describe, expect, it } from "vitest";
-import { checkPnpm } from "./generate-flatpak-sources.mts";
+import { checkPnpm, filterSources } from "./generate-flatpak-sources.mjs";
describe("checkPnpm", () => {
it("accepts the pinned pnpm major, with or without a corepack checksum", () => {
@@ -14,3 +14,44 @@ describe("checkPnpm", () => {
expect(() => checkPnpm(`{}`)).toThrow(/undefined/);
});
});
+
+describe("filterSources", () => {
+ const tarballs = Array.from({ length: 2500 }, (_, i) => ({
+ type: "file",
+ url: `https://registry.npmjs.org/pkg/-/pkg-${i}.tgz`,
+ dest: "flatpak-node/pnpm-tarballs"
+ }));
+ const electron = {
+ type: "file",
+ url: "https://github.com/electron/electron/releases/download/v44.0.0/electron-v44.0.0-linux-x64.zip",
+ dest: "flatpak-node/cache/electron"
+ };
+ const playwright = [
+ {
+ type: "archive",
+ url: "https://cdn.playwright.dev/builds/cft/151.0/linux64/chrome-linux64.zip",
+ dest: "flatpak-node/cache/ms-playwright/chromium-1234"
+ },
+ {
+ type: "inline",
+ contents: "flatpak-node-cache",
+ dest: "flatpak-node/cache/ms-playwright/chromium-1234"
+ }
+ ];
+
+ it("drops exactly the Playwright cache entries", () => {
+ const kept = filterSources([ ...tarballs, electron, ...playwright ]);
+ expect(kept).toHaveLength(tarballs.length + 1);
+ expect(kept.some((s) => s.dest?.includes("ms-playwright"))).toBe(false);
+ expect(kept).toContain(electron);
+ });
+
+ it("rejects generator output that lost its expected shape", () => {
+ // Nothing matching the filter means the generator moved its cache paths.
+ expect(() => filterSources([ ...tarballs, electron ])).toThrow(/no Playwright/);
+ // A collapsed count means packages went missing wholesale.
+ expect(() => filterSources([ electron, ...playwright ])).toThrow(/expected around 2500/);
+ // The manifest unpacks the Electron zip, so its absence must fail here.
+ expect(() => filterSources([ ...tarballs, ...playwright ])).toThrow(/Electron zip/);
+ });
+});