Skip to content

Commit e125e76

Browse files
authored
feat: provenance option (#16)
1 parent 3327612 commit e125e76

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

src/publish.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ import {
88
} from "./utils";
99
import type { publish as def } from "./types";
1010

11-
export const publish: typeof def = async ({ defaultPackage, getPkgDir }) => {
11+
export const publish: typeof def = async ({
12+
defaultPackage,
13+
getPkgDir,
14+
provenance,
15+
}) => {
1216
const tag = args._[0];
1317
if (!tag) throw new Error("No tag specified");
1418

@@ -36,5 +40,5 @@ export const publish: typeof def = async ({ defaultPackage, getPkgDir }) => {
3640
: activeVersion && semver.lt(pkg.version, activeVersion)
3741
? "previous"
3842
: undefined;
39-
await publishPackage(pkgDir, releaseTag);
43+
await publishPackage(pkgDir, releaseTag, provenance);
4044
};

src/types.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
export declare function publish(options: {
22
defaultPackage: string;
33
getPkgDir?: (pkg: string) => string;
4+
/**
5+
* Enables npm package provenance https://docs.npmjs.com/generating-provenance-statements
6+
* @default false
7+
*/
8+
provenance?: boolean;
49
}): Promise<void>;
510

611
export declare function release(options: {

src/utils.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,15 @@ export function updateVersion(pkgPath: string, version: string): void {
137137
export async function publishPackage(
138138
pkdDir: string,
139139
tag?: string,
140+
provenance?: boolean,
140141
): Promise<void> {
141142
const publicArgs = ["publish", "--access", "public"];
142143
if (tag) {
143144
publicArgs.push(`--tag`, tag);
144145
}
146+
if (provenance) {
147+
publicArgs.push(`--provenance`);
148+
}
145149
await runIfNotDry("npm", publicArgs, {
146150
cwd: pkdDir,
147151
});

0 commit comments

Comments
 (0)