@vltpkg/cli-sdk 0.0.0-9 → 1.0.0-rc.2

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 (149) hide show
  1. package/dist/esm/commands/build.d.ts +25 -0
  2. package/dist/esm/commands/build.d.ts.map +1 -0
  3. package/dist/esm/commands/build.js +102 -0
  4. package/dist/esm/commands/build.js.map +1 -0
  5. package/dist/esm/commands/cache.d.ts +18 -0
  6. package/dist/esm/commands/cache.d.ts.map +1 -1
  7. package/dist/esm/commands/cache.js +48 -2
  8. package/dist/esm/commands/cache.js.map +1 -1
  9. package/dist/esm/commands/ci.d.ts +11 -0
  10. package/dist/esm/commands/ci.d.ts.map +1 -0
  11. package/dist/esm/commands/ci.js +32 -0
  12. package/dist/esm/commands/ci.js.map +1 -0
  13. package/dist/esm/commands/config.d.ts +3 -2
  14. package/dist/esm/commands/config.d.ts.map +1 -1
  15. package/dist/esm/commands/config.js +372 -101
  16. package/dist/esm/commands/config.js.map +1 -1
  17. package/dist/esm/commands/docs.d.ts +18 -0
  18. package/dist/esm/commands/docs.d.ts.map +1 -0
  19. package/dist/esm/commands/docs.js +154 -0
  20. package/dist/esm/commands/docs.js.map +1 -0
  21. package/dist/esm/commands/exec-cache.d.ts +49 -0
  22. package/dist/esm/commands/exec-cache.d.ts.map +1 -0
  23. package/dist/esm/commands/exec-cache.js +146 -0
  24. package/dist/esm/commands/exec-cache.js.map +1 -0
  25. package/dist/esm/commands/exec-local.d.ts +1 -0
  26. package/dist/esm/commands/exec-local.d.ts.map +1 -1
  27. package/dist/esm/commands/exec-local.js +2 -0
  28. package/dist/esm/commands/exec-local.js.map +1 -1
  29. package/dist/esm/commands/exec.d.ts +6 -1
  30. package/dist/esm/commands/exec.d.ts.map +1 -1
  31. package/dist/esm/commands/exec.js +79 -5
  32. package/dist/esm/commands/exec.js.map +1 -1
  33. package/dist/esm/commands/help.d.ts +1 -1
  34. package/dist/esm/commands/help.d.ts.map +1 -1
  35. package/dist/esm/commands/help.js +32 -3
  36. package/dist/esm/commands/help.js.map +1 -1
  37. package/dist/esm/commands/init.d.ts +3 -3
  38. package/dist/esm/commands/init.d.ts.map +1 -1
  39. package/dist/esm/commands/init.js +95 -9
  40. package/dist/esm/commands/init.js.map +1 -1
  41. package/dist/esm/commands/install/reporter.d.ts +3 -2
  42. package/dist/esm/commands/install/reporter.d.ts.map +1 -1
  43. package/dist/esm/commands/install/reporter.js +42 -15
  44. package/dist/esm/commands/install/reporter.js.map +1 -1
  45. package/dist/esm/commands/install.d.ts +21 -3
  46. package/dist/esm/commands/install.d.ts.map +1 -1
  47. package/dist/esm/commands/install.js +27 -3
  48. package/dist/esm/commands/install.js.map +1 -1
  49. package/dist/esm/commands/list.d.ts +2 -2
  50. package/dist/esm/commands/list.d.ts.map +1 -1
  51. package/dist/esm/commands/list.js +149 -49
  52. package/dist/esm/commands/list.js.map +1 -1
  53. package/dist/esm/commands/pack.d.ts +32 -0
  54. package/dist/esm/commands/pack.d.ts.map +1 -0
  55. package/dist/esm/commands/pack.js +147 -0
  56. package/dist/esm/commands/pack.js.map +1 -0
  57. package/dist/esm/commands/pkg.d.ts +1 -2
  58. package/dist/esm/commands/pkg.d.ts.map +1 -1
  59. package/dist/esm/commands/pkg.js +123 -38
  60. package/dist/esm/commands/pkg.js.map +1 -1
  61. package/dist/esm/commands/publish.d.ts +22 -0
  62. package/dist/esm/commands/publish.d.ts.map +1 -0
  63. package/dist/esm/commands/publish.js +245 -0
  64. package/dist/esm/commands/publish.js.map +1 -0
  65. package/dist/esm/commands/query.d.ts +2 -3
  66. package/dist/esm/commands/query.d.ts.map +1 -1
  67. package/dist/esm/commands/query.js +132 -38
  68. package/dist/esm/commands/query.js.map +1 -1
  69. package/dist/esm/commands/run-exec.d.ts +1 -0
  70. package/dist/esm/commands/run-exec.d.ts.map +1 -1
  71. package/dist/esm/commands/run-exec.js +1 -0
  72. package/dist/esm/commands/run-exec.js.map +1 -1
  73. package/dist/esm/commands/run.d.ts +1 -0
  74. package/dist/esm/commands/run.d.ts.map +1 -1
  75. package/dist/esm/commands/run.js +13 -16
  76. package/dist/esm/commands/run.js.map +1 -1
  77. package/dist/esm/commands/serve.d.ts +14 -0
  78. package/dist/esm/commands/serve.d.ts.map +1 -0
  79. package/dist/esm/commands/serve.js +103 -0
  80. package/dist/esm/commands/serve.js.map +1 -0
  81. package/dist/esm/commands/uninstall.d.ts +8 -2
  82. package/dist/esm/commands/uninstall.d.ts.map +1 -1
  83. package/dist/esm/commands/uninstall.js +8 -3
  84. package/dist/esm/commands/uninstall.js.map +1 -1
  85. package/dist/esm/commands/update.d.ts +14 -0
  86. package/dist/esm/commands/update.d.ts.map +1 -0
  87. package/dist/esm/commands/update.js +41 -0
  88. package/dist/esm/commands/update.js.map +1 -0
  89. package/dist/esm/commands/version.d.ts +26 -0
  90. package/dist/esm/commands/version.d.ts.map +1 -0
  91. package/dist/esm/commands/version.js +226 -0
  92. package/dist/esm/commands/version.js.map +1 -0
  93. package/dist/esm/config/definition.d.ts +118 -15
  94. package/dist/esm/config/definition.d.ts.map +1 -1
  95. package/dist/esm/config/definition.js +185 -37
  96. package/dist/esm/config/definition.js.map +1 -1
  97. package/dist/esm/config/index.d.ts +41 -37
  98. package/dist/esm/config/index.d.ts.map +1 -1
  99. package/dist/esm/config/index.js +109 -172
  100. package/dist/esm/config/index.js.map +1 -1
  101. package/dist/esm/config/merge.d.ts +3 -1
  102. package/dist/esm/config/merge.d.ts.map +1 -1
  103. package/dist/esm/config/merge.js +11 -6
  104. package/dist/esm/config/merge.js.map +1 -1
  105. package/dist/esm/custom-help.d.ts +9 -0
  106. package/dist/esm/custom-help.d.ts.map +1 -0
  107. package/dist/esm/custom-help.js +400 -0
  108. package/dist/esm/custom-help.js.map +1 -0
  109. package/dist/esm/exec-command.d.ts +33 -14
  110. package/dist/esm/exec-command.d.ts.map +1 -1
  111. package/dist/esm/exec-command.js +213 -64
  112. package/dist/esm/exec-command.js.map +1 -1
  113. package/dist/esm/index.d.ts +1 -14
  114. package/dist/esm/index.d.ts.map +1 -1
  115. package/dist/esm/index.js +45 -19
  116. package/dist/esm/index.js.map +1 -1
  117. package/dist/esm/load-command.d.ts +16 -0
  118. package/dist/esm/load-command.d.ts.map +1 -0
  119. package/dist/esm/load-command.js +21 -0
  120. package/dist/esm/load-command.js.map +1 -0
  121. package/dist/esm/output.d.ts +6 -11
  122. package/dist/esm/output.d.ts.map +1 -1
  123. package/dist/esm/output.js +64 -27
  124. package/dist/esm/output.js.map +1 -1
  125. package/dist/esm/pack-tarball.d.ts +22 -0
  126. package/dist/esm/pack-tarball.d.ts.map +1 -0
  127. package/dist/esm/pack-tarball.js +249 -0
  128. package/dist/esm/pack-tarball.js.map +1 -0
  129. package/dist/esm/print-err.d.ts +9 -2
  130. package/dist/esm/print-err.d.ts.map +1 -1
  131. package/dist/esm/print-err.js +130 -46
  132. package/dist/esm/print-err.js.map +1 -1
  133. package/dist/esm/query-host-contexts.d.ts +16 -0
  134. package/dist/esm/query-host-contexts.d.ts.map +1 -0
  135. package/dist/esm/query-host-contexts.js +135 -0
  136. package/dist/esm/query-host-contexts.js.map +1 -0
  137. package/dist/esm/start-gui.d.ts +1 -0
  138. package/dist/esm/start-gui.d.ts.map +1 -1
  139. package/dist/esm/start-gui.js +28 -8
  140. package/dist/esm/start-gui.js.map +1 -1
  141. package/dist/esm/view.d.ts +2 -3
  142. package/dist/esm/view.d.ts.map +1 -1
  143. package/dist/esm/view.js +1 -1
  144. package/dist/esm/view.js.map +1 -1
  145. package/package.json +51 -37
  146. package/dist/esm/commands/gui.d.ts +0 -6
  147. package/dist/esm/commands/gui.d.ts.map +0 -1
  148. package/dist/esm/commands/gui.js +0 -13
  149. package/dist/esm/commands/gui.js.map +0 -1
