UNPKG

knip

Version:

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

25 lines (24 loc) 1.07 kB
import parseArgs from 'minimist'; import { isFile } from '../../util/fs.js'; import { toEntry } from '../../util/input.js'; import { isAbsolute, join } from '../../util/path.js'; import { resolveX } from './bunx.js'; const commands = ['add', 'create', 'init', 'install', 'link', 'pm', 'remove', 'run', 'test', 'update', 'upgrade', 'x']; export const resolve = (_binary, args, options) => { const parsed = parseArgs(args); const [command, script] = parsed._; if (command === 'x') { const argsForX = args.filter(arg => arg !== 'x'); return resolveX(argsForX, options); } const { manifestScriptNames, cwd, fromArgs } = options; if (command === 'run' && manifestScriptNames.has(script)) return []; if (manifestScriptNames.has(command) || commands.includes(command)) return []; const filePath = command === 'run' ? script : command; const absFilePath = isAbsolute(filePath) ? filePath : join(cwd, filePath); if (isFile(absFilePath)) return [toEntry(absFilePath)]; return fromArgs(args); };