diff --git a/reviewing/dependencies-hierarchy/src/getPkgInfo.ts b/reviewing/dependencies-hierarchy/src/getPkgInfo.ts index d3af243108..b7ede3282f 100644 --- a/reviewing/dependencies-hierarchy/src/getPkgInfo.ts +++ b/reviewing/dependencies-hierarchy/src/getPkgInfo.ts @@ -39,7 +39,7 @@ export interface GetPkgInfoOpts { export function getPkgInfo (opts: GetPkgInfoOpts): PackageInfo { let name!: string - let version!: string + let version: string let resolved: string | undefined let dev: boolean | undefined let optional: true | undefined @@ -73,6 +73,9 @@ export function getPkgInfo (opts: GetPkgInfoOpts): PackageInfo { name = opts.alias version = opts.ref } + if (!version) { + version = opts.ref + } const fullPackagePath = depPath ? path.join(opts.virtualStoreDir ?? '.pnpm', depPathToFilename(depPath), 'node_modules', name) : path.join(opts.linkedPathBaseDir, opts.ref.slice(5)) diff --git a/reviewing/plugin-commands-listing/test/index.ts b/reviewing/plugin-commands-listing/test/index.ts index c61a57dea6..d33ea024d6 100644 --- a/reviewing/plugin-commands-listing/test/index.ts +++ b/reviewing/plugin-commands-listing/test/index.ts @@ -154,3 +154,37 @@ pkg-with-optional 1.0.0 └── not-compatible-with-any-os 1.0.0 skipped`) } }) + +// Covers https://github.com/pnpm/pnpm/issues/6873 +test('listing packages should not fail on package that has local file directory in dependencies', async () => { + preparePackages([ + { + name: 'dep', + version: '1.0.0', + }, + { + name: 'pkg', + version: '1.0.0', + + dependencies: { + dep: 'file:../dep', + }, + }, + ]) + + const pkgDir = path.resolve('pkg') + await execa('node', [pnpmBin, 'install'], { cwd: pkgDir }) + + const output = await list.handler({ + dev: false, + dir: pkgDir, + optional: false, + }, []) + + expect(stripAnsi(output)).toBe(`Legend: production dependency, optional only, dev only + +pkg@1.0.0 ${pkgDir} + +dependencies: +dep file:../dep`) +})