@pnpm/global.commands 1100.0.9 → 1100.0.11

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/lib/index.d.ts CHANGED
@@ -3,4 +3,4 @@ export { type GlobalAddOptions, handleGlobalAdd } from './globalAdd.js';
3
3
  export { handleGlobalRemove } from './globalRemove.js';
4
4
  export { type GlobalUpdateOptions, handleGlobalUpdate } from './globalUpdate.js';
5
5
  export { installGlobalPackages, type InstallGlobalPackagesOptions } from './installGlobalPackages.js';
6
- export { listGlobalPackages } from './listGlobalPackages.js';
6
+ export { findGlobalInstallDirs, listGlobalPackages } from './listGlobalPackages.js';
package/lib/index.js CHANGED
@@ -3,5 +3,5 @@ export { handleGlobalAdd } from './globalAdd.js';
3
3
  export { handleGlobalRemove } from './globalRemove.js';
4
4
  export { handleGlobalUpdate } from './globalUpdate.js';
5
5
  export { installGlobalPackages } from './installGlobalPackages.js';
6
- export { listGlobalPackages } from './listGlobalPackages.js';
6
+ export { findGlobalInstallDirs, listGlobalPackages } from './listGlobalPackages.js';
7
7
  //# sourceMappingURL=index.js.map
@@ -1 +1,6 @@
1
- export declare function listGlobalPackages(globalPkgDir: string, params: string[]): Promise<string>;
1
+ export declare function findGlobalInstallDirs(globalPkgDir: string, params: string[]): string[];
2
+ export interface ListGlobalPackagesOptions {
3
+ long?: boolean;
4
+ reportAs?: 'parseable' | 'tree' | 'json';
5
+ }
6
+ export declare function listGlobalPackages(globalPkgDir: string, params: string[], opts?: ListGlobalPackagesOptions): Promise<string>;
@@ -1,22 +1,75 @@
1
+ import path from 'node:path';
1
2
  import { createMatcher } from '@pnpm/config.matcher';
3
+ import { renderJson, renderParseable, renderTree } from '@pnpm/deps.inspection.list';
2
4
  import { getGlobalPackageDetails, scanGlobalPackages, } from '@pnpm/global.packages';
3
5
  import { lexCompare } from '@pnpm/util.lex-comparator';
