mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-11-22 15:03:28 +00:00
pnpm.fetchDeps: pnpmWorkspace -> pnpmWorkspaces
This commit is contained in:
parent
02ba5770a7
commit
09cec0f560
@ -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`.
|
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}
|
#### 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}
|
#### PNPM Workspaces {#javascript-pnpm-workspaces}
|
||||||
|
|
||||||
If you need to use a PNPM workspace for your project, then set `pnpmWorkspace = "<workspace project name>"` in your `pnpm.fetchDeps` call,
|
If you need to use a PNPM workspace for your project, then set `pnpmWorkspaces = [ "<workspace project name 1>" "<workspace project name 2>" ]`, etc, in your `pnpm.fetchDeps` call,
|
||||||
which will make PNPM only install dependencies for that workspace package.
|
which will make PNPM only install dependencies for those workspace packages.
|
||||||
|
|
||||||
For example:
|
For example:
|
||||||
|
|
||||||
```nix
|
```nix
|
||||||
...
|
...
|
||||||
pnpmWorkspace = "@astrojs/language-server";
|
pnpmWorkspaces = [ "@astrojs/language-server" ];
|
||||||
pnpmDeps = pnpm.fetchDeps {
|
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.
|
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.
|
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=<pnpm workspace name> 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
|
```nix
|
||||||
buildPhase = ''
|
buildPhase = ''
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
{
|
{
|
||||||
hash ? "",
|
hash ? "",
|
||||||
pname,
|
pname,
|
||||||
pnpmWorkspace ? "",
|
pnpmWorkspaces ? [ ],
|
||||||
prePnpmInstall ? "",
|
prePnpmInstall ? "",
|
||||||
...
|
...
|
||||||
}@args:
|
}@args:
|
||||||
@ -32,8 +32,14 @@
|
|||||||
outputHash = "";
|
outputHash = "";
|
||||||
outputHashAlgo = "sha256";
|
outputHashAlgo = "sha256";
|
||||||
};
|
};
|
||||||
installFlags = lib.optionalString (pnpmWorkspace != "") "--filter=${pnpmWorkspace}";
|
|
||||||
|
filterFlags = lib.map (package: "--filter=${package}") pnpmWorkspaces;
|
||||||
in
|
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 (
|
stdenvNoCC.mkDerivation (
|
||||||
finalAttrs:
|
finalAttrs:
|
||||||
(
|
(
|
||||||
@ -74,6 +80,7 @@
|
|||||||
--force \
|
--force \
|
||||||
--ignore-scripts \
|
--ignore-scripts \
|
||||||
${installFlags} \
|
${installFlags} \
|
||||||
|
${lib.escapeShellArgs filterFlags} \
|
||||||
--frozen-lockfile
|
--frozen-lockfile
|
||||||
|
|
||||||
runHook postInstall
|
runHook postInstall
|
||||||
|
@ -22,11 +22,19 @@ pnpmConfigHook() {
|
|||||||
|
|
||||||
pnpm config set store-dir "$STORE_PATH"
|
pnpm config set store-dir "$STORE_PATH"
|
||||||
|
|
||||||
echo "Installing dependencies"
|
|
||||||
|
|
||||||
if [[ -n "$pnpmWorkspace" ]]; then
|
if [[ -n "$pnpmWorkspace" ]]; then
|
||||||
pnpmInstallFlags+=("--filter=$pnpmWorkspace")
|
echo "'pnpmWorkspace' is deprecated, please migrate to 'pnpmWorkspaces'."
|
||||||
|
exit 2
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
echo "Installing dependencies"
|
||||||
|
if [[ -n "$pnpmWorkspaces" ]]; then
|
||||||
|
local IFS=" "
|
||||||
|
for ws in $pnpmWorkspaces; do
|
||||||
|
pnpmInstallFlags+=("--filter=$ws")
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
runHook prePnpmInstall
|
runHook prePnpmInstall
|
||||||
|
|
||||||
pnpm install \
|
pnpm install \
|
||||||
|
Loading…
Reference in New Issue
Block a user