Skip to content

Commit

Permalink
back
Browse files Browse the repository at this point in the history
  • Loading branch information
adamraine committed Jul 6, 2023
1 parent ebcbe78 commit ad5ef5c
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions core/config/config-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {getModuleDirectory} from '../../esm-utils.js';

const require = createRequire(import.meta.url);

/** @typedef {typeof import('../gather/base-gatherer.js').default} GathererConstructor */
/** @typedef {typeof import('../gather/gatherers/gatherer.js').Gatherer} GathererConstructor */
/** @typedef {typeof import('../audits/audit.js')['Audit']} Audit */
/** @typedef {InstanceType<GathererConstructor>} Gatherer */

Expand Down Expand Up @@ -160,7 +160,7 @@ function mergeConfigFragmentArrayByKey(baseArray, extensionArray, keyFn) {
* - {instance: myGathererInstance}
*
* @param {LH.Config.GathererJson} gatherer
* @return {{instance?: Gatherer, implementation?: GathererConstructor, path?: string}}
* @return {{instance?: Gatherer, implementation?: GathererConstructor, path?: string}} passes
*/
function expandGathererShorthand(gatherer) {
if (typeof gatherer === 'string') {
Expand All @@ -178,7 +178,7 @@ function expandGathererShorthand(gatherer) {
} else if (typeof gatherer === 'function') {
// just GathererConstructor
return {implementation: gatherer};
} else if (gatherer && typeof gatherer.getArtifact === 'function') {
} else if (gatherer && typeof gatherer.beforePass === 'function') {
// just GathererInstance
return {instance: gatherer};
} else {
Expand Down Expand Up @@ -595,6 +595,13 @@ function deepCloneConfigJson(json) {

// Copy arrays that could contain non-serializable properties to allow for programmatic
// injection of audit and gatherer implementations.
if (Array.isArray(cloned.passes) && Array.isArray(json.passes)) {
for (let i = 0; i < cloned.passes.length; i++) {
const pass = cloned.passes[i];
pass.gatherers = (json.passes[i].gatherers || []).map(gatherer => shallowClone(gatherer));
}
}

if (Array.isArray(json.audits)) {
cloned.audits = json.audits.map(audit => shallowClone(audit));
}
Expand Down

0 comments on commit ad5ef5c

Please sign in to comment.