@pnpm/config.version-policy 1100.0.2 → 1100.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/lib/index.d.ts CHANGED
@@ -1,3 +1,24 @@
1
1
  import type { PackageVersionPolicy } from '@pnpm/types';
2
2
  export declare function createPackageVersionPolicy(patterns: string[]): PackageVersionPolicy;
3
+ /**
4
+ * Like {@link createPackageVersionPolicy}, but rewraps parser errors with an
5
+ * `INVALID_<KEY>` PnpmError so the message points at the user-facing config key
6
+ * (e.g. `minimumReleaseAgeExclude`) instead of the internal parser code.
7
+ */
8
+ export declare function createPackageVersionPolicyOrThrow(patterns: string[], key: string): PackageVersionPolicy;
9
+ export interface PublishedByPolicyOptions {
10
+ minimumReleaseAge?: number;
11
+ minimumReleaseAgeExclude?: string[];
12
+ }
13
+ export interface PublishedByPolicy {
14
+ publishedBy?: Date;
15
+ publishedByExclude?: PackageVersionPolicy;
16
+ }
17
+ /**
18
+ * Derives the resolver's `publishedBy` cutoff date and `publishedByExclude`
19
+ * policy from the user's `minimumReleaseAge` / `minimumReleaseAgeExclude`
20
+ * config. Centralized so every call site computes the cutoff at the same
21
+ * instant and surfaces invalid exclude patterns under the same error code.
22
+ */
23
+ export declare function getPublishedByPolicy(opts: PublishedByPolicyOptions): PublishedByPolicy;
3
24
  export declare function expandPackageVersionSpecs(specs: string[]): Set<string>;
package/lib/index.js CHANGED
@@ -9,6 +9,37 @@ export function createPackageVersionPolicy(patterns) {
9
9
  }
10
10
  return evaluateVersionPolicy.bind(null, rules);
11
11
  }
12
+ /**
13
+ * Like {@link createPackageVersionPolicy}, but rewraps parser errors with an
14
+ * `INVALID_<KEY>` PnpmError so the message points at the user-facing config key
15
+ * (e.g. `minimumReleaseAgeExclude`) instead of the internal parser code.
16
+ */
17
+ export function createPackageVersionPolicyOrThrow(patterns, key) {
18
+ try {
19
+ return createPackageVersionPolicy(patterns);
20
+ }
21
+ catch (err) {
22
+ if (!err || typeof err !== 'object' || !('message' in err))
23
+ throw err;
24
+ throw new PnpmError(`INVALID_${key.replace(/([A-Z])/g, '_$1').toUpperCase()}`, `Invalid value in ${key}: ${err.message}`);
25
+ }
26
+ }
27
+ /**
28
+ * Derives the resolver's `publishedBy` cutoff date and `publishedByExclude`
29
+ * policy from the user's `minimumReleaseAge` / `minimumReleaseAgeExclude`
30
+ * config. Centralized so every call site computes the cutoff at the same
31
+ * instant and surfaces invalid exclude patterns under the same error code.
32
+ */
33
+ export function getPublishedByPolicy(opts) {
34
+ return {
35
+ publishedBy: opts.minimumReleaseAge
36
+ ? new Date(Date.now() - opts.minimumReleaseAge * 60 * 1000)
37
+ : undefined,
38
+ publishedByExclude: opts.minimumReleaseAgeExclude
39
+ ? createPackageVersionPolicyOrThrow(opts.minimumReleaseAgeExclude, 'minimumReleaseAgeExclude')
40
+ : undefined,
41
+ };
42
+ }
12
43
  export function expandPackageVersionSpecs(specs) {
13
44
  const expandedSpecs = new Set();
14
45
  for (const spec of specs) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pnpm/config.version-policy",
3
- "version": "1100.0.2",
3
+ "version": "1100.1.0",
4
4
  "description": "Parses and evaluates package version policy specs and produces package-version matchers",
5
5
  "keywords": [
6
6
  "pnpm",
@@ -25,14 +25,14 @@
25
25
  ],
26
26
  "dependencies": {
27
27
  "semver": "^7.7.2",
28
- "@pnpm/types": "1101.0.0",
28
+ "@pnpm/types": "1101.1.0",
29
29
  "@pnpm/error": "1100.0.0",
30
30
  "@pnpm/config.matcher": "1100.0.1"
31
31
  },
32
32
  "devDependencies": {
33
33
  "@jest/globals": "30.3.0",
34
34
  "@types/semver": "7.7.1",
35
- "@pnpm/config.version-policy": "1100.0.2"
35
+ "@pnpm/config.version-policy": "1100.1.0"
36
36
  },
37
37
  "engines": {
38
38
  "node": ">=22.13"