@@ -10,6 +10,10 @@ dotenv.config();
10
10
11
11
const puppeteerCacheDir = join ( homedir ( ) , '.cache' , 'puppeteer' ) ;
12
12
13
+ // Guard to prevent multiple executions
14
+ let hasRunOnSuccess = false ;
15
+ let hasRunOnPostBuild = false ;
16
+
13
17
const onPreBuild = async ( { utils } = { } ) => {
14
18
console . log ( 'onPreBuild handler called' ) ;
15
19
console . log ( 'Restoring Lighthouse cache...' ) ;
@@ -41,6 +45,13 @@ export default function lighthousePlugin(inputs) {
41
45
} ,
42
46
onSuccess : async ( { constants, utils, inputs } = { } ) => {
43
47
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
+
44
55
// Mock the required `utils` functions if running locally
45
56
const { failPlugin, show } = getUtils ( { utils } ) ;
46
57
@@ -58,6 +69,13 @@ export default function lighthousePlugin(inputs) {
58
69
onPreBuild,
59
70
onPostBuild : async ( { constants, utils, inputs } = { } ) => {
60
71
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
+
61
79
// Mock the required `utils` functions if running locally
62
80
const { failBuild, show } = getUtils ( { utils } ) ;
63
81
0 commit comments