refactor: trim PR debloat and fix transformers build

Extract shared helpers for home notices, timetable subtitles, and theme images; dedupe global search, Select, and build scripts while preserving behaviour.

Add @huggingface/transformers as a direct dependency and resolve ORT WASM paths via require.resolve so pnpm postinstall and Vite can bundle vector search.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-06-28 10:30:25 +09:30
parent dcb4dd2f5e
commit 4fda63dedd
76 changed files with 2003 additions and 4149 deletions
+6 -45
View File
@@ -1,59 +1,20 @@
// ref: https://stackoverflow.com/a/76920975
import type { Plugin } from "vite";
/**
* Creates a Vite plugin designed to gracefully handle the conclusion of the build process.
* This plugin utilizes the `buildEnd` and `closeBundle` hooks provided by Vite.
* It checks for errors at the end of the build:
* - If an error occurred during the build (`buildEnd` hook receives an error), it logs the error
* and explicitly exits the Node.js process with a status code of 1 (indicating failure).
* - If the build completes without errors and the bundle is successfully generated
* (`closeBundle` hook is called), it logs a success message and exits the process
* with a status code of 0 (indicating success).
* This explicit process exiting can be useful in CI/CD environments or scripts that
* rely on the process status code to determine the build outcome.
* The core logic for using these hooks to exit the process is inspired by
* a solution found on StackOverflow (https://stackoverflow.com/a/76920975).
*
* @returns {Plugin} A Vite plugin object configured with `name`, `buildEnd`, and `closeBundle` hooks.
*/
/** Exit with code 1 on build failure; do not exit on success (multi-target builds). */
export default function ClosePlugin(): Plugin {
return {
/**
* The unique name of this Vite plugin. This name is used by Vite for identification
* purposes and will appear in warnings, errors, and logs related to this plugin.
* @type {string}
*/
name: "ClosePlugin", // required, will show up in warnings and errors
/**
* A Vite hook that is called when the build process has finished, regardless of
* whether it was successful or encountered an error.
*
* @param {Error} [error] An optional error object. If the build failed, this parameter
* will contain the error that occurred. If the build was successful,
* this parameter will be undefined or null.
*/
name: "ClosePlugin",
buildEnd(error) {
if (error) {
console.error("Error bundling");
console.error(error);
process.exit(1); // Exit with status 1 indicating an error
console.error("Error bundling", error);
process.exit(1);
} else {
console.log("Build ended"); // Log successful completion of the build phase
console.log("Build ended");
}
},
/**
* A Vite hook that is called after the `buildEnd` hook, but only if the build
* was successful (i.e., no errors were passed to `buildEnd`) and all output
* files have been generated and written to disk. This signifies the successful
* completion of the entire bundling process.
*/
closeBundle() {
console.log("Bundle closed"); // Log successful closure of the bundle
// Do not process.exit here — it can mask Vite render errors and break
// multi-target builds (`npm run build` runs chrome then firefox).
console.log("Bundle closed");
},
};
}
+4 -15
View File
@@ -1,12 +1,6 @@
import type { Plugin } from "vite";
/**
* Vite's default base (`/`) emits absolute chunk paths like `/assets/chunk.js`.
* In content scripts those resolve against the SEQTA page origin on Firefox,
* not the extension — causing MIME type / NS_ERROR_CORRUPTED_CONTENT failures.
*
* Use relative base plus `chrome.runtime.getURL` for dynamic import targets.
*/
/** Relative chunk/CSS URLs via chrome.runtime.getURL for content-script dynamic imports. */
export function extensionChunkUrls(): Plugin {
return {
name: "extension-chunk-urls",
@@ -17,16 +11,11 @@ export function extensionChunkUrls(): Plugin {
renderBuiltUrl(filename, { hostType, type }) {
const path = filename.replace(/^\//, "");
if (type === "chunk" && hostType === "js") {
return {
runtime: `chrome.runtime.getURL(${JSON.stringify(path)})`,
};
return { runtime: `chrome.runtime.getURL(${JSON.stringify(path)})` };
}
// Rewrite CSS preloads from JS dynamic imports (content scripts).
// Do not rewrite hostType "css" — extension HTML pages need static hrefs.
// JS-triggered CSS preloads only — extension HTML pages need static hrefs.
if (type === "asset" && hostType === "js" && path.endsWith(".css")) {
return {
runtime: `chrome.runtime.getURL(${JSON.stringify(path)})`,
};
return { runtime: `chrome.runtime.getURL(${JSON.stringify(path)})` };
}
},
},
+20 -59
View File
@@ -1,71 +1,32 @@
// vite-plugin-inline-worker-dev.ts
// vite-plugin-inline-worker-dev.ts
import { Plugin } from "vite";
import fs from "fs/promises";
import { build } from "esbuild";
/**
* Creates a Vite plugin designed for bundling and inlining web worker scripts during development.
* This plugin specifically targets module imports that include a `?inlineWorker` query parameter.
* When such an import is encountered, the plugin bundles the worker script using `esbuild`
* and then generates JavaScript code that inlines this bundled worker as a Blob,
* creating the worker instance via `URL.createObjectURL()`.
* The name "vite:inline-worker-dev" suggests it's primarily intended for development builds.
*
* @returns {Plugin} A Vite plugin object with `name` and `load` properties.
*/
/** Bundle worker entry points imported with `?inlineWorker` as Blob-backed Workers in dev. */
export default function InlineWorkerDevPlugin(): Plugin {
return {
/**
* The unique name of this Vite plugin.
* @type {string}
*/
name: "vite:inline-worker-dev",
/**
* The Vite hook responsible for loading and transforming modules.
* This function intercepts modules imported with `?inlineWorker`.
* For such modules, it bundles the worker script and returns JavaScript code
* that, when executed, will create an instance of this worker from an inlined Blob.
*
* @async
* @param {string} id The path or ID of the module Vite is attempting to load,
* potentially including query parameters (e.g., "/path/to/worker.ts?inlineWorker").
* @returns {Promise<string | null>} A promise that resolves to:
* - `null` if the module ID does not include `?inlineWorker`.
* - A string of JavaScript code if the module is an inline worker.
* This code will define a default export function (e.g., `InlineWorker`)
* that, when called, creates and returns a new `Worker` instance
* from the bundled and inlined worker script.
*/
async load(id) {
if (id.includes("?inlineWorker")) {
const [cleanPath] = id.split("?");
// Note: Original code had `await fs.readFile(cleanPath, "utf-8");` but `code` wasn't used.
// `esbuild` directly takes `cleanPath` as an entry point.
const result = await build({
entryPoints: [cleanPath],
bundle: true,
write: false,
platform: "browser",
format: "iife",
target: "esnext",
external: ["webextension-polyfill"],
});
if (!id.includes("?inlineWorker")) return null;
const workerCode = result.outputFiles[0].text;
const [cleanPath] = id.split("?");
const result = await build({
entryPoints: [cleanPath],
bundle: true,
write: false,
platform: "browser",
format: "iife",
target: "esnext",
external: ["webextension-polyfill"],
});
// Construct JavaScript code that will create the worker from a Blob.
// This code is what gets returned to Vite and replaces the original import.
const workerBlobCode = `
const code = ${JSON.stringify(workerCode)};
export default function InlineWorker() {
const blob = new Blob([code], { type: 'application/javascript' });
return new Worker(URL.createObjectURL(blob), { type: 'module' });
}
`;
return workerBlobCode;
}
return null; // Let Vite handle other modules normally
const workerCode = result.outputFiles[0].text;
return `
const code = ${JSON.stringify(workerCode)};
export default function InlineWorker() {
const blob = new Blob([code], { type: 'application/javascript' });
return new Worker(URL.createObjectURL(blob), { type: 'module' });
}
`;
},
};
}