@swmansion/argent 0.18.1-next.14 → 0.18.1-next.15
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/cli-cmds.mjs +59 -10
- package/package.json +1 -1
package/dist/cli-cmds.mjs
CHANGED
|
@@ -1304,15 +1304,20 @@ function setAtPath(obj, dottedKey, value) {
|
|
|
1304
1304
|
}
|
|
1305
1305
|
function deleteAtPath(obj, dottedKey) {
|
|
1306
1306
|
const parts = splitKey(dottedKey);
|
|
1307
|
-
|
|
1307
|
+
const chain = [obj];
|
|
1308
1308
|
for (let i2 = 0; i2 < parts.length - 1; i2++) {
|
|
1309
|
-
const next =
|
|
1309
|
+
const next = chain[i2][parts[i2]];
|
|
1310
1310
|
if (!isPlainObject(next)) return false;
|
|
1311
|
-
|
|
1311
|
+
chain.push(next);
|
|
1312
1312
|
}
|
|
1313
|
+
const parent = chain[parts.length - 1];
|
|
1313
1314
|
const leaf = parts[parts.length - 1];
|
|
1314
|
-
if (!Object.hasOwn(
|
|
1315
|
-
delete
|
|
1315
|
+
if (!Object.hasOwn(parent, leaf)) return false;
|
|
1316
|
+
delete parent[leaf];
|
|
1317
|
+
for (let i2 = chain.length - 1; i2 >= 1; i2--) {
|
|
1318
|
+
if (Object.keys(chain[i2]).length > 0) break;
|
|
1319
|
+
delete chain[i2 - 1][parts[i2 - 1]];
|
|
1320
|
+
}
|
|
1316
1321
|
return true;
|
|
1317
1322
|
}
|
|
1318
1323
|
var LOCK_STALE_MS2 = 1e4;
|
|
@@ -1447,6 +1452,9 @@ function asString(raw) {
|
|
|
1447
1452
|
const trimmed = raw.trim();
|
|
1448
1453
|
return trimmed === "" ? void 0 : trimmed;
|
|
1449
1454
|
}
|
|
1455
|
+
function asNumber(raw) {
|
|
1456
|
+
return typeof raw === "number" && Number.isFinite(raw) ? raw : void 0;
|
|
1457
|
+
}
|
|
1450
1458
|
function asStringArray(raw) {
|
|
1451
1459
|
if (!Array.isArray(raw)) return void 0;
|
|
1452
1460
|
const out = [];
|
|
@@ -1455,6 +1463,15 @@ function asStringArray(raw) {
|
|
|
1455
1463
|
}
|
|
1456
1464
|
return out;
|
|
1457
1465
|
}
|
|
1466
|
+
var PARSER_EXPECTATIONS = /* @__PURE__ */ new Map([
|
|
1467
|
+
[asBoolean, "a boolean (true or false)"],
|
|
1468
|
+
[asString, "a non-empty string"],
|
|
1469
|
+
[asNumber, "a number"],
|
|
1470
|
+
[asStringArray, "an array of strings"]
|
|
1471
|
+
]);
|
|
1472
|
+
function describeExpectedValue(def) {
|
|
1473
|
+
return def.expected ?? PARSER_EXPECTATIONS.get(def.parse);
|
|
1474
|
+
}
|
|
1458
1475
|
var CONFIG_SCHEMA = [
|
|
1459
1476
|
{
|
|
1460
1477
|
key: "telemetry.enabled",
|
|
@@ -1560,12 +1577,18 @@ var ConfigScopeError = class extends Error {
|
|
|
1560
1577
|
allowed;
|
|
1561
1578
|
};
|
|
1562
1579
|
var ConfigValidationError = class extends Error {
|
|
1563
|
-
constructor(key) {
|
|
1564
|
-
super(
|
|
1580
|
+
constructor(key, expected, example) {
|
|
1581
|
+
super(
|
|
1582
|
+
expected ? `Invalid value for config key "${key}": expected ${expected}.` : `Invalid value for config key "${key}".`
|
|
1583
|
+
);
|
|
1565
1584
|
this.key = key;
|
|
1585
|
+
this.expected = expected;
|
|
1586
|
+
this.example = example;
|
|
1566
1587
|
this.name = "ConfigValidationError";
|
|
1567
1588
|
}
|
|
1568
1589
|
key;
|
|
1590
|
+
expected;
|
|
1591
|
+
example;
|
|
1569
1592
|
};
|
|
1570
1593
|
var ConfigManagedElsewhereError = class extends Error {
|
|
1571
1594
|
constructor(key, command) {
|
|
@@ -1582,7 +1605,8 @@ function setConfigValue(key, rawValue, scope = "global", options = {}, registry
|
|
|
1582
1605
|
if (def.manageCommand) throw new ConfigManagedElsewhereError(key, def.manageCommand);
|
|
1583
1606
|
if (!def.scopes.includes(scope)) throw new ConfigScopeError(key, scope, def.scopes);
|
|
1584
1607
|
const parsed = def.parse(rawValue);
|
|
1585
|
-
if (parsed === void 0)
|
|
1608
|
+
if (parsed === void 0)
|
|
1609
|
+
throw new ConfigValidationError(def.key, describeExpectedValue(def), def.example);
|
|
1586
1610
|
updateConfig((config2) => setAtPath(config2, key, parsed), scope, options);
|
|
1587
1611
|
return parsed;
|
|
1588
1612
|
}
|
|
@@ -1607,6 +1631,8 @@ function listConfig(options = {}, registry = CONFIG_SCHEMA) {
|
|
|
1607
1631
|
description: def.description,
|
|
1608
1632
|
scopes: def.scopes,
|
|
1609
1633
|
...def.manageCommand ? { manageCommand: def.manageCommand } : {},
|
|
1634
|
+
...describeExpectedValue(def) ? { expected: describeExpectedValue(def) } : {},
|
|
1635
|
+
...def.example ? { example: def.example } : {},
|
|
1610
1636
|
effective: getConfigValue(def, options),
|
|
1611
1637
|
project: readScopeValue(def, "project", options),
|
|
1612
1638
|
global: readScopeValue(def, "global", options)
|
|
@@ -11055,6 +11081,7 @@ the raw value stored at each scope.`);
|
|
|
11055
11081
|
}
|
|
11056
11082
|
function scopeDetail(e) {
|
|
11057
11083
|
const parts = [`scopes: ${e.scopes.join(", ")}`];
|
|
11084
|
+
if (e.expected) parts.push(`value: ${e.expected}${e.example ? `, e.g. ${e.example}` : ""}`);
|
|
11058
11085
|
if (e.project !== void 0) parts.push(`project=${formatValuePlain(e.project)}`);
|
|
11059
11086
|
if (e.global !== void 0) parts.push(`global=${formatValuePlain(e.global)}`);
|
|
11060
11087
|
return parts.join(" \xB7 ");
|
|
@@ -11119,7 +11146,7 @@ parsed (e.g. \`true\`, \`42\`, \`["a","b"]\`); anything else is stored as a stri
|
|
|
11119
11146
|
if (warning) console.error(import_picocolors2.default.yellow(warning));
|
|
11120
11147
|
console.log(`Set ${import_picocolors2.default.bold(key)} = ${formatValuePlain(stored)} (${scopeLabel(targetScope)}).`);
|
|
11121
11148
|
} catch (err) {
|
|
11122
|
-
reportError(err);
|
|
11149
|
+
reportError(err, () => suggestCorrectedSet(err, key, rawValue, scope));
|
|
11123
11150
|
}
|
|
11124
11151
|
}
|
|
11125
11152
|
function cmdUnset(argv) {
|
|
@@ -11212,7 +11239,20 @@ function formatValue(value) {
|
|
|
11212
11239
|
}
|
|
11213
11240
|
return formatValuePlain(value);
|
|
11214
11241
|
}
|
|
11215
|
-
function
|
|
11242
|
+
function quoteForShell(value) {
|
|
11243
|
+
if (/^[A-Za-z0-9._/@:+-]+$/.test(value)) return value;
|
|
11244
|
+
return `'${value.replace(/'/g, `'\\''`)}'`;
|
|
11245
|
+
}
|
|
11246
|
+
function suggestCorrectedSet(err, key, rawValue, scope) {
|
|
11247
|
+
if (!(err instanceof ConfigValidationError)) return null;
|
|
11248
|
+
const def = getConfigDefinition(key);
|
|
11249
|
+
if (!def) return null;
|
|
11250
|
+
const wrapped = def.parse([rawValue]);
|
|
11251
|
+
if (wrapped === void 0) return null;
|
|
11252
|
+
const scopeFlag = scope ? ` --scope ${scope}` : "";
|
|
11253
|
+
return `argent config set ${key} ${quoteForShell(JSON.stringify([rawValue]))}${scopeFlag}`;
|
|
11254
|
+
}
|
|
11255
|
+
function reportError(err, suggest) {
|
|
11216
11256
|
if (err instanceof ConfigManagedElsewhereError) {
|
|
11217
11257
|
console.error(`Error: ${err.message} Use \`${err.command}\` instead.`);
|
|
11218
11258
|
} else if (err instanceof UnknownConfigKeyError || err instanceof ConfigScopeError || err instanceof ConfigValidationError) {
|
|
@@ -11220,6 +11260,15 @@ function reportError(err) {
|
|
|
11220
11260
|
if (err instanceof UnknownConfigKeyError) {
|
|
11221
11261
|
console.error(`Run \`argent config list\` to see available keys.`);
|
|
11222
11262
|
}
|
|
11263
|
+
if (err instanceof ConfigValidationError) {
|
|
11264
|
+
const corrected = suggest?.() ?? null;
|
|
11265
|
+
if (corrected) {
|
|
11266
|
+
console.error(`Did you mean: ${corrected}`);
|
|
11267
|
+
} else if (err.example) {
|
|
11268
|
+
console.error(`Example: argent config set ${err.key} ${quoteForShell(err.example)}`);
|
|
11269
|
+
}
|
|
11270
|
+
console.error(`Run \`argent config list\` to see each key's expected value.`);
|
|
11271
|
+
}
|
|
11223
11272
|
} else {
|
|
11224
11273
|
console.error(`Error: ${err instanceof Error ? err.message : String(err)}`);
|
|
11225
11274
|
}
|
package/package.json
CHANGED