Skip to content
This repository has been archived by the owner on May 20, 2021. It is now read-only.

Support for Yarn workspaces #58

Merged
merged 10 commits into from
Jun 17, 2018
Merged

Conversation

nightkr
Copy link
Contributor

@nightkr nightkr commented Jun 15, 2018

This adds a new argument workspaceDependencies to mkYarnPackage, the contents of which are added to a Yarn Workspace before yarn install. Example:

  rec {
    package-one = yarn2nix.mkYarnPackage {
      src = ./workspace/package-one;
      yarnLock = ./workspace/yarn.lock;
      workspaceDependencies = { inherit package-two; };
    };
    package-two = yarn2nix.mkYarnPackage {
      src = ./workspace/package-two;
      yarnLock = ./workspace/yarn.lock;
    };
  }.package-one

Notes:

  • Workspace dependencies must be manually added to workspaceDependencies
    • However, transitive dependencies are supported (for a relationship a -> b -> c, a does not need to explicitly depend on c)
  • Local dependency build steps are not supported
    • This is because local dependencies are removed at the end of mkYarnModules and added back in mkYarnPackage, to avoid re-running yarn after source-only changes

This (sort of) fixes #57.

Copy link
Member

@zimbatm zimbatm left a comment

Choose a reason for hiding this comment

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

Sounds good. It adds a lot of complexity but it seems like it's unavoidable. Thanks for doing all the research and implementing a solution for the workspaces scenario.

default.nix Outdated
@@ -45,12 +45,14 @@ in rec {

mkYarnModules = {
name,
pname,
Copy link
Member

Choose a reason for hiding this comment

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

in that case let's remove the name argument and also pass the version along the pname

default.nix Outdated
phases = ["configurePhase" "buildPhase"];
buildInputs = [ yarn nodejs ] ++ extraBuildInputs;
passAsFile = [ "workspaceJSON" ];
Copy link
Member

Choose a reason for hiding this comment

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

This is an obscure feature of nix. Do you mind using pkgs.writeText to create a derivation out of workspaceJSON and pass this instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure.

default.nix Outdated
cp ${yarnLock} ./yarn.lock
chmod +w ./yarn.lock
chmod +w ./yarn.lock # ./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.

leftover comment

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Whoops, fixing.

@nightkr
Copy link
Contributor Author

nightkr commented Jun 16, 2018

Done @zimbatm

@zimbatm zimbatm merged commit 1000845 into nix-community:master Jun 17, 2018
@zimbatm
Copy link
Member

zimbatm commented Jun 17, 2018

thanks!

nightkr added a commit to nightkr/yarn2nix that referenced this pull request Jun 26, 2018
See nix-community#57 for the initial ticket. nix-community#58 adds the basic plumbing, but requires you to
manually define the workspace. This will automatically import the "master"
`package.json` and find all subpackages.
@qknight qknight mentioned this pull request Aug 28, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

yarn workspaces
2 participants