Skip to content

Commit ffada82

Browse files
committed
fix(pm-x): make version optional
1 parent 5fe253e commit ffada82

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

docs/2.generators/pm-x.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,4 @@ The `pm-x` generator generates commands for running/executing a package through
3535
- `name`: The package name (by default tries to read from the `name` field in `package.json`).
3636
- `separate`: Separate code blocks for each package manager (defaults to `false`).
3737
- `args`: An additional string appended at the end of each command suggesting arguments to be used with the program. (defaults to `""`).
38+
- `version`: Show version in exec command

src/generators/pm.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,15 @@ export const pmX = defineGenerator({
6464
};
6565
}
6666

67+
let versionSuffix = "";
68+
if (args.version) {
69+
versionSuffix =
70+
typeof args.version === "string" ? `@${args.version}` : `@${version}`;
71+
}
72+
6773
const contents = RUN_COMMANDS.map(
6874
([pm, cmd]) =>
69-
`# ${pm}\n${cmd} ${name}@${version ? `${version}` : ""}${args.args ? ` ${args.args}` : ""}`,
75+
`# ${pm}\n${cmd} ${name}${versionSuffix}${args.args ? ` ${args.args}` : ""}`,
7076
);
7177

7278
if ((args.separate ?? false) === false) {

test/fixture/OUTPUT.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@
1717

1818
```sh
1919
# npm
20-
npx automd@0.3.4 .
20+
npx automd .
2121

2222
# pnpm
23-
pnpm dlx automd@0.3.4 .
23+
pnpm dlx automd .
2424

2525
# bun
26-
bunx automd@0.3.4 .
26+
bunx automd .
2727
```
2828

2929
<!-- /automd -->

0 commit comments

Comments
 (0)