Skip to content

Commit

Permalink
Remove type
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Feb 6, 2022
1 parent ad12d5e commit 9a79b10
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 16 deletions.
17 changes: 10 additions & 7 deletions src/config/plugin/id.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import { PluginError } from '../../error/main.js'
// (e.g. runners) because those should use variations instead.
// Since the list of plugin module names is unknown, users must indicate using
// this by the usage of a delimiter character.
export const getModuleId = function (id, type, multiple) {
export const getModuleId = function (id, multiple, selectPropName) {
const [moduleId, customId] = splitId(id, multiple)
validateModuleId(moduleId, type)
validateCustomId(customId, type)
validateModuleId(moduleId, selectPropName)
validateCustomId(customId, selectPropName)
return moduleId
}

Expand All @@ -34,9 +34,9 @@ const splitId = function (id, multiple) {

const CUSTOM_ID_DELIMITER = '_'

const validateModuleId = function (moduleId, type) {
const validateModuleId = function (moduleId, selectPropName) {
if (!MODULE_ID_REGEXP.test(moduleId)) {
throw new PluginError(`The identifier of the ${type} "${moduleId}" is invalid.
throw new PluginError(`The identifier of the ${selectPropName} "${moduleId}" is invalid.
It should only contain lowercase letters and digits.`)
}
}
Expand All @@ -52,8 +52,11 @@ It should only contain lowercase letters and digits.`)
// This is purposely not applied to shared configs.
const MODULE_ID_REGEXP = /^[a-z][a-z\d]*$/u

const validateCustomId = function (customId, type) {
const validateCustomId = function (customId, selectPropName) {
if (customId !== undefined) {
validateUserId({ id: customId, messageName: `${type} identifier suffix` })
validateUserId({
id: customId,
messageName: `${selectPropName} identifier suffix`,
})
}
}
5 changes: 2 additions & 3 deletions src/config/plugin/import.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@ import { getModuleId } from './id.js'
// a dynamic `Module` instance.
export const importPlugin = async function ({
id,
type,
selectPropName,
modulePrefix,
builtins,
multiple,
}) {
const moduleId = getModuleId(id, type, multiple)
const moduleId = getModuleId(id, multiple, selectPropName)
const builtin = builtins[moduleId]

if (builtin !== undefined) {
Expand All @@ -36,7 +35,7 @@ export const importPlugin = async function ({
} catch (error) {
throw wrapError(
error,
`Could not load "${type}" module "${moduleId}"\n\n`,
`Could not load "${selectPropName}" module "${moduleId}"\n\n`,
PluginError,
)
}
Expand Down
2 changes: 0 additions & 2 deletions src/config/plugin/load.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ export const loadPlugins = async function ({
const loadPlugin = async function (
{ id, config, topConfig, context, configInfos },
{
type,
selectProp: { name: selectPropName },
configProp: { name: configPropName },
modulePrefix,
Expand All @@ -39,7 +38,6 @@ const loadPlugin = async function (
) {
const plugin = await importPlugin({
id,
type,
selectPropName,
modulePrefix,
builtins,
Expand Down
4 changes: 2 additions & 2 deletions src/config/plugin/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { RUNNER_PLUGIN_TYPE } from '../../runners/plugin.js'

// All plugin types
export const PLUGIN_TYPES = {
[RUNNER_PLUGIN_TYPE.type]: RUNNER_PLUGIN_TYPE,
[REPORTER_PLUGIN_TYPE.type]: REPORTER_PLUGIN_TYPE,
[RUNNER_PLUGIN_TYPE.selectProp.name]: RUNNER_PLUGIN_TYPE,
[REPORTER_PLUGIN_TYPE.selectProp.name]: REPORTER_PLUGIN_TYPE,
}

export const PLUGIN_TYPES_ARRAY = Object.values(PLUGIN_TYPES)
1 change: 0 additions & 1 deletion src/report/reporters/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import { sharedProps } from './shared_props.js'
const pick = amongCommands(['remove', 'run', 'show'])

export const REPORTER_PLUGIN_TYPE = {
type: 'reporter',
modulePrefix: 'spyd-reporter-',
multiple: true,
shape: [
Expand Down
1 change: 0 additions & 1 deletion src/runners/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { sharedProps } from './shared_props.js'
const pick = amongCommands(['dev', 'run'])

export const RUNNER_PLUGIN_TYPE = {
type: 'runner',
// Prefix of the npm package
modulePrefix: 'spyd-runner-',
// When `true`, the plugin can be selected twice but with different configs
Expand Down

0 comments on commit 9a79b10

Please sign in to comment.