@procedures/pnpm 0.60.0 → 0.61.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,42 @@
1
1
  # @procedures/pnpm
2
2
 
3
+ ## 0.61.0
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [8506442]
8
+ - Updated dependencies [f9a78f9]
9
+ - Updated dependencies [3eb4b59]
10
+ - @procedures/client@0.61.0
11
+ - @procedures/shell@0.61.0
12
+
13
+ ## 0.60.1
14
+
15
+ ### Patch Changes
16
+
17
+ - 6e6805f: `snapshot.create` reads the pnpm version from the `package.json` of the pnpm package. It starts no program, so its declared effects hold without `process`.
18
+
19
+ - The new function `installedPnpmVersion()` of `@procedures/pnpm` gives the version of the pnpm that `resolvePnpm()` finds. It starts no program.
20
+ - For a global shim of pnpm 12, it reads the target in `.pnpm-shim-v1-<name>-target`, or in the line `# cmd-shim-target=` of a shell shim.
21
+ - When it finds no `package.json` of a pnpm package, the snapshot records the version as `unknown`.
22
+ - `@procedures/snapshot` does not depend on `@procedures/shell`.
23
+ - Updated dependencies [beca782]
24
+ - Updated dependencies [d472a8b]
25
+ - Updated dependencies [6dbc47e]
26
+ - Updated dependencies [663465c]
27
+ - Updated dependencies [66585f5]
28
+ - Updated dependencies [511d820]
29
+ - Updated dependencies [02a7074]
30
+ - Updated dependencies [265f41c]
31
+ - Updated dependencies [a87cdda]
32
+ - Updated dependencies [94b5f88]
33
+ - Updated dependencies [ca23351]
34
+ - Updated dependencies [84e1b25]
35
+ - Updated dependencies [fe6cd23]
36
+ - Updated dependencies [e9b7551]
37
+ - @procedures/client@0.60.1
38
+ - @procedures/shell@0.60.1
39
+
3
40
  ## 0.60.0
4
41
 
5
42
  ### Patch Changes
package/dist/index.d.ts CHANGED
@@ -25,6 +25,6 @@
25
25
  export type { PnpmInstallInput, PnpmAddInput, PnpmRemoveInput, PnpmLinkInput, PnpmRunInput, PnpmCommandOutput, PnpmJsonOutput, PnpmExecInput, PnpmListInput, PnpmWhyInput, PnpmOutdatedInput, PnpmUpdateInput, PnpmPackInput, } from "./types.js";
26
26
  export { PnpmInstallInputSchema, PnpmAddInputSchema, PnpmRemoveInputSchema, PnpmLinkInputSchema, PnpmRunInputSchema, PnpmExecInputSchema, PnpmListInputSchema, PnpmWhyInputSchema, PnpmOutdatedInputSchema, PnpmUpdateInputSchema, PnpmPackInputSchema, } from "./types.js";
27
27
  export { pnpmInstall, pnpmAdd, pnpmRemove, pnpmLink, pnpmRun, pnpmExec, pnpmList, pnpmWhy, pnpmOutdated, pnpmUpdate, pnpmPack, } from "./procedures/pnpm/index.js";
28
- export { resolvePnpm } from "./procedures/pnpm/shared.js";
28
+ export { installedPnpmVersion, resolvePnpm } from "./procedures/pnpm/shared.js";
29
29
  export { registerPnpmProcedures } from "./module.js";
