From 8dd9400852c4ca2cd4b7fa85b30395e609bb6ce8 Mon Sep 17 00:00:00 2001 From: Dan Wallis Date: Mon, 24 Oct 2022 19:54:19 +0100 Subject: [PATCH] Block magepack during 'generate' command (#151) --- lib/generate/blockMagepack.js | 22 ++++++++++++++++++++++ lib/generate/collector/category.js | 3 +++ lib/generate/collector/checkout.js | 3 +++ lib/generate/collector/cms.js | 3 +++ lib/generate/collector/product.js | 3 +++ 5 files changed, 34 insertions(+) create mode 100644 lib/generate/blockMagepack.js diff --git a/lib/generate/blockMagepack.js b/lib/generate/blockMagepack.js new file mode 100644 index 0000000..209a5b9 --- /dev/null +++ b/lib/generate/blockMagepack.js @@ -0,0 +1,22 @@ +const logger = require('../utils/logger'); + +/** + * @param {Page} page Puppeteer Page object instance. + */ +const blockMagepack = (page) => { + page.setRequestInterception(true); + page.on('request', (request) => { + const url = request.url(); + + // If we let these resources load, 'magepack generate' hangs at rjsResolver step. + if (url.match(/magepack\/requirejs-config-.*\.js$/)) { + logger.info('Blocked resource: ' + url); + request.abort(); + return; + } + + request.continue(); + }); +}; + +module.exports = blockMagepack; diff --git a/lib/generate/collector/category.js b/lib/generate/collector/category.js index cc1b287..15a1640 100644 --- a/lib/generate/collector/category.js +++ b/lib/generate/collector/category.js @@ -2,6 +2,7 @@ const merge = require('lodash.merge'); const logger = require('../../utils/logger'); const authenticate = require('../authenticate'); +const blockMagepack = require('../blockMagepack'); const collectModules = require('../collectModules'); const baseConfig = { @@ -31,6 +32,8 @@ const category = async ( const page = await browserContext.newPage(); + blockMagepack(page); + await authenticate(page, authUsername, authPassword); await page.goto(categoryUrl, { diff --git a/lib/generate/collector/checkout.js b/lib/generate/collector/checkout.js index 39f19d1..eb29d42 100644 --- a/lib/generate/collector/checkout.js +++ b/lib/generate/collector/checkout.js @@ -4,6 +4,7 @@ const merge = require('lodash.merge'); const logger = require('../../utils/logger'); const authenticate = require('../authenticate'); +const blockMagepack = require('../blockMagepack'); const collectModules = require('../collectModules'); const baseConfig = { @@ -33,6 +34,8 @@ const checkout = async ( const page = await browserContext.newPage(); + blockMagepack(page); + await authenticate(page, authUsername, authPassword); await page.goto(productUrl, { waitUntil: 'networkidle0' }); diff --git a/lib/generate/collector/cms.js b/lib/generate/collector/cms.js index 98297ef..7292506 100644 --- a/lib/generate/collector/cms.js +++ b/lib/generate/collector/cms.js @@ -2,6 +2,7 @@ const merge = require('lodash.merge'); const logger = require('../../utils/logger'); const authenticate = require('../authenticate'); +const blockMagepack = require('../blockMagepack'); const collectModules = require('../collectModules'); const baseConfig = { @@ -28,6 +29,8 @@ const cms = async (browserContext, { cmsUrl, authUsername, authPassword }) => { const page = await browserContext.newPage(); + blockMagepack(page); + await authenticate(page, authUsername, authPassword); await page.goto(cmsUrl, { waitUntil: 'networkidle0' }); diff --git a/lib/generate/collector/product.js b/lib/generate/collector/product.js index 2d2b8f3..4b4c182 100644 --- a/lib/generate/collector/product.js +++ b/lib/generate/collector/product.js @@ -2,6 +2,7 @@ const merge = require('lodash.merge'); const logger = require('../../utils/logger'); const authenticate = require('../authenticate'); +const blockMagepack = require('../blockMagepack'); const collectModules = require('../collectModules'); const baseConfig = { @@ -31,6 +32,8 @@ const product = async ( const page = await browserContext.newPage(); + blockMagepack(page); + await authenticate(page, authUsername, authPassword); await page.goto(productUrl, { waitUntil: 'networkidle0' });