Skip to content

Commit bc95336

Browse files
smorimotoarcanis
andauthored
fix(core): fix the value check for publishConfig.provenance (#6781)
## What's the problem this PR addresses? This PR resolves an issue where the `publishConfig.provenance` field in `package.json` wasn't being read correctly. Specifically: - When `publishConfig.provenance: true` was set in `package.json`, Yarn's `npm publish` command wouldn't generate provenance statements - Whilst the `PublishConfig` interface had `provenance?: boolean` defined, the `load` method in `Manifest.ts` was missing the processing logic for the `provenance` field when handling `publishConfig` - Other fields (`access`, `main`, `module`, `browser`, `registry`, `bin`, `executableFiles`) were being processed correctly, but `provenance` was the only one being omitted ## How did you fix it? I added the following code to the `publishConfig` processing section within the `load` method in `packages/yarnpkg-core/sources/Manifest.ts`: ```typescript if (typeof data.publishConfig.provenance === `boolean`) this.publishConfig.provenance = data.publishConfig.provenance; ``` This fix ensures: 1. The `publishConfig.provenance` field in `package.json` is read correctly when it's a boolean value 2. It becomes available as `workspace.manifest.publishConfig.provenance` 3. The existing logic in `npm publish` command (`publish.ts` lines 109-120) functions properly Additionally, to ensure the accuracy of the fix, I added test cases to `packages/yarnpkg-core/tests/Manifest.test.ts`: - Test for when `provenance: true` is set - Test for when `provenance: false` is set - Test to verify that non-boolean values are ignored With this fix, when `publishConfig.provenance` is configured in `package.json`, provenance statements will be generated as expected. ## Checklist - [x] I have read the [Contributing Guide](https://yarnpkg.com/advanced/contributing). - [x] I have set the packages that need to be released for my changes to be effective. - [x] I will check that all automated PR checks pass before the PR gets reviewed. --------- Signed-off-by: Sora Morimoto <sora@morimoto.io> Co-authored-by: Maël Nison <nison.mael@gmail.com>
1 parent 73f0354 commit bc95336

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed

.yarn/versions/d2747135.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
releases:
2+
"@yarnpkg/cli": patch
3+
"@yarnpkg/core": patch
4+
5+
declined:
6+
- "@yarnpkg/plugin-compat"
7+
- "@yarnpkg/plugin-constraints"
8+
- "@yarnpkg/plugin-dlx"
9+
- "@yarnpkg/plugin-essentials"
10+
- "@yarnpkg/plugin-exec"
11+
- "@yarnpkg/plugin-file"
12+
- "@yarnpkg/plugin-git"
13+
- "@yarnpkg/plugin-github"
14+
- "@yarnpkg/plugin-http"
15+
- "@yarnpkg/plugin-init"
16+
- "@yarnpkg/plugin-interactive-tools"
17+
- "@yarnpkg/plugin-jsr"
18+
- "@yarnpkg/plugin-link"
19+
- "@yarnpkg/plugin-nm"
20+
- "@yarnpkg/plugin-npm"
21+
- "@yarnpkg/plugin-npm-cli"
22+
- "@yarnpkg/plugin-pack"
23+
- "@yarnpkg/plugin-patch"
24+
- "@yarnpkg/plugin-pnp"
25+
- "@yarnpkg/plugin-pnpm"
26+
- "@yarnpkg/plugin-stage"
27+
- "@yarnpkg/plugin-typescript"
28+
- "@yarnpkg/plugin-version"
29+
- "@yarnpkg/plugin-workspace-tools"
30+
- "@yarnpkg/builder"
31+
- "@yarnpkg/doctor"
32+
- "@yarnpkg/extensions"
33+
- "@yarnpkg/nm"
34+
- "@yarnpkg/pnpify"
35+
- "@yarnpkg/sdks"

packages/yarnpkg-core/sources/Manifest.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,9 @@ export class Manifest {
523523
if (typeof data.publishConfig.registry === `string`)
524524
this.publishConfig.registry = data.publishConfig.registry;
525525

526+
if (typeof data.publishConfig.provenance === `boolean`)
527+
this.publishConfig.provenance = data.publishConfig.provenance;
528+
526529
if (typeof data.publishConfig.bin === `string`) {
527530
if (this.name !== null) {
528531
this.publishConfig.bin = new Map([[this.name.name, normalizeSlashes(data.publishConfig.bin)]]);

packages/yarnpkg-core/tests/Manifest.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,21 @@ describe(`Manifest`, () => {
5555
expect(manifest.exportTo({}).bin).toEqual({bin2: `./bin2.js`});
5656
});
5757
});
58+
59+
describe(`publishConfig`, () => {
60+
it(`should parse provenance field when set to true`, () => {
61+
const manifest = Manifest.fromText(`{ "publishConfig": { "provenance": true } }`);
62+
expect(manifest.publishConfig?.provenance).toBe(true);
63+
});
64+
65+
it(`should parse provenance field when set to false`, () => {
66+
const manifest = Manifest.fromText(`{ "publishConfig": { "provenance": false } }`);
67+
expect(manifest.publishConfig?.provenance).toBe(false);
68+
});
69+
70+
it(`should ignore non-boolean provenance values`, () => {
71+
const manifest = Manifest.fromText(`{ "publishConfig": { "provenance": "true" } }`);
72+
expect(manifest.publishConfig?.provenance).toBeUndefined();
73+
});
74+
});
5875
});

0 commit comments

Comments
 (0)