Skip to content

Commit

Permalink
Block magepack during 'generate' command (#151)
Browse files Browse the repository at this point in the history
  • Loading branch information
fredden authored Oct 24, 2022
1 parent d874da3 commit 8dd9400
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 0 deletions.
22 changes: 22 additions & 0 deletions lib/generate/blockMagepack.js
Original file line number Diff line number Diff line change
@@ -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;
3 changes: 3 additions & 0 deletions lib/generate/collector/category.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -31,6 +32,8 @@ const category = async (

const page = await browserContext.newPage();

blockMagepack(page);

await authenticate(page, authUsername, authPassword);

await page.goto(categoryUrl, {
Expand Down
3 changes: 3 additions & 0 deletions lib/generate/collector/checkout.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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' });
Expand Down
3 changes: 3 additions & 0 deletions lib/generate/collector/cms.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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' });
Expand Down
3 changes: 3 additions & 0 deletions lib/generate/collector/product.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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' });
Expand Down

0 comments on commit 8dd9400

Please sign in to comment.