Skip to content
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

feat(plugin-nm): support configuring link mode #4981

Merged
merged 12 commits into from
Oct 25, 2022
Merged

feat(plugin-nm): support configuring link mode #4981

merged 12 commits into from
Oct 25, 2022

Conversation

jeff-wishnie
Copy link
Contributor

@jeff-wishnie jeff-wishnie commented Oct 21, 2022

What's the problem this PR addresses?

Closes #4979

Currently on Windows yarn uses junctions to link workspaces into node_modules directories. On other platforms yarn uses symlinks.

As a result, workspace links in node_modules on Windows are always absolute paths. On other platforms links may be relative paths, leading to inconsistent behavior when using nodeLinker: node-modules and running yarn install from Windows vs. Linux.

A particularly bad side-effect of absolute paths on Windows is that it breaks Docker builds--when a monorepo is mounted into a container, the absolute paths are invalid.

The PR adds an additional configuration option for the nm-linker to use symbolic links on Windows as well, thereby supporting relative links, and fixing container builds.
...

How did you fix it?
added the option nmFolderLinkMode with two settiings:

  • classic (the default) -- nm-linker behaves exactly as today, using junctions on Windows and symlinks on other platforms.
  • symlinks -- nm-linker uses symlinks on all platforms

...

Checklist

  • I have set the packages that need to be released for my changes to be effective.
    [PLEASE CHECK MY WORK HERE!]
  • I will check that all automated PR checks pass before the PR gets reviewed.
    [A handful of unit and integration tests are failing when I run against master. This same set fails on my branch]

            Add `nmFolderLinkMode` to schema
modified:   packages/plugin-nm/sources/NodeModulesLinker.ts
            remove debug console.log
            version incremenets for plugin-nm and cli
modified:   packages/gatsby/static/configuration/yarnrc.json
modified:   packages/plugin-nm/sources/index.ts
@jeff-wishnie
Copy link
Contributor Author

There seems to be an issue with the E2E NM Babel Install pipeline. There hasn't been a passing run since Sept 18.

@RDIL RDIL requested a review from larixer October 21, 2022 19:59
@merceyz merceyz changed the title Implement nm folder link mode option feat(plugin-nm): support configuring link mode Oct 21, 2022
@merceyz
Copy link
Member

merceyz commented Oct 21, 2022

Indeed, they have some custom plugins that aren't compatible with Yarn v4 (master).

Copy link
Member

@merceyz merceyz left a comment

Choose a reason for hiding this comment

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

We also do this in the pnpm linker, should the same logic be applied there?

await xfs.symlinkPromise(depSrcPaths.packageLocation, depDstPath, `junction`);

@jeff-wishnie
Copy link
Contributor Author

We also do this in the pnpm linker, should the same logic be applied there?

await xfs.symlinkPromise(depSrcPaths.packageLocation, depDstPath, `junction`);

That probably would make sense, but I'm not familiar with pnpm (never used it) so wouldn't want to make that call.

If the pnpm folks like it's the right thing to do, would it make sense to have a single configuration setting that applies to both nm-linker and pnpm-linker or separate flags? It seems like the convention is for plugins to have their own config extensions (e.g. the configs prefixes with nm or npm) and that it could get messy if plugins tried to share config settings that are not defined in core.

It looks like you are one of the maintainers of pnpm-plugin, what would you like to do?

I'm happy to make a similar PR for that plugin.

@jeff-wishnie jeff-wishnie requested review from merceyz and removed request for larixer October 21, 2022 21:49
@merceyz merceyz requested a review from larixer October 21, 2022 21:58
@larixer
Copy link
Member

larixer commented Oct 22, 2022

The integration test for this feature is missing, we typically have integration tests for all the features in Yarn, that make sure they will not become broken in the future. Please add a test. The nm linker integration tests should be added here:
https://github.com/yarnpkg/berry/blob/master/packages/acceptance-tests/pkg-tests-specs/sources/node-modules.test.ts

@jeff-wishnie jeff-wishnie requested review from larixer and removed request for merceyz and larixer October 23, 2022 23:22
@jeff-wishnie jeff-wishnie requested review from merceyz and larixer and removed request for merceyz and larixer October 23, 2022 23:22
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.

Looks good to me, thank you!

@jeff-wishnie
Copy link
Contributor Author

@larixer @merceyz , thank you for the reviews.

@merceyz I think merge is blocked by the change you requested that I made via a push rather than the GitHub UI. I don't see how to clear the change-request, is that something you can do?

@jeff-wishnie jeff-wishnie requested a review from merceyz October 24, 2022 14:59
@RDIL RDIL dismissed merceyz’s stale review October 24, 2022 15:59

Feedback addressed

@jeff-wishnie
Copy link
Contributor Author

I think this is ready for merge.

@merceyz would you like me to propose a similar PR for the pnpm linker?

Copy link
Member

@merceyz merceyz left a comment

Choose a reason for hiding this comment

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

[...], what would you like to do?
would you like me to propose a similar PR for the pnpm linker?

I was thinking there should be a single setting controlling all symlink/junction creation in Yarn instead of one for each individual case, however I wont block this PR on that.

@jeff-wishnie
Copy link
Contributor Author

I was thinking there should be a single setting controlling all symlink/junction creation in Yarn

I'd be happy to work on that as a follow-up PR:

  • replace current nm-linker specific config with a global setting
  • update the pnpm linker to respect that setting as well.

I don't see junctions used elsewhere in the code base, but wonder if there are any contrib plugins that do that would want to update as well?

@larixer larixer merged commit d74c1f2 into yarnpkg:master Oct 25, 2022
@larixer
Copy link
Member

larixer commented Oct 25, 2022

@jeff-wishnie Sounds good. I'm not aware about any contrib plugins. I think the pnpm linker is the only other place where junctions are used. We would be grateful if you submit a follow-up PR for pnpm linker.

@jeff-wishnie jeff-wishnie deleted the implement-nmFolderLinkMode-option branch October 25, 2022 15:31
@jeff-wishnie
Copy link
Contributor Author

Will! As noted above, I've never worked with pnpm, this seems a pretty mechanical change so I'm not concerned but definitely looking for another solid review of that one!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants