diff --git a/pkgs/build-support/node/fetch-pnpm-deps/pnpm-config-hook.sh b/pkgs/build-support/node/fetch-pnpm-deps/pnpm-config-hook.sh index 5cafdd6d1d8b..38f6eb97b56b 100644 --- a/pkgs/build-support/node/fetch-pnpm-deps/pnpm-config-hook.sh +++ b/pkgs/build-support/node/fetch-pnpm-deps/pnpm-config-hook.sh @@ -71,12 +71,13 @@ pnpmConfigHook() { pnpm config set package-import-method clone-or-copy echo "Installing dependencies" - if [[ -n "$pnpmWorkspaces" ]]; then - local IFS=" " - for ws in $pnpmWorkspaces; do - pnpmInstallFlags+=("--filter=$ws") - done - fi + + local -a pnpmWorkspacesArray + concatTo pnpmWorkspacesArray pnpmWorkspaces + + for ws in "${pnpmWorkspacesArray[@]}"; do + pnpmInstallFlags+=("--filter=$ws") + done runHook prePnpmInstall diff --git a/pkgs/test/pnpm/default.nix b/pkgs/test/pnpm/default.nix index 14c62ea820d3..27938a8a0405 100644 --- a/pkgs/test/pnpm/default.nix +++ b/pkgs/test/pnpm/default.nix @@ -1,7 +1,8 @@ -{ callPackage }: +{ callPackage, lib }: { pnpm-empty-lockfile = callPackage ./pnpm-empty-lockfile { }; pnpm-fixup-state-db = callPackage ./pnpm-fixup-state-db { }; + pnpm-workspaces = lib.recurseIntoAttrs (callPackage ./pnpm-workspaces { }); pnpm_11_v3 = callPackage ./pnpm_11_v3 { }; pnpm_11_v4 = callPackage ./pnpm_11_v4 { }; } diff --git a/pkgs/test/pnpm/pnpm-workspaces/default.nix b/pkgs/test/pnpm/pnpm-workspaces/default.nix new file mode 100644 index 000000000000..d856d03f6796 --- /dev/null +++ b/pkgs/test/pnpm/pnpm-workspaces/default.nix @@ -0,0 +1,57 @@ +{ + stdenv, + fetchPnpmDeps, + pnpm, + pnpmConfigHook, + testers, +}: +let + mkTest = + { structuredAttrs }: + stdenv.mkDerivation (finalAttrs: { + name = "pnpm-workspaces-${if structuredAttrs then "structured" else "legacy"}"; + + src = ./src; + + pnpmDeps = testers.invalidateFetcherByDrvHash fetchPnpmDeps { + pname = "pnpm-workspaces"; + inherit (finalAttrs) src pnpmWorkspaces; + inherit pnpm; + fetcherVersion = 4; + hash = "sha256-dIp6CNh1Kn4aqJWku1G/FUdn/u+epzhqlqwnAkB2uW0="; + }; + + pnpmWorkspaces = [ + "@pnpm-workspaces-test/a" + "@pnpm-workspaces-test/b" + ]; + + __structuredAttrs = structuredAttrs; + + nativeBuildInputs = [ + pnpm + pnpmConfigHook + ]; + + buildPhase = '' + runHook preBuild + + for package in a b; do + if [ -e "packages/$package/node_modules/@pnpm-workspaces-test/$package-dep" ]; then + echo "$package was installed (its dependency $package-dep is linked)" + else + echo "ERROR: $package was not installed" + exit 1 + fi + done + + touch $out + + runHook postBuild + ''; + }); +in +{ + legacy = mkTest { structuredAttrs = false; }; + structured = mkTest { structuredAttrs = true; }; +} diff --git a/pkgs/test/pnpm/pnpm-workspaces/src/package.json b/pkgs/test/pnpm/pnpm-workspaces/src/package.json new file mode 100644 index 000000000000..05343efc28e7 --- /dev/null +++ b/pkgs/test/pnpm/pnpm-workspaces/src/package.json @@ -0,0 +1,5 @@ +{ + "name": "pnpm-workspaces-test", + "version": "0.0.0", + "private": true +} diff --git a/pkgs/test/pnpm/pnpm-workspaces/src/packages/a-dep/package.json b/pkgs/test/pnpm/pnpm-workspaces/src/packages/a-dep/package.json new file mode 100644 index 000000000000..ce526ded8c2f --- /dev/null +++ b/pkgs/test/pnpm/pnpm-workspaces/src/packages/a-dep/package.json @@ -0,0 +1,4 @@ +{ + "name": "@pnpm-workspaces-test/a-dep", + "version": "0.0.0" +} diff --git a/pkgs/test/pnpm/pnpm-workspaces/src/packages/a/package.json b/pkgs/test/pnpm/pnpm-workspaces/src/packages/a/package.json new file mode 100644 index 000000000000..680b1bf88179 --- /dev/null +++ b/pkgs/test/pnpm/pnpm-workspaces/src/packages/a/package.json @@ -0,0 +1,7 @@ +{ + "name": "@pnpm-workspaces-test/a", + "version": "0.0.0", + "dependencies": { + "@pnpm-workspaces-test/a-dep": "workspace:*" + } +} diff --git a/pkgs/test/pnpm/pnpm-workspaces/src/packages/b-dep/package.json b/pkgs/test/pnpm/pnpm-workspaces/src/packages/b-dep/package.json new file mode 100644 index 000000000000..16b1ce859578 --- /dev/null +++ b/pkgs/test/pnpm/pnpm-workspaces/src/packages/b-dep/package.json @@ -0,0 +1,4 @@ +{ + "name": "@pnpm-workspaces-test/b-dep", + "version": "0.0.0" +} diff --git a/pkgs/test/pnpm/pnpm-workspaces/src/packages/b/package.json b/pkgs/test/pnpm/pnpm-workspaces/src/packages/b/package.json new file mode 100644 index 000000000000..a1d6a578df37 --- /dev/null +++ b/pkgs/test/pnpm/pnpm-workspaces/src/packages/b/package.json @@ -0,0 +1,7 @@ +{ + "name": "@pnpm-workspaces-test/b", + "version": "0.0.0", + "dependencies": { + "@pnpm-workspaces-test/b-dep": "workspace:*" + } +} diff --git a/pkgs/test/pnpm/pnpm-workspaces/src/pnpm-lock.yaml b/pkgs/test/pnpm/pnpm-workspaces/src/pnpm-lock.yaml new file mode 100644 index 000000000000..c584ae73ee0c --- /dev/null +++ b/pkgs/test/pnpm/pnpm-workspaces/src/pnpm-lock.yaml @@ -0,0 +1,25 @@ +lockfileVersion: '9.0' + +settings: + autoInstallPeers: true + excludeLinksFromLockfile: false + +importers: + + .: {} + + packages/a: + dependencies: + '@pnpm-workspaces-test/a-dep': + specifier: workspace:* + version: link:../a-dep + + packages/a-dep: {} + + packages/b: + dependencies: + '@pnpm-workspaces-test/b-dep': + specifier: workspace:* + version: link:../b-dep + + packages/b-dep: {} diff --git a/pkgs/test/pnpm/pnpm-workspaces/src/pnpm-workspace.yaml b/pkgs/test/pnpm/pnpm-workspaces/src/pnpm-workspace.yaml new file mode 100644 index 000000000000..18ec407efca7 --- /dev/null +++ b/pkgs/test/pnpm/pnpm-workspaces/src/pnpm-workspace.yaml @@ -0,0 +1,2 @@ +packages: + - 'packages/*'