30
30
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAGH,YAAY,EACV,gBAAgB,EAChB,YAAY,EACZ,eAAe,EACf,aAAa,EACb,YAAY,EACZ,iBAAiB,EACjB,cAAc,EACd,aAAa,EACb,aAAa,EACb,YAAY,EACZ,iBAAiB,EACjB,eAAe,EACf,aAAa,GACd,MAAM,YAAY,CAAC;AAEpB,OAAO,EACL,sBAAsB,EACtB,kBAAkB,EAClB,qBAAqB,EACrB,mBAAmB,EACnB,kBAAkB,EAClB,mBAAmB,EACnB,mBAAmB,EACnB,kBAAkB,EAClB,uBAAuB,EACvB,qBAAqB,EACrB,mBAAmB,GACpB,MAAM,YAAY,CAAC;AAGpB,OAAO,EACL,WAAW,EACX,OAAO,EACP,UAAU,EACV,QAAQ,EACR,OAAO,EACP,QAAQ,EACR,QAAQ,EACR,OAAO,EACP,YAAY,EACZ,UAAU,EACV,QAAQ,GACT,MAAM,4BAA4B,CAAC;AAGpC,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAG1D,OAAO,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAGH,YAAY,EACV,gBAAgB,EAChB,YAAY,EACZ,eAAe,EACf,aAAa,EACb,YAAY,EACZ,iBAAiB,EACjB,cAAc,EACd,aAAa,EACb,aAAa,EACb,YAAY,EACZ,iBAAiB,EACjB,eAAe,EACf,aAAa,GACd,MAAM,YAAY,CAAC;AAEpB,OAAO,EACL,sBAAsB,EACtB,kBAAkB,EAClB,qBAAqB,EACrB,mBAAmB,EACnB,kBAAkB,EAClB,mBAAmB,EACnB,mBAAmB,EACnB,kBAAkB,EAClB,uBAAuB,EACvB,qBAAqB,EACrB,mBAAmB,GACpB,MAAM,YAAY,CAAC;AAGpB,OAAO,EACL,WAAW,EACX,OAAO,EACP,UAAU,EACV,QAAQ,EACR,OAAO,EACP,QAAQ,EACR,QAAQ,EACR,OAAO,EACP,YAAY,EACZ,UAAU,EACV,QAAQ,GACT,MAAM,4BAA4B,CAAC;AAGpC,OAAO,EAAE,oBAAoB,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAGhF,OAAO,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC"}
package/dist/index.js CHANGED
@@ -26,7 +26,7 @@ export { PnpmInstallInputSchema, PnpmAddInputSchema, PnpmRemoveInputSchema, Pnpm
26
26
  // Procedures
27
27
  export { pnpmInstall, pnpmAdd, pnpmRemove, pnpmLink, pnpmRun, pnpmExec, pnpmList, pnpmWhy, pnpmOutdated, pnpmUpdate, pnpmPack, } from "./procedures/pnpm/index.js";
28
28
  // How the procedures find pnpm (no shell): other packages that run pnpm use it too
29
- export { resolvePnpm } from "./procedures/pnpm/shared.js";
29
+ export { installedPnpmVersion, resolvePnpm } from "./procedures/pnpm/shared.js";
30
30
  // Registration
31
31
  export { registerPnpmProcedures } from "./module.js";
32
32
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAmBH,OAAO,EACL,sBAAsB,EACtB,kBAAkB,EAClB,qBAAqB,EACrB,mBAAmB,EACnB,kBAAkB,EAClB,mBAAmB,EACnB,mBAAmB,EACnB,kBAAkB,EAClB,uBAAuB,EACvB,qBAAqB,EACrB,mBAAmB,GACpB,MAAM,YAAY,CAAC;AAEpB,aAAa;AACb,OAAO,EACL,WAAW,EACX,OAAO,EACP,UAAU,EACV,QAAQ,EACR,OAAO,EACP,QAAQ,EACR,QAAQ,EACR,OAAO,EACP,YAAY,EACZ,UAAU,EACV,QAAQ,GACT,MAAM,4BAA4B,CAAC;AAEpC,mFAAmF;AACnF,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAE1D,eAAe;AACf,OAAO,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAmBH,OAAO,EACL,sBAAsB,EACtB,kBAAkB,EAClB,qBAAqB,EACrB,mBAAmB,EACnB,kBAAkB,EAClB,mBAAmB,EACnB,mBAAmB,EACnB,kBAAkB,EAClB,uBAAuB,EACvB,qBAAqB,EACrB,mBAAmB,GACpB,MAAM,YAAY,CAAC;AAEpB,aAAa;AACb,OAAO,EACL,WAAW,EACX,OAAO,EACP,UAAU,EACV,QAAQ,EACR,OAAO,EACP,QAAQ,EACR,QAAQ,EACR,OAAO,EACP,YAAY,EACZ,UAAU,EACV,QAAQ,GACT,MAAM,4BAA4B,CAAC;AAEpC,mFAAmF;AACnF,OAAO,EAAE,oBAAoB,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAEhF,eAAe;AACf,OAAO,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC"}
@@ -29,6 +29,16 @@ export declare function resolvePnpm(): {
29
29
  command: string;
30
30
  prefix: string[];
31
31
  };
32
+ /**
33
+ * This function gives the version of the pnpm that `resolvePnpm` finds. It reads the
34
+ * `package.json` of the pnpm package of the program, and it starts no program. For a global shim
35
+ * of pnpm 12, it reads the package of the target of the shim. It gives `undefined` when it finds no
36
+ * pnpm, or no `package.json` of a pnpm package.
37
+ *
38
+ * `pnpm --version` reads the configuration of the working folder. Its `packageManager` field can
39
+ * make pnpm download and start a different pnpm. Thus this function does not start pnpm.
40
+ */
41
+ export declare function installedPnpmVersion(): string | undefined;
32
42
  /** This function runs `pnpm <args>` and gives its result. It does not throw for a failed command. */
33
43
  export declare function runPnpm(args: string[], input: {
34
44
  cwd?: string | undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../../../src/procedures/pnpm/shared.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAIH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAE3D,OAAO,KAAK,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAExE,wGAAwG;AACxG,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAE3D;AAED,0EAA0E;AAC1E,MAAM,WAAW,aAAa;IAC5B,MAAM,CAAC,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC;IAC9B,SAAS,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;CACjC;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,aAAa,GAAG,MAAM,EAAE,CAI5D;AAED,2EAA2E;AAC3E,wBAAgB,WAAW,IAAI;IAAE,OAAO,EAAE,MAAM,CA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AE,CAenE;AA2DD;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,IAAI,MAAM,GAAG,SAAS,CAmBzD;AAKD,qGAAqG;AACrG,wBAAsB,OAAO,CAC3B,IAAI,EAAE,MAAM,EAAE,EACd,KAAK,EAAE;IAAE,GAAG,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,EACjE,GAAG,EAAE,gBAAgB,GACpB,OAAO,CAAC,iBAAiB,CAAC,CAE5B;AAQD;;;GAGG;AACH,wBAAsB,WAAW,CAC/B,IAAI,EAAE,MAAM,EAAE,EACd,KAAK,EAAE;IAAE,GAAG,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,EACjE,GAAG,EAAE,gBAAgB,GACpB,OAAO,CAAC,cAAc,CAAC,CAEzB"}
@@ -9,8 +9,8 @@
9
9
  * So the helper finds the real program: a `pnpm.exe` (the standalone pnpm), or the `pnpm.cjs`
10
10
  * script that the `.cmd` file starts, run with Node.
11
11
  */
12
- import { existsSync } from "node:fs";
13
- import { join } from "node:path";
12
+ import { existsSync, readFileSync, realpathSync, statSync } from "node:fs";
13
+ import { basename, dirname, isAbsolute, join, resolve } from "node:path";
14
14
  import { defineCliTool, execPathProgram, findInPath, nodeScript, parseJsonDocument } from "@procedures/shell/cli";
15
15
  /** A value that pnpm reads as an argument (a package, a script, a path): it must not start with "-". */
16
16
  export function pnpmArg(name, value) {
@@ -47,6 +47,97 @@ export function resolvePnpm() {
47
47
  const execPath = process.env["npm_execpath"];
48
48
  throw new Error(`pnpm was not found: install pnpm, or run this from a pnpm script (npm_execpath: ${execPath ?? "not set"})`);
49
49
  }
50
+ /** This function gives true when the npm package name is the name of a package that holds a pnpm program. */
51
+ function isPnpmPackage(name) {
52
+ return name === "pnpm" || (typeof name === "string" && name.startsWith("@pnpm/exe"));
53
+ }
54
+ /** This function gives the version in the `package.json` of the pnpm package that holds the program file, or undefined. */
55
+ function pnpmPackageVersion(file) {
56
+ let real;
57
+ try {
58
+ real = realpathSync(file);
59
+ }
60
+ catch {
61
+ return undefined;
62
+ }
63
+ // The executable of pnpm 12 is in the folder of its package, and pnpm.cjs is in the bin folder
64
+ for (const dir of [dirname(real), dirname(dirname(real))]) {
65
+ const manifest = join(dir, "package.json");
66
+ if (!existsSync(manifest))
67
+ continue;
68
+ try {
69
+ const data = JSON.parse(readFileSync(manifest, "utf8"));
70
+ if (isPnpmPackage(data.name) && typeof data.version === "string")
71
+ return data.version;
72
+ }
73
+ catch {
74
+ continue;
75
+ }
76
+ }
77
+ return undefined;
78
+ }
79
+ /** The largest shell shim that `shimTarget` reads, as in pnpm. */
80
+ const MAX_SHELL_SHIM_BYTES = 64 * 1024;
81
+ /**
82
+ * This function gives the target of a global shim of pnpm 12, or undefined for a file that is not
83
+ * a shim. A shim is a copy of the pnpm executable. The file `.pnpm-shim-v1-<name>-target` beside
84
+ * it holds the path of its target: UTF-16 on Windows, the raw bytes on other systems. An older
85
+ * shim is a shell script with the line `# cmd-shim-target=<path>`. A target `pkg:<package>` has no
86
+ * installed program.
87
+ */
88
+ function shimTarget(file) {
89
+ const dir = dirname(file);
90
+ const sidecar = join(dir, `.pnpm-shim-v1-${basename(file).replace(/\.exe$/i, "")}-target`);
91
+ let target;
92
+ try {
93
+ if (existsSync(sidecar)) {
94
+ const bytes = readFileSync(sidecar);
95
+ // A path of Linux or macOS has no NUL byte, and UTF-16 has one in each ASCII character
96
+ target = bytes.toString(bytes.includes(0) ? "utf16le" : "utf8");
97
+ }
98
+ else if (statSync(file).size <= MAX_SHELL_SHIM_BYTES) {
99
+ const marker = "# cmd-shim-target=";
100
+ const line = readFileSync(file, "utf8").split(/\r?\n/).findLast((text) => text.startsWith(marker));
101
+ target = line?.slice(marker.length);
102
+ }
103
+ }
104
+ catch {
105
+ return undefined;
106
+ }
107
+ return target === undefined || target === "" || target.startsWith("pkg:") ? undefined : resolve(dir, target);
108
+ }
109
+ /**
110
+ * This function gives the version of the pnpm that `resolvePnpm` finds. It reads the
111
+ * `package.json` of the pnpm package of the program, and it starts no program. For a global shim
112
+ * of pnpm 12, it reads the package of the target of the shim. It gives `undefined` when it finds no
113
+ * pnpm, or no `package.json` of a pnpm package.
114
+ *
115
+ * `pnpm --version` reads the configuration of the working folder. Its `packageManager` field can
116
+ * make pnpm download and start a different pnpm. Thus this function does not start pnpm.
117
+ */
118
+ export function installedPnpmVersion() {
119
+ let program;
120
+ try {
121
+ program = resolvePnpm();
122
+ }
123
+ catch {
124
+ return undefined;
125
+ }
126
+ // A script of pnpm runs with Node: the file of pnpm is the first argument
127
+ let file = program.prefix[0] ?? program.command;
128
+ if (!isAbsolute(file)) {
129
+ const name = file;
130
+ const found = findInPath((dir) => (existsSync(join(dir, name)) ? { command: join(dir, name), prefix: [] } : undefined));
131
+ if (found === undefined)
132
+ return undefined;
133
+ file = found.command;
134
+ }
135
+ const version = pnpmPackageVersion(file);
136
+ if (version !== undefined)
137
+ return version;
138
+ const target = shimTarget(file);
139
+ return target === undefined ? undefined : pnpmPackageVersion(target);
140
+ }
50
141
  /** The runner of pnpm. It finds pnpm at each command. */
51
142
  const pnpm = defineCliTool({ name: "pnpm", resolve: resolvePnpm });
52
143
  /** This function runs `pnpm <args>` and gives its result. It does not throw for a failed command. */
@@ -1 +1 @@
1
- {"version":3,"file":"shared.js","sourceRoot":"","sources":["../../../src/procedures/pnpm/shared.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,UAAU,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAGlH,wGAAwG;AACxG,MAAM,UAAU,OAAO,CAAC,IAAY,EAAE,KAAa;IAC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AAC,CAAC,CAAC,kBAAkB,CAAC,MAAM,CAAC,CAAC;AACvE,CAAC;AAED,yDAAyD;AACzD,MAAM,IAAI,GAAG,aAAa,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,CAAC,CAAC;AAEnE,qGAAqG;AACrG,MAAM,CAAC,KAAK,UAAU,OAAO,CAC3B,IAAc,EACd,KAAiE,EACjE,GAAqB;IAErB,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,EAAE,GAAG,EAAE,KAAK,CAAC,GAAG,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,EAAE,GAAG,CAAC,CAAC;AACzE,CAAC;AAED,uGAAuG;AACvG,SAAS,aAAa,CAAC,MAAc;IACnC,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,EAAE,CAAC;IAC3B,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;AAC5F,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,IAAc,EACd,KAAiE,EACjE,GAAqB;IAErB,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,GAAG,EAAE,KAAK,CAAC,GAAG,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,EAAE,GAAG,EAAE,aAAa,CAAC,CAAC;AAC5F,CAAC"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package",
3
3
  "name": "@procedures/pnpm",
4
- "version": "0.60.0",
4
+ "version": "0.61.0",
5
5
  "description": "pnpm commands as typed procedures: install, add, remove, run, exec, list, why, outdated, update, pack and link, with --filter and -r, run with argv and option-injection guards.",
6
6
  "keywords": [
7
7
  "pnpm",
@@ -64,13 +64,13 @@
64
64
  "provenance": true
65
65
  },
66
66
  "dependencies": {
67
- "@procedures/client": "0.60.0",
68
- "@procedures/shell": "0.60.0",
67
+ "@procedures/client": "0.61.0",
68
+ "@procedures/shell": "0.61.0",
69
69
  "zod": "^4.6.5"
70
70
  },
71
71
  "devDependencies": {
72
72
  "@mark1russell7/cue": "^2.1.1",
73
- "@procedures/fs": "0.60.0",
73
+ "@procedures/fs": "0.61.0",
74
74
  "@types/node": "^22.0.0",
75
75
  "typescript": "^7.0.2",
76
76
  "vitest": "^5.0.3"
package/src/index.ts CHANGED
@@ -70,7 +70,7 @@ export {
70
70
  } from "./procedures/pnpm/index.js";
71
71
 
72
72
  // How the procedures find pnpm (no shell): other packages that run pnpm use it too
73
- export { resolvePnpm } from "./procedures/pnpm/shared.js";
73
+ export { installedPnpmVersion, resolvePnpm } from "./procedures/pnpm/shared.js";
74
74
 
75
75
  // Registration
76
76
  export { registerPnpmProcedures } from "./module.js";
@@ -10,8 +10,8 @@
10
10
  * script that the `.cmd` file starts, run with Node.
11
11
  */
12
12
 
13
- import { existsSync } from "node:fs";
14
- import { join } from "node:path";
13
+ import { existsSync, readFileSync, realpathSync, statSync } from "node:fs";
14
+ import { basename, dirname, isAbsolute, join, resolve } from "node:path";
15
15
  import type { ProcedureContext } from "@procedures/client";
16
16
  import { defineCliTool, execPathProgram, findInPath, nodeScript, parseJsonDocument } from "@procedures/shell/cli";
17
17
  import type { PnpmCommandOutput, PnpmJsonOutput } from "../../types.js";
@@ -56,6 +56,93 @@ export function resolvePnpm(): { command: string; prefix: string[] } {
56
56
  throw new Error(`pnpm was not found: install pnpm, or run this from a pnpm script (npm_execpath: ${execPath ?? "not set"})`);
57
57
  }
58
58
 
59
+ /** This function gives true when the npm package name is the name of a package that holds a pnpm program. */
60
+ function isPnpmPackage(name: unknown): boolean {
61
+ return name === "pnpm" || (typeof name === "string" && name.startsWith("@pnpm/exe"));
62
+ }
63
+
64
+ /** This function gives the version in the `package.json` of the pnpm package that holds the program file, or undefined. */
65
+ function pnpmPackageVersion(file: string): string | undefined {
66
+ let real: string;
67
+ try {
68
+ real = realpathSync(file);
69
+ } catch {
70
+ return undefined;
71
+ }
72
+ // The executable of pnpm 12 is in the folder of its package, and pnpm.cjs is in the bin folder
73
+ for (const dir of [dirname(real), dirname(dirname(real))]) {
74
+ const manifest = join(dir, "package.json");
75
+ if (!existsSync(manifest)) continue;
76
+ try {
77
+ const data = JSON.parse(readFileSync(manifest, "utf8")) as { name?: unknown; version?: unknown };
78
+ if (isPnpmPackage(data.name) && typeof data.version === "string") return data.version;
79
+ } catch {
80
+ continue;
81
+ }
82
+ }
83
+ return undefined;
84
+ }
85
+
86
+ /** The largest shell shim that `shimTarget` reads, as in pnpm. */
87
+ const MAX_SHELL_SHIM_BYTES = 64 * 1024;
88
+
89
+ /**
90
+ * This function gives the target of a global shim of pnpm 12, or undefined for a file that is not
91
+ * a shim. A shim is a copy of the pnpm executable. The file `.pnpm-shim-v1-<name>-target` beside
92
+ * it holds the path of its target: UTF-16 on Windows, the raw bytes on other systems. An older
93
+ * shim is a shell script with the line `# cmd-shim-target=<path>`. A target `pkg:<package>` has no
94
+ * installed program.
95
+ */
96
+ function shimTarget(file: string): string | undefined {
97
+ const dir = dirname(file);
98
+ const sidecar = join(dir, `.pnpm-shim-v1-${basename(file).replace(/\.exe$/i, "")}-target`);
99
+ let target: string | undefined;
100
+ try {
101
+ if (existsSync(sidecar)) {
102
+ const bytes = readFileSync(sidecar);
103
+ // A path of Linux or macOS has no NUL byte, and UTF-16 has one in each ASCII character
104
+ target = bytes.toString(bytes.includes(0) ? "utf16le" : "utf8");
105
+ } else if (statSync(file).size <= MAX_SHELL_SHIM_BYTES) {
106
+ const marker = "# cmd-shim-target=";
107
+ const line = readFileSync(file, "utf8").split(/\r?\n/).findLast((text) => text.startsWith(marker));
108
+ target = line?.slice(marker.length);
109
+ }
110
+ } catch {
111
+ return undefined;
112
+ }
113
+ return target === undefined || target === "" || target.startsWith("pkg:") ? undefined : resolve(dir, target);
114
+ }
115
+
116
+ /**
117
+ * This function gives the version of the pnpm that `resolvePnpm` finds. It reads the
118
+ * `package.json` of the pnpm package of the program, and it starts no program. For a global shim
119
+ * of pnpm 12, it reads the package of the target of the shim. It gives `undefined` when it finds no
120
+ * pnpm, or no `package.json` of a pnpm package.
121
+ *
122
+ * `pnpm --version` reads the configuration of the working folder. Its `packageManager` field can
123
+ * make pnpm download and start a different pnpm. Thus this function does not start pnpm.
124
+ */
125
+ export function installedPnpmVersion(): string | undefined {
126
+ let program: { command: string; prefix: string[] };
127
+ try {
128
+ program = resolvePnpm();
129
+ } catch {
130
+ return undefined;
131
+ }
132
+ // A script of pnpm runs with Node: the file of pnpm is the first argument
133
+ let file = program.prefix[0] ?? program.command;
134
+ if (!isAbsolute(file)) {
135
+ const name = file;
136
+ const found = findInPath((dir) => (existsSync(join(dir, name)) ? { command: join(dir, name), prefix: [] } : undefined));
137
+ if (found === undefined) return undefined;
138
+ file = found.command;
139
+ }
140
+ const version = pnpmPackageVersion(file);
141
+ if (version !== undefined) return version;
142
+ const target = shimTarget(file);
143
+ return target === undefined ? undefined : pnpmPackageVersion(target);
144
+ }
145
+
59
146
  /** The runner of pnpm. It finds pnpm at each command. */
60
147
  const pnpm = defineCliTool({ name: "pnpm", resolve: resolvePnpm });
61
148