Skip to content

Conversation

joshhunt
Copy link
Contributor

@joshhunt joshhunt commented Jan 17, 2024

What's the problem this PR addresses?

Adds an integration test for #6058 to assert that link: dependencies are not mistreated as inner workspaces.

It took a bit of trial and error to get the right dependency tree that causes the issue, but eventually figured it out. It's roughly the same as https://github.com/joshhunt/yarn-repro-uuid-install-location, but with the existing fixtures.

...

How did you fix it?

It's just a test :)

I wrote the test against main to make sure it fails, and then check out the PR with the test and it passed :)

Test output against main and branch
~/d/g/yarn-berry (master)> git status
On branch master
Your branch is up to date with 'origin/master'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   packages/acceptance-tests/pkg-tests-specs/sources/node-modules.test.ts

no changes added to commit (use "git add" and/or "git commit -a")


~/d/g/yarn-berry (master)> yarn test:integration node-modules --verbose=false -t "should not treat link: dependencies as an inner workspaces"
 FAIL  packages/acceptance-tests/pkg-tests-specs/sources/node-modules.test.ts
  ● Node_Modules › should not treat link: dependencies as an inner workspaces

    Temporary fixture folder: /tmp/xfs-0e84f398/test

    expect(received).toBe(expected) // Object.is equality

    Expected: false
    Received: true

      169 |     ),
      170 |   );
    > 171 |
          | ^
      172 |   test(`should not treat link: dependencies as an inner workspaces`,
      173 |     makeTemporaryEnv(
      174 |       {

      at pkg-tests-specs/sources/node-modules.test.ts:171:101
      at Object.<anonymous> (pkg-tests-core/sources/utils/tests.ts:788:11)

Test Suites: 1 failed, 1 total
Tests:       1 failed, 57 skipped, 58 total
Snapshots:   0 total
Time:        1.685 s, estimated 28 s
Ran all test suites matching /node-modules/i with tests matching "should not treat link: dependencies as an inner workspaces".


~/d/g/yarn-berry (master)> git co larixer/nm-mistreatment-link-as-workspace-fix
branch 'larixer/nm-mistreatment-link-as-workspace-fix' set up to track 'origin/larixer/nm-mistreatment-link-as-workspace-fix'.
Switched to a new branch 'larixer/nm-mistreatment-link-as-workspace-fix'


~/d/g/yarn-berry (larixer/nm-mistreatment-link-as-workspace-fix)> yarn; yarn build:cli
...


~/d/g/yarn-berry (larixer/nm-mistreatment-link-as-workspace-fix)> yarn test:integration node-modules --verbose=false -t "should not treat link: dependencies as an inner workspaces"
 PASS  packages/acceptance-tests/pkg-tests-specs/sources/node-modules.test.ts

Test Suites: 1 passed, 1 total
Tests:       57 skipped, 1 passed, 58 total
Snapshots:   0 total
Time:        2.242 s
Ran all test suites matching /node-modules/i with tests matching "should not treat link: dependencies as an inner workspaces".

...

Checklist

  • I have set the packages that need to be released for my changes to be effective.
  • I will check that all automated PR checks pass before the PR gets reviewed.

{
private: true,
dependencies: {
[`one-fixed-dep`]: `2.0.0`,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I bet the line above is not needed. The test should be minimal

[`app`]: `link:./app`,
},
workspaces: [
`packages/*`,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The line above is not needed

nodeLinker: `node-modules`,
},
async ({path, run, source}) => {
await writeJson(npath.toPortablePath(`${path}/packages/workspace/package.json`), {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, this statement should be irrelevant to the test and can be removed

@larixer
Copy link
Member

larixer commented Jan 17, 2024

@joshhunt Many thanks! Please shrink down the test to a minimum, I made notices about the lines that can be safely removed in my opinion. Please correct me if I am wrong.

@joshhunt
Copy link
Contributor Author

joshhunt commented Jan 17, 2024

Thanks for the review @larixer! I've pushed up what I believe to be the most minimal reproduction of the issue that fails on master. Indeed the packages/workspace package was not required.

If I remove all the suggested lines, the issue doesn't reproduce on master:

test(`should not treat link: dependencies as an inner workspaces`,
  makeTemporaryEnv(
    {
      private: true,
      dependencies: {
        // [`one-fixed-dep`]: `2.0.0`,
        [`app`]: `link:./app`,
      },
      workspaces: [
        `app/plugins/*`,
      ],
    },
    {
      nodeLinker: `node-modules`,
    },
    async ({path, run, source}) => {
      console.log(`path`, path);

      await writeJson(npath.toPortablePath(`${path}/app/plugins/foo-plugin/package.json`), {
        name: `foo-plugin`,
        version: `1.0.0`,
        dependencies: {
          [`one-fixed-dep`]: `1.0.0`,
        },
      });

      await run(`install`);

      expect(await xfs.existsPromise(npath.toPortablePath(`${path}/app/node_modules`))).toBe(false);
    },
  ),
);
~/d/g/yarn-berry (master)> tree /tmp/xfs-6cf41900/test
/tmp/xfs-6cf41900/test
├── app
│   └── plugins
│       └── foo-plugin
│           └── package.json
├── node_modules
│   ├── app -> ../app
│   ├── foo-plugin -> ../app/plugins/foo-plugin
│   ├── no-deps
│   │   ├── index.js
│   │   ├── no-deps-1.0.0.js
│   │   └── package.json
│   └── one-fixed-dep
│       ├── index.js
│       └── package.json
├── package.json
└── yarn.lock

8 directories, 8 files

(I added the extra file to the no-deps package to quickly show what version it is)

I'm a bit out of my depth with all this package manager stuff, but I believe conflicting versions of a transitive depedency (no-deps) is required to reproduce the issue, as it's the hosting(?) logic that picks the link: as a candidate for node_modules.

Here's the problematic tree (from master)

 ~/d/g/yarn-berry (master)> tree /tmp/xfs-570c7b4d/test
/tmp/xfs-570c7b4d/test
├── app
│   ├── node_modules
│   │   └── no-deps
│   │       ├── index.js
│   │       ├── no-deps-1.0.0.js
│   │       └── package.json
│   └── plugins
│       └── foo-plugin
│           ├── node_modules
│           │   └── one-fixed-dep
│           │       ├── index.js
│           │       └── package.json
│           └── package.json
├── node_modules
│   ├── app -> ../app
│   ├── foo-plugin -> ../app/plugins/foo-plugin
│   ├── no-deps
│   │   ├── index.js
│   │   ├── no-deps-2.0.0.js
│   │   └── package.json
│   └── one-fixed-dep
│       ├── index.js
│       └── package.json
├── package.json
└── yarn.lock

12 directories, 13 files

Note that it's not the direct dependency one-fixed-dep that's incorrectly installed into app/node_modules, but the transitive [email protected].

Just for throughness, here's what the file tree should look like with your fix:

 ~/d/g/yarn-berry (joshhunt/nm-mistreatment-link-as-workspace-fix-test)> tree /tmp/xfs-484f3a71/test
/tmp/xfs-484f3a71/test
├── app
│   └── plugins
│       └── foo-plugin
│           ├── node_modules
│           │   ├── no-deps
│           │   │   ├── index.js
│           │   │   └── package.json
│           │   └── one-fixed-dep
│           │       ├── index.js
│           │       └── package.json
│           └── package.json
├── node_modules
│   ├── app -> ../app
│   ├── foo-plugin -> ../app/plugins/foo-plugin
│   ├── no-deps
│   │   ├── index.js
│   │   └── package.json
│   └── one-fixed-dep
│       ├── index.js
│       └── package.json
├── package.json
└── yarn.lock

11 directories, 11 files

@joshhunt joshhunt requested a review from larixer January 17, 2024 17:36
Copy link
Member

@larixer larixer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, yes, you are right the extra dependency at the workspace root is mandatory. Looks good!

@merceyz merceyz merged commit e8632d1 into yarnpkg:larixer/nm-mistreatment-link-as-workspace-fix Jan 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants