rman 2.33.0 → 2.35.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/builtins/platforms/node/augmentation/system-info.augmentation.js +17 -1
- package/builtins/platforms/node/commands/ci.command.js +1 -1
- package/builtins/platforms/node/node-dependency-updater.d.ts +24 -5
- package/builtins/platforms/node/node-dependency-updater.js +74 -20
- package/builtins/platforms/node/services/ci.service.d.ts +8 -1
- package/builtins/platforms/node/services/ci.service.js +67 -2
- package/builtins/publish-targets/npm/npm-publish-target.js +1 -1
- package/constants.js +1 -1
- package/package.json +1 -1
|
@@ -47,7 +47,10 @@ export function augmentSystemInfo() {
|
|
|
47
47
|
const configured = options?.repository?.config?.packageManager;
|
|
48
48
|
if (typeof configured === 'string')
|
|
49
49
|
CiService.resolvePackageManager(options.repository);
|
|
50
|
-
const packageManager = options?.packageManager ??
|
|
50
|
+
const packageManager = options?.packageManager ??
|
|
51
|
+
asPackageManager(configured?.node) ??
|
|
52
|
+
detected(options?.repository) ??
|
|
53
|
+
'npm';
|
|
51
54
|
return base({
|
|
52
55
|
...options,
|
|
53
56
|
envinfo: {
|
|
@@ -80,6 +83,19 @@ function asPackageManager(value) {
|
|
|
80
83
|
? value
|
|
81
84
|
: undefined;
|
|
82
85
|
}
|
|
86
|
+
/** The package manager the repository's lockfile names, as `ci` and `publish` would read it. */
|
|
87
|
+
/* **A lockfile pair `ci` would refuse reads as no answer here**: `info` is what someone runs to find
|
|
88
|
+
* out what is wrong, so it must not be the command that stops on it - `ci` names the files. */
|
|
89
|
+
function detected(repository) {
|
|
90
|
+
if (!repository)
|
|
91
|
+
return undefined;
|
|
92
|
+
try {
|
|
93
|
+
return CiService.detectPackageManager(repository);
|
|
94
|
+
}
|
|
95
|
+
catch {
|
|
96
|
+
return undefined;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
83
99
|
/** Marks an implementation as already wrapped. A symbol rather than a property name so it cannot
|
|
84
100
|
* collide with anything `envinfo` or a future core option carries. */
|
|
85
101
|
const AUGMENTED = Symbol.for('rman.node.systemInfo.augmented');
|
|
@@ -12,7 +12,7 @@ const config = {
|
|
|
12
12
|
packageManager: {
|
|
13
13
|
target: 'cli',
|
|
14
14
|
cliName: 'package-manager',
|
|
15
|
-
describe: 'Package manager to install with (default:
|
|
15
|
+
describe: 'Package manager to install with (default: .rmanrc "packageManager.node", else the lockfile\'s, else npm)',
|
|
16
16
|
choices: CiService.PACKAGE_MANAGERS,
|
|
17
17
|
},
|
|
18
18
|
progress: {
|
|
@@ -5,9 +5,10 @@ import { type NpmRelease, type NpmReleases } from '../../publish-targets/npm/npm
|
|
|
5
5
|
* npm's answer to `rman deps`: which of a `package.json`'s dependencies have a newer version on the
|
|
6
6
|
* registry, and which of those can be taken without breaking a rule another dependency states.
|
|
7
7
|
*
|
|
8
|
-
* Only a caret or tilde range on a plain version moves (`^1.2.3`, `~1.2.3`), keeping its prefix
|
|
9
|
-
*
|
|
10
|
-
*
|
|
8
|
+
* Only a caret or tilde range on a plain version moves (`^1.2.3`, `~1.2.3`), keeping its prefix -
|
|
9
|
+
* an npm alias of one too (`npm:@scope/real@^1.2.3`), asked about under the package it names. An
|
|
10
|
+
* exact version, a compound range (`>=1 <2`, `a || b`), a dist-tag, a URL and an in-repo package
|
|
11
|
+
* are left as they are - but every one of them still counts as a rule the others must keep.
|
|
11
12
|
*/
|
|
12
13
|
export declare class NodeDependencyUpdater implements DependencyUpdater {
|
|
13
14
|
/** `.rmanrc "deps.types"`'s short spellings, as `npm-check-updates` named them. The field names
|
|
@@ -90,10 +91,22 @@ export declare class NodeDependencyUpdater implements DependencyUpdater {
|
|
|
90
91
|
/** The newest release `d`'s declarations already allow - what an install picks if `d` does not
|
|
91
92
|
* move. */
|
|
92
93
|
protected resolvedDeclared(d: NodeDependencyUpdater.Decision): string | undefined;
|
|
93
|
-
/** What `d` declares in `field` once it has moved. */
|
|
94
94
|
/** Whether `line` names `token` (`name@version`) whole - not `1.2.3` inside `1.2.30`. */
|
|
95
95
|
protected mentions(line: string, token: string): boolean;
|
|
96
|
+
/** What `d` declares in `field` once it has moved - the range alone, an alias's `npm:<name>@`
|
|
97
|
+
* left off, which is what every rule compares. */
|
|
96
98
|
protected rangeFor(d: NodeDependencyUpdater.Decision, field: string): string;
|
|
99
|
+
/** The name `d`'s versions are asked under - the package an alias names, else its own. */
|
|
100
|
+
protected sourceOf(d: NodeDependencyUpdater.Decision): string;
|
|
101
|
+
/** What `field` holds once `d` has moved, as the manifest spells it - an alias keeps its
|
|
102
|
+
* `npm:<name>@`. */
|
|
103
|
+
protected writtenFor(d: NodeDependencyUpdater.Decision, field: string): string;
|
|
104
|
+
/** `npm:<name>@<range>`, npm's alias form, as the package it names and the range - or `undefined`
|
|
105
|
+
* for anything else. */
|
|
106
|
+
protected aliasOf(value: string): {
|
|
107
|
+
source: string;
|
|
108
|
+
range: string;
|
|
109
|
+
} | undefined;
|
|
97
110
|
/** The in-repo packages `pkg` declares a dependency on. */
|
|
98
111
|
protected siblingsOf(pkg: Package, repoPackages: ReadonlyMap<string, Package>): Package[];
|
|
99
112
|
protected toEntry(d: NodeDependencyUpdater.Decision): DependencyUpdater.Entry;
|
|
@@ -116,8 +129,14 @@ export declare namespace NodeDependencyUpdater {
|
|
|
116
129
|
pkg: Package;
|
|
117
130
|
name: string;
|
|
118
131
|
settings: DependencyUpdater.Settings;
|
|
119
|
-
/** Every field declaring the name, and its range there
|
|
132
|
+
/** Every field declaring the name, and its range there - an alias's range, its `npm:<name>@`
|
|
133
|
+
* kept in `aliases`. */
|
|
120
134
|
fields: Map<string, string>;
|
|
135
|
+
/** The fields declaring the name as an npm alias, and the `npm:<name>@` they write in front. */
|
|
136
|
+
aliases: Map<string, string>;
|
|
137
|
+
/** The package an alias names, whose versions every field of this name is held to - an alias
|
|
138
|
+
* is what installs, so a plain peer range beside it is satisfied by that package. */
|
|
139
|
+
source?: string;
|
|
121
140
|
/** The fields whose range is rewritten. */
|
|
122
141
|
movable: string[];
|
|
123
142
|
/** The fields holding a valid range rman does not rewrite - a pinned version, `>=a <b`. */
|
|
@@ -14,10 +14,17 @@ import { parseWorkspaceRange } from './utils/workspace-range.js';
|
|
|
14
14
|
* npm's answer to `rman deps`: which of a `package.json`'s dependencies have a newer version on the
|
|
15
15
|
* registry, and which of those can be taken without breaking a rule another dependency states.
|
|
16
16
|
*
|
|
17
|
-
* Only a caret or tilde range on a plain version moves (`^1.2.3`, `~1.2.3`), keeping its prefix
|
|
18
|
-
*
|
|
19
|
-
*
|
|
17
|
+
* Only a caret or tilde range on a plain version moves (`^1.2.3`, `~1.2.3`), keeping its prefix -
|
|
18
|
+
* an npm alias of one too (`npm:@scope/real@^1.2.3`), asked about under the package it names. An
|
|
19
|
+
* exact version, a compound range (`>=1 <2`, `a || b`), a dist-tag, a URL and an in-repo package
|
|
20
|
+
* are left as they are - but every one of them still counts as a rule the others must keep.
|
|
20
21
|
*/
|
|
22
|
+
/* **Aliases were skipped outright, and silently**: `npm:...` is no semver range, so the field was
|
|
23
|
+
* neither moved nor listed. Measured on `abisena/syncbridge-iomt`, whose host modules are a peer
|
|
24
|
+
* `"@syncbridge/hl7": "^2.0.0"` beside a dev `"npm:@sbext/syncbridge__hl7@^2.0.0"` from a mirror:
|
|
25
|
+
* the alias never appeared, and the peer was asked of npmjs.org under its own name, which stops at
|
|
26
|
+
* 1.2.1 - so a 2.1.0 on the mirror would have read "up to date". The alias is what installs, so the
|
|
27
|
+
* whole name is held to the package it names, and the peer moves with it. */
|
|
21
28
|
/* **The default is the policy every `.ncurc.yml` in this organization wrote by hand.** Twenty
|
|
22
29
|
* repositories carried the same `rejectVersion: "/(\|\|)|(&&)|>|<|^[0-9]/"` - no `||`, no `&&`, no
|
|
23
30
|
* comparator, no bare version - which leaves exactly a `^` or `~` range. Built in, it is a line
|
|
@@ -62,7 +69,7 @@ export class NodeDependencyUpdater {
|
|
|
62
69
|
const withTime = decisions.some(d => d.settings.minAge > 0);
|
|
63
70
|
const registry = await this.fetchAll(ctx, decisions, withTime);
|
|
64
71
|
for (const d of decisions)
|
|
65
|
-
this.prepare(d, registry.get(d
|
|
72
|
+
this.prepare(d, registry.get(this.sourceOf(d)));
|
|
66
73
|
this.resolve(decisions, ctx);
|
|
67
74
|
return decisions
|
|
68
75
|
.filter(d => d.wanted || d.unmovable)
|
|
@@ -87,8 +94,8 @@ export class NodeDependencyUpdater {
|
|
|
87
94
|
if (!originals.has(d.pkg))
|
|
88
95
|
originals.set(d.pkg, fs.readFileSync(this.manifestFile(d.pkg), 'utf-8'));
|
|
89
96
|
for (const field of d.movable) {
|
|
90
|
-
|
|
91
|
-
|
|
97
|
+
d.pkg.manifest.raw[field][d.name] =
|
|
98
|
+
(d.aliases.get(field) ?? '') + this.movablePattern.exec(d.fields.get(field))[1] + version;
|
|
92
99
|
}
|
|
93
100
|
}
|
|
94
101
|
for (const pkg of originals.keys())
|
|
@@ -142,21 +149,39 @@ export class NodeDependencyUpdater {
|
|
|
142
149
|
* tree around it. The `Could not resolve dependency:` line is npm's own verdict - measured on the
|
|
143
150
|
* `@hookform/resolvers` case it reads `peerOptional effect@"^4.0.0" from @hookform/resolvers@6.0.0`
|
|
144
151
|
* - 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.
|
|
152
|
+
* sat past the 20 lines `verify` used to keep, which is why it now keeps them all.
|
|
153
|
+
*
|
|
154
|
+
* **The range form is the other name npm uses**, and missing it misattributed the hold: measured on
|
|
155
|
+
* `abisena/syncbridge-iomt`, the verdict read `dev @syncbridge/syncbuild@"^2.2.0" from the root
|
|
156
|
+
* project`, matched nothing, and every move the output mentioned anywhere was held under that one
|
|
157
|
+
* line - `@syncbridge/testing` included, with syncbuild's reason. */
|
|
146
158
|
blame(refusal, plan) {
|
|
147
159
|
const moves = plan.flatMap(entry => {
|
|
148
160
|
const d = this.planned.get(entry);
|
|
149
|
-
|
|
161
|
+
if (entry.status !== 'update' || !d)
|
|
162
|
+
return [];
|
|
163
|
+
/** npm names a move two ways: at the version it resolved (`from x@2.2.0`) and as the range a
|
|
164
|
+
* manifest declares (`dev x@"^2.2.0" from the root project`). */
|
|
165
|
+
const tokens = [
|
|
166
|
+
`${d.name}@${d.candidates[d.index]}`,
|
|
167
|
+
...d.movable.map(f => `${d.name}@"${this.writtenFor(d, f)}"`),
|
|
168
|
+
];
|
|
169
|
+
return [{ entry, tokens }];
|
|
150
170
|
});
|
|
171
|
+
const names = (line, m) => m.tokens.some(t => this.mentions(line, t));
|
|
151
172
|
const lines = refusal.split('\n').map(line => line.trim());
|
|
152
173
|
const at = lines.indexOf('Could not resolve dependency:');
|
|
153
174
|
const verdict = at >= 0 ? lines.slice(at + 1).find(Boolean) : undefined;
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
175
|
+
/** What it conflicts with, when npm says - the half of the verdict that explains it. */
|
|
176
|
+
const conflict = lines.find(l => l.startsWith('Conflicting peer dependency:'));
|
|
177
|
+
const named = verdict ? moves.filter(m => names(verdict, m)) : [];
|
|
178
|
+
if (named.length) {
|
|
179
|
+
const reason = `npm cannot install it: ${verdict}${conflict ? ` - ${conflict}` : ''}`;
|
|
180
|
+
return named.map(m => ({ entry: m.entry, reason }));
|
|
181
|
+
}
|
|
157
182
|
return moves.flatMap(m => {
|
|
158
|
-
const line = lines.find(l =>
|
|
159
|
-
return line ? [{ entry: m.entry, reason: `npm cannot install it: ${
|
|
183
|
+
const line = lines.find(l => names(l, m));
|
|
184
|
+
return line ? [{ entry: m.entry, reason: `npm cannot install it: ${line}` }] : [];
|
|
160
185
|
});
|
|
161
186
|
}
|
|
162
187
|
/** One decision per dependency name `pkg` declares, whether or not it may move - one that may not
|
|
@@ -168,8 +193,8 @@ export class NodeDependencyUpdater {
|
|
|
168
193
|
const declared = pkg.manifest.raw[field];
|
|
169
194
|
if (!declared || typeof declared !== 'object')
|
|
170
195
|
continue;
|
|
171
|
-
for (const [name,
|
|
172
|
-
if (typeof
|
|
196
|
+
for (const [name, value] of Object.entries(declared)) {
|
|
197
|
+
if (typeof value !== 'string' || inRepo.has(name) || parseWorkspaceRange(value))
|
|
173
198
|
continue;
|
|
174
199
|
let d = byName.get(name);
|
|
175
200
|
if (!d) {
|
|
@@ -178,6 +203,7 @@ export class NodeDependencyUpdater {
|
|
|
178
203
|
name,
|
|
179
204
|
settings,
|
|
180
205
|
fields: new Map(),
|
|
206
|
+
aliases: new Map(),
|
|
181
207
|
movable: [],
|
|
182
208
|
fixed: [],
|
|
183
209
|
wanted: false,
|
|
@@ -187,6 +213,17 @@ export class NodeDependencyUpdater {
|
|
|
187
213
|
};
|
|
188
214
|
byName.set(name, d);
|
|
189
215
|
}
|
|
216
|
+
/** An alias is the range of the package it names: its versions are that package's, so the
|
|
217
|
+
* rules compare the range and the rewrite keeps the `npm:<name>@` in front. */
|
|
218
|
+
/** Two fields aliasing one name to different packages have no one version list to share -
|
|
219
|
+
* the second is left as written, which no rule moves. */
|
|
220
|
+
const parsed = this.aliasOf(value);
|
|
221
|
+
const alias = parsed && (!d.source || d.source === parsed.source) ? parsed : undefined;
|
|
222
|
+
if (alias) {
|
|
223
|
+
d.source = alias.source;
|
|
224
|
+
d.aliases.set(field, `npm:${alias.source}@`);
|
|
225
|
+
}
|
|
226
|
+
const range = alias ? alias.range : value;
|
|
190
227
|
d.fields.set(field, range);
|
|
191
228
|
if (kinds && !kinds.includes(field))
|
|
192
229
|
continue;
|
|
@@ -212,13 +249,14 @@ export class NodeDependencyUpdater {
|
|
|
212
249
|
async fetchAll(ctx, decisions, withTime) {
|
|
213
250
|
const floors = new Map();
|
|
214
251
|
for (const d of decisions) {
|
|
252
|
+
const source = this.sourceOf(d);
|
|
215
253
|
for (const range of d.fields.values()) {
|
|
216
254
|
const min = semver.validRange(range) ? semver.minVersion(range)?.version : undefined;
|
|
217
255
|
if (!min)
|
|
218
256
|
continue;
|
|
219
|
-
const known = floors.get(
|
|
257
|
+
const known = floors.get(source);
|
|
220
258
|
if (!known || semver.lt(min, known))
|
|
221
|
-
floors.set(
|
|
259
|
+
floors.set(source, min);
|
|
222
260
|
}
|
|
223
261
|
}
|
|
224
262
|
const names = [...floors.keys()];
|
|
@@ -480,18 +518,34 @@ export class NodeDependencyUpdater {
|
|
|
480
518
|
.filter(v => ranges.every(r => semver.satisfies(v, r)))
|
|
481
519
|
.sort(semver.rcompare)[0];
|
|
482
520
|
}
|
|
483
|
-
/** What `d` declares in `field` once it has moved. */
|
|
484
521
|
/** Whether `line` names `token` (`name@version`) whole - not `1.2.3` inside `1.2.30`. */
|
|
485
522
|
mentions(line, token) {
|
|
486
523
|
const escaped = token.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
487
524
|
return new RegExp(`(^|[\\s"'(])${escaped}(?![\\w.+-])`).test(line);
|
|
488
525
|
}
|
|
526
|
+
/** What `d` declares in `field` once it has moved - the range alone, an alias's `npm:<name>@`
|
|
527
|
+
* left off, which is what every rule compares. */
|
|
489
528
|
rangeFor(d, field) {
|
|
490
529
|
const declared = d.fields.get(field) ?? '';
|
|
491
530
|
if (d.index < 0 || !d.movable.includes(field))
|
|
492
531
|
return declared;
|
|
493
532
|
return this.movablePattern.exec(declared)[1] + d.candidates[d.index];
|
|
494
533
|
}
|
|
534
|
+
/** The name `d`'s versions are asked under - the package an alias names, else its own. */
|
|
535
|
+
sourceOf(d) {
|
|
536
|
+
return d.source ?? d.name;
|
|
537
|
+
}
|
|
538
|
+
/** What `field` holds once `d` has moved, as the manifest spells it - an alias keeps its
|
|
539
|
+
* `npm:<name>@`. */
|
|
540
|
+
writtenFor(d, field) {
|
|
541
|
+
return (d.aliases.get(field) ?? '') + this.rangeFor(d, field);
|
|
542
|
+
}
|
|
543
|
+
/** `npm:<name>@<range>`, npm's alias form, as the package it names and the range - or `undefined`
|
|
544
|
+
* for anything else. */
|
|
545
|
+
aliasOf(value) {
|
|
546
|
+
const match = /^npm:((?:@[^/@\s]+\/)?[^@\s]+)@(.+)$/.exec(value);
|
|
547
|
+
return match ? { source: match[1], range: match[2] } : undefined;
|
|
548
|
+
}
|
|
495
549
|
/** The in-repo packages `pkg` declares a dependency on. */
|
|
496
550
|
siblingsOf(pkg, repoPackages) {
|
|
497
551
|
const result = new Set();
|
|
@@ -522,7 +576,7 @@ export class NodeDependencyUpdater {
|
|
|
522
576
|
package: d.pkg,
|
|
523
577
|
name: d.name,
|
|
524
578
|
types: [...d.fields.keys()],
|
|
525
|
-
current: d.fields.get(d.movable[0]),
|
|
579
|
+
current: (d.aliases.get(d.movable[0]) ?? '') + d.fields.get(d.movable[0]),
|
|
526
580
|
status: 'up-to-date',
|
|
527
581
|
latest: d.allowed[0],
|
|
528
582
|
available: d.available,
|
|
@@ -539,7 +593,7 @@ export class NodeDependencyUpdater {
|
|
|
539
593
|
const result = {
|
|
540
594
|
...entry,
|
|
541
595
|
status: 'update',
|
|
542
|
-
target: this.
|
|
596
|
+
target: this.writtenFor(d, d.movable[0]),
|
|
543
597
|
bump: this.sizeOf(d.floor, version),
|
|
544
598
|
/** What stopped it short of `available`, if anything did - another rule first, since that is
|
|
545
599
|
* the nearer reason. */
|
|
@@ -24,9 +24,16 @@ export declare namespace CiService {
|
|
|
24
24
|
}
|
|
25
25
|
/**
|
|
26
26
|
* The package manager `pkg` uses: `cliValue` when given, else its `.rmanrc "packageManager.node"`,
|
|
27
|
-
* else
|
|
27
|
+
* else the one its lockfile belongs to (`detectPackageManager`), else `npm`. Pass the repository
|
|
28
|
+
* for the one the repository installs with.
|
|
28
29
|
*/
|
|
29
30
|
function resolvePackageManager(pkg: Package, cliValue?: PackageManager): PackageManager;
|
|
31
|
+
/**
|
|
32
|
+
* The package manager whose lockfile sits nearest `pkg` - its own directory, then each one above
|
|
33
|
+
* it up to the repository root - or `undefined` when there is none. Throws when the nearest
|
|
34
|
+
* directory holding a lockfile holds two package managers' lockfiles, naming them.
|
|
35
|
+
*/
|
|
36
|
+
function detectPackageManager(pkg: Package): PackageManager | undefined;
|
|
30
37
|
/** Deletes `node_modules` and any known lockfile directly under `dirname`. Returns the names
|
|
31
38
|
* that actually existed (and were removed), so the caller can log only those. */
|
|
32
39
|
function wipe(dirname: string): Promise<string[]>;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
1
2
|
import fs from 'node:fs/promises';
|
|
2
3
|
import path from 'node:path';
|
|
3
4
|
import colors from 'ansi-colors';
|
|
@@ -18,7 +19,8 @@ export var CiService;
|
|
|
18
19
|
CiService.PACKAGE_MANAGERS = ['npm', 'yarn', 'pnpm', 'bun'];
|
|
19
20
|
/**
|
|
20
21
|
* The package manager `pkg` uses: `cliValue` when given, else its `.rmanrc "packageManager.node"`,
|
|
21
|
-
* else
|
|
22
|
+
* else the one its lockfile belongs to (`detectPackageManager`), else `npm`. Pass the repository
|
|
23
|
+
* for the one the repository installs with.
|
|
22
24
|
*/
|
|
23
25
|
/* **The bare string is refused rather than read.** `packageManager: pnpm` was the old spelling,
|
|
24
26
|
* and rman validates no config keys, so read as an object it would simply have no `node` entry -
|
|
@@ -34,12 +36,47 @@ export var CiService;
|
|
|
34
36
|
}
|
|
35
37
|
const node = configured?.node;
|
|
36
38
|
if (node === undefined)
|
|
37
|
-
return 'npm';
|
|
39
|
+
return detectPackageManager(pkg) ?? 'npm';
|
|
38
40
|
if (typeof node === 'string' && CiService.PACKAGE_MANAGERS.includes(node))
|
|
39
41
|
return node;
|
|
40
42
|
throw new Error(`Invalid "packageManager.node" in .rmanrc: "${String(node)}" (expected one of: ${CiService.PACKAGE_MANAGERS.join(', ')})`);
|
|
41
43
|
}
|
|
42
44
|
CiService.resolvePackageManager = resolvePackageManager;
|
|
45
|
+
/**
|
|
46
|
+
* The package manager whose lockfile sits nearest `pkg` - its own directory, then each one above
|
|
47
|
+
* it up to the repository root - or `undefined` when there is none. Throws when the nearest
|
|
48
|
+
* directory holding a lockfile holds two package managers' lockfiles, naming them.
|
|
49
|
+
*/
|
|
50
|
+
/* **The lockfile, not `package.json#packageManager`.** The lockfile is what the last install
|
|
51
|
+
* actually wrote; the field is a declaration nothing checks, and it goes stale. Measured on this
|
|
52
|
+
* repository: its root `package.json` says `yarn@3.4.1` and it has only ever installed with npm
|
|
53
|
+
* (`package-lock.json`, no `yarn.lock`) - read first, the field would have sent `rman ci` to yarn.
|
|
54
|
+
*
|
|
55
|
+
* **Two managers in one directory is refused, not ranked.** Any order picks a tool on the
|
|
56
|
+
* repository's behalf, and the wrong pick is silent: `ci` wipes every lockfile before it installs,
|
|
57
|
+
* so the one it guessed against is gone and the next run sees only what it wrote. The fix is one
|
|
58
|
+
* line of config, and the message says which.
|
|
59
|
+
*
|
|
60
|
+
* **Nearest, not root-only**: a package installing on its own keeps its lockfile beside its own
|
|
61
|
+
* `package.json`, and the walk stops at the repository root so a checkout nested inside another
|
|
62
|
+
* project never answers with the outer one's tool. */
|
|
63
|
+
function detectPackageManager(pkg) {
|
|
64
|
+
if (!pkg.dirname)
|
|
65
|
+
return undefined;
|
|
66
|
+
for (const dir of lockfileDirs(pkg)) {
|
|
67
|
+
const found = Object.keys(LOCKFILE_MANAGERS).filter(name => existsSync(path.join(dir, name)));
|
|
68
|
+
if (!found.length)
|
|
69
|
+
continue;
|
|
70
|
+
const managers = [...new Set(found.map(name => LOCKFILE_MANAGERS[name]))];
|
|
71
|
+
if (managers.length === 1)
|
|
72
|
+
return managers[0];
|
|
73
|
+
throw new Error(`Cannot tell which package manager ${dir} uses: it holds lockfiles of ${managers.join(' and ')} ` +
|
|
74
|
+
`(${found.join(', ')}). Delete the stale one, or say which in .rmanrc: ` +
|
|
75
|
+
`packageManager: { node: ${managers.join(' | ')} }.`);
|
|
76
|
+
}
|
|
77
|
+
return undefined;
|
|
78
|
+
}
|
|
79
|
+
CiService.detectPackageManager = detectPackageManager;
|
|
43
80
|
/** Deletes `node_modules` and any known lockfile directly under `dirname`. Returns the names
|
|
44
81
|
* that actually existed (and were removed), so the caller can log only those. */
|
|
45
82
|
async function wipe(dirname) {
|
|
@@ -129,6 +166,34 @@ export var CiService;
|
|
|
129
166
|
CiService.reinstall = reinstall;
|
|
130
167
|
})(CiService || (CiService = {}));
|
|
131
168
|
const LOCK_FILES = ['package-lock.json', 'yarn.lock', 'pnpm-lock.yaml', 'bun.lock', 'bun.lockb'];
|
|
169
|
+
/** Which package manager each lockfile belongs to, for `detectPackageManager`. */
|
|
170
|
+
/* `npm-shrinkwrap.json` is here and not in `LOCK_FILES`: it says npm as surely as a
|
|
171
|
+
* `package-lock.json` does, but it is published with the package, so `ci` has no business deleting
|
|
172
|
+
* it. */
|
|
173
|
+
const LOCKFILE_MANAGERS = {
|
|
174
|
+
'package-lock.json': 'npm',
|
|
175
|
+
'npm-shrinkwrap.json': 'npm',
|
|
176
|
+
'yarn.lock': 'yarn',
|
|
177
|
+
'pnpm-lock.yaml': 'pnpm',
|
|
178
|
+
'bun.lock': 'bun',
|
|
179
|
+
'bun.lockb': 'bun',
|
|
180
|
+
};
|
|
181
|
+
/** `pkg`'s own directory, then each one above it, ending at the repository root - only `pkg`'s own
|
|
182
|
+
* when it has no repository or does not sit inside it. */
|
|
183
|
+
function lockfileDirs(pkg) {
|
|
184
|
+
const root = pkg.repository?.dirname;
|
|
185
|
+
const dirs = [pkg.dirname];
|
|
186
|
+
if (!root || path.relative(root, pkg.dirname).startsWith('..'))
|
|
187
|
+
return dirs;
|
|
188
|
+
let dir = pkg.dirname;
|
|
189
|
+
while (dir !== root) {
|
|
190
|
+
const parent = path.dirname(dir);
|
|
191
|
+
if (parent === dir)
|
|
192
|
+
break;
|
|
193
|
+
dirs.push((dir = parent));
|
|
194
|
+
}
|
|
195
|
+
return dirs;
|
|
196
|
+
}
|
|
132
197
|
/** Runs a shell `command` in `cwd`, driving `item` for the live panel when it's on, or falling
|
|
133
198
|
* back to the plain "classic" log line `logLine` prints first - the same split `run`'s classic
|
|
134
199
|
* log uses. `logLine` is expected to go through a `Logger` (so it respects `--log-level`), not a
|
|
@@ -32,7 +32,7 @@ export class NpmPublishTarget {
|
|
|
32
32
|
packageManager: {
|
|
33
33
|
target: 'cli',
|
|
34
34
|
cliName: 'package-manager',
|
|
35
|
-
describe: 'Package manager to publish with (default: .rmanrc "packageManager.node", else npm)',
|
|
35
|
+
describe: 'Package manager to publish with (default: .rmanrc "packageManager.node", else the lockfile\'s, else npm)',
|
|
36
36
|
choices: CiService.PACKAGE_MANAGERS,
|
|
37
37
|
},
|
|
38
38
|
access: {
|
package/constants.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '2.
|
|
1
|
+
export const version = '2.35.0';
|