From c64268f62b7d556a17cf6943cdd3397b4bbacb84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Nison?= Date: Tue, 24 Oct 2023 14:45:05 +0200 Subject: [PATCH 1/2] Fixes the optional check depending on the order the tree is traversed --- .yarn/versions/0d12a741.yml | 34 ++++++++++++++ .../pkg-tests-specs/sources/dragon.test.js | 44 +++++++++++++++++++ packages/yarnpkg-core/sources/Project.ts | 6 +-- 3 files changed, 81 insertions(+), 3 deletions(-) create mode 100644 .yarn/versions/0d12a741.yml diff --git a/.yarn/versions/0d12a741.yml b/.yarn/versions/0d12a741.yml new file mode 100644 index 000000000000..2d6a48f178d8 --- /dev/null +++ b/.yarn/versions/0d12a741.yml @@ -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" diff --git a/packages/acceptance-tests/pkg-tests-specs/sources/dragon.test.js b/packages/acceptance-tests/pkg-tests-specs/sources/dragon.test.js index c749b8ce4a60..ff69cc3e0de6 100644 --- a/packages/acceptance-tests/pkg-tests-specs/sources/dragon.test.js +++ b/packages/acceptance-tests/pkg-tests-specs/sources/dragon.test.js @@ -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 pkg-c as + // being traversed, and skipping future traversals. If we're not being + // careful, it may cause the "not optional" flag to be skipped as well, + // making Yarn believe that pkg-c 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`); + }, + ), + ); }); diff --git a/packages/yarnpkg-core/sources/Project.ts b/packages/yarnpkg-core/sources/Project.ts index 96f8db94224b..c04836135f4d 100644 --- a/packages/yarnpkg-core/sources/Project.ts +++ b/packages/yarnpkg-core/sources/Project.ts @@ -2244,14 +2244,14 @@ function applyVirtualResolutionMutations({ }; const resolvePeerDependenciesImpl = (parentDescriptor: Descriptor, parentLocator: Locator, peerSlots: Map, {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`); From cedfbaf0ae8f8261dce2ba88d703e26a94c17e12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Nison?= Date: Tue, 24 Oct 2023 17:39:36 +0200 Subject: [PATCH 2/2] Update dragon.test.js --- .../pkg-tests-specs/sources/dragon.test.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/acceptance-tests/pkg-tests-specs/sources/dragon.test.js b/packages/acceptance-tests/pkg-tests-specs/sources/dragon.test.js index ff69cc3e0de6..beb74f281ef0 100644 --- a/packages/acceptance-tests/pkg-tests-specs/sources/dragon.test.js +++ b/packages/acceptance-tests/pkg-tests-specs/sources/dragon.test.js @@ -701,10 +701,10 @@ describe(`Dragon tests`, () => { // └── pkg-b/ // └── no-deps-failing (not optional) // - // Depending on the order of traversal, we may end up marking pkg-c as - // being traversed, and skipping future traversals. If we're not being - // careful, it may cause the "not optional" flag to be skipped as well, - // making Yarn believe that pkg-c is optional when it's not. + // 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`, {