@pnpm/hooks.read-package-hook 1100.2.4 → 1100.3.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 +22 -0
- package/lib/createVersionsOverrider.d.ts +26 -1
- package/lib/createVersionsOverrider.js +44 -6
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -1
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
# @pnpm/hooks.read-package-hook
|
|
2
2
|
|
|
3
|
+
## 1100.3.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- `pnpm update` no longer moves the range a project declares for a dependency that `overrides` also lists, even when the override repeats that range verbatim. Previously the updated `package.json` disagreed with the lockfile, so the next `pnpm install --frozen-lockfile` failed with a specifier mismatch [#14224](https://github.com/pnpm/pnpm/issues/14224).
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies:
|
|
12
|
+
- @pnpm/types@1102.1.0
|
|
13
|
+
|
|
14
|
+
## 1100.2.5
|
|
15
|
+
|
|
16
|
+
### Patch Changes
|
|
17
|
+
|
|
18
|
+
- Fixed an issue where package overrides were written into the metadata cache, causing removed overrides to keep applying on subsequent installs [pnpm/pnpm#13918](https://github.com/pnpm/pnpm/issues/13918).
|
|
19
|
+
|
|
20
|
+
- Updated dependencies:
|
|
21
|
+
- @pnpm/config.parse-overrides@1100.1.4
|
|
22
|
+
- @pnpm/error@1100.1.3
|
|
23
|
+
- @pnpm/types@1102.0.0
|
|
24
|
+
|
|
3
25
|
## 1100.2.4
|
|
4
26
|
|
|
5
27
|
### Patch Changes
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { VersionOverride as VersionOverrideBase } from '@pnpm/config.parse-overrides';
|
|
2
|
-
import type
|
|
2
|
+
import { type DependenciesOrPeersField, type ProjectManifest, type ReadPackageHook } from '@pnpm/types';
|
|
3
3
|
export type VersionOverrideWithoutRawSelector = Omit<VersionOverrideBase, 'selector'>;
|
|
4
4
|
export interface CreateVersionsOverriderOptions {
|
|
5
5
|
/**
|
|
@@ -26,4 +26,29 @@ export type DependencyOverrider = (name: string, bareSpecifier: string, dir?: st
|
|
|
26
26
|
* project with no overrides — or with parent-scoped ones only.
|
|
27
27
|
*/
|
|
28
28
|
export declare function createDependencyOverrider(overrides: VersionOverrideWithoutRawSelector[], rootDir: string): DependencyOverrider | undefined;
|
|
29
|
+
/**
|
|
30
|
+
* What an override needs to read to decide whether it claims a dependency: the
|
|
31
|
+
* parent half of a `parent>child` key is matched against the manifest's own
|
|
32
|
+
* name and version. Workspace projects may declare neither, so this is wider
|
|
33
|
+
* than {@link PackageManifest}.
|
|
34
|
+
*/
|
|
35
|
+
export type OverridableManifest = Pick<ProjectManifest, 'name' | 'version' | DependenciesOrPeersField>;
|
|
36
|
+
/**
|
|
37
|
+
* Whether an override claims a dependency declared as `bareSpecifier` —
|
|
38
|
+
* whether or not it rewrites the text. The specifier is part of the question:
|
|
39
|
+
* a range-scoped override (`foo@^2`) claims one declaration of `foo` and not
|
|
40
|
+
* another, so an alias alone cannot answer it.
|
|
41
|
+
*/
|
|
42
|
+
export type OverriddenDependencyMatcher = (alias: string, bareSpecifier: string) => boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Builds an {@link OverriddenDependencyMatcher} for one manifest: a
|
|
45
|
+
* `parent>child` override key is matched against that manifest's own name and
|
|
46
|
+
* version, so a project asks only about the overrides that govern its own
|
|
47
|
+
* declarations. Binding to the manifest also selects those once, rather than
|
|
48
|
+
* once per dependency asked about.
|
|
49
|
+
*
|
|
50
|
+
* `undefined` when no override in the set could claim anything, so a caller
|
|
51
|
+
* with none configured skips the work entirely.
|
|
52
|
+
*/
|
|
53
|
+
export declare function createOverriddenDependencyMatcher(overrides: VersionOverrideWithoutRawSelector[], rootDir: string): ((manifest: OverridableManifest) => OverriddenDependencyMatcher) | undefined;
|
|
29
54
|
export declare function createVersionsOverrider(overrides: VersionOverrideWithoutRawSelector[], rootDir: string, opts?: CreateVersionsOverriderOptions): ReadPackageHook;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
import { isValidPeerRange } from '@pnpm/deps.peer-range';
|
|
3
|
+
import { DEPENDENCIES_OR_PEER_FIELDS } from '@pnpm/types';
|
|
3
4
|
import normalizePath from 'normalize-path';
|
|
4
5
|
import { partition } from 'ramda';
|
|
5
6
|
import semver from 'semver';
|
|
@@ -23,20 +24,57 @@ export function createDependencyOverrider(overrides, rootDir) {
|
|
|
23
24
|
return convergeBareSpecifier(convergeVersions, name, bareSpecifier);
|
|
24
25
|
};
|
|
25
26
|
}
|
|
27
|
+
/**
|
|
28
|
+
* Builds an {@link OverriddenDependencyMatcher} for one manifest: a
|
|
29
|
+
* `parent>child` override key is matched against that manifest's own name and
|
|
30
|
+
* version, so a project asks only about the overrides that govern its own
|
|
31
|
+
* declarations. Binding to the manifest also selects those once, rather than
|
|
32
|
+
* once per dependency asked about.
|
|
33
|
+
*
|
|
34
|
+
* `undefined` when no override in the set could claim anything, so a caller
|
|
35
|
+
* with none configured skips the work entirely.
|
|
36
|
+
*/
|
|
37
|
+
export function createOverriddenDependencyMatcher(overrides, rootDir) {
|
|
38
|
+
const { versionOverrides, genericVersionOverrides, convergeVersions } = splitOverrides(overrides, rootDir);
|
|
39
|
+
if (versionOverrides.length === 0 && genericVersionOverrides.length === 0 && convergeVersions.size === 0) {
|
|
40
|
+
return undefined;
|
|
41
|
+
}
|
|
42
|
+
return (manifest) => {
|
|
43
|
+
const overridesForManifest = {
|
|
44
|
+
versionOverrides: pickOverridesOfParent(versionOverrides, manifest),
|
|
45
|
+
genericVersionOverrides,
|
|
46
|
+
};
|
|
47
|
+
return (alias, bareSpecifier) => pickVersionOverride(overridesForManifest, alias, bareSpecifier) != null ||
|
|
48
|
+
convergeBareSpecifier(convergeVersions, alias, bareSpecifier) != null;
|
|
49
|
+
};
|
|
50
|
+
}
|
|
26
51
|
export function createVersionsOverrider(overrides, rootDir, opts) {
|
|
27
52
|
const { versionOverrides, genericVersionOverrides, convergeVersions } = splitOverrides(overrides, rootDir);
|
|
28
53
|
return ((manifest, dir) => {
|
|
29
|
-
const versionOverridesWithParent = versionOverrides
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
|
|
54
|
+
const versionOverridesWithParent = pickOverridesOfParent(versionOverrides, manifest);
|
|
55
|
+
// The manifest may come from a shared cache, so the fields the overrides
|
|
56
|
+
// rewrite are cloned instead of mutated in place.
|
|
57
|
+
const clonedManifest = { ...manifest };
|
|
58
|
+
for (const depsField of DEPENDENCIES_OR_PEER_FIELDS) {
|
|
59
|
+
if (manifest[depsField] != null) {
|
|
60
|
+
clonedManifest[depsField] = { ...manifest[depsField] };
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
overrideDepsOfPkg({ manifest: clonedManifest, dir }, versionOverridesWithParent, genericVersionOverrides, {
|
|
34
64
|
convergeVersions,
|
|
35
65
|
convergeDeclaredRanges: opts?.convergeDeclaredRanges,
|
|
36
66
|
});
|
|
37
|
-
return
|
|
67
|
+
return clonedManifest;
|
|
38
68
|
});
|
|
39
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
* The parent-scoped overrides (`parent>child`) whose parent half this manifest
|
|
72
|
+
* answers to. The rest never govern its dependencies.
|
|
73
|
+
*/
|
|
74
|
+
function pickOverridesOfParent(versionOverrides, manifest) {
|
|
75
|
+
return versionOverrides.filter(({ parentPkg }) => (parentPkg.name === manifest.name &&
|
|
76
|
+
(!parentPkg.bareSpecifier || (manifest.version != null && semver.satisfies(manifest.version, parentPkg.bareSpecifier)))));
|
|
77
|
+
}
|
|
40
78
|
function splitOverrides(overrides, rootDir) {
|
|
41
79
|
const [convergeOverrides, explicitOverrides] = partition(({ converge }) => converge === true, overrides);
|
|
42
80
|
const [versionOverrides, genericVersionOverrides] = partition(({ parentPkg }) => parentPkg != null, explicitOverrides.map((override) => ({
|
package/lib/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { createReadPackageHook, getEffectivePackageExtensions } from './createReadPackageHook.js';
|
|
2
|
-
export { createDependencyOverrider, type DependencyOverrider } from './createVersionsOverrider.js';
|
|
2
|
+
export { createDependencyOverrider, createOverriddenDependencyMatcher, type DependencyOverrider, type OverriddenDependencyMatcher } from './createVersionsOverrider.js';
|
package/lib/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { createReadPackageHook, getEffectivePackageExtensions } from './createReadPackageHook.js';
|
|
2
|
-
export { createDependencyOverrider } from './createVersionsOverrider.js';
|
|
2
|
+
export { createDependencyOverrider, createOverriddenDependencyMatcher } from './createVersionsOverrider.js';
|
|
3
3
|
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pnpm/hooks.read-package-hook",
|
|
3
|
-
"version": "1100.
|
|
3
|
+
"version": "1100.3.0",
|
|
4
4
|
"description": "Creates the default package reader hook used by pnpm",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pnpm",
|
|
@@ -28,11 +28,11 @@
|
|
|
28
28
|
],
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"@pnpm/config.matcher": "1100.0.2",
|
|
31
|
-
"@pnpm/config.parse-overrides": "1100.1.
|
|
31
|
+
"@pnpm/config.parse-overrides": "1100.1.4",
|
|
32
32
|
"@pnpm/deps.peer-range": "1100.1.1",
|
|
33
|
-
"@pnpm/error": "1100.1.
|
|
33
|
+
"@pnpm/error": "1100.1.3",
|
|
34
34
|
"@pnpm/resolving.parse-wanted-dependency": "1100.0.2",
|
|
35
|
-
"@pnpm/types": "
|
|
35
|
+
"@pnpm/types": "1102.1.0",
|
|
36
36
|
"@yarnpkg/extensions": "2.0.7",
|
|
37
37
|
"normalize-path": "^3.0.0",
|
|
38
38
|
"ramda": "npm:@pnpm/ramda@0.28.1",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@jest/globals": "30.4.1",
|
|
43
|
-
"@pnpm/hooks.read-package-hook": "1100.
|
|
43
|
+
"@pnpm/hooks.read-package-hook": "1100.3.0",
|
|
44
44
|
"@types/normalize-path": "^3.0.2",
|
|
45
45
|
"@types/ramda": "0.32.0",
|
|
46
46
|
"@types/semver": "7.8.0",
|