@pnpm/lockfile.filtering 1100.1.13 → 1100.1.14
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 +16 -0
- package/lib/filterImporter.d.ts +7 -0
- package/lib/filterImporter.js +23 -0
- package/lib/filterLockfile.d.ts +9 -0
- package/lib/filterLockfile.js +8 -0
- package/lib/filterLockfileByImporters.d.ts +10 -0
- package/lib/filterLockfileByImporters.js +36 -0
- package/lib/filterLockfileByImportersAndEngine.d.ts +24 -0
- package/lib/filterLockfileByImportersAndEngine.js +165 -0
- package/lib/index.d.ts +3 -0
- package/package.json +10 -10
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @pnpm/filter-lockfile
|
|
2
2
|
|
|
3
|
+
## 1100.1.14
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Republished every package: the tarballs published by the v11.13.1 through v11.16.0 releases were missing most of their compiled files due to a packing bug [#13164](https://github.com/pnpm/pnpm/issues/13164).
|
|
8
|
+
|
|
9
|
+
- Updated dependencies:
|
|
10
|
+
- @pnpm/config.package-is-installable@1100.0.16
|
|
11
|
+
- @pnpm/constants@1100.0.1
|
|
12
|
+
- @pnpm/deps.path@1100.0.11
|
|
13
|
+
- @pnpm/error@1100.1.0
|
|
14
|
+
- @pnpm/lockfile.types@1100.0.16
|
|
15
|
+
- @pnpm/lockfile.utils@1100.1.5
|
|
16
|
+
- @pnpm/lockfile.walker@1100.0.16
|
|
17
|
+
- @pnpm/types@1101.6.0
|
|
18
|
+
|
|
3
19
|
## 1100.1.13
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ProjectSnapshot } from '@pnpm/lockfile.types';
|
|
2
|
+
import type { DependenciesField } from '@pnpm/types';
|
|
3
|
+
export declare function filterImporter(importer: ProjectSnapshot, include: {
|
|
4
|
+
[dependenciesField in DependenciesField]: boolean;
|
|
5
|
+
}, opts?: {
|
|
6
|
+
skipRuntimes?: boolean;
|
|
7
|
+
}): ProjectSnapshot;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export function filterImporter(importer, include, opts) {
|
|
2
|
+
const skipRuntimes = opts?.skipRuntimes === true;
|
|
3
|
+
return {
|
|
4
|
+
dependencies: !include.dependencies ? {} : pickNonRuntime(importer.dependencies, skipRuntimes),
|
|
5
|
+
devDependencies: !include.devDependencies ? {} : pickNonRuntime(importer.devDependencies, skipRuntimes),
|
|
6
|
+
optionalDependencies: !include.optionalDependencies ? {} : pickNonRuntime(importer.optionalDependencies, skipRuntimes),
|
|
7
|
+
specifiers: pickNonRuntime(importer.specifiers, skipRuntimes),
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
function pickNonRuntime(deps, skipRuntimes) {
|
|
11
|
+
if (!deps)
|
|
12
|
+
return {};
|
|
13
|
+
if (!skipRuntimes)
|
|
14
|
+
return deps;
|
|
15
|
+
const result = {};
|
|
16
|
+
for (const [name, ref] of Object.entries(deps)) {
|
|
17
|
+
if (!ref.startsWith('runtime:')) {
|
|
18
|
+
result[name] = ref;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return result;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=filterImporter.js.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { LockfileObject } from '@pnpm/lockfile.types';
|
|
2
|
+
import type { DependenciesField, DepPath } from '@pnpm/types';
|
|
3
|
+
export declare function filterLockfile(lockfile: LockfileObject, opts: {
|
|
4
|
+
include: {
|
|
5
|
+
[dependenciesField in DependenciesField]: boolean;
|
|
6
|
+
};
|
|
7
|
+
skipped: Set<DepPath>;
|
|
8
|
+
skipRuntimes?: boolean;
|
|
9
|
+
}): LockfileObject;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { filterLockfileByImporters } from './filterLockfileByImporters.js';
|
|
2
|
+
export function filterLockfile(lockfile, opts) {
|
|
3
|
+
return filterLockfileByImporters(lockfile, Object.keys(lockfile.importers), {
|
|
4
|
+
...opts,
|
|
5
|
+
failOnMissingDependencies: false,
|
|
6
|
+
});
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=filterLockfile.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { LockfileObject } from '@pnpm/lockfile.types';
|
|
2
|
+
import type { DependenciesField, DepPath, ProjectId } from '@pnpm/types';
|
|
3
|
+
export declare function filterLockfileByImporters(lockfile: LockfileObject, importerIds: ProjectId[], opts: {
|
|
4
|
+
include: {
|
|
5
|
+
[dependenciesField in DependenciesField]: boolean;
|
|
6
|
+
};
|
|
7
|
+
skipped: Set<DepPath>;
|
|
8
|
+
skipRuntimes?: boolean;
|
|
9
|
+
failOnMissingDependencies: boolean;
|
|
10
|
+
}): LockfileObject;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { WANTED_LOCKFILE } from '@pnpm/constants';
|
|
2
|
+
import { LockfileMissingDependencyError } from '@pnpm/error';
|
|
3
|
+
import { lockfileWalker } from '@pnpm/lockfile.walker';
|
|
4
|
+
import { logger } from '@pnpm/logger';
|
|
5
|
+
import { filterImporter } from './filterImporter.js';
|
|
6
|
+
const lockfileLogger = logger('lockfile');
|
|
7
|
+
export function filterLockfileByImporters(lockfile, importerIds, opts) {
|
|
8
|
+
const importers = { ...lockfile.importers };
|
|
9
|
+
for (const importerId of importerIds) {
|
|
10
|
+
importers[importerId] = filterImporter(lockfile.importers[importerId], opts.include, { skipRuntimes: opts.skipRuntimes });
|
|
11
|
+
}
|
|
12
|
+
const packages = {};
|
|
13
|
+
if (lockfile.packages != null) {
|
|
14
|
+
pkgAllDeps(lockfileWalker({ ...lockfile, importers }, importerIds, { include: opts.include, skipped: opts.skipped }).step, packages, {
|
|
15
|
+
failOnMissingDependencies: opts.failOnMissingDependencies,
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
return {
|
|
19
|
+
...lockfile,
|
|
20
|
+
importers,
|
|
21
|
+
packages,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
function pkgAllDeps(step, pickedPackages, opts) {
|
|
25
|
+
for (const { pkgSnapshot, depPath, next } of step.dependencies) {
|
|
26
|
+
pickedPackages[depPath] = pkgSnapshot;
|
|
27
|
+
pkgAllDeps(next(), pickedPackages, opts);
|
|
28
|
+
}
|
|
29
|
+
for (const depPath of step.missing) {
|
|
30
|
+
if (opts.failOnMissingDependencies) {
|
|
31
|
+
throw new LockfileMissingDependencyError(depPath);
|
|
32
|
+
}
|
|
33
|
+
lockfileLogger.debug(`No entry for "${depPath}" in ${WANTED_LOCKFILE}`);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=filterLockfileByImporters.js.map
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { LockfileObject } from '@pnpm/lockfile.types';
|
|
2
|
+
import type { DependenciesField, ProjectId, SupportedArchitectures } from '@pnpm/types';
|
|
3
|
+
export interface FilterLockfileResult {
|
|
4
|
+
lockfile: LockfileObject;
|
|
5
|
+
selectedImporterIds: ProjectId[];
|
|
6
|
+
}
|
|
7
|
+
export declare function filterLockfileByEngine(lockfile: LockfileObject, opts: FilterLockfileOptions): FilterLockfileResult;
|
|
8
|
+
export interface FilterLockfileOptions {
|
|
9
|
+
currentEngine: {
|
|
10
|
+
nodeVersion?: string;
|
|
11
|
+
pnpmVersion: string;
|
|
12
|
+
};
|
|
13
|
+
engineStrict: boolean;
|
|
14
|
+
include: {
|
|
15
|
+
[dependenciesField in DependenciesField]: boolean;
|
|
16
|
+
};
|
|
17
|
+
includeIncompatiblePackages?: boolean;
|
|
18
|
+
failOnMissingDependencies: boolean;
|
|
19
|
+
lockfileDir: string;
|
|
20
|
+
skipped: Set<string>;
|
|
21
|
+
skipRuntimes?: boolean;
|
|
22
|
+
supportedArchitectures?: SupportedArchitectures;
|
|
23
|
+
}
|
|
24
|
+
export declare function filterLockfileByImportersAndEngine(lockfile: LockfileObject, importerIds: ProjectId[], opts: FilterLockfileOptions): FilterLockfileResult;
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { packageIsInstallable } from '@pnpm/config.package-is-installable';
|
|
2
|
+
import { WANTED_LOCKFILE } from '@pnpm/constants';
|
|
3
|
+
import * as dp from '@pnpm/deps.path';
|
|
4
|
+
import { LockfileMissingDependencyError } from '@pnpm/error';
|
|
5
|
+
import { nameVerFromPkgSnapshot } from '@pnpm/lockfile.utils';
|
|
6
|
+
import { logger } from '@pnpm/logger';
|
|
7
|
+
import { map as mapValues, pickBy, unnest } from 'ramda';
|
|
8
|
+
import { filterImporter } from './filterImporter.js';
|
|
9
|
+
const lockfileLogger = logger('lockfile');
|
|
10
|
+
export function filterLockfileByEngine(lockfile, opts) {
|
|
11
|
+
const importerIds = Object.keys(lockfile.importers);
|
|
12
|
+
return filterLockfileByImportersAndEngine(lockfile, importerIds, opts);
|
|
13
|
+
}
|
|
14
|
+
export function filterLockfileByImportersAndEngine(lockfile, importerIds, opts) {
|
|
15
|
+
const importerIdSet = new Set(importerIds);
|
|
16
|
+
const directDepPaths = toImporterDepPaths(lockfile, importerIds, {
|
|
17
|
+
include: opts.include,
|
|
18
|
+
importerIdSet,
|
|
19
|
+
skipRuntimes: opts.skipRuntimes,
|
|
20
|
+
});
|
|
21
|
+
const packages = lockfile.packages != null
|
|
22
|
+
? pickPkgsWithAllDeps(lockfile, directDepPaths, importerIdSet, {
|
|
23
|
+
currentEngine: opts.currentEngine,
|
|
24
|
+
engineStrict: opts.engineStrict,
|
|
25
|
+
failOnMissingDependencies: opts.failOnMissingDependencies,
|
|
26
|
+
include: opts.include,
|
|
27
|
+
includeIncompatiblePackages: opts.includeIncompatiblePackages === true,
|
|
28
|
+
lockfileDir: opts.lockfileDir,
|
|
29
|
+
skipped: opts.skipped,
|
|
30
|
+
skipRuntimes: opts.skipRuntimes,
|
|
31
|
+
supportedArchitectures: opts.supportedArchitectures,
|
|
32
|
+
})
|
|
33
|
+
: {};
|
|
34
|
+
const importers = mapValues((importer) => {
|
|
35
|
+
const newImporter = filterImporter(importer, opts.include, { skipRuntimes: opts.skipRuntimes });
|
|
36
|
+
if (newImporter.optionalDependencies != null) {
|
|
37
|
+
newImporter.optionalDependencies = pickBy((ref, depName) => {
|
|
38
|
+
const depPath = dp.refToRelative(ref, depName);
|
|
39
|
+
return !depPath || packages[depPath] != null;
|
|
40
|
+
}, newImporter.optionalDependencies);
|
|
41
|
+
}
|
|
42
|
+
return newImporter;
|
|
43
|
+
}, lockfile.importers);
|
|
44
|
+
return {
|
|
45
|
+
lockfile: {
|
|
46
|
+
...lockfile,
|
|
47
|
+
importers,
|
|
48
|
+
packages,
|
|
49
|
+
},
|
|
50
|
+
selectedImporterIds: Array.from(importerIdSet),
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
function pickPkgsWithAllDeps(lockfile, depPaths, importerIdSet, opts) {
|
|
54
|
+
const pickedPackages = {};
|
|
55
|
+
pkgAllDeps({ lockfile, pickedPackages, importerIdSet }, depPaths, true, opts);
|
|
56
|
+
return pickedPackages;
|
|
57
|
+
}
|
|
58
|
+
function pkgAllDeps(ctx, depPaths, parentIsInstallable, opts) {
|
|
59
|
+
for (const depPath of depPaths) {
|
|
60
|
+
if (ctx.pickedPackages[depPath])
|
|
61
|
+
continue;
|
|
62
|
+
const pkgSnapshot = ctx.lockfile.packages[depPath];
|
|
63
|
+
if (!pkgSnapshot && !depPath.startsWith('link:')) {
|
|
64
|
+
if (opts.failOnMissingDependencies) {
|
|
65
|
+
throw new LockfileMissingDependencyError(depPath);
|
|
66
|
+
}
|
|
67
|
+
lockfileLogger.debug(`No entry for "${depPath}" in ${WANTED_LOCKFILE}`);
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
let installable;
|
|
71
|
+
if (!parentIsInstallable) {
|
|
72
|
+
installable = false;
|
|
73
|
+
if (!ctx.pickedPackages[depPath] && pkgSnapshot.optional === true) {
|
|
74
|
+
opts.skipped.add(depPath);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
const pkg = {
|
|
79
|
+
...nameVerFromPkgSnapshot(depPath, pkgSnapshot),
|
|
80
|
+
cpu: pkgSnapshot.cpu,
|
|
81
|
+
engines: pkgSnapshot.engines,
|
|
82
|
+
os: pkgSnapshot.os,
|
|
83
|
+
libc: pkgSnapshot.libc,
|
|
84
|
+
};
|
|
85
|
+
// TODO: depPath is not the package ID. Should be fixed
|
|
86
|
+
installable =
|
|
87
|
+
opts.includeIncompatiblePackages ||
|
|
88
|
+
packageIsInstallable(pkgSnapshot.id ?? depPath, pkg, {
|
|
89
|
+
engineStrict: opts.engineStrict,
|
|
90
|
+
lockfileDir: opts.lockfileDir,
|
|
91
|
+
nodeVersion: opts.currentEngine.nodeVersion,
|
|
92
|
+
optional: pkgSnapshot.optional === true,
|
|
93
|
+
supportedArchitectures: opts.supportedArchitectures,
|
|
94
|
+
}) !== false;
|
|
95
|
+
if (!installable) {
|
|
96
|
+
if (!ctx.pickedPackages[depPath] && pkgSnapshot.optional === true) {
|
|
97
|
+
opts.skipped.add(depPath);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
opts.skipped.delete(depPath);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
ctx.pickedPackages[depPath] = pkgSnapshot;
|
|
105
|
+
const { depPaths: nextRelDepPaths, importerIds: additionalImporterIds } = parseDepRefs(Object.entries({
|
|
106
|
+
...pkgSnapshot.dependencies,
|
|
107
|
+
...(opts.include.optionalDependencies
|
|
108
|
+
? pkgSnapshot.optionalDependencies
|
|
109
|
+
: {}),
|
|
110
|
+
}), ctx.lockfile);
|
|
111
|
+
additionalImporterIds.forEach((importerId) => ctx.importerIdSet.add(importerId));
|
|
112
|
+
nextRelDepPaths.push(...toImporterDepPaths(ctx.lockfile, additionalImporterIds, {
|
|
113
|
+
include: opts.include,
|
|
114
|
+
importerIdSet: ctx.importerIdSet,
|
|
115
|
+
skipRuntimes: opts.skipRuntimes,
|
|
116
|
+
}));
|
|
117
|
+
pkgAllDeps(ctx, nextRelDepPaths, installable, opts);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
function toImporterDepPaths(lockfile, importerIds, opts) {
|
|
121
|
+
const importerDeps = importerIds
|
|
122
|
+
.map(importerId => lockfile.importers[importerId])
|
|
123
|
+
.map(importer => ({
|
|
124
|
+
...(opts.include.dependencies ? importer.dependencies : {}),
|
|
125
|
+
...(opts.include.devDependencies ? importer.devDependencies : {}),
|
|
126
|
+
...(opts.include.optionalDependencies
|
|
127
|
+
? importer.optionalDependencies
|
|
128
|
+
: {}),
|
|
129
|
+
}))
|
|
130
|
+
.map(Object.entries)
|
|
131
|
+
.map(entries => opts.skipRuntimes ? entries.filter(([, ref]) => !ref.startsWith('runtime:')) : entries);
|
|
132
|
+
let { depPaths, importerIds: nextImporterIds } = parseDepRefs(unnest(importerDeps), lockfile);
|
|
133
|
+
if (!nextImporterIds.length) {
|
|
134
|
+
return depPaths;
|
|
135
|
+
}
|
|
136
|
+
nextImporterIds = nextImporterIds.filter(importerId => !opts.importerIdSet.has(importerId));
|
|
137
|
+
for (const importerId of nextImporterIds) {
|
|
138
|
+
opts.importerIdSet.add(importerId);
|
|
139
|
+
}
|
|
140
|
+
return [
|
|
141
|
+
...depPaths,
|
|
142
|
+
...toImporterDepPaths(lockfile, nextImporterIds, opts),
|
|
143
|
+
];
|
|
144
|
+
}
|
|
145
|
+
function parseDepRefs(refsByPkgNames, lockfile) {
|
|
146
|
+
const acc = {
|
|
147
|
+
depPaths: [],
|
|
148
|
+
importerIds: [],
|
|
149
|
+
};
|
|
150
|
+
for (const [pkgName, ref] of refsByPkgNames) {
|
|
151
|
+
if (ref.startsWith('link:')) {
|
|
152
|
+
const importerId = ref.substring(5);
|
|
153
|
+
if (lockfile.importers[importerId]) {
|
|
154
|
+
acc.importerIds.push(importerId);
|
|
155
|
+
}
|
|
156
|
+
continue;
|
|
157
|
+
}
|
|
158
|
+
const depPath = dp.refToRelative(ref, pkgName);
|
|
159
|
+
if (depPath == null)
|
|
160
|
+
continue;
|
|
161
|
+
acc.depPaths.push(depPath);
|
|
162
|
+
}
|
|
163
|
+
return acc;
|
|
164
|
+
}
|
|
165
|
+
//# sourceMappingURL=filterLockfileByImportersAndEngine.js.map
|
package/lib/index.d.ts
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pnpm/lockfile.filtering",
|
|
3
|
-
"version": "1100.1.
|
|
3
|
+
"version": "1100.1.14",
|
|
4
4
|
"description": "Filters a lockfile",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pnpm",
|
|
@@ -29,14 +29,14 @@
|
|
|
29
29
|
"!*.map"
|
|
30
30
|
],
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@pnpm/config.package-is-installable": "1100.0.
|
|
33
|
-
"@pnpm/constants": "1100.0.
|
|
34
|
-
"@pnpm/deps.path": "1100.0.
|
|
35
|
-
"@pnpm/error": "1100.0
|
|
36
|
-
"@pnpm/lockfile.types": "1100.0.
|
|
37
|
-
"@pnpm/lockfile.utils": "1100.1.
|
|
38
|
-
"@pnpm/lockfile.walker": "1100.0.
|
|
39
|
-
"@pnpm/types": "1101.
|
|
32
|
+
"@pnpm/config.package-is-installable": "1100.0.16",
|
|
33
|
+
"@pnpm/constants": "1100.0.1",
|
|
34
|
+
"@pnpm/deps.path": "1100.0.11",
|
|
35
|
+
"@pnpm/error": "1100.1.0",
|
|
36
|
+
"@pnpm/lockfile.types": "1100.0.16",
|
|
37
|
+
"@pnpm/lockfile.utils": "1100.1.5",
|
|
38
|
+
"@pnpm/lockfile.walker": "1100.0.16",
|
|
39
|
+
"@pnpm/types": "1101.6.0",
|
|
40
40
|
"ramda": "npm:@pnpm/ramda@0.28.1"
|
|
41
41
|
},
|
|
42
42
|
"peerDependencies": {
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@jest/globals": "30.4.1",
|
|
47
|
-
"@pnpm/lockfile.filtering": "1100.1.
|
|
47
|
+
"@pnpm/lockfile.filtering": "1100.1.14",
|
|
48
48
|
"@pnpm/logger": "1100.0.0",
|
|
49
49
|
"@types/ramda": "0.31.1",
|
|
50
50
|
"detect-libc": "^2.1.2",
|