UNPKG

knip

Version:

Find unused files, dependencies and exports in your TypeScript and JavaScript projects

48 lines (47 loc) 1.92 kB
import { toDeferResolve, toEntry } from '../../util/input.js'; import { join, relative } from '../../util/path.js'; import { hasDependency } from '../../util/plugin.js'; const title = 'Playwright'; const enablers = ['@playwright/test']; const isEnabled = ({ dependencies }) => hasDependency(dependencies, enablers); const config = ['playwright.config.{js,ts,mjs}']; export const entry = ['**/*.@(spec|test).?(c|m)[jt]s?(x)']; const toEntryPatterns = (testMatch, cwd, configDir, localConfig, rootConfig) => { if (!testMatch) return []; const testDir = localConfig.testDir ?? rootConfig.testDir; const dir = relative(cwd, testDir ? join(configDir, testDir) : configDir); const patterns = [testMatch].flat().filter((p) => typeof p === 'string'); return patterns.map(pattern => toEntry(join(dir, pattern))); }; const builtinReporters = ['dot', 'line', 'list', 'junit', 'html', 'blob', 'json', 'github']; export const resolveEntryPaths = async (localConfig, options) => { const { cwd, configFileDir } = options; const projects = localConfig.projects ? [localConfig, ...localConfig.projects] : [localConfig]; return projects.flatMap(config => toEntryPatterns(config.testMatch, cwd, configFileDir, config, localConfig)); }; export const resolveConfig = async (config) => { const reporters = [config.reporter].flat().flatMap(reporter => { const name = typeof reporter === 'string' ? reporter : reporter?.[0]; if (!name || builtinReporters.includes(name)) return []; return [name]; }); return [...reporters].map(toDeferResolve); }; export const args = { binaries: ['playwright'], positional: true, args: (args) => args.filter(arg => arg !== 'install' && arg !== 'test'), config: true, }; export default { title, enablers, isEnabled, config, entry, resolveConfig, resolveEntryPaths, args, };