Skip to content

Commit

Permalink
fix: pnpm bug with nesting workspaces
Browse files Browse the repository at this point in the history
  • Loading branch information
gearonix committed Mar 22, 2024
1 parent 8154103 commit 2c887dd
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions src/pkg-manager/managers/pnpm.pkg-manager.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,44 @@
import { parseJson } from '@neodx/fs'
import { concurrently, isTruthy, isTypeOfString } from '@neodx/std'
import {
compact,
concurrently,
isTruthy,
isTypeOfString
} from '@neodx/std'
import { cpus } from 'node:os'
import { pathEqual } from 'path-equal'
import { AbstractPackageManager } from '@/pkg-manager/managers/abstract.pkg-manager'
import { PackageManager, ROOT_PROJECT } from '@/pkg-manager/pkg-manager.consts'
import type { PackageManagerFactoryOptions } from '@/pkg-manager/pkg-manager.factory'
import type { RunCommandOptions } from '@/pkg-manager/pkg-manager.types'

type PnpmWorkspaceMeta = Array<{
interface PnpmWorkspaceMeta {
name: string
version?: string
path: string
private?: boolean
}>
}

export class PnpmPackageManager extends AbstractPackageManager {
constructor(opts: PackageManagerFactoryOptions) {
super(opts, PackageManager.PNPM)
}

public async computeWorkspaceProjects(): Promise<void> {
const output = await this.exec('list --recursive --depth -1 --json')
const workspaces = parseJson<PnpmWorkspaceMeta>(output)

if (!Array.isArray(workspaces)) {
return this.updateProjects()
}
const rawOutput = await this.exec('list --recursive --depth -1 --json')
const serializedMeta = compact(rawOutput.split(']')).map((s) =>
s.concat(']')
)

const pnpmWorkspaces = await concurrently(
workspaces,
async ({ name, path }) => {
serializedMeta,
async (meta) => {
const [workspaceMeta] = parseJson<[PnpmWorkspaceMeta]>(meta)
const { path, name } = workspaceMeta

const isRoot = pathEqual(path, process.cwd())
if (isRoot) return null

if (!isRoot) return

const { targets, type } =
await this.resolver.resolveProjectTargets(path)
Expand Down

0 comments on commit 2c887dd

Please sign in to comment.