From 5c1f48673f11f42ef2af589ab04ba13cbbf7d92f Mon Sep 17 00:00:00 2001 From: Gleb Volkov Date: Wed, 20 May 2026 16:52:08 +0200 Subject: [PATCH] feat: skip bundling unused extension free functions in export --- .../EventsFunctionsExtensionsLoader/index.js | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/newIDE/app/src/EventsFunctionsExtensionsLoader/index.js b/newIDE/app/src/EventsFunctionsExtensionsLoader/index.js index cda683b7fc20..ba5e8f616a4b 100644 --- a/newIDE/app/src/EventsFunctionsExtensionsLoader/index.js +++ b/newIDE/app/src/EventsFunctionsExtensionsLoader/index.js @@ -107,8 +107,11 @@ const loadProjectEventsFunctionsExtension = ( }; /** - * Get the list of mandatory include files when using the - * extension. + * Get include files for extension lifecycle functions (onFirstSceneLoaded, + * onSceneLoaded, etc.) that self-register at load time and are never + * referenced via event sheet instructions. Non-lifecycle free functions + * are included only when actually referenced (transitive deps resolved + * during code generation). */ const getExtensionIncludeFiles = ( project: gdProject, @@ -119,6 +122,14 @@ const getExtensionIncludeFiles = ( return mapFor(0, freeEventsFunctions.getEventsFunctionsCount(), i => { const eventsFunction = freeEventsFunctions.getEventsFunctionAt(i); + if ( + !gd.MetadataDeclarationHelper.isExtensionLifecycleEventsFunction( + eventsFunction.getName() + ) + ) { + return null; + } + const functionName = gd.MetadataDeclarationHelper.getFreeFunctionCodeName( eventsFunctionsExtension, eventsFunction @@ -401,7 +412,7 @@ const generateFreeFunctionMetadata = ( ); instructionOrExpression.addIncludeFile(functionFile); - // Always include the extension include files when using a free function. + // Include lifecycle function files so they self-register when the extension is loaded. codeGenerationContext.extensionIncludeFiles.forEach(includeFile => { instructionOrExpression.addIncludeFile(includeFile); }); @@ -511,7 +522,7 @@ function generateBehaviorMetadata( behaviorMetadata.addIncludeFile(includeFile); - // Always include the extension include files when using a behavior. + // Include lifecycle function files so they self-register when the extension is loaded. codeGenerationContext.extensionIncludeFiles.forEach(includeFile => { behaviorMetadata.addIncludeFile(includeFile); }); @@ -615,7 +626,7 @@ function generateObjectMetadata( // Objects may already have included files for 3D for instance. objectMetadata.addIncludeFile(includeFile); - // Always include the extension include files when using an object. + // Include lifecycle function files so they self-register when the extension is loaded. codeGenerationContext.extensionIncludeFiles.forEach(includeFile => { objectMetadata.addIncludeFile(includeFile); });