@antasphere/cli-core 0.6.0 → 0.7.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/README.md +324 -96
- package/dist/auth.d.ts +1 -1
- package/dist/auth.d.ts.map +1 -1
- package/dist/config.d.ts +120 -73
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +207 -109
- package/dist/config.js.map +1 -1
- package/dist/connect-on-demand.d.ts +194 -132
- package/dist/connect-on-demand.d.ts.map +1 -1
- package/dist/connect-on-demand.js +561 -148
- package/dist/connect-on-demand.js.map +1 -1
- package/dist/connect.d.ts +8 -8
- package/dist/connect.d.ts.map +1 -1
- package/dist/index.d.ts +25 -17
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +20 -15
- package/dist/index.js.map +1 -1
- package/dist/kept-keys.d.ts +208 -0
- package/dist/kept-keys.d.ts.map +1 -0
- package/dist/kept-keys.js +484 -0
- package/dist/kept-keys.js.map +1 -0
- package/dist/lock.d.ts +65 -0
- package/dist/lock.d.ts.map +1 -0
- package/dist/lock.js +408 -0
- package/dist/lock.js.map +1 -0
- package/dist/migrate.d.ts +9 -3
- package/dist/migrate.d.ts.map +1 -1
- package/dist/migrate.js +32 -11
- package/dist/migrate.js.map +1 -1
- package/dist/resolve.d.ts +12 -4
- package/dist/resolve.d.ts.map +1 -1
- package/dist/resolve.js +12 -8
- package/dist/resolve.js.map +1 -1
- package/dist/sign-in.d.ts +266 -0
- package/dist/sign-in.d.ts.map +1 -0
- package/dist/sign-in.js +398 -0
- package/dist/sign-in.js.map +1 -0
- package/package.json +1 -1
- package/src/auth.ts +1 -1
- package/src/config.ts +303 -158
- package/src/connect-on-demand.ts +797 -271
- package/src/connect.ts +8 -8
- package/src/index.ts +40 -27
- package/src/kept-keys.ts +561 -0
- package/src/lock.ts +479 -0
- package/src/migrate.ts +33 -11
- package/src/resolve.ts +20 -15
- package/src/sign-in.ts +601 -0
package/dist/lock.js
ADDED
|
@@ -0,0 +1,408 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import { closeSync, fstatSync, linkSync, lstatSync, mkdirSync, openSync, readdirSync, readFileSync, renameSync, unlinkSync, writeFileSync } from 'node:fs';
|
|
3
|
+
import { hostname } from 'node:os';
|
|
4
|
+
import { basename, dirname, join, resolve } from 'node:path';
|
|
5
|
+
import { setTimeout as delay } from 'node:timers/promises';
|
|
6
|
+
import { CliConfigError } from './config.js';
|
|
7
|
+
/** A marker older than this is a dead taker's, whoever it names: a take-over lasts a few calls. */
|
|
8
|
+
const BREAK_STALE_MS = 10_000;
|
|
9
|
+
/** How many takers of one dead lock may die in turn before a waiter waits as on a live holder. */
|
|
10
|
+
const MAX_TAKERS = 64;
|
|
11
|
+
/** The lock paths this process holds, with their nesting depth. */
|
|
12
|
+
const held = new Map();
|
|
13
|
+
const pause = new Int32Array(new SharedArrayBuffer(4));
|
|
14
|
+
/** Block this thread for `ms` milliseconds: the waits of a synchronous API. */
|
|
15
|
+
export function sleepSync(ms) {
|
|
16
|
+
Atomics.wait(pause, 0, 0, ms);
|
|
17
|
+
}
|
|
18
|
+
/** The `code` of a Node system error (`ENOENT`, `EEXIST`, …), if it has one. */
|
|
19
|
+
export function errorCode(e) {
|
|
20
|
+
if (typeof e !== 'object' || e === null || !('code' in e))
|
|
21
|
+
return undefined;
|
|
22
|
+
return typeof e.code === 'string' ? e.code : undefined;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Run `fn` holding the lock file `lockPath`, created when free, waited on
|
|
26
|
+
* while a live holder has it, taken over when its holder is dead, and
|
|
27
|
+
* released when `fn` returns or throws. Re-entrant within one process: a
|
|
28
|
+
* nested call on a path this process holds runs `fn` at once. `fn` is
|
|
29
|
+
* synchronous; the lock is released as soon as it returns.
|
|
30
|
+
*/
|
|
31
|
+
export function withFileLock(lockPath, fn, opts = {}) {
|
|
32
|
+
const key = resolve(lockPath);
|
|
33
|
+
const depth = held.get(key);
|
|
34
|
+
if (depth !== undefined) {
|
|
35
|
+
held.set(key, depth + 1);
|
|
36
|
+
try {
|
|
37
|
+
return fn();
|
|
38
|
+
}
|
|
39
|
+
finally {
|
|
40
|
+
held.set(key, depth);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
const token = acquire(lockPath, opts);
|
|
44
|
+
held.set(key, 1);
|
|
45
|
+
try {
|
|
46
|
+
return fn();
|
|
47
|
+
}
|
|
48
|
+
finally {
|
|
49
|
+
held.delete(key);
|
|
50
|
+
release(lockPath, token);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Run the asynchronous `fn` holding the lock file `lockPath`: the protocol of
|
|
55
|
+
* `withFileLock` (created when free, waited on while a live holder has it,
|
|
56
|
+
* taken over when its holder is dead, released by token when `fn` settles),
|
|
57
|
+
* with the waits awaited, so the lock may span network calls. NOT re-entrant:
|
|
58
|
+
* two calls of one process on one path take turns like two processes, and a
|
|
59
|
+
* nested call on a path this call holds waits for itself until `timeoutMs`.
|
|
60
|
+
*/
|
|
61
|
+
export async function withFileLockAsync(lockPath, fn, opts = {}) {
|
|
62
|
+
const wait = startWait(opts);
|
|
63
|
+
for (;;) {
|
|
64
|
+
const step = attempt(lockPath, wait);
|
|
65
|
+
if (step === 'acquired')
|
|
66
|
+
break;
|
|
67
|
+
if (step === 'again')
|
|
68
|
+
continue;
|
|
69
|
+
if (Date.now() >= wait.deadline)
|
|
70
|
+
throw lockedError(lockPath, step.holder);
|
|
71
|
+
await delay(wait.backoff);
|
|
72
|
+
wait.backoff = Math.min(wait.backoff * 2, 50);
|
|
73
|
+
}
|
|
74
|
+
try {
|
|
75
|
+
return await fn();
|
|
76
|
+
}
|
|
77
|
+
finally {
|
|
78
|
+
release(lockPath, wait.token);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
function startWait(opts) {
|
|
82
|
+
return {
|
|
83
|
+
host: hostname(),
|
|
84
|
+
token: randomUUID(),
|
|
85
|
+
deadline: Date.now() + (opts.timeoutMs ?? 10_000),
|
|
86
|
+
staleMs: opts.staleMs ?? 30_000,
|
|
87
|
+
emptyStaleMs: opts.emptyStaleMs ?? 2_000,
|
|
88
|
+
backoff: 10
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
/** What a lock or a marker of this process holds. */
|
|
92
|
+
function holderText(host, token) {
|
|
93
|
+
const holder = { pid: process.pid, host, token, at: new Date().toISOString() };
|
|
94
|
+
return JSON.stringify(holder);
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* One try at the lock: `acquired`; `again` when it is worth trying again at
|
|
98
|
+
* once (it was released between our try and our look, a dead holder's lock
|
|
99
|
+
* was moved out of the way, or a taker's marker went meanwhile); otherwise
|
|
100
|
+
* the live lock to wait on.
|
|
101
|
+
*/
|
|
102
|
+
function attempt(lockPath, wait) {
|
|
103
|
+
if (create(lockPath, holderText(wait.host, wait.token))) {
|
|
104
|
+
sweep(lockPath, wait.staleMs);
|
|
105
|
+
return 'acquired';
|
|
106
|
+
}
|
|
107
|
+
const seen = look(lockPath);
|
|
108
|
+
if (!seen)
|
|
109
|
+
return 'again';
|
|
110
|
+
if (!isStale(seen, wait.host, wait.staleMs, wait.emptyStaleMs))
|
|
111
|
+
return seen;
|
|
112
|
+
return takeOver(lockPath, seen, wait);
|
|
113
|
+
}
|
|
114
|
+
function acquire(lockPath, opts) {
|
|
115
|
+
const wait = startWait(opts);
|
|
116
|
+
for (;;) {
|
|
117
|
+
const step = attempt(lockPath, wait);
|
|
118
|
+
if (step === 'acquired')
|
|
119
|
+
return wait.token;
|
|
120
|
+
if (step === 'again')
|
|
121
|
+
continue;
|
|
122
|
+
if (Date.now() >= wait.deadline)
|
|
123
|
+
throw lockedError(lockPath, step.holder);
|
|
124
|
+
sleepSync(wait.backoff);
|
|
125
|
+
wait.backoff = Math.min(wait.backoff * 2, 50);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
/** Create the lock (or a marker) exclusively and write its holder; false when it already exists. */
|
|
129
|
+
function create(path, content) {
|
|
130
|
+
let fd;
|
|
131
|
+
try {
|
|
132
|
+
fd = openSync(path, 'wx', 0o600);
|
|
133
|
+
}
|
|
134
|
+
catch (e) {
|
|
135
|
+
const code = errorCode(e);
|
|
136
|
+
if (code === 'EEXIST')
|
|
137
|
+
return false;
|
|
138
|
+
if (code !== 'ENOENT')
|
|
139
|
+
throw e;
|
|
140
|
+
// The directory is not there yet: make it, as every write does.
|
|
141
|
+
mkdirSync(dirname(path), { recursive: true, mode: 0o700 });
|
|
142
|
+
try {
|
|
143
|
+
fd = openSync(path, 'wx', 0o600);
|
|
144
|
+
}
|
|
145
|
+
catch (again) {
|
|
146
|
+
if (errorCode(again) === 'EEXIST')
|
|
147
|
+
return false;
|
|
148
|
+
throw again;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
try {
|
|
152
|
+
writeFileSync(fd, content);
|
|
153
|
+
}
|
|
154
|
+
catch (e) {
|
|
155
|
+
// An empty lock of ours would hold everyone for `emptyStaleMs`.
|
|
156
|
+
closeSync(fd);
|
|
157
|
+
try {
|
|
158
|
+
unlinkSync(path);
|
|
159
|
+
}
|
|
160
|
+
catch {
|
|
161
|
+
// The write's own error is the one to report.
|
|
162
|
+
}
|
|
163
|
+
throw e;
|
|
164
|
+
}
|
|
165
|
+
closeSync(fd);
|
|
166
|
+
return true;
|
|
167
|
+
}
|
|
168
|
+
function identityOf(stats) {
|
|
169
|
+
return { dev: stats.dev, ino: stats.ino, mtimeNs: stats.mtimeNs };
|
|
170
|
+
}
|
|
171
|
+
/** Whether two looks saw one file: the same device, the same inode, the same mtime. */
|
|
172
|
+
function sameFile(a, b) {
|
|
173
|
+
return a.dev === b.dev && a.ino === b.ino && a.mtimeNs === b.mtimeNs;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Look at someone else's lock (or marker) through ONE descriptor: the
|
|
177
|
+
* file's identity and its bytes come from the same file, whatever happens to
|
|
178
|
+
* the path meanwhile. Undefined when it is gone (just released).
|
|
179
|
+
*/
|
|
180
|
+
function look(path) {
|
|
181
|
+
let fd;
|
|
182
|
+
try {
|
|
183
|
+
fd = openSync(path, 'r');
|
|
184
|
+
}
|
|
185
|
+
catch (e) {
|
|
186
|
+
if (errorCode(e) === 'ENOENT')
|
|
187
|
+
return undefined;
|
|
188
|
+
throw e;
|
|
189
|
+
}
|
|
190
|
+
try {
|
|
191
|
+
const stats = fstatSync(fd, { bigint: true });
|
|
192
|
+
const raw = readFileSync(fd);
|
|
193
|
+
return {
|
|
194
|
+
...identityOf(stats),
|
|
195
|
+
mtimeMs: Number(stats.mtimeMs),
|
|
196
|
+
raw,
|
|
197
|
+
holder: parseHolder(raw.toString('utf8'))
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
finally {
|
|
201
|
+
closeSync(fd);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
/** The holder a lock names, or undefined when it does not parse into one (empty, partial, foreign). */
|
|
205
|
+
function parseHolder(text) {
|
|
206
|
+
let value;
|
|
207
|
+
try {
|
|
208
|
+
value = JSON.parse(text);
|
|
209
|
+
}
|
|
210
|
+
catch {
|
|
211
|
+
return undefined;
|
|
212
|
+
}
|
|
213
|
+
if (typeof value !== 'object' || value === null)
|
|
214
|
+
return undefined;
|
|
215
|
+
const { pid, host, token, at } = value;
|
|
216
|
+
if (typeof pid !== 'number' || !Number.isInteger(pid) || pid <= 0)
|
|
217
|
+
return undefined;
|
|
218
|
+
if (typeof host !== 'string' || typeof token !== 'string' || typeof at !== 'string')
|
|
219
|
+
return undefined;
|
|
220
|
+
return { pid, host, token, at };
|
|
221
|
+
}
|
|
222
|
+
function isStale(seen, host, staleMs, emptyStaleMs) {
|
|
223
|
+
const age = Date.now() - seen.mtimeMs;
|
|
224
|
+
if (age > staleMs)
|
|
225
|
+
return true;
|
|
226
|
+
if (!seen.holder)
|
|
227
|
+
return age > emptyStaleMs;
|
|
228
|
+
return seen.holder.host === host && !pidAlive(seen.holder.pid);
|
|
229
|
+
}
|
|
230
|
+
/** A pid is alive when signal 0 reaches it, or reaches a process we may not signal (EPERM). */
|
|
231
|
+
function pidAlive(pid) {
|
|
232
|
+
try {
|
|
233
|
+
process.kill(pid, 0);
|
|
234
|
+
return true;
|
|
235
|
+
}
|
|
236
|
+
catch (e) {
|
|
237
|
+
return errorCode(e) === 'EPERM';
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Take over the lock judged stale on the look `seen`, one taker at a time:
|
|
242
|
+
* the takers of that file take turns through markers named for it (its
|
|
243
|
+
* device and inode, not its mtime: a lock created empty and written later
|
|
244
|
+
* keeps its inode) and for their turn, `<lockPath>.break.<dev>-<ino>.<n>`.
|
|
245
|
+
* Holding the marker of its turn, a taker looks at the lock again and moves
|
|
246
|
+
* it aside only while it is still the very file judged, and still stale on a
|
|
247
|
+
* fresh judgement. A live taker's marker is waited on; a dead taker's is left
|
|
248
|
+
* where it is, and the next turn tried. Answers `again` when the acquire is
|
|
249
|
+
* worth trying again at once (the lock is gone or was removed, or a marker
|
|
250
|
+
* went meanwhile), or the lock to wait on (a live taker holds a turn, every
|
|
251
|
+
* turn is a dead taker's, the lock is another file now or no longer stale,
|
|
252
|
+
* or a moved file was put back).
|
|
253
|
+
*/
|
|
254
|
+
function takeOver(lockPath, seen, wait) {
|
|
255
|
+
for (let n = 0; n < MAX_TAKERS; n += 1) {
|
|
256
|
+
const marker = `${lockPath}.break.${seen.dev}-${seen.ino}.${n}`;
|
|
257
|
+
const token = randomUUID();
|
|
258
|
+
if (create(marker, holderText(wait.host, token))) {
|
|
259
|
+
try {
|
|
260
|
+
const now = look(lockPath);
|
|
261
|
+
if (!now)
|
|
262
|
+
return 'again';
|
|
263
|
+
if (!sameFile(now, seen) || !isStale(now, wait.host, wait.staleMs, wait.emptyStaleMs))
|
|
264
|
+
return now;
|
|
265
|
+
const moved = moveAside(lockPath, now);
|
|
266
|
+
if (moved === 'removed' || moved === 'gone')
|
|
267
|
+
return 'again';
|
|
268
|
+
return look(lockPath) ?? 'again';
|
|
269
|
+
}
|
|
270
|
+
finally {
|
|
271
|
+
release(marker, token);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
const taker = look(marker);
|
|
275
|
+
if (!taker)
|
|
276
|
+
return 'again';
|
|
277
|
+
// A live taker younger than 10 s is waited on like any holder. A dead taker's marker is never
|
|
278
|
+
// moved: it stays where it is, and the next turn is tried.
|
|
279
|
+
if (!isStale(taker, wait.host, BREAK_STALE_MS, wait.emptyStaleMs))
|
|
280
|
+
return seen;
|
|
281
|
+
}
|
|
282
|
+
return seen;
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* Move a lock judged dead (`judged`, the look it was judged on) out of the
|
|
286
|
+
* way: renamed to `<path>.<ms>.<uuid>.stale` (the time of the move in its
|
|
287
|
+
* name), then removed only when the moved file is that very file (the same
|
|
288
|
+
* device, inode and mtime). Any other file moved by mistake is put back.
|
|
289
|
+
* Answers `removed`, `gone` (nothing was there to move), `restored` (put
|
|
290
|
+
* back), or `left` (it could not be put back).
|
|
291
|
+
*/
|
|
292
|
+
function moveAside(path, judged) {
|
|
293
|
+
const moved = `${path}.${Date.now()}.${randomUUID()}.stale`;
|
|
294
|
+
try {
|
|
295
|
+
renameSync(path, moved);
|
|
296
|
+
}
|
|
297
|
+
catch (e) {
|
|
298
|
+
if (errorCode(e) === 'ENOENT')
|
|
299
|
+
return 'gone';
|
|
300
|
+
throw e;
|
|
301
|
+
}
|
|
302
|
+
if (sameFile(identityOf(lstatSync(moved, { bigint: true })), judged)) {
|
|
303
|
+
unlinkSync(moved);
|
|
304
|
+
return 'removed';
|
|
305
|
+
}
|
|
306
|
+
try {
|
|
307
|
+
linkSync(moved, path);
|
|
308
|
+
}
|
|
309
|
+
catch (e) {
|
|
310
|
+
if (errorCode(e) !== 'EEXIST')
|
|
311
|
+
throw e;
|
|
312
|
+
// Another file took the path meanwhile, so the moved one cannot go back, and it may be a live
|
|
313
|
+
// holder's: it is never unlinked here, it stays where it is (`<path>.<ms>.<uuid>.stale`) until a
|
|
314
|
+
// later holder sweeps it, once older than `staleMs`. The path can only change under a taker that
|
|
315
|
+
// holds its marker when a holder judged dead by age was in fact alive: the lock's (older than
|
|
316
|
+
// `staleMs`, or empty and older than `emptyStaleMs`), letting go in between, or another taker's
|
|
317
|
+
// (its marker older than 10 s), still taking the lock over.
|
|
318
|
+
return 'left';
|
|
319
|
+
}
|
|
320
|
+
// Back in place: the moved name is a second link to the same file, and goes.
|
|
321
|
+
unlinkSync(moved);
|
|
322
|
+
return 'restored';
|
|
323
|
+
}
|
|
324
|
+
/** A take-over marker, after `<lock>.`: `break.<dev>-<ino>.<n>`. */
|
|
325
|
+
const MARKER_NAME = /^break\.\d+-\d+\.\d+$/;
|
|
326
|
+
/** A lock moved aside, after `<lock>.`: `<ms>.<uuid>.stale`, the time of the move in its name. */
|
|
327
|
+
const MOVED_NAME = /^(\d+)\.[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\.stale$/;
|
|
328
|
+
/**
|
|
329
|
+
* Remove what take-overs left beside the lock just acquired, once it is older
|
|
330
|
+
* than `staleMs` (the age at which any lock is a dead holder's), never
|
|
331
|
+
* younger: the markers (`<lock>.break.<dev>-<ino>.<n>`, aged by their mtime:
|
|
332
|
+
* a marker is written once, at its creation) and the locks moved aside
|
|
333
|
+
* (`<lock>.<ms>.<uuid>.stale`, aged by the time in their name: a moved file
|
|
334
|
+
* keeps the mtime of the lock it was). Removing a marker is safe here: the
|
|
335
|
+
* sweeper holds the lock, so every marker beside it is of a lock that is
|
|
336
|
+
* gone. Nothing else is ever removed, and nothing here throws: a directory
|
|
337
|
+
* that cannot be read, an entry gone meanwhile or one that cannot be removed
|
|
338
|
+
* is skipped, and the next holder looks again.
|
|
339
|
+
*/
|
|
340
|
+
function sweep(lockPath, staleMs) {
|
|
341
|
+
const dir = dirname(lockPath);
|
|
342
|
+
const prefix = `${basename(lockPath)}.`;
|
|
343
|
+
let names;
|
|
344
|
+
try {
|
|
345
|
+
names = readdirSync(dir);
|
|
346
|
+
}
|
|
347
|
+
catch {
|
|
348
|
+
return;
|
|
349
|
+
}
|
|
350
|
+
const now = Date.now();
|
|
351
|
+
for (const name of names) {
|
|
352
|
+
if (!name.startsWith(prefix))
|
|
353
|
+
continue;
|
|
354
|
+
const rest = name.slice(prefix.length);
|
|
355
|
+
const path = join(dir, name);
|
|
356
|
+
let at;
|
|
357
|
+
if (MARKER_NAME.test(rest)) {
|
|
358
|
+
try {
|
|
359
|
+
at = lstatSync(path).mtimeMs;
|
|
360
|
+
}
|
|
361
|
+
catch {
|
|
362
|
+
continue;
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
else {
|
|
366
|
+
const moved = MOVED_NAME.exec(rest);
|
|
367
|
+
if (!moved)
|
|
368
|
+
continue;
|
|
369
|
+
at = Number(moved[1]);
|
|
370
|
+
}
|
|
371
|
+
if (!(now - at > staleMs))
|
|
372
|
+
continue;
|
|
373
|
+
try {
|
|
374
|
+
unlinkSync(path);
|
|
375
|
+
}
|
|
376
|
+
catch {
|
|
377
|
+
// Gone meanwhile, or not an entry this holder can remove: the next holder looks again.
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
/** Remove a lock (or a marker) only while it still holds our token; one already gone is fine. */
|
|
382
|
+
function release(path, token) {
|
|
383
|
+
let text;
|
|
384
|
+
try {
|
|
385
|
+
text = readFileSync(path, 'utf8');
|
|
386
|
+
}
|
|
387
|
+
catch (e) {
|
|
388
|
+
if (errorCode(e) === 'ENOENT')
|
|
389
|
+
return;
|
|
390
|
+
throw e;
|
|
391
|
+
}
|
|
392
|
+
if (parseHolder(text)?.token !== token)
|
|
393
|
+
return;
|
|
394
|
+
try {
|
|
395
|
+
unlinkSync(path);
|
|
396
|
+
}
|
|
397
|
+
catch (e) {
|
|
398
|
+
if (errorCode(e) !== 'ENOENT')
|
|
399
|
+
throw e;
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
function lockedError(lockPath, holder) {
|
|
403
|
+
const file = lockPath.replace(/\.lock$/, '');
|
|
404
|
+
const by = holder ? `process ${holder.pid} on ${holder.host} since ${holder.at}` : 'an unknown process';
|
|
405
|
+
return new CliConfigError(`The config file ${file} is locked by ${by} (${lockPath}). If no command of this CLI is running, ` +
|
|
406
|
+
'delete that lock file, then retry.');
|
|
407
|
+
}
|
|
408
|
+
//# sourceMappingURL=lock.js.map
|
package/dist/lock.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lock.js","sourceRoot":"","sources":["../src/lock.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EACL,SAAS,EACT,SAAS,EACT,QAAQ,EACR,SAAS,EACT,SAAS,EACT,QAAQ,EACR,WAAW,EACX,YAAY,EACZ,UAAU,EACV,UAAU,EACV,aAAa,EAEd,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC7D,OAAO,EAAE,UAAU,IAAI,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAsE7C,mGAAmG;AACnG,MAAM,cAAc,GAAG,MAAM,CAAC;AAE9B,kGAAkG;AAClG,MAAM,UAAU,GAAG,EAAE,CAAC;AAEtB,mEAAmE;AACnE,MAAM,IAAI,GAAG,IAAI,GAAG,EAAkB,CAAC;AAEvC,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,IAAI,iBAAiB,CAAC,CAAC,CAAC,CAAC,CAAC;AAEvD,+EAA+E;AAC/E,MAAM,UAAU,SAAS,CAAC,EAAU;IAClC,OAAO,CAAC,IAA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,CAAC;YACP,uFAAuF;QACzF,CAAC;IACH,CAAC;AACH,CAAC;AAED,iGAAiG;AACjG,SAAS,OAAO,CAAC,IAAY,EAAE,KAAa;IAC1C,IAAI,IAAY,CAAC;IACjB,IAAI,CAAC;QACH,IAAI,GAAG,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IACpC,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,IAAI,SAAS,CAAC,CAAC,CAAC,KAAK,QAAQ;YAAE,OAAO;QACtC,MAAM,CAAC,CAAC;IACV,CAAC;IACD,IAAI,WAAW,CAAC,IAAI,CAAC,EAAE,KAAK,KAAK,KAAK;QAAE,OAAO;IAC/C,IAAI,CAAC;QACH,UAAU,CAAC,IAAI,CAAC,CAAC;IACnB,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,IAAI,SAAS,CAAC,CAAC,CAAC,KAAK,QAAQ;YAAE,MAAM,CAAC,CAAC;IACzC,CAAC;AACH,CAAC;AAED,SAAS,WAAW,CAAC,QAAgB,EAAE,MAA0B;IAC/D,MAAM,IAAI,GAAG,QAAQ,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC;IAC7C,MAAM,EAAE,GAAG,MAAM,CAAC,CAAC,CAAC,WAAW,MAAM,CAAC,GAAG,OAAO,MAAM,CAAC,IAAI,UAAU,MAAM,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,oBAAoB,CAAC;IACxG,OAAO,IAAI,cAAc,CACvB,mBAAmB,IAAI,iBAAiB,EAAE,KAAK,QAAQ,2CAA2C;QAChG,oCAAoC,CACvC,CAAC;AACJ,CAAC"}
|
package/dist/migrate.d.ts
CHANGED
|
@@ -20,9 +20,15 @@ export interface MigrationResult {
|
|
|
20
20
|
}
|
|
21
21
|
/**
|
|
22
22
|
* Imports iff (a) the tool has NO profiles in the shared home yet, and
|
|
23
|
-
* (b) the legacy file exists and holds at least one profile
|
|
24
|
-
*
|
|
25
|
-
*
|
|
23
|
+
* (b) the legacy file exists and holds at least one profile that is a plain
|
|
24
|
+
* object. Only those come across, so the shared file stays one the strict
|
|
25
|
+
* loader reads: a list of profiles, or a profile that is not an object, is
|
|
26
|
+
* left behind. Anything else — no home, no legacy file, empty/corrupt legacy
|
|
27
|
+
* content, no profile that is an object, or a shared-home config already
|
|
28
|
+
* carrying profiles — is a no-op that writes nothing. The
|
|
29
|
+
* check of (a) and the import are one `updateConfig` on the shared file, so
|
|
30
|
+
* a command writing its first profile meanwhile is never overwritten; a
|
|
31
|
+
* shared file that does not parse is a `CliConfigError`, never imported over.
|
|
26
32
|
*/
|
|
27
33
|
export declare function migrateLegacyConfig(env: CliEnv, spec: LegacyMigrationSpec): MigrationResult;
|
|
28
34
|
//# sourceMappingURL=migrate.d.ts.map
|
package/dist/migrate.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"migrate.d.ts","sourceRoot":"","sources":["../src/migrate.ts"],"names":[],"mappings":"AAEA,OAAO,EAML,KAAK,MAAM,EACZ,MAAM,aAAa,CAAC;AAErB;;;;;GAKG;AAEH,MAAM,WAAW,mBAAmB;IAClC,mEAAmE;IACnE,IAAI,EAAE,MAAM,CAAC;IACb,+DAA+D;IAC/D,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,eAAe;IAC9B,QAAQ,EAAE,OAAO,CAAC;IAClB,yDAAyD;IACzD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,wDAAwD;IACxD,EAAE,CAAC,EAAE,MAAM,CAAC;CACb;
|
|
1
|
+
{"version":3,"file":"migrate.d.ts","sourceRoot":"","sources":["../src/migrate.ts"],"names":[],"mappings":"AAEA,OAAO,EAML,KAAK,MAAM,EACZ,MAAM,aAAa,CAAC;AAErB;;;;;GAKG;AAEH,MAAM,WAAW,mBAAmB;IAClC,mEAAmE;IACnE,IAAI,EAAE,MAAM,CAAC;IACb,+DAA+D;IAC/D,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,eAAe;IAC9B,QAAQ,EAAE,OAAO,CAAC;IAClB,yDAAyD;IACzD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,wDAAwD;IACxD,EAAE,CAAC,EAAE,MAAM,CAAC;CACb;AAMD;;;;;;;;;;;GAWG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,mBAAmB,GAAG,eAAe,CAiC3F"}
|
package/dist/migrate.js
CHANGED
|
@@ -1,11 +1,20 @@
|
|
|
1
1
|
import { existsSync, readFileSync } from 'node:fs';
|
|
2
2
|
import { join } from 'node:path';
|
|
3
|
-
import { assertToolNamespace, configPath,
|
|
3
|
+
import { assertToolNamespace, configPath, parseConfig, updateConfig } from './config.js';
|
|
4
|
+
function isPlainObject(value) {
|
|
5
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
6
|
+
}
|
|
4
7
|
/**
|
|
5
8
|
* Imports iff (a) the tool has NO profiles in the shared home yet, and
|
|
6
|
-
* (b) the legacy file exists and holds at least one profile
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
+
* (b) the legacy file exists and holds at least one profile that is a plain
|
|
10
|
+
* object. Only those come across, so the shared file stays one the strict
|
|
11
|
+
* loader reads: a list of profiles, or a profile that is not an object, is
|
|
12
|
+
* left behind. Anything else — no home, no legacy file, empty/corrupt legacy
|
|
13
|
+
* content, no profile that is an object, or a shared-home config already
|
|
14
|
+
* carrying profiles — is a no-op that writes nothing. The
|
|
15
|
+
* check of (a) and the import are one `updateConfig` on the shared file, so
|
|
16
|
+
* a command writing its first profile meanwhile is never overwritten; a
|
|
17
|
+
* shared file that does not parse is a `CliConfigError`, never imported over.
|
|
9
18
|
*/
|
|
10
19
|
export function migrateLegacyConfig(env, spec) {
|
|
11
20
|
assertToolNamespace(spec.tool);
|
|
@@ -13,9 +22,6 @@ export function migrateLegacyConfig(env, spec) {
|
|
|
13
22
|
const to = configPath(env, spec.tool);
|
|
14
23
|
if (!to)
|
|
15
24
|
return { migrated: false };
|
|
16
|
-
const current = loadConfig(env, spec.tool);
|
|
17
|
-
if (Object.keys(current.profiles).length > 0)
|
|
18
|
-
return { migrated: false };
|
|
19
25
|
const base = env.XDG_CONFIG_HOME || (env.HOME ? join(env.HOME, '.config') : null);
|
|
20
26
|
if (!base)
|
|
21
27
|
return { migrated: false };
|
|
@@ -29,10 +35,25 @@ export function migrateLegacyConfig(env, spec) {
|
|
|
29
35
|
catch {
|
|
30
36
|
return { migrated: false };
|
|
31
37
|
}
|
|
32
|
-
const
|
|
33
|
-
|
|
38
|
+
const parsed = parseConfig(raw);
|
|
39
|
+
// Only the profiles that are plain objects come across: the shared file must stay one the strict
|
|
40
|
+
// loader reads (a list of profiles, or a profile that is a string, is no profile).
|
|
41
|
+
const kept = isPlainObject(parsed.profiles)
|
|
42
|
+
? Object.entries(parsed.profiles).filter(([, profile]) => isPlainObject(profile))
|
|
43
|
+
: [];
|
|
44
|
+
if (kept.length === 0)
|
|
34
45
|
return { migrated: false };
|
|
35
|
-
|
|
36
|
-
|
|
46
|
+
const legacy = {
|
|
47
|
+
...(parsed.activeProfile !== undefined ? { activeProfile: parsed.activeProfile } : {}),
|
|
48
|
+
profiles: Object.fromEntries(kept)
|
|
49
|
+
};
|
|
50
|
+
let migrated = false;
|
|
51
|
+
updateConfig(env, spec.tool, (draft) => {
|
|
52
|
+
if (Object.keys(draft.profiles).length > 0)
|
|
53
|
+
return;
|
|
54
|
+
migrated = true;
|
|
55
|
+
return legacy;
|
|
56
|
+
});
|
|
57
|
+
return migrated ? { migrated: true, from, to } : { migrated: false };
|
|
37
58
|
}
|
|
38
59
|
//# sourceMappingURL=migrate.js.map
|
package/dist/migrate.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"migrate.js","sourceRoot":"","sources":["../src/migrate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACnD,OA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AI,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC;AACvE,CAAC"}
|
package/dist/resolve.d.ts
CHANGED
|
@@ -44,7 +44,7 @@ export declare function sameInstance(a: string, b: string): boolean;
|
|
|
44
44
|
/**
|
|
45
45
|
* The name an instance URL's profile gets when nothing named it: `cloud`
|
|
46
46
|
* for the tool's cloud URL, else the host with its port
|
|
47
|
-
* (`share.
|
|
47
|
+
* (`share.example.com`, `localhost:3400`). The person may rename it.
|
|
48
48
|
*/
|
|
49
49
|
export declare function profileNameFor(url: string, cloudUrl?: string | undefined): string;
|
|
50
50
|
/**
|
|
@@ -56,6 +56,14 @@ export declare function firstSet(...values: Array<string | undefined>): string |
|
|
|
56
56
|
/** The instance a profile is at: its `baseUrl`, else the tool's cloud URL.
|
|
57
57
|
* A blank `baseUrl` is no `baseUrl`. */
|
|
58
58
|
export declare function profileUrl(profile: CliProfile, cloudUrl: string | undefined): string | undefined;
|
|
59
|
+
/**
|
|
60
|
+
* The name a new profile at an instance gets, one nothing in `config` has:
|
|
61
|
+
* `cloud` for the cloud URL, else the host; when that name is taken, the
|
|
62
|
+
* host, then `<host>-2`, `<host>-3`, … so a key is never written onto a
|
|
63
|
+
* profile that is not this instance's. The name `selectProfile` gives the
|
|
64
|
+
* profile it makes in memory; a hub file's new login is named the same way.
|
|
65
|
+
*/
|
|
66
|
+
export declare function freshProfileName(config: CliConfig, url: string, cloudUrl?: string | undefined): string;
|
|
59
67
|
/** The rule that picked the profile. */
|
|
60
68
|
export type ProfileSource = 'flag' | 'url' | 'active' | 'cloud';
|
|
61
69
|
export interface SelectedProfile extends ResolvedProfile {
|
|
@@ -64,8 +72,8 @@ export interface SelectedProfile extends ResolvedProfile {
|
|
|
64
72
|
/**
|
|
65
73
|
* true = the profile is not on disk yet: it was made in memory for the
|
|
66
74
|
* instance URL given, or it is the implicit cloud profile, under a name
|
|
67
|
-
* no profile on disk has.
|
|
68
|
-
*
|
|
75
|
+
* no profile on disk has. The first kept key `connectOnDemand` stores
|
|
76
|
+
* writes it; selection never does.
|
|
69
77
|
*/
|
|
70
78
|
created: boolean;
|
|
71
79
|
}
|
|
@@ -117,7 +125,7 @@ export interface ResolveBaseUrlOptions {
|
|
|
117
125
|
profile?: CliProfile | undefined;
|
|
118
126
|
/**
|
|
119
127
|
* The tool's cloud home, the last fallback: every CLI that has a cloud
|
|
120
|
-
* instance ships it (`https://
|
|
128
|
+
* instance ships it (`https://tool.example.com`), so a clean
|
|
121
129
|
* machine with an `antasphere login` needs no flag. A tool with none (a
|
|
122
130
|
* template placeholder) errors with `missingMessage` as before.
|
|
123
131
|
*/
|
package/dist/resolve.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolve.d.ts","sourceRoot":"","sources":["../src/resolve.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEjE;;;;;GAKG;AACH,qBAAa,aAAc,SAAQ,KAAK;IACtC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;gBAEd,OAAO,EAAE,MAAM,EAAE,IAAI,GAAE;QAAE,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAO;CAK9D;AAED;;;;;GAKG;AACH,eAAO,MAAM,aAAa,UAAU,CAAC;AAErC,MAAM,WAAW,eAAe;IAC9B,8EAA8E;IAC9E,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;IACzB,OAAO,EAAE,UAAU,GAAG,SAAS,CAAC;CACjC;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAC5B,MAAM,EAAE,SAAS,EACjB,SAAS,EAAE,MAAM,GAAG,SAAS,EAC7B,IAAI,GAAE;IAAE,WAAW,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CAAO,GAC9C,eAAe,CAajB;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,G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AAC;CACtB;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,oBAAoB,GAAG,eAAe,CAyBzE;AAED,MAAM,WAAW,qBAAqB;IACpC,mDAAmD;IACnD,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1B,GAAG,EAAE,MAAM,CAAC;IACZ,uEAAuE;IACvE,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,UAAU,GAAG,SAAS,CAAC;IACjC;;;;;OAKG;IACH,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,kEAAkE;IAClE,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,qBAAqB,GAAG,MAAM,CAQlE;AAED,MAAM,WAAW,oBAAoB;IACnC,qCAAqC;IACrC,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1B,GAAG,EAAE,MAAM,CAAC;IACZ,+EAA+E;IAC/E,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,UAAU,GAAG,SAAS,CAAC;CAClC;AAED;4CAC4C;AAC5C,wBAAgB,aAAa,CAAC,IAAI,EAAE,oBAAoB,GAAG,MAAM,GAAG,SAAS,CAE5E;AAED,MAAM,WAAW,iBAAiB;IAChC,gEAAgE;IAChE,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1B,GAAG,EAAE,MAAM,CAAC;IACZ,uEAAuE;IACvE,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;;;;;;;GAQG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,iBAAiB,GAAG,MAAM,GAAG,SAAS,CAEtE"}
|
package/dist/resolve.js
CHANGED
|
@@ -59,7 +59,7 @@ export function sameInstance(a, b) {
|
|
|
59
59
|
/**
|
|
60
60
|
* The name an instance URL's profile gets when nothing named it: `cloud`
|
|
61
61
|
* for the tool's cloud URL, else the host with its port
|
|
62
|
-
* (`share.
|
|
62
|
+
* (`share.example.com`, `localhost:3400`). The person may rename it.
|
|
63
63
|
*/
|
|
64
64
|
export function profileNameFor(url, cloudUrl) {
|
|
65
65
|
if (cloudUrl && sameInstance(url, cloudUrl))
|
|
@@ -104,20 +104,24 @@ function profileAt(config, url, cloudUrl) {
|
|
|
104
104
|
return pick ? { name: pick[0], profile: pick[1] } : undefined;
|
|
105
105
|
}
|
|
106
106
|
/**
|
|
107
|
-
*
|
|
108
|
-
*
|
|
109
|
-
*
|
|
110
|
-
*
|
|
111
|
-
* profile
|
|
107
|
+
* The name a new profile at an instance gets, one nothing in `config` has:
|
|
108
|
+
* `cloud` for the cloud URL, else the host; when that name is taken, the
|
|
109
|
+
* host, then `<host>-2`, `<host>-3`, … so a key is never written onto a
|
|
110
|
+
* profile that is not this instance's. The name `selectProfile` gives the
|
|
111
|
+
* profile it makes in memory; a hub file's new login is named the same way.
|
|
112
112
|
*/
|
|
113
|
-
function
|
|
113
|
+
export function freshProfileName(config, url, cloudUrl) {
|
|
114
114
|
const host = profileNameFor(url);
|
|
115
115
|
let name = [profileNameFor(url, cloudUrl), host].find((c) => !(c in config.profiles));
|
|
116
116
|
for (let n = 2; name === undefined; n += 1) {
|
|
117
117
|
if (!(`${host}-${n}` in config.profiles))
|
|
118
118
|
name = `${host}-${n}`;
|
|
119
119
|
}
|
|
120
|
-
return
|
|
120
|
+
return name;
|
|
121
|
+
}
|
|
122
|
+
/** A profile made in memory for an instance nothing on disk names, under `freshProfileName`. */
|
|
123
|
+
function freshProfileAt(config, url, cloudUrl) {
|
|
124
|
+
return { name: freshProfileName(config, url, cloudUrl), profile: { baseUrl: normalizeUrl(url) } };
|
|
121
125
|
}
|
|
122
126
|
/**
|
|
123
127
|
* A profile is an instance. The selection rule every tool CLI applies, in
|