LibreChat/packages/client/tsdown.config.mjs
Marco Beretta 69d5eca048
Some checks are pending
Backend Unit Tests / Build packages (push) Waiting to run
Backend Unit Tests / Codegraph select (push) Waiting to run
Backend Unit Tests / TypeScript type checks (push) Blocked by required conditions
Backend Unit Tests / Circular dependency checks (push) Waiting to run
Backend Unit Tests / Tests: api (shard 1/3) (push) Blocked by required conditions
Backend Unit Tests / Tests: api (shard 2/3) (push) Blocked by required conditions
Backend Unit Tests / Tests: api (shard 3/3) (push) Blocked by required conditions
Backend Unit Tests / Tests: data-provider (push) Blocked by required conditions
Backend Unit Tests / Tests: data-schemas (push) Blocked by required conditions
Backend Unit Tests / Tests: @librechat/api (shard 1/4) (push) Blocked by required conditions
Backend Unit Tests / Tests: @librechat/api (shard 2/4) (push) Blocked by required conditions
Backend Unit Tests / Tests: @librechat/api (shard 3/4) (push) Blocked by required conditions
Backend Unit Tests / Tests: @librechat/api (shard 4/4) (push) Blocked by required conditions
Codegraph E2E Vote Gate / Gate (push) Waiting to run
Codegraph E2E Votes / vote (shard 1/10) (push) Waiting to run
Codegraph E2E Votes / vote (shard 10/10) (push) Waiting to run
Codegraph E2E Votes / vote (shard 2/10) (push) Waiting to run
Codegraph E2E Votes / vote (shard 3/10) (push) Waiting to run
Codegraph E2E Votes / vote (shard 4/10) (push) Waiting to run
Codegraph E2E Votes / vote (shard 5/10) (push) Waiting to run
Codegraph E2E Votes / vote (shard 6/10) (push) Waiting to run
Codegraph E2E Votes / vote (shard 7/10) (push) Waiting to run
Codegraph E2E Votes / vote (shard 8/10) (push) Waiting to run
Codegraph E2E Votes / vote (shard 9/10) (push) Waiting to run
Docker Dev Branch Images Build / publish (push) Waiting to run
Frontend Unit Tests / Client build recovery regression (push) Waiting to run
Frontend Unit Tests / Codegraph select (push) Waiting to run
Frontend Unit Tests / Build packages (push) Waiting to run
Frontend Unit Tests / TypeScript type checks (client) (push) Blocked by required conditions
Frontend Unit Tests / Tests: @librechat/chat (push) Blocked by required conditions
Frontend Unit Tests / Tests: @librechat/client (push) Blocked by required conditions
Frontend Unit Tests / Tests: Ubuntu (shard 1/2) (push) Blocked by required conditions
Frontend Unit Tests / Tests: Ubuntu (shard 2/2) (push) Blocked by required conditions
Frontend Unit Tests / Vite build verification (push) Blocked by required conditions
🕰️ fix: Refresh Copied Client Bundle Timestamps After Build (#17906)
* fix: Refresh Copied Client Bundle Files After Build

fs.cp keeps the source mtime on Windows, so dist/tokens.css and the other
copied theme files never looked newer than packages/client inputs written
later by a checkout, and the pre-commit freshness check failed after every
rebuild. Stamp the copied outputs in tsdown's build:done hook.

Related to #17731

* test: Cover copied client bundle freshness where cp keeps mtimes
2026-11-08 19:31:55 +01:00

69 lines
3.3 KiB
JavaScript

import path from 'node:path';
import { readdir, utimes } from 'node:fs/promises';
import { defineConfig } from 'tsdown';
// Mirror the prior Rollup `@rollup/plugin-replace` substitutions: only these three are
// baked at lib-build time. `import.meta.env.MODE` and `REACT_APP_*` are intentionally left
// intact so the consuming Vite app resolves them at app-build time.
const define = {
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || 'production'),
'process.env.VITE_ENABLE_LOGGER': JSON.stringify(process.env.VITE_ENABLE_LOGGER || 'false'),
'process.env.VITE_LOGGER_FILTER': JSON.stringify(process.env.VITE_LOGGER_FILTER || ''),
};
const copy = [
// The color tokens ship as CSS: an app imports `@librechat/client/theme.css` into the
// stylesheet that imports Tailwind, and gets `bg-surface-primary` and the rest. `to` names
// the destination directory, not the file, pointing it at `dist/theme.css` produced a
// directory of that name holding `tokens.css`, and the export resolved to a folder, so the
// file keeps its name in `dist` and the export maps `./theme.css` onto it. It imports the stock
// values and the font faces beside it by relative path, and the faces load `fonts/`, so all of
// them ship side by side.
{ from: 'src/theme/tokens.css', to: 'dist' },
{ from: 'src/theme/defaults.css', to: 'dist' },
{ from: 'src/theme/fonts.css', to: 'dist' },
{ from: 'src/theme/fonts', to: 'dist' },
];
/** Sets each copied output, and everything under a copied directory, to the current time. */
async function touchCopies() {
const now = new Date();
const touch = async (target) => {
await utimes(target, now, now);
const entries = await readdir(target, { withFileTypes: true }).catch(() => []);
await Promise.all(entries.map((entry) => touch(path.join(target, entry.name))));
};
await Promise.all(
copy.map(({ from, to }) => touch(path.resolve(import.meta.dirname, to, path.basename(from)))),
);
}
export default defineConfig({
entry: ['src/index.ts'],
format: ['esm', 'cjs'],
platform: 'browser',
dts: { oxc: true },
outDir: 'dist',
sourcemap: true,
// Warn on module cycles at build time; CI enforces via config/circular-deps.mjs.
checks: { circularDependency: true },
// Force .mjs/.cjs (and .d.mts/.d.cts) regardless of package `type`, so the package can stay
// CommonJS (jest.config.js / babel.config.js are CJS) while still shipping dual ESM/CJS.
fixedExtension: true,
define,
copy,
// `fs.cp` keeps the source's mtime on some platforms (Windows `CopyFileW`), so a copied file
// would never look newer than the sources the static checks compare `dist` against, and the
// pre-commit hook would reject every commit after a checkout however often it rebuilt. Stamp
// the copies once they land so a successful build always leaves `dist` fresh.
hooks: { 'build:done': () => touchCopies() },
// Extract all component CSS into a single `dist/style.css` (no import left in the JS, so the
// CJS output stays valid CommonJS). Consumers import `@librechat/client/style.css` once.
css: { inject: false },
// Externalize every third-party import (consumers provide the peers + react/jsx-runtime);
// bundle only relative, `~`-aliased, and absolute sources.
deps: {
neverBundle: (id) => !id.startsWith('.') && !id.startsWith('~') && !path.isAbsolute(id),
onlyBundle: false,
},
});