mirror of
https://github.com/readest/readest.git
synced 2026-12-03 03:30:01 +00:00
* fix(build): repair the Docker and Nix builds after #6368
Two main-branch builds broke on 8750c310 and both are fallout from that PR.
**Docker** (`pnpm build-web`: "Can't resolve '@pdfjs/pdf.min.mjs'",
"Can't resolve '@simplecc/simplecc_wasm'"). `setup-vendors` runs in the
`dependencies` stage and its output is not in the build context, so every
directory it creates needs an explicit `COPY --from=dependencies`. Splitting
the bundler-imported modules out of `public/vendor` into `vendor/` left the
new directory with no COPY line. The test derives the expected roots from the
`prepare-vendor` script, so adding another one fails until the Dockerfile
copies it.
**Nix** ("no matching package named `sentry-debug-images` found"). The Linux
CEF build vendors from `Cargo.cef.lock`, which `nix/package.nix` copies over
`Cargo.lock`, and that second lock never learned about the two crates the
sentry `debug-images` feature pulls in. Added `findshlibs` and
`sentry-debug-images` there, plus the dependency entry on `sentry`; both need
only packages the lock already had.
This is also why `nix-deps-check` stayed green on #6368: it hashes
`Cargo.cef.lock`, which that PR did not touch, so the stale vendor set only
surfaced when the full Nix build ran on main.
`cargoHash` is updated in a follow-up commit from the hash the deps-check
prints, since the vendor contents change.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
* style: format the vendor-root docker test
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
* fix(nix): update cargoHash for the new sentry debug-images crates
The vendor set gained findshlibs and sentry-debug-images, so the pinned
hash moved. Value taken from the nix-deps-check run on this PR:
specified: sha256-EPNbiv0YJ79rqBHFCO5gjQwt9Vn1v9HV0ZfH7f2Eo/E=
got: sha256-8MIkn2N65P87tG0RncOQtH01SYfRUM4qB6rOzd+fwwQ=
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
* refactor: one vendor dir, with the bundler importing from packages
#6368 split the vendored modules into a second `vendor/` directory to stop
them shipping twice (Tauri embeds every published file, and `public/` is
published whole). Two vendor directories is the wrong shape, and the copies
were never needed: the aliases can resolve straight at the sources, which is
how `jieba-wasm` has always been imported.
@pdfjs/* -> packages/foliate-js/node_modules/pdfjs-dist/legacy/build/*
@simplecc/* -> packages/simplecc-wasm/dist/web/*
`public/vendor/pdfjs` now holds only what the reader fetches by URL at
runtime — the worker, the WASM decoders, cmaps, standard fonts and the layer
CSS — and `vendor/` is gone, along with `copy-pdfjs-lib`, `copy-simplecc`,
`setup-simplecc`, its Dockerfile COPY and its worktree copy.
Two details this turned up:
- The @pdfjs alias needs an explicit `declare module`. TypeScript inferred
types for the minified JS while it sat inside the app, but skips JavaScript
under node_modules, and pdfjs-dist ships `pdf.d.mts`, not the
`pdf.min.d.mts` that would sit beside the minified build. Only the import's
side effect is used, so the declaration is bare.
- `packages/simplecc-wasm` is a submodule the worktree script skips, so the
script now copies its committed `dist/web` into a new worktree instead of a
vendor directory.
A true `import ... from 'simplecc-wasm'`, matching jieba exactly, would need a
change in that submodule: its `exports` map points at `pkg/`, which is build
output and not committed (only `dist/web` is), and the map forbids other
subpaths.
Verified with a real build: modules resolve with no `vendor/` present,
`out/vendor` holds only pdfjs, `pdf.min.mjs` is bundled into a chunk and not
published, and both jieba and simplecc WASM are emitted once each.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
* docs: say why the @pdfjs alias points at the package, not public/
The comments still described a vendored copy. Record the constraint
instead: a module the bundler imports must not also be published, or
Tauri embeds it twice.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
* test: drop the vendor/docker config assertions
These assert on config files rather than behaviour: the alias-target test,
the Dockerfile vendor-COPY test, and the pdfjs wasm copy-script test.
The SELF_HOSTED default check in docker-image-defaults.test.ts stays; it
predates this work (#6100) and guards runtime behaviour of the published
image rather than a config shape.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
112 lines
4.1 KiB
TypeScript
112 lines
4.1 KiB
TypeScript
import { resolve } from 'node:path';
|
|
import tsconfigPaths from 'vite-tsconfig-paths';
|
|
import react from '@vitejs/plugin-react';
|
|
import { defineConfig } from 'vitest/config';
|
|
import { playwright } from '@vitest/browser-playwright';
|
|
import { loadEnvFile } from './vitest.env.mts';
|
|
|
|
// Load .env and .env.web so browser tests have the same env as the web app.
|
|
const env = { ...loadEnvFile('.env'), ...loadEnvFile('.env.web') };
|
|
|
|
// Matches both wordings Chromium has used for the benign resize notice:
|
|
// "ResizeObserver loop limit exceeded" (older) and "ResizeObserver loop
|
|
// completed with undelivered notifications." (current).
|
|
const RESIZE_OBSERVER_NOTICE = /ResizeObserver loop/;
|
|
|
|
export default defineConfig({
|
|
plugins: [tsconfigPaths(), react()],
|
|
define: {
|
|
'process.env': JSON.stringify(env),
|
|
},
|
|
resolve: {
|
|
conditions: ['development'],
|
|
alias: {
|
|
// The @pdfjs alias from tsconfig only resolves within the app's own
|
|
// source files. foliate-js/pdf.js lives outside that scope, so Vite
|
|
// needs an explicit alias to reach pdfjs-dist. It points at the real
|
|
// package rather than a copy under `public/`: a module the bundler
|
|
// imports must not be published too, or Tauri embeds it twice (#6368).
|
|
'@pdfjs': resolve(import.meta.dirname, '../../packages/foliate-js/node_modules/pdfjs-dist/legacy/build'),
|
|
},
|
|
},
|
|
optimizeDeps: {
|
|
include: [
|
|
'@supabase/supabase-js',
|
|
'@tauri-apps/plugin-fs',
|
|
'@tauri-apps/plugin-http',
|
|
'@tauri-apps/api/path',
|
|
'@tauri-apps/api/core',
|
|
'@testing-library/react',
|
|
'@dnd-kit/core',
|
|
'@dnd-kit/sortable',
|
|
'@dnd-kit/utilities',
|
|
'@radix-ui/react-tooltip',
|
|
'react-virtuoso',
|
|
'react-icons/lia',
|
|
'next/image',
|
|
'@zip.js/zip.js',
|
|
'franc-min',
|
|
'iso-639-2',
|
|
'iso-639-3',
|
|
'js-md5',
|
|
'jwt-decode',
|
|
'uuid',
|
|
],
|
|
exclude: [
|
|
'@pdfjs/pdf.min.mjs',
|
|
'@readest/turso-database-wasm',
|
|
'@readest/turso-database-wasm-common',
|
|
'@readest/turso-database-common',
|
|
],
|
|
},
|
|
server: {
|
|
headers: {
|
|
'Cross-Origin-Embedder-Policy': 'require-corp',
|
|
'Cross-Origin-Opener-Policy': 'same-origin',
|
|
},
|
|
},
|
|
test: {
|
|
include: ['src/**/*.browser.test.ts', 'src/**/*.browser.test.tsx'],
|
|
onConsoleLog(log, type) {
|
|
if (type === 'stdout') return false;
|
|
// Chromium reports the benign "ResizeObserver loop ..." notice as an
|
|
// ErrorEvent carrying only `message` and no `error`. @vitest/browser's
|
|
// error catcher console.errors exactly that shape (see its
|
|
// error-catcher.js: `console.error(e.message ? new Error(e.message) : e)`),
|
|
// so it cannot be filtered with `onUnhandledError` — it never reaches
|
|
// that hook. Paginated layouts fire it constantly and it buried the CI
|
|
// log under ~1.1k copies. The notice only means observations were
|
|
// deferred to the next frame; nothing is dropped and nothing is
|
|
// actionable.
|
|
if (RESIZE_OBSERVER_NOTICE.test(log)) return false;
|
|
},
|
|
browser: {
|
|
enabled: true,
|
|
headless: true,
|
|
screenshotFailures: false,
|
|
provider: playwright({
|
|
contextOptions: {
|
|
viewport: { width: 1920, height: 1080 },
|
|
deviceScaleFactor: 2,
|
|
},
|
|
}),
|
|
instances: [{ browser: 'chromium' }],
|
|
expect: {
|
|
toMatchScreenshot: {
|
|
comparatorName: 'pixelmatch',
|
|
comparatorOptions: {
|
|
threshold: 0.1,
|
|
allowedMismatchedPixelRatio: 0.02,
|
|
},
|
|
// Strip platform from the path so one baseline works on macOS and Linux.
|
|
// Must be absolute: vitest runs the path through Vite's `server.fs`
|
|
// access check before writing, and a relative path is always denied,
|
|
// which surfaces as "Couldn't write file to fs" when generating
|
|
// baselines (reads still worked because they resolve against cwd).
|
|
resolveScreenshotPath: ({ arg, browserName, ext, root, testFileDirectory, testFileName }) =>
|
|
resolve(root, testFileDirectory, '__screenshots__', testFileName, `${arg}-${browserName}${ext}`),
|
|
},
|
|
},
|
|
},
|
|
},
|
|
});
|