fix(license-scanner): handle git repo names with capital letters (#7488)

---------

Co-authored-by: Zoltan Kochan <z@kochan.io>
This commit is contained in:
Eric Higgins
2024-01-09 02:18:38 -08:00
committed by Zoltan Kochan
parent d9564e3546
commit dcf3ef7e4f
6 changed files with 45 additions and 8 deletions

View File

@@ -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).

View File

@@ -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,

View File

@@ -68,6 +68,7 @@ export async function lockfileToLicenseNode (
const packageInfo = await getPkgInfo(
{
id: pkgSnapshot.id ?? depPath,
name,
version,
depPath,

View File

@@ -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: {

View File

@@ -0,0 +1,7 @@
{
"name": "with-git-protocol-caps",
"version": "1.0.0",
"dependencies": {
"capitalized-repo": "github:pnpm-e2e/Capitalized-Repo"
}
}

View File

@@ -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)
})