Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Feb 6, 2022
1 parent d3310a7 commit 05d0943
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 35 deletions.
8 changes: 1 addition & 7 deletions src/config/merge/tasks.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { PLUGIN_TYPES } from '../plugin/lib/types.js'

// Custom merging logic for tasks.
// `tasks` or `runnnerConfig.{runnerId}.tasks` are concatenated, not overridden
// so that shared configurations consumers can add tasks.
Expand All @@ -12,11 +10,7 @@ const isTopTasks = function (keys) {
}

const isRunnerTasks = function (keys) {
return (
keys.length === 3 &&
keys[0] === PLUGIN_TYPES.runner.configProp &&
keys[2] === 'tasks'
)
return keys.length === 3 && keys[0] === 'runnerConfig' && keys[2] === 'tasks'
}

// Order matters since later `tasks` have priority when merging two task files
Expand Down
4 changes: 2 additions & 2 deletions src/config/normalize/definitions.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { transformPrecision, DEFAULT_PRECISION } from '../../run/precision.js'
import { DEFAULT_SELECT } from '../../select/main.js'
import { DEFAULT_OUTLIERS } from '../../stats/outliers/main.js'
import { CONFIG_DEFINITIONS } from '../load/normalize.js'
import { getPluginsProps } from '../plugin/lib/main_props.js'
import { getPluginsConfigProps } from '../plugin/main.js'

import { getDummyDefinitions, getDummyDefinitionsNames } from './dummy.js'
import { amongCommands } from './pick.js'
Expand All @@ -34,7 +34,7 @@ import {
const configProps = getDummyDefinitions(CONFIG_DEFINITIONS)

// All plugins definitions: `reporter`, `reporterConfig`, `runner`, etc.
const plugins = getDummyDefinitionsNames(getPluginsProps())
const plugins = getDummyDefinitionsNames(getPluginsConfigProps())

const cwd = {
name: 'cwd',
Expand Down
9 changes: 3 additions & 6 deletions src/config/plugin/lib/extract.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,10 @@ import { set, remove } from '../../normalize/lib/prop_path/set.js'

import { addPluginTypeDefault } from './default.js'
import { getMainProps } from './main_props.js'
import { PLUGIN_TYPES_ARRAY } from './types.js'

// Retrieve all plugin types, normalized
export const getPluginTypes = function () {
return PLUGIN_TYPES_ARRAY.map(addPluginTypeDefault).map(
addSharedConfigPropNames,
)
// Normalize all plugin types
export const normalizePluginTypes = function (pluginTypes) {
return pluginTypes.map(addPluginTypeDefault).map(addSharedConfigPropNames)
}

// Retrieve all unique `name` of shared config properties, excluding their
Expand Down
19 changes: 14 additions & 5 deletions src/config/plugin/lib/main.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { getPluginTypes, getTopConfig, removeTopProps } from './extract.js'
import {
normalizePluginTypes,
getTopConfig,
removeTopProps,
} from './extract.js'
import { loadPlugins } from './load.js'
import { normalizeMainProps } from './main_props.js'

Expand All @@ -7,15 +11,20 @@ import { normalizeMainProps } from './main_props.js'
// - Plugins without configuration
// - Single plugin per type, as opposed to multiple
// - Single configuration per plugin
export const addPlugins = async function (config, context, configInfos) {
const pluginTypes = getPluginTypes()
export const addPlugins = async function ({
config,
pluginTypes,
context,
configInfos,
}) {
const pluginTypesA = normalizePluginTypes(pluginTypes)
const pluginsConfigs = await addPluginsProps({
config,
pluginTypes,
pluginTypes: pluginTypesA,
context,
configInfos,
})
const configA = removeTopProps(config, pluginTypes)
const configA = removeTopProps(config, pluginTypesA)
return { ...configA, ...pluginsConfigs }
}

Expand Down
5 changes: 2 additions & 3 deletions src/config/plugin/lib/main_props.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ import {
import { validateDefinedString } from '../../normalize/validate/simple.js'

import { addPluginTypeDefault } from './default.js'
import { PLUGIN_TYPES_ARRAY } from './types.js'

// Ensure selection and configuration properties are not marked as unknown
export const getPluginsProps = function () {
return PLUGIN_TYPES_ARRAY.map(addPluginTypeDefault).flatMap(getMainProps)
export const getPluginsProps = function (pluginTypes) {
return pluginTypes.map(addPluginTypeDefault).flatMap(getMainProps)
}

export const getMainProps = function ({ configProp, selectProp }) {
Expand Down
10 changes: 0 additions & 10 deletions src/config/plugin/lib/types.js

This file was deleted.

20 changes: 18 additions & 2 deletions src/config/plugin/main.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,31 @@
import { normalizeReporters } from '../../report/config/main.js'
import { REPORTER_PLUGIN_TYPE } from '../../report/reporters/plugin.js'
import { RUNNER_PLUGIN_TYPE } from '../../runners/plugin.js'

import { addPlugins } from './lib/main.js'
import { getPluginsProps } from './lib/main_props.js'

// Handle the configuration all spyd-specific plugins: reporters and runners
// Handle the configuration all spyd-specific plugins: runners and reporters
export const normalizePluginsConfig = async function ({
config,
command,
context,
configInfos,
}) {
const configA = await addPlugins(config, context, configInfos)
const configA = await addPlugins({
config,
pluginTypes: PLUGIN_TYPES,
context,
configInfos,
})
const configB = normalizeReporters(configA, command)
return configB
}

// Retrieve the name of all plugin top properties
export const getPluginsConfigProps = function () {
return getPluginsProps(PLUGIN_TYPES)
}

// All plugin types
const PLUGIN_TYPES = [RUNNER_PLUGIN_TYPE, REPORTER_PLUGIN_TYPE]

0 comments on commit 05d0943

Please sign in to comment.