mirror of
https://github.com/pnpm/pnpm.git
synced 2026-03-27 11:31:45 -04:00
- Rename `installing/core` → `installing/deps-installer` and `installing/headless` → `installing/deps-restorer` for clearer naming
- Rename all `plugin-commands-*` directories to use `-commands` suffix convention
- Merge multiple command packages per domain into a single `commands/` directory (one commands package per domain rule):
- `building/{build-commands,policy-commands}` → `building/commands`
- `deps/compliance/{audit-commands,licenses-commands,sbom-commands}` → `deps/compliance/commands`
- `deps/inspection/{listing-commands,outdated-commands}` → `deps/inspection/commands`
- `store/{store-commands,inspecting-commands}` → `store/commands`
- `releasing/{publish-commands,deploy-commands}` → `releasing/commands`
- `cli/{completion-commands,doctor-commands}` → `cli/commands`
- `engine/pm/{self-updater-commands,setup-commands}` → `engine/pm/commands`
- `engine/runtime/{runtime-commands,env-commands}` → `engine/runtime/commands`
- `cache/cache-commands` → `cache/commands`
- Fix relative paths in merged test files (pnpmBin, __typings__ references)
- Update jest config to ignore `utils/` dirs at any nesting depth under `test/`
- Fix stale package names in changeset files
143 lines
4.2 KiB
TypeScript
143 lines
4.2 KiB
TypeScript
import { jest } from '@jest/globals'
|
|
import { PnpmError } from '@pnpm/error'
|
|
|
|
import { DLX_DEFAULT_OPTS as DEFAULT_OPTS } from './utils/index.js'
|
|
|
|
jest.unstable_mockModule('../src/dlx.js', () => ({ handler: jest.fn() }))
|
|
|
|
const { create, dlx } = await import('../src/index.js')
|
|
|
|
beforeEach(() => jest.mocked(dlx.handler).mockClear())
|
|
|
|
it('throws an error if called without arguments', async () => {
|
|
await expect(create.handler({
|
|
...DEFAULT_OPTS,
|
|
dir: process.cwd(),
|
|
}, [])).rejects.toThrow(PnpmError)
|
|
expect(dlx.handler).not.toHaveBeenCalled()
|
|
})
|
|
|
|
it(
|
|
'appends `create-` to an unscoped package that doesn\'t start with `create-`',
|
|
async () => {
|
|
await create.handler({
|
|
...DEFAULT_OPTS,
|
|
dir: process.cwd(),
|
|
}, ['some-app'])
|
|
expect(dlx.handler).toHaveBeenCalledWith(expect.anything(), ['create-some-app'])
|
|
|
|
await create.handler({
|
|
...DEFAULT_OPTS,
|
|
dir: process.cwd(),
|
|
}, ['create_no_dash'])
|
|
expect(dlx.handler).toHaveBeenCalledWith(expect.anything(), ['create-create_no_dash'])
|
|
}
|
|
)
|
|
|
|
it(
|
|
'does not append `create-` to an unscoped package that starts with `create-`',
|
|
async () => {
|
|
await create.handler({
|
|
...DEFAULT_OPTS,
|
|
dir: process.cwd(),
|
|
}, ['create-some-app'])
|
|
expect(dlx.handler).toHaveBeenCalledWith(expect.anything(), ['create-some-app'])
|
|
|
|
await create.handler({
|
|
...DEFAULT_OPTS,
|
|
dir: process.cwd(),
|
|
}, ['create-'])
|
|
expect(dlx.handler).toHaveBeenCalledWith(expect.anything(), ['create-'])
|
|
}
|
|
)
|
|
|
|
it(
|
|
'appends `create-` to a scoped package that doesn\'t start with `create-`',
|
|
async () => {
|
|
await create.handler({
|
|
...DEFAULT_OPTS,
|
|
dir: process.cwd(),
|
|
}, ['@scope/some-app'])
|
|
expect(dlx.handler).toHaveBeenCalledWith(expect.anything(), ['@scope/create-some-app'])
|
|
|
|
await create.handler({
|
|
...DEFAULT_OPTS,
|
|
dir: process.cwd(),
|
|
}, ['@scope/create_no_dash'])
|
|
expect(dlx.handler).toHaveBeenCalledWith(expect.anything(), ['@scope/create-create_no_dash'])
|
|
}
|
|
)
|
|
|
|
it(
|
|
'does not append `create-` to a scoped package that starts with `create-`',
|
|
async () => {
|
|
await create.handler({
|
|
...DEFAULT_OPTS,
|
|
dir: process.cwd(),
|
|
}, ['@scope/create-some-app'])
|
|
expect(dlx.handler).toHaveBeenCalledWith(expect.anything(), ['@scope/create-some-app'])
|
|
|
|
await create.handler({
|
|
...DEFAULT_OPTS,
|
|
dir: process.cwd(),
|
|
}, ['@scope/create-'])
|
|
expect(dlx.handler).toHaveBeenCalledWith(expect.anything(), ['@scope/create-'])
|
|
}
|
|
)
|
|
|
|
it('infers a package name from a plain scope', async () => {
|
|
await create.handler({
|
|
...DEFAULT_OPTS,
|
|
dir: process.cwd(),
|
|
}, ['@scope'])
|
|
expect(dlx.handler).toHaveBeenCalledWith(expect.anything(), ['@scope/create'])
|
|
})
|
|
|
|
it('passes the remaining arguments to `dlx`', async () => {
|
|
await create.handler({
|
|
...DEFAULT_OPTS,
|
|
dir: process.cwd(),
|
|
}, ['some-app', 'directory/', '--silent'])
|
|
expect(dlx.handler).toHaveBeenCalledWith(expect.anything(), ['create-some-app', 'directory/', '--silent'])
|
|
})
|
|
|
|
it(
|
|
'appends `create` to package with preferred version`',
|
|
async () => {
|
|
await create.handler({
|
|
...DEFAULT_OPTS,
|
|
dir: process.cwd(),
|
|
}, ['foo@2.0.0'])
|
|
expect(dlx.handler).toHaveBeenCalledWith(expect.anything(), ['create-foo@2.0.0'])
|
|
await create.handler({
|
|
...DEFAULT_OPTS,
|
|
dir: process.cwd(),
|
|
}, ['foo@latest'])
|
|
expect(dlx.handler).toHaveBeenCalledWith(expect.anything(), ['create-foo@latest'])
|
|
|
|
await create.handler({
|
|
...DEFAULT_OPTS,
|
|
dir: process.cwd(),
|
|
}, ['@scope@2.0.0'])
|
|
expect(dlx.handler).toHaveBeenCalledWith(expect.anything(), ['@scope/create@2.0.0'])
|
|
|
|
await create.handler({
|
|
...DEFAULT_OPTS,
|
|
dir: process.cwd(),
|
|
}, ['@scope@next'])
|
|
expect(dlx.handler).toHaveBeenCalledWith(expect.anything(), ['@scope/create@next'])
|
|
|
|
await create.handler({
|
|
...DEFAULT_OPTS,
|
|
dir: process.cwd(),
|
|
}, ['@scope/foo@2.0.0'])
|
|
expect(dlx.handler).toHaveBeenCalledWith(expect.anything(), ['@scope/create-foo@2.0.0'])
|
|
|
|
await create.handler({
|
|
...DEFAULT_OPTS,
|
|
dir: process.cwd(),
|
|
}, ['@scope/create-a@2.0.0'])
|
|
expect(dlx.handler).toHaveBeenCalledWith(expect.anything(), ['@scope/create-a@2.0.0'])
|
|
}
|
|
)
|