fix(init): throw an error if arguments are passed to init command (#4665)

close #4662
This commit is contained in:
Zoltan Kochan
2022-05-05 12:10:11 +03:00
committed by GitHub
parent c3cebd536c
commit 0eefba9bee
3 changed files with 21 additions and 1 deletions

View File

@@ -0,0 +1,6 @@
---
"@pnpm/plugin-commands-init": patch
"pnpm": patch
---
Throw an error if arguments are passed to the `pnpm init` command.

View File

@@ -25,8 +25,14 @@ export function help () {
}
export async function handler (
opts: Pick<UniversalOptions, 'rawConfig'>
opts: Pick<UniversalOptions, 'rawConfig'>,
params?: string[]
) {
if (params?.length) {
throw new PnpmError('INIT_ARG', 'init command does not accept any arguments', {
hint: `Maybe you wanted to run "pnpm create ${params.join(' ')}"`,
})
}
// Using cwd instead of the dir option because the dir option
// is set to the first parent directory that has a package.json file.
const manifestPath = path.join(process.cwd(), 'package.json')

View File

@@ -34,3 +34,11 @@ test('init a new package.json with npmrc', async () => {
expect(manifest.author).toBe(expectAuthor)
expect(manifest.license).toBe(rawConfig['init-license'])
})
test('throw an error if params are passed to the init command', async () => {
prepare({})
await expect(
init.handler({ rawConfig: {} }, ['react-app'])
).rejects.toThrow('init command does not accept any arguments')
})