Skip to content

Commit d8f3322

Browse files
committed
Add npm provenance support
Fixes #701
1 parent 0a8af7b commit d8f3322

5 files changed

Lines changed: 18 additions & 0 deletions

File tree

readme.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ $ np --help
7373
--no-2fa Don't enable 2FA on new packages (not recommended)
7474
--message Version bump commit message, '%s' will be replaced with version (default: '%s' with npm and 'v%s' with yarn)
7575
--package-manager Use a specific package manager (default: 'packageManager' field in package.json)
76+
--provenance Publish with npm provenance statements (CI-only)
7677
7778
Examples
7879
$ np
@@ -109,6 +110,7 @@ Currently, these are the flags you can configure:
109110
- `2fa` - Enable 2FA on new packages (`true` by default) (setting this to `false` is not recommended).
110111
- `message` - The commit message used for the version bump. Any `%s` in the string will be replaced with the new version. By default, npm uses `%s` and Yarn uses `v%s`.
111112
- `packageManager` - Set the package manager to be used. Defaults to the [packageManager field in package.json](https://nodejs.org/dist/latest-v16.x/docs/api/all.html#all_packages_packagemanager), so only use if you can't update package.json for some reason.
113+
- `provenance` - Publish with [npm provenance statements](https://docs.npmjs.com/generating-provenance-statements) (`false` by default). Requires npm 9.5.0+ and a supported CI environment (GitHub Actions or GitLab CI/CD).
112114

113115
For example, this configures `np` to use `unit-test` as a test script, and to use `dist` as the subdirectory to publish:
114116

source/cli-implementation.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ const cli = meow(`
4040
--no-2fa Don't enable 2FA on new packages (not recommended)
4141
--message Version bump commit message, '%s' will be replaced with version (default: '%s' with npm and 'v%s' with yarn)
4242
--package-manager Use a specific package manager (default: 'packageManager' field in package.json)
43+
--provenance Publish with npm provenance statements (CI-only)
4344
4445
Examples
4546
$ np
@@ -100,6 +101,9 @@ const cli = meow(`
100101
message: {
101102
type: 'string',
102103
},
104+
provenance: {
105+
type: 'boolean',
106+
},
103107
},
104108
});
105109

source/npm/publish.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ export const getPackagePublishArguments = options => {
1515
arguments_.push('--access', 'public');
1616
}
1717

18+
if (options.provenance) {
19+
arguments_.push('--provenance');
20+
}
21+
1822
return arguments_;
1923
};
2024

test/cli.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ test('flags: --help', cliPasses, cli, '--help', [
3232
'--no-2fa Don\'t enable 2FA on new packages (not recommended)',
3333
'--message Version bump commit message, \'%s\' will be replaced with version (default: \'%s\' with npm and \'v%s\' with yarn)',
3434
'--package-manager Use a specific package manager (default: \'packageManager\' field in package.json)',
35+
'--provenance Publish with npm provenance statements (CI-only)',
3536
'',
3637
'Examples',
3738
'$ np',

test/npm/publish.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ test('options.publishScoped', t => {
2929
);
3030
});
3131

32+
test('options.provenance', t => {
33+
t.deepEqual(
34+
getPackagePublishArguments({provenance: true}),
35+
['publish', '--provenance'],
36+
);
37+
});
38+
3239
test('runPublish uses cwd option when provided', async t => {
3340
const result = await runPublish(['echo', ['test']], {cwd: '/tmp'});
3441
t.is(result.cwd, '/tmp');

0 commit comments

Comments
 (0)