rman 2.28.0 → 2.30.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.
@@ -26,6 +26,11 @@ export declare class NodeDependencyUpdater implements DependencyUpdater {
26
26
  * Another package manager is not asked - its dry run is not the same question - and a note says so.
27
27
  */
28
28
  verify(ctx: DependencyUpdater.Context): Promise<string | undefined>;
29
+ /**
30
+ * The upgrades an `ERESOLVE` names at the version they move to - the one under `Could not resolve
31
+ * dependency:` when it is one of them, else every one the output mentions.
32
+ */
33
+ blame(refusal: string, plan: readonly DependencyUpdater.Entry[]): DependencyUpdater.Blame[];
29
34
  /** One decision per dependency name `pkg` declares, whether or not it may move - one that may not
30
35
  * still states rules the others have to keep. */
31
36
  protected collect(pkg: Package, settings: DependencyUpdater.Settings, options: DependencyUpdater.Options, inRepo: ReadonlySet<string>): NodeDependencyUpdater.Decision[];
@@ -86,6 +91,8 @@ export declare class NodeDependencyUpdater implements DependencyUpdater {
86
91
  * move. */
87
92
  protected resolvedDeclared(d: NodeDependencyUpdater.Decision): string | undefined;
88
93
  /** What `d` declares in `field` once it has moved. */
94
+ /** Whether `line` names `token` (`name@version`) whole - not `1.2.3` inside `1.2.30`. */
95
+ protected mentions(line: string, token: string): boolean;
89
96
  protected rangeFor(d: NodeDependencyUpdater.Decision, field: string): string;
90
97
  /** The in-repo packages `pkg` declares a dependency on. */
91
98
  protected siblingsOf(pkg: Package, repoPackages: ReadonlyMap<string, Package>): Package[];
@@ -131,7 +131,33 @@ export class NodeDependencyUpdater {
131
131
  .filter(line => /^npm (error|ERR!)/.test(line) && !/complete log|_logs/.test(line))
132
132
  .map(line => line.replace(/^npm (error|ERR!)\s?/, ' '))
133
133
  .filter(line => line.trim());
134
- return lines.slice(0, 20).join('\n') || ` npm install --dry-run exited ${result.code}`;
134
+ return lines.join('\n') || ` npm install --dry-run exited ${result.code}`;
135
+ }
136
+ /**
137
+ * The upgrades an `ERESOLVE` names at the version they move to - the one under `Could not resolve
138
+ * dependency:` when it is one of them, else every one the output mentions.
139
+ */
140
+ /* **The version is what makes the name evidence.** `@hookform/resolvers@6.0.0` appears in the
141
+ * output only because this run moved it there; the name alone also appears on every line about the
142
+ * tree around it. The `Could not resolve dependency:` line is npm's own verdict - measured on the
143
+ * `@hookform/resolvers` case it reads `peerOptional effect@"^4.0.0" from @hookform/resolvers@6.0.0`
144
+ * - so a move it names is the one to hold, and the others it merely passes through stay. That line
145
+ * sat past the 20 lines `verify` used to keep, which is why it now keeps them all. */
146
+ blame(refusal, plan) {
147
+ const moves = plan.flatMap(entry => {
148
+ const d = this.planned.get(entry);
149
+ return entry.status === 'update' && d ? [{ entry, token: `${d.name}@${d.candidates[d.index]}` }] : [];
150
+ });
151
+ const lines = refusal.split('\n').map(line => line.trim());
152
+ const at = lines.indexOf('Could not resolve dependency:');
153
+ const verdict = at >= 0 ? lines.slice(at + 1).find(Boolean) : undefined;
154
+ const named = verdict ? moves.filter(m => this.mentions(verdict, m.token)) : [];
155
+ if (named.length)
156
+ return named.map(m => ({ entry: m.entry, reason: `npm cannot install it: ${verdict}` }));
157
+ return moves.flatMap(m => {
158
+ const line = lines.find(l => this.mentions(l, m.token));
159
+ return line ? [{ entry: m.entry, reason: `npm cannot install it: ${verdict ?? line}` }] : [];
160
+ });
135
161
  }
136
162
  /** One decision per dependency name `pkg` declares, whether or not it may move - one that may not
137
163
  * still states rules the others have to keep. */
@@ -455,6 +481,11 @@ export class NodeDependencyUpdater {
455
481
  .sort(semver.rcompare)[0];
456
482
  }
457
483
  /** What `d` declares in `field` once it has moved. */
484
+ /** Whether `line` names `token` (`name@version`) whole - not `1.2.3` inside `1.2.30`. */
485
+ mentions(line, token) {
486
+ const escaped = token.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
487
+ return new RegExp(`(^|[\\s"'(])${escaped}(?![\\w.+-])`).test(line);
488
+ }
458
489
  rangeFor(d, field) {
459
490
  const declared = d.fields.get(field) ?? '';
460
491
  if (d.index < 0 || !d.movable.includes(field))
@@ -18,6 +18,9 @@ export declare class NodeManifestProvider implements ManifestProvider {
18
18
  * that does not hold resolves its own way, which is why this is the provider's job.
19
19
  */
20
20
  dependencies(manifest: Manifest, candidates: readonly Package[]): Package[];
21
+ /** `dependencies`, `optionalDependencies` and the peers that are not optional - everything but
22
+ * what only a developer of the package installs. */
23
+ runtimeDependencies(manifest: Manifest, candidates: readonly Package[]): Package[];
21
24
  /** npm's `@scope/name`. A name with no `/` has no scope and is its own unscoped form; the
22
25
  * *last* `/` splits it, so `@scope/a/b` keeps `@scope/a` as the scope the registry would. */
23
26
  splitName(name: string): {
@@ -58,6 +58,26 @@ export class NodeManifestProvider {
58
58
  }
59
59
  return result;
60
60
  }
61
+ /** `dependencies`, `optionalDependencies` and the peers that are not optional - everything but
62
+ * what only a developer of the package installs. */
63
+ runtimeDependencies(manifest, candidates) {
64
+ const optionalPeers = this.optionalPeerNames(manifest);
65
+ const byName = new Map(candidates.map(p => [p.name, p]));
66
+ const result = [];
67
+ for (const key of ['dependencies', 'optionalDependencies', 'peerDependencies']) {
68
+ const declared = manifest.raw[key];
69
+ if (!declared || typeof declared !== 'object')
70
+ continue;
71
+ for (const name of Object.keys(declared)) {
72
+ if (key === 'peerDependencies' && optionalPeers.has(name))
73
+ continue;
74
+ const pkg = byName.get(name);
75
+ if (pkg && !result.includes(pkg))
76
+ result.push(pkg);
77
+ }
78
+ }
79
+ return result;
80
+ }
61
81
  /** npm's `@scope/name`. A name with no `/` has no scope and is its own unscoped form; the
62
82
  * *last* `/` splits it, so `@scope/a/b` keeps `@scope/a` as the scope the registry would. */
63
83
  splitName(name) {
@@ -16,8 +16,9 @@
16
16
  */
17
17
  import fs from 'node:fs';
18
18
  import path from 'node:path';
19
+ import { filesOwnedBy } from '../../../../utils/bundled-packages.js';
19
20
  import { exec } from '../../../../utils/exec.js';
20
- import { dirtyReason, filesUnder, GitHelper } from '../../../../utils/git.js';
21
+ import { dirtyReason, GitHelper } from '../../../../utils/git.js';
21
22
  import { filterPackages } from '../../../../utils/package-filter.js';
22
23
  import { isCalendarVersion } from '../../../../utils/release-version.js';
23
24
  import { npmViewPackage } from '../../../publish-targets/npm/npm-view.js';
@@ -197,7 +198,7 @@ export var PublishService;
197
198
  const git = new GitHelper({ cwd: repository.dirname });
198
199
  const packages = filterPackages(repository.getPackages({ toposort: true }), options).filter(pkg => options.shipsHere?.(pkg) ?? true);
199
200
  const dirtyFiles = await git.listDirtyFiles({ absolute: true });
200
- const isDirty = (pkg) => filesUnder(dirtyFiles, pkg.dirname).length > 0;
201
+ const isDirty = (pkg) => filesOwnedBy(dirtyFiles, pkg).length > 0;
201
202
  /** Per package, not per run: `resolveRegistry` reads the package's own `publishConfig.registry`
202
203
  * when `--registry` was not given, so the question is asked where the answer lives. The test
203
204
  * seam keeps its `(name, cwd)` shape - a stub answers from a map and has no registry to
@@ -250,7 +251,7 @@ export var PublishService;
250
251
  package: pkg,
251
252
  version: pkg.version,
252
253
  status: options.ignoreDirty ? 'skip' : 'error',
253
- reason: dirtyReason(filesUnder(dirtyFiles, pkg.dirname), repository.dirname),
254
+ reason: dirtyReason(filesOwnedBy(dirtyFiles, pkg), repository.dirname),
254
255
  });
255
256
  }
256
257
  else {
@@ -2,7 +2,8 @@ import fs from 'node:fs';
2
2
  import path from 'node:path';
3
3
  import { Service } from '../../../core/classes/service.js';
4
4
  import { targetsOf } from '../../../core/interfaces/publish-target.js';
5
- import { dirtyReason, filesUnder, GitHelper } from '../../../utils/git.js';
5
+ import { filesOwnedBy } from '../../../utils/bundled-packages.js';
6
+ import { dirtyReason, GitHelper } from '../../../utils/git.js';
6
7
  import { filterPackages } from '../../../utils/package-filter.js';
7
8
  import { runBin } from '../../../utils/run-bin.js';
8
9
  /** The name this target answers to in `publish.target` and `--target`. */
@@ -34,7 +35,7 @@ export class CloudflarePublishService extends Service {
34
35
  const git = new GitHelper({ cwd: repository.dirname });
35
36
  const packages = filterPackages(repository.getPackages({ toposort: true }), options).filter(pkg => targetsOf(this.app, pkg).some(t => t.name === CLOUDFLARE_TARGET) && !pkg.config.publish?.skip);
36
37
  const dirtyFiles = await git.listDirtyFiles({ absolute: true });
37
- const isDirty = (pkg) => filesUnder(dirtyFiles, pkg.dirname).length > 0;
38
+ const isDirty = (pkg) => filesOwnedBy(dirtyFiles, pkg).length > 0;
38
39
  const credentials = this.credentials();
39
40
  const isDeployed = deps.isDeployed ?? ((deploy) => this.isDeployed(deploy));
40
41
  return Promise.all(packages.map(async (pkg) => {
@@ -51,7 +52,7 @@ export class CloudflarePublishService extends Service {
51
52
  return {
52
53
  ...located,
53
54
  status: options.ignoreDirty ? 'skip' : 'error',
54
- reason: dirtyReason(filesUnder(dirtyFiles, pkg.dirname), repository.dirname),
55
+ reason: dirtyReason(filesOwnedBy(dirtyFiles, pkg), repository.dirname),
55
56
  };
56
57
  }
57
58
  if (!credentials) {
@@ -4,8 +4,9 @@ import path from 'node:path';
4
4
  import { promisify } from 'node:util';
5
5
  import { Service } from '../../../core/classes/service.js';
6
6
  import { targetsOf } from '../../../core/interfaces/publish-target.js';
7
+ import { filesOwnedBy } from '../../../utils/bundled-packages.js';
7
8
  import { exec } from '../../../utils/exec.js';
8
- import { dirtyReason, filesUnder, GitHelper } from '../../../utils/git.js';
9
+ import { dirtyReason, GitHelper } from '../../../utils/git.js';
9
10
  import { filterPackages } from '../../../utils/package-filter.js';
10
11
  import { isCalendarVersion } from '../../../utils/release-version.js';
11
12
  /**
@@ -43,7 +44,7 @@ export class DockerPublishService extends Service {
43
44
  * where a package ships. */
44
45
  const packages = filterPackages(repository.getPackages({ toposort: true }), options).filter(pkg => targetsOf(this.app, pkg).some(t => t.name === DOCKER_TARGET) && !pkg.config.publish?.skip);
45
46
  const dirtyFiles = await git.listDirtyFiles({ absolute: true });
46
- const isDirty = (pkg) => filesUnder(dirtyFiles, pkg.dirname).length > 0;
47
+ const isDirty = (pkg) => filesOwnedBy(dirtyFiles, pkg).length > 0;
47
48
  const imageExists = deps.imageExists ?? defaultImageExists;
48
49
  const entries = new Map();
49
50
  const toCheck = [];
@@ -73,7 +74,7 @@ export class DockerPublishService extends Service {
73
74
  image,
74
75
  detail: image,
75
76
  status: options.ignoreDirty ? 'skip' : 'error',
76
- reason: dirtyReason(filesUnder(dirtyFiles, pkg.dirname), repository.dirname),
77
+ reason: dirtyReason(filesOwnedBy(dirtyFiles, pkg), repository.dirname),
77
78
  });
78
79
  continue;
79
80
  }
@@ -115,10 +115,11 @@ const depsCommand = registerCommand(app => {
115
115
  for (const [updater, packages] of byUpdater)
116
116
  plans.set(updater, await updater.getPlan(ctx, packages));
117
117
  const all = [...plans.values()].flat();
118
- if (args.json)
119
- console.log(JSON.stringify(jsonPlan(all), undefined, 2));
120
- else
118
+ /** Under `-u --json` the document waits for the resolver, so it holds what was really written. */
119
+ if (!args.json)
121
120
  printPlan(all, repository.dirname);
121
+ else if (!args.upgrade)
122
+ console.log(JSON.stringify(jsonPlan(all), undefined, 2));
122
123
  const errors = all.filter(e => e.status === 'error');
123
124
  const updates = all.filter(e => e.status === 'update');
124
125
  if (!args.upgrade) {
@@ -128,23 +129,55 @@ const depsCommand = registerCommand(app => {
128
129
  throw logged(`${errors.length} dependency lookup(s) failed - see above.`);
129
130
  return;
130
131
  }
131
- const applied = [];
132
- for (const [updater, plan] of plans) {
132
+ const applied = new Map();
133
+ const apply = async (updater, plan) => {
133
134
  if (plan.some(e => e.status === 'update'))
134
- applied.push(await updater.applyPlan(ctx, plan));
135
- }
136
- const files = applied.flatMap(a => a.files);
137
- if (files.length && args.verify !== false) {
135
+ applied.set(updater, await updater.applyPlan(ctx, plan));
136
+ else
137
+ applied.delete(updater);
138
+ };
139
+ for (const [updater, plan] of plans)
140
+ await apply(updater, plan);
141
+ /* A refusal the updater can pin on some of the moves holds those back and asks again with the
142
+ * rest - each round holds at least one, so it ends. One it cannot pin puts everything back. */
143
+ const held = [];
144
+ if (applied.size && args.verify !== false) {
138
145
  for (const [updater, packages] of byUpdater) {
139
- const refused = await updater.verify?.(ctx, packages);
140
- if (!refused)
141
- continue;
142
- for (const a of applied)
143
- a.restore();
144
- throw logged(`The upgraded manifests do not install, so they were put back:\n${refused}`);
146
+ const plan = plans.get(updater);
147
+ while (applied.has(updater)) {
148
+ const refused = await updater.verify?.(ctx, packages);
149
+ if (!refused)
150
+ break;
151
+ const blamed = updater.blame?.(refused, plan).filter(b => b.entry.status === 'update') ?? [];
152
+ applied.get(updater).restore();
153
+ applied.delete(updater);
154
+ if (!blamed.length) {
155
+ for (const a of applied.values())
156
+ a.restore();
157
+ const shown = refused.split('\n');
158
+ const text = shown.slice(0, 40).join('\n') + (shown.length > 40 ? '\n ...' : '');
159
+ throw logged(`The upgraded manifests do not install, so they were put back:\n${text}`);
160
+ }
161
+ for (const b of blamed) {
162
+ Object.assign(b.entry, { status: 'held', target: undefined, bump: undefined, reason: b.reason });
163
+ held.push(b);
164
+ }
165
+ await apply(updater, plan);
166
+ }
145
167
  }
146
168
  }
147
- if (!args.json) {
169
+ const files = [...applied.values()].flatMap(a => a.files);
170
+ if (args.json)
171
+ console.log(JSON.stringify(jsonPlan(all), undefined, 2));
172
+ else {
173
+ if (held.length) {
174
+ console.log(colors.yellow('\nHeld back - the resolver refused them:'));
175
+ for (const { entry, reason } of held) {
176
+ console.log(` ${colors.cyan(entry.package.name)} ${entry.name} ${entry.current} ${colors.gray(reason)}`);
177
+ }
178
+ }
179
+ if (held.length && !files.length)
180
+ console.log(colors.yellow('Nothing upgraded.'));
148
181
  for (const file of files)
149
182
  console.log(colors.green('updated'), path.relative(repository.dirname, file));
150
183
  }
package/constants.js CHANGED
@@ -1 +1 @@
1
- export const version = '2.28.0';
1
+ export const version = '2.30.0';
@@ -20,6 +20,12 @@ export interface DependencyUpdater {
20
20
  * Omit it when the ecosystem has no resolver to ask; the plan's own checks then stand alone.
21
21
  */
22
22
  verify?(ctx: DependencyUpdater.Context, packages: readonly Package[]): Promise<string | undefined>;
23
+ /**
24
+ * The `'update'` entries of `plan` that `refusal` - what `verify` returned - is about, each with
25
+ * the reason to show for it. The command holds those back and tries the rest again; an empty
26
+ * answer, or none at all, puts every write back.
27
+ */
28
+ blame?(refusal: string, plan: readonly DependencyUpdater.Entry[]): DependencyUpdater.Blame[];
23
29
  }
24
30
  export declare namespace DependencyUpdater {
25
31
  /** What one call is handed. */
@@ -62,7 +68,7 @@ export declare namespace DependencyUpdater {
62
68
  *
63
69
  * - `'update'`: `target` is the new range; `reason` says why it is lower than `latest`, if it is.
64
70
  * - `'held'`: a newer version exists and is allowed, but another dependency's rule refuses it -
65
- * `reason` names that rule.
71
+ * `reason` names that rule - or, under `--upgrade`, the ecosystem's resolver refused it.
66
72
  * - `'skipped'`: a newer version exists, and the package's own settings leave it out - a major
67
73
  * under `target: minor`, or one younger than `minAge`. `reason` says which.
68
74
  * - `'up-to-date'`: nothing newer exists.
@@ -97,6 +103,11 @@ export declare namespace DependencyUpdater {
97
103
  bump?: string;
98
104
  reason?: string;
99
105
  }
106
+ /** One entry a resolver's refusal is about, and the reason to show for it. */
107
+ interface Blame {
108
+ entry: Entry;
109
+ reason: string;
110
+ }
100
111
  /** What `applyPlan` wrote. */
101
112
  interface Applied {
102
113
  /** Every file it changed, absolute. */
@@ -113,6 +113,14 @@ export interface ManifestProvider {
113
113
  * Omit it and a package has no declared dependencies beyond `.rmanrc "dependencies"`.
114
114
  */
115
115
  dependencies?(manifest: Manifest, candidates: readonly Package[]): Package[];
116
+ /**
117
+ * Which of `candidates` this package's artifact needs where it runs - what a consumer installs
118
+ * with it, or what an image built from it carries. A subset of `dependencies`: npm leaves out
119
+ * `devDependencies` and optional peers.
120
+ *
121
+ * Omit it and every dependency counts.
122
+ */
123
+ runtimeDependencies?(manifest: Manifest, candidates: readonly Package[]): Package[];
116
124
  /**
117
125
  * Splits a package name into the parts a config expression can ask for - `${{ pkg.scope }}` and
118
126
  * `${{ pkg.unscopedName }}`.
@@ -245,6 +253,9 @@ export declare namespace Manifest {
245
253
  * of can still describe its own graph by hand.
246
254
  */
247
255
  function dependenciesOf(pkg: Package, candidates: readonly Package[]): Package[];
256
+ /** The packages `pkg`'s artifact needs at run time - see `ManifestProvider.runtimeDependencies`.
257
+ * Every declared dependency when the provider has no opinion. */
258
+ function runtimeDependenciesOf(pkg: Package, candidates: readonly Package[]): Package[];
248
259
  /** `${{ pkg.scope }}`/`${{ pkg.unscopedName }}`, by whichever provider recognizes `dir` - and
249
260
  * "no scope, the name is its own unscoped form" when none has an opinion. */
250
261
  function splitName(app: RmanApplication, dir: string, name: string): {
@@ -67,6 +67,13 @@ export var Manifest;
67
67
  return platformOf(pkg)?.manifestProvider.dependencies?.(pkg.manifest, candidates) ?? [];
68
68
  }
69
69
  Manifest.dependenciesOf = dependenciesOf;
70
+ /** The packages `pkg`'s artifact needs at run time - see `ManifestProvider.runtimeDependencies`.
71
+ * Every declared dependency when the provider has no opinion. */
72
+ function runtimeDependenciesOf(pkg, candidates) {
73
+ const provider = platformOf(pkg)?.manifestProvider;
74
+ return (provider?.runtimeDependencies ?? provider?.dependencies)?.call(provider, pkg.manifest, candidates) ?? [];
75
+ }
76
+ Manifest.runtimeDependenciesOf = runtimeDependenciesOf;
70
77
  /** `${{ pkg.scope }}`/`${{ pkg.unscopedName }}`, by whichever provider recognizes `dir` - and
71
78
  * "no scope, the name is its own unscoped form" when none has an opinion. */
72
79
  function splitName(app, dir, name) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "rman",
3
3
  "description": "Repository manager",
4
- "version": "2.28.0",
4
+ "version": "2.30.0",
5
5
  "author": "Panates",
6
6
  "license": "MIT",
7
7
  "dependencies": {
@@ -1,6 +1,7 @@
1
1
  import fs from 'node:fs';
2
2
  import path from 'node:path';
3
3
  import { Service } from '../core/classes/service.js';
4
+ import { bundledPackages } from '../utils/bundled-packages.js';
4
5
  import { GitHelper } from '../utils/git.js';
5
6
  import { filterPackages } from '../utils/package-filter.js';
6
7
  import { groupKeyOf } from '../utils/version-group.js';
@@ -181,6 +182,10 @@ export class ChangelogService extends Service {
181
182
  * --changelog` and `github-release` see too, since both pass an explicit boundary.
182
183
  */
183
184
  const dirsAt = homesAt(homes, commitsByTarget[i]);
185
+ /** A member's commits include those of the unversioned packages it carries - the same rule
186
+ * `version` bumps by (`bundledPackages`), or a release would be cut for a change its notes
187
+ * never mention. */
188
+ const owns = new Set([...group.members].flatMap(m => [m, ...bundledPackages(m)]));
184
189
  const floor = await resolveStartingPoint(git, pkg, options);
185
190
  const floorIndex = floor?.sha ? commitsByTarget[i].findIndex(c => c.sha === floor.sha) : -1;
186
191
  const withUnreleased = resolveUnreleased(pkg, options);
@@ -193,7 +198,7 @@ export class ChangelogService extends Service {
193
198
  continue;
194
199
  /** A commit belongs to a group when it belongs to **any** of its members - one line for a
195
200
  * commit touching two of them, which is the whole reason a group shares a file. */
196
- const ownCommits = dropVersionBumps(segment.commits).filter(c => [...ownersOf(repository, c, dirsAt(c))].some(owner => group.members.has(owner)));
201
+ const ownCommits = dropVersionBumps(segment.commits).filter(c => [...ownersOf(repository, c, dirsAt(c))].some(owner => owns.has(owner)));
197
202
  if (!ownCommits.length)
198
203
  continue;
199
204
  const sections = groupCommits(ownCommits, ignoreTypesConfig(pkg), titles, order, withCommitHash(pkg, options));
@@ -72,9 +72,9 @@ export declare abstract class VersionPlanService {
72
72
  */
73
73
  getPlan(repository: Repository, options?: VersionPlanService.Options): Promise<VersionPlanService.Entry[]>;
74
74
  /**
75
- * Why `pkg` takes no version at all, or `undefined` when it does: `.rmanrc "version.skip"` when
76
- * it says so, and otherwise whether it has been kept out of publishing - `publish.skip`, or every
77
- * target that ships it leaving it out (npm's `private`).
75
+ * Why `pkg` takes no version at all, or `undefined` when it does - `unversionedReason`'s answer,
76
+ * kept `protected` so a planner can override it. A package this answers for is also one whose
77
+ * commits count toward the published packages that carry it (`bundledPackages`).
78
78
  */
79
79
  protected notVersionedReason(pkg: Package): string | undefined;
80
80
  /**
@@ -2,7 +2,7 @@ import path from 'node:path';
2
2
  import { RmanApplication } from '../core/application.js';
3
3
  import { assertOneScheme, semverScheme, VersionScheme } from '../core/classes/version-scheme.js';
4
4
  import { Manifest } from '../core/interfaces/manifest.js';
5
- import { skipReasonFor, targetsOf } from '../core/interfaces/publish-target.js';
5
+ import { bundledPackages, unversionedReason } from '../utils/bundled-packages.js';
6
6
  import { dirtyReason, filesUnder, GitHelper } from '../utils/git.js';
7
7
  import { filterPackages } from '../utils/package-filter.js';
8
8
  import { findLastReleaseVersion, formatCalendarVersion, usesCalendarVersion } from '../utils/release-version.js';
@@ -98,9 +98,14 @@ export class VersionPlanService {
98
98
  }
99
99
  const git = new GitHelper({ cwd: repository.dirname });
100
100
  const packages = filterPackages(repository.getPackages(), options);
101
+ /** Each package with the unversioned packages it carries - see `bundledPackages`. Their files
102
+ * are the package's own for every question below: commits, and a dirty tree. */
103
+ const carried = new Map(packages.map(pkg => [pkg, bundledPackages(pkg, p => !!this.notVersionedReason(p))]));
104
+ const homesOf = (pkg) => [pkg, ...(carried.get(pkg) ?? [])].map(p => p.dirname);
101
105
  const dirtyFiles = await git.listDirtyFiles({ absolute: true });
102
- const isDirty = (pkg) => filesUnder(dirtyFiles, pkg.dirname).length > 0;
103
- const dirtyReasonOf = (pkg) => dirtyReason(filesUnder(dirtyFiles, pkg.dirname), repository.dirname);
106
+ const dirtyOf = (pkg) => [...new Set(homesOf(pkg).flatMap(dir => filesUnder(dirtyFiles, dir)))];
107
+ const isDirty = (pkg) => dirtyOf(pkg).length > 0;
108
+ const dirtyReasonOf = (pkg) => dirtyReason(dirtyOf(pkg), repository.dirname);
104
109
  const dirty = packages.filter(isDirty);
105
110
  const entries = new Map();
106
111
  /**
@@ -163,13 +168,19 @@ export class VersionPlanService {
163
168
  }
164
169
  const since = await this.plannerFor(pkg).detectBoundary(git, pkg, options);
165
170
  const commits = since ? await git.listCommits({ hash: since }) : await git.listAllCommits();
166
- const belongsToPkg = (c) => c.files.some(f => !path.relative(pkg.dirname, f).startsWith('..'));
171
+ const homes = homesOf(pkg);
172
+ const under = (dir, f) => !path.relative(dir, f).startsWith('..');
173
+ const belongsToPkg = (c) => c.files.some(f => homes.some(dir => under(dir, f)));
167
174
  const real = commits.filter(c => belongsToPkg(c) && !ConventionalCommitsService.isReleaseCommit(c.subject, commitMessage));
168
175
  if (!real.length)
169
176
  return;
177
+ /** Named when a carried package is all that changed, or part of it - the one thing that
178
+ * explains a bump with no commit under the package's own directory. */
179
+ const via = (carried.get(pkg) ?? []).filter(dep => real.some(c => c.files.some(f => under(dep.dirname, f))));
180
+ const base = since ? `changed since ${since}` : 'unreleased commits';
170
181
  changeByPackage.set(pkg.name, {
171
182
  bump: explicitBump ?? this.detectBump(real, pkg.versionScheme),
172
- reason: since ? `changed since ${since}` : 'unreleased commits',
183
+ reason: via.length ? `${base} (via ${via.map(d => d.name).join(', ')})` : base,
173
184
  });
174
185
  }));
175
186
  const groups = new Map();
@@ -218,44 +229,12 @@ export class VersionPlanService {
218
229
  return result;
219
230
  }
220
231
  /**
221
- * Why `pkg` takes no version at all, or `undefined` when it does: `.rmanrc "version.skip"` when
222
- * it says so, and otherwise whether it has been kept out of publishing - `publish.skip`, or every
223
- * target that ships it leaving it out (npm's `private`).
232
+ * Why `pkg` takes no version at all, or `undefined` when it does - `unversionedReason`'s answer,
233
+ * kept `protected` so a planner can override it. A package this answers for is also one whose
234
+ * commits count toward the published packages that carry it (`bundledPackages`).
224
235
  */
225
- /* **A version nothing publishes is a number nobody can install**, and that is the user's reason
226
- * for reversing the old rule that `version` never reads `publish.skip`. Measured on
227
- * `panates/syncbridge`: fourteen packages kept out of publishing were still bumped, tagged and
228
- * written into changelogs on every release - tags with nothing on the registry behind them, and a
229
- * version line that had jumped by the time publishing was switched back on.
230
- *
231
- * `version.skip` decides first, both ways: `true` holds back a package that does publish, `false`
232
- * versions one that does not - an application deployed by other means, whose number still
233
- * matters. A monorepo's root never reaches here; its version is the repository's release
234
- * identity, decided by `buildRootEntry`.
235
- *
236
- * **A package no target ships to is still versioned**, deliberately. Tried the other way first,
237
- * and it stopped versioning every package of a repository that has no publish target at all - one
238
- * that versions with rman and publishes by other means, or a technology rman has no target for -
239
- * which is most of the core's own spec fixtures. Only a package kept out *on purpose* is left
240
- * out. */
241
236
  notVersionedReason(pkg) {
242
- const declared = pkg.config.version?.skip;
243
- if (declared === true)
244
- return 'excluded via .rmanrc "version.skip"';
245
- if (declared === false)
246
- return undefined;
247
- if (pkg.config.publish?.skip)
248
- return 'not published - .rmanrc "publish.skip"';
249
- const app = pkg.repository?.app;
250
- if (!app)
251
- return undefined;
252
- const targets = targetsOf(app, pkg);
253
- if (!targets.length)
254
- return undefined;
255
- const reasons = targets.map(target => skipReasonFor(pkg, target));
256
- if (reasons.every(Boolean))
257
- return `not published - ${reasons[0]}`;
258
- return undefined;
237
+ return unversionedReason(pkg);
259
238
  }
260
239
  /**
261
240
  * **Which planner answers for one package: its own technology's.**
@@ -0,0 +1,22 @@
1
+ import type { Package } from '../core/classes/package.js';
2
+ /**
3
+ * Why `pkg` takes no version at all, or `undefined` when it does: `.rmanrc "version.skip"` when it
4
+ * says so, and otherwise whether it has been kept out of publishing - `publish.skip`, or every
5
+ * target that ships it leaving it out (npm's `private`).
6
+ */
7
+ export declare function unversionedReason(pkg: Package): string | undefined;
8
+ /**
9
+ * The in-repo packages whose commits count as `pkg`'s own: those it needs at run time that take no
10
+ * version themselves, and theirs in turn - a versioned one stops the walk, since it releases on its
11
+ * own and reaches `pkg` through the ordinary cascade. Empty for a package that is itself not
12
+ * versioned.
13
+ *
14
+ * `isUnversioned` is the planner's answer when one is asking; `unversionedReason` otherwise.
15
+ */
16
+ export declare function bundledPackages(pkg: Package, isUnversioned?: (p: Package) => boolean): Package[];
17
+ /**
18
+ * The files of `files` that are `pkg`'s - under its own directory or under one of the packages it
19
+ * carries (`bundledPackages`). What every "is this package dirty" check asks, so an artifact is
20
+ * never built from a carried package's uncommitted changes.
21
+ */
22
+ export declare function filesOwnedBy(files: readonly string[], pkg: Package): string[];
@@ -0,0 +1,91 @@
1
+ import { Manifest } from '../core/interfaces/manifest.js';
2
+ import { skipReasonFor, targetsOf } from '../core/interfaces/publish-target.js';
3
+ import { filesUnder } from './git.js';
4
+ /**
5
+ * Why `pkg` takes no version at all, or `undefined` when it does: `.rmanrc "version.skip"` when it
6
+ * says so, and otherwise whether it has been kept out of publishing - `publish.skip`, or every
7
+ * target that ships it leaving it out (npm's `private`).
8
+ */
9
+ /* **A version nothing publishes is a number nobody can install**, and that is the user's reason
10
+ * for reversing the old rule that `version` never reads `publish.skip`. Measured on
11
+ * `panates/syncbridge`: fourteen packages kept out of publishing were still bumped, tagged and
12
+ * written into changelogs on every release - tags with nothing on the registry behind them, and a
13
+ * version line that had jumped by the time publishing was switched back on.
14
+ *
15
+ * `version.skip` decides first, both ways: `true` holds back a package that does publish, `false`
16
+ * versions one that does not - an application deployed by other means, whose number still
17
+ * matters. A monorepo's root never reaches here; its version is the repository's release
18
+ * identity, decided by `buildRootEntry`.
19
+ *
20
+ * **A package no target ships to is still versioned**, deliberately. Tried the other way first,
21
+ * and it stopped versioning every package of a repository that has no publish target at all - one
22
+ * that versions with rman and publishes by other means, or a technology rman has no target for -
23
+ * which is most of the core's own spec fixtures. Only a package kept out *on purpose* is left
24
+ * out.
25
+ *
26
+ * **Here rather than on `VersionPlanService`**, which delegates to it, because `ChangelogService`
27
+ * asks the same question through `bundledPackages` and must work in a repository with no planner -
28
+ * the `groupKeyOf` arrangement. */
29
+ export function unversionedReason(pkg) {
30
+ const declared = pkg.config.version?.skip;
31
+ if (declared === true)
32
+ return 'excluded via .rmanrc "version.skip"';
33
+ if (declared === false)
34
+ return undefined;
35
+ if (pkg.config.publish?.skip)
36
+ return 'not published - .rmanrc "publish.skip"';
37
+ const app = pkg.repository?.app;
38
+ if (!app)
39
+ return undefined;
40
+ const targets = targetsOf(app, pkg);
41
+ if (!targets.length)
42
+ return undefined;
43
+ const reasons = targets.map(target => skipReasonFor(pkg, target));
44
+ if (reasons.every(Boolean))
45
+ return `not published - ${reasons[0]}`;
46
+ return undefined;
47
+ }
48
+ /**
49
+ * The in-repo packages whose commits count as `pkg`'s own: those it needs at run time that take no
50
+ * version themselves, and theirs in turn - a versioned one stops the walk, since it releases on its
51
+ * own and reaches `pkg` through the ordinary cascade. Empty for a package that is itself not
52
+ * versioned.
53
+ *
54
+ * `isUnversioned` is the planner's answer when one is asking; `unversionedReason` otherwise.
55
+ */
56
+ /* **Asked for on `panates/syncbridge-cloud`**: the server ships as a Docker image built from four
57
+ * workspace packages that are `publish.skip`, so take no version. A fix to one of them changed the
58
+ * image and left the server `no-change` - the four were out of the plan before any commit was read,
59
+ * and a commit counted only for the package whose directory held its files. A package kept out of
60
+ * publishing that a published one needs at run time can reach anyone only inside that published
61
+ * package's artifact, so a change to it *is* a change to the artifact.
62
+ *
63
+ * **Run-time edges only** (`Manifest.runtimeDependenciesOf`): a test helper kept out of publishing
64
+ * that a library lists under `devDependencies` would otherwise release the library on every change
65
+ * to it. */
66
+ export function bundledPackages(pkg, isUnversioned = p => !!unversionedReason(p)) {
67
+ const repository = pkg.repository;
68
+ if (!repository || isUnversioned(pkg))
69
+ return [];
70
+ const candidates = repository.packages;
71
+ const result = [];
72
+ const visit = (from) => {
73
+ for (const dep of Manifest.runtimeDependenciesOf(from, candidates)) {
74
+ if (dep === pkg || result.includes(dep) || !isUnversioned(dep))
75
+ continue;
76
+ result.push(dep);
77
+ visit(dep);
78
+ }
79
+ };
80
+ visit(pkg);
81
+ return result;
82
+ }
83
+ /**
84
+ * The files of `files` that are `pkg`'s - under its own directory or under one of the packages it
85
+ * carries (`bundledPackages`). What every "is this package dirty" check asks, so an artifact is
86
+ * never built from a carried package's uncommitted changes.
87
+ */
88
+ export function filesOwnedBy(files, pkg) {
89
+ const dirs = [pkg, ...bundledPackages(pkg)].map(p => p.dirname);
90
+ return [...new Set(dirs.flatMap(dir => filesUnder(files, dir)))];
91
+ }