@zenfs/devel 1.1.1 → 1.2.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.
@@ -1,3 +1,4 @@
1
+ import type * as changelog from './changelog.js';
1
2
  import type { Api } from './docs.js';
2
3
  import type { NodeRepository } from './node.js';
3
4
  import type { PR } from './pr.js';
@@ -46,6 +47,27 @@ export declare class Analysis {
46
47
  * @param prs Defaults to every PR
47
48
  */
48
49
  filterPRs(filter: PRFilter, prs?: Iterable<PRStatus>): PRStatus[];
50
+ /**
51
+ * PRs and APIs that are part of a release, including those released earlier.
52
+ * API availability comes from the docs' `added` and `removed` versions, so APIs without an `added` version are always included.
53
+ */
54
+ coverage(version: string): Coverage | undefined;
55
+ /**
56
+ * The newest release with every PR and API covered.
57
+ * @param latest Only consider this release and older ones
58
+ */
59
+ lastComplete(latest?: string): Coverage | undefined;
60
+ }
61
+ export interface Coverage {
62
+ release: changelog.Release;
63
+ /** Every PR that is part of the release */
64
+ prs: PRStatus[];
65
+ /** Every API documented for the release */
66
+ apis: ApiStatus[];
67
+ pending: PRStatus[];
68
+ /** APIs ZenFS lacks that are not marked */
69
+ missing: ApiStatus[];
70
+ complete: boolean;
49
71
  }
50
72
  /**
51
73
  * Sorts newest first, by landing date on the tracked ref or by first release.
@@ -1,4 +1,4 @@
1
- import { compareVersions } from './versions.js';
1
+ import { compareVersions, isVersion } from './versions.js';
2
2
  import * as zenfs from './zenfs.js';
3
3
  /**
4
4
  * Combines Node.js data, the ZenFS probe, and manual marks.
@@ -51,6 +51,36 @@ export class Analysis {
51
51
  return true;
52
52
  });
53
53
  }
54
+ /**
55
+ * PRs and APIs that are part of a release, including those released earlier.
56
+ * API availability comes from the docs' `added` and `removed` versions, so APIs without an `added` version are always included.
57
+ */
58
+ coverage(version) {
59
+ const release = this.node.releases.find(release => release.version == version.replace(/^v/, ''));
60
+ if (!release)
61
+ return;
62
+ const prs = [...this.prs.values()].filter(({ pr }) => this.node.releaseIncludes(release.version, pr.releases.map(release => release.version)));
63
+ const apis = [...this.apis.values()].filter(({ api }) => {
64
+ const added = api.added.filter(isVersion);
65
+ return (!added.length || this.node.releaseIncludes(release.version, added)) && !this.node.releaseIncludes(release.version, api.removed);
66
+ });
67
+ const pending = prs.filter(({ status }) => status == 'pending');
68
+ const missing = apis.filter(({ present, mark }) => !present && !mark);
69
+ return { release, prs, apis, pending, missing, complete: !pending.length && !missing.length };
70
+ }
71
+ /**
72
+ * The newest release with every PR and API covered.
73
+ * @param latest Only consider this release and older ones
74
+ */
75
+ lastComplete(latest) {
76
+ for (const { version } of this.node.releases) {
77
+ if (latest && compareVersions(version, latest) > 0)
78
+ continue;
79
+ const coverage = this.coverage(version);
80
+ if (coverage?.complete)
81
+ return coverage;
82
+ }
83
+ }
54
84
  }
55
85
  /**
56
86
  * Sorts newest first, by landing date on the tracked ref or by first release.
@@ -22,11 +22,20 @@ export declare class NodeRepository extends Repository {
22
22
  readonly apis: Map<string, docs.Api>;
23
23
  /** Every release found in the changelogs, newest first */
24
24
  readonly releases: changelog.Release[];
25
+ /** ISO date of each release line's first release */
26
+ private readonly lineStarts;
27
+ private readonly releaseDates;
25
28
  /**
26
29
  * Loads PRs, releases, and the API surface from a local Node.js clone.
27
30
  */
28
31
  constructor({ subsystems, docs: docPath, ...options }: NodeRepositoryInit);
