-
-
Notifications
You must be signed in to change notification settings - Fork 938
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(dlx): dlx should work when pkg name is not same as cmd name (#4682)
close #4672
- Loading branch information
Showing
28 changed files
with
1,167 additions
and
783 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"@pnpm/plugin-commands-script-runners": patch | ||
"pnpm": patch | ||
--- | ||
|
||
`pnpm dlx` should work when the bin name of the executed package isn't the same as the package name [#4672](https://github.com/pnpm/pnpm/issues/4672). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@pnpm/plugin-commands-installation": patch | ||
--- | ||
|
||
Export AddCommandOptions. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,99 @@ | ||
import PnpmError from '@pnpm/error' | ||
import { create, dlx } from '../src' | ||
import { DLX_DEFAULT_OPTS as DEFAULT_OPTS } from './utils' | ||
|
||
jest.mock('../src/dlx', () => ({ handler: jest.fn() })) | ||
|
||
beforeEach((dlx.handler as jest.Mock).mockClear) | ||
|
||
it('throws an error if called without arguments', async () => { | ||
await expect(create.handler({}, [])).rejects.toThrow(PnpmError) | ||
await expect(create.handler({ | ||
...DEFAULT_OPTS, | ||
dir: process.cwd(), | ||
}, [])).rejects.toThrow(PnpmError) | ||
expect(dlx.handler).not.toBeCalled() | ||
}) | ||
|
||
it( | ||
'appends `create-` to an unscoped package that doesn\'t start with `create-`', | ||
async () => { | ||
await create.handler({}, ['some-app']) | ||
expect(dlx.handler).toBeCalledWith({}, ['create-some-app']) | ||
await create.handler({ | ||
...DEFAULT_OPTS, | ||
dir: process.cwd(), | ||
}, ['some-app']) | ||
expect(dlx.handler).toBeCalledWith(expect.anything(), ['create-some-app']) | ||
|
||
await create.handler({}, ['create_no_dash']) | ||
expect(dlx.handler).toBeCalledWith({}, ['create-create_no_dash']) | ||
await create.handler({ | ||
...DEFAULT_OPTS, | ||
dir: process.cwd(), | ||
}, ['create_no_dash']) | ||
expect(dlx.handler).toBeCalledWith(expect.anything(), ['create-create_no_dash']) | ||
} | ||
) | ||
|
||
it( | ||
'does not append `create-` to an unscoped package that starts with `create-`', | ||
async () => { | ||
await create.handler({}, ['create-some-app']) | ||
expect(dlx.handler).toBeCalledWith({}, ['create-some-app']) | ||
await create.handler({ | ||
...DEFAULT_OPTS, | ||
dir: process.cwd(), | ||
}, ['create-some-app']) | ||
expect(dlx.handler).toBeCalledWith(expect.anything(), ['create-some-app']) | ||
|
||
await create.handler({}, ['create-']) | ||
expect(dlx.handler).toBeCalledWith({}, ['create-']) | ||
await create.handler({ | ||
...DEFAULT_OPTS, | ||
dir: process.cwd(), | ||
}, ['create-']) | ||
expect(dlx.handler).toBeCalledWith(expect.anything(), ['create-']) | ||
} | ||
) | ||
|
||
it( | ||
'appends `create-` to a scoped package that doesn\'t start with `create-`', | ||
async () => { | ||
await create.handler({}, ['@scope/some-app']) | ||
expect(dlx.handler).toBeCalledWith({}, ['@scope/create-some-app']) | ||
await create.handler({ | ||
...DEFAULT_OPTS, | ||
dir: process.cwd(), | ||
}, ['@scope/some-app']) | ||
expect(dlx.handler).toBeCalledWith(expect.anything(), ['@scope/create-some-app']) | ||
|
||
await create.handler({}, ['@scope/create_no_dash']) | ||
expect(dlx.handler).toBeCalledWith({}, ['@scope/create-create_no_dash']) | ||
await create.handler({ | ||
...DEFAULT_OPTS, | ||
dir: process.cwd(), | ||
}, ['@scope/create_no_dash']) | ||
expect(dlx.handler).toBeCalledWith(expect.anything(), ['@scope/create-create_no_dash']) | ||
} | ||
) | ||
|
||
it( | ||
'does not append `create-` to a scoped package that starts with `create-`', | ||
async () => { | ||
await create.handler({}, ['@scope/create-some-app']) | ||
expect(dlx.handler).toBeCalledWith({}, ['@scope/create-some-app']) | ||
await create.handler({ | ||
...DEFAULT_OPTS, | ||
dir: process.cwd(), | ||
}, ['@scope/create-some-app']) | ||
expect(dlx.handler).toBeCalledWith(expect.anything(), ['@scope/create-some-app']) | ||
|
||
await create.handler({}, ['@scope/create-']) | ||
expect(dlx.handler).toBeCalledWith({}, ['@scope/create-']) | ||
await create.handler({ | ||
...DEFAULT_OPTS, | ||
dir: process.cwd(), | ||
}, ['@scope/create-']) | ||
expect(dlx.handler).toBeCalledWith(expect.anything(), ['@scope/create-']) | ||
} | ||
) | ||
|
||
it('infers a package name from a plain scope', async () => { | ||
await create.handler({}, ['@scope']) | ||
expect(dlx.handler).toBeCalledWith({}, ['@scope/create']) | ||
await create.handler({ | ||
...DEFAULT_OPTS, | ||
dir: process.cwd(), | ||
}, ['@scope']) | ||
expect(dlx.handler).toBeCalledWith(expect.anything(), ['@scope/create']) | ||
}) | ||
|
||
it('passes the remaining arguments to `dlx`', async () => { | ||
await create.handler({}, ['some-app', 'directory/', '--silent']) | ||
expect(dlx.handler).toBeCalledWith({}, ['create-some-app', 'directory/', '--silent']) | ||
await create.handler({ | ||
...DEFAULT_OPTS, | ||
dir: process.cwd(), | ||
}, ['some-app', 'directory/', '--silent']) | ||
expect(dlx.handler).toBeCalledWith(expect.anything(), ['create-some-app', 'directory/', '--silent']) | ||
}) |
Oops, something went wrong.