From aaefb07d0b46ea801c87511e06990fcdf3d2a4de Mon Sep 17 00:00:00 2001 From: Zoltan Kochan Date: Sat, 5 Aug 2023 12:58:03 +0300 Subject: [PATCH] fix(list): don't fail on local directory dependencies (#6911) close #6873 --- .../dependencies-hierarchy/src/getPkgInfo.ts | 5 ++- .../plugin-commands-listing/test/index.ts | 34 +++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) 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`) +})