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:
parent
a35c43661b
commit
064a7e8e32
3 changed files with 14 additions and 7 deletions
|
|
@ -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": {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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 };
|
||||
const jsonPath = join(process.cwd(), 'src/data/live/indicators.json');
|
||||
if (existsSync(jsonPath)) {
|
||||
try {
|
||||
const raw = await import('../../data/live/indicators.json');
|
||||
indicateursData = raw.default || raw;
|
||||
indicateursData = JSON.parse(readFileSync(jsonPath, 'utf-8'));
|
||||
} catch {
|
||||
// Données non disponibles (premier build sans fetch)
|
||||
// fichier corrompu, on utilise les défauts
|
||||
}
|
||||
}
|
||||
|
||||
// Indexer par ID pour accès rapide
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue