rman 2.34.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/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: {
|
|
@@ -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';
|