UNPKG

knip

Version:

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

48 lines (47 loc) 1.85 kB
import MDX from "../../compilers/mdx.js"; import { toEntry, toIgnore, toProductionEntry } from "../../util/input.js"; import { hasDependency } from "../../util/plugin.js"; import { config } from "../vite/index.js"; import { getRoutesDirs, getSrcDir } from "./resolveFromAST.js"; const title = 'Qwik'; const enablers = ['@builder.io/qwik']; const isEnabled = ({ dependencies }) => hasDependency(dependencies, enablers); const entry = ['src/entry.dev.tsx']; const production = ['src/root.tsx', 'src/entry.*.tsx']; const routeProduction = ['src/routes/**/*.{tsx,ts,md,mdx}']; const resolveFromAST = program => { const srcDir = getSrcDir(program); const routesDirs = getRoutesDirs(program, srcDir); const setSrcDir = (pattern) => pattern.replace(/^src\//, `${srcDir}/`); const setRoutesDir = (pattern, routesDir) => pattern.replace(/^src\/routes\//, `${routesDir}/`); const routeEntries = []; for (const routesDir of routesDirs) { for (const pattern of routeProduction) { routeEntries.push(toProductionEntry(setRoutesDir(pattern, routesDir))); } } return [ ...entry.map(setSrcDir).map(path => toEntry(path)), ...production.map(setSrcDir).map(path => toProductionEntry(path)), ...routeEntries, toIgnore('@qwik-city-plan', 'unlisted'), toIgnore('@qwik-city-sw-register', 'unlisted'), toIgnore('@qwik-client-manifest', 'unlisted'), ]; }; const registerCompilers = ({ registerCompiler, hasDependency }) => { if (hasDependency('@builder.io/qwik-city')) { registerCompiler({ extension: '.mdx', compiler: MDX.compiler }); } }; const plugin = { title, enablers, isEnabled, config, entry, production: [...production, ...routeProduction], registerCompilers, resolveFromAST, }; export default plugin;