mirror of
https://github.com/pnpm/pnpm.git
synced 2026-04-27 18:46:18 -04:00
fix(init): throw an error if arguments are passed to init command (#4665)
close #4662
This commit is contained in:
6
.changeset/green-cows-work.md
Normal file
6
.changeset/green-cows-work.md
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
"@pnpm/plugin-commands-init": patch
|
||||
"pnpm": patch
|
||||
---
|
||||
|
||||
Throw an error if arguments are passed to the `pnpm init` command.
|
||||
@@ -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')
|
||||
|
||||
@@ -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')
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user