From 064a7e8e32bf83a739d84aebc16188d8bb69bcf1 Mon Sep 17 00:00:00 2001 From: Marc Reverdin Date: Sun, 7 Jun 2026 00:13:45 +0200 Subject: [PATCH] =?UTF-8?q?fix(irpf):=20r=C3=A9soudre=20les=20deux=20?= =?UTF-8?q?=C3=A9checs=20de=20build=20VPS?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- package.json | 2 +- src/integrations/fetch-indicators.ts | 4 +++- src/pages/donnees/index.astro | 15 ++++++++++----- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index c36efa6..fb07ac2 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/src/integrations/fetch-indicators.ts b/src/integrations/fetch-indicators.ts index fb83c51..13d5c70 100644 --- a/src/integrations/fetch-indicators.ts +++ b/src/integrations/fetch-indicators.ts @@ -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 diff --git a/src/pages/donnees/index.astro b/src/pages/donnees/index.astro index ae39eb0..2440236 100644 --- a/src/pages/donnees/index.astro +++ b/src/pages/donnees/index.astro @@ -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