4
- export async function listGlobalPackages(globalPkgDir, params) {
6
+ export function findGlobalInstallDirs(globalPkgDir, params) {
7
+ const packages = scanGlobalPackages(globalPkgDir);
8
+ const matches = params.length > 0 ? createMatcher(params) : () => true;
9
+ const installDirs = new Set();
10
+ for (const pkg of packages) {
11
+ for (const alias of Object.keys(pkg.dependencies)) {
12
+ if (matches(alias)) {
13
+ installDirs.add(pkg.installDir);
14
+ break;
15
+ }
16
+ }
17
+ }
18
+ return [...installDirs];
19
+ }
20
+ export async function listGlobalPackages(globalPkgDir, params, opts = {}) {
21
+ const reportAs = opts.reportAs ?? 'tree';
22
+ const long = opts.long ?? false;
5
23
  const packages = scanGlobalPackages(globalPkgDir);
6
24
  const allDetails = await Promise.all(packages.map((pkg) => getGlobalPackageDetails(pkg)));
7
25
  const matches = params.length > 0 ? createMatcher(params) : () => true;
8
- const lines = [];
9
- for (const installed of allDetails.flat()) {
10
- if (!matches(installed.alias))
11
- continue;
12
- lines.push(`${installed.alias}@${installed.version}`);
26
+ const dependencies = [];
27
+ for (let i = 0; i < packages.length; i++) {
28
+ const installDir = packages[i].installDir;
29
+ for (const installed of allDetails[i]) {
30
+ if (!matches(installed.alias))
31
+ continue;
32
+ dependencies.push({
33
+ alias: installed.alias,
34
+ name: installed.manifest.name,
35
+ version: installed.version,
36
+ path: path.join(installDir, 'node_modules', installed.alias),
37
+ isPeer: false,
38
+ isSkipped: false,
39
+ isMissing: false,
40
+ });
41
+ }
13
42
  }
14
- if (lines.length === 0) {
43
+ dependencies.sort((a, b) => lexCompare(a.alias, b.alias));
44
+ if (dependencies.length === 0) {
45
+ if (reportAs === 'json') {
46
+ return JSON.stringify([{ path: globalPkgDir, private: true, dependencies: {} }], null, 2);
47
+ }
48
+ if (reportAs === 'parseable') {
49
+ return globalPkgDir;
50
+ }
15
51
  return params.length > 0
16
52
  ? 'No matching global packages found'
17
53
  : 'No global packages found';
18
54
  }
19
- lines.sort(lexCompare);
20
- return lines.join('\n');
55
+ const hierarchy = [{
56
+ path: globalPkgDir,
57
+ private: true,
58
+ dependencies,
59
+ }];
60
+ switch (reportAs) {
61
+ case 'json':
62
+ return renderJson(hierarchy, { depth: 0, long, search: false });
63
+ case 'parseable':
64
+ return renderParseable(hierarchy, { depth: 0, long, alwaysPrintRootPackage: true, search: false });
65
+ case 'tree':
66
+ return renderTree(hierarchy, {
67
+ alwaysPrintRootPackage: false,
68
+ depth: 0,
69
+ long,
70
+ search: false,
71
+ showExtraneous: false,
72
+ });
73
+ }
21
74
  }
22
75
  //# sourceMappingURL=listGlobalPackages.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pnpm/global.commands",
3
- "version": "1100.0.9",
3
+ "version": "1100.0.11",
4
4
  "description": "Global package command handlers for pnpm",
5
5
  "keywords": [
6
6
  "pnpm",
@@ -28,23 +28,24 @@
28
28
  "@pnpm/util.lex-comparator": "^3.0.2",
29
29
  "is-subdir": "^2.0.0",
30
30
  "symlink-dir": "^10.0.1",
31
- "@pnpm/bins.linker": "1100.0.3",
32
31
  "@pnpm/bins.resolver": "1100.0.2",
33
- "@pnpm/bins.remover": "1100.0.2",
32
+ "@pnpm/bins.linker": "1100.0.3",
34
33
  "@pnpm/cli.command": "1100.0.1",
35
- "@pnpm/cli.utils": "1101.0.2",
36
34
  "@pnpm/config.matcher": "1100.0.1",
37
- "@pnpm/config.reader": "1101.1.4",
38
- "@pnpm/error": "1100.0.0",
35
+ "@pnpm/config.reader": "1101.2.0",
36
+ "@pnpm/cli.utils": "1101.0.2",
37
+ "@pnpm/bins.remover": "1100.0.2",
39
38
  "@pnpm/global.packages": "1100.0.2",
40
- "@pnpm/installing.deps-installer": "1101.0.5",
39
+ "@pnpm/installing.deps-installer": "1101.0.6",
40
+ "@pnpm/store.connection-manager": "1100.0.10",
41
41
  "@pnpm/pkg-manifest.reader": "1100.0.2",
42
- "@pnpm/store.connection-manager": "1100.0.9",
43
- "@pnpm/types": "1101.0.0"
42
+ "@pnpm/error": "1100.0.0",
43
+ "@pnpm/types": "1101.0.0",
44
+ "@pnpm/deps.inspection.list": "1100.0.5"
44
45
  },
45
46
  "devDependencies": {
46
47
  "@jest/globals": "30.3.0",
47
- "@pnpm/global.commands": "1100.0.9"
48
+ "@pnpm/global.commands": "1100.0.11"
48
49
  },
49
50
  "engines": {
50
51
  "node": ">=22.13"