@vltpkg/cli-sdk 1.0.0-rc.18 → 1.0.0-rc.22

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.
Files changed (169) hide show
  1. package/package.json +52 -49
  2. package/dist/commands/bugs.d.ts +0 -18
  3. package/dist/commands/bugs.d.ts.map +0 -1
  4. package/dist/commands/bugs.js +0 -164
  5. package/dist/commands/bugs.js.map +0 -1
  6. package/dist/commands/build.d.ts +0 -25
  7. package/dist/commands/build.d.ts.map +0 -1
  8. package/dist/commands/build.js +0 -102
  9. package/dist/commands/build.js.map +0 -1
  10. package/dist/commands/cache.d.ts +0 -65
  11. package/dist/commands/cache.d.ts.map +0 -1
  12. package/dist/commands/cache.js +0 -257
  13. package/dist/commands/cache.js.map +0 -1
  14. package/dist/commands/ci.d.ts +0 -11
  15. package/dist/commands/ci.d.ts.map +0 -1
  16. package/dist/commands/ci.js +0 -32
  17. package/dist/commands/ci.js.map +0 -1
  18. package/dist/commands/config.d.ts +0 -6
  19. package/dist/commands/config.d.ts.map +0 -1
  20. package/dist/commands/config.js +0 -424
  21. package/dist/commands/config.js.map +0 -1
  22. package/dist/commands/docs.d.ts +0 -18
  23. package/dist/commands/docs.d.ts.map +0 -1
  24. package/dist/commands/docs.js +0 -154
  25. package/dist/commands/docs.js.map +0 -1
  26. package/dist/commands/exec-cache.d.ts +0 -49
  27. package/dist/commands/exec-cache.d.ts.map +0 -1
  28. package/dist/commands/exec-cache.js +0 -146
  29. package/dist/commands/exec-cache.js.map +0 -1
  30. package/dist/commands/exec-local.d.ts +0 -6
  31. package/dist/commands/exec-local.d.ts.map +0 -1
  32. package/dist/commands/exec-local.js +0 -24
  33. package/dist/commands/exec-local.js.map +0 -1
  34. package/dist/commands/exec.d.ts +0 -9
  35. package/dist/commands/exec.d.ts.map +0 -1
  36. package/dist/commands/exec.js +0 -87
  37. package/dist/commands/exec.js.map +0 -1
  38. package/dist/commands/help.d.ts +0 -4
  39. package/dist/commands/help.d.ts.map +0 -1
  40. package/dist/commands/help.js +0 -39
  41. package/dist/commands/help.js.map +0 -1
  42. package/dist/commands/init.d.ts +0 -8
  43. package/dist/commands/init.d.ts.map +0 -1
  44. package/dist/commands/init.js +0 -111
  45. package/dist/commands/init.js.map +0 -1
  46. package/dist/commands/install/reporter.d.ts +0 -11
  47. package/dist/commands/install/reporter.d.ts.map +0 -1
  48. package/dist/commands/install/reporter.js +0 -94
  49. package/dist/commands/install/reporter.js.map +0 -1
  50. package/dist/commands/install.d.ts +0 -28
  51. package/dist/commands/install.d.ts.map +0 -1
  52. package/dist/commands/install.js +0 -46
  53. package/dist/commands/install.js.map +0 -1
  54. package/dist/commands/list.d.ts +0 -15
  55. package/dist/commands/list.d.ts.map +0 -1
  56. package/dist/commands/list.js +0 -195
  57. package/dist/commands/list.js.map +0 -1
  58. package/dist/commands/login.d.ts +0 -4
  59. package/dist/commands/login.d.ts.map +0 -1
  60. package/dist/commands/login.js +0 -13
  61. package/dist/commands/login.js.map +0 -1
  62. package/dist/commands/logout.d.ts +0 -4
  63. package/dist/commands/logout.d.ts.map +0 -1
  64. package/dist/commands/logout.js +0 -13
  65. package/dist/commands/logout.js.map +0 -1
  66. package/dist/commands/pack.d.ts +0 -32
  67. package/dist/commands/pack.d.ts.map +0 -1
  68. package/dist/commands/pack.js +0 -147
  69. package/dist/commands/pack.js.map +0 -1
  70. package/dist/commands/pkg.d.ts +0 -7
  71. package/dist/commands/pkg.d.ts.map +0 -1
  72. package/dist/commands/pkg.js +0 -206
  73. package/dist/commands/pkg.js.map +0 -1
  74. package/dist/commands/publish.d.ts +0 -22
  75. package/dist/commands/publish.d.ts.map +0 -1
  76. package/dist/commands/publish.js +0 -245
  77. package/dist/commands/publish.js.map +0 -1
  78. package/dist/commands/query.d.ts +0 -16
  79. package/dist/commands/query.d.ts.map +0 -1
  80. package/dist/commands/query.js +0 -210
  81. package/dist/commands/query.js.map +0 -1
  82. package/dist/commands/run-exec.d.ts +0 -6
  83. package/dist/commands/run-exec.d.ts.map +0 -1
  84. package/dist/commands/run-exec.js +0 -14
  85. package/dist/commands/run-exec.js.map +0 -1
  86. package/dist/commands/run.d.ts +0 -6
  87. package/dist/commands/run.d.ts.map +0 -1
  88. package/dist/commands/run.js +0 -36
  89. package/dist/commands/run.js.map +0 -1
  90. package/dist/commands/token.d.ts +0 -4
  91. package/dist/commands/token.d.ts.map +0 -1
  92. package/dist/commands/token.js +0 -30
  93. package/dist/commands/token.js.map +0 -1
  94. package/dist/commands/uninstall.d.ts +0 -16
  95. package/dist/commands/uninstall.d.ts.map +0 -1
  96. package/dist/commands/uninstall.js +0 -26
  97. package/dist/commands/uninstall.js.map +0 -1
  98. package/dist/commands/update.d.ts +0 -14
  99. package/dist/commands/update.d.ts.map +0 -1
  100. package/dist/commands/update.js +0 -41
  101. package/dist/commands/update.js.map +0 -1
  102. package/dist/commands/version.d.ts +0 -26
  103. package/dist/commands/version.d.ts.map +0 -1
  104. package/dist/commands/version.js +0 -226
  105. package/dist/commands/version.js.map +0 -1
  106. package/dist/commands/whoami.d.ts +0 -13
  107. package/dist/commands/whoami.d.ts.map +0 -1
  108. package/dist/commands/whoami.js +0 -19
  109. package/dist/commands/whoami.js.map +0 -1
  110. package/dist/config/definition.d.ts +0 -396
  111. package/dist/config/definition.d.ts.map +0 -1
  112. package/dist/config/definition.js +0 -651
  113. package/dist/config/definition.js.map +0 -1
  114. package/dist/config/index.d.ts +0 -219
  115. package/dist/config/index.d.ts.map +0 -1
  116. package/dist/config/index.js +0 -489
  117. package/dist/config/index.js.map +0 -1
  118. package/dist/config/merge.d.ts +0 -4
  119. package/dist/config/merge.d.ts.map +0 -1
  120. package/dist/config/merge.js +0 -28
  121. package/dist/config/merge.js.map +0 -1
  122. package/dist/config/usage.d.ts +0 -19
  123. package/dist/config/usage.d.ts.map +0 -1
  124. package/dist/config/usage.js +0 -40
  125. package/dist/config/usage.js.map +0 -1
  126. package/dist/custom-help.d.ts +0 -9
  127. package/dist/custom-help.d.ts.map +0 -1
  128. package/dist/custom-help.js +0 -392
  129. package/dist/custom-help.js.map +0 -1
  130. package/dist/exec-command.d.ts +0 -53
  131. package/dist/exec-command.d.ts.map +0 -1
  132. package/dist/exec-command.js +0 -310
  133. package/dist/exec-command.js.map +0 -1
  134. package/dist/index.d.ts +0 -4
  135. package/dist/index.d.ts.map +0 -1
  136. package/dist/index.js +0 -73
  137. package/dist/index.js.map +0 -1
  138. package/dist/load-command.d.ts +0 -16
  139. package/dist/load-command.d.ts.map +0 -1
  140. package/dist/load-command.js +0 -21
  141. package/dist/load-command.js.map +0 -1
  142. package/dist/output.d.ts +0 -21
  143. package/dist/output.d.ts.map +0 -1
  144. package/dist/output.js +0 -126
  145. package/dist/output.js.map +0 -1
  146. package/dist/pack-tarball.d.ts +0 -22
  147. package/dist/pack-tarball.d.ts.map +0 -1
  148. package/dist/pack-tarball.js +0 -249
  149. package/dist/pack-tarball.js.map +0 -1
  150. package/dist/parse-add-remove-args.d.ts +0 -29
  151. package/dist/parse-add-remove-args.d.ts.map +0 -1
  152. package/dist/parse-add-remove-args.js +0 -104
  153. package/dist/parse-add-remove-args.js.map +0 -1
  154. package/dist/print-err.d.ts +0 -14
  155. package/dist/print-err.d.ts.map +0 -1
  156. package/dist/print-err.js +0 -178
  157. package/dist/print-err.js.map +0 -1
  158. package/dist/query-host-contexts.d.ts +0 -16
  159. package/dist/query-host-contexts.d.ts.map +0 -1
  160. package/dist/query-host-contexts.js +0 -135
  161. package/dist/query-host-contexts.js.map +0 -1
  162. package/dist/read-password.d.ts +0 -8
  163. package/dist/read-password.d.ts.map +0 -1
  164. package/dist/read-password.js +0 -33
  165. package/dist/read-password.js.map +0 -1
  166. package/dist/view.d.ts +0 -30
  167. package/dist/view.d.ts.map +0 -1
  168. package/dist/view.js +0 -31
  169. package/dist/view.js.map +0 -1
