diff --git a/src/pkg-manager/managers/pnpm.pkg-manager.ts b/src/pkg-manager/managers/pnpm.pkg-manager.ts index aa68c16..92046c4 100644 --- a/src/pkg-manager/managers/pnpm.pkg-manager.ts +++ b/src/pkg-manager/managers/pnpm.pkg-manager.ts @@ -1,5 +1,10 @@ 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' @@ -7,12 +12,12 @@ 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) { @@ -20,18 +25,20 @@ export class PnpmPackageManager extends AbstractPackageManager { } public async computeWorkspaceProjects(): Promise { - const output = await this.exec('list --recursive --depth -1 --json') - const workspaces = parseJson(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)