diff --git a/.changeset/green-cows-work.md b/.changeset/green-cows-work.md new file mode 100644 index 0000000000..9f9a2936c8 --- /dev/null +++ b/.changeset/green-cows-work.md @@ -0,0 +1,6 @@ +--- +"@pnpm/plugin-commands-init": patch +"pnpm": patch +--- + +Throw an error if arguments are passed to the `pnpm init` command. diff --git a/packages/plugin-commands-init/src/init.ts b/packages/plugin-commands-init/src/init.ts index 96b506cea4..1bb07f8a40 100644 --- a/packages/plugin-commands-init/src/init.ts +++ b/packages/plugin-commands-init/src/init.ts @@ -25,8 +25,14 @@ export function help () { } export async function handler ( - opts: Pick + opts: Pick, + 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') diff --git a/packages/plugin-commands-init/test/init.test.ts b/packages/plugin-commands-init/test/init.test.ts index 3770ba6d12..30ba1cbfaf 100644 --- a/packages/plugin-commands-init/test/init.test.ts +++ b/packages/plugin-commands-init/test/init.test.ts @@ -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') +})