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:
@@ -29,6 +29,7 @@
|
|||||||
"class-validator": "^0.14.0",
|
"class-validator": "^0.14.0",
|
||||||
"class-transformer": "^0.5.0",
|
"class-transformer": "^0.5.0",
|
||||||
"@asyncapi/cli": "6.0.0",
|
"@asyncapi/cli": "6.0.0",
|
||||||
|
"@asyncapi/bundler": "0.9.0",
|
||||||
"@asyncapi/generator": "3.0.1",
|
"@asyncapi/generator": "3.0.1",
|
||||||
"@asyncapi/html-template": "3.5.6",
|
"@asyncapi/html-template": "3.5.6",
|
||||||
"@redocly/cli": "latest"
|
"@redocly/cli": "latest"
|
||||||
|
|||||||
@@ -15,6 +15,8 @@ import * as os from 'os';
|
|||||||
import { execFile } from 'child_process';
|
import { execFile } from 'child_process';
|
||||||
import { promisify } from 'util';
|
import { promisify } from 'util';
|
||||||
import { randomUUID } from 'crypto';
|
import { randomUUID } from 'crypto';
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
||||||
|
const asyncapiBundle = require('@asyncapi/bundler');
|
||||||
|
|
||||||
const execFileAsync = promisify(execFile);
|
const execFileAsync = promisify(execFile);
|
||||||
const localBin = path.join(process.cwd(), 'node_modules', '.bin');
|
const localBin = path.join(process.cwd(), 'node_modules', '.bin');
|
||||||
@@ -152,12 +154,15 @@ export class UploadsController {
|
|||||||
const mainPath = path.join(tempDir, mainFile.originalname);
|
const mainPath = path.join(tempDir, mainFile.originalname);
|
||||||
|
|
||||||
if (type === 'OPENAPI') {
|
if (type === 'OPENAPI') {
|
||||||
|
/* redocly bundle : pas d'appel réseau, fonctionne en local */
|
||||||
await execFileAsync('redocly', ['bundle', mainPath, '--output', bundledPath], { shell: true, env: execEnv });
|
await execFileAsync('redocly', ['bundle', mainPath, '--output', bundledPath], { shell: true, env: execEnv });
|
||||||
} else {
|
|
||||||
await execFileAsync('asyncapi', ['bundle', mainPath, '--output', bundledPath], { shell: true, env: execEnv });
|
|
||||||
}
|
|
||||||
|
|
||||||
return await fsPromises.readFile(bundledPath, 'utf-8');
|
return await fsPromises.readFile(bundledPath, 'utf-8');
|
||||||
|
} else {
|
||||||
|
/* @asyncapi/bundler API programmatique : aucun appel réseau */
|
||||||
|
const bundleFn = asyncapiBundle.default ?? asyncapiBundle;
|
||||||
|
const document = await bundleFn([mainPath], { base: mainPath });
|
||||||
|
return document.string();
|
||||||
|
}
|
||||||
} finally {
|
} finally {
|
||||||
/* Nettoyage du répertoire temp même en cas d'erreur */
|
/* Nettoyage du répertoire temp même en cas d'erreur */
|
||||||
await fsPromises.rm(tempDir, { recursive: true, force: true }).catch(() => undefined);
|
await fsPromises.rm(tempDir, { recursive: true, force: true }).catch(() => undefined);
|
||||||
|
|||||||
Reference in New Issue
Block a user