diff --git a/doc/languages-frameworks/javascript.section.md b/doc/languages-frameworks/javascript.section.md index e68a29b0b3fd..9acfd4181108 100644 --- a/doc/languages-frameworks/javascript.section.md +++ b/doc/languages-frameworks/javascript.section.md @@ -428,7 +428,26 @@ NOTE: It is highly recommended to use a pinned version of pnpm (i.e. `pnpm_8` or In case you are patching `package.json` or `pnpm-lock.yaml`, make sure to pass `finalAttrs.patches` to the function as well (i.e. `inherit (finalAttrs) patches`. -`pnpm.configHook` supports adding additional `pnpm install` flags via `pnpmInstallFlags` which can be set to a Nix string array. +`pnpm.configHook` supports adding additional `pnpm install` flags via `pnpmInstallFlags` which can be set to a Nix string array: + +```nix +{ + pnpm, +}: + +stdenv.mkDerivation (finalAttrs: { + pname = "foo"; + version = "0-unstable-1980-01-01"; + + src = ...; + + pnpmInstallFlags = [ "--shamefully-hoist" ]; + + pnpmDeps = pnpm.fetchDeps { + inherit (finalAttrs) pnpmInstallFlags; + }; +}) +``` #### Dealing with `sourceRoot` {#javascript-pnpm-sourceRoot} @@ -459,16 +478,16 @@ Assuming the following directory structure, we can define `sourceRoot` and `pnpm #### PNPM Workspaces {#javascript-pnpm-workspaces} -If you need to use a PNPM workspace for your project, then set `pnpmWorkspace = ""` in your `pnpm.fetchDeps` call, -which will make PNPM only install dependencies for that workspace package. +If you need to use a PNPM workspace for your project, then set `pnpmWorkspaces = [ "" "" ]`, etc, in your `pnpm.fetchDeps` call, +which will make PNPM only install dependencies for those workspace packages. For example: ```nix ... -pnpmWorkspace = "@astrojs/language-server"; +pnpmWorkspaces = [ "@astrojs/language-server" ]; pnpmDeps = pnpm.fetchDeps { - inherit (finalAttrs) pnpmWorkspace; + inherit (finalAttrs) pnpmWorkspaces; ... } ``` @@ -476,7 +495,7 @@ pnpmDeps = pnpm.fetchDeps { The above would make `pnpm.fetchDeps` call only install dependencies for the `@astrojs/language-server` workspace package. Note that you do not need to set `sourceRoot` to make this work. -Usually in such cases, you'd want to use `pnpm --filter=$pnpmWorkspace build` to build your project, as `npmHooks.npmBuildHook` probably won't work. A `buildPhase` based on the following example will probably fit most workspace projects: +Usually in such cases, you'd want to use `pnpm --filter= build` to build your project, as `npmHooks.npmBuildHook` probably won't work. A `buildPhase` based on the following example will probably fit most workspace projects: ```nix buildPhase = '' diff --git a/pkgs/development/tools/pnpm/fetch-deps/default.nix b/pkgs/development/tools/pnpm/fetch-deps/default.nix index d89160064406..a8200fcad65a 100644 --- a/pkgs/development/tools/pnpm/fetch-deps/default.nix +++ b/pkgs/development/tools/pnpm/fetch-deps/default.nix @@ -15,7 +15,7 @@ { hash ? "", pname, - pnpmWorkspace ? "", + pnpmWorkspaces ? [ ], prePnpmInstall ? "", ... }@args: @@ -32,8 +32,14 @@ outputHash = ""; outputHashAlgo = "sha256"; }; - installFlags = lib.optionalString (pnpmWorkspace != "") "--filter=${pnpmWorkspace}"; + + filterFlags = lib.map (package: "--filter=${package}") pnpmWorkspaces; in + # pnpmWorkspace was deprecated, so throw if it's used. + assert (lib.throwIf (args ? pnpmWorkspace) + "pnpm.fetchDeps: `pnpmWorkspace` is no longer supported, please migrate to `pnpmWorkspaces`." + ) true; + stdenvNoCC.mkDerivation ( finalAttrs: ( @@ -74,6 +80,7 @@ --force \ --ignore-scripts \ ${installFlags} \ + ${lib.escapeShellArgs filterFlags} \ --frozen-lockfile runHook postInstall diff --git a/pkgs/development/tools/pnpm/fetch-deps/pnpm-config-hook.sh b/pkgs/development/tools/pnpm/fetch-deps/pnpm-config-hook.sh index e82a62f9101c..a47e3184e9cb 100644 --- a/pkgs/development/tools/pnpm/fetch-deps/pnpm-config-hook.sh +++ b/pkgs/development/tools/pnpm/fetch-deps/pnpm-config-hook.sh @@ -22,11 +22,19 @@ pnpmConfigHook() { pnpm config set store-dir "$STORE_PATH" - echo "Installing dependencies" - if [[ -n "$pnpmWorkspace" ]]; then - pnpmInstallFlags+=("--filter=$pnpmWorkspace") + echo "'pnpmWorkspace' is deprecated, please migrate to 'pnpmWorkspaces'." + exit 2 fi + + echo "Installing dependencies" + if [[ -n "$pnpmWorkspaces" ]]; then + local IFS=" " + for ws in $pnpmWorkspaces; do + pnpmInstallFlags+=("--filter=$ws") + done + fi + runHook prePnpmInstall pnpm install \