Skip to content

Commit

Permalink
Start using new plugins shape
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Feb 13, 2022
1 parent 6841065 commit b4d65a1
Show file tree
Hide file tree
Showing 13 changed files with 123 additions and 134 deletions.
17 changes: 9 additions & 8 deletions benchmark/spyd.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
inputs:
one: 1
two: 2
select: not network slow uniform exponential ushaped growing
runner:
- id: node
tasks: tasks.js
# - id: cli
# tasks: tasks.yml
showPrecision: true
showSystem: false
system:
machine: one
cluster: purple
inputs:
one: 1
two: 2
reporter:
- id: any
showPrecision: true
showSystem: false
- id: debug
- id: history
- id: histogram
mini: true
- id: boxplot
mini: true
system:
machine: one
cluster: purple
4 changes: 2 additions & 2 deletions src/bin/commands/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { RUN_CONFIG } from '../config/run.js'
import { SELECT_CONFIG } from '../config/select.js'

export const RUN_COMMAND = {
command: ['run [tasks]', '* [tasks]'],
command: ['run [runner.tasks]', '* [runner.tasks]'],
describe: 'Measure tasks',

config: {
Expand All @@ -18,7 +18,7 @@ export const RUN_COMMAND = {
...HISTORY_CONFIG,
},

usage: `$0 [flags...] [tasks]
usage: `$0 [flags...] [runner.tasks]
Measure tasks.`,

Expand Down
35 changes: 16 additions & 19 deletions src/bin/config/combinations.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,22 @@ import { TASKS, HISTORY } from './groups.js'

// Configuration shared by commands that can run combinations: `run`, `dev`
export const COMBINATIONS_CONFIG = {
tasks: {
runner: {
group: TASKS,
describe: `Runner-related configuration.
Can be specified several times to use several runners.`,
},
'runner.id': {
group: TASKS,
requiresArg: true,
describe: `Tasks' programming language or platform.
When using multiple runners, this can be "any" to apply some configuration to
all other reporters.
Built-in runners: "node", "cli"
Custom runners can be installed from npm.
Default: "node"`,
},
'runner.tasks': {
group: TASKS,
alias: 't',
requiresArg: true,
Expand All @@ -16,24 +31,6 @@ When using multiple runners, each runner can have its own tasks file by using
--runnerId.tasks=path
Can be specified several times.
Can be a globbing pattern.`,
},
runner: {
group: TASKS,
describe: `Tasks' programming language or platform.
Can be specified several times.
This is an object with:
- An "id" property with the runner's id, such as "node"
- Any configuration property passed to that runner, such as "version: 8"
- The "tasks" configuration property can be specified to apply it only to
that runner
A string can be used instead as a shortcut if the object has a single "id"
property.
Built-in runners: "node", "cli"
Custom runners can be installed from npm.
Default: "node"`,
},
inputs: {
group: TASKS,
Expand Down
55 changes: 25 additions & 30 deletions src/bin/config/report.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,23 @@ import { REPORT, HISTORY } from './groups.js'
export const REPORT_CONFIG = {
reporter: {
group: REPORT,
alias: 'r',
describe: `Modules to report the result.
describe: `Reporter-related configuration.
Can be empty, if no reporters should be used.
Can be specified several times. The same reporter can be used several times but
with different configurations.
This is an object with:
- An "id" property with the reporter's id, such as "histogram"
- Any configuration property passed to that reporter, such as "mini: true"
- The "quiet", "output", "colors", "showTitles", "showSystem", "showMetadata",
"showPrecision" and "showDiff" configuration properties can be specified to
apply them only to that reporter
A string can be used instead as a shortcut if the object has a single "id"
property.
Can be specified several times to use several reporters, or the same reporter
with different configurations.`,
},
'reporter.id': {
group: REPORT,
alias: 'r',
requiresArg: true,
describe: `Module to report the result.
When using multiple reporters, this can be "any" to apply some configuration to
all other reporters.
Built-in reporters: "debug", "histogram", "boxplot", "history"
Custom reporters can also be installed from npm.
Default: "debug"`,
},
output: {
'reporter.output': {
group: REPORT,
alias: 'o',
requiresArg: true,
Expand All @@ -38,42 +33,42 @@ Otherwise, the file is overwritten.
The default value depends on the reporter`,
},
colors: {
'reporter.colors': {
group: REPORT,
describe: `Use colors in output.
Default: true if the output is an interactive terminal.`,
},
titles: {
group: REPORT,
requiresArg: true,
describe: `Rename some identifiers in reports.
Uses a dot notation such as --titles.id=string
The id can be any identifier: task, runner, system, variation.`,
},
showTitles: {
'reporter.showTitles': {
group: REPORT,
describe: `Show titles instead of identifiers.
Default: false`,
},
showSystem: {
'reporter.showSystem': {
group: REPORT,
describe: `Show hardware and software information.
Default: true when the result has a "system", false otherwise`,
},
showMetadata: {
'reporter.showMetadata': {
group: REPORT,
describe: `Show metadata such as id, timestamp, commit/branch or CI build.
Default: true for command "show" and "remove", false otherwise`,
},
showPrecision: {
'reporter.showPrecision': {
group: REPORT,
describe: `Show the results confidence interval.
Default: false.`,
},
showDiff: {
'reporter.showDiff': {
group: HISTORY,
describe: `Show the difference with previous results.
Default: true if the output is an interactive terminal.`,
},
titles: {
group: REPORT,
requiresArg: true,
describe: `Rename some identifiers in reports.
Uses a dot notation such as --titles.id=string
The id can be any identifier: task, runner, system, variation.`,
},
limit: {
group: HISTORY,
Expand Down
2 changes: 1 addition & 1 deletion src/bin/config/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const RUN_CONFIG = {
The default is 5.
A higher level increases precision but makes the benchmark last longer.`,
},
quiet: {
'reporter.quiet': {
group: REPORT,
alias: 'q',
describe: `Preview the results and display a progress bar.
Expand Down
25 changes: 7 additions & 18 deletions src/config/plugin/lib/config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { deepMerge } from '../../merge.js'
import { getDummyDefinitions } from '../../normalize/dummy.js'
import { has } from '../../normalize/lib/prop_path/get.js'

import { UserError, PluginError, ConsumerError } from './error.js'
import { safeNormalizeConfig } from './normalize.js'
Expand All @@ -12,8 +10,6 @@ import { safeNormalizeConfig } from './normalize.js'
// - The property name is not pluralized
// This is optimized for configuration-less plugins by providing with a shortcut
// syntax: only the plugin `id` instead of a plugin object.
// Some configuration properties are shared by all plugins of a given type:
// - Top-level properties can be used to configure them for all plugins
// When merging multiple configurations (CLI flags, programmatic, child and
// parent config files):
// - This is optimized for replacing a whole list of plugins of a given type,
Expand All @@ -27,56 +23,49 @@ import { safeNormalizeConfig } from './normalize.js'
// should use variations instead
export const normalizePluginConfig = async function ({
propName,
sharedConfig,
pluginConfig: unmergedConfig,
pluginConfig,
plugin,
context,
cwd,
pluginConfigDefinitions = [],
item,
}) {
const pluginConfig = deepMerge([sharedConfig, unmergedConfig])
const prefix = getPrefix.bind(undefined, unmergedConfig, propName)
const pluginConfigA = await normalizeSharedConfig({
pluginConfig,
item,
pluginConfigDefinitions,
context,
cwd,
plugin,
prefix,
propName,
})
const pluginConfigB = await normalizeSpecificConfig({
pluginConfig: pluginConfigA,
item,
pluginConfigDefinitions,
context,
cwd,
prefix,
propName,
})
return pluginConfigB
}

const getPrefix = function (unmergedConfig, propName, { path }) {
return has(unmergedConfig, path) ? `${propName}.` : undefined
}

const normalizeSharedConfig = async function ({
pluginConfig,
item,
pluginConfigDefinitions,
context,
cwd,
plugin,
prefix,
propName,
}) {
const dummyDefinitions = getDummyDefinitions(pluginConfigDefinitions)
return await safeNormalizeConfig(
pluginConfig,
[...item, ...dummyDefinitions],
{
context: { ...context, plugin },
prefix,
prefix: propName,
cwd,
UserErrorType: ConsumerError,
SystemErrorType: UserError,
Expand All @@ -90,15 +79,15 @@ const normalizeSpecificConfig = async function ({
pluginConfigDefinitions,
context,
cwd,
prefix,
propName,
}) {
const dummyDefinitions = getDummyDefinitions(item)
return await safeNormalizeConfig(
pluginConfig,
[...dummyDefinitions, ...pluginConfigDefinitions],
{
context,
prefix,
prefix: propName,
cwd,
UserErrorType: ConsumerError,
SystemErrorType: PluginError,
Expand Down
2 changes: 0 additions & 2 deletions src/config/plugin/lib/each.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export const addPlugin = async function (
index,
pluginsCount,
sharedPropNames,
sharedConfig,
context,
cwd,
},
Expand All @@ -37,7 +36,6 @@ export const addPlugin = async function (
})
const pluginConfigA = await normalizePluginConfig({
propName,
sharedConfig,
pluginConfig,
plugin: pluginA,
context,
Expand Down
18 changes: 8 additions & 10 deletions src/config/plugin/lib/main.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { addPlugin } from './each.js'
import { normalizeList } from './list.js'
import { handleMultiple } from './multiple.js'
import { getSharedConfig } from './shared.js'
import { applySharedConfigs } from './shared_config.js'
import { getSharedConfigPropNames } from './shared_names.js'
import { normalizePluginType } from './type.js'

// Generic utility to add plugins which can be selected and configured by users.
Expand All @@ -12,29 +13,26 @@ import { normalizePluginType } from './type.js'
export const addPlugins = async function (
pluginConfigs,
pluginType,
{ sharedConfig = {}, context, cwd } = {},
{ context, cwd } = {},
) {
const pluginTypeA = normalizePluginType(pluginType)
const { sharedConfig: sharedConfigA, sharedPropNames } = getSharedConfig(
sharedConfig,
pluginTypeA,
)
const pluginConfigsA = await normalizeList({
pluginConfigs,
pluginType: pluginTypeA,
context,
cwd,
})
const pluginConfigsB = handleMultiple(pluginConfigsA, pluginTypeA)
const pluginsCount = pluginConfigsB.length
const sharedPropNames = getSharedConfigPropNames(pluginTypeA)
const pluginConfigsB = applySharedConfigs(pluginConfigsA, pluginTypeA)
const pluginConfigsC = handleMultiple(pluginConfigsB, pluginTypeA)
const pluginsCount = pluginConfigsC.length
const plugins = await Promise.all(
pluginConfigsB.map((pluginConfig, index) =>
pluginConfigsC.map((pluginConfig, index) =>
addPlugin(pluginTypeA, {
pluginConfig,
index,
pluginsCount,
sharedPropNames,
sharedConfig: sharedConfigA,
context,
cwd,
}),
Expand Down
4 changes: 4 additions & 0 deletions src/config/plugin/lib/multiple.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ const handleDuplicatePlugin = function (
pluginConfigs,
pluginConfig,
) {
if (pluginConfig[pluginProp] === undefined) {
return pluginConfig
}

const duplicatePlugins = pluginConfigs.filter(
(pluginConfigB) => pluginConfig[pluginProp] === pluginConfigB[pluginProp],
)
Expand Down
Loading

0 comments on commit b4d65a1

Please sign in to comment.