Skip to content

Commit 5d363ac

Browse files
authored
feat(publish): add packageManager option (#26)
1 parent 032519c commit 5d363ac

File tree

4 files changed

+15
-4
lines changed

4 files changed

+15
-4
lines changed

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ release({
2222
).toString(),
2323
),
2424
generateChangelog: (pkg, version) => {},
25-
// use getPkgDir when not using a monorepo. Default to `packages/${pkg}`
25+
// Use getPkgDir when not using a monorepo. Default to `packages/${pkg}`
2626
getPkgDir: (pkg) => ".",
2727
});
2828
```
@@ -35,7 +35,11 @@ import { publish } from "@vitejs/release-scripts";
3535
publish({
3636
// Used when tag is not `pkg@version`
3737
defaultPackage: "release-scripts",
38-
// use getPkgDir when not in a monorepo. Default to `packages/${pkg}`
38+
// Use getPkgDir when not in a monorepo. Default to `packages/${pkg}`
3939
getPkgDir: (pkg) => ".",
40+
// Publish with provenance https://docs.npmjs.com/generating-provenance-statements
41+
provenance: true,
42+
// Package manager that runs the publish command
43+
packageManager: "pnpm",
4044
});
4145
```

src/publish.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export const publish: typeof def = async ({
1212
defaultPackage,
1313
getPkgDir,
1414
provenance,
15+
packageManager,
1516
}) => {
1617
const tag = args._[0];
1718
if (!tag) throw new Error("No tag specified");
@@ -40,5 +41,5 @@ export const publish: typeof def = async ({
4041
: activeVersion && semver.lt(pkg.version, activeVersion)
4142
? "previous"
4243
: undefined;
43-
await publishPackage(pkgDir, releaseTag, provenance);
44+
await publishPackage(pkgDir, releaseTag, provenance, packageManager);
4445
};

src/types.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ export declare function publish(options: {
66
* @default false
77
*/
88
provenance?: boolean;
9+
/**
10+
* Package manager that runs the publish command
11+
* @default "npm"
12+
*/
13+
packageManager?: "npm" | "pnpm";
914
}): Promise<void>;
1015

1116
export declare function release(options: {

src/utils.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ export async function publishPackage(
138138
pkgDir: string,
139139
tag?: string,
140140
provenance?: boolean,
141+
packageManager: "npm" | "pnpm" = "npm",
141142
): Promise<void> {
142143
const publicArgs = ["publish", "--access", "public"];
143144
if (tag) {
@@ -146,7 +147,7 @@ export async function publishPackage(
146147
if (provenance) {
147148
publicArgs.push(`--provenance`);
148149
}
149-
await runIfNotDry("npm", publicArgs, {
150+
await runIfNotDry(packageManager, publicArgs, {
150151
cwd: pkgDir,
151152
});
152153
}

0 commit comments

Comments
 (0)