29
32
  get latest(): changelog.Release | undefined;
33
+ /**
34
+ * Whether a change released in any of `versions` is part of `target`.
35
+ * Releases from older lines count if they came out before the target's line started.
36
+ * @param versions Versions, optionally prefixed with `v`
37
+ */
38
+ releaseIncludes(target: string, versions: string[]): boolean;
30
39
  /**
31
40
  * Date of the first release at or after a version.
32
41
  */
@@ -4,12 +4,15 @@ import { matchesSubsystem, readApiHistory, readCommits } from './commits.js';
4
4
  import * as docs from './docs.js';
5
5
  import { Repository } from './git.js';
6
6
  import { PR } from './pr.js';
7
- import { compareVersions } from './versions.js';
7
+ import { compareVersions, isVersion, parseVersion } from './versions.js';
8
8
  export class NodeRepository extends Repository {
9
9
  prs = new Map();
10
10
  apis = new Map();
11
11
  /** Every release found in the changelogs, newest first */
12
12
  releases = [];
13
+ /** ISO date of each release line's first release */
14
+ lineStarts = new Map();
15
+ releaseDates = new Map();
13
16
  /**
14
17
  * Loads PRs, releases, and the API surface from a local Node.js clone.
15
18
  */
@@ -43,10 +46,35 @@ export class NodeRepository extends Repository {
43
46
  }
44
47
  }
45
48
  this.releases = [...releases.values()].sort((left, right) => compareVersions(right.version, left.version));
49
+ for (const release of this.releases.toReversed()) {
50
+ this.releaseDates.set(release.version, release.date);
51
+ if (!this.lineStarts.has(release.line))
52
+ this.lineStarts.set(release.line, release.date);
53
+ }
46
54
  }
47
55
  get latest() {
48
56
  return this.releases[0];
49
57
  }
58
+ /**
59
+ * Whether a change released in any of `versions` is part of `target`.
60
+ * Releases from older lines count if they came out before the target's line started.
61
+ * @param versions Versions, optionally prefixed with `v`
62
+ */
63
+ releaseIncludes(target, versions) {
64
+ const [line] = parseVersion(target);
65
+ const lineStart = this.lineStarts.get(line);
66
+ return versions.some(version => {
67
+ if (!isVersion(version))
68
+ return false;
69
+ const [major] = parseVersion(version);
70
+ if (major == line)
71
+ return compareVersions(version, target) <= 0;
72
+ if (major > line || !lineStart)
73
+ return false;
74
+ const date = this.releaseDates.get(version.replace(/^v/, ''));
75
+ return !date || date <= lineStart;
76
+ });
77
+ }
50
78
  /**
51
79
  * Date of the first release at or after a version.
52
80
  */
@@ -2,4 +2,8 @@
2
2
  * @param version A full or partial version, optionally prefixed with `v`
3
3
  */
4
4
  export declare function parseVersion(version: string): [major: number, minor: number, patch: number];
5
+ /**
6
+ * Whether `version` is a full version, optionally prefixed with `v`, rather than a placeholder like `REPLACEME`
7
+ */
8
+ export declare function isVersion(version: string): boolean;
5
9
  export declare function compareVersions(left: string, right: string): number;
@@ -6,6 +6,12 @@ export function parseVersion(version) {
6
6
  const [major = 0, minor = 0, patch = 0] = version.replace(/^v/, '').split('.').map(Number);
7
7
  return [major, minor, patch];
8
8
  }
9
+ /**
10
+ * Whether `version` is a full version, optionally prefixed with `v`, rather than a placeholder like `REPLACEME`
11
+ */
12
+ export function isVersion(version) {
13
+ return /^v?\d+\.\d+\.\d+$/.test(version);
14
+ }
9
15
  export function compareVersions(left, right) {
10
16
  const [leftMajor, leftMinor, leftPatch] = parseVersion(left);
11
17
  const [rightMajor, rightMinor, rightPatch] = parseVersion(right);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zenfs/devel",
3
- "version": "1.1.1",
3
+ "version": "1.2.0",
4
4
  "description": "Tooling for developing ZenFS packages",
5
5
  "funding": {
6
6
  "type": "individual",