UNPKG

@inlang/paraglide-js

Version:

[![Inlang-ecosystem compatibility badge](https://cdn.jsdelivr.net/gh/opral/monorepo@main/inlang/assets/md-badges/inlang.svg)](https://inlang.com)

78 lines (77 loc) 1.98 kB
/** * A list of packages that we consider relevant for stack detection. * * We (Loris & Nils) decided against using _all_ packages because that would be too much unnecessary data * that would slow down queries. */ const RelevantPackages = [ "next", "solid", "solid-start", "svelte", "@sveltejs/kit", "vue", "nuxt", "react", "react-native", "remix", "astro", "react", "react-router", "vite", "vike", "webpack", "rollup", "esbuild", "qwick", "parcel", "lit", "@angular/core", ]; /** * Returns information about the tech-stack used based on the package.json. * It will return an object with a map of relevant packages and their versions * as the `packages` property. * * If no interestring packages are found, the `packages` property will be an empty object. * If an error occurs, the `packages` property will be an empty object. * * @example * * ```ts * { * "packages": { * "next": "^14.0.0", * "react": "^17.0.0" * } * } * ``` * * @param packageJson The JSON parsed package.json file. */ export function getStackInfo(packageJson) { const packages = {}; try { const pkg = packageJson; const dependencies = pkg?.dependencies ?? {}; const devDependencies = pkg?.devDependencies ?? {}; const peerDependencies = pkg?.peerDependencies ?? {}; const allDependencies = { ...dependencies, ...devDependencies, ...peerDependencies, }; for (const dependencyName of RelevantPackages) { if (dependencyName in allDependencies) { const dependencyVersion = allDependencies[dependencyName]; if (typeof dependencyVersion !== "string") continue; packages[dependencyName] = dependencyVersion; } } return { packages }; } catch { return { packages }; } }