From 410c953933083d6ea8211bb103efe73a02e96d6b Mon Sep 17 00:00:00 2001 From: StroepWafel Date: Mon, 22 Jun 2026 23:37:06 +0930 Subject: [PATCH] Fix CI errors --- .github/actions/build-extension/action.yml | 4 +- .github/workflows/pr-ci.yml | 10 +- package.json | 5 +- scripts/compile-layerchart-vendor.mjs | 113 ++++++++++++++++++ .../components/store/ThemeModal.svelte | 2 +- src/interface/pages/settings.svelte | 11 +- .../src/utils/HighlightedText.svelte | 2 +- vite.config.ts | 41 ++++--- 8 files changed, 158 insertions(+), 30 deletions(-) create mode 100644 scripts/compile-layerchart-vendor.mjs diff --git a/.github/actions/build-extension/action.yml b/.github/actions/build-extension/action.yml index 6cd68c9e..2e6afc8a 100644 --- a/.github/actions/build-extension/action.yml +++ b/.github/actions/build-extension/action.yml @@ -33,10 +33,10 @@ outputs: runs: using: composite steps: - - name: Use Node.js 20.x + - name: Use Node.js 22.x uses: actions/setup-node@v4 with: - node-version: 20.x + node-version: 22.x - name: Install dependencies shell: bash diff --git a/.github/workflows/pr-ci.yml b/.github/workflows/pr-ci.yml index dbc5ab58..40d40d17 100644 --- a/.github/workflows/pr-ci.yml +++ b/.github/workflows/pr-ci.yml @@ -6,14 +6,18 @@ on: jobs: ci: - runs-on: ubuntu-latest + # windows-latest: Vite/Svelte build fails on Linux CI for layerchart vendor .svelte (see nightly.yml). + runs-on: windows-latest + defaults: + run: + shell: bash steps: - uses: actions/checkout@v4 - - name: Use Node.js 20.x + - name: Use Node.js 22.x uses: actions/setup-node@v4 with: - node-version: 20.x + node-version: 22.x - name: Install dependencies run: npm install --legacy-peer-deps diff --git a/package.json b/package.json index f3e12894..a943c4d6 100644 --- a/package.json +++ b/package.json @@ -5,12 +5,13 @@ "description": "Enhance SEQTA Learn's usability and aesthetics! A fork of BetterSEQTA to continue development and add heaps more features!", "browserslist": "> 0.5%, last 2 versions, not dead", "scripts": { - "postinstall": "node scripts/copy-pdfjs-assets.mjs", + "compile:layerchart": "node scripts/compile-layerchart-vendor.mjs", + "postinstall": "node scripts/copy-pdfjs-assets.mjs && npm run compile:layerchart", "autoaudit": "npm audit && npm audit fix && npm run build", "dev": "cross-env MODE=chrome vite dev", "dev:firefox": "cross-env MODE=firefox vite build --watch", "compile": "npm i && npm run build", - "build": "cross-env MODE=chrome vite build && cross-env MODE=firefox vite build", + "build": "npm run compile:layerchart && cross-env MODE=chrome vite build && cross-env MODE=firefox vite build", "build:chrome": "cross-env MODE=chrome vite build", "build:firefox": "cross-env MODE=firefox vite build", "build:safari": "cross-env MODE=safari vite build", diff --git a/scripts/compile-layerchart-vendor.mjs b/scripts/compile-layerchart-vendor.mjs new file mode 100644 index 00000000..6aa7c81c --- /dev/null +++ b/scripts/compile-layerchart-vendor.mjs @@ -0,0 +1,113 @@ +/** + * layerchart ships raw `.svelte` sources in `dist/`. Vite/Svelte compilation is + * unreliable for this package on CI (Rollup parses vendor sources as JS). Compile + * to plain `.js` at install/build time and rewrite internal imports. + */ +import { compile } from "svelte/compiler"; +import { + readFileSync, + readdirSync, + statSync, + writeFileSync, +} from "node:fs"; +import { dirname, join } from "node:path"; +import { fileURLToPath } from "node:url"; + +const root = join(dirname(fileURLToPath(import.meta.url)), ".."); +const layerchartRoot = join(root, "node_modules", "layerchart"); +const layerchartDist = join(layerchartRoot, "dist"); +const stampPath = join(layerchartDist, ".bsplus-compiled"); + +function exists(path) { + try { + statSync(path); + return true; + } catch { + return false; + } +} + +if (!exists(layerchartDist)) { + console.log("compile-layerchart-vendor: layerchart not installed, skipping"); + process.exit(0); +} + +const COMPILE_ALGO_VERSION = "2"; + +const layerchartVersion = JSON.parse( + readFileSync(join(layerchartRoot, "package.json"), "utf8"), +).version; + +const stampContent = `${layerchartVersion}\n${COMPILE_ALGO_VERSION}`; + +if ( + exists(stampPath) && + readFileSync(stampPath, "utf8").trim() === stampContent +) { + console.log( + `compile-layerchart-vendor: layerchart@${layerchartVersion} already compiled, skipping`, + ); + process.exit(0); +} + +function walkFiles(dir, files = []) { + for (const name of readdirSync(dir)) { + if (name === "node_modules") continue; + const path = join(dir, name); + if (statSync(path).isDirectory()) { + walkFiles(path, files); + } else { + files.push(path); + } + } + return files; +} + +const importSuffixPattern = /\.svelte(?=['"])/g; + +function patchSvelteImports(content) { + return content.replace(importSuffixPattern, ".js"); +} + +/** Rollup CJS resolver chokes on TS optional params (`name?`) in vendor `.js`. */ +function stripRollupBreakingSyntax(code) { + return code + .replace(/(\w+)\?(?=\s*[,)\]])/g, "$1") + .replace(/(\w+)\?(?=\s*:)/g, "$1"); +} + +const svelteFiles = walkFiles(layerchartDist).filter((f) => f.endsWith(".svelte")); + +for (const sveltePath of svelteFiles) { + const source = readFileSync(sveltePath, "utf8"); + if (!source.includes(" + /\.(js|svelte|ts|mjs)$/.test(f), +); + +for (const filePath of patchable) { + const content = readFileSync(filePath, "utf8"); + if (!content.includes(".svelte")) continue; + const patched = patchSvelteImports(content); + if (patched !== content) { + writeFileSync(filePath, patched); + } +} + +writeFileSync(stampPath, stampContent); + +console.log( + `compile-layerchart-vendor: compiled ${svelteFiles.length} Svelte files`, +); diff --git a/src/interface/components/store/ThemeModal.svelte b/src/interface/components/store/ThemeModal.svelte index 8dd09da7..f1663644 100644 --- a/src/interface/components/store/ThemeModal.svelte +++ b/src/interface/components/store/ThemeModal.svelte @@ -260,7 +260,7 @@ - const hideModal = (relatedTheme?: Theme | null) => { + const hideModal = (relatedTheme = null) => { animate( diff --git a/src/interface/pages/settings.svelte b/src/interface/pages/settings.svelte index 50b64851..9b738bf2 100644 --- a/src/interface/pages/settings.svelte +++ b/src/interface/pages/settings.svelte @@ -101,10 +101,15 @@ showCloudPanel = true; }; - const showDisclaimer = (onConfirm: () => void, onCancel: () => void, title?: string, message?: string) => { + const showDisclaimer = ( + onConfirm: () => void, + onCancel: () => void, + title = "Confirm", + message = "", + ) => { disclaimerCallbacks = { onConfirm, onCancel }; - disclaimerTitle = title ?? "Confirm"; - disclaimerMessage = message ?? ""; + disclaimerTitle = title; + disclaimerMessage = message; showDisclaimerModal = true; }; diff --git a/src/plugins/built-in/globalSearch/src/utils/HighlightedText.svelte b/src/plugins/built-in/globalSearch/src/utils/HighlightedText.svelte index 12941a93..e9b7a17c 100644 --- a/src/plugins/built-in/globalSearch/src/utils/HighlightedText.svelte +++ b/src/plugins/built-in/globalSearch/src/utils/HighlightedText.svelte @@ -10,7 +10,7 @@ const segments = $derived(getSegments(text, term, matches)); // Build highlight map (copied and adapted from highlightMatch) - function getSegments(text: string, term: string, matches?: readonly FuseResultMatch[]) { + function getSegments(text: string, term: string, matches = undefined) { if (!term.trim() || !matches || matches.length === 0) return [{ text, highlight: false }]; try { diff --git a/vite.config.ts b/vite.config.ts index c56d4bbd..e051dd41 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -72,13 +72,26 @@ export default defineConfig(({ command }) => ({ __BUILD_LABEL__: JSON.stringify(process.env.BUILD_LABEL ?? ""), }, plugins: [ + svelte({ + emitCss: false, + configFile: join(__dirname, "src", "svelte.config.js"), + }), extensionChunkUrls(), base64Loader, InlineWorkerPlugin(), - svelte({ - emitCss: false, - }), - ...(useMillion ? [million.vite({ auto: true })] : []), + ...(useMillion && command !== "build" + ? [ + million.vite({ + auto: true, + filter: { + exclude: [ + "**/*.svelte", + "node_modules/**/*.{jsx,tsx,ts,js,mjs,cjs}", + ], + }, + }), + ] + : []), crx({ manifest: withDevManifestCsp( targets.find((t) => t.browser === mode.toLowerCase())?.manifest ?? @@ -115,6 +128,12 @@ export default defineConfig(({ command }) => ({ include: [ "@babel/runtime/helpers/extends", "@babel/runtime/helpers/interopRequireDefault", + "layerchart", + "d3-scale", + "d3-shape", + "d3-array", + "d3-format", + "d3-time", ], }, legacy: { @@ -133,20 +152,6 @@ export default defineConfig(({ command }) => ({ input: { settings: join(__dirname, "src", "interface", "index.html"), pageState: join(__dirname, "src", "pageState.js"), - seqtaMenuColourPatch: join( - __dirname, - "src", - "seqta", - "utils", - "seqtaMenuColourPatch.js", - ), - themeImagePagePatch: join( - __dirname, - "src", - "seqta", - "utils", - "themeImagePagePatch.js", - ), }, output: { assetFileNames: "assets/[name]-[hash][extname]",