fix(irpf): résoudre les deux échecs de build VPS

1. tsx bin: utilise node_modules/.bin/tsx au lieu de npx qui nécessite
   l'accès à registry.npmjs.org (bloqué depuis le container Docker)
2. indicators.json: remplace le dynamic import Vite (résolution statique)
   par readFileSync + existsSync — le build ne plante plus si le fichier
   est absent au premier déploiement

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Marc Reverdin 2026-06-07 00:13:45 +02:00
parent a35c43661b
commit 064a7e8e32
3 changed files with 14 additions and 7 deletions

View file

@ -10,7 +10,7 @@
"build": "astro build",
"preview": "astro preview",
"astro": "astro",
"fetch-data": "npx tsx src/scripts/fetch-indicators.ts",
"fetch-data": "tsx src/scripts/fetch-indicators.ts",
"fetch-and-build": "npm run fetch-data && npm run build"
},
"dependencies": {

View file

@ -31,7 +31,9 @@ export function fetchIndicatorsIntegration(): AstroIntegration {
// Import dynamique pour éviter les problèmes de résolution au démarrage
const { spawnSync } = await import('child_process');
const scriptPath = new URL('../scripts/fetch-indicators.ts', import.meta.url).pathname;
const result = spawnSync('npx', ['tsx', scriptPath], {
// Utilise tsx installé dans node_modules (pas npx qui nécessite internet)
const tsxBin = new URL('../../node_modules/.bin/tsx', import.meta.url).pathname;
const result = spawnSync(tsxBin, [scriptPath], {
stdio: 'inherit',
encoding: 'utf-8',
timeout: 120_000, // 2 min max

View file

@ -2,14 +2,19 @@
import BaseLayout from '../../layouts/BaseLayout.astro';
import KpiLive from '../../components/KpiLive.astro';
import { INDICATEURS_BY_THEME, PAYS_LABEL } from '../../lib/indicators-config.ts';
import { existsSync, readFileSync } from 'node:fs';
import { join } from 'node:path';
// Charger le JSON des indicateurs (généré en pré-build)
// Utilise readFileSync + existsSync pour éviter l'échec de résolution statique Vite
let indicateursData: any = { indicators: [], insee: {}, generated_at: null };
try {
const raw = await import('../../data/live/indicators.json');
indicateursData = raw.default || raw;
} catch {
// Données non disponibles (premier build sans fetch)
const jsonPath = join(process.cwd(), 'src/data/live/indicators.json');
if (existsSync(jsonPath)) {
try {
indicateursData = JSON.parse(readFileSync(jsonPath, 'utf-8'));
} catch {
// fichier corrompu, on utilise les défauts
}
}
// Indexer par ID pour accès rapide