diff --git a/src/core/base-runner.js b/src/core/base-runner.js index 792386ae1e..fbe996eeab 100644 --- a/src/core/base-runner.js +++ b/src/core/base-runner.js @@ -24,10 +24,9 @@ export async function runAll(plugs) { runnables.forEach( plug => !plug.name && console.warn("Plugin lacks name:", plug) ); - respecConfig.state = {}; - await executePreparePass(runnables, respecConfig); - await executeRunPass(runnables, respecConfig); - respecConfig.state = {}; + const state = {}; + await executePreparePass(runnables, respecConfig, state); + await executeRunPass(runnables, respecConfig, state); pub("plugins-done", respecConfig); await postProcess(respecConfig); @@ -41,17 +40,18 @@ function isRunnableModule(plug) { return plug && (plug.run || plug.Plugin); } -async function executePreparePass(runnables, config) { +async function executePreparePass(runnables, config, state) { for (const plug of runnables.filter(p => p.prepare)) { + state[plug.name] = {}; try { - await plug.prepare(config); + await plug.prepare(config, state); } catch (err) { console.error(err); } } } -async function executeRunPass(runnables, config) { +async function executeRunPass(runnables, config, state) { for (const plug of runnables) { const name = plug.name || ""; @@ -67,10 +67,10 @@ async function executeRunPass(runnables, config) { performance.mark(`${name}-start`); try { if (plug.Plugin) { - await new plug.Plugin(config).run(); + await new plug.Plugin(config, state).run(); resolve(); } else if (plug.run) { - await plug.run(config); + await plug.run(config, state); resolve(); } } catch (err) { diff --git a/src/core/caniuse.js b/src/core/caniuse.js index 392af98bd3..203486ffb6 100644 --- a/src/core/caniuse.js +++ b/src/core/caniuse.js @@ -39,7 +39,7 @@ async function loadStyle() { } } -export async function prepare(conf) { +export async function prepare(conf, state) { if (!conf.caniuse) { return; // nothing to do. } @@ -56,12 +56,10 @@ export async function prepare(conf) { const apiUrl = options.apiURL || API_URL; // Initiate a fetch, but do not wait. Try to fill the cache early instead. - conf.state[name] = { - fetchPromise: fetchStats(apiUrl, options), - }; + state[name].fetchPromise = fetchStats(apiUrl, options); } -export async function run(conf) { +export async function run(conf, state) { const options = conf.caniuse; if (!options?.feature) return; @@ -70,7 +68,7 @@ export async function run(conf) { const headDlElem = document.querySelector(".head dl"); const contentPromise = (async () => { try { - const stats = await conf.state[name].fetchPromise; + const stats = await state[name].fetchPromise; return html`${{ html: stats }}`; } catch (err) { const msg = `Couldn't find feature "${options.feature}" on caniuse.com.`;