diff --git a/src/lib/context/dependencies.ts b/src/lib/context/dependencies.ts index 41ea1ff..8755693 100644 --- a/src/lib/context/dependencies.ts +++ b/src/lib/context/dependencies.ts @@ -99,7 +99,7 @@ interface GetInstalledPackagesParameters { projectDirectory: string } -// eslint-disable-next-line sonarjs/cognitive-complexity +// eslint-disable-next-line sonarjs/cognitive-complexity, complexity const getPnpmPackages = (projectDirectory: string): InstalledPackage[] => { const installedPackages: InstalledPackage[] = [] const pnpmLockRaw = fs.readFileSync(path.join(projectDirectory, 'pnpm-lock.yaml'), 'utf8') @@ -140,6 +140,29 @@ const getPnpmPackages = (projectDirectory: string): InstalledPackage[] => { } } + for (const dependencyName in pnpmLock.dependencies) { + if (Object.prototype.hasOwnProperty.call(pnpmLock.dependencies, dependencyName)) { + const dependency = pnpmLock.dependencies[dependencyName] + installedPackages.push({ + name: dependencyName, + isDev: false, + version: dependency.version, + }) + } + } + + for (const dependencyName in pnpmLock.devDependencies) { + if (Object.prototype.hasOwnProperty.call(pnpmLock.devDependencies, dependencyName)) { + const dependency = pnpmLock.devDependencies[dependencyName] + installedPackages.push({ + name: dependencyName, + isDev: true, + version: dependency.version, + }) + } + } + console.log(installedPackages) + return installedPackages } diff --git a/src/types/pnpmLock.ts b/src/types/pnpmLock.ts index 3382efc..4f48f25 100644 --- a/src/types/pnpmLock.ts +++ b/src/types/pnpmLock.ts @@ -6,7 +6,7 @@ export interface PnpmLock { autoInstallPeers: boolean excludeLinksFromLockfile: boolean } - importers: Record< + importers?: Record< string, { dependencies: Record @@ -31,6 +31,20 @@ export interface PnpmLock { dev: boolean } > + dependencies?: Record< + string, + { + specifier: string + version: string + } + > + devDependencies?: Record< + string, + { + specifier: string + version: string + } + > } interface PackageDescriptor {