@pnpm/installing.deps-resolver 1008.3.1
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 +22 -0
- package/README.md +17 -0
- package/lib/dedupeInjectedDeps.d.ts +14 -0
- package/lib/dedupeInjectedDeps.js +72 -0
- package/lib/depPathToRef.d.ts +4 -0
- package/lib/depPathToRef.js +7 -0
- package/lib/getCatalogSnapshots.d.ts +4 -0
- package/lib/getCatalogSnapshots.js +21 -0
- package/lib/getExactSinglePreferredVersions.d.ts +6 -0
- package/lib/getExactSinglePreferredVersions.js +11 -0
- package/lib/getNonDevWantedDependencies.d.ts +12 -0
- package/lib/getNonDevWantedDependencies.js +29 -0
- package/lib/getWantedDependencies.d.ts +14 -0
- package/lib/getWantedDependencies.js +45 -0
- package/lib/hoistPeers.d.ts +10 -0
- package/lib/hoistPeers.js +75 -0
- package/lib/index.d.ts +53 -0
- package/lib/index.js +335 -0
- package/lib/mergePeers.d.ts +7 -0
- package/lib/mergePeers.js +30 -0
- package/lib/nextNodeId.d.ts +6 -0
- package/lib/nextNodeId.js +5 -0
- package/lib/parentIdsContainSequence.d.ts +2 -0
- package/lib/parentIdsContainSequence.js +9 -0
- package/lib/replaceVersionInBareSpecifier.d.ts +1 -0
- package/lib/replaceVersionInBareSpecifier.js +15 -0
- package/lib/resolveDependencies.d.ts +248 -0
- package/lib/resolveDependencies.js +1182 -0
- package/lib/resolveDependencyTree.d.ts +122 -0
- package/lib/resolveDependencyTree.js +228 -0
- package/lib/resolvePeers.d.ts +59 -0
- package/lib/resolvePeers.js +702 -0
- package/lib/safeIsInnerLink.d.ts +6 -0
- package/lib/safeIsInnerLink.js +31 -0
- package/lib/toResolveImporter.d.ts +22 -0
- package/lib/toResolveImporter.js +117 -0
- package/lib/unwrapPackageName.d.ts +23 -0
- package/lib/unwrapPackageName.js +39 -0
- package/lib/updateLockfile.d.ts +10 -0
- package/lib/updateLockfile.js +121 -0
- package/lib/updateProjectManifest.d.ts +8 -0
- package/lib/updateProjectManifest.js +34 -0
- package/lib/validatePeerDependencies.d.ts +6 -0
- package/lib/validatePeerDependencies.js +15 -0
- package/lib/wantedDepIsLocallyAvailable.d.ts +6 -0
- package/lib/wantedDepIsLocallyAvailable.js +23 -0
- package/package.json +91 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { logger } from '@pnpm/logger';
|
|
3
|
+
import { isInnerLink } from 'is-inner-link';
|
|
4
|
+
import { isSubdir } from 'is-subdir';
|
|
5
|
+
import { renameOverwrite } from 'rename-overwrite';
|
|
6
|
+
export async function safeIsInnerLink(projectModulesDir, depName, opts) {
|
|
7
|
+
try {
|
|
8
|
+
const link = await isInnerLink(projectModulesDir, depName);
|
|
9
|
+
if (link.isInner)
|
|
10
|
+
return true;
|
|
11
|
+
if (isSubdir(opts.virtualStoreDir, link.target) ||
|
|
12
|
+
opts.globalVirtualStoreDir !== opts.virtualStoreDir && isSubdir(opts.globalVirtualStoreDir, link.target)) {
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
return link.target;
|
|
16
|
+
}
|
|
17
|
+
catch (err) { // eslint-disable-line
|
|
18
|
+
if (err.code === 'ENOENT')
|
|
19
|
+
return true;
|
|
20
|
+
if (opts.hideAlienModules) {
|
|
21
|
+
logger.warn({
|
|
22
|
+
message: `Moving ${depName} that was installed by a different package manager to "node_modules/.ignored"`,
|
|
23
|
+
prefix: opts.projectDir,
|
|
24
|
+
});
|
|
25
|
+
const ignoredDir = path.join(projectModulesDir, '.ignored', depName);
|
|
26
|
+
await renameOverwrite(path.join(projectModulesDir, depName), ignoredDir);
|
|
27
|
+
}
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=safeIsInnerLink.js.map
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { PreferredVersions, WorkspacePackages } from '@pnpm/resolving.resolver-base';
|
|
2
|
+
import { type WantedDependency } from './getWantedDependencies.js';
|
|
3
|
+
import type { ImporterToResolve } from './index.js';
|
|
4
|
+
import type { ImporterToResolveGeneric } from './resolveDependencyTree.js';
|
|
5
|
+
export interface ResolveImporter extends ImporterToResolve, ImporterToResolveGeneric<{
|
|
6
|
+
isNew?: boolean;
|
|
7
|
+
}> {
|
|
8
|
+
wantedDependencies: Array<WantedDependency & {
|
|
9
|
+
isNew?: boolean;
|
|
10
|
+
updateDepth: number;
|
|
11
|
+
}>;
|
|
12
|
+
}
|
|
13
|
+
export declare function toResolveImporter(opts: {
|
|
14
|
+
defaultUpdateDepth: number;
|
|
15
|
+
lockfileOnly: boolean;
|
|
16
|
+
preferredVersions?: PreferredVersions;
|
|
17
|
+
virtualStoreDir: string;
|
|
18
|
+
globalVirtualStoreDir: string;
|
|
19
|
+
workspacePackages: WorkspacePackages;
|
|
20
|
+
updateToLatest?: boolean;
|
|
21
|
+
noDependencySelectors: boolean;
|
|
22
|
+
}, project: ImporterToResolve): Promise<ResolveImporter>;
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { logger } from '@pnpm/logger';
|
|
2
|
+
import { getAllDependenciesFromManifest } from '@pnpm/pkg-manifest.utils';
|
|
3
|
+
import getVerSelType from 'version-selector-type';
|
|
4
|
+
import { getWantedDependencies } from './getWantedDependencies.js';
|
|
5
|
+
import { safeIsInnerLink } from './safeIsInnerLink.js';
|
|
6
|
+
import { unwrapPackageName } from './unwrapPackageName.js';
|
|
7
|
+
import { validatePeerDependencies } from './validatePeerDependencies.js';
|
|
8
|
+
export async function toResolveImporter(opts, project) {
|
|
9
|
+
validatePeerDependencies(project);
|
|
10
|
+
const allDeps = getWantedDependencies(project.manifest);
|
|
11
|
+
const nonLinkedDependencies = await partitionLinkedPackages(allDeps, {
|
|
12
|
+
lockfileOnly: opts.lockfileOnly,
|
|
13
|
+
modulesDir: project.modulesDir,
|
|
14
|
+
projectDir: project.rootDir,
|
|
15
|
+
virtualStoreDir: opts.virtualStoreDir,
|
|
16
|
+
globalVirtualStoreDir: opts.globalVirtualStoreDir,
|
|
17
|
+
workspacePackages: opts.workspacePackages,
|
|
18
|
+
});
|
|
19
|
+
const defaultUpdateDepth = (project.update === true || (project.updateMatching != null)) ? opts.defaultUpdateDepth : -1;
|
|
20
|
+
const existingDeps = nonLinkedDependencies
|
|
21
|
+
.filter(({ alias }) => !project.wantedDependencies.some((wantedDep) => wantedDep.alias === alias));
|
|
22
|
+
if (opts.updateToLatest && opts.noDependencySelectors) {
|
|
23
|
+
for (const dep of existingDeps) {
|
|
24
|
+
dep.updateSpec = true;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
let wantedDependencies;
|
|
28
|
+
if (!project.manifest) {
|
|
29
|
+
wantedDependencies = [
|
|
30
|
+
...project.wantedDependencies,
|
|
31
|
+
...existingDeps,
|
|
32
|
+
]
|
|
33
|
+
.map((dep) => ({
|
|
34
|
+
...dep,
|
|
35
|
+
updateDepth: defaultUpdateDepth,
|
|
36
|
+
}));
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
// Direct local tarballs are always checked,
|
|
40
|
+
// so their update depth should be at least 0
|
|
41
|
+
const updateLocalTarballs = (dep) => ({
|
|
42
|
+
...dep,
|
|
43
|
+
updateDepth: project.updateMatching != null
|
|
44
|
+
? defaultUpdateDepth
|
|
45
|
+
: (prefIsLocalTarball(dep.bareSpecifier) ? 0 : defaultUpdateDepth),
|
|
46
|
+
});
|
|
47
|
+
wantedDependencies = [
|
|
48
|
+
...project.wantedDependencies.map(defaultUpdateDepth < 0
|
|
49
|
+
? updateLocalTarballs
|
|
50
|
+
: (dep) => ({ ...dep, updateDepth: defaultUpdateDepth })),
|
|
51
|
+
...existingDeps.map(opts.noDependencySelectors && project.updateMatching != null
|
|
52
|
+
? updateLocalTarballs
|
|
53
|
+
: (dep) => ({ ...dep, updateDepth: -1 })),
|
|
54
|
+
];
|
|
55
|
+
}
|
|
56
|
+
return {
|
|
57
|
+
...project,
|
|
58
|
+
hasRemovedDependencies: Boolean(project.removePackages?.length),
|
|
59
|
+
preferredVersions: opts.preferredVersions ?? (project.manifest && getPreferredVersionsFromPackage(project.manifest)) ?? {},
|
|
60
|
+
wantedDependencies,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
function prefIsLocalTarball(bareSpecifier) {
|
|
64
|
+
return bareSpecifier.startsWith('file:') && bareSpecifier.endsWith('.tgz');
|
|
65
|
+
}
|
|
66
|
+
async function partitionLinkedPackages(dependencies, opts) {
|
|
67
|
+
const nonLinkedDependencies = [];
|
|
68
|
+
const linkedAliases = new Set();
|
|
69
|
+
await Promise.all(dependencies.map(async (dependency) => {
|
|
70
|
+
if (!dependency.alias ||
|
|
71
|
+
opts.workspacePackages?.get(dependency.alias) != null ||
|
|
72
|
+
dependency.bareSpecifier.startsWith('workspace:')) {
|
|
73
|
+
nonLinkedDependencies.push(dependency);
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
const isInnerLink = await safeIsInnerLink(opts.modulesDir, dependency.alias, {
|
|
77
|
+
hideAlienModules: !opts.lockfileOnly,
|
|
78
|
+
projectDir: opts.projectDir,
|
|
79
|
+
virtualStoreDir: opts.virtualStoreDir,
|
|
80
|
+
globalVirtualStoreDir: opts.globalVirtualStoreDir,
|
|
81
|
+
});
|
|
82
|
+
if (isInnerLink === true) {
|
|
83
|
+
nonLinkedDependencies.push(dependency);
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
if (!dependency.bareSpecifier.startsWith('link:')) {
|
|
87
|
+
// This info-log might be better to be moved to the reporter
|
|
88
|
+
logger.info({
|
|
89
|
+
message: `${dependency.alias} is linked to ${opts.modulesDir} from ${isInnerLink}`,
|
|
90
|
+
prefix: opts.projectDir,
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
linkedAliases.add(dependency.alias);
|
|
94
|
+
}));
|
|
95
|
+
return nonLinkedDependencies;
|
|
96
|
+
}
|
|
97
|
+
function getPreferredVersionsFromPackage(pkg) {
|
|
98
|
+
return getVersionSpecsByRealNames(getAllDependenciesFromManifest(pkg));
|
|
99
|
+
}
|
|
100
|
+
function getVersionSpecsByRealNames(deps) {
|
|
101
|
+
const acc = {};
|
|
102
|
+
for (const depName in deps) {
|
|
103
|
+
const currentBareSpecifier = deps[depName];
|
|
104
|
+
const { pkgName, bareSpecifier } = unwrapPackageName(depName, currentBareSpecifier);
|
|
105
|
+
// we really care only about semver specs
|
|
106
|
+
if (bareSpecifier.includes(':')) {
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
const selector = getVerSelType(bareSpecifier);
|
|
110
|
+
if (selector != null) {
|
|
111
|
+
acc[pkgName] = acc[pkgName] || {};
|
|
112
|
+
acc[pkgName][selector.normalized] = selector.type;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return acc;
|
|
116
|
+
}
|
|
117
|
+
//# sourceMappingURL=toResolveImporter.js.map
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export interface UnwrappedPackageInfo {
|
|
2
|
+
readonly pkgName: string;
|
|
3
|
+
readonly bareSpecifier: string;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* When declaring dependencies in a package.json file, it's possible to specify
|
|
7
|
+
* an "alias".
|
|
8
|
+
*
|
|
9
|
+
* An example of this would be:
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```json
|
|
13
|
+
* {
|
|
14
|
+
* "dependencies": {
|
|
15
|
+
* "my-alias": "npm:is-positive@^1.0.0"
|
|
16
|
+
* }
|
|
17
|
+
* }
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* This function normalizes out the alias and returns the real package name
|
|
21
|
+
* (i.e. "is-positive" for this example) if "npm:" is used.
|
|
22
|
+
*/
|
|
23
|
+
export declare function unwrapPackageName(alias: string, originalBareSpecifier: string): UnwrappedPackageInfo;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* When declaring dependencies in a package.json file, it's possible to specify
|
|
3
|
+
* an "alias".
|
|
4
|
+
*
|
|
5
|
+
* An example of this would be:
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```json
|
|
9
|
+
* {
|
|
10
|
+
* "dependencies": {
|
|
11
|
+
* "my-alias": "npm:is-positive@^1.0.0"
|
|
12
|
+
* }
|
|
13
|
+
* }
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* This function normalizes out the alias and returns the real package name
|
|
17
|
+
* (i.e. "is-positive" for this example) if "npm:" is used.
|
|
18
|
+
*/
|
|
19
|
+
export function unwrapPackageName(alias, originalBareSpecifier) {
|
|
20
|
+
// If the specifier doesn't start with "npm:", there's no more work to do. The
|
|
21
|
+
// "alias" argument is just the real package's name.
|
|
22
|
+
if (!originalBareSpecifier.startsWith('npm:')) {
|
|
23
|
+
return { pkgName: alias, bareSpecifier: originalBareSpecifier };
|
|
24
|
+
}
|
|
25
|
+
const npmAliasSpecifierValue = originalBareSpecifier.slice(4);
|
|
26
|
+
const index = npmAliasSpecifierValue.lastIndexOf('@');
|
|
27
|
+
// If the "@" character isn't found or is the first character, then
|
|
28
|
+
// this alias is just a package name without a spec. Examples:
|
|
29
|
+
// "npm:is-positive", "npm:@pnpm/lockfile.fs"
|
|
30
|
+
//
|
|
31
|
+
// In this case, the bare specifier will be "*".
|
|
32
|
+
if (index === -1 || index === 0) {
|
|
33
|
+
return { pkgName: npmAliasSpecifierValue, bareSpecifier: '*' };
|
|
34
|
+
}
|
|
35
|
+
const bareSpecifier = npmAliasSpecifierValue.slice(index + 1);
|
|
36
|
+
const pkgName = npmAliasSpecifierValue.substring(0, index);
|
|
37
|
+
return { pkgName, bareSpecifier };
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=unwrapPackageName.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type LockfileObject } from '@pnpm/lockfile.pruner';
|
|
2
|
+
import type { Registries } from '@pnpm/types';
|
|
3
|
+
import type { DependenciesGraph } from './index.js';
|
|
4
|
+
export declare function updateLockfile({ dependenciesGraph, lockfile, prefix, registries, lockfileIncludeTarballUrl }: {
|
|
5
|
+
dependenciesGraph: DependenciesGraph;
|
|
6
|
+
lockfile: LockfileObject;
|
|
7
|
+
prefix: string;
|
|
8
|
+
registries: Registries;
|
|
9
|
+
lockfileIncludeTarballUrl?: boolean;
|
|
10
|
+
}): LockfileObject;
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import * as dp from '@pnpm/deps.path';
|
|
2
|
+
import { pruneSharedLockfile, } from '@pnpm/lockfile.pruner';
|
|
3
|
+
import { toLockfileResolution } from '@pnpm/lockfile.utils';
|
|
4
|
+
import { logger } from '@pnpm/logger';
|
|
5
|
+
import { partition } from 'ramda';
|
|
6
|
+
import { depPathToRef } from './depPathToRef.js';
|
|
7
|
+
export function updateLockfile({ dependenciesGraph, lockfile, prefix, registries, lockfileIncludeTarballUrl }) {
|
|
8
|
+
lockfile.packages = lockfile.packages ?? {};
|
|
9
|
+
for (const [depPath, depNode] of Object.entries(dependenciesGraph)) {
|
|
10
|
+
const [updatedOptionalDeps, updatedDeps] = partition((child) => depNode.optionalDependencies.has(child.alias) || depNode.peerDependencies[child.alias]?.optional === true, Object.entries(depNode.children).map(([alias, depPath]) => ({ alias, depPath })));
|
|
11
|
+
lockfile.packages[depPath] = toLockfileDependency(depNode, {
|
|
12
|
+
depGraph: dependenciesGraph,
|
|
13
|
+
depPath,
|
|
14
|
+
prevSnapshot: lockfile.packages[depPath],
|
|
15
|
+
registries,
|
|
16
|
+
registry: dp.getRegistryByPackageName(registries, depNode.name),
|
|
17
|
+
updatedDeps,
|
|
18
|
+
updatedOptionalDeps,
|
|
19
|
+
lockfileIncludeTarballUrl,
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
const warn = (message) => {
|
|
23
|
+
logger.warn({ message, prefix });
|
|
24
|
+
};
|
|
25
|
+
return pruneSharedLockfile(lockfile, { warn, dependenciesGraph });
|
|
26
|
+
}
|
|
27
|
+
function toLockfileDependency(pkg, opts) {
|
|
28
|
+
const lockfileResolution = toLockfileResolution({ name: pkg.name, version: pkg.version }, pkg.resolution, opts.registry, opts.lockfileIncludeTarballUrl);
|
|
29
|
+
const newResolvedDeps = updateResolvedDeps(opts.updatedDeps, opts.depGraph);
|
|
30
|
+
const newResolvedOptionalDeps = updateResolvedDeps(opts.updatedOptionalDeps, opts.depGraph);
|
|
31
|
+
const result = {
|
|
32
|
+
resolution: lockfileResolution,
|
|
33
|
+
};
|
|
34
|
+
if (opts.depPath.includes(':')) {
|
|
35
|
+
// There is no guarantee that a non-npmjs.org-hosted package is going to have a version field.
|
|
36
|
+
// Also, for local directory dependencies, the version is not needed.
|
|
37
|
+
if (pkg.version &&
|
|
38
|
+
(!('type' in lockfileResolution) ||
|
|
39
|
+
lockfileResolution.type !== 'directory')) {
|
|
40
|
+
result['version'] = pkg.version;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
if (Object.keys(newResolvedDeps).length > 0) {
|
|
44
|
+
result['dependencies'] = newResolvedDeps;
|
|
45
|
+
}
|
|
46
|
+
if (Object.keys(newResolvedOptionalDeps).length > 0) {
|
|
47
|
+
result['optionalDependencies'] = newResolvedOptionalDeps;
|
|
48
|
+
}
|
|
49
|
+
if (pkg.optional) {
|
|
50
|
+
result['optional'] = true;
|
|
51
|
+
}
|
|
52
|
+
if (pkg.transitivePeerDependencies.size) {
|
|
53
|
+
result['transitivePeerDependencies'] = Array.from(pkg.transitivePeerDependencies).sort();
|
|
54
|
+
}
|
|
55
|
+
if (Object.keys(pkg.peerDependencies ?? {}).length > 0) {
|
|
56
|
+
const peerPkgs = {};
|
|
57
|
+
const normalizedPeerDependenciesMeta = {};
|
|
58
|
+
for (const [peer, { version, optional }] of Object.entries(pkg.peerDependencies)) {
|
|
59
|
+
peerPkgs[peer] = version;
|
|
60
|
+
if (optional) {
|
|
61
|
+
normalizedPeerDependenciesMeta[peer] = { optional: true };
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
result['peerDependencies'] = peerPkgs;
|
|
65
|
+
if (Object.keys(normalizedPeerDependenciesMeta).length > 0) {
|
|
66
|
+
result['peerDependenciesMeta'] = normalizedPeerDependenciesMeta;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
if (pkg.additionalInfo.engines != null) {
|
|
70
|
+
for (const [engine, version] of Object.entries(pkg.additionalInfo.engines)) {
|
|
71
|
+
if (version === '*')
|
|
72
|
+
continue;
|
|
73
|
+
result.engines = result.engines ?? {}; // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
74
|
+
result.engines[engine] = version;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
if (pkg.additionalInfo.cpu != null) {
|
|
78
|
+
result['cpu'] = pkg.additionalInfo.cpu;
|
|
79
|
+
}
|
|
80
|
+
if (pkg.additionalInfo.os != null) {
|
|
81
|
+
result['os'] = pkg.additionalInfo.os;
|
|
82
|
+
}
|
|
83
|
+
if (pkg.additionalInfo.libc != null) {
|
|
84
|
+
result['libc'] = pkg.additionalInfo.libc;
|
|
85
|
+
}
|
|
86
|
+
if (Array.isArray(pkg.additionalInfo.bundledDependencies) ||
|
|
87
|
+
pkg.additionalInfo.bundledDependencies === true) {
|
|
88
|
+
result['bundledDependencies'] = pkg.additionalInfo.bundledDependencies;
|
|
89
|
+
}
|
|
90
|
+
else if (Array.isArray(pkg.additionalInfo.bundleDependencies) ||
|
|
91
|
+
pkg.additionalInfo.bundleDependencies === true) {
|
|
92
|
+
result['bundledDependencies'] = pkg.additionalInfo.bundleDependencies;
|
|
93
|
+
}
|
|
94
|
+
if (pkg.additionalInfo.deprecated) {
|
|
95
|
+
result['deprecated'] = pkg.additionalInfo.deprecated;
|
|
96
|
+
}
|
|
97
|
+
if (pkg.hasBin) {
|
|
98
|
+
result['hasBin'] = true;
|
|
99
|
+
}
|
|
100
|
+
if (pkg.patch) {
|
|
101
|
+
result['patched'] = true;
|
|
102
|
+
}
|
|
103
|
+
return result;
|
|
104
|
+
}
|
|
105
|
+
function updateResolvedDeps(updatedDeps, depGraph) {
|
|
106
|
+
return Object.fromEntries(updatedDeps
|
|
107
|
+
.map(({ alias, depPath }) => {
|
|
108
|
+
if (depPath.startsWith('link:')) {
|
|
109
|
+
return [alias, depPath];
|
|
110
|
+
}
|
|
111
|
+
const depNode = depGraph[depPath];
|
|
112
|
+
return [
|
|
113
|
+
alias,
|
|
114
|
+
depPathToRef(depPath, {
|
|
115
|
+
alias,
|
|
116
|
+
realName: depNode.name,
|
|
117
|
+
}),
|
|
118
|
+
];
|
|
119
|
+
}));
|
|
120
|
+
}
|
|
121
|
+
//# sourceMappingURL=updateLockfile.js.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ProjectManifest } from '@pnpm/types';
|
|
2
|
+
import type { ImporterToResolve } from './index.js';
|
|
3
|
+
import type { ResolvedDirectDependency } from './resolveDependencyTree.js';
|
|
4
|
+
export declare function updateProjectManifest(importer: ImporterToResolve, opts: {
|
|
5
|
+
directDependencies: ResolvedDirectDependency[];
|
|
6
|
+
preserveWorkspaceProtocol: boolean;
|
|
7
|
+
saveWorkspaceProtocol: boolean | 'rolling';
|
|
8
|
+
}): Promise<Array<ProjectManifest | undefined>>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { updateProjectManifestObject, } from '@pnpm/pkg-manifest.utils';
|
|
2
|
+
export async function updateProjectManifest(importer, opts) {
|
|
3
|
+
if (!importer.manifest) {
|
|
4
|
+
throw new Error('Cannot save because no package.json found');
|
|
5
|
+
}
|
|
6
|
+
const specsToUpsert = opts.directDependencies
|
|
7
|
+
.filter((rdd, index) => importer.wantedDependencies[index]?.updateSpec)
|
|
8
|
+
.map((rdd, index) => {
|
|
9
|
+
const wantedDep = importer.wantedDependencies[index];
|
|
10
|
+
return {
|
|
11
|
+
alias: rdd.alias,
|
|
12
|
+
peer: importer.peer,
|
|
13
|
+
bareSpecifier: rdd.catalogLookup?.userSpecifiedBareSpecifier ?? rdd.normalizedBareSpecifier ?? wantedDep.bareSpecifier,
|
|
14
|
+
resolvedVersion: rdd.version,
|
|
15
|
+
pinnedVersion: importer.pinnedVersion,
|
|
16
|
+
saveType: importer.targetDependenciesField,
|
|
17
|
+
};
|
|
18
|
+
});
|
|
19
|
+
for (const pkgToInstall of importer.wantedDependencies) {
|
|
20
|
+
if (pkgToInstall.updateSpec && pkgToInstall.alias && !specsToUpsert.some(({ alias }) => alias === pkgToInstall.alias)) {
|
|
21
|
+
specsToUpsert.push({
|
|
22
|
+
alias: pkgToInstall.alias,
|
|
23
|
+
peer: importer.peer,
|
|
24
|
+
saveType: importer.targetDependenciesField,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
const hookedManifest = await updateProjectManifestObject(importer.rootDir, importer.manifest, specsToUpsert);
|
|
29
|
+
const originalManifest = (importer.originalManifest != null)
|
|
30
|
+
? await updateProjectManifestObject(importer.rootDir, importer.originalManifest, specsToUpsert)
|
|
31
|
+
: undefined;
|
|
32
|
+
return [hookedManifest, originalManifest];
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=updateProjectManifest.js.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { isValidPeerRange } from '@pnpm/deps.peer-range';
|
|
2
|
+
import { PnpmError } from '@pnpm/error';
|
|
3
|
+
export function validatePeerDependencies(project) {
|
|
4
|
+
const { name, peerDependencies } = project.manifest;
|
|
5
|
+
const projectId = name ?? project.rootDir;
|
|
6
|
+
for (const depName in peerDependencies) {
|
|
7
|
+
const version = peerDependencies[depName];
|
|
8
|
+
if (!isValidPeerRange(version)) {
|
|
9
|
+
throw new PnpmError('INVALID_PEER_DEPENDENCY_SPECIFICATION', `The peerDependencies field named '${depName}' of package '${projectId}' has an invalid value: '${version}'`, {
|
|
10
|
+
hint: 'The values in peerDependencies should be either a valid semver range, a `workspace:` spec, or a `catalog:` spec',
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=validatePeerDependencies.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { WorkspacePackages } from '@pnpm/resolving.resolver-base';
|
|
2
|
+
import type { WantedDependency } from './getNonDevWantedDependencies.js';
|
|
3
|
+
export declare function wantedDepIsLocallyAvailable(workspacePackages: WorkspacePackages, wantedDependency: WantedDependency, opts: {
|
|
4
|
+
defaultTag: string;
|
|
5
|
+
registry: string;
|
|
6
|
+
}): boolean;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { parseBareSpecifier } from '@pnpm/resolving.npm-resolver';
|
|
2
|
+
import semver from 'semver';
|
|
3
|
+
export function wantedDepIsLocallyAvailable(workspacePackages, wantedDependency, opts) {
|
|
4
|
+
const spec = parseBareSpecifier(wantedDependency.bareSpecifier, wantedDependency.alias, opts.defaultTag || 'latest', opts.registry);
|
|
5
|
+
if ((spec == null) || !workspacePackages.has(spec.name))
|
|
6
|
+
return false;
|
|
7
|
+
return pickMatchingLocalVersionOrNull(workspacePackages.get(spec.name), spec) !== null;
|
|
8
|
+
}
|
|
9
|
+
// TODO: move this function to separate package or import from @pnpm/resolving.npm-resolver
|
|
10
|
+
function pickMatchingLocalVersionOrNull(versions, spec) {
|
|
11
|
+
const localVersions = Array.from(versions.keys());
|
|
12
|
+
switch (spec.type) {
|
|
13
|
+
case 'tag':
|
|
14
|
+
return semver.maxSatisfying(localVersions, '*');
|
|
15
|
+
case 'version':
|
|
16
|
+
return versions.has(spec.fetchSpec) ? spec.fetchSpec : null;
|
|
17
|
+
case 'range':
|
|
18
|
+
return semver.maxSatisfying(localVersions, spec.fetchSpec, true);
|
|
19
|
+
default:
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=wantedDepIsLocallyAvailable.js.map
|
package/package.json
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@pnpm/installing.deps-resolver",
|
|
3
|
+
"version": "1008.3.1",
|
|
4
|
+
"description": "Resolves dependency graph of a package",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"pnpm",
|
|
7
|
+
"pnpm11"
|
|
8
|
+
],
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"funding": "https://opencollective.com/pnpm",
|
|
11
|
+
"repository": "https://github.com/pnpm/pnpm/tree/main/installing/deps-resolver",
|
|
12
|
+
"homepage": "https://github.com/pnpm/pnpm/tree/main/installing/deps-resolver#readme",
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/pnpm/pnpm/issues"
|
|
15
|
+
},
|
|
16
|
+
"type": "module",
|
|
17
|
+
"main": "lib/index.js",
|
|
18
|
+
"types": "lib/index.d.ts",
|
|
19
|
+
"exports": {
|
|
20
|
+
".": "./lib/index.js"
|
|
21
|
+
},
|
|
22
|
+
"files": [
|
|
23
|
+
"lib",
|
|
24
|
+
"!*.map"
|
|
25
|
+
],
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"@pnpm/util.lex-comparator": "^3.0.2",
|
|
28
|
+
"@yarnpkg/core": "4.2.0",
|
|
29
|
+
"filenamify": "^6.0.0",
|
|
30
|
+
"graph-cycles": "3.0.0",
|
|
31
|
+
"is-inner-link": "^5.0.0",
|
|
32
|
+
"is-subdir": "^2.0.0",
|
|
33
|
+
"normalize-path": "^3.0.0",
|
|
34
|
+
"p-defer": "^4.0.1",
|
|
35
|
+
"path-exists": "^5.0.0",
|
|
36
|
+
"promise-share": "^2.0.0",
|
|
37
|
+
"ramda": "npm:@pnpm/ramda@0.28.1",
|
|
38
|
+
"rename-overwrite": "^7.0.0",
|
|
39
|
+
"safe-promise-defer": "^2.0.0",
|
|
40
|
+
"semver": "^7.7.2",
|
|
41
|
+
"semver-range-intersect": "^0.3.1",
|
|
42
|
+
"version-selector-type": "^3.0.0",
|
|
43
|
+
"@pnpm/catalogs.resolver": "1000.0.5",
|
|
44
|
+
"@pnpm/catalogs.types": "1000.0.0",
|
|
45
|
+
"@pnpm/config.version-policy": "1000.0.0",
|
|
46
|
+
"@pnpm/constants": "1001.3.1",
|
|
47
|
+
"@pnpm/core-loggers": "1001.0.4",
|
|
48
|
+
"@pnpm/deps.peer-range": "1000.0.0",
|
|
49
|
+
"@pnpm/deps.path": "1001.1.3",
|
|
50
|
+
"@pnpm/fetching.pick-fetcher": "1001.0.0",
|
|
51
|
+
"@pnpm/deps.graph-hasher": "1002.0.8",
|
|
52
|
+
"@pnpm/error": "1000.0.5",
|
|
53
|
+
"@pnpm/lockfile.preferred-versions": "1000.0.22",
|
|
54
|
+
"@pnpm/lockfile.types": "1002.0.2",
|
|
55
|
+
"@pnpm/hooks.types": "1001.0.12",
|
|
56
|
+
"@pnpm/lockfile.pruner": "1001.0.17",
|
|
57
|
+
"@pnpm/lockfile.utils": "1003.0.3",
|
|
58
|
+
"@pnpm/patching.config": "1001.0.11",
|
|
59
|
+
"@pnpm/patching.types": "1000.1.0",
|
|
60
|
+
"@pnpm/pkg-manifest.utils": "1001.0.6",
|
|
61
|
+
"@pnpm/resolving.npm-resolver": "1004.4.1",
|
|
62
|
+
"@pnpm/pkg-manifest.reader": "1000.1.2",
|
|
63
|
+
"@pnpm/store.controller-types": "1004.1.0",
|
|
64
|
+
"@pnpm/types": "1000.9.0",
|
|
65
|
+
"@pnpm/workspace.spec-parser": "1000.0.0",
|
|
66
|
+
"@pnpm/resolving.resolver-base": "1005.1.0"
|
|
67
|
+
},
|
|
68
|
+
"peerDependencies": {
|
|
69
|
+
"@pnpm/logger": ">=1001.0.0 <1002.0.0"
|
|
70
|
+
},
|
|
71
|
+
"devDependencies": {
|
|
72
|
+
"@types/normalize-path": "^3.0.2",
|
|
73
|
+
"@types/ramda": "0.29.12",
|
|
74
|
+
"@types/semver": "7.7.1",
|
|
75
|
+
"@pnpm/installing.deps-resolver": "1008.3.1",
|
|
76
|
+
"@pnpm/logger": "1001.0.1"
|
|
77
|
+
},
|
|
78
|
+
"engines": {
|
|
79
|
+
"node": ">=22.13"
|
|
80
|
+
},
|
|
81
|
+
"jest": {
|
|
82
|
+
"preset": "@pnpm/jest-config"
|
|
83
|
+
},
|
|
84
|
+
"scripts": {
|
|
85
|
+
"start": "tsgo --watch",
|
|
86
|
+
"test": "pnpm run compile && pnpm run _test",
|
|
87
|
+
"lint": "eslint \"src/**/*.ts\" \"test/**/*.ts\"",
|
|
88
|
+
"compile": "tsgo --build && pnpm run lint --fix",
|
|
89
|
+
"_test": "cross-env NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules --disable-warning=ExperimentalWarning --disable-warning=DEP0169\" jest"
|
|
90
|
+
}
|
|
91
|
+
}
|