fix: don't list commands twice in workspace root (#3423)

This commit is contained in:
Zoltan Kochan
2021-05-07 11:46:03 +03:00
committed by GitHub
parent 0e69ad4403
commit ff9714d783
3 changed files with 40 additions and 11 deletions

View File

@@ -0,0 +1,5 @@
---
"@pnpm/plugin-commands-script-runners": patch
---
Don't list the commands twice when `pnpm run` is executed in the root of a workspace.

View File

@@ -136,7 +136,9 @@ export async function handler (
}
const manifest = await readProjectManifestOnly(dir, opts)
if (!scriptName) {
const rootManifest = opts.workspaceDir ? (await tryReadProjectManifest(opts.workspaceDir, opts)).manifest : undefined
const rootManifest = opts.workspaceDir && opts.workspaceDir !== dir
? (await tryReadProjectManifest(opts.workspaceDir, opts)).manifest
: undefined
return printProjectCommands(manifest, rootManifest ?? undefined)
}
if (scriptName !== 'start' && !manifest.scripts?.[scriptName]) {

View File

@@ -295,17 +295,18 @@ test('"pnpm run" prints the list of available commands, including commands of th
const { allProjects, selectedProjectsGraph } = await readProjects(process.cwd(), [])
process.chdir('foo')
const output = await run.handler({
allProjects,
dir: process.cwd(),
extraBinPaths: [],
rawConfig: {},
selectedProjectsGraph,
workspaceDir,
}, [])
{
process.chdir('foo')
const output = await run.handler({
allProjects,
dir: process.cwd(),
extraBinPaths: [],
rawConfig: {},
selectedProjectsGraph,
workspaceDir,
}, [])
expect(output).toBe(`\
expect(output).toBe(`\
Lifecycle scripts:
test
ts-node test
@@ -319,6 +320,27 @@ Commands of the root workspace project (to run them, use "pnpm -w run"):
echo root
test
test-all`)
}
{
process.chdir('..')
const output = await run.handler({
allProjects,
dir: process.cwd(),
extraBinPaths: [],
rawConfig: {},
selectedProjectsGraph,
workspaceDir,
}, [])
expect(output).toBe(`\
Lifecycle scripts:
test
test-all
Commands available via "pnpm run":
build
echo root`)
}
})
test('pnpm run does not fail with --if-present even if the wanted script is not present', async () => {