@@ -23,15 +23,13 @@
23
23
  import { error } from '@vltpkg/error-cause';
24
24
  import { PackageInfoClient } from '@vltpkg/package-info';
25
25
  import { PackageJson } from '@vltpkg/package-json';
26
+ import { resetCaches } from '@vltpkg/dep-id';
27
+ import { assertRecordStringString, assertRecordStringT, isRecordStringString, } from '@vltpkg/types';
28
+ import { find, load, reload, save } from '@vltpkg/vlt-json';
26
29
  import { Monorepo } from '@vltpkg/workspaces';
27
- import { XDG } from '@vltpkg/xdg';
28
- import { readFileSync, rmSync, writeFileSync } from 'node:fs';
29
- import { lstat, mkdir, readFile, writeFile } from 'node:fs/promises';
30
- import { homedir } from 'node:os';
31
- import { dirname, resolve } from 'node:path';
30
+ import { readFile, rm, writeFile } from 'node:fs/promises';
31
+ import { dirname } from 'node:path';
32
32
  import { PathScurry } from 'path-scurry';
33
- import { parse as jsonParse, stringify as jsonStringify, kIndent, kNewline, } from 'polite-json';
34
- import { walkUp } from 'walk-up-path';
35
33
  import { commands, definition, getCommand, isRecordField, recordFields, } from "./definition.js";
