@@ -10,6 +10,10 @@ dotenv.config();
1010
1111const puppeteerCacheDir = join ( homedir ( ) , '.cache' , 'puppeteer' ) ;
1212
13+ // Guard to prevent multiple executions
14+ let hasRunOnSuccess = false ;
15+ let hasRunOnPostBuild = false ;
16+
1317const onPreBuild = async ( { utils } = { } ) => {
1418 console . log ( 'onPreBuild handler called' ) ;
1519 console . log ( 'Restoring Lighthouse cache...' ) ;
@@ -41,6 +45,13 @@ export default function lighthousePlugin(inputs) {
4145 } ,
4246 onSuccess : async ( { constants, utils, inputs } = { } ) => {
4347 console . log ( 'onSuccess handler called' ) ;
48+
49+ if ( hasRunOnSuccess ) {
50+ console . log ( 'onSuccess already executed, skipping duplicate call' ) ;
51+ return ;
52+ }
53+ hasRunOnSuccess = true ;
54+
4455 // Mock the required `utils` functions if running locally
4556 const { failPlugin, show } = getUtils ( { utils } ) ;
4657
@@ -58,6 +69,13 @@ export default function lighthousePlugin(inputs) {
5869 onPreBuild,
5970 onPostBuild : async ( { constants, utils, inputs } = { } ) => {
6071 console . log ( 'onPostBuild handler called (onPostBuild mode)' ) ;
72+
73+ if ( hasRunOnPostBuild ) {
74+ console . log ( 'onPostBuild already executed, skipping duplicate call' ) ;
75+ return ;
76+ }
77+ hasRunOnPostBuild = true ;
78+
6179 // Mock the required `utils` functions if running locally
6280 const { failBuild, show } = getUtils ( { utils } ) ;
6381
0 commit comments