Skip to content

Commit

Permalink
fix: license ls should work even when there is a patched git protocol…
Browse files Browse the repository at this point in the history
… dependency (#6681)

close #6595
  • Loading branch information
await-ovo authored and zkochan committed Jun 17, 2023
1 parent 5c1a033 commit fac4501
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 2 deletions.
7 changes: 7 additions & 0 deletions .changeset/wet-laws-retire.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@pnpm/plugin-commands-licenses": patch
"@pnpm/license-scanner": patch
"pnpm": patch
---

`pnpm license ls` should work even when there is a patched git protocol dependency [#6595](https://github.com/pnpm/pnpm/issues/6595)
4 changes: 2 additions & 2 deletions reviewing/license-scanner/src/getPkgInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,9 @@ export async function readPackageIndexFile (
)
} else if (!packageResolution.type && packageResolution.tarball) {
// If the package resolution has a tarball then we need to clean up
// the call to depPathToFilename as it adds '_[hash]' part to the
// 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(depPath).split('_')[0]
pkgIndexFilePath = path.join(
opts.storeDir,
packageDirInStore,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "with-patched-deps",
"version": "1.0.0",
"dependencies": {
"is-positive": "github:kevva/is-positive"
},
"pnpm": {
"patchedDependencies": {
"is-positive@3.1.0": "patches/is-positive@3.1.0.patch"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
diff --git a/index.js b/index.js
index ce27efbbbf6aaecfae5709f67181a15fe20dc602..4ba2734688ebdd8e8041bf6d373e5434c1c38ddb 100644
--- a/index.js
+++ b/index.js
@@ -1,4 +1,5 @@
'use strict';
+console.log('patched')
module.exports = function (n) {
return toString.call(n) === '[object Number]' && n > 0;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "with-git-protocol-peer-deps",
"version": "1.0.0",
"dependencies": {
"ajv-keywords": "github:ajv-validator/ajv-keywords"
}
}
46 changes: 46 additions & 0 deletions reviewing/plugin-commands-licenses/test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,3 +186,49 @@ test('pnpm licenses should work with file protocol dependency', async () => {
expect(exitCode).toBe(0)
expect(stripAnsi(output)).toMatchSnapshot('show-packages')
})

test('pnpm licenses should work with git protocol dep that have patches', async () => {
const workspaceDir = tempDir()
f.copy('with-git-protocol-patched-deps', 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)
})

test('pnpm licenses should work with git protocol dep that have peerDependencies', async () => {
const workspaceDir = tempDir()
f.copy('with-git-protocol-peer-deps', 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)
})

0 comments on commit fac4501

Please sign in to comment.