diff --git a/.changeset/silly-dryers-pull.md b/.changeset/silly-dryers-pull.md new file mode 100644 index 0000000000..a6d3f47360 --- /dev/null +++ b/.changeset/silly-dryers-pull.md @@ -0,0 +1,7 @@ +--- +"@pnpm/plugin-commands-licenses": patch +"@pnpm/license-scanner": patch +"pnpm": patch +--- + +Handle Git repository names containing capital letters [#7488](https://github.com/pnpm/pnpm/pull/7488). diff --git a/reviewing/license-scanner/src/getPkgInfo.ts b/reviewing/license-scanner/src/getPkgInfo.ts index fedb4fa73a..08252d040a 100644 --- a/reviewing/license-scanner/src/getPkgInfo.ts +++ b/reviewing/license-scanner/src/getPkgInfo.ts @@ -158,7 +158,7 @@ async function readLicenseFileFromCafs (cafsDir: string, { integrity, mode }: Pa */ export async function readPackageIndexFile ( packageResolution: Resolution, - depPath: string, + id: string, opts: { cafsDir: string, storeDir: string, lockfileDir: string } ): Promise< | { @@ -195,10 +195,7 @@ export async function readPackageIndexFile ( 'index' ) } else if (!packageResolution.type && packageResolution.tarball) { - // If the package resolution has a tarball then we need to clean up - // the return value to depPathToFilename as it adds peer deps(e.g. a@1.0.0_peer-foo@18.0.0_peer-bar@18.0.0) or patch hash(a@1.0.0_patch_hash=xxxx) part to the - // directory for the package in the content-addressable store - const packageDirInStore = depPathToFilename(depPath).split('_')[0] + const packageDirInStore = depPathToFilename(id) pkgIndexFilePath = path.join( opts.storeDir, packageDirInStore, @@ -207,7 +204,7 @@ export async function readPackageIndexFile ( } else { throw new PnpmError( 'UNSUPPORTED_PACKAGE_TYPE', - `Unsupported package resolution type for ${depPath}` + `Unsupported package resolution type for ${id}` ) } @@ -221,7 +218,7 @@ export async function readPackageIndexFile ( if (err.code === 'ENOENT') { throw new PnpmError( 'MISSING_PACKAGE_INDEX_FILE', - `Failed to find package index file for ${depPath}, please consider running 'pnpm install'` + `Failed to find package index file for ${id}, please consider running 'pnpm install'` ) } @@ -230,6 +227,7 @@ export async function readPackageIndexFile ( } export interface PackageInfo { + id: string name?: string version?: string depPath: string @@ -270,7 +268,7 @@ export async function getPkgInfo ( const packageFileIndexInfo = await readPackageIndexFile( packageResolution as Resolution, - pkg.depPath, + pkg.id, { cafsDir, storeDir: opts.storeDir, diff --git a/reviewing/license-scanner/src/lockfileToLicenseNodeTree.ts b/reviewing/license-scanner/src/lockfileToLicenseNodeTree.ts index 642a0c7165..c573abeee7 100644 --- a/reviewing/license-scanner/src/lockfileToLicenseNodeTree.ts +++ b/reviewing/license-scanner/src/lockfileToLicenseNodeTree.ts @@ -68,6 +68,7 @@ export async function lockfileToLicenseNode ( const packageInfo = await getPkgInfo( { + id: pkgSnapshot.id ?? depPath, name, version, depPath, diff --git a/reviewing/license-scanner/test/getPkgInfo.spec.ts b/reviewing/license-scanner/test/getPkgInfo.spec.ts index c4b524ad07..1ee70a1b8e 100644 --- a/reviewing/license-scanner/test/getPkgInfo.spec.ts +++ b/reviewing/license-scanner/test/getPkgInfo.spec.ts @@ -11,6 +11,7 @@ describe('licences', () => { { name: 'bogus-package', version: '1.0.0', + id: '/bogus-package/1.0.0', depPath: '/bogus-package/1.0.0', snapshot: { resolution: { diff --git a/reviewing/plugin-commands-licenses/test/fixtures/with-git-protocol-caps/package.json b/reviewing/plugin-commands-licenses/test/fixtures/with-git-protocol-caps/package.json new file mode 100644 index 0000000000..1b65682175 --- /dev/null +++ b/reviewing/plugin-commands-licenses/test/fixtures/with-git-protocol-caps/package.json @@ -0,0 +1,7 @@ +{ + "name": "with-git-protocol-caps", + "version": "1.0.0", + "dependencies": { + "capitalized-repo": "github:pnpm-e2e/Capitalized-Repo" + } +} diff --git a/reviewing/plugin-commands-licenses/test/index.ts b/reviewing/plugin-commands-licenses/test/index.ts index a2eb7a743c..3d5e61ea17 100644 --- a/reviewing/plugin-commands-licenses/test/index.ts +++ b/reviewing/plugin-commands-licenses/test/index.ts @@ -255,3 +255,26 @@ test('pnpm licenses should work with git protocol dep that have peerDependencies expect(exitCode).toBe(0) }) + +test('pnpm licenses should work git repository name containing capital letters', async () => { + const workspaceDir = tempDir() + f.copy('with-git-protocol-caps', workspaceDir) + + const storeDir = path.join(workspaceDir, 'store') + await install.handler({ + ...DEFAULT_OPTS, + dir: workspaceDir, + pnpmHomeDir: '', + storeDir, + }) + + const { exitCode } = await licenses.handler({ + ...DEFAULT_OPTS, + dir: workspaceDir, + pnpmHomeDir: '', + long: false, + storeDir: path.resolve(storeDir, 'v3'), + }, ['list']) + + expect(exitCode).toBe(0) +})