Skip to content

Commit

Permalink
fix(deps): Upgrade puppeteer using cache utils (#540)
Browse files Browse the repository at this point in the history
* Upgrade puppeteer, use cache-utils

* try getting homedir in es6 way

* Add some log lines
  • Loading branch information
aitchiss authored Jan 24, 2023
1 parent dd35a17 commit f831eb1
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 38 deletions.
84 changes: 47 additions & 37 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"express": "^4.17.1",
"html-minifier": "^4.0.0",
"lighthouse": "^9.6.3",
"puppeteer": "^18.0.0"
"puppeteer": "^19.5.2"
},
"engines": {
"node": ">=14.15 <19"
Expand Down
17 changes: 17 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import { join } from 'path';
import { homedir } from 'os';

import chalk from 'chalk';
import * as dotenv from 'dotenv';

Expand All @@ -9,7 +12,21 @@ import runAudit from './lib/run-audit/index.js';

dotenv.config();

const puppeteerCacheDir = join(homedir(), '.cache', 'puppeteer');

export const onPreBuild = async ({ utils } = {}) => {
console.log('Restoring Lighthouse cache...');
// Puppeteer relies on a global cache since v19.x, which otherwise would not be persisted in Netlify builds
await utils?.cache.restore(puppeteerCacheDir);
console.log('Lighthouse cache restored');
};

export const onPostBuild = async ({ constants, utils, inputs } = {}) => {
// Persist Puppeteer cache for subsequent builds/plugin runs
console.log('Persisting Lighthouse cache resources...');
await utils?.cache.save(puppeteerCacheDir);
console.log('Lighthouse cache resources persisted');

const { failBuild, show } = getUtils({ utils });
let errorMetadata = [];

Expand Down

0 comments on commit f831eb1

Please sign in to comment.