(name: string, type?: string)
| 11 | * 3. otherwise try to require "wdio-<name>-<type>" |
| 12 | */ |
| 13 | export default async function initializePlugin (name: string, type?: string): Promise<Services.ServicePlugin | Services.RunnerPlugin> { |
| 14 | /** |
| 15 | * directly import packages that are scoped or start with an absolute path |
| 16 | */ |
| 17 | if (name[0] === '@' || isAbsolute(name)) { |
| 18 | const fileUrl = name[0] === '@' ? name : ensureFileURL(name) |
| 19 | const service = await safeImport(fileUrl) |
| 20 | |
| 21 | if (service) { |
| 22 | return service |
| 23 | } |
| 24 | } |
| 25 | |
| 26 | if (typeof type !== 'string') { |
| 27 | throw new Error('No plugin type provided') |
| 28 | } |
| 29 | |
| 30 | /** |
| 31 | * check for scoped version of plugin first (e.g. @wdio/sauce-service) |
| 32 | */ |
| 33 | const scopedPlugin = await safeImport(`@wdio/${name.toLowerCase()}-${type}`) |
| 34 | if (scopedPlugin) { |
| 35 | return scopedPlugin |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * check for old type of |
| 40 | */ |
| 41 | const plugin = await safeImport(`wdio-${name.toLowerCase()}-${type}`) |
| 42 | if (plugin) { |
| 43 | return plugin |
| 44 | } |
| 45 | |
| 46 | throw new Error( |
| 47 | `Couldn't find plugin "${name}" ${type}, neither as wdio scoped package `+ |
| 48 | `"@wdio/${name.toLowerCase()}-${type}" nor as community package ` + |
| 49 | `"wdio-${name.toLowerCase()}-${type}". Please make sure you have it installed!` |
| 50 | ) |
| 51 | } |
| 52 | |
| 53 | function ensureFileURL(path:string) { |
| 54 | if (path.startsWith(FILE_PROTOCOL)) { |
no test coverage detected
searching dependent graphs…