feat: allow scoped name as bin name (#7237)

close #7112
This commit is contained in:
await-ovo
2023-10-24 11:38:24 +08:00
committed by GitHub
parent a60e7fee30
commit d2dc2e66ab
3 changed files with 31 additions and 3 deletions

View File

@@ -0,0 +1,6 @@
---
"@pnpm/package-bins": patch
"pnpm": patch
---
Allow scoped name as bin name [#7112](https://github.com/pnpm/pnpm/issues/7112).

View File

@@ -42,16 +42,20 @@ function commandsFromBin (bin: PackageBin, pkgName: string, pkgPath: string) {
if (typeof bin === 'string') {
return [
{
name: pkgName[0] === '@' ? pkgName.slice(pkgName.indexOf('/') + 1) : pkgName,
name: normalizeBinName(pkgName),
path: path.join(pkgPath, bin),
},
]
}
return Object.keys(bin)
.filter((commandName) => encodeURIComponent(commandName) === commandName || commandName === '$')
.filter((commandName) => encodeURIComponent(commandName) === commandName || commandName === '$' || commandName[0] === '@')
.map((commandName) => ({
name: commandName,
name: normalizeBinName(commandName),
path: path.join(pkgPath, bin[commandName]),
}))
.filter((cmd) => isSubdir(pkgPath, cmd.path))
}
function normalizeBinName (name: string) {
return name[0] === '@' ? name.slice(name.indexOf('/') + 1) : name
}

View File

@@ -108,3 +108,21 @@ test('skip dangerous bin locations', async () => {
]
)
})
test('get bin from scoped bin name', async () => {
expect(
await getBinsFromPackageManifest({
name: '@foo/a',
version: '1.0.0',
bin: {
'@foo/a': './a',
},
}, process.cwd())).toStrictEqual(
[
{
name: 'a',
path: path.resolve('a'),
},
]
)
})