Skip to content

Commit

Permalink
support non-ws pnpm dep resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikolai Katkov committed Jan 26, 2024
1 parent 6ba39e4 commit 0f84ef4
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
25 changes: 24 additions & 1 deletion src/lib/context/dependencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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
}

Expand Down
16 changes: 15 additions & 1 deletion src/types/pnpmLock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export interface PnpmLock {
autoInstallPeers: boolean
excludeLinksFromLockfile: boolean
}
importers: Record<
importers?: Record<
string,
{
dependencies: Record<string, PackageDescriptor>
Expand All @@ -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 {
Expand Down

0 comments on commit 0f84ef4

Please sign in to comment.