Skip to content

Commit 0b5fc6d

Browse files
committed
feat: support all npm 3rd party flags
1 parent 2c0a3eb commit 0b5fc6d

File tree

6 files changed

+48
-7
lines changed

6 files changed

+48
-7
lines changed

.yarnrc.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ initScope: yarnpkg
1717

1818
npmPublishAccess: public
1919

20+
npmPublishProvenance: true
21+
2022
packageExtensions:
2123
"@codemirror/lang-html@*":
2224
dependencies:

packages/docusaurus/static/configuration/manifest.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,11 @@
362362
"format": "uri-reference",
363363
"examples": ["./build/index.mjs"]
364364
},
365+
"provenance": {
366+
"title": "Define whether to produce a provenance statement for the package when publishing. Overrides all other provenance settings.",
367+
"type": "boolean",
368+
"examples": [true]
369+
},
365370
"registry": {
366371
"description": "If present, will replace whatever registry is defined in the configuration when the package is about to be pushed to a remote location.",
367372
"type": "string",

packages/docusaurus/static/configuration/yarnrc.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -529,9 +529,16 @@
529529
"_package": "@yarnpkg/plugin-npm-cli",
530530
"type": "string",
531531
"title": "Define the default access to use when publishing packages to the npm registry.",
532-
"description": "Valid values are `public` and `restricted`, but `restricted` usually requires to register for a paid plan (this is up to the registry you use). Can be overridden on a per-package basis using the `publishConfig.access` field.",
532+
"description": "Valid values are `public` and `restricted`, but `restricted` usually requires to register for a paid plan (this is up to the registry you use). Can be overridden on a per-package basis using the [`publishConfig.access`](manifest#publishConfig.access) field.",
533533
"enum": ["public", "restricted"]
534534
},
535+
"npmPublishProvenance": {
536+
"_package": "@yarnpkg/plugin-npm-cli",
537+
"title": "Define whether to attach a provenance statement when publishing packages to the npm registry.",
538+
"description": "If true, Yarn will generate and publish the provenance information when publishing packages. Can be overridden on a per-package basis using the [`publishConfig.provenance`](manifest#publishConfig.provenance) field.",
539+
"type": "boolean",
540+
"default": false
541+
},
535542
"npmAuditExcludePackages": {
536543
"_package": "@yarnpkg/plugin-npm-cli",
537544
"title": "Array of package name glob patterns to exclude from `yarn npm audit`.",

packages/plugin-npm-cli/sources/commands/npm/publish.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export default class NpmPublishCommand extends BaseCommand {
4343
});
4444

4545
provenance = Option.Boolean(`--provenance`, false, {
46-
description: `Generate provenance for the package. Only available in GitHub Actions and GitLab CI.`,
46+
description: `Generate provenance for the package. Only available in GitHub Actions and GitLab CI. Can be set globally through the \`npmPublishProvenance\` setting or the \`NPM_CONFIG_PROVENANCE\` environment variable, or per-package through the \`publishConfig.provenance\` field in package.json.`,
4747
});
4848

4949
async execute() {
@@ -106,12 +106,32 @@ export default class NpmPublishCommand extends BaseCommand {
106106
const buffer = await miscUtils.bufferStream(pack);
107107

108108
const gitHead = await npmPublishUtils.getGitHead(workspace.cwd);
109+
110+
let provenance = false;
111+
if (workspace.manifest.publishConfig && `provenance` in workspace.manifest.publishConfig) {
112+
provenance = Boolean(workspace.manifest.publishConfig.provenance);
113+
if (provenance) {
114+
report.reportInfo(null, `Generating provenance statement because \`publishConfig.provenance\` field is set.`);
115+
} else {
116+
report.reportInfo(null, `Skipping provenance statement because \`publishConfig.provenance\` field is set to false.`);
117+
}
118+
} else if (this.provenance) {
119+
provenance = true;
120+
report.reportInfo(null, `Generating provenance statement because \`--provenance\` flag is set.`);
121+
} else if (process.env.NPM_CONFIG_PROVENANCE) {
122+
provenance = true;
123+
report.reportInfo(null, `Generating provenance statement because \`NPM_CONFIG_PROVENANCE\` env var is set.`);
124+
} else if (configuration.get(`npmPublishProvenance`)) {
125+
provenance = true;
126+
report.reportInfo(null, `Generating provenance statement because \`npmPublishProvenance\` setting is set.`);
127+
}
128+
109129
const body = await npmPublishUtils.makePublishBody(workspace, buffer, {
110130
access: this.access,
111131
tag: this.tag,
112132
registry,
113133
gitHead,
114-
provenance: this.provenance,
134+
provenance,
115135
});
116136

117137
await npmHttpUtils.put(npmHttpUtils.getIdentUrl(ident), body, {

packages/plugin-npm-cli/sources/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export {NpmWhoamiCommand};
2727
declare module '@yarnpkg/core' {
2828
interface ConfigurationValueMap {
2929
npmPublishAccess: string | null;
30+
npmPublishProvenance: boolean;
3031
npmAuditExcludePackages: Array<string>;
3132
npmAuditIgnoreAdvisories: Array<string>;
3233
}
@@ -39,6 +40,11 @@ const plugin: Plugin = {
3940
type: SettingsType.STRING,
4041
default: null,
4142
},
43+
npmPublishProvenance: {
44+
description: `Whether to generate provenance for the published packages`,
45+
type: SettingsType.BOOLEAN,
46+
default: false,
47+
},
4248
npmAuditExcludePackages: {
4349
description: `Array of glob patterns of packages to exclude from npm audit`,
4450
type: SettingsType.STRING,

packages/yarnpkg-core/sources/Manifest.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,14 @@ export interface PeerDependencyMeta {
2828

2929
export interface PublishConfig {
3030
access?: string;
31+
bin?: Map<string, PortablePath>;
32+
browser?: PortablePath | Map<PortablePath, boolean | PortablePath>;
33+
executableFiles?: Set<PortablePath>;
3134
main?: PortablePath;
3235
module?: PortablePath;
33-
type?: string;
34-
browser?: PortablePath | Map<PortablePath, boolean | PortablePath>;
35-
bin?: Map<string, PortablePath>;
36+
provenance?: boolean;
3637
registry?: string;
37-
executableFiles?: Set<PortablePath>;
38+
type?: string;
3839
}
3940

4041
export interface InstallConfig {

0 commit comments

Comments
 (0)