Skip to content

Commit

Permalink
Merge branch 'main' into android-args
Browse files Browse the repository at this point in the history
  • Loading branch information
soulgalore authored Feb 2, 2025
2 parents b70dd79 + e0d004b commit b0da9da
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 85 deletions.
12 changes: 7 additions & 5 deletions lib/core/pluginLoader.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import path from 'node:path';
import { readdir as _readdir } from 'node:fs';
import { promisify } from 'node:util';
import { fileURLToPath, pathToFileURL } from 'node:url';

import { importGlobalSilent } from 'import-global';
const readdir = promisify(_readdir);
const __dirname = path.dirname(import.meta.url);
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

const defaultPlugins = new Set([
'browsertime',
Expand Down Expand Up @@ -49,7 +51,7 @@ export async function parsePluginNames(options) {
return pluginNames;
};

const files = await readdir(new URL(pluginsDir));
const files = await readdir(pluginsDir);

const builtins = files.map(name => path.basename(name, '.js'));
// eslint-disable-next-line unicorn/no-array-callback-reference
Expand All @@ -60,9 +62,9 @@ export async function loadPlugins(pluginNames, options, context, queue) {
const plugins = [];
for (let name of pluginNames) {
try {
let { default: plugin } = await import(
path.join(pluginsDir, name, 'index.js')
);
const pluginPath = path.join(pluginsDir, name, 'index.js');
const pluginUrl = pathToFileURL(pluginPath).href;
let { default: plugin } = await import(pluginUrl);
let p = new plugin(options, context, queue);
plugins.push(p);
} catch (error_) {
Expand Down
166 changes: 86 additions & 80 deletions lib/sitespeed.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,92 +51,98 @@ function runOptionalFunction(objects, fN) {
}

export async function run(options) {
const url = options.urls[0];
const timestamp = options.utc ? dayjs.utc() : dayjs();
const { storageManager, resultUrls } = resultsStorage(
url,
timestamp,
options
);

if (
options.browsertime &&
options.browsertime.tcpdump &&
!env.SSLKEYLOGFILE
) {
env.SSLKEYLOGFILE = path.join(
storageManager.getBaseDir(),
'SSLKEYLOGFILE.txt'
try {
const url = options.urls[0];
const timestamp = options.utc ? dayjs.utc() : dayjs();
const { storageManager, resultUrls } = resultsStorage(
url,
timestamp,
options
);
}
configure(options);

// Tell the world what we are using
log.info(
'Versions OS: %s nodejs: %s sitespeed.io: %s browsertime: %s coach: %s',
platform() + ' ' + release(),
version,
packageJson.version,
packageJson.dependencies.browsertime,
packageJson.dependencies['coach-core']
);

log.debug('Running with options: %:2j', options);

let pluginNames = await parsePluginNames(options);

const plugins = options.plugins;

// Deprecated setup
if (plugins) {
if (plugins.disable) {
log.warn('--plugins.disable is deprecated, use plugins.remove instead.');
plugins.remove = plugins.disable;
}
if (plugins.load) {
log.warn('--plugins.load is deprecated, use plugins.add instead.');
plugins.add = plugins.load;
if (
options.browsertime &&
options.browsertime.tcpdump &&
!env.SSLKEYLOGFILE
) {
env.SSLKEYLOGFILE = path.join(
storageManager.getBaseDir(),
'SSLKEYLOGFILE.txt'
);
}
configure(options);

// Tell the world what we are using
log.info(
'Versions OS: %s nodejs: %s sitespeed.io: %s browsertime: %s coach: %s',
platform() + ' ' + release(),
version,
packageJson.version,
packageJson.dependencies.browsertime,
packageJson.dependencies['coach-core']
);

// Finalize the plugins that we wanna run
// First we add the new ones and then remove, that means remove
// always wins
pluginNames = [...new Set([...pluginNames, ...toArray(plugins.add)])];
log.debug('Running with options: %:2j', options);

let pluginNames = await parsePluginNames(options);

const plugins = options.plugins;

// Deprecated setup
if (plugins) {
if (plugins.disable) {
log.warn(
'--plugins.disable is deprecated, use plugins.remove instead.'
);
plugins.remove = plugins.disable;
}
if (plugins.load) {
log.warn('--plugins.load is deprecated, use plugins.add instead.');
plugins.add = plugins.load;
}

// Finalize the plugins that we wanna run
// First we add the new ones and then remove, that means remove
// always wins
pluginNames = [...new Set([...pluginNames, ...toArray(plugins.add)])];

const removeSet = new Set(toArray(plugins.remove));
pluginNames = pluginNames.filter(name => !removeSet.has(name));

if (plugins.list) {
log.info(
'The following plugins are enabled: %s',
pluginNames.join(', ')
);
}
}

const removeSet = new Set(toArray(plugins.remove));
pluginNames = pluginNames.filter(name => !removeSet.has(name));
// This is the contect where we wanna run our tests
const context = {
storageManager,
resultUrls,
timestamp,
budget: budgetResult,
name: url,
log,
getLogger,
messageMaker,
statsHelpers,
filterRegistry
};
const queueHandler = new QueueHandler(options);
const runningPlugins = await loadPlugins(
pluginNames,
options,
context,
queueHandler
);
const urlSources = [options.multi ? scriptSource : urlSource];
const allPlugins = [...runningPlugins];
queueHandler.setup(runningPlugins);

if (plugins.list) {
log.info('The following plugins are enabled: %s', pluginNames.join(', '));
}
}
// Open/start each and every plugin

// This is the contect where we wanna run our tests
const context = {
storageManager,
resultUrls,
timestamp,
budget: budgetResult,
name: url,
log,
getLogger,
messageMaker,
statsHelpers,
filterRegistry
};
const queueHandler = new QueueHandler(options);
const runningPlugins = await loadPlugins(
pluginNames,
options,
context,
queueHandler
);
const urlSources = [options.multi ? scriptSource : urlSource];
const allPlugins = [...runningPlugins];
queueHandler.setup(runningPlugins);

// Open/start each and every plugin
try {
await Promise.all(
runOptionalFunction(allPlugins, 'open', context, options)
);
Expand Down Expand Up @@ -180,7 +186,7 @@ export async function run(options) {
timestamp: timestamp.format()
};
} catch (error) {
log.error(error);
log.error(error.stack);
throw error;
}
}

0 comments on commit b0da9da

Please sign in to comment.