@pnpm/reviewing.dependencies-hierarchy 1.0.0 → 1.1.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/LICENSE +1 -1
- package/lib/DependenciesCache.d.ts +76 -0
- package/lib/DependenciesCache.js +85 -0
- package/lib/DependenciesCache.js.map +1 -0
- package/lib/PackageNode.d.ts +15 -0
- package/lib/PackageNode.js +3 -0
- package/lib/PackageNode.js.map +1 -0
- package/lib/TreeNodeId.d.ts +17 -0
- package/lib/TreeNodeId.js +19 -0
- package/lib/TreeNodeId.js.map +1 -0
- package/lib/buildDependenciesHierarchy.d.ts +21 -0
- package/lib/buildDependenciesHierarchy.js +178 -0
- package/lib/buildDependenciesHierarchy.js.map +1 -0
- package/lib/getPkgInfo.d.ts +33 -0
- package/lib/getPkgInfo.js +77 -0
- package/lib/getPkgInfo.js.map +1 -0
- package/lib/getTree.d.ts +21 -0
- package/lib/getTree.js +184 -0
- package/lib/getTree.js.map +1 -0
- package/lib/getTreeNodeChildId.d.ts +12 -0
- package/lib/getTreeNodeChildId.js +43 -0
- package/lib/getTreeNodeChildId.js.map +1 -0
- package/lib/index.d.ts +3 -37
- package/lib/index.js +2 -310
- package/lib/index.js.map +1 -1
- package/lib/types.d.ts +4 -0
- package/lib/types.js +3 -0
- package/lib/types.js.map +1 -0
- package/package.json +10 -10
package/LICENSE
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
The MIT License (MIT)
|
|
2
2
|
|
|
3
3
|
Copyright (c) 2015-2016 Rico Sta. Cruz and other contributors
|
|
4
|
-
Copyright (c) 2016-
|
|
4
|
+
Copyright (c) 2016-2023 Zoltan Kochan and other contributors
|
|
5
5
|
|
|
6
6
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
7
|
of this software and associated documentation files (the "Software"), to deal
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { PackageNode } from './PackageNode';
|
|
2
|
+
import { TreeNodeId } from './TreeNodeId';
|
|
3
|
+
export interface GetDependenciesCacheEntryArgs {
|
|
4
|
+
readonly parentId: TreeNodeId;
|
|
5
|
+
readonly requestedDepth: number;
|
|
6
|
+
}
|
|
7
|
+
export interface TraversalResultFullyVisited {
|
|
8
|
+
readonly dependencies: PackageNode[];
|
|
9
|
+
/**
|
|
10
|
+
* Describes the height of the parent node in the fully enumerated dependency
|
|
11
|
+
* tree. A height of 0 means no entries are present in the dependencies array.
|
|
12
|
+
* A height of 1 means entries in the dependencies array do not have any of
|
|
13
|
+
* their own dependencies.
|
|
14
|
+
*/
|
|
15
|
+
readonly height: number;
|
|
16
|
+
}
|
|
17
|
+
export interface TraversalResultPartiallyVisited {
|
|
18
|
+
readonly dependencies: PackageNode[];
|
|
19
|
+
/**
|
|
20
|
+
* Describes how deep the dependencies tree was previously traversed. Since
|
|
21
|
+
* the traversal result was limited by a max depth, there are likely more
|
|
22
|
+
* dependencies present deeper in the tree not shown.
|
|
23
|
+
*
|
|
24
|
+
* A depth of 0 would indicate no entries in the dependencies array. A depth
|
|
25
|
+
* of 1 means entries in the dependencies array do not have any of their own
|
|
26
|
+
* dependencies.
|
|
27
|
+
*/
|
|
28
|
+
readonly depth: number;
|
|
29
|
+
}
|
|
30
|
+
export interface CacheHit {
|
|
31
|
+
readonly dependencies: PackageNode[];
|
|
32
|
+
readonly height: number | 'unknown';
|
|
33
|
+
readonly circular: false;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* A cache for the dependencies of a package.
|
|
37
|
+
*
|
|
38
|
+
* ## Depth Considerations
|
|
39
|
+
*
|
|
40
|
+
* Since the enumerated dependency tree can be limited by a max depth argument,
|
|
41
|
+
* several considerations have to be made when caching.
|
|
42
|
+
*
|
|
43
|
+
* - If a package is visited with a requested depth greater than the cached
|
|
44
|
+
* depth, the cache cannot be used. The tree needs to be enumerated again
|
|
45
|
+
* deeper.
|
|
46
|
+
* - If a package is visited with a requested depth less than the cached
|
|
47
|
+
* depth, the cache probably can't be used. This depends on how strict the
|
|
48
|
+
* depth constraint is and whether it's acceptable to exceed the max depth.
|
|
49
|
+
* This cache assumes the max depth should not be exceeded.
|
|
50
|
+
* - Cycles may or may not be cached. It depends on whether the cycle is
|
|
51
|
+
* introduced by a package outside of the cached tree.
|
|
52
|
+
*
|
|
53
|
+
* This cache adds an optimization when a dependency tree has been fully
|
|
54
|
+
* enumerated and wasn't limited by a max depth argument. In that case,
|
|
55
|
+
* dependency trees cached can be used when the max depth argument is greater
|
|
56
|
+
* than or equal to the height of the tree root.
|
|
57
|
+
*
|
|
58
|
+
* ## Future Optimizations
|
|
59
|
+
*
|
|
60
|
+
* The necessity of this cache may be removed in the future with a refactor of
|
|
61
|
+
* the `pnpm list` command. This cache attempts to optimize runtime to O(# of
|
|
62
|
+
* unique packages), but the list command is O(# of nodes) anyway since every
|
|
63
|
+
* node needs to be printed. It's possible a generator function could be
|
|
64
|
+
* returned here to avoid computing large trees in-memory before passing to
|
|
65
|
+
* downstream commands.
|
|
66
|
+
*/
|
|
67
|
+
export declare class DependenciesCache {
|
|
68
|
+
private readonly fullyVisitedCache;
|
|
69
|
+
/**
|
|
70
|
+
* Maps cacheKey -> visitedDepth -> dependencies
|
|
71
|
+
*/
|
|
72
|
+
private readonly partiallyVisitedCache;
|
|
73
|
+
get(args: GetDependenciesCacheEntryArgs): CacheHit | undefined;
|
|
74
|
+
addFullyVisitedResult(treeNodeId: TreeNodeId, result: TraversalResultFullyVisited): void;
|
|
75
|
+
addPartiallyVisitedResult(treeNodeId: TreeNodeId, result: TraversalResultPartiallyVisited): void;
|
|
76
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DependenciesCache = void 0;
|
|
4
|
+
const TreeNodeId_1 = require("./TreeNodeId");
|
|
5
|
+
/**
|
|
6
|
+
* A cache for the dependencies of a package.
|
|
7
|
+
*
|
|
8
|
+
* ## Depth Considerations
|
|
9
|
+
*
|
|
10
|
+
* Since the enumerated dependency tree can be limited by a max depth argument,
|
|
11
|
+
* several considerations have to be made when caching.
|
|
12
|
+
*
|
|
13
|
+
* - If a package is visited with a requested depth greater than the cached
|
|
14
|
+
* depth, the cache cannot be used. The tree needs to be enumerated again
|
|
15
|
+
* deeper.
|
|
16
|
+
* - If a package is visited with a requested depth less than the cached
|
|
17
|
+
* depth, the cache probably can't be used. This depends on how strict the
|
|
18
|
+
* depth constraint is and whether it's acceptable to exceed the max depth.
|
|
19
|
+
* This cache assumes the max depth should not be exceeded.
|
|
20
|
+
* - Cycles may or may not be cached. It depends on whether the cycle is
|
|
21
|
+
* introduced by a package outside of the cached tree.
|
|
22
|
+
*
|
|
23
|
+
* This cache adds an optimization when a dependency tree has been fully
|
|
24
|
+
* enumerated and wasn't limited by a max depth argument. In that case,
|
|
25
|
+
* dependency trees cached can be used when the max depth argument is greater
|
|
26
|
+
* than or equal to the height of the tree root.
|
|
27
|
+
*
|
|
28
|
+
* ## Future Optimizations
|
|
29
|
+
*
|
|
30
|
+
* The necessity of this cache may be removed in the future with a refactor of
|
|
31
|
+
* the `pnpm list` command. This cache attempts to optimize runtime to O(# of
|
|
32
|
+
* unique packages), but the list command is O(# of nodes) anyway since every
|
|
33
|
+
* node needs to be printed. It's possible a generator function could be
|
|
34
|
+
* returned here to avoid computing large trees in-memory before passing to
|
|
35
|
+
* downstream commands.
|
|
36
|
+
*/
|
|
37
|
+
class DependenciesCache {
|
|
38
|
+
constructor() {
|
|
39
|
+
this.fullyVisitedCache = new Map();
|
|
40
|
+
/**
|
|
41
|
+
* Maps cacheKey -> visitedDepth -> dependencies
|
|
42
|
+
*/
|
|
43
|
+
this.partiallyVisitedCache = new Map();
|
|
44
|
+
}
|
|
45
|
+
get(args) {
|
|
46
|
+
const cacheKey = (0, TreeNodeId_1.serializeTreeNodeId)(args.parentId);
|
|
47
|
+
// The fully visited cache is only usable if the height doesn't exceed the
|
|
48
|
+
// requested depth. Otherwise the final dependencies listing will print
|
|
49
|
+
// entries with a greater depth than requested.
|
|
50
|
+
//
|
|
51
|
+
// If that is the case, the partially visited cache should be checked to see
|
|
52
|
+
// if dependencies were requested at that exact depth before.
|
|
53
|
+
const fullyVisitedEntry = this.fullyVisitedCache.get(cacheKey);
|
|
54
|
+
if (fullyVisitedEntry !== undefined && fullyVisitedEntry.height <= args.requestedDepth) {
|
|
55
|
+
return {
|
|
56
|
+
dependencies: fullyVisitedEntry.dependencies,
|
|
57
|
+
height: fullyVisitedEntry.height,
|
|
58
|
+
circular: false,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
const partiallyVisitedEntry = this.partiallyVisitedCache.get(cacheKey)?.get(args.requestedDepth);
|
|
62
|
+
if (partiallyVisitedEntry != null) {
|
|
63
|
+
return {
|
|
64
|
+
dependencies: partiallyVisitedEntry,
|
|
65
|
+
height: 'unknown',
|
|
66
|
+
circular: false,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
return undefined;
|
|
70
|
+
}
|
|
71
|
+
addFullyVisitedResult(treeNodeId, result) {
|
|
72
|
+
const cacheKey = (0, TreeNodeId_1.serializeTreeNodeId)(treeNodeId);
|
|
73
|
+
this.fullyVisitedCache.set(cacheKey, result);
|
|
74
|
+
}
|
|
75
|
+
addPartiallyVisitedResult(treeNodeId, result) {
|
|
76
|
+
const cacheKey = (0, TreeNodeId_1.serializeTreeNodeId)(treeNodeId);
|
|
77
|
+
const dependenciesByDepth = this.partiallyVisitedCache.get(cacheKey) ?? new Map();
|
|
78
|
+
if (!this.partiallyVisitedCache.has(cacheKey)) {
|
|
79
|
+
this.partiallyVisitedCache.set(cacheKey, dependenciesByDepth);
|
|
80
|
+
}
|
|
81
|
+
dependenciesByDepth.set(result.depth, result.dependencies);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
exports.DependenciesCache = DependenciesCache;
|
|
85
|
+
//# sourceMappingURL=DependenciesCache.js.map
|
|
@@ -0,0 +1 @@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iBAAiB,CAAC,GAAG,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAA;IAC9C,CAAC;IAEM,yBAAyB,CAAE,UAAsB,EAAE,MAAuC;QAC/F,MAAM,QAAQ,GAAG,IAAA,gCAAmB,EAAC,UAAU,CAAC,CAAA;QAChD,MAAM,mBAAmB,GAAG,IAAI,CAAC,qBAAqB,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,IAAI,GAAG,EAAE,CAAA;QACjF,IAAI,CAAC,IAAI,CAAC,qBAAqB,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE;YAC7C,IAAI,CAAC,qBAAqB,CAAC,GAAG,CAAC,QAAQ,EAAE,mBAAmB,CAAC,CAAA;SAC9D;QAED,mBAAmB,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,YAAY,CAAC,CAAA;IAC5D,CAAC;CACF;AApDD,8CAoDC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export interface PackageNode {
|
|
2
|
+
alias: string;
|
|
3
|
+
circular?: true;
|
|
4
|
+
dependencies?: PackageNode[];
|
|
5
|
+
dev?: boolean;
|
|
6
|
+
isPeer: boolean;
|
|
7
|
+
isSkipped: boolean;
|
|
8
|
+
isMissing: boolean;
|
|
9
|
+
name: string;
|
|
10
|
+
optional?: true;
|
|
11
|
+
path: string;
|
|
12
|
+
resolved?: string;
|
|
13
|
+
searched?: true;
|
|
14
|
+
version: string;
|
|
15
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PackageNode.js","sourceRoot":"","sources":["../src/PackageNode.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export type TreeNodeId = TreeNodeIdImporter | TreeNodeIdPackage;
|
|
2
|
+
/**
|
|
3
|
+
* A project local to the pnpm workspace.
|
|
4
|
+
*/
|
|
5
|
+
interface TreeNodeIdImporter {
|
|
6
|
+
readonly type: 'importer';
|
|
7
|
+
readonly importerId: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* An npm package depended on externally.
|
|
11
|
+
*/
|
|
12
|
+
interface TreeNodeIdPackage {
|
|
13
|
+
readonly type: 'package';
|
|
14
|
+
readonly depPath: string;
|
|
15
|
+
}
|
|
16
|
+
export declare function serializeTreeNodeId(treeNodeId: TreeNodeId): string;
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.serializeTreeNodeId = void 0;
|
|
4
|
+
function serializeTreeNodeId(treeNodeId) {
|
|
5
|
+
switch (treeNodeId.type) {
|
|
6
|
+
case 'importer': {
|
|
7
|
+
// Only serialize known fields from TreeNodeId. TypeScript is duck typed and
|
|
8
|
+
// objects can have any number of unknown extra fields.
|
|
9
|
+
const { type, importerId } = treeNodeId;
|
|
10
|
+
return JSON.stringify({ type, importerId });
|
|
11
|
+
}
|
|
12
|
+
case 'package': {
|
|
13
|
+
const { type, depPath } = treeNodeId;
|
|
14
|
+
return JSON.stringify({ type, depPath });
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.serializeTreeNodeId = serializeTreeNodeId;
|
|
19
|
+
//# sourceMappingURL=TreeNodeId.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TreeNodeId.js","sourceRoot":"","sources":["../src/TreeNodeId.ts"],"names":[],"mappings":";;;AAkBA,SAAgB,mBAAmB,CAAE,UAAsB;IACzD,QAAQ,UAAU,CAAC,IAAI,EAAE;QACzB,KAAK,UAAU,CAAC,CAAC;YACf,4EAA4E;YAC5E,uDAAuD;YACvD,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,GAAG,UAAU,CAAA;YACvC,OAAO,IAAI,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC,CAAA;SAC5C;QACD,KAAK,SAAS,CAAC,CAAC;YACd,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,UAAU,CAAA;YACpC,OAAO,IAAI,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAA;SACzC;KACA;AACH,CAAC;AAbD,kDAaC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { DependenciesField, Registries } from '@pnpm/types';
|
|
2
|
+
import { PackageNode } from './PackageNode';
|
|
3
|
+
import { SearchFunction } from './types';
|
|
4
|
+
export interface DependenciesHierarchy {
|
|
5
|
+
dependencies?: PackageNode[];
|
|
6
|
+
devDependencies?: PackageNode[];
|
|
7
|
+
optionalDependencies?: PackageNode[];
|
|
8
|
+
unsavedDependencies?: PackageNode[];
|
|
9
|
+
}
|
|
10
|
+
export declare function buildDependenciesHierarchy(projectPaths: string[], maybeOpts: {
|
|
11
|
+
depth: number;
|
|
12
|
+
include?: {
|
|
13
|
+
[dependenciesField in DependenciesField]: boolean;
|
|
14
|
+
};
|
|
15
|
+
registries?: Registries;
|
|
16
|
+
onlyProjects?: boolean;
|
|
17
|
+
search?: SearchFunction;
|
|
18
|
+
lockfileDir: string;
|
|
19
|
+
}): Promise<{
|
|
20
|
+
[projectDir: string]: DependenciesHierarchy;
|
|
21
|
+
}>;
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.buildDependenciesHierarchy = void 0;
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const lockfile_file_1 = require("@pnpm/lockfile-file");
|
|
9
|
+
const modules_yaml_1 = require("@pnpm/modules-yaml");
|
|
10
|
+
const normalize_registries_1 = require("@pnpm/normalize-registries");
|
|
11
|
+
const read_modules_dir_1 = require("@pnpm/read-modules-dir");
|
|
12
|
+
const read_package_json_1 = require("@pnpm/read-package-json");
|
|
13
|
+
const types_1 = require("@pnpm/types");
|
|
14
|
+
const normalize_path_1 = __importDefault(require("normalize-path"));
|
|
15
|
+
const realpath_missing_1 = __importDefault(require("realpath-missing"));
|
|
16
|
+
const resolve_link_target_1 = __importDefault(require("resolve-link-target"));
|
|
17
|
+
const getTree_1 = require("./getTree");
|
|
18
|
+
const getTreeNodeChildId_1 = require("./getTreeNodeChildId");
|
|
19
|
+
const getPkgInfo_1 = require("./getPkgInfo");
|
|
20
|
+
async function buildDependenciesHierarchy(projectPaths, maybeOpts) {
|
|
21
|
+
if (!maybeOpts?.lockfileDir) {
|
|
22
|
+
throw new TypeError('opts.lockfileDir is required');
|
|
23
|
+
}
|
|
24
|
+
const modulesDir = await (0, realpath_missing_1.default)(path_1.default.join(maybeOpts.lockfileDir, 'node_modules'));
|
|
25
|
+
const modules = await (0, modules_yaml_1.readModulesManifest)(modulesDir);
|
|
26
|
+
const registries = (0, normalize_registries_1.normalizeRegistries)({
|
|
27
|
+
...maybeOpts?.registries,
|
|
28
|
+
...modules?.registries,
|
|
29
|
+
});
|
|
30
|
+
const currentLockfile = (modules?.virtualStoreDir && await (0, lockfile_file_1.readCurrentLockfile)(modules.virtualStoreDir, { ignoreIncompatible: false })) ?? null;
|
|
31
|
+
const result = {};
|
|
32
|
+
if (!currentLockfile) {
|
|
33
|
+
for (const projectPath of projectPaths) {
|
|
34
|
+
result[projectPath] = {};
|
|
35
|
+
}
|
|
36
|
+
return result;
|
|
37
|
+
}
|
|
38
|
+
const opts = {
|
|
39
|
+
depth: maybeOpts.depth || 0,
|
|
40
|
+
include: maybeOpts.include ?? {
|
|
41
|
+
dependencies: true,
|
|
42
|
+
devDependencies: true,
|
|
43
|
+
optionalDependencies: true,
|
|
44
|
+
},
|
|
45
|
+
lockfileDir: maybeOpts.lockfileDir,
|
|
46
|
+
onlyProjects: maybeOpts.onlyProjects,
|
|
47
|
+
registries,
|
|
48
|
+
search: maybeOpts.search,
|
|
49
|
+
skipped: new Set(modules?.skipped ?? []),
|
|
50
|
+
};
|
|
51
|
+
(await Promise.all(projectPaths.map(async (projectPath) => {
|
|
52
|
+
return [
|
|
53
|
+
projectPath,
|
|
54
|
+
await dependenciesHierarchyForPackage(projectPath, currentLockfile, opts),
|
|
55
|
+
];
|
|
56
|
+
}))).forEach(([projectPath, dependenciesHierarchy]) => {
|
|
57
|
+
result[projectPath] = dependenciesHierarchy;
|
|
58
|
+
});
|
|
59
|
+
return result;
|
|
60
|
+
}
|
|
61
|
+
exports.buildDependenciesHierarchy = buildDependenciesHierarchy;
|
|
62
|
+
async function dependenciesHierarchyForPackage(projectPath, currentLockfile, opts) {
|
|
63
|
+
const importerId = (0, lockfile_file_1.getLockfileImporterId)(opts.lockfileDir, projectPath);
|
|
64
|
+
if (!currentLockfile.importers[importerId])
|
|
65
|
+
return {};
|
|
66
|
+
const modulesDir = path_1.default.join(projectPath, 'node_modules');
|
|
67
|
+
const savedDeps = getAllDirectDependencies(currentLockfile.importers[importerId]);
|
|
68
|
+
const allDirectDeps = await (0, read_modules_dir_1.readModulesDir)(modulesDir) ?? [];
|
|
69
|
+
const unsavedDeps = allDirectDeps.filter((directDep) => !savedDeps[directDep]);
|
|
70
|
+
const wantedLockfile = await (0, lockfile_file_1.readWantedLockfile)(opts.lockfileDir, { ignoreIncompatible: false }) ?? { packages: {} };
|
|
71
|
+
const getChildrenTree = getTree_1.getTree.bind(null, {
|
|
72
|
+
currentPackages: currentLockfile.packages ?? {},
|
|
73
|
+
importers: currentLockfile.importers,
|
|
74
|
+
includeOptionalDependencies: opts.include.optionalDependencies,
|
|
75
|
+
lockfileDir: opts.lockfileDir,
|
|
76
|
+
onlyProjects: opts.onlyProjects,
|
|
77
|
+
rewriteLinkVersionDir: projectPath,
|
|
78
|
+
maxDepth: opts.depth,
|
|
79
|
+
modulesDir,
|
|
80
|
+
registries: opts.registries,
|
|
81
|
+
search: opts.search,
|
|
82
|
+
skipped: opts.skipped,
|
|
83
|
+
wantedPackages: wantedLockfile.packages ?? {},
|
|
84
|
+
});
|
|
85
|
+
const parentId = { type: 'importer', importerId };
|
|
86
|
+
const result = {};
|
|
87
|
+
for (const dependenciesField of types_1.DEPENDENCIES_FIELDS.sort().filter(dependenciedField => opts.include[dependenciedField])) {
|
|
88
|
+
const topDeps = currentLockfile.importers[importerId][dependenciesField] ?? {};
|
|
89
|
+
result[dependenciesField] = [];
|
|
90
|
+
Object.entries(topDeps).forEach(([alias, ref]) => {
|
|
91
|
+
const packageInfo = (0, getPkgInfo_1.getPkgInfo)({
|
|
92
|
+
alias,
|
|
93
|
+
currentPackages: currentLockfile.packages ?? {},
|
|
94
|
+
rewriteLinkVersionDir: projectPath,
|
|
95
|
+
linkedPathBaseDir: projectPath,
|
|
96
|
+
modulesDir,
|
|
97
|
+
ref,
|
|
98
|
+
registries: opts.registries,
|
|
99
|
+
skipped: opts.skipped,
|
|
100
|
+
wantedPackages: wantedLockfile.packages ?? {},
|
|
101
|
+
});
|
|
102
|
+
let newEntry = null;
|
|
103
|
+
const matchedSearched = opts.search?.(packageInfo);
|
|
104
|
+
const nodeId = (0, getTreeNodeChildId_1.getTreeNodeChildId)({
|
|
105
|
+
parentId,
|
|
106
|
+
dep: { alias, ref },
|
|
107
|
+
lockfileDir: opts.lockfileDir,
|
|
108
|
+
importers: currentLockfile.importers,
|
|
109
|
+
});
|
|
110
|
+
if (opts.onlyProjects && nodeId?.type !== 'importer') {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
else if (nodeId == null) {
|
|
114
|
+
if ((opts.search != null) && !matchedSearched)
|
|
115
|
+
return;
|
|
116
|
+
newEntry = packageInfo;
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
const dependencies = getChildrenTree(nodeId);
|
|
120
|
+
if (dependencies.length > 0) {
|
|
121
|
+
newEntry = {
|
|
122
|
+
...packageInfo,
|
|
123
|
+
dependencies,
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
else if ((opts.search == null) || matchedSearched) {
|
|
127
|
+
newEntry = packageInfo;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
if (newEntry != null) {
|
|
131
|
+
if (matchedSearched) {
|
|
132
|
+
newEntry.searched = true;
|
|
133
|
+
}
|
|
134
|
+
result[dependenciesField].push(newEntry);
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
await Promise.all(unsavedDeps.map(async (unsavedDep) => {
|
|
139
|
+
let pkgPath = path_1.default.join(modulesDir, unsavedDep);
|
|
140
|
+
let version;
|
|
141
|
+
try {
|
|
142
|
+
pkgPath = await (0, resolve_link_target_1.default)(pkgPath);
|
|
143
|
+
version = `link:${(0, normalize_path_1.default)(path_1.default.relative(projectPath, pkgPath))}`;
|
|
144
|
+
}
|
|
145
|
+
catch (err) { // eslint-disable-line
|
|
146
|
+
// if error happened. The package is not a link
|
|
147
|
+
const pkg = await (0, read_package_json_1.safeReadPackageJsonFromDir)(pkgPath);
|
|
148
|
+
version = pkg?.version ?? 'undefined';
|
|
149
|
+
}
|
|
150
|
+
const pkg = {
|
|
151
|
+
alias: unsavedDep,
|
|
152
|
+
isMissing: false,
|
|
153
|
+
isPeer: false,
|
|
154
|
+
isSkipped: false,
|
|
155
|
+
name: unsavedDep,
|
|
156
|
+
path: pkgPath,
|
|
157
|
+
version,
|
|
158
|
+
};
|
|
159
|
+
const matchedSearched = opts.search?.(pkg);
|
|
160
|
+
if ((opts.search != null) && !matchedSearched)
|
|
161
|
+
return;
|
|
162
|
+
const newEntry = pkg;
|
|
163
|
+
if (matchedSearched) {
|
|
164
|
+
newEntry.searched = true;
|
|
165
|
+
}
|
|
166
|
+
result.unsavedDependencies = result.unsavedDependencies ?? [];
|
|
167
|
+
result.unsavedDependencies.push(newEntry);
|
|
168
|
+
}));
|
|
169
|
+
return result;
|
|
170
|
+
}
|
|
171
|
+
function getAllDirectDependencies(projectSnapshot) {
|
|
172
|
+
return {
|
|
173
|
+
...projectSnapshot.dependencies,
|
|
174
|
+
...projectSnapshot.devDependencies,
|
|
175
|
+
...projectSnapshot.optionalDependencies,
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
//# sourceMappingURL=buildDependenciesHierarchy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buildDependenciesHierarchy.js","sourceRoot":"","sources":["../src/buildDependenciesHierarchy.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAuB;AACvB,uDAM4B;AAC5B,qDAAwD;AACxD,qEAAgE;AAChE,6DAAuD;AACvD,+DAAoE;AACpE,uCAAgF;AAChF,oEAA0C;AAC1C,wEAA8C;AAC9C,8EAAmD;AAGnD,uCAAmC;AACnC,6DAAyD;AACzD,6CAAyC;AAUlC,KAAK,UAAU,0BAA0B,CAC9C,YAAsB,EACtB,SAOC;IAED,IAAI,CAAC,SAAS,EAAE,WAAW,EAAE;QAC3B,MAAM,IAAI,SAAS,CAAC,8BAA8B,CAAC,CAAA;KACpD;IACD,MAAM,UAAU,GAAG,MAAM,IAAA,0BAAe,EAAC,cAAI,CAAC,IAAI,CAAC,SAAS,CAAC,WAAW,EAAE,cAAc,CAAC,CAAC,CAAA;IAC1F,MAAM,OAAO,GAAG,MAAM,IAAA,kCAAmB,EAAC,UAAU,CAAC,CAAA;IACrD,MAAM,UAAU,GAAG,IAAA,0CAAmB,EAAC;QACrC,GAAG,SAAS,EAAE,UAAU;QACxB,GAAG,OAAO,EAAE,UAAU;KACvB,CAAC,CAAA;IACF,MAAM,eAAe,GAAG,CAAC,OAAO,EAAE,eAAe,IAAI,MAAM,IAAA,mCAAmB,EAAC,OAAO,CAAC,eAAe,EAAE,EAAE,kBAAkB,EAAE,KAAK,EAAE,CAAC,CAAC,IAAI,IAAI,CAAA;IAE/I,MAAM,MAAM,GAAG,EAAqD,CAAA;IAEpE,IAAI,CAAC,eAAe,EAAE;QACpB,KAAK,MAAM,WAAW,IAAI,YAAY,EAAE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,GAAG,CAAC,CAAA;QAC1C,IAAI,CAAC,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,IAAI,CAAC,eAAe;YAAE,OAAM;QACrD,MAAM,QAAQ,GAAgB,GAAG,CAAA;QACjC,IAAI,eAAe,EAAE;YACnB,QAAQ,CAAC,QAAQ,GAAG,IAAI,CAAA;SACzB;QACD,MAAM,CAAC,mBAAmB,GAAG,MAAM,CAAC,mBAAmB,IAAI,EAAE,CAAA;QAC7D,MAAM,CAAC,mBAAmB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;IAC3C,CAAC,CAAC,CACH,CAAA;IAED,OAAO,MAAM,CAAA;AACf,CAAC;AAED,SAAS,wBAAwB,CAAE,eAAgC;IACjE,OAAO;QACL,GAAG,eAAe,CAAC,YAAY;QAC/B,GAAG,eAAe,CAAC,eAAe;QAClC,GAAG,eAAe,CAAC,oBAAoB;KACxC,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { PackageSnapshots } from '@pnpm/lockfile-file';
|
|
2
|
+
import { Registries } from '@pnpm/types';
|
|
3
|
+
export interface GetPkgInfoOpts {
|
|
4
|
+
readonly alias: string;
|
|
5
|
+
readonly modulesDir: string;
|
|
6
|
+
readonly ref: string;
|
|
7
|
+
readonly currentPackages: PackageSnapshots;
|
|
8
|
+
readonly peers?: Set<string>;
|
|
9
|
+
readonly registries: Registries;
|
|
10
|
+
readonly skipped: Set<string>;
|
|
11
|
+
readonly wantedPackages: PackageSnapshots;
|
|
12
|
+
/**
|
|
13
|
+
* The base dir if the `ref` argument is a `"link:"` relative path.
|
|
14
|
+
*/
|
|
15
|
+
readonly linkedPathBaseDir: string;
|
|
16
|
+
/**
|
|
17
|
+
* If the `ref` argument is a `"link:"` relative path, the ref is reused for
|
|
18
|
+
* the version field. (Since the true semver may not be known.)
|
|
19
|
+
*
|
|
20
|
+
* Optionally rewrite this relative path to a base dir before writing it to
|
|
21
|
+
* version.
|
|
22
|
+
*/
|
|
23
|
+
readonly rewriteLinkVersionDir?: string;
|
|
24
|
+
}
|
|
25
|
+
export declare function getPkgInfo(opts: GetPkgInfoOpts): {
|
|
26
|
+
alias: string;
|
|
27
|
+
isMissing: boolean;
|
|
28
|
+
isPeer: boolean;
|
|
29
|
+
isSkipped: boolean;
|
|
30
|
+
name: string;
|
|
31
|
+
path: string;
|
|
32
|
+
version: string;
|
|
33
|
+
};
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getPkgInfo = void 0;
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const lockfile_utils_1 = require("@pnpm/lockfile-utils");
|
|
9
|
+
const dependency_path_1 = require("@pnpm/dependency-path");
|
|
10
|
+
const normalize_path_1 = __importDefault(require("normalize-path"));
|
|
11
|
+
function getPkgInfo(opts) {
|
|
12
|
+
let name;
|
|
13
|
+
let version;
|
|
14
|
+
let resolved;
|
|
15
|
+
let dev;
|
|
16
|
+
let optional;
|
|
17
|
+
let isSkipped = false;
|
|
18
|
+
let isMissing = false;
|
|
19
|
+
const depPath = (0, dependency_path_1.refToRelative)(opts.ref, opts.alias);
|
|
20
|
+
if (depPath) {
|
|
21
|
+
let pkgSnapshot;
|
|
22
|
+
if (opts.currentPackages[depPath]) {
|
|
23
|
+
pkgSnapshot = opts.currentPackages[depPath];
|
|
24
|
+
const parsed = (0, lockfile_utils_1.nameVerFromPkgSnapshot)(depPath, pkgSnapshot);
|
|
25
|
+
name = parsed.name;
|
|
26
|
+
version = parsed.version;
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
pkgSnapshot = opts.wantedPackages[depPath];
|
|
30
|
+
if (pkgSnapshot) {
|
|
31
|
+
const parsed = (0, lockfile_utils_1.nameVerFromPkgSnapshot)(depPath, pkgSnapshot);
|
|
32
|
+
name = parsed.name;
|
|
33
|
+
version = parsed.version;
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
name = opts.alias;
|
|
37
|
+
version = opts.ref;
|
|
38
|
+
}
|
|
39
|
+
isMissing = true;
|
|
40
|
+
isSkipped = opts.skipped.has(depPath);
|
|
41
|
+
}
|
|
42
|
+
resolved = (0, lockfile_utils_1.pkgSnapshotToResolution)(depPath, pkgSnapshot, opts.registries)['tarball'];
|
|
43
|
+
dev = pkgSnapshot.dev;
|
|
44
|
+
optional = pkgSnapshot.optional;
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
name = opts.alias;
|
|
48
|
+
version = opts.ref;
|
|
49
|
+
}
|
|
50
|
+
const fullPackagePath = depPath
|
|
51
|
+
? path_1.default.join(opts.modulesDir, '.pnpm', (0, dependency_path_1.depPathToFilename)(depPath))
|
|
52
|
+
: path_1.default.join(opts.linkedPathBaseDir, opts.ref.slice(5));
|
|
53
|
+
if (version.startsWith('link:') && opts.rewriteLinkVersionDir) {
|
|
54
|
+
version = `link:${(0, normalize_path_1.default)(path_1.default.relative(opts.rewriteLinkVersionDir, fullPackagePath))}`;
|
|
55
|
+
}
|
|
56
|
+
const packageInfo = {
|
|
57
|
+
alias: opts.alias,
|
|
58
|
+
isMissing,
|
|
59
|
+
isPeer: Boolean(opts.peers?.has(opts.alias)),
|
|
60
|
+
isSkipped,
|
|
61
|
+
name,
|
|
62
|
+
path: fullPackagePath,
|
|
63
|
+
version,
|
|
64
|
+
};
|
|
65
|
+
if (resolved) {
|
|
66
|
+
packageInfo['resolved'] = resolved;
|
|
67
|
+
}
|
|
68
|
+
if (optional === true) {
|
|
69
|
+
packageInfo['optional'] = true;
|
|
70
|
+
}
|
|
71
|
+
if (typeof dev === 'boolean') {
|
|
72
|
+
packageInfo['dev'] = dev;
|
|
73
|
+
}
|
|
74
|
+
return packageInfo;
|
|
75
|
+
}
|
|
76
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,CAAA;KACnC;IACD,IAAI,QAAQ,KAAK,IAAI,EAAE;QACrB,WAAW,CAAC,UAAU,CAAC,GAAG,IAAI,CAAA;KAC/B;IACD,IAAI,OAAO,GAAG,KAAK,SAAS,EAAE;QAC5B,WAAW,CAAC,KAAK,CAAC,GAAG,GAAG,CAAA;KACzB;IACD,OAAO,WAAW,CAAA;AACpB,CAAC;AA/DD,gCA+DC"}
|
package/lib/getTree.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { PackageSnapshots, ProjectSnapshot } from '@pnpm/lockfile-file';
|
|
2
|
+
import { Registries } from '@pnpm/types';
|
|
3
|
+
import { SearchFunction } from './types';
|
|
4
|
+
import { PackageNode } from './PackageNode';
|
|
5
|
+
import { TreeNodeId } from './TreeNodeId';
|
|
6
|
+
interface GetTreeOpts {
|
|
7
|
+
maxDepth: number;
|
|
8
|
+
rewriteLinkVersionDir: string;
|
|
9
|
+
modulesDir: string;
|
|
10
|
+
includeOptionalDependencies: boolean;
|
|
11
|
+
lockfileDir: string;
|
|
12
|
+
onlyProjects?: boolean;
|
|
13
|
+
search?: SearchFunction;
|
|
14
|
+
skipped: Set<string>;
|
|
15
|
+
registries: Registries;
|
|
16
|
+
importers: Record<string, ProjectSnapshot>;
|
|
17
|
+
currentPackages: PackageSnapshots;
|
|
18
|
+
wantedPackages: PackageSnapshots;
|
|
19
|
+
}
|
|
20
|
+
export declare function getTree(opts: GetTreeOpts, parentId: TreeNodeId): PackageNode[];
|
|
21
|
+
export {};
|