morfeo 0.6.3 → 0.6.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/lib/render.mjs +48 -1
  2. package/package.json +1 -1
package/lib/render.mjs CHANGED
@@ -80,6 +80,47 @@ const conHuella = (config) => ({
80
80
  resolve: {...config.resolve, modules: [...(config.resolve?.modules ?? ['node_modules']), path.join(PAQUETE, 'node_modules')]},
81
81
  });
82
82
 
83
+ const PREFIJO_BUNDLE = 'remotion-webpack-bundle-';
84
+ const esBundleTemporal = (dir) => path.basename(dir).startsWith(PREFIJO_BUNDLE) && fs.realpathSync(path.dirname(dir)) === fs.realpathSync(os.tmpdir());
85
+
86
+ /** Bundles que dejó un render interrumpido (o versiones anteriores de Morfeo, que no los borraban): fuera si tienen más de un día. */
87
+ function limpiarBundlesViejos() {
88
+ try {
89
+ const limite = Date.now() - 24 * 3600 * 1000;
90
+ for (const n of fs.readdirSync(os.tmpdir())) {
91
+ if (!n.startsWith(PREFIJO_BUNDLE)) continue;
92
+ const dir = path.join(os.tmpdir(), n);
93
+ if (fs.statSync(dir).mtimeMs < limite) fs.rmSync(dir, {recursive: true, force: true});
94
+ }
95
+ } catch {}
96
+ }
97
+
98
+ /**
99
+ * Webpack guarda un caché (~300 MB) por cada huella del motor y de la configuración, y no borra los anteriores:
100
+ * tras varias actualizaciones eran varios GB. Se quedan los dos más recientes.
101
+ */
102
+ function podarCacheWebpack(raiz) {
103
+ try {
104
+ let dir = raiz;
105
+ while (!fs.existsSync(path.join(dir, 'node_modules', '.cache', 'webpack'))) {
106
+ const arriba = path.dirname(dir);
107
+ if (arriba === dir) return;
108
+ dir = arriba;
109
+ }
110
+ const base = path.join(dir, 'node_modules', '.cache', 'webpack');
111
+ for (const grupo of fs.readdirSync(base)) {
112
+ if (!grupo.startsWith('remotion-')) continue;
113
+ const g = path.join(base, grupo);
114
+ const viejos = fs
115
+ .readdirSync(g)
116
+ .map((n) => ({d: path.join(g, n), m: fs.statSync(path.join(g, n)).mtimeMs}))
117
+ .sort((x, y) => y.m - x.m)
118
+ .slice(2);
119
+ for (const v of viejos) fs.rmSync(v.d, {recursive: true, force: true});
120
+ }
121
+ } catch {}
122
+ }
123
+
83
124
  /**
84
125
  * Entrada de Remotion. Sin componentes propios es la del paquete; con ellos, Morfeo escribe
85
126
  * .morfeo/entrada.tsx que los importa y los registra antes de arrancar.
@@ -294,13 +335,17 @@ export async function render({proyecto = process.cwd(), ids, todos = false, camb
294
335
  // cuadros pedazos de texto de cuadros anteriores (rótulos o subtítulos fantasma)
295
336
  const hechos = [];
296
337
  const soltar = await tomarCandado(log);
338
+ let serveUrl;
297
339
  try {
298
340
  log('Empaquetando la animación...');
299
341
  const {bundle} = await import('@remotion/bundler');
300
342
  const {renderMedia, renderStill, selectComposition} = await import('@remotion/renderer');
301
343
  const entrada = entradaDe(p);
302
344
  const tBundle = Date.now();
303
- const serveUrl = await bundle({entryPoint: entrada, publicDir: publico, rootDir: entrada === ENTRADA_REMOTION ? path.dirname(ENTRADA_REMOTION) : p.proyecto, webpackOverride: conHuella});
345
+ limpiarBundlesViejos();
346
+ const raizBundle = entrada === ENTRADA_REMOTION ? path.dirname(ENTRADA_REMOTION) : p.proyecto;
347
+ serveUrl = await bundle({entryPoint: entrada, publicDir: publico, rootDir: raizBundle, webpackOverride: conHuella});
348
+ podarCacheWebpack(raizBundle);
304
349
  const segBundle = (Date.now() - tBundle) / 1000;
305
350
  fs.mkdirSync(p.salida, {recursive: true});
306
351
  const chromiumOptions = {gl: p.render.gl};
@@ -414,6 +459,8 @@ export async function render({proyecto = process.cwd(), ids, todos = false, camb
414
459
  }
415
460
  }
416
461
  } finally {
462
+ // el bundle es una copia de la animación y de public/ (cientos de MB) en la carpeta temporal: Remotion no la borra
463
+ if (serveUrl && esBundleTemporal(serveUrl)) fs.rmSync(serveUrl, {recursive: true, force: true});
417
464
  soltar();
418
465
  }
419
466
  if (previa || parcial) return hechos;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "morfeo",
3
- "version": "0.6.3",
3
+ "version": "0.6.4",
4
4
  "description": "Genera videos verticales animados (Remotion + Three.js) con voz, música y subtítulos, desde un guion en código o escrito por IA.",
5
5
  "type": "module",
6
6
  "license": "SEE LICENSE IN LICENSE",