Skip to content

Commit

Permalink
fix(pm-install): disable version by default
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Feb 21, 2024
1 parent b7ce756 commit f59c5a6
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
7 changes: 4 additions & 3 deletions docs/2.generators/pm-install.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ The `pm-install` or `pm-i` generator generates installation commands for several

## Example

<!-- automd:example generator=pm-install no-version name=package-name dev -->
<!-- automd:example generator=pm-install name=package-name dev -->

### Input

<!-- automd:pm-install no-version name="package-name" dev -->
<!-- automd:pm-install name="package-name" dev -->
<!-- /automd -->

### Output

<!-- automd:pm-install no-version name="package-name" dev -->
<!-- automd:pm-install name="package-name" dev -->

```sh
# ✨ Auto-detect
Expand Down Expand Up @@ -42,3 +42,4 @@ The `pm-install` or `pm-i` generator generates installation commands for several
- `dev`: Install as a dev dependency (defaults to `false`).
- `separate`: Separate code blocks for each package manager (defaults to `false`).
- `auto`: Auto-detect package manager using [unjs/nypm](https://github.com/unjs/nypm#-nypm) (defaults to `true`).
- `version`: Show version in install command
8 changes: 7 additions & 1 deletion src/generators/pm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,15 @@ export const pmInstall = defineGenerator({
INSTALL_COMMANDS.unshift(["npx nypm", "i"]);
}

let versionSuffix = "";
if (args.version) {
versionSuffix =
typeof args.version === "string" ? `@${args.version}` : `@^${version}`;
}

const contents = INSTALL_COMMANDS.map(
([cmd, install]) =>
`# ${cmd.includes("nypm") ? "✨ Auto-detect" : cmd}\n${cmd} ${install}${args.dev ? " -D" : ""} ${name}${version ? `@^${version}` : ""}`,
`# ${cmd.includes("nypm") ? "✨ Auto-detect" : cmd}\n${cmd} ${install}${args.dev ? " -D" : ""} ${name}${versionSuffix}`,
);

if ((args.separate ?? false) === false) {
Expand Down
2 changes: 1 addition & 1 deletion test/fixture/INPUT.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

## `pm-install`

<!-- automd:pm-install no-version dev separate-->
<!-- automd:pm-install dev separate-->
<!-- /automd -->

## `jsdocs`
Expand Down
2 changes: 1 addition & 1 deletion test/fixture/OUTPUT.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ bunx [email protected] .

## `pm-install`

<!-- automd:pm-install no-version dev separate-->
<!-- automd:pm-install dev separate-->

```sh
# ✨ Auto-detect
Expand Down

0 comments on commit f59c5a6

Please sign in to comment.