Skip to content

Stops reporting identical objects as being different #5934

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .yarn/versions/68e485e1.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
releases:
"@yarnpkg/cli": patch
"@yarnpkg/plugin-constraints": patch

declined:
- "@yarnpkg/plugin-compat"
- "@yarnpkg/plugin-dlx"
- "@yarnpkg/plugin-essentials"
- "@yarnpkg/plugin-init"
- "@yarnpkg/plugin-interactive-tools"
- "@yarnpkg/plugin-nm"
- "@yarnpkg/plugin-npm-cli"
- "@yarnpkg/plugin-pack"
- "@yarnpkg/plugin-patch"
- "@yarnpkg/plugin-pnp"
- "@yarnpkg/plugin-pnpm"
- "@yarnpkg/plugin-stage"
- "@yarnpkg/plugin-typescript"
- "@yarnpkg/plugin-version"
- "@yarnpkg/plugin-workspace-tools"
- "@yarnpkg/builder"
- "@yarnpkg/core"
- "@yarnpkg/doctor"
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,39 @@ describe(`Commands`, () => {
await expect(run(`constraints`)).rejects.toThrow(/This should fail/);
}));

it(`shouldn't report errors when comparing identical objects`, makeTemporaryEnv({
foo: {
ok: true,
},
}, async ({path, run, source}) => {
await run(`install`);

await writeFile(ppath.join(path, `yarn.config.cjs`), `
exports.constraints = ({Yarn}) => {
Yarn.workspace().set('foo', {ok: true});
};
`);

await run(`constraints`);
}));

it(`should report an error when comparing objects with different key ordering`, makeTemporaryEnv({
foo: {
b: true,
a: true,
},
}, async ({path, run, source}) => {
await run(`install`);

await writeFile(ppath.join(path, `yarn.config.cjs`), `
exports.constraints = ({Yarn}) => {
Yarn.workspace().set('foo', {a: true, b: true});
};
`);

await expect(run(`constraints`)).rejects.toThrow(`Invalid field foo; expected { a: true, b: true }, found { b: true, a: true }`);
}));

for (const [environmentDescription, environment] of Object.entries(environments)) {
for (const [scriptDescription, scripts] of Object.entries(constraints)) {
for (const [scriptType, script] of Object.entries(scripts)) {
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-constraints/sources/constraintUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ export function applyEngineReport(project: Project, {manifestUpdates, reportedEr
const [[newValue]] = newValues;

const currentValue = get(manifest, fieldPath);
if (currentValue === newValue)
if (JSON.stringify(currentValue) === JSON.stringify(newValue))
continue;

if (!fix) {
Expand Down