Skip to content

Commit

Permalink
fix: #29 remove versions from yarn create commands (#30)
Browse files Browse the repository at this point in the history
Co-authored-by: [email protected] <[email protected]>
Co-authored-by: HiDeoo <[email protected]>
  • Loading branch information
3 people authored Jan 31, 2025
1 parent 795479d commit b88d821
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/silent-rings-guess.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'starlight-package-managers': patch
---

Strips version from package names for the [`create`](https://starlight-package-managers.vercel.app/usage/#create) command type for the `yarn` package manager which [does not support](https://github.com/yarnpkg/yarn/issues/6587) versioned package names for this command type.
7 changes: 6 additions & 1 deletion packages/starlight-package-managers/pkg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,12 @@ export function getCommand(
}

if (pkg) {
command += ` ${pkg}`
/**
* Strip `@version` from package name for yarn create commands.
* @see https://github.com/yarnpkg/yarn/issues/6587
*/
const processedPkg = type === 'create' && pkgManager === 'yarn' ? pkg.replace(/@[^\s]+/, '') : pkg
command += ` ${processedPkg}`
}

if (options.args && options.args.length > 0) {
Expand Down
12 changes: 11 additions & 1 deletion packages/starlight-package-managers/tests/unit/commands.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,21 @@ describe('add', () => {

describe('create', () => {
test("should generate the 'create' command for supported package managers", () => {
expect(getCommands('create', 'astro', {})).toEqual(['npm create astro', 'yarn create astro', 'pnpm create astro'])
})

test("should strip versions for the 'create' command with yarn", () => {
expect(getCommands('create', 'astro@latest', {})).toEqual([
'npm create astro@latest',
'yarn create astro@latest',
'yarn create astro',
'pnpm create astro@latest',
])

expect(getCommands('create', '[email protected]', {})).toEqual([
'npm create [email protected]',
'yarn create astro',
'pnpm create [email protected]',
])
})

test("should generate the 'create' command with additional arguments", () => {
Expand Down

0 comments on commit b88d821

Please sign in to comment.