@@ -10,14 +10,14 @@ dotenv.config();
1010
1111const puppeteerCacheDir = join ( homedir ( ) , '.cache' , 'puppeteer' ) ;
1212
13- const onPreBuild = async ( { utils } = { } ) => {
13+ const restorePuppeteerCache = async ( { utils } = { } ) => {
1414 console . log ( 'Restoring Lighthouse cache...' ) ;
1515 // Puppeteer relies on a global cache since v19.x, which otherwise would not be persisted in Netlify builds
1616 await utils ?. cache . restore ( puppeteerCacheDir ) ;
1717 console . log ( 'Lighthouse cache restored' ) ;
1818} ;
1919
20- const persistCache = async ( { utils } = { } ) => {
20+ const persistPuppeteerCache = async ( { utils } = { } ) => {
2121 console . log ( 'Persisting Lighthouse cache...' ) ;
2222 await utils ?. cache . save ( puppeteerCacheDir ) ;
2323 console . log ( 'Lighthouse cache persisted' ) ;
@@ -32,10 +32,9 @@ export default function lighthousePlugin(inputs) {
3232
3333 if ( defaultEvent === 'onSuccess' ) {
3434 return {
35- // onPreBuild,
36- // onPostBuild: ({ utils }) => persistCache({ utils }),
3735 onSuccess : async ( { constants, utils, inputs } = { } ) => {
3836 console . log ( '🚨 LIGHTHOUSE PLUGIN onSuccess invoked' ) ;
37+ await restorePuppeteerCache ( { utils } ) ;
3938 // Mock the required `utils` functions if running locally
4039 const { failPlugin, show } = getUtils ( { utils } ) ;
4140
@@ -46,24 +45,24 @@ export default function lighthousePlugin(inputs) {
4645 onComplete : show ,
4746 onFail : failPlugin ,
4847 } ) ;
48+ await persistPuppeteerCache ( { utils } ) ;
4949 } ,
5050 } ;
5151 } else {
5252 return {
53- onPreBuild,
5453 onPostBuild : async ( { constants, utils, inputs } = { } ) => {
54+ await restorePuppeteerCache ( { utils } ) ;
5555 // Mock the required `utils` functions if running locally
5656 const { failBuild, show } = getUtils ( { utils } ) ;
57- console . log ( '🚨 LIGHTHOUSE PLUGIN onPostBuild invoked' ) ;
5857
59- await persistCache ( { utils } ) ;
6058 await runEvent ( {
6159 event : 'onPostBuild' ,
6260 constants,
6361 inputs,
6462 onComplete : show ,
6563 onFail : failBuild ,
6664 } ) ;
65+ await persistPuppeteerCache ( { utils } ) ;
6766 } ,
6867 } ;
6968 }
0 commit comments