mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-02-20 17:34:10 +01:00
📝 docs: Add AGENTS.md for Project Structure and Coding Standards (#11866)
* 📝 docs: Add AGENTS.md for project structure and coding standards
- Introduced AGENTS.md to outline project workspaces, coding standards, and development commands.
- Defined workspace boundaries for backend and frontend development, emphasizing TypeScript usage.
- Established guidelines for code style, iteration performance, type safety, and import order.
- Updated CONTRIBUTING.md to reference AGENTS.md for coding standards and project conventions.
- Modified package.json to streamline build commands, consolidating frontend and backend build processes.
* chore: Update build commands and improve smart reinstall process
- Modified AGENTS.md to clarify the purpose of `npm run smart-reinstall` and other build commands, emphasizing Turborepo's role in dependency management and builds.
- Updated package.json to streamline build commands, replacing the legacy frontend build with a Turborepo-based approach for improved performance.
- Enhanced the smart reinstall script to fully delegate build processes to Turborepo, including cache management and dependency checks, ensuring a more efficient build workflow.
This commit is contained in:
parent
9eeec6bc4f
commit
c3da148fa0
4 changed files with 217 additions and 121 deletions
|
|
@ -9,10 +9,9 @@
|
|||
* Skips npm ci entirely when the lockfile hasn't changed.
|
||||
*
|
||||
* Package builds (Turborepo):
|
||||
* Turbo hashes each package's source/config inputs, caches build
|
||||
* outputs (dist/), and restores from cache when inputs match.
|
||||
* Turbo v2 uses a global cache (~/.cache/turbo) that survives
|
||||
* npm ci and is shared across worktrees.
|
||||
* Turbo hashes each package's source/config inputs (including the
|
||||
* lockfile), caches build outputs (dist/), and restores from cache
|
||||
* when inputs match. This script delegates entirely to turbo for builds.
|
||||
*
|
||||
* Usage:
|
||||
* npm run smart-reinstall # Smart cached mode
|
||||
|
|
@ -27,11 +26,8 @@ const fs = require('fs');
|
|||
const path = require('path');
|
||||
const { execSync } = require('child_process');
|
||||
|
||||
// Adds console.green, console.purple, etc.
|
||||
require('./helpers');
|
||||
|
||||
// ─── Configuration ───────────────────────────────────────────────────────────
|
||||
|
||||
const ROOT_DIR = path.resolve(__dirname, '..');
|
||||
const DEPS_HASH_MARKER = path.join(ROOT_DIR, 'node_modules', '.librechat-deps-hash');
|
||||
|
||||
|
|
@ -42,7 +38,6 @@ const flags = {
|
|||
verbose: process.argv.includes('--verbose'),
|
||||
};
|
||||
|
||||
// Workspace directories whose node_modules should be cleaned during reinstall
|
||||
const NODE_MODULES_DIRS = [
|
||||
ROOT_DIR,
|
||||
path.join(ROOT_DIR, 'packages', 'data-provider'),
|
||||
|
|
@ -53,8 +48,6 @@ const NODE_MODULES_DIRS = [
|
|||
path.join(ROOT_DIR, 'api'),
|
||||
];
|
||||
|
||||
// ─── Helpers ─────────────────────────────────────────────────────────────────
|
||||
|
||||
function hashFile(filePath) {
|
||||
return crypto.createHash('sha256').update(fs.readFileSync(filePath)).digest('hex').slice(0, 16);
|
||||
}
|
||||
|
|
@ -63,8 +56,6 @@ function exec(cmd, opts = {}) {
|
|||
execSync(cmd, { cwd: ROOT_DIR, stdio: 'inherit', ...opts });
|
||||
}
|
||||
|
||||
// ─── Dependency Installation ─────────────────────────────────────────────────
|
||||
|
||||
function checkDeps() {
|
||||
const lockfile = path.join(ROOT_DIR, 'package-lock.json');
|
||||
if (!fs.existsSync(lockfile)) {
|
||||
|
|
@ -97,19 +88,15 @@ function installDeps(hash) {
|
|||
fs.writeFileSync(DEPS_HASH_MARKER, hash, 'utf-8');
|
||||
}
|
||||
|
||||
// ─── Turbo Build ─────────────────────────────────────────────────────────────
|
||||
|
||||
function runTurboBuild() {
|
||||
const args = ['npx', 'turbo', 'run', 'build'];
|
||||
|
||||
if (flags.skipClient) {
|
||||
args.push('--filter=!@librechat/frontend');
|
||||
}
|
||||
|
||||
if (flags.force) {
|
||||
args.push('--force');
|
||||
}
|
||||
|
||||
if (flags.verbose) {
|
||||
args.push('--verbosity=2');
|
||||
}
|
||||
|
|
@ -119,76 +106,41 @@ function runTurboBuild() {
|
|||
exec(cmd);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fallback for when turbo is not installed (e.g., first run before npm ci).
|
||||
* Runs the same sequential build as the original `npm run frontend`.
|
||||
*/
|
||||
function runFallbackBuild() {
|
||||
console.orange(' turbo not found — using sequential fallback build\n');
|
||||
|
||||
const scripts = [
|
||||
'build:data-provider',
|
||||
'build:data-schemas',
|
||||
'build:api',
|
||||
'build:client-package',
|
||||
];
|
||||
|
||||
if (!flags.skipClient) {
|
||||
scripts.push('build:client');
|
||||
function cleanTurboCache() {
|
||||
console.purple('Clearing Turborepo cache...');
|
||||
try {
|
||||
exec('npx turbo daemon stop', { stdio: 'pipe' });
|
||||
} catch {
|
||||
// daemon may not be running
|
||||
}
|
||||
|
||||
for (const script of scripts) {
|
||||
console.purple(` Running ${script}...`);
|
||||
exec(`npm run ${script}`);
|
||||
const localTurboCache = path.join(ROOT_DIR, '.turbo');
|
||||
if (fs.existsSync(localTurboCache)) {
|
||||
fs.rmSync(localTurboCache, { recursive: true });
|
||||
}
|
||||
|
||||
try {
|
||||
exec('npx turbo clean', { stdio: 'pipe' });
|
||||
console.green('Turbo cache cleared.');
|
||||
} catch {
|
||||
console.gray('Could not clear global turbo cache (may not exist yet).');
|
||||
}
|
||||
}
|
||||
|
||||
function hasTurbo() {
|
||||
const binDir = path.join(ROOT_DIR, 'node_modules', '.bin');
|
||||
return ['turbo', 'turbo.cmd', 'turbo.ps1'].some((name) => fs.existsSync(path.join(binDir, name)));
|
||||
}
|
||||
|
||||
// ─── Main ────────────────────────────────────────────────────────────────────
|
||||
|
||||
(async () => {
|
||||
const startTime = Date.now();
|
||||
|
||||
console.green('\n Smart Reinstall — LibreChat');
|
||||
console.green('─'.repeat(45));
|
||||
|
||||
// ── Handle --clean-cache ───────────────────────────────────────────────
|
||||
if (flags.cleanCache) {
|
||||
console.purple('Clearing Turborepo cache...');
|
||||
if (hasTurbo()) {
|
||||
try {
|
||||
exec('npx turbo daemon stop', { stdio: 'pipe' });
|
||||
} catch {
|
||||
// ignore — daemon may not be running
|
||||
}
|
||||
}
|
||||
// Clear local .turbo cache dir
|
||||
const localTurboCache = path.join(ROOT_DIR, '.turbo');
|
||||
if (fs.existsSync(localTurboCache)) {
|
||||
fs.rmSync(localTurboCache, { recursive: true });
|
||||
}
|
||||
// Clear global turbo cache
|
||||
if (hasTurbo()) {
|
||||
try {
|
||||
exec('npx turbo clean', { stdio: 'pipe' });
|
||||
console.green('Turbo cache cleared.');
|
||||
} catch {
|
||||
console.gray('Could not clear global turbo cache (may not exist yet).');
|
||||
}
|
||||
} else {
|
||||
console.gray('turbo not installed — nothing to clear.');
|
||||
}
|
||||
|
||||
cleanTurboCache();
|
||||
if (!flags.force) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// ── Step 1: Dependencies ───────────────────────────────────────────────
|
||||
// Step 1: Dependencies
|
||||
console.purple('\n[1/2] Checking dependencies...');
|
||||
|
||||
if (flags.force) {
|
||||
|
|
@ -208,16 +160,10 @@ function hasTurbo() {
|
|||
}
|
||||
}
|
||||
|
||||
// ── Step 2: Build packages ─────────────────────────────────────────────
|
||||
// Step 2: Build via Turborepo
|
||||
console.purple('\n[2/2] Building packages...');
|
||||
runTurboBuild();
|
||||
|
||||
if (hasTurbo()) {
|
||||
runTurboBuild();
|
||||
} else {
|
||||
runFallbackBuild();
|
||||
}
|
||||
|
||||
// ── Done ───────────────────────────────────────────────────────────────
|
||||
const elapsed = ((Date.now() - startTime) / 1000).toFixed(1);
|
||||
console.log('');
|
||||
console.green('─'.repeat(45));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue