fix(uploads): bundling AsyncAPI multi-fichiers sans appel réseau

- Ajout @asyncapi/bundler@0.9.0 en dépendance locale
- Remplace execFile('asyncapi bundle') par l'API programmatique
- redocly bundle conservé pour OpenAPI (pas de pb réseau)

Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
This commit is contained in:
z3n
2026-06-01 09:08:57 +00:00
parent 8d6deb8691
commit b975e01e15
2 changed files with 9 additions and 3 deletions

View File

@@ -15,6 +15,8 @@ import * as os from 'os';
import { execFile } from 'child_process';
import { promisify } from 'util';
import { randomUUID } from 'crypto';
// eslint-disable-next-line @typescript-eslint/no-require-imports
const asyncapiBundle = require('@asyncapi/bundler');
const execFileAsync = promisify(execFile);
const localBin = path.join(process.cwd(), 'node_modules', '.bin');
@@ -152,12 +154,15 @@ export class UploadsController {
const mainPath = path.join(tempDir, mainFile.originalname);
if (type === 'OPENAPI') {
/* redocly bundle : pas d'appel réseau, fonctionne en local */
await execFileAsync('redocly', ['bundle', mainPath, '--output', bundledPath], { shell: true, env: execEnv });
return await fsPromises.readFile(bundledPath, 'utf-8');
} else {
await execFileAsync('asyncapi', ['bundle', mainPath, '--output', bundledPath], { shell: true, env: execEnv });
/* @asyncapi/bundler API programmatique : aucun appel réseau */
const bundleFn = asyncapiBundle.default ?? asyncapiBundle;
const document = await bundleFn([mainPath], { base: mainPath });
return document.string();
}
return await fsPromises.readFile(bundledPath, 'utf-8');
} finally {
/* Nettoyage du répertoire temp même en cas d'erreur */
await fsPromises.rm(tempDir, { recursive: true, force: true }).catch(() => undefined);