@@ -1,489 +0,0 @@
1
- /**
2
- * Module that handles all vlt configuration needs
3
- *
4
- * Project-level configs are set in a `vlt.json` file in the local project
5
- * if present. This will override the user-level configs in the appropriate
6
- * XDG config path.
7
- *
8
- * Command-specific configuration can be specified by putting options in a
9
- * field in the `command` object. For example:
10
- *
11
- * ```json
12
- * {
13
- * "registry": "https://registry.npmjs.org/",
14
- * "command": {
15
- * "publish": {
16
- * "registry": "http://registry.internal"
17
- * }
18
- * }
19
- * }
20
- * ```
21
- * @module
22
- */
23
- import { error } from '@vltpkg/error-cause';
24
- import { PackageInfoClient } from '@vltpkg/package-info';
25
- import { PackageJson } from '@vltpkg/package-json';
26
- import { resetCaches } from '@vltpkg/dep-id';
27
- import { getOptions } from '@vltpkg/spec';
28
- import { assertRecordStringString, assertRecordStringT, isRecordStringString, } from '@vltpkg/types';
29
- import { find, load, reload, save } from '@vltpkg/vlt-json';
30
- import { Monorepo } from '@vltpkg/workspaces';
31
- import { readFile, rm, writeFile } from 'node:fs/promises';
32
- import { dirname } from 'node:path';
33
- import { PathScurry } from 'path-scurry';
34
- import { commands, definition, getCommand, isRecordField, recordFields, } from "./definition.js";
35
- import { merge } from "./merge.js";
36
- export { commands, definition, isRecordField, recordFields, };
37
- export const kCustomInspect = Symbol.for('nodejs.util.inspect.custom');
38
- // turn a set of pairs into a Record object.
39
- // if a kv pair doesn't have a = character, set to `''`
40
- const reducePairs = (pairs) => {
41
- const record = {};
42
- for (const kv of pairs) {
43
- const eq = kv.indexOf('=');
44
- if (eq === -1)
45
- record[kv] = '';
46
- else {
47
- const key = kv.substring(0, eq);
48
- const val = kv.substring(eq + 1);
49
- record[key] = val;
50
- }
51
- }
52
- return record;
53
- };
54
- const isRecordFieldValue = (k, v) => Array.isArray(v) &&
55
- recordFields.includes(k);
56
- export const pairsToRecords = (obj) => {
57
- return Object.fromEntries(Object.entries(obj).map(([k, v]) => [
58
- k,
59
- k === 'command' && v && typeof v === 'object' ?
60
- Object.fromEntries(Object.entries(v).map(([k, v]) => [
61
- k,
62
- pairsToRecords(v),
63
- ]))
64
- : isRecordFieldValue(k, v) ? reducePairs(v)
65
- : v,
66
- ]));
67
- };
68
- export const recordsToPairs = (obj) => {
69
- return Object.fromEntries(Object.entries(obj)
70
- .filter(([k]) => !(k === 'scurry' ||
71
- k === 'packageJson' ||
72
- k === 'monorepo' ||
73
- k === 'projectRoot' ||
74
- k === 'packageInfo'))
75
- .map(([k, v]) => [
76
- k,
77
- k === 'command' && v && typeof v === 'object' ?
78
- recordsToPairs(v)
79
- : (!v ||
80
- typeof v !== 'object' ||
81
- Array.isArray(v) ||
82
- !isRecordField(k)) ?
83
- v
84
- : Object.entries(v).map(([k, v]) => `${k}=${v}`),
85
- ]));
86
- };
87
- const kRecord = Symbol('parsed key=value record');
88
- /**
89
- * Class that handles configuration for vlt.
90
- *
91
- * Call {@link Config.load} to get one of these.
92
- */
93
- export class Config {
94
- /**
95
- * The {@link https://npmjs.com/jackspeak | JackSpeak} object
96
- * representing vlt's configuration
97
- */
98
- jack;
99
- /**
100
- * Parsed values in effect
101
- */
102
- values;
103
- /**
104
- * Command-specific config values
105
- */
106
- commandValues = {};
107
- /**
108
- * A flattened object of the parsed configuration
109
- */
110
- get options() {
111
- if (this.#options)
112
- return this.#options;
113
- const scurry = new PathScurry(this.projectRoot);
114
- const packageJson = new PackageJson();
115
- const asRecords = pairsToRecords(this.parse().values);
116
- const extras = {
117
- projectRoot: this.projectRoot,
118
- scurry,
119
- packageJson,
120
- monorepo: Monorepo.maybeLoad(this.projectRoot, {
121
- scurry,
122
- packageJson,
123
- load: {
124
- paths: asRecords.workspace,
125
- groups: asRecords['workspace-group'],
126
- },
127
- }),
128
- catalog: load('catalog', assertRecordStringString),
129
- catalogs: load('catalogs', o => assertRecordStringT(o, isRecordStringString, 'Record<string, Record<string, string>>')),
130
- };
131
- const options = Object.assign(asRecords, extras);
132
- // Ensure spec-related options (registries, jsr-registries, git hosts, etc.)
133
- // are always filled with defaults. Some downstream libraries (eg. @vltpkg/dep-id)
134
- // expect these defaults to be present even when the user didn't configure them.
135
- Object.assign(options, getOptions(options));
136
- this.#options = Object.assign(options, {
137
- packageInfo: new PackageInfoClient(options),
138
- [kCustomInspect]() {
139
- return Object.fromEntries(Object.entries(options).filter(([k]) => k !== 'monorepo' &&
140
- k !== 'scurry' &&
141
- k !== 'packageJson' &&
142
- k !== 'packageInfo'));
143
- },
144
- });
145
- return this.#options;
146
- }
147
- /**
148
- * Reset the options value, optionally setting a new project root
149
- * to recalculate the options.
150
- */
151
- resetOptions(projectRoot = process.cwd()) {
152
- this.projectRoot = projectRoot;
153
- this.#options = undefined;
154
- resetCaches();
155
- }
156
- // memoized options() getter value
157
- #options;
158
- /**
159
- * positional arguments to the vlt process
160
- */
161
- positionals;
162
- /**
163
- * Original arguments used for parsing (stored for reload purposes)
164
- * @internal
165
- */
166
- #originalArgs;
167
- /**
168
- * The root of the project where a vlt.json, vlt.json,
169
- * package.json, or .git was found. Not necessarily the `process.cwd()`,
170
- * though that is the default location.
171
- *
172
- * Never walks up as far as `$HOME`. So for example, if a project is in
173
- * `~/projects/xyz`, then the highest dir it will check is `~/projects`
174
- */
175
- projectRoot;
176
- /**
177
- * `Record<alias, canonical name>` to dereference command aliases.
178
- */
179
- commands;
180
- /**
181
- * Which command name to use for overriding with command-specific values,
182
- * determined from the argv when parse() is called.
183
- */
184
- command;
185
- constructor(jack = definition, projectRoot = process.cwd()) {
186
- this.projectRoot = projectRoot;
187
- this.commands = commands;
188
- this.jack = jack;
189
- }
190
- /**
191
- * Parse the arguments and set configuration and positionals accordingly.
192
- */
193
- parse(args = process.argv) {
194
- if (isParsed(this))
195
- return this;
196
- // Store the original args for potential reload
197
- this.#originalArgs = [...args];
198
- this.jack.loadEnvDefaults();
199
- const p = this.jack.parseRaw(args);
200
- const fallback = getCommand(p.values['fallback-command']);
201
- this.command = getCommand(p.positionals[0]);
202
- const cmdOrFallback = this.command ?? fallback;
203
- const cmdSpecific = cmdOrFallback && this.commandValues[cmdOrFallback];
204
- if (cmdSpecific) {
205
- this.jack.setConfigValues(recordsToPairs(cmdSpecific));
206
- }
207
- // ok, applied cmd-specific defaults, do rest of the parse
208
- this.jack.applyDefaults(p);
209
- this.jack.writeEnv(p);
210
- if (this.command)
211
- p.positionals.shift();
212
- else
213
- this.command = getCommand(p.values['fallback-command']);
214
- Object.assign(this, p);
215
- /* c8 ignore start - unpossible */
216
- if (!isParsed(this))
217
- throw error('failed to parse config');
218
- /* c8 ignore stop */
219
- return this;
220
- }
221
- /**
222
- * Get a `key=value` list option value as an object.
223
- *
224
- * For example, a list option with a vlaue of `['key=value', 'xyz=as=df' ]`
225
- * would be returned as `{key: 'value', xyz: 'as=df'}`
226
- *
227
- * Results are memoized, so subsequent calls for the same key will return the
228
- * same object. If new strings are added to the list, then the memoized value
229
- * is *not* updated, so only use once configurations have been fully loaded.
230
- *
231
- * If the config value is not set at all, an empty object is returned.
232
- */
233
- getRecord(k) {
234
- const pairs = this.get(k);
235
- if (!pairs)
236
- return {};
237
- if (pairs[kRecord])
238
- return pairs[kRecord];
239
- const kv = pairs.reduce((kv, pair) => {
240
- const eq = pair.indexOf('=');
241
- if (eq === -1)
242
- return kv;
243
- const key = pair.substring(0, eq);
244
- const val = pair.substring(eq + 1);
245
- kv[key] = val;
246
- return kv;
247
- }, {});
248
- Object.assign(pairs, { [kRecord]: kv });
249
- return kv;
250
- }
251
- /**
252
- * Get a configuration value.
253
- *
254
- * Note: `key=value` pair configs are returned as a string array. To get them
255
- * as an object, use {@link Config#getRecord}.
256
- */
257
- get(k) {
258
- /* c8 ignore next -- impossible but TS doesn't know that */
259
- return (this.values ?? this.parse().values)[k];
260
- }
261
- /**
262
- * Write the config values to the user or project config file.
263
- */
264
- async writeConfigFile(which, values) {
265
- save('config', pairsToRecords(values), which);
266
- await this.#reloadConfig();
267
- }
268
- /**
269
- * Fold in the provided fields with the existing properties
270
- * in the config file.
271
- */
272
- async addConfigToFile(which, values) {
273
- return this.writeConfigFile(which, merge((await this.#maybeLoadConfigFile(which)) ?? {}, values));
274
- }
275
- // called in this weird bound way so that it can be used by the
276
- // vlt-json config loading module.
277
- #validator = function (c, file) {
278
- this.#validateConfig(c, file);
279
- }.bind(this);
280
- #validateConfig(c, file) {
281
- if (!c || typeof c !== 'object' || Array.isArray(c)) {
282
- throw error('invalid config, expected object', {
283
- path: file,
284
- found: c,
285
- wanted: 'ConfigFileData',
286
- });
287
- }
288
- const { command, ...values } = recordsToPairs(c);
289
- // Validate registries keys don't contain reserved ~ character
290
- const registries = c.registries;
291
- if (registries && typeof registries === 'object') {
292
- const registriesObj = Array.isArray(registries) ?
293
- reducePairs(registries)
294
- : registries;
295
- for (const key of Object.keys(registriesObj)) {
296
- if (key === '' || key.includes('~')) {
297
- throw error('Reserved character found in registries name', {
298
- path: file,
299
- found: key,
300
- });
301
- }
302
- }
303
- }
304
- if (command) {
305
- for (const [c, opts] of Object.entries(command)) {
306
- const cmd = getCommand(c);
307
- if (cmd && opts && typeof opts === 'object') {
308
- // Validate registries in command-specific config
309
- const cmdRegistries = opts.registries;
310
- if (cmdRegistries && typeof cmdRegistries === 'object') {
311
- const cmdRegistriesObj = Array.isArray(cmdRegistries) ?
312
- reducePairs(cmdRegistries)
313
- : cmdRegistries;
314
- for (const key of Object.keys(cmdRegistriesObj)) {
315
- if (key === '' || key.includes('~')) {
316
- throw error('Reserved character found in registries name', {
317
- path: file,
318
- found: key,
319
- });
320
- }
321
- }
322
- }
323
- this.commandValues[cmd] = merge(this.commandValues[cmd] ?? {}, opts);
324
- }
325
- }
326
- }
327
- this.jack.setConfigValues(values, file);
328
- }
329
- /**
330
- * if the file exists, parse and load it. returns object if data was
331
- * loaded, or undefined if not.
332
- */
333
- async #maybeLoadConfigFile(whichConfig) {
334
- return load('config', this.#validator, whichConfig);
335
- }
336
- /**
337
- * Deletes the specified config fields from the named file
338
- * Returns `true` if anything was changed.
339
- */
340
- async deleteConfigKeys(which, fields) {
341
- const data = await this.#maybeLoadConfigFile(which);
342
- if (!data)
343
- return false;
344
- let didSomething = false;
345
- for (const f of fields) {
346
- const [key, ...sk] = f.split('.');
347
- const subs = sk.join('.');
348
- const k = key;
349
- const v = data[k];
350
- if (v === undefined)
351
- continue;
352
- if (subs && v && typeof v === 'object') {
353
- if (Array.isArray(v)) {
354
- const i = v.findIndex(subvalue => subvalue.startsWith(`${subs}=`));
355
- if (i !== -1) {
356
- if (v.length === 1)
357
- delete data[k];
358
- else
359
- v.splice(i, 1);
360
- didSomething = true;
361
- }
362
- }
363
- else {
364
- if (v[subs] !== undefined) {
365
- delete v[subs];
366
- if (Object.keys(v).length === 0)
367
- delete data[k];
368
- didSomething = true;
369
- }
370
- }
371
- }
372
- else {
373
- didSomething = true;
374
- delete data[k];
375
- }
376
- }
377
- if (didSomething)
378
- await this.writeConfigFile(which, data);
379
- return didSomething;
380
- }
381
- /**
382
- * Edit the user or project configuration file.
383
- *
384
- * If the file isn't present, then it starts with `{}` so the user has
385
- * something to work with.
386
- *
387
- * If the result is not valid, or no config settings are contained in the
388
- * file after editing, then it's restored to what it was before, which might
389
- * mean deleting the file.
390
- */
391
- async editConfigFile(which, edit) {
392
- // load the file as a backup
393
- // call the edit function
394
- // reload it
395
- const file = find(which);
396
- const backup = await readFile(file, 'utf8').catch(() => undefined);
397
- if (!backup) {
398
- await writeFile(file, JSON.stringify({ config: {} }, null, 2) + '\n');
399
- }
400
- let valid = false;
401
- try {
402
- await edit(file);
403
- // force it to reload the file and validate it again
404
- // if this fails, we roll back.
405
- const result = reload('config', which);
406
- save('config', result ?? {}, which);
407
- valid = true;
408
- }
409
- finally {
410
- if (!valid) {
411
- // TODO: maybe write the file to a re-edit backup location?
412
- // then you could do `vlt config edit retry` or something.
413
- if (backup) {
414
- await writeFile(file, backup);
415
- reload(which);
416
- }
417
- else {
418
- await rm(file, { force: true });
419
- }
420
- }
421
- }
422
- }
423
- /**
424
- * Find the local config file and load both it and the user-level config in
425
- * the XDG config home.
426
- */
427
- async loadConfigFile() {
428
- await this.#maybeLoadConfigFile('user');
429
- this.projectRoot = dirname(find('project', this.projectRoot));
430
- await this.#maybeLoadConfigFile('project');
431
- return this;
432
- }
433
- /**
434
- * Clear cached config values to force re-reading from updated files.
435
- * @internal
436
- */
437
- async #reloadConfig() {
438
- // Clear the memoized options to force recalculation
439
- this.#options = undefined;
440
- }
441
- /**
442
- * Force a complete reload of config files from disk.
443
- * This clears all caches and re-reads config files.
444
- * Useful for long-running processes that need to pick up config changes.
445
- */
446
- async reloadFromDisk() {
447
- // Clear the memoized options to force recalculation
448
- this.#options = undefined;
449
- // Clear the parsed state to force re-parsing
450
- // This is crucial because parse() returns early if already parsed
451
- this.values = undefined;
452
- this.positionals = undefined;
453
- this.command = undefined;
454
- // Clear vlt-json caches for both user and project configs
455
- // This ensures that the next time config files are read, they'll be re-read from disk
456
- const { unload } = await import('@vltpkg/vlt-json');
457
- unload('user');
458
- unload('project');
459
- // Force reload of config files by calling the load methods again
460
- // This will re-read the files and re-apply them to the jack parser
461
- await this.#maybeLoadConfigFile('user');
462
- await this.#maybeLoadConfigFile('project');
463
- // Re-parse to pick up the updated config values using the original arguments
464
- this.parse(this.#originalArgs);
465
- }
466
- /**
467
- * cache of the loaded config
468
- */
469
- static #loaded;
470
- /**
471
- * Load the configuration and return a Promise to a
472
- * {@link Config} object
473
- */
474
- static async load(projectRoot = process.cwd(), argv = process.argv,
475
- /**
476
- * only used in tests, resets the memoization
477
- * @internal
478
- */
479
- reload = false) {
480
- if (this.#loaded && !reload)
481
- return this.#loaded;
482
- const a = new Config(definition, projectRoot);
483
- const b = await a.loadConfigFile();
484
- this.#loaded = b.parse(argv);
485
- return this.#loaded;
486
- }
487
- }
488
- const isParsed = (c) => !!(c.values && c.positionals && c.command);
489
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/config/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAC3C,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;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AC,CAAC,KAAK,CAAC,IAAI,CAAiB,CAAA;QAC5C,OAAO,IAAI,CAAC,OAAO,CAAA;IACrB,CAAC;CACF;AAED,MAAM,QAAQ,GAAG,CAAC,CAAS,EAAqB,EAAE,CAChD,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,IAAI,CAAC,CAAC,WAAW,IAAI,CAAC,CAAC,OAAO,CAAC,CAAA","sourcesContent":["/**\n * Module that handles all vlt configuration needs\n *\n * Project-level configs are set in a `vlt.json` file in the local project\n * if present. This will override the user-level configs in the appropriate\n * XDG config path.\n *\n * Command-specific configuration can be specified by putting options in a\n * field in the `command` object. For example:\n *\n * ```json\n * {\n * \"registry\": \"https://registry.npmjs.org/\",\n * \"command\": {\n * \"publish\": {\n * \"registry\": \"http://registry.internal\"\n * }\n * }\n * }\n * ```\n * @module\n */\n\nimport { error } from '@vltpkg/error-cause'\nimport { PackageInfoClient } from '@vltpkg/package-info'\nimport { PackageJson } from '@vltpkg/package-json'\nimport { resetCaches } from '@vltpkg/dep-id'\nimport type { SpecOptions } from '@vltpkg/spec'\nimport { getOptions } from '@vltpkg/spec'\nimport {\n assertRecordStringString,\n assertRecordStringT,\n isRecordStringString,\n} from '@vltpkg/types'\nimport type { Validator, WhichConfig } from '@vltpkg/vlt-json'\nimport { find, load, reload, save } from '@vltpkg/vlt-json'\nimport { Monorepo } from '@vltpkg/workspaces'\nimport type { Jack, OptionsResults, Unwrap } from 'jackspeak'\nimport { readFile, rm, writeFile } from 'node:fs/promises'\nimport { dirname } from 'node:path'\nimport { PathScurry } from 'path-scurry'\nimport type { Commands, RecordField } from './definition.ts'\nimport {\n commands,\n definition,\n getCommand,\n isRecordField,\n recordFields,\n} from './definition.ts'\nimport { merge } from './merge.ts'\nexport {\n commands,\n definition,\n isRecordField,\n recordFields,\n type Commands,\n}\n\nexport const kCustomInspect = Symbol.for('nodejs.util.inspect.custom')\n\nexport type RecordPairs = Record<string, unknown>\nexport type RecordString = Record<string, string>\n\n// turn a set of pairs into a Record object.\n// if a kv pair doesn't have a = character, set to `''`\nconst reducePairs = <T extends string[]>(\n pairs: T,\n): RecordString | T => {\n const record: RecordString = {}\n for (const kv of pairs) {\n const eq = kv.indexOf('=')\n if (eq === -1) record[kv] = ''\n else {\n const key = kv.substring(0, eq)\n const val = kv.substring(eq + 1)\n record[key] = val\n }\n }\n return record\n}\n\nconst isRecordFieldValue = (k: string, v: unknown): v is string[] =>\n Array.isArray(v) &&\n recordFields.includes(k as (typeof recordFields)[number])\n\nexport type PairsAsRecords = ConfigOptionsNoExtras & {\n command?: {\n [k in keyof Commands]?: ConfigOptionsNoExtras\n }\n}\n\nexport const pairsToRecords = (\n obj:\n | NonNullable<ConfigFileData>\n | OptionsResults<ConfigDefinitions>,\n): PairsAsRecords => {\n return Object.fromEntries(\n Object.entries(obj).map(([k, v]) => [\n k,\n k === 'command' && v && typeof v === 'object' ?\n Object.fromEntries(\n Object.entries(v).map(([k, v]) => [\n k,\n pairsToRecords(v as NonNullable<ConfigFileData>),\n ]),\n )\n : isRecordFieldValue(k, v) ? reducePairs(v)\n : v,\n ]),\n // hard cast because TS can't see through the entries/fromEntries\n ) as unknown as PairsAsRecords\n}\n\nexport const recordsToPairs = (obj: RecordPairs): RecordPairs => {\n return Object.fromEntries(\n Object.entries(obj)\n .filter(\n ([k]) =>\n !(\n k === 'scurry' ||\n k === 'packageJson' ||\n k === 'monorepo' ||\n k === 'projectRoot' ||\n k === 'packageInfo'\n ),\n )\n .map(([k, v]) => [\n k,\n k === 'command' && v && typeof v === 'object' ?\n recordsToPairs(v as RecordPairs)\n : (\n !v ||\n typeof v !== 'object' ||\n Array.isArray(v) ||\n !isRecordField(k)\n ) ?\n v\n : Object.entries(v).map(([k, v]) => `${k}=${v}`),\n ]),\n )\n}\n\nconst kRecord = Symbol('parsed key=value record')\n\nexport type ConfigDataNoCommand = {\n [k in keyof OptionsResults<ConfigDefinitions>]?: OptionsResults<ConfigDefinitions>[k]\n}\n\n/**\n * Config data can be any options, and also a 'command' field which\n * contains command names and override options for that command.\n */\nexport type ConfigData = ConfigDataNoCommand & {\n command?: {\n [k in keyof Commands]?: ConfigDataNoCommand\n }\n}\n\nexport type ConfigFileDataNoCommand = {\n [k in keyof ConfigDataNoCommand]: k extends (\n OptListKeys<ConfigDataNoCommand>\n ) ?\n RecordString | string[]\n : ConfigDataNoCommand[k]\n}\n\n/**\n * Config data as it appears in the config field of the vlt.json, with kv pair\n * lists stored as `Record<string, string>` and\n */\nexport type ConfigFileData = ConfigFileDataNoCommand & {\n command?: {\n [k in keyof Commands]?: ConfigFileDataNoCommand\n }\n}\n\nexport type ConfigOptionsNoExtras = {\n [k in keyof OptionsResults<ConfigDefinitions>]: k extends (\n RecordField\n ) ?\n RecordString\n : k extends 'command' ? never\n : OptionsResults<ConfigDefinitions>[k]\n}\n\nexport type ConfigOptions = ConfigOptionsNoExtras &\n Pick<SpecOptions, 'catalog' | 'catalogs'> & {\n packageJson: PackageJson\n scurry: PathScurry\n projectRoot: string\n monorepo?: Monorepo\n packageInfo: PackageInfoClient\n }\n\n/**\n * The base config definition set as a type\n */\nexport type ConfigDefinitions = Unwrap<typeof definition>\n\nexport type StringListKeys<O> = {\n [k in keyof O]: O[k] extends string[] | undefined ? k : never\n}\nexport type OptListKeys<O> = Exclude<\n StringListKeys<O>[keyof StringListKeys<O>],\n undefined\n>\n\n/**\n * Class that handles configuration for vlt.\n *\n * Call {@link Config.load} to get one of these.\n */\nexport class Config {\n /**\n * The {@link https://npmjs.com/jackspeak | JackSpeak} object\n * representing vlt's configuration\n */\n jack: Jack<ConfigDefinitions>\n\n /**\n * Parsed values in effect\n */\n values?: OptionsResults<ConfigDefinitions>\n\n /**\n * Command-specific config values\n */\n commandValues: {\n [cmd in Commands[keyof Commands]]?: ConfigData\n } = {}\n\n /**\n * A flattened object of the parsed configuration\n */\n get options(): ConfigOptions {\n if (this.#options) return this.#options\n const scurry = new PathScurry(this.projectRoot)\n const packageJson = new PackageJson()\n const asRecords = pairsToRecords(this.parse().values)\n const extras = {\n projectRoot: this.projectRoot,\n scurry,\n packageJson,\n monorepo: Monorepo.maybeLoad(this.projectRoot, {\n scurry,\n packageJson,\n load: {\n paths: asRecords.workspace,\n groups: asRecords['workspace-group'],\n },\n }),\n catalog: load<Record<string, string>>(\n 'catalog',\n assertRecordStringString,\n ),\n catalogs: load<Record<string, Record<string, string>>>(\n 'catalogs',\n o =>\n assertRecordStringT(\n o,\n isRecordStringString,\n 'Record<string, Record<string, string>>',\n ),\n ),\n }\n\n const options: Omit<ConfigOptions, 'packageInfo'> = Object.assign(\n asRecords,\n extras,\n )\n\n // Ensure spec-related options (registries, jsr-registries, git hosts, etc.)\n // are always filled with defaults. Some downstream libraries (eg. @vltpkg/dep-id)\n // expect these defaults to be present even when the user didn't configure them.\n Object.assign(\n options,\n getOptions(\n options as unknown as SpecOptions,\n ) as unknown as SpecOptions,\n )\n\n this.#options = Object.assign(options, {\n packageInfo: new PackageInfoClient(options),\n [kCustomInspect]() {\n return Object.fromEntries(\n Object.entries(options).filter(\n ([k]) =>\n k !== 'monorepo' &&\n k !== 'scurry' &&\n k !== 'packageJson' &&\n k !== 'packageInfo',\n ),\n )\n },\n })\n return this.#options\n }\n\n /**\n * Reset the options value, optionally setting a new project root\n * to recalculate the options.\n */\n resetOptions(projectRoot: string = process.cwd()) {\n this.projectRoot = projectRoot\n this.#options = undefined\n resetCaches()\n }\n\n // memoized options() getter value\n #options?: ConfigOptions\n\n /**\n * positional arguments to the vlt process\n */\n positionals?: string[]\n\n /**\n * Original arguments used for parsing (stored for reload purposes)\n * @internal\n */\n #originalArgs?: string[]\n\n /**\n * The root of the project where a vlt.json, vlt.json,\n * package.json, or .git was found. Not necessarily the `process.cwd()`,\n * though that is the default location.\n *\n * Never walks up as far as `$HOME`. So for example, if a project is in\n * `~/projects/xyz`, then the highest dir it will check is `~/projects`\n */\n projectRoot: string\n\n /**\n * `Record<alias, canonical name>` to dereference command aliases.\n */\n commands: Commands\n\n /**\n * Which command name to use for overriding with command-specific values,\n * determined from the argv when parse() is called.\n */\n command?: Commands[keyof Commands]\n\n constructor(\n jack: Jack<ConfigDefinitions> = definition,\n projectRoot = process.cwd(),\n ) {\n this.projectRoot = projectRoot\n this.commands = commands\n this.jack = jack\n }\n\n /**\n * Parse the arguments and set configuration and positionals accordingly.\n */\n parse(args: string[] = process.argv): this & ParsedConfig {\n if (isParsed(this)) return this\n\n // Store the original args for potential reload\n this.#originalArgs = [...args]\n\n this.jack.loadEnvDefaults()\n const p = this.jack.parseRaw(args)\n\n const fallback = getCommand(p.values['fallback-command'])\n this.command = getCommand(p.positionals[0])\n\n const cmdOrFallback = this.command ?? fallback\n const cmdSpecific =\n cmdOrFallback && this.commandValues[cmdOrFallback]\n if (cmdSpecific) {\n this.jack.setConfigValues(recordsToPairs(cmdSpecific))\n }\n\n // ok, applied cmd-specific defaults, do rest of the parse\n this.jack.applyDefaults(p)\n this.jack.writeEnv(p)\n\n if (this.command) p.positionals.shift()\n else this.command = getCommand(p.values['fallback-command'])\n\n Object.assign(this, p)\n\n /* c8 ignore start - unpossible */\n if (!isParsed(this)) throw error('failed to parse config')\n /* c8 ignore stop */\n\n return this\n }\n\n /**\n * Get a `key=value` list option value as an object.\n *\n * For example, a list option with a vlaue of `['key=value', 'xyz=as=df' ]`\n * would be returned as `{key: 'value', xyz: 'as=df'}`\n *\n * Results are memoized, so subsequent calls for the same key will return the\n * same object. If new strings are added to the list, then the memoized value\n * is *not* updated, so only use once configurations have been fully loaded.\n *\n * If the config value is not set at all, an empty object is returned.\n */\n getRecord(k: OptListKeys<ConfigData>): RecordString {\n const pairs = this.get(k) as\n | (string[] & { [kRecord]?: RecordString })\n | undefined\n if (!pairs) return {}\n if (pairs[kRecord]) return pairs[kRecord]\n const kv = pairs.reduce((kv: RecordString, pair) => {\n const eq = pair.indexOf('=')\n if (eq === -1) return kv\n const key = pair.substring(0, eq)\n const val = pair.substring(eq + 1)\n kv[key] = val\n return kv\n }, {})\n Object.assign(pairs, { [kRecord]: kv })\n return kv\n }\n\n /**\n * Get a configuration value.\n *\n * Note: `key=value` pair configs are returned as a string array. To get them\n * as an object, use {@link Config#getRecord}.\n */\n get<K extends keyof OptionsResults<ConfigDefinitions>>(\n k: K,\n ): OptionsResults<ConfigDefinitions>[K] {\n /* c8 ignore next -- impossible but TS doesn't know that */\n return (this.values ?? this.parse().values)[k]\n }\n\n /**\n * Write the config values to the user or project config file.\n */\n async writeConfigFile(\n this: LoadedConfig,\n which: WhichConfig,\n values: NonNullable<ConfigFileData>,\n ) {\n save('config', pairsToRecords(values), which)\n await this.#reloadConfig()\n }\n\n /**\n * Fold in the provided fields with the existing properties\n * in the config file.\n */\n async addConfigToFile(\n this: LoadedConfig,\n which: WhichConfig,\n values: NonNullable<ConfigFileData>,\n ) {\n return this.writeConfigFile(\n which,\n merge((await this.#maybeLoadConfigFile(which)) ?? {}, values),\n )\n }\n\n // called in this weird bound way so that it can be used by the\n // vlt-json config loading module.\n #validator: Validator<ConfigFileData> = function (\n this: Config,\n c: unknown,\n file: string,\n ) {\n this.#validateConfig(c, file)\n }.bind(this)\n\n #validateConfig(\n c: unknown,\n file: string,\n ): asserts c is ConfigFileData {\n if (!c || typeof c !== 'object' || Array.isArray(c)) {\n throw error('invalid config, expected object', {\n path: file,\n found: c,\n wanted: 'ConfigFileData',\n })\n }\n\n const { command, ...values } = recordsToPairs(c as RecordPairs)\n\n // Validate registries keys don't contain reserved ~ character\n const registries = (c as RecordPairs).registries\n if (registries && typeof registries === 'object') {\n const registriesObj =\n Array.isArray(registries) ?\n reducePairs(registries)\n : registries\n for (const key of Object.keys(registriesObj)) {\n if (key === '' || key.includes('~')) {\n throw error('Reserved character found in registries name', {\n path: file,\n found: key,\n })\n }\n }\n }\n\n if (command) {\n for (const [c, opts] of Object.entries(command)) {\n const cmd = getCommand(c)\n if (cmd && opts && typeof opts === 'object') {\n // Validate registries in command-specific config\n const cmdRegistries = (opts as RecordPairs).registries\n if (cmdRegistries && typeof cmdRegistries === 'object') {\n const cmdRegistriesObj =\n Array.isArray(cmdRegistries) ?\n reducePairs(cmdRegistries)\n : cmdRegistries\n for (const key of Object.keys(cmdRegistriesObj)) {\n if (key === '' || key.includes('~')) {\n throw error(\n 'Reserved character found in registries name',\n {\n path: file,\n found: key,\n },\n )\n }\n }\n }\n\n this.commandValues[cmd] = merge<ConfigData>(\n this.commandValues[cmd] ?? ({} as ConfigData),\n opts as ConfigData,\n )\n }\n }\n }\n this.jack.setConfigValues(values, file)\n }\n\n /**\n * if the file exists, parse and load it. returns object if data was\n * loaded, or undefined if not.\n */\n async #maybeLoadConfigFile(whichConfig: WhichConfig) {\n return load('config', this.#validator, whichConfig)\n }\n\n /**\n * Deletes the specified config fields from the named file\n * Returns `true` if anything was changed.\n */\n async deleteConfigKeys(\n this: LoadedConfig,\n which: WhichConfig,\n fields: string[],\n ) {\n const data = await this.#maybeLoadConfigFile(which)\n if (!data) return false\n let didSomething = false\n for (const f of fields) {\n const [key, ...sk] = f.split('.') as [\n h: string,\n ...rest: string[],\n ]\n const subs = sk.join('.')\n const k = key as keyof ConfigDefinitions\n const v = data[k]\n if (v === undefined) continue\n if (subs && v && typeof v === 'object') {\n if (Array.isArray(v)) {\n const i = v.findIndex(subvalue =>\n subvalue.startsWith(`${subs}=`),\n )\n if (i !== -1) {\n if (v.length === 1) delete data[k]\n else v.splice(i, 1)\n didSomething = true\n }\n } else {\n if (v[subs] !== undefined) {\n delete v[subs]\n if (Object.keys(v).length === 0) delete data[k]\n didSomething = true\n }\n }\n } else {\n didSomething = true\n delete data[k]\n }\n }\n if (didSomething) await this.writeConfigFile(which, data)\n return didSomething\n }\n\n /**\n * Edit the user or project configuration file.\n *\n * If the file isn't present, then it starts with `{}` so the user has\n * something to work with.\n *\n * If the result is not valid, or no config settings are contained in the\n * file after editing, then it's restored to what it was before, which might\n * mean deleting the file.\n */\n async editConfigFile(\n this: LoadedConfig,\n which: WhichConfig,\n edit: (file: string) => Promise<void> | void,\n ) {\n // load the file as a backup\n // call the edit function\n // reload it\n const file = find(which)\n const backup = await readFile(file, 'utf8').catch(() => undefined)\n if (!backup) {\n await writeFile(\n file,\n JSON.stringify({ config: {} }, null, 2) + '\\n',\n )\n }\n let valid = false\n try {\n await edit(file)\n // force it to reload the file and validate it again\n // if this fails, we roll back.\n const result = reload('config', which)\n save('config', result ?? {}, which)\n valid = true\n } finally {\n if (!valid) {\n // TODO: maybe write the file to a re-edit backup location?\n // then you could do `vlt config edit retry` or something.\n if (backup) {\n await writeFile(file, backup)\n reload(which)\n } else {\n await rm(file, { force: true })\n }\n }\n }\n }\n\n /**\n * Find the local config file and load both it and the user-level config in\n * the XDG config home.\n */\n async loadConfigFile(): Promise<this> {\n await this.#maybeLoadConfigFile('user')\n this.projectRoot = dirname(find('project', this.projectRoot))\n await this.#maybeLoadConfigFile('project')\n return this\n }\n\n /**\n * Clear cached config values to force re-reading from updated files.\n * @internal\n */\n async #reloadConfig() {\n // Clear the memoized options to force recalculation\n this.#options = undefined\n }\n\n /**\n * Force a complete reload of config files from disk.\n * This clears all caches and re-reads config files.\n * Useful for long-running processes that need to pick up config changes.\n */\n async reloadFromDisk(): Promise<void> {\n // Clear the memoized options to force recalculation\n this.#options = undefined\n\n // Clear the parsed state to force re-parsing\n // This is crucial because parse() returns early if already parsed\n this.values = undefined\n this.positionals = undefined\n this.command = undefined\n\n // Clear vlt-json caches for both user and project configs\n // This ensures that the next time config files are read, they'll be re-read from disk\n const { unload } = await import('@vltpkg/vlt-json')\n unload('user')\n unload('project')\n\n // Force reload of config files by calling the load methods again\n // This will re-read the files and re-apply them to the jack parser\n await this.#maybeLoadConfigFile('user')\n await this.#maybeLoadConfigFile('project')\n\n // Re-parse to pick up the updated config values using the original arguments\n this.parse(this.#originalArgs)\n }\n\n /**\n * cache of the loaded config\n */\n static #loaded: LoadedConfig | undefined\n\n /**\n * Load the configuration and return a Promise to a\n * {@link Config} object\n */\n static async load(\n projectRoot = process.cwd(),\n argv = process.argv,\n /**\n * only used in tests, resets the memoization\n * @internal\n */\n reload = false,\n ): Promise<LoadedConfig> {\n if (this.#loaded && !reload) return this.#loaded\n const a = new Config(definition, projectRoot)\n const b = await a.loadConfigFile()\n this.#loaded = b.parse(argv) as LoadedConfig\n return this.#loaded\n }\n}\n\nconst isParsed = (c: Config): c is ParsedConfig =>\n !!(c.values && c.positionals && c.command)\n\nexport type ParsedConfig = Config & {\n command: NonNullable<Config['command']>\n values: OptionsResults<ConfigDefinitions>\n positionals: string[]\n}\n\n/**\n * A fully loaded {@link Config} object\n */\nexport type LoadedConfig = ParsedConfig\n"]}
@@ -1,4 +0,0 @@
1
- type MergeableObject = Record<string, unknown>;
2
- export declare const merge: <T extends MergeableObject>(base: T, add: T) => T;
3
- export {};
4
- //# sourceMappingURL=merge.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"merge.d.ts","sourceRoot":"","sources":["../../src/config/merge.ts"],"names":[],"mappings":"AAAA,KAAK,eAAe,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;AAQ9C,eAAO,MAAM,KAAK,GAAI,CAAC,SAAS,eAAe,QACvC,CAAC,OACF,CAAC,KACL,CA2BK,CAAA"}
@@ -1,28 +0,0 @@
1
- /*
2
- * deep merge 2 objects
3
- * scalars are overwritten, objects are folded in together
4
- * if nothing to be added, then return the base object.
5
- */
6
- export const merge = (base, add) => Object.fromEntries(Object.entries(base)
7
- .map(([k, v]) => [
8
- k,
9
- add[k] === undefined ? v
10
- : Array.isArray(v) && Array.isArray(add[k]) ?
11
- [
12
- ...new Set([
13
- ...v,
14
- ...add[k],
15
- ]),
16
- ]
17
- : Array.isArray(v) || Array.isArray(add[k]) ? add[k]
18
- : (!!v &&
19
- typeof v === 'object' &&
20
- !!add[k] &&
21
- typeof add[k] === 'object') ?
22
- merge(v, add[k])
23
- : add[k],
24
- ])
25
- .concat(
26
- // already merged together if existing, so just get new additions
27
- Object.entries(add).filter(([k]) => base[k] === undefined)));
28
- //# sourceMappingURL=merge.js.map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KAAK,SAAS,CAAC,CAC3D,CACC,CAAA","sourcesContent":["type MergeableObject = Record<string, unknown>\ntype MergeableArray = unknown[]\n\n/*\n * deep merge 2 objects\n * scalars are overwritten, objects are folded in together\n * if nothing to be added, then return the base object.\n */\nexport const merge = <T extends MergeableObject>(\n base: T,\n add: T,\n): T =>\n Object.fromEntries(\n Object.entries(base)\n .map(([k, v]): [string, unknown] => [\n k,\n add[k] === undefined ? v\n : Array.isArray(v) && Array.isArray(add[k]) ?\n [\n ...new Set([\n ...(v as MergeableArray),\n ...(add[k] as MergeableArray),\n ]),\n ]\n : Array.isArray(v) || Array.isArray(add[k]) ? add[k]\n : (\n !!v &&\n typeof v === 'object' &&\n !!add[k] &&\n typeof add[k] === 'object'\n ) ?\n merge(v as MergeableObject, add[k] as MergeableObject)\n : add[k],\n ])\n .concat(\n // already merged together if existing, so just get new additions\n Object.entries(add).filter(([k]) => base[k] === undefined),\n ),\n ) as T\n"]}
@@ -1,19 +0,0 @@
1
- import type { CommandUsage } from '../index.ts';
2
- export type CommandUsageDefinition = {
3
- command: string;
4
- usage: string | string[];
5
- description: string;
6
- subcommands?: Record<string, {
7
- usage?: string | string[];
8
- description: string;
9
- }>;
10
- examples?: Record<string, {
11
- description: string;
12
- }>;
13
- options?: Record<string, {
14
- value?: string;
15
- description: string;
16
- }>;
17
- };
18
- export declare const commandUsage: ({ command, usage, description, subcommands, examples, options, }: CommandUsageDefinition) => ReturnType<CommandUsage>;
19
- //# sourceMappingURL=usage.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"usage.d.ts","sourceRoot":"","sources":["../../src/config/usage.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAU/C,MAAM,MAAM,sBAAsB,GAAG;IACnC,OAAO,EAAE,MAAM,CAAA;IACf,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;IACxB,WAAW,EAAE,MAAM,CAAA;IACnB,WAAW,CAAC,EAAE,MAAM,CAClB,MAAM,EACN;QAAE,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;QAAC,WAAW,EAAE,MAAM,CAAA;KAAE,CACnD,CAAA;IACD,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE;QAAE,WAAW,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;IAClD,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;CAClE,CAAA;AAED,eAAO,MAAM,YAAY,qEAOtB,sBAAsB,KAAG,UAAU,CAAC,YAAY,CA+ClD,CAAA"}