Skip to content

Fixes the optional check depending on the order the tree is traversed #5840

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 4 commits into from
Jan 22, 2024
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
34 changes: 34 additions & 0 deletions .yarn/versions/0d12a741.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
releases:
"@yarnpkg/cli": patch
"@yarnpkg/core": patch

declined:
- "@yarnpkg/plugin-compat"
- "@yarnpkg/plugin-constraints"
- "@yarnpkg/plugin-dlx"
- "@yarnpkg/plugin-essentials"
- "@yarnpkg/plugin-exec"
- "@yarnpkg/plugin-file"
- "@yarnpkg/plugin-git"
- "@yarnpkg/plugin-github"
- "@yarnpkg/plugin-http"
- "@yarnpkg/plugin-init"
- "@yarnpkg/plugin-interactive-tools"
- "@yarnpkg/plugin-link"
- "@yarnpkg/plugin-nm"
- "@yarnpkg/plugin-npm"
- "@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/doctor"
- "@yarnpkg/extensions"
- "@yarnpkg/nm"
- "@yarnpkg/pnpify"
- "@yarnpkg/sdks"
44 changes: 44 additions & 0 deletions packages/acceptance-tests/pkg-tests-specs/sources/dragon.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -682,4 +682,48 @@ describe(`Dragon tests`, () => {
},
),
);

test(
`it should pass the dragon test 13`,
makeTemporaryEnv(
{
workspaces: [
`pkg-a`,
`pkg-b`,
],
},
async ({path, run, source}) => {
// This dragon test represents the following scenario:
//
// .
// ├── pkg-a/
// │ └── no-deps-failing (optional)
// └── pkg-b/
// └── no-deps-failing (not optional)
//
// Depending on the order of traversal we may end up marking no-deps-failing
// as being traversed, and skip all future traversals. If we're not being
// careful this may cause setting the "not optional" flag to be skipped as
// well, making Yarn believe that no-deps-failing is optional when it's not.

await xfs.mkdirPromise(`${path}/pkg-a`);
await xfs.writeJsonPromise(`${path}/pkg-a/package.json`, {
name: `pkg-a`,
optionalDependencies: {
[`no-deps-failing`]: `1.0.0`,
},
});

await xfs.mkdirPromise(`${path}/pkg-b`);
await xfs.writeJsonPromise(`${path}/pkg-b/package.json`, {
name: `pkg-b`,
dependencies: {
[`no-deps-failing`]: `1.0.0`,
},
});

await expect(run(`install`)).rejects.toThrowError(`no-deps-failing@npm:1.0.0 couldn't be built successfully`);
},
),
);
});
6 changes: 3 additions & 3 deletions packages/yarnpkg-core/sources/Project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2235,14 +2235,14 @@ function applyVirtualResolutionMutations({
};

const resolvePeerDependenciesImpl = (parentDescriptor: Descriptor, parentLocator: Locator, peerSlots: Map<IdentHash, LocatorHash>, {top, optional}: {top: LocatorHash, optional: boolean}) => {
if (!optional)
optionalBuilds.delete(parentLocator.locatorHash);

if (accessibleLocators.has(parentLocator.locatorHash))
return;

accessibleLocators.add(parentLocator.locatorHash);

if (!optional)
optionalBuilds.delete(parentLocator.locatorHash);

const parentPackage = allPackages.get(parentLocator.locatorHash);
if (!parentPackage)
throw new Error(`Assertion failed: The package (${structUtils.prettyLocator(project.configuration, parentLocator)}) should have been registered`);
Expand Down