36
34
  import { merge } from "./merge.js";
37
35
  export { commands, definition, isRecordField, recordFields, };
@@ -86,9 +84,6 @@ export const recordsToPairs = (obj) => {
86
84
  ]));
87
85
  };
88
86
  const kRecord = Symbol('parsed key=value record');
89
- const exists = (f) => lstat(f).then(() => true, () => false);
90
- const home = homedir();
91
- const xdg = new XDG('vlt');
92
87
  /**
93
88
  * Class that handles configuration for vlt.
94
89
  *
@@ -100,8 +95,6 @@ export class Config {
100
95
  * representing vlt's configuration
101
96
  */
102
97
  jack;
103
- stringifyOptions = { [kIndent]: ' ', [kNewline]: '\n' };
104
- configFiles = {};
105
98
  /**
106
99
  * Parsed values in effect
107
100
  */
@@ -126,7 +119,13 @@ export class Config {
126
119
  monorepo: Monorepo.maybeLoad(this.projectRoot, {
127
120
  scurry,
128
121
  packageJson,
122
+ load: {
123
+ paths: asRecords.workspace,
124
+ groups: asRecords['workspace-group'],
125
+ },
129
126
  }),
127
+ catalog: load('catalog', assertRecordStringString),
128
+ catalogs: load('catalogs', o => assertRecordStringT(o, isRecordStringString, 'Record<string, Record<string, string>>')),
130
129
  };
131
130
  const options = Object.assign(asRecords, extras);
132
131
  this.#options = Object.assign(options, {
@@ -147,6 +146,7 @@ export class Config {
147
146
  resetOptions(projectRoot = process.cwd()) {
148
147
  this.projectRoot = projectRoot;
149
148
  this.#options = undefined;
149
+ resetCaches();
150
150
  }
151
151
  // memoized options() getter value
152
152
  #options;
@@ -155,7 +155,12 @@ export class Config {
155
155
  */
156
156
  positionals;
157
157
  /**
158
- * The root of the project where a vlt.json, vlt-workspaces.json,
158
+ * Original arguments used for parsing (stored for reload purposes)
159
+ * @internal
160
+ */
161
+ #originalArgs;
162
+ /**
163
+ * The root of the project where a vlt.json, vlt.json,
159
164
  * package.json, or .git was found. Not necessarily the `process.cwd()`,
160
165
  * though that is the default location.
161
166
  *
@@ -183,6 +188,8 @@ export class Config {
183
188
  parse(args = process.argv) {
184
189
  if (isParsed(this))
185
190
  return this;
191
+ // Store the original args for potential reload
192
+ this.#originalArgs = [...args];
186
193
  this.jack.loadEnvDefaults();
187
194
  const p = this.jack.parseRaw(args);
188
195
  const fallback = getCommand(p.values['fallback-command']);
@@ -250,86 +257,55 @@ export class Config {
250
257
  * Write the config values to the user or project config file.
251
258
  */
252
259
  async writeConfigFile(which, values) {
253
- const f = this.getFilename(which);
254
- await mkdir(dirname(f), { recursive: true });
255
- const vals = Object.assign(pairsToRecords(values), this.stringifyOptions);
256
- await writeFile(f, jsonStringify(vals));
257
- this.configFiles[f] = vals;
258
- return values;
260
+ save('config', pairsToRecords(values), which);
261
+ await this.#reloadConfig();
259
262
  }
260
263
  /**
261
264
  * Fold in the provided fields with the existing properties
262
265
  * in the config file.
263
266
  */
264
267
  async addConfigToFile(which, values) {
265
- const f = this.getFilename(which);
266
- return this.writeConfigFile(which, merge((await this.#maybeLoadConfigFile(f)) ?? {}, values));
267
- }
268
- /**
269
- * if the file exists, parse and load it. returns object if data was
270
- * loaded, or undefined if not.
271
- */
272
- async #maybeLoadConfigFile(file) {
273
- const result = await this.#readConfigFile(file);
274
- if (result) {
275
- try {
276
- const { command, ...values } = recordsToPairs(result);
277
- if (command) {
278
- for (const [c, opts] of Object.entries(command)) {
279
- const cmd = getCommand(c);
280
- if (cmd) {
281
- this.commandValues[cmd] = merge(this.commandValues[cmd] ?? {}, opts);
282
- }
283
- }
284
- }
285
- this.jack.setConfigValues(values, file);
286
- return result;
287
- }
288
- catch (er) {
289
- throw error('failed to load config values from file', {
290
- path: file,
291
- cause: er,
292
- });
293
- }
294
- }
268
+ return this.writeConfigFile(which, merge((await this.#maybeLoadConfigFile(which)) ?? {}, values));
295
269
  }
296
- async #readConfigFile(file) {
297
- if (this.configFiles[file])
298
- return this.configFiles[file];
299
- const data = await readFile(file, 'utf8').catch(() => { });
300
- if (!data)
301
- return undefined;
302
- let result;
303
- try {
304
- result = jsonParse(data);
305
- if (result && typeof result === 'object') {
306
- if (result[kIndent] !== undefined)
307
- this.stringifyOptions[kIndent] = result[kIndent];
308
- if (result[kNewline] !== undefined)
309
- this.stringifyOptions[kNewline] = result[kNewline];
310
- }
311
- }
312
- catch (er) {
313
- throw error('failed to parse vlt config file', {
270
+ // called in this weird bound way so that it can be used by the
271
+ // vlt-json config loading module.
272
+ #validator = function (c, file) {
273
+ this.#validateConfig(c, file);
274
+ }.bind(this);
275
+ #validateConfig(c, file) {
276
+ if (!c || typeof c !== 'object' || Array.isArray(c)) {
277
+ throw error('invalid config, expected object', {
314
278
  path: file,
315
- cause: er,
279
+ found: c,
280
+ wanted: 'ConfigFileData',
316
281
  });
317
282
  }
318
- this.configFiles[file] = result;
319
- return result;
283
+ const { command, ...values } = recordsToPairs(c);
284
+ if (command) {
285
+ for (const [c, opts] of Object.entries(command)) {
286
+ const cmd = getCommand(c);
287
+ if (cmd) {
288
+ this.commandValues[cmd] = merge(this.commandValues[cmd] ?? {}, opts);
289
+ }
290
+ }
291
+ }
292
+ this.jack.setConfigValues(values, file);
320
293
  }
321
- getFilename(which = 'project') {
322
- return which === 'user' ?
323
- xdg.config('vlt.json')
324
- : resolve(this.projectRoot, 'vlt.json');
294
+ /**
295
+ * if the file exists, parse and load it. returns object if data was
296
+ * loaded, or undefined if not.
297
+ */
298
+ async #maybeLoadConfigFile(whichConfig) {
299
+ return load('config', this.#validator, whichConfig);
325
300
  }
301
+ /**
302
+ * Deletes the specified config fields from the named file
303
+ * Returns `true` if anything was changed.
304
+ */
326
305
  async deleteConfigKeys(which, fields) {
327
- const file = this.getFilename(which);
328
- const data = await this.#maybeLoadConfigFile(file);
329
- if (!data) {
330
- rmSync(file, { force: true });
306
+ const data = await this.#maybeLoadConfigFile(which);
307
+ if (!data)
331
308
  return false;
332
- }
333
309
  let didSomething = false;
334
310
  for (const f of fields) {
335
311
  const [key, ...sk] = f.split('.');
@@ -342,9 +318,10 @@ export class Config {
342
318
  if (Array.isArray(v)) {
343
319
  const i = v.findIndex(subvalue => subvalue.startsWith(`${subs}=`));
344
320
  if (i !== -1) {
345
- v.splice(i, 1);
346
- if (v.length === 0)
321
+ if (v.length === 1)
347
322
  delete data[k];
323
+ else
324
+ v.splice(i, 1);
348
325
  didSomething = true;
349
326
  }
350
327
  }
@@ -362,13 +339,8 @@ export class Config {
362
339
  delete data[k];
363
340
  }
364
341
  }
365
- const d = jsonStringify(data);
366
- if (d.trim() === '{}') {
367
- rmSync(file, { force: true });
368
- }
369
- else {
370
- writeFileSync(file, jsonStringify(data));
371
- }
342
+ if (didSomething)
343
+ await this.writeConfigFile(which, data);
372
344
  return didSomething;
373
345
  }
374
346
  /**
@@ -382,39 +354,33 @@ export class Config {
382
354
  * mean deleting the file.
383
355
  */
384
356
  async editConfigFile(which, edit) {
385
- const file = this.getFilename(which);
386
- const backup = this.configFiles[file];
357
+ // load the file as a backup
358
+ // call the edit function
359
+ // reload it
360
+ const file = find(which);
361
+ const backup = await readFile(file, 'utf8').catch(() => undefined);
387
362
  if (!backup) {
388
- writeFileSync(file, '{\n\n}\n');
363
+ await writeFile(file, JSON.stringify({ config: {} }, null, 2) + '\n');
389
364
  }
390
365
  let valid = false;
391
366
  try {
392
367
  await edit(file);
393
- const res = jsonParse(readFileSync(file, 'utf8'));
394
- if (!res || typeof res !== 'object' || Array.isArray(res)) {
395
- throw error('Invalid configuration, expected object', {
396
- path: file,
397
- found: res,
398
- });
399
- }
400
- if (Object.keys(res).length === 0) {
401
- // nothing there, remove file
402
- delete this.configFiles[file];
403
- rmSync(file, { force: true });
404
- }
405
- else {
406
- this.jack.setConfigValues(recordsToPairs(res));
407
- this.configFiles[file] = res;
408
- }
368
+ // force it to reload the file and validate it again
369
+ // if this fails, we roll back.
370
+ const result = reload('config', which);
371
+ save('config', result ?? {}, which);
409
372
  valid = true;
410
373
  }
411
374
  finally {
412
375
  if (!valid) {
376
+ // TODO: maybe write the file to a re-edit backup location?
377
+ // then you could do `vlt config edit retry` or something.
413
378
  if (backup) {
414
- writeFileSync(file, jsonStringify(backup));
379
+ await writeFile(file, backup);
380
+ reload(which);
415
381
  }
416
382
  else {
417
- rmSync(file, { force: true });
383
+ await rm(file, { force: true });
418
384
  }
419
385
  }
420
386
  }
@@ -422,73 +388,45 @@ export class Config {
422
388
  /**
423
389
  * Find the local config file and load both it and the user-level config in
424
390
  * the XDG config home.
425
- *
426
- * Note: if working in a workspaces monorepo, then the vlt.json file MUST
427
- * be in the same folder as the vlt-workspaces.json file, because we stop
428
- * looking when we find either one.
429
391
  */
430
392
  async loadConfigFile() {
431
- const userConfig = xdg.config('vlt.json');
432
- await this.#maybeLoadConfigFile(userConfig);
433
- let lastKnownRoot = resolve(this.projectRoot);
434
- for (const dir of walkUp(this.projectRoot)) {
435
- // don't look in ~
436
- if (dir === home)
437
- break;
438
- // finding a project config file stops the search
439
- const projectConfig = resolve(dir, 'vlt.json');
440
- if (projectConfig === userConfig)
441
- break;
442
- if ((await exists(projectConfig)) &&
443
- (await this.#maybeLoadConfigFile(projectConfig))) {
444
- lastKnownRoot = dir;
445
- break;
446
- }
447
- // stat existence of these files
448
- const [hasPackage, hasModules, hasWorkspaces, hasGit] = await Promise.all([
449
- exists(resolve(dir, 'package.json')),
450
- exists(resolve(dir, 'node_modules')),
451
- exists(resolve(dir, 'vlt-workspaces.json')),
452
- exists(resolve(dir, '.git')),
453
- ]);
454
- // treat these as potential roots
455
- if (hasPackage || hasModules || hasWorkspaces) {
456
- lastKnownRoot = dir;
457
- }
458
- // define backstops
459
- if (hasWorkspaces || hasGit) {
460
- break;
461
- }
462
- }
463
- this.projectRoot = lastKnownRoot;
393
+ await this.#maybeLoadConfigFile('user');
394
+ this.projectRoot = dirname(find('project', this.projectRoot));
395
+ await this.#maybeLoadConfigFile('project');
464
396
  return this;
465
397
  }
466
398
  /**
467
- * Determine whether we should use colors in the output. Update
468
- * chalk appropriately.
469
- *
470
- * Implicitly calls this.parse() if it not parsed already.
399
+ * Clear cached config values to force re-reading from updated files.
400
+ * @internal
471
401
  */
472
- async loadColor() {
473
- const c = this.get('color');
474
- const chalk = (await import('chalk')).default;
475
- let color;
476
- if (process.env.NO_COLOR !== '1' &&
477
- (c === true || (c === undefined && chalk.level > 0))) {
478
- color = true;
479
- chalk.level = Math.max(chalk.level, 1);
480
- process.env.FORCE_COLOR = String(chalk.level);
481
- delete process.env.NO_COLOR;
482
- }
483
- else {
484
- color = false;
485
- chalk.level = 0;
486
- process.env.FORCE_COLOR = '0';
487
- process.env.NO_COLOR = '1';
488
- }
489
- const { values = this.parse().values } = this;
490
- values.color = color;
491
- return this;
402
+ async #reloadConfig() {
403
+ // Clear the memoized options to force recalculation
404
+ this.#options = undefined;
405
+ }
406
+ /**
407
+ * Force a complete reload of config files from disk.
408
+ * This clears all caches and re-reads config files.
409
+ * Useful for long-running processes that need to pick up config changes.
410
+ */
411
+ async reloadFromDisk() {
412
+ // Clear the memoized options to force recalculation
413
+ this.#options = undefined;
414
+ // Clear the parsed state to force re-parsing
415
+ // This is crucial because parse() returns early if already parsed
416
+ this.values = undefined;
417
+ this.positionals = undefined;
418
+ this.command = undefined;
419
+ // Clear vlt-json caches for both user and project configs
420
+ // This ensures that the next time config files are read, they'll be re-read from disk
421
+ const { unload } = await import('@vltpkg/vlt-json');
422
+ unload('user');
423
+ unload('project');
424
+ // Force reload of config files by calling the load methods again
425
+ // This will re-read the files and re-apply them to the jack parser
426
+ await this.#maybeLoadConfigFile('user');
427
+ await this.#maybeLoadConfigFile('project');
428
+ // Re-parse to pick up the updated config values using the original arguments
429
+ this.parse(this.#originalArgs);
492
430
  }
493
431
  /**
494
432
  * cache of the loaded config
@@ -508,8 +446,7 @@ export class Config {
508
446
  return this.#loaded;
509
447
  const a = new Config(definition, projectRoot);
510
448
  const b = await a.loadConfigFile();
511
- const c = await b.parse(argv).loadColor();
512
- this.#loaded = c;
449
+ this.#loaded = b.parse(argv);
513
450
  return this.#loaded;
514
451
  }
515
452
  }
@@ -1 +1 @@
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;AACxD,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAClD,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAA;AAC7C,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAA;AAEjC,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAC7D,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AACpE,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AACjC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAExC,OAAO,EACL,KAAK,IAAI,SAAS,EAClB,SAAS,IAAI,aAAa,EAC1B,OAAO,EACP,QAAQ,GACT,MAAM,aAAa,CAAA;AACpB,OAAO,EAAE,MAAM,EAAE,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OAAO,IAAI,CAAC,MAAM;YAAE,OAAO,IAAI,CAAC,OAAO,CAAA;QAChD,MAAM,CAAC,GAAG,IAAI,MAAM,CAAC,UAAU,EAAE,WAAW,CAAC,CAAA;QAC7C,MAAM,CAAC,GAAG,MAAM,CAAC,CAAC,cAAc,EAAE,CAAA;QAClC,MAAM,CAAC,GAAG,MAAM,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,CAAA;QACzC,IAAI,CAAC,OAAO,GAAG,CAAiB,CAAA;QAChC,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 { Monorepo } from '@vltpkg/workspaces'\nimport { XDG } from '@vltpkg/xdg'\nimport type { Jack, OptionsResults, Unwrap } from 'jackspeak'\nimport { readFileSync, rmSync, writeFileSync } from 'node:fs'\nimport { lstat, mkdir, readFile, writeFile } from 'node:fs/promises'\nimport { homedir } from 'node:os'\nimport { dirname, resolve } from 'node:path'\nimport { PathScurry } from 'path-scurry'\nimport type { JSONResult } from 'polite-json'\nimport {\n parse as jsonParse,\n stringify as jsonStringify,\n kIndent,\n kNewline,\n} from 'polite-json'\nimport { walkUp } from 'walk-up-path'\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>\nexport type ConfigFiles = Record<string, ConfigFileData>\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 = Omit<\n ConfigOptions,\n | 'projectRoot'\n | 'scurry'\n | 'packageJson'\n | 'monorepo'\n | 'packageInfo'\n> & {\n command?: Record<string, ConfigOptions>\n}\n\nexport const pairsToRecords = (\n obj: ConfigFileData,\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 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')\nconst exists = (f: string) =>\n lstat(f).then(\n () => true,\n () => false,\n )\n\nconst home = homedir()\nconst xdg = new XDG('vlt')\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 = OptionsResults<ConfigDefinitions> & {\n command?: Record<string, OptionsResults<ConfigDefinitions>>\n}\n\n/**\n * Config data as it appears in config files, with kv pair lists\n * stored as `Record<string, string>`.\n */\nexport type ConfigFileData = {\n [k in keyof ConfigData]?: k extends OptListKeys<ConfigData> ?\n RecordString | string[]\n : k extends 'command' ? ConfigFiles\n : ConfigData[k]\n}\n\nexport type ConfigOptions = {\n [k in keyof ConfigData]: k extends RecordField ? RecordString\n : k extends 'command' ? never\n : ConfigData[k]\n} & {\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 stringifyOptions: {\n [kIndent]: string\n [kNewline]: string\n } = { [kIndent]: ' ', [kNewline]: '\\n' }\n\n configFiles: ConfigFiles = {}\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 }),\n }\n const options: Omit<ConfigOptions, 'packageInfo'> = Object.assign(\n asRecords,\n extras,\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 }\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 * The root of the project where a vlt.json, vlt-workspaces.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 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 which: 'project' | 'user',\n values: ConfigFileData,\n ) {\n const f = this.getFilename(which)\n await mkdir(dirname(f), { recursive: true })\n const vals = Object.assign(\n pairsToRecords(values),\n this.stringifyOptions,\n )\n await writeFile(f, jsonStringify(vals))\n this.configFiles[f] = vals\n return values\n }\n\n /**\n * Fold in the provided fields with the existing properties\n * in the config file.\n */\n async addConfigToFile(\n which: 'project' | 'user',\n values: ConfigFileData,\n ) {\n const f = this.getFilename(which)\n return this.writeConfigFile(\n which,\n merge((await this.#maybeLoadConfigFile(f)) ?? {}, values),\n )\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(\n file: string,\n ): Promise<ConfigFileData | undefined> {\n const result = await this.#readConfigFile(file)\n\n if (result) {\n try {\n const { command, ...values } = recordsToPairs(result)\n if (command) {\n for (const [c, opts] of Object.entries(command)) {\n const cmd = getCommand(c)\n if (cmd) {\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 return result\n } catch (er) {\n throw error('failed to load config values from file', {\n path: file,\n cause: er,\n })\n }\n }\n }\n\n async #readConfigFile(\n file: string,\n ): Promise<ConfigFileData | undefined> {\n if (this.configFiles[file]) return this.configFiles[file]\n const data = await readFile(file, 'utf8').catch(() => {})\n if (!data) return undefined\n let result: JSONResult\n try {\n result = jsonParse(data)\n if (result && typeof result === 'object') {\n if (result[kIndent] !== undefined)\n this.stringifyOptions[kIndent] = result[kIndent]\n if (result[kNewline] !== undefined)\n this.stringifyOptions[kNewline] = result[kNewline]\n }\n } catch (er) {\n throw error('failed to parse vlt config file', {\n path: file,\n cause: er,\n })\n }\n this.configFiles[file] = result as ConfigFileData\n return result as ConfigFileData\n }\n\n getFilename(which: 'project' | 'user' = 'project'): string {\n return which === 'user' ?\n xdg.config('vlt.json')\n : resolve(this.projectRoot, 'vlt.json')\n }\n\n async deleteConfigKeys(\n which: 'project' | 'user',\n fields: string[],\n ) {\n const file = this.getFilename(which)\n const data = await this.#maybeLoadConfigFile(file)\n if (!data) {\n rmSync(file, { force: true })\n return false\n }\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 v.splice(i, 1)\n if (v.length === 0) delete data[k]\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 const d = jsonStringify(data)\n if (d.trim() === '{}') {\n rmSync(file, { force: true })\n } else {\n writeFileSync(file, jsonStringify(data))\n }\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 which: 'project' | 'user',\n edit: (file: string) => Promise<void> | void,\n ) {\n const file = this.getFilename(which)\n const backup = this.configFiles[file]\n if (!backup) {\n writeFileSync(file, '{\\n\\n}\\n')\n }\n let valid = false\n try {\n await edit(file)\n const res = jsonParse(readFileSync(file, 'utf8'))\n if (!res || typeof res !== 'object' || Array.isArray(res)) {\n throw error('Invalid configuration, expected object', {\n path: file,\n found: res,\n })\n }\n if (Object.keys(res).length === 0) {\n // nothing there, remove file\n delete this.configFiles[file]\n rmSync(file, { force: true })\n } else {\n this.jack.setConfigValues(recordsToPairs(res))\n this.configFiles[file] = res as ConfigFileData\n }\n valid = true\n } finally {\n if (!valid) {\n if (backup) {\n writeFileSync(file, jsonStringify(backup))\n } else {\n rmSync(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 * Note: if working in a workspaces monorepo, then the vlt.json file MUST\n * be in the same folder as the vlt-workspaces.json file, because we stop\n * looking when we find either one.\n */\n async loadConfigFile(): Promise<this> {\n const userConfig = xdg.config('vlt.json')\n await this.#maybeLoadConfigFile(userConfig)\n\n let lastKnownRoot = resolve(this.projectRoot)\n for (const dir of walkUp(this.projectRoot)) {\n // don't look in ~\n if (dir === home) break\n\n // finding a project config file stops the search\n const projectConfig = resolve(dir, 'vlt.json')\n if (projectConfig === userConfig) break\n if (\n (await exists(projectConfig)) &&\n (await this.#maybeLoadConfigFile(projectConfig))\n ) {\n lastKnownRoot = dir\n break\n }\n\n // stat existence of these files\n const [hasPackage, hasModules, hasWorkspaces, hasGit] =\n await Promise.all([\n exists(resolve(dir, 'package.json')),\n exists(resolve(dir, 'node_modules')),\n exists(resolve(dir, 'vlt-workspaces.json')),\n exists(resolve(dir, '.git')),\n ])\n\n // treat these as potential roots\n if (hasPackage || hasModules || hasWorkspaces) {\n lastKnownRoot = dir\n }\n\n // define backstops\n if (hasWorkspaces || hasGit) {\n break\n }\n }\n this.projectRoot = lastKnownRoot\n return this\n }\n\n /**\n * Determine whether we should use colors in the output. Update\n * chalk appropriately.\n *\n * Implicitly calls this.parse() if it not parsed already.\n */\n async loadColor(): Promise<this & LoadedConfig> {\n const c = this.get('color')\n const chalk = (await import('chalk')).default\n let color: boolean\n if (\n process.env.NO_COLOR !== '1' &&\n (c === true || (c === undefined && chalk.level > 0))\n ) {\n color = true\n chalk.level = Math.max(chalk.level, 1) as 0 | 1 | 2 | 3\n process.env.FORCE_COLOR = String(chalk.level)\n delete process.env.NO_COLOR\n } else {\n color = false\n chalk.level = 0\n process.env.FORCE_COLOR = '0'\n process.env.NO_COLOR = '1'\n }\n const { values = this.parse().values } = this\n ;(values as ConfigData & { color: boolean }).color = color\n return this as this & LoadedConfig\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 const c = await b.parse(argv).loadColor()\n this.#loaded = c 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 get(k: 'color'): boolean\n}\n"]}
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;AACxD,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAE5C,OAAO,EACL,wBAAwB,EACxB,mBAAmB,EACnB,oBAAoB,GACrB,MAAM,eAAe,CAAA;AAEtB,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAA;AAC3D,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAA;AAE7C,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAC1D,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACnC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAExC,OAAO,EACL,QAAQ,EACR,UAAU,EAC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oB,CAAC,SAAS,CAAC,CAAA;QAE1C,6EAA6E;QAC7E,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,aAAa,CAAC,CAAA;IAChC,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,OAAO,CAA0B;IAExC;;;OAGG;IACH,MAAM,CAAC,KAAK,CAAC,IAAI,CACf,WAAW,GAAG,OAAO,CAAC,GAAG,EAAE,EAC3B,IAAI,GAAG,OAAO,CAAC,IAAI;IACnB;;;OAGG;IACH,MAAM,GAAG,KAAK;QAEd,IAAI,IAAI,CAAC,OAAO,IAAI,CAAC,MAAM;YAAE,OAAO,IAAI,CAAC,OAAO,CAAA;QAChD,MAAM,CAAC,GAAG,IAAI,MAAM,CAAC,UAAU,EAAE,WAAW,CAAC,CAAA;QAC7C,MAAM,CAAC,GAAG,MAAM,CAAC,CAAC,cAAc,EAAE,CAAA;QAClC,IAAI,CAAC,OAAO,GAAG,CAAC,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 {\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 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 if (command) {\n for (const [c, opts] of Object.entries(command)) {\n const cmd = getCommand(c)\n if (cmd) {\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,2 +1,4 @@
1
- export declare const merge: <T extends Record<string, any>>(base: T, add: T) => T;
1
+ type MergeableObject = Record<string, unknown>;
2
+ export declare const merge: <T extends MergeableObject>(base: T, add: T) => T;
3
+ export {};
2
4
  //# sourceMappingURL=merge.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"merge.d.ts","sourceRoot":"","sources":["../../../src/config/merge.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,KAAK,GAAI,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,QAC3C,CAAC,OACF,CAAC,KACL,CAsBK,CAAA"}
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,14 +1,19 @@
1
- /* eslint-disable @typescript-eslint/no-unsafe-assignment */
2
- /* eslint-disable @typescript-eslint/no-unsafe-return */
3
- // deep merge 2 objects
4
- // scalars are overwritten, objects are folded in together
5
- // if nothing to be added, then return the base object.
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
6
  export const merge = (base, add) => Object.fromEntries(Object.entries(base)
7
7
  .map(([k, v]) => [
8
8
  k,
9
9
  add[k] === undefined ? v
10
10
  : Array.isArray(v) && Array.isArray(add[k]) ?
11
- [...new Set([...v, ...add[k]])]
11
+ [
12
+ ...new Set([
13
+ ...v,
14
+ ...add[k],
15
+ ]),
16
+ ]
12
17
  : Array.isArray(v) || Array.isArray(add[k]) ? add[k]
13
18
  : (!!v &&
14
19
  typeof v === 'object' &&
@@ -1 +1 @@
1
- {"version":3,"file":"merge.js","sourceRoot":"","sources":["../../../src/config/merge.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,wDAAwD;AAExD,uBAAuB;AACvB,0DAA0D;AAC1D,uDAAuD;AACvD,MAAM,CAAC,MAAM,KAAK,GAAG,CACnB,IAAO,EACP,GAAM,EACH,EAAE,CACL,MAAM,CAAC,WAAW,CAChB,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC;KACjB,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC;IACf,CAAC;IACD,GAAG,CAAC,CAAC,CAAC,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC;QACxB,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YAC3C,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,CAAC,EAAE,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YACjC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;gBACpD,CAAC,CAAC,CACA,CAAC,CAAC,CAAC;oBACH,OAAO,CAAC,KAAK,QAAQ;oBACrB,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;oBACR,OAAO,GAAG,CAAC,CAAC,CAAC,KAAK,QAAQ,CAC3B,CAAC,CAAC;oBACD,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC;oBAClB,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;CACT,CAAC;KACD,MAAM;AACL,iEAAiE;AACjE,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,SAAS,CAAC,CAC3D,CACC,CAAA","sourcesContent":["/* eslint-disable @typescript-eslint/no-unsafe-assignment */\n/* eslint-disable @typescript-eslint/no-unsafe-return */\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.\nexport const merge = <T extends Record<string, any>>(\n base: T,\n add: T,\n): T =>\n Object.fromEntries(\n Object.entries(base)\n .map(([k, v]) => [\n k,\n add[k] === undefined ? v\n : Array.isArray(v) && Array.isArray(add[k]) ?\n [...new Set([...v, ...add[k]])]\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, add[k])\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
+ {"version":3,"file":"merge.js","sourceRoot":"","sources":["../../../src/config/merge.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG,CACnB,IAAO,EACP,GAAM,EACH,EAAE,CACL,MAAM,CAAC,WAAW,CAChB,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC;KACjB,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAqB,EAAE,CAAC;IAClC,CAAC;IACD,GAAG,CAAC,CAAC,CAAC,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC;QACxB,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YAC3C;gBACE,GAAG,IAAI,GAAG,CAAC;oBACT,GAAI,CAAoB;oBACxB,GAAI,GAAG,CAAC,CAAC,CAAoB;iBAC9B,CAAC;aACH;YACH,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;gBACpD,CAAC,CAAC,CACA,CAAC,CAAC,CAAC;oBACH,OAAO,CAAC,KAAK,QAAQ;oBACrB,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;oBACR,OAAO,GAAG,CAAC,CAAC,CAAC,KAAK,QAAQ,CAC3B,CAAC,CAAC;oBACD,KAAK,CAAC,CAAoB,EAAE,GAAG,CAAC,CAAC,CAAoB,CAAC;oBACxD,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;CACT,CAAC;KACD,MAAM;AACL,iEAAiE;AACjE,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,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"]}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Generates the custom default help output for vlt
3
+ */
4
+ export declare const generateDefaultHelp: (colors?: boolean) => string;
5
+ /**
6
+ * Generates the full help output with all commands when --all flag is used
7
+ */
8
+ export declare const generateFullHelp: (colors?: boolean) => string;
9
+ //# sourceMappingURL=custom-help.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"custom-help.d.ts","sourceRoot":"","sources":["../../src/custom-help.ts"],"names":[],"mappings":"AAkQA;;GAEG;AACH,eAAO,MAAM,mBAAmB,wBAAqB,MAiDpD,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,gBAAgB,wBAAqB,MA8HjD,CAAA"}