Skip to content

Commit c0e2228

Browse files
felixtrzmeta-codesync[bot]
authored andcommitted
fix(vite-plugin-metaspatial): ensure GLXF generation runs after component discovery
Summary: Move GLXF generation from buildStart to buildEnd with order: 'post' to fix a race condition where the Meta Spatial CLI was running before component XML files were written to disk. This ensures discoverComponents completes its XML generation before generateGLXF executes, which is required since the CLI depends on those component definitions. Reviewed By: zjm-meta Differential Revision: D90284014 Privacy Context Container: L1334777 fbshipit-source-id: b5e9395881898f5867aaadbeaba3c86be0d29b90
1 parent 42ddb60 commit c0e2228

File tree

1 file changed

+25
-13
lines changed
  • packages/vite-plugin-metaspatial/src/generate-glxf

1 file changed

+25
-13
lines changed

packages/vite-plugin-metaspatial/src/generate-glxf/index.ts

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import * as path from 'path';
99
import type { FSWatcher } from 'chokidar';
1010
import fs from 'fs-extra';
1111
import type { Plugin, ViteDevServer } from 'vite';
12+
import { resolveMetaSpatialCliPath } from './cli-path-resolver.js';
1213
import { regenerateGLXF, createFileWatcher, cleanup } from './file-watcher.js';
1314
import type { GLXFGenerationOptions, ProcessedGLXFOptions } from './types.js';
14-
import { resolveMetaSpatialCliPath } from './cli-path-resolver.js';
1515

1616
// Export types
1717
export type { GLXFGenerationOptions } from './types.js';
@@ -266,28 +266,40 @@ export function generateGLXF(options: GLXFGenerationOptions = {}): Plugin {
266266
console.log('👁️ GLXF file watcher started - monitoring for changes...');
267267
},
268268

269-
async buildStart() {
270-
// Only generate GLXF during build, not during dev server
269+
buildStart() {
270+
// Only reset stats during build, not during dev server
271271
// config.command is 'serve' for dev, 'build' for production
272272
if (config.command === 'serve') {
273273
return;
274274
}
275275

276276
// Reset stats for each build
277277
generationStats = [];
278-
await generateBuildGLXF(pluginOptions, generationStats);
279278
},
280279

281-
buildEnd() {
282-
// Clean up watcher when build ends
283-
if (watcher) {
284-
watcher.close();
285-
watcher = null;
286-
cleanup(); // Clear any pending debounced operations
287-
if (pluginOptions.verbose) {
288-
console.log('👋 Meta Spatial file watcher closed');
280+
// Use order: 'post' to ensure this runs AFTER discoverComponents.buildEnd()
281+
// which writes the component XML files that the Meta Spatial CLI needs
282+
buildEnd: {
283+
order: 'post',
284+
async handler() {
285+
// Only generate GLXF during build, not during dev server
286+
if (config.command === 'serve') {
287+
return;
289288
}
290-
}
289+
290+
// Generate GLXF files (after component XMLs have been written)
291+
await generateBuildGLXF(pluginOptions, generationStats);
292+
293+
// Clean up watcher when build ends
294+
if (watcher) {
295+
watcher.close();
296+
watcher = null;
297+
cleanup(); // Clear any pending debounced operations
298+
if (pluginOptions.verbose) {
299+
console.log('👋 Meta Spatial file watcher closed');
300+
}
301+
}
302+
},
291303
},
292304

293305
// Display GLXF generation summary at the very end of build process

0 commit comments

Comments
 (0)