Skip to content

Commit 7d318df

Browse files
committed
pnpm_11: init at 11.1.0
Signed-off-by: Sefa Eyeoglu <contact@scrumplex.net>
1 parent 83ace87 commit 7d318df

13 files changed

Lines changed: 176 additions & 57 deletions

File tree

doc/languages-frameworks/javascript.section.md

Lines changed: 11 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -305,19 +305,26 @@ This package puts the corepack wrappers for pnpm and yarn in your PATH, and they
305305

306306
### pnpm {#javascript-pnpm}
307307

308-
pnpm is available as the top-level package `pnpm`. Additionally, there are variants pinned to certain major versions, like `pnpm_8`, `pnpm_9` and `pnpm_10`, which support different sets of lock file versions.
308+
pnpm is available as the top-level package `pnpm`. Additionally, there are variants pinned to certain major versions, like `pnpm_8`, `pnpm_9`, `pnpm_10`, `pnpm_10_29_2` and `pnpm_11`, which support different sets of lock file versions.
309309

310310
When packaging an application that includes a `pnpm-lock.yaml`, you need to fetch the pnpm store for that project using a fixed-output-derivation. The function `fetchPnpmDeps` can create this pnpm store derivation. In conjunction, the setup hook `pnpmConfigHook` will prepare the build environment to install the pre-fetched dependencies store. Here is an example for a package that contains `package.json` and a `pnpm-lock.yaml` files using the fetcher and setup hook above:
311311

312312
```nix
313313
{
314314
fetchPnpmDeps,
315315
nodejs,
316-
pnpm,
316+
pnpm_11,
317317
pnpmConfigHook,
318318
stdenv,
319319
}:
320-
320+
let
321+
# It is recommended to pin pnpm to a major version, due to regular breaking changes in the store format
322+
# The latest major version is always available under `pkgs.pnpm`
323+
# Optionally override pnpm to use a custom nodejs version
324+
# Make sure that the same nodejs version is referenced in nativeBuildInputs
325+
# pnpm = pnpm_11.override { nodejs = nodejs_24; };
326+
pnpm = pnpm_11;
327+
in
321328
stdenv.mkDerivation (finalAttrs: {
322329
pname = "foo";
323330
version = "0-unstable-1980-01-01";
@@ -334,54 +341,13 @@ stdenv.mkDerivation (finalAttrs: {
334341
335342
pnpmDeps = fetchPnpmDeps {
336343
inherit (finalAttrs) pname version src;
344+
inherit pnpm;
337345
fetcherVersion = 3;
338346
hash = "...";
339347
};
340348
})
341349
```
342350

343-
It is highly recommended to use a pinned version of pnpm (i.e., `pnpm_9` or `pnpm_10`), to increase future reproducibility. It might also be required to use an older version if the package needs support for a certain lock file version. To do so, you can pass the `pnpm` argument to `fetchPnpmDeps` and override the `pnpm` arg in `pnpmConfigHook`. Here are the changes in the example above to use a pinned pnpm version:
344-
345-
<!-- TODO: Does splicing still work when overriding in nativeBuildInputs here? -->
346-
347-
```diff
348-
{
349-
fetchPnpmDeps,
350-
nodejs,
351-
- pnpm,
352-
+ pnpm_10,
353-
pnpmConfigHook,
354-
stdenv,
355-
}:
356-
+let
357-
+ # Optionally override pnpm to use a custom nodejs version
358-
+ # Make sure that the same nodejs version is referenced in nativeBuildInputs
359-
+ # pnpm = pnpm_10.override { nodejs = nodejs_20; };
360-
+in
361-
stdenv.mkDerivation (finalAttrs: {
362-
pname = "foo";
363-
version = "0-unstable-1980-01-01";
364-
365-
src = {
366-
#...
367-
};
368-
369-
nativeBuildInputs = [
370-
nodejs # in case scripts are run outside of a pnpm call
371-
pnpmConfigHook
372-
- pnpm # At least required by pnpmConfigHook, if not other (custom) phases
373-
+ pnpm_10 # At least required by pnpmConfigHook, if not other (custom) phases
374-
];
375-
376-
pnpmDeps = fetchPnpmDeps {
377-
inherit (finalAttrs) pname version src;
378-
+ pnpm = pnpm_10;
379-
fetcherVersion = 3;
380-
hash = "...";
381-
};
382-
})
383-
```
384-
385351
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`.
386352

387353
`pnpmConfigHook` supports adding additional `pnpm install` flags via `pnpmInstallFlags` which can be set to a Nix string array:

pkgs/build-support/node/fetch-pnpm-deps/serve.nix

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
pnpm,
44
pnpmDeps,
55
zstd,
6+
lib,
67
}:
78

89
writeShellApplication {
@@ -41,4 +42,8 @@ writeShellApplication {
4142
pnpm server start \
4243
--store-dir "$storePath"
4344
'';
45+
46+
meta = {
47+
broken = lib.versionAtLeast pnpm.version "11";
48+
};
4449
}

pkgs/development/tools/pnpm/default.nix

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ let
2525
version = "10.33.4";
2626
hash = "sha256-jnDdxmSbGLw9iVzzqQjAKR6kw4A5rYcixH4Bja8enPw=";
2727
};
28+
"11" = {
29+
version = "11.1.0";
30+
hash = "sha256-VzyCrTVuiwl+bKxIG3OB+d7tM6MYr38xGYSFjr4fl+8=";
31+
};
2832
};
2933

3034
callPnpm = variant: callPackage ./generic.nix { inherit (variant) version hash; };

pkgs/development/tools/pnpm/generic.nix

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
testers,
1111
buildPackages,
1212
bashNonInteractive,
13+
tests,
1314

1415
withNode ? true,
1516
version,
@@ -43,16 +44,21 @@ stdenvNoCC.mkDerivation (finalAttrs: {
4344
rm -r package/dist/reflink.*node package/dist/vendor
4445
'';
4546

46-
installPhase = ''
47-
runHook preInstall
47+
installPhase =
48+
let
49+
# Use ESM pnpm for versions > 11
50+
ext = if lib.versionOlder finalAttrs.version "11" then "cjs" else "mjs";
51+
in
52+
''
53+
runHook preInstall
4854
49-
install -d $out/{bin,libexec}
50-
cp -R . $out/libexec/pnpm
51-
ln -s $out/libexec/pnpm/bin/pnpm.cjs $out/bin/pnpm
52-
ln -s $out/libexec/pnpm/bin/pnpx.cjs $out/bin/pnpx
55+
install -d $out/{bin,libexec}
56+
cp -R . $out/libexec/pnpm
57+
ln -s $out/libexec/pnpm/bin/pnpm.${ext} $out/bin/pnpm
58+
ln -s $out/libexec/pnpm/bin/pnpx.${ext} $out/bin/pnpx
5359
54-
runHook postInstall
55-
'';
60+
runHook postInstall
61+
'';
5662

5763
postInstall =
5864
if lib.toInt (lib.versions.major version) < 9 then
@@ -105,9 +111,10 @@ stdenvNoCC.mkDerivation (finalAttrs: {
105111
);
106112
inherit nodejs majorVersion;
107113

108-
tests.version = lib.optionalAttrs withNode (
109-
testers.testVersion { package = finalAttrs.finalPackage; }
110-
);
114+
tests = {
115+
inherit (tests) pnpm;
116+
version = lib.optionalAttrs withNode (testers.testVersion { package = finalAttrs.finalPackage; });
117+
};
111118
updateScript = writeScript "pnpm-update-script" ''
112119
#!/usr/bin/env nix-shell
113120
#!nix-shell -i bash -p curl jq common-updater-scripts

pkgs/test/pnpm/default.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
{
33
pnpm-empty-lockfile = callPackage ./pnpm-empty-lockfile { };
44
pnpm-fixup-state-db = callPackage ./pnpm-fixup-state-db { };
5+
pnpm_11 = callPackage ./pnpm_11 { };
56
}
-4 KB
Binary file not shown.

pkgs/test/pnpm/pnpm_11/default.nix

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
{
2+
fetchPnpmDeps,
3+
lib,
4+
makeShellWrapper,
5+
nodejs,
6+
pnpmConfigHook,
7+
pnpm_11,
8+
stdenv,
9+
testers,
10+
}:
11+
let
12+
pnpm = pnpm_11;
13+
in
14+
stdenv.mkDerivation (finalAttrs: {
15+
pname = "pnpm-test";
16+
inherit (pnpm) version;
17+
18+
src = ./src;
19+
20+
pnpmDeps = testers.invalidateFetcherByDrvHash fetchPnpmDeps {
21+
inherit (finalAttrs) pname version src;
22+
inherit pnpm;
23+
fetcherVersion = 3;
24+
hash = "sha256-+Vrv5ZiVIARDZrR5/4OYRmaecQQZmcZFtMjK4qhXKb8=";
25+
};
26+
27+
nativeBuildInputs = [
28+
makeShellWrapper
29+
nodejs
30+
pnpm
31+
pnpmConfigHook
32+
];
33+
34+
buildPhase = ''
35+
runHook preBuild
36+
37+
pnpm build
38+
39+
runHook postBuild
40+
'';
41+
42+
installPhase = ''
43+
runHook preInstall
44+
45+
install -Dm644 -t $out/lib/pnpm-11-test dist/index.js
46+
47+
makeWrapper ${lib.getExe nodejs} $out/bin/pnpm11test \
48+
--add-flags "$out/lib/pnpm11test"
49+
50+
runHook postInstall
51+
'';
52+
53+
__structuredAttrs = true;
54+
55+
meta = {
56+
license = lib.licenses.mit;
57+
mainProgram = "pnpm11test";
58+
inherit (pnpm.meta) maintainers;
59+
};
60+
})
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
dist/
2+
node_modules/
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
console.log("Hello World");
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"name": "pnpm11test",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "dist/index.js",
6+
"scripts": {
7+
"build": "tsc",
8+
"start": "node dist/index.js"
9+
},
10+
"license": "MIT",
11+
"packageManager": "pnpm",
12+
"type": "module",
13+
"files": [
14+
"dist/"
15+
],
16+
"devDependencies": {
17+
"@types/node": "^25.5.0",
18+
"typescript": "^6.0.2"
19+
}
20+
}

0 commit comments

Comments
 (0)