Skip to content

pnpm.fetchDeps: Add workspace and custom pnpm config commands support - #323493

Merged
doronbehar merged 5 commits into
NixOS:masterfrom
pyrox0:pnpm-fetchdeps-improve
Aug 7, 2024
Merged

doronbehar merged 5 commits into
NixOS:masterfrom
pyrox0:pnpm-fetchdeps-improve

Conversation

@pyrox0

@pyrox0 pyrox0 commented Jun 30, 2024

Copy link
Copy Markdown
Member

Description of changes

Adds pnpmWorkspace and extraPnpmCommands options for pnpm.fetchDeps calls

These can be used to either use a specific pnpm workspace for installation, and to run custom pnpm config commands during dependency fetching. Some packages may need a setting such as dedupe-peer-dependents set to a non-default value, and so this allows them to set those when needed.

See the discussion in #309100 (starting at #309100 (comment)) as to why these are useful.

I've also updated the documentation appropriately.

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 24.11 Release Notes (or backporting 23.11 and 24.05 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

Add a 👍 reaction to pull requests you find important.

@github-actions github-actions Bot added 8.has: documentation This PR adds or changes documentation 6.topic: nodejs Node.js is a free, open-source, cross-platform JavaScript runtime environment labels Jun 30, 2024
@ofborg ofborg Bot added 10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. 10.rebuild-linux: 11-100 This PR causes between 11 and 100 packages to rebuild on Linux. labels Jun 30, 2024
@getchoo
getchoo self-requested a review July 2, 2024 15:46
@doronbehar
doronbehar force-pushed the pnpm-fetchdeps-improve branch from ada805a to b410759 Compare July 3, 2024 17:56
@doronbehar

Copy link
Copy Markdown
Contributor

On a 2nd thought, this PR is a good opportunity to test this new interface. I also had motivation to work on this feature for bash-language-server and to fix #316908 , so I pushed 2 more commits that will also close #309100 .

@ofborg ofborg Bot added the 8.has: package (new) This PR adds a new package label Jul 3, 2024
@ofborg
ofborg Bot requested a review from doronbehar July 3, 2024 19:40
@ofborg ofborg Bot added 10.rebuild-darwin: 11-100 This PR causes between 11 and 100 packages to rebuild on Darwin. and removed 10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. labels Jul 3, 2024

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

i think it would be much better to just use a built in phase here

i.e., if someone wants to set specific options or run arbitrary commands, they can just use postConfigure/postInstall/etc from mkDerivation rather than this (single) unique phase

this would require splitting up some of the internal phases here, namely when HOME, store-dir, and other defaults are applied - they should probably in the configurePhase

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

i think it would be much better to just use a built in phase here

i.e., if someone wants to set specific options or run arbitrary commands, they can just use postConfigure/postInstall/etc from mkDerivation rather than this (single) unique phase

this would require splitting up some of the internal phases here, namely when HOME, store-dir, and other defaults are applied - they should probably in the configurePhase

Hmm you have a point, but still though, even if I'd simply move the runHook preInstall line after HOME is set, which would allow to perform such an override, I'd have to do something like this:

stdenv.mkDerivation (finalAttrs: {
  # ...
  pnpmDeps = (pnpm_8.fetchDeps {
    inherit (finalAttrs) pname version src pnpmWorkspace;
    hash = "sha256-n7HTd/rKxJdQKnty5TeOcyvBU9j/EClQ9IHqbBaEwQE=";
  }).overrideAttrs(_: {
    preInstall = finalAttrs.prePnpmInstall;
  });

  prePnpmInstall = ''
    pnpm config set dedupe-peer-dependents false
  '';
  # ...
})

Seems much more ugly. Even if we'll just rename the argument to preInstall, such that the interface would look like this:

stdenv.mkDerivation (finalAttrs: {
  # ...
  pnpmDeps = pnpm_8.fetchDeps {
    inherit (finalAttrs) pname version src pnpmWorkspace;
    preInstall = finalAttrs.prePnpmInstall;
    hash = "sha256-n7HTd/rKxJdQKnty5TeOcyvBU9j/EClQ9IHqbBaEwQE=";
  };

  prePnpmInstall = ''
    pnpm config set dedupe-peer-dependents false
  '';
  # ...
})

It is still a bit weird IMO how these arguments are named differently, since they serve exactly the same purpose.

If you weren't thinking of either of these interfaces, I didn't fully understand you.

Comment on lines 34 to 36

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
extraPnpmInstallFlags =
if pnpmWorkspace != "" then "--filter=${pnpmWorkspace}"
else "";
installFlags = lib.optional (pnpmWorkspace != "") "--filter=${pnpmWorkspace}";

this would also be nice as similar to above, callers would be able to use standard mkDerivation variables rather than unique ones found here

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this would also be nice as similar to above, this would also be nice as similar to above, callers would be able to use standard mkDerivation variables rather than unique ones found here

I agree that installFlags is a better variable name (pushed this change), but I'm not sure how that helps someone override this variable with an interface similar to mkDerivation...

Comment on lines 66 to 65

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
# Run any additional pnpm configuration commands that users provide.
${prePnpmInstall}

see above. this wouldn't be required anymore

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Another option would be to runHook prePnpmInstall here.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why can't we detect pnpmWorkspace and set that automatically in the hook?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why can't we detect pnpmWorkspace and set that automatically in the hook?

See my comment regarding the pnpm.buildHook idea below.

Comment on lines 27 to 29

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If we set this already, why are we doing the buildPhases above by hand? I am confused

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If we set this already, why are we doing the buildPhases above by hand? I am confused

You are confused because (surprisingly) we don't have a pnpm.buildHook. If the project you try to package doesn't have a specific workspace you are interested in, using npmHooks.npmBuildHook probably will do the job. With a specific workspace you pretty much have to use pnpm --filter=.. build. Perhaps we should add pnpm.buildHook.

@dezren39

dezren39 commented Jul 6, 2024

Copy link
Copy Markdown
Contributor

@doronbehar would this be something we could use for wrangler in #322573 ? should we wait for this to possibly merge in and then update the pr with these new commands? the pr builds and works fine, but uses quite a bit of disk and needs a bit more testing.

@dezren39 dezren39 mentioned this pull request Jul 6, 2024
5 of 13 tasks
@doronbehar
doronbehar force-pushed the pnpm-fetchdeps-improve branch from b410759 to 036d922 Compare July 7, 2024 12:55
@ofborg
ofborg Bot requested a review from Luflosi July 7, 2024 13:41
@doronbehar
doronbehar force-pushed the pnpm-fetchdeps-improve branch from 036d922 to a21e1c5 Compare July 21, 2024 07:55
@thenbe

thenbe commented Aug 1, 2024

Copy link
Copy Markdown
Contributor

Just a heads up that pnpm had a bug where attempting to install deps using --filter wasn't behaving as expected in certain cases.

The issue was fixed in pnpm v9.5.0. nixos-unstable is currently on v9.4.0 (an update PR to v9.6.0 is pending).

@doronbehar doronbehar mentioned this pull request Aug 2, 2024
5 of 13 tasks
@doronbehar
doronbehar force-pushed the pnpm-fetchdeps-improve branch from a21e1c5 to 4334aaa Compare August 2, 2024 07:07
@doronbehar

Copy link
Copy Markdown
Contributor

Thanks @thenbe for notifying. Now (after #325837 is merged) this is rebased. I will merge this after CI is green.

@doronbehar
doronbehar force-pushed the pnpm-fetchdeps-improve branch 2 times, most recently from 9871fba to 5ed4fad Compare August 2, 2024 07:12
@doronbehar

Copy link
Copy Markdown
Contributor

There are a few unresolved review conversations above, so I let @SuperSandro2000 and @getchoo a chance to reply to them for a few days.

@doronbehar
doronbehar force-pushed the pnpm-fetchdeps-improve branch from 5ed4fad to 4fefd63 Compare August 2, 2024 08:25
@doronbehar

Copy link
Copy Markdown
Contributor

Thanks for the suggestions @gepbird! Both of them fixed.

@doronbehar
doronbehar force-pushed the pnpm-fetchdeps-improve branch from 4fefd63 to d128948 Compare August 5, 2024 15:37
@doronbehar

Copy link
Copy Markdown
Contributor

Thanks @niklaskorz for the review :) I fixed that in separate commits before the main commits of the PR. I will merge this when CI is green.

@Scrumplex
Scrumplex self-requested a review August 5, 2024 18:17
@doronbehar
doronbehar merged commit d6f7206 into NixOS:master Aug 7, 2024
@ck3d

ck3d commented Aug 10, 2024

Copy link
Copy Markdown
Contributor

This PR broke the package bash-language-server, which has been fixed with #333701.

@ck3d

ck3d commented Aug 10, 2024

Copy link
Copy Markdown
Contributor

The resulting dependencies for the packages bash-language-server and astro-language-server do not change if pnpmWorkspace is set. The hashes and the content of the dependencies is the same, regardless of the value of pnpmWorkspace.
I think this PR needs rework for the parameter pnpmWorkspace.

@doronbehar

Copy link
Copy Markdown
Contributor

The resulting dependencies for the packages bash-language-server and astro-language-server do not change if pnpmWorkspace is set. The hashes and the content of the dependencies is the same, regardless of the value of pnpmWorkspace. I think this PR needs rework for the parameter pnpmWorkspace.

Thanks for noticing that. I suspect that what me and @pyrox0 experienced back when we initially worked on this PR, was a related to this upstream pnpm issue. Perhaps indeed now the workspace support could be simplified. I'm pretty sure though, that for astro-language-server, using pnpm config set dedupe-peer-dependants false is required, and support for prePnpmInstall was added here as well.

Hence for now, I think we'll have to wait for more packages that use pnpm workspaces to aggregate in Nixpkgs, and we can revise this topic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

6.topic: nodejs Node.js is a free, open-source, cross-platform JavaScript runtime environment 8.has: documentation This PR adds or changes documentation 8.has: package (new) This PR adds a new package 10.rebuild-darwin: 11-100 This PR causes between 11 and 100 packages to rebuild on Darwin. 10.rebuild-linux: 11-100 This PR causes between 11 and 100 packages to rebuild on Linux.

Projects

None yet

Development

Successfully merging this pull request may close these issues.