@fluid-app/fluid-cli 0.1.349 → 0.1.350
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/dist/bin/fluid.mjs +9 -3
- package/dist/bin/fluid.mjs.map +1 -1
- package/dist/{token-DgwRaKgP.mjs → hook-CZoMQwJE.mjs} +257 -8
- package/dist/hook-CZoMQwJE.mjs.map +1 -0
- package/dist/index.d.mts +86 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +90 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/dist/token-DgwRaKgP.mjs.map +0 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { existsSync, mkdirSync, readFileSync, renameSync, unlinkSync, writeFileSync } from "node:fs";
|
|
2
|
-
import { randomBytes, randomUUID, timingSafeEqual } from "node:crypto";
|
|
1
|
+
import { existsSync, mkdirSync, readFileSync, realpathSync, renameSync, unlinkSync, writeFileSync, writeSync } from "node:fs";
|
|
2
|
+
import { createHash, randomBytes, randomUUID, timingSafeEqual } from "node:crypto";
|
|
3
3
|
import { execFile } from "node:child_process";
|
|
4
4
|
import { createServer } from "node:http";
|
|
5
|
-
import { dirname, join } from "node:path";
|
|
5
|
+
import { dirname, isAbsolute, join, sep } from "node:path";
|
|
6
6
|
import { homedir } from "node:os";
|
|
7
7
|
//#region src/catalog/annotations.ts
|
|
8
8
|
const ANNOTATION = Symbol.for("@fluid-app/fluid-cli.command-annotation");
|
|
@@ -71,7 +71,7 @@ function walkCommands(root) {
|
|
|
71
71
|
aliases: command.aliases(),
|
|
72
72
|
arguments: command.registeredArguments.map(describeArgument),
|
|
73
73
|
options: visibleOptions(command).map(describeOption),
|
|
74
|
-
inheritsOptionsFrom: ancestors.filter((ancestor) => visibleOptions(ancestor).some((option) => option.long !== "--version")).map((ancestor) => commandPath(ancestor).join(" ")),
|
|
74
|
+
inheritsOptionsFrom: ancestors.filter((ancestor) => visibleOptions(ancestor).some((option) => option.long !== "--version")).map((ancestor) => commandPath$1(ancestor).join(" ")),
|
|
75
75
|
subcommands: subcommands.map((sub) => sub.name()),
|
|
76
76
|
runnable: isRunnable(command),
|
|
77
77
|
writes: inferWrites(command, annotation?.writes),
|
|
@@ -87,7 +87,7 @@ function rootCommand(command) {
|
|
|
87
87
|
while (root.parent) root = root.parent;
|
|
88
88
|
return root;
|
|
89
89
|
}
|
|
90
|
-
function commandPath(command) {
|
|
90
|
+
function commandPath$1(command) {
|
|
91
91
|
const path = [];
|
|
92
92
|
for (let c = command; c; c = c.parent) path.unshift(c.name());
|
|
93
93
|
return path;
|
|
@@ -100,7 +100,7 @@ function filterCatalog(entries, root, prefix) {
|
|
|
100
100
|
if (!next) return [];
|
|
101
101
|
target = next;
|
|
102
102
|
}
|
|
103
|
-
const base = commandPath(target);
|
|
103
|
+
const base = commandPath$1(target);
|
|
104
104
|
return entries.filter((entry) => base.every((word, index) => entry.path[index] === word));
|
|
105
105
|
}
|
|
106
106
|
//#endregion
|
|
@@ -3330,6 +3330,255 @@ function listProfileNames() {
|
|
|
3330
3330
|
return Object.keys(config.profiles);
|
|
3331
3331
|
}
|
|
3332
3332
|
//#endregion
|
|
3333
|
-
|
|
3333
|
+
//#region src/inputs/declare.ts
|
|
3334
|
+
const resolvers = /* @__PURE__ */ new WeakMap();
|
|
3335
|
+
/**
|
|
3336
|
+
* Declares the local inputs a command's action reads.
|
|
3337
|
+
*
|
|
3338
|
+
* command - the leaf command whose action reads the inputs
|
|
3339
|
+
* resolver - maps commander's parsed opts and args to the input specs
|
|
3340
|
+
*
|
|
3341
|
+
* Returns the command.
|
|
3342
|
+
*/
|
|
3343
|
+
function declareInputs(command, resolver) {
|
|
3344
|
+
resolvers.set(command, resolver);
|
|
3345
|
+
return command;
|
|
3346
|
+
}
|
|
3347
|
+
function getInputResolver(command) {
|
|
3348
|
+
return resolvers.get(command);
|
|
3349
|
+
}
|
|
3350
|
+
//#endregion
|
|
3351
|
+
//#region src/inputs/scope.ts
|
|
3352
|
+
let internalDepth = 0;
|
|
3353
|
+
/** True while the inputs implementation itself is touching the filesystem. */
|
|
3354
|
+
function inInternalRead() {
|
|
3355
|
+
return internalDepth > 0;
|
|
3356
|
+
}
|
|
3357
|
+
function withInternalReads(fn) {
|
|
3358
|
+
internalDepth++;
|
|
3359
|
+
try {
|
|
3360
|
+
return fn();
|
|
3361
|
+
} finally {
|
|
3362
|
+
internalDepth--;
|
|
3363
|
+
}
|
|
3364
|
+
}
|
|
3365
|
+
//#endregion
|
|
3366
|
+
//#region src/inputs/paths.ts
|
|
3367
|
+
function lexicalPath(path, cwd = process.cwd()) {
|
|
3368
|
+
return isAbsolute(path) ? path : `${cwd}${sep}${path}`;
|
|
3369
|
+
}
|
|
3370
|
+
/**
|
|
3371
|
+
* The path rule for resolve and expect mode (default mode reads the lexical
|
|
3372
|
+
* path so /dev/stdin works): make the path absolute without normalizing, then realpath it natively so `..` after a symlink keeps OS
|
|
3373
|
+
* semantics. Throws when the path does not exist.
|
|
3374
|
+
*/
|
|
3375
|
+
function canonicalPath(path, cwd = process.cwd()) {
|
|
3376
|
+
const lexical = lexicalPath(path, cwd);
|
|
3377
|
+
return {
|
|
3378
|
+
lexical,
|
|
3379
|
+
canonical: withInternalReads(() => realpathSync.native(lexical))
|
|
3380
|
+
};
|
|
3381
|
+
}
|
|
3382
|
+
//#endregion
|
|
3383
|
+
//#region src/inputs/reader.ts
|
|
3384
|
+
let activeSnapshot = null;
|
|
3385
|
+
function setActiveSnapshot(snapshot) {
|
|
3386
|
+
activeSnapshot = snapshot;
|
|
3387
|
+
}
|
|
3388
|
+
var InputsUndeclaredError = class extends Error {
|
|
3389
|
+
constructor(path) {
|
|
3390
|
+
super(`Undeclared input read: ${path}`);
|
|
3391
|
+
this.name = "InputsUndeclaredError";
|
|
3392
|
+
}
|
|
3393
|
+
};
|
|
3394
|
+
function declaredKey(path, snapshot) {
|
|
3395
|
+
const lexical = lexicalPath(path);
|
|
3396
|
+
const key = snapshot.aliases.get(lexical) ?? lexical;
|
|
3397
|
+
return snapshot.files.has(key) ? key : void 0;
|
|
3398
|
+
}
|
|
3399
|
+
/**
|
|
3400
|
+
* The reader behind ctx.inputs. Outside expect mode it reads from disk; once
|
|
3401
|
+
* an expect-mode snapshot is active it serves only that snapshot and throws
|
|
3402
|
+
* for anything undeclared.
|
|
3403
|
+
*/
|
|
3404
|
+
function createInputsReader() {
|
|
3405
|
+
return { readFile(path, encoding) {
|
|
3406
|
+
const snapshot = activeSnapshot;
|
|
3407
|
+
if (!snapshot) {
|
|
3408
|
+
const content = withInternalReads(() => readFileSync(lexicalPath(path)));
|
|
3409
|
+
return encoding ? content.toString(encoding) : content;
|
|
3410
|
+
}
|
|
3411
|
+
const key = declaredKey(path, snapshot);
|
|
3412
|
+
const content = key === void 0 ? void 0 : snapshot.files.get(key);
|
|
3413
|
+
if (!content) throw new InputsUndeclaredError(path);
|
|
3414
|
+
return encoding ? content.toString(encoding) : Buffer.from(content);
|
|
3415
|
+
} };
|
|
3416
|
+
}
|
|
3417
|
+
function sha256(data) {
|
|
3418
|
+
return createHash("sha256").update(data).digest("hex");
|
|
3419
|
+
}
|
|
3420
|
+
function resolveInputs(specs, cwd = process.cwd()) {
|
|
3421
|
+
return withInternalReads(() => {
|
|
3422
|
+
const snapshot = {
|
|
3423
|
+
files: /* @__PURE__ */ new Map(),
|
|
3424
|
+
aliases: /* @__PURE__ */ new Map()
|
|
3425
|
+
};
|
|
3426
|
+
const entries = [];
|
|
3427
|
+
for (const spec of specs) if (spec.kind === "ref") entries.push({
|
|
3428
|
+
kind: "ref",
|
|
3429
|
+
name: spec.name,
|
|
3430
|
+
value: spec.value
|
|
3431
|
+
});
|
|
3432
|
+
else if (spec.kind === "file" || spec.kind === "config") {
|
|
3433
|
+
const { lexical, canonical: path } = canonicalPath(spec.path, cwd);
|
|
3434
|
+
const content = readFileSync(path);
|
|
3435
|
+
snapshot.aliases.set(lexical, path);
|
|
3436
|
+
snapshot.aliases.set(path, path);
|
|
3437
|
+
snapshot.files.set(path, content);
|
|
3438
|
+
entries.push({
|
|
3439
|
+
kind: spec.kind,
|
|
3440
|
+
path,
|
|
3441
|
+
sha256: sha256(content),
|
|
3442
|
+
size: content.length
|
|
3443
|
+
});
|
|
3444
|
+
} else throw new Error("tree inputs not supported yet");
|
|
3445
|
+
return {
|
|
3446
|
+
entries,
|
|
3447
|
+
snapshot
|
|
3448
|
+
};
|
|
3449
|
+
});
|
|
3450
|
+
}
|
|
3451
|
+
function sortKey(entry) {
|
|
3452
|
+
const id = entry.kind === "ref" ? entry.name : entry.path;
|
|
3453
|
+
return `${entry.kind}\0${id}`;
|
|
3454
|
+
}
|
|
3455
|
+
function canonicalEntries(entries) {
|
|
3456
|
+
return entries.map((e) => {
|
|
3457
|
+
if (e.kind === "ref") return {
|
|
3458
|
+
kind: "ref",
|
|
3459
|
+
name: e.name,
|
|
3460
|
+
value: e.value
|
|
3461
|
+
};
|
|
3462
|
+
return {
|
|
3463
|
+
kind: e.kind,
|
|
3464
|
+
path: e.path,
|
|
3465
|
+
sha256: e.sha256,
|
|
3466
|
+
size: e.size
|
|
3467
|
+
};
|
|
3468
|
+
}).sort((a, b) => {
|
|
3469
|
+
const ka = sortKey(a);
|
|
3470
|
+
const kb = sortKey(b);
|
|
3471
|
+
return ka < kb ? -1 : ka > kb ? 1 : 0;
|
|
3472
|
+
});
|
|
3473
|
+
}
|
|
3474
|
+
function manifestJson(command, entries) {
|
|
3475
|
+
return JSON.stringify({
|
|
3476
|
+
version: 1,
|
|
3477
|
+
command,
|
|
3478
|
+
inputs: canonicalEntries(entries)
|
|
3479
|
+
});
|
|
3480
|
+
}
|
|
3481
|
+
//#endregion
|
|
3482
|
+
//#region src/inputs/hook.ts
|
|
3483
|
+
const INPUTS_MODE_ENV = "FLUID_INPUTS_MODE";
|
|
3484
|
+
const INPUTS_EXPECT_ENV = "FLUID_INPUTS_EXPECT";
|
|
3485
|
+
const INPUTS_UNDECLARED_CODE = "inputs_undeclared";
|
|
3486
|
+
const INPUTS_UNDECLARED_EXIT = 64;
|
|
3487
|
+
const INPUTS_MISMATCH_CODE = "inputs_mismatch";
|
|
3488
|
+
const INPUTS_MISMATCH_EXIT = 65;
|
|
3489
|
+
function writeAll(fd, text) {
|
|
3490
|
+
const buffer = Buffer.from(text);
|
|
3491
|
+
let offset = 0;
|
|
3492
|
+
while (offset < buffer.length) try {
|
|
3493
|
+
offset += writeSync(fd, buffer, offset);
|
|
3494
|
+
} catch (error) {
|
|
3495
|
+
if (error.code !== "EAGAIN") throw error;
|
|
3496
|
+
}
|
|
3497
|
+
}
|
|
3498
|
+
const processIo = {
|
|
3499
|
+
env: process.env,
|
|
3500
|
+
stdout: (text) => writeAll(1, text),
|
|
3501
|
+
stderr: (text) => writeAll(2, text),
|
|
3502
|
+
exit: (code) => process.exit(code)
|
|
3503
|
+
};
|
|
3504
|
+
function inputsModeActive(env) {
|
|
3505
|
+
return env["FLUID_INPUTS_MODE"] !== void 0 || env["FLUID_INPUTS_EXPECT"] !== void 0;
|
|
3506
|
+
}
|
|
3507
|
+
function commandPath(command) {
|
|
3508
|
+
const names = [];
|
|
3509
|
+
for (let c = command; c; c = c.parent) names.unshift(c.name());
|
|
3510
|
+
return names.join(" ");
|
|
3511
|
+
}
|
|
3512
|
+
function readManifest(path) {
|
|
3513
|
+
try {
|
|
3514
|
+
const parsed = JSON.parse(withInternalReads(() => readFileSync(path, "utf8")));
|
|
3515
|
+
if (!Array.isArray(parsed.inputs)) return null;
|
|
3516
|
+
return {
|
|
3517
|
+
version: parsed.version,
|
|
3518
|
+
command: parsed.command,
|
|
3519
|
+
inputs: canonicalEntries(parsed.inputs)
|
|
3520
|
+
};
|
|
3521
|
+
} catch {
|
|
3522
|
+
return null;
|
|
3523
|
+
}
|
|
3524
|
+
}
|
|
3525
|
+
function inputsPreAction(actionCommand, io = processIo) {
|
|
3526
|
+
const mode = io.env[INPUTS_MODE_ENV];
|
|
3527
|
+
const expectPath = io.env[INPUTS_EXPECT_ENV];
|
|
3528
|
+
setActiveSnapshot(null);
|
|
3529
|
+
if (mode === void 0 && expectPath === void 0) return;
|
|
3530
|
+
const resolveMode = mode === "resolve";
|
|
3531
|
+
if (mode !== void 0 && !resolveMode || expectPath === "" || resolveMode && expectPath !== void 0) {
|
|
3532
|
+
io.stderr(`${INPUTS_MISMATCH_CODE}\n`);
|
|
3533
|
+
return io.exit(65);
|
|
3534
|
+
}
|
|
3535
|
+
const resolver = getInputResolver(actionCommand);
|
|
3536
|
+
if (!resolver) {
|
|
3537
|
+
io.stderr(`${INPUTS_UNDECLARED_CODE}\n`);
|
|
3538
|
+
return io.exit(64);
|
|
3539
|
+
}
|
|
3540
|
+
let resolved;
|
|
3541
|
+
try {
|
|
3542
|
+
resolved = resolveInputs(resolver(actionCommand.optsWithGlobals(), actionCommand.args));
|
|
3543
|
+
} catch (error) {
|
|
3544
|
+
if (resolveMode) {
|
|
3545
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
3546
|
+
io.stderr(`${message}\n`);
|
|
3547
|
+
return io.exit(1);
|
|
3548
|
+
}
|
|
3549
|
+
io.stderr(`${INPUTS_MISMATCH_CODE}\n`);
|
|
3550
|
+
return io.exit(65);
|
|
3551
|
+
}
|
|
3552
|
+
if (resolveMode) {
|
|
3553
|
+
io.stdout(`${manifestJson(commandPath(actionCommand), resolved.entries)}\n`);
|
|
3554
|
+
return io.exit(0);
|
|
3555
|
+
}
|
|
3556
|
+
const expected = readManifest(expectPath);
|
|
3557
|
+
if (!expected || expected.version !== 1 || expected.command !== commandPath(actionCommand) || JSON.stringify(expected.inputs) !== JSON.stringify(canonicalEntries(resolved.entries))) {
|
|
3558
|
+
io.stderr(`${INPUTS_MISMATCH_CODE}\n`);
|
|
3559
|
+
return io.exit(65);
|
|
3560
|
+
}
|
|
3561
|
+
setActiveSnapshot(resolved.snapshot);
|
|
3562
|
+
}
|
|
3563
|
+
/**
|
|
3564
|
+
* Registers the inputs preAction hook. Register it before any credential
|
|
3565
|
+
* hook.
|
|
3566
|
+
*/
|
|
3567
|
+
function registerInputsHook(program, io = processIo) {
|
|
3568
|
+
program.hook("preAction", (_program, actionCommand) => {
|
|
3569
|
+
inputsPreAction(actionCommand, io);
|
|
3570
|
+
});
|
|
3571
|
+
}
|
|
3572
|
+
/**
|
|
3573
|
+
* Maps an undeclared read in expect mode to the fixed undeclared exit; any
|
|
3574
|
+
* other error is returned to the caller untouched.
|
|
3575
|
+
*/
|
|
3576
|
+
function exitOnInputsError(error, io = processIo) {
|
|
3577
|
+
if (!(error instanceof InputsUndeclaredError)) return;
|
|
3578
|
+
io.stderr(`${INPUTS_UNDECLARED_CODE}\n`);
|
|
3579
|
+
io.exit(64);
|
|
3580
|
+
}
|
|
3581
|
+
//#endregion
|
|
3582
|
+
export { mapResult as $, signInWithBrowser as A, getFluidApiBase as B, getConfigDir as C, primeIdentityProfile as D, identityToken as E, isIdentityProfile as F, validateToken as G, sendMfa as H, FLUID_API_ERROR as I, isError as J, failure as K, SIGNUP_ERROR as L, resolveIdentityUrl as M, createFetchClient as N, profileAccessToken as O, createDefaultConfig as P, mapError as Q, confirmMfa as R, isStrictConfig as S, describeIdentityError as T, signup as U, redeemIdentityLink as V, switchCompany as W, isNodeError as X, isFailure as Y, isSuccess as Z, resolveCredentialSource as _, INPUTS_UNDECLARED_CODE as a, filterCatalog as at, updateConfig as b, inputsModeActive as c, visibleSubcommands as ct, inInternalRead as d, success as et, declareInputs as f, listProfileNames as g, getAuthTokenAsync as h, INPUTS_MODE_ENV as i, unwrapOr as it, signOutIdentity as j, sessionFacts as k, registerInputsHook as l, walkCommands as lt, getAuthToken as m, INPUTS_MISMATCH_CODE as n, tryCatchAsync as nt, INPUTS_UNDECLARED_EXIT as o, rootCommand as ot, getActiveProfile as p, getErrorMessage$1 as q, INPUTS_MISMATCH_EXIT as r, unwrap as rt, exitOnInputsError as s, visibleOptions as st, INPUTS_EXPECT_ENV as t, tryCatch as tt, createInputsReader as u, describeCommand as ut, findProjectConfig as v, getConfigFilePath as w, writeConfig as x, readConfig as y, fetchUserCompanies as z };
|
|
3334
3583
|
|
|
3335
|
-
//# sourceMappingURL=
|
|
3584
|
+
//# sourceMappingURL=hook-CZoMQwJE.mjs.map
|