From abba2731e30bab89f5a7805b52fd04d0a8c76cee Mon Sep 17 00:00:00 2001 From: Philipp Hagemeister Date: Tue, 3 Mar 2026 04:53:07 +0100 Subject: [PATCH] browser_utils: Only import sharp during runtime Our dependency sharp is very particular about the CPU it runs on. Building is absolutely non-trivial. Do not require all pentf users to navigate this; move the import to the `assertSnapshot` function. --- src/browser_utils.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/browser_utils.js b/src/browser_utils.js index 06c75b3b..f3fbe7dc 100644 --- a/src/browser_utils.js +++ b/src/browser_utils.js @@ -14,7 +14,6 @@ const { performance } = require('perf_hooks'); const mkdirpCb = require('mkdirp'); const { PNG } = require('pngjs'); const pixelmatch = require('pixelmatch'); -const sharp = require('sharp'); const rimraf = require('rimraf'); const { assertAsyncEventually } = require('./assert_utils'); @@ -2222,6 +2221,10 @@ async function assertSnapshot( name, { threshold = 0.2, selector, fullPage = true, ...pxl } = {} ) { + // Load during runtime: sharp is quite particular about the operating system CPU, and requires AVX. + // Do not require this from users who don't use this function. + const sharp = require('sharp'); + await mkdirp(config.snapshot_directory); const target = path.join( config.snapshot_directory,