@vltpkg/cli-sdk 0.0.0-13 → 0.0.0-15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/commands/cache.js +1 -0
- package/dist/esm/commands/cache.js.map +1 -1
- package/dist/esm/commands/config.js.map +1 -1
- package/dist/esm/commands/exec-cache.js +12 -3
- package/dist/esm/commands/exec-cache.js.map +1 -1
- package/dist/esm/commands/exec.d.ts.map +1 -1
- package/dist/esm/commands/exec.js +4 -1
- package/dist/esm/commands/exec.js.map +1 -1
- package/dist/esm/config/definition.d.ts +7 -0
- package/dist/esm/config/definition.d.ts.map +1 -1
- package/dist/esm/config/definition.js +6 -0
- package/dist/esm/config/definition.js.map +1 -1
- package/dist/esm/config/index.d.ts +34 -115
- package/dist/esm/config/index.d.ts.map +1 -1
- package/dist/esm/config/index.js +58 -144
- package/dist/esm/config/index.js.map +1 -1
- package/dist/esm/exec-command.d.ts +1 -1
- package/dist/esm/exec-command.d.ts.map +1 -1
- package/dist/esm/exec-command.js +46 -8
- package/dist/esm/exec-command.js.map +1 -1
- package/dist/esm/output.d.ts.map +1 -1
- package/dist/esm/output.js +1 -3
- package/dist/esm/output.js.map +1 -1
- package/dist/esm/print-err.d.ts +1 -1
- package/dist/esm/print-err.d.ts.map +1 -1
- package/dist/esm/print-err.js +45 -2
- package/dist/esm/print-err.js.map +1 -1
- package/package.json +30 -30
|
@@ -22,41 +22,52 @@
|
|
|
22
22
|
*/
|
|
23
23
|
import { PackageInfoClient } from '@vltpkg/package-info';
|
|
24
24
|
import { PackageJson } from '@vltpkg/package-json';
|
|
25
|
+
import type { SpecOptions } from '@vltpkg/spec';
|
|
26
|
+
import type { WhichConfig } from '@vltpkg/vlt-json';
|
|
25
27
|
import { Monorepo } from '@vltpkg/workspaces';
|
|
26
28
|
import type { Jack, OptionsResults, Unwrap } from 'jackspeak';
|
|
27
29
|
import { PathScurry } from 'path-scurry';
|
|
28
|
-
import { kIndent, kNewline } from 'polite-json';
|
|
29
30
|
import type { Commands, RecordField } from './definition.ts';
|
|
30
31
|
import { commands, definition, isRecordField, recordFields } from './definition.ts';
|
|
31
32
|
export { commands, definition, isRecordField, recordFields, type Commands, };
|
|
32
33
|
export declare const kCustomInspect: unique symbol;
|
|
33
34
|
export type RecordPairs = Record<string, unknown>;
|
|
34
35
|
export type RecordString = Record<string, string>;
|
|
35
|
-
export type
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
export type PairsAsRecords = ConfigOptionsNoExtras & {
|
|
37
|
+
command?: {
|
|
38
|
+
[k in keyof Commands]?: ConfigOptionsNoExtras;
|
|
39
|
+
};
|
|
38
40
|
};
|
|
39
|
-
export declare const pairsToRecords: (obj: NonNullable<ConfigFileData
|
|
41
|
+
export declare const pairsToRecords: (obj: NonNullable<ConfigFileData> | OptionsResults<ConfigDefinitions>) => PairsAsRecords;
|
|
40
42
|
export declare const recordsToPairs: (obj: RecordPairs) => RecordPairs;
|
|
43
|
+
export type ConfigDataNoCommand = {
|
|
44
|
+
[k in keyof OptionsResults<ConfigDefinitions>]?: OptionsResults<ConfigDefinitions>[k];
|
|
45
|
+
};
|
|
41
46
|
/**
|
|
42
47
|
* Config data can be any options, and also a 'command' field which
|
|
43
48
|
* contains command names and override options for that command.
|
|
44
49
|
*/
|
|
45
|
-
export type ConfigData =
|
|
46
|
-
command?:
|
|
50
|
+
export type ConfigData = ConfigDataNoCommand & {
|
|
51
|
+
command?: {
|
|
52
|
+
[k in keyof Commands]?: ConfigDataNoCommand;
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
export type ConfigFileDataNoCommand = {
|
|
56
|
+
[k in keyof ConfigDataNoCommand]: k extends (OptListKeys<ConfigDataNoCommand>) ? RecordString | string[] : ConfigDataNoCommand[k];
|
|
47
57
|
};
|
|
48
58
|
/**
|
|
49
|
-
* Config data as it appears in config
|
|
50
|
-
* stored as `Record<string, string
|
|
59
|
+
* Config data as it appears in the config field of the vlt.json, with kv pair
|
|
60
|
+
* lists stored as `Record<string, string>` and
|
|
51
61
|
*/
|
|
52
|
-
export type ConfigFileData = {
|
|
53
|
-
|
|
54
|
-
[k in keyof
|
|
62
|
+
export type ConfigFileData = ConfigFileDataNoCommand & {
|
|
63
|
+
command?: {
|
|
64
|
+
[k in keyof Commands]?: ConfigFileDataNoCommand;
|
|
55
65
|
};
|
|
56
66
|
};
|
|
57
|
-
export type
|
|
58
|
-
[k in keyof
|
|
59
|
-
}
|
|
67
|
+
export type ConfigOptionsNoExtras = {
|
|
68
|
+
[k in keyof OptionsResults<ConfigDefinitions>]: k extends (RecordField) ? RecordString : k extends 'command' ? never : OptionsResults<ConfigDefinitions>[k];
|
|
69
|
+
};
|
|
70
|
+
export type ConfigOptions = ConfigOptionsNoExtras & Pick<SpecOptions, 'catalog' | 'catalogs'> & {
|
|
60
71
|
packageJson: PackageJson;
|
|
61
72
|
scurry: PathScurry;
|
|
62
73
|
projectRoot: string;
|
|
@@ -83,11 +94,6 @@ export declare class Config {
|
|
|
83
94
|
* representing vlt's configuration
|
|
84
95
|
*/
|
|
85
96
|
jack: Jack<ConfigDefinitions>;
|
|
86
|
-
stringifyOptions: {
|
|
87
|
-
[kIndent]: string;
|
|
88
|
-
[kNewline]: string;
|
|
89
|
-
};
|
|
90
|
-
configFiles: ConfigFiles;
|
|
91
97
|
/**
|
|
92
98
|
* Parsed values in effect
|
|
93
99
|
*/
|
|
@@ -157,100 +163,17 @@ export declare class Config {
|
|
|
157
163
|
/**
|
|
158
164
|
* Write the config values to the user or project config file.
|
|
159
165
|
*/
|
|
160
|
-
writeConfigFile(
|
|
161
|
-
color?: boolean | undefined;
|
|
162
|
-
'no-color'?: boolean | undefined;
|
|
163
|
-
registry?: string | undefined;
|
|
164
|
-
registries?: string[] | RecordString | undefined;
|
|
165
|
-
'scope-registries'?: string[] | RecordString | undefined;
|
|
166
|
-
'jsr-registries'?: string[] | RecordString | undefined;
|
|
167
|
-
'git-hosts'?: string[] | RecordString | undefined;
|
|
168
|
-
'git-host-archives'?: string[] | RecordString | undefined;
|
|
169
|
-
cache?: string | undefined;
|
|
170
|
-
tag?: string | undefined;
|
|
171
|
-
before?: string | undefined;
|
|
172
|
-
os?: string | undefined;
|
|
173
|
-
arch?: string | undefined;
|
|
174
|
-
'node-version'?: string | undefined;
|
|
175
|
-
'git-shallow'?: boolean | undefined;
|
|
176
|
-
'fetch-retries'?: number | undefined;
|
|
177
|
-
'fetch-retry-factor'?: number | undefined;
|
|
178
|
-
'fetch-retry-mintimeout'?: number | undefined;
|
|
179
|
-
'fetch-retry-maxtimeout'?: number | undefined;
|
|
180
|
-
'stale-while-revalidate-factor'?: number | undefined;
|
|
181
|
-
identity?: string | undefined;
|
|
182
|
-
workspace?: string[] | RecordString | undefined;
|
|
183
|
-
'workspace-group'?: string[] | RecordString | undefined;
|
|
184
|
-
recursive?: boolean | undefined;
|
|
185
|
-
bail?: boolean | undefined;
|
|
186
|
-
'no-bail'?: boolean | undefined;
|
|
187
|
-
config?: "user" | "project" | undefined;
|
|
188
|
-
editor?: string | undefined;
|
|
189
|
-
'script-shell'?: string | undefined;
|
|
190
|
-
'fallback-command'?: string | undefined;
|
|
191
|
-
package?: string | undefined;
|
|
192
|
-
view?: "human" | "json" | "gui" | "mermaid" | "inspect" | undefined;
|
|
193
|
-
'dashboard-root'?: string[] | RecordString | undefined;
|
|
194
|
-
'save-dev'?: boolean | undefined;
|
|
195
|
-
'save-optional'?: boolean | undefined;
|
|
196
|
-
'save-peer'?: boolean | undefined;
|
|
197
|
-
'save-prod'?: boolean | undefined;
|
|
198
|
-
'expect-results'?: string | undefined;
|
|
199
|
-
yes?: boolean | undefined;
|
|
200
|
-
version?: boolean | undefined;
|
|
201
|
-
help?: boolean | undefined;
|
|
202
|
-
command?: ConfigFiles | undefined;
|
|
203
|
-
}>;
|
|
166
|
+
writeConfigFile(this: LoadedConfig, which: WhichConfig, values: NonNullable<ConfigFileData>): Promise<void>;
|
|
204
167
|
/**
|
|
205
168
|
* Fold in the provided fields with the existing properties
|
|
206
169
|
* in the config file.
|
|
207
170
|
*/
|
|
208
|
-
addConfigToFile(
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
'jsr-registries'?: string[] | RecordString | undefined;
|
|
215
|
-
'git-hosts'?: string[] | RecordString | undefined;
|
|
216
|
-
'git-host-archives'?: string[] | RecordString | undefined;
|
|
217
|
-
cache?: string | undefined;
|
|
218
|
-
tag?: string | undefined;
|
|
219
|
-
before?: string | undefined;
|
|
220
|
-
os?: string | undefined;
|
|
221
|
-
arch?: string | undefined;
|
|
222
|
-
'node-version'?: string | undefined;
|
|
223
|
-
'git-shallow'?: boolean | undefined;
|
|
224
|
-
'fetch-retries'?: number | undefined;
|
|
225
|
-
'fetch-retry-factor'?: number | undefined;
|
|
226
|
-
'fetch-retry-mintimeout'?: number | undefined;
|
|
227
|
-
'fetch-retry-maxtimeout'?: number | undefined;
|
|
228
|
-
'stale-while-revalidate-factor'?: number | undefined;
|
|
229
|
-
identity?: string | undefined;
|
|
230
|
-
workspace?: string[] | RecordString | undefined;
|
|
231
|
-
'workspace-group'?: string[] | RecordString | undefined;
|
|
232
|
-
recursive?: boolean | undefined;
|
|
233
|
-
bail?: boolean | undefined;
|
|
234
|
-
'no-bail'?: boolean | undefined;
|
|
235
|
-
config?: "user" | "project" | undefined;
|
|
236
|
-
editor?: string | undefined;
|
|
237
|
-
'script-shell'?: string | undefined;
|
|
238
|
-
'fallback-command'?: string | undefined;
|
|
239
|
-
package?: string | undefined;
|
|
240
|
-
view?: "human" | "json" | "gui" | "mermaid" | "inspect" | undefined;
|
|
241
|
-
'dashboard-root'?: string[] | RecordString | undefined;
|
|
242
|
-
'save-dev'?: boolean | undefined;
|
|
243
|
-
'save-optional'?: boolean | undefined;
|
|
244
|
-
'save-peer'?: boolean | undefined;
|
|
245
|
-
'save-prod'?: boolean | undefined;
|
|
246
|
-
'expect-results'?: string | undefined;
|
|
247
|
-
yes?: boolean | undefined;
|
|
248
|
-
version?: boolean | undefined;
|
|
249
|
-
help?: boolean | undefined;
|
|
250
|
-
command?: ConfigFiles | undefined;
|
|
251
|
-
}>;
|
|
252
|
-
getFilename(which?: 'project' | 'user'): string;
|
|
253
|
-
deleteConfigKeys(which: 'project' | 'user', fields: string[]): Promise<boolean>;
|
|
171
|
+
addConfigToFile(this: LoadedConfig, which: WhichConfig, values: NonNullable<ConfigFileData>): Promise<void>;
|
|
172
|
+
/**
|
|
173
|
+
* Deletes the specified config fields from the named file
|
|
174
|
+
* Returns `true` if anything was changed.
|
|
175
|
+
*/
|
|
176
|
+
deleteConfigKeys(this: LoadedConfig, which: WhichConfig, fields: string[]): Promise<boolean>;
|
|
254
177
|
/**
|
|
255
178
|
* Edit the user or project configuration file.
|
|
256
179
|
*
|
|
@@ -261,14 +184,10 @@ export declare class Config {
|
|
|
261
184
|
* file after editing, then it's restored to what it was before, which might
|
|
262
185
|
* mean deleting the file.
|
|
263
186
|
*/
|
|
264
|
-
editConfigFile(
|
|
187
|
+
editConfigFile(this: LoadedConfig, which: WhichConfig, edit: (file: string) => Promise<void> | void): Promise<void>;
|
|
265
188
|
/**
|
|
266
189
|
* Find the local config file and load both it and the user-level config in
|
|
267
190
|
* the XDG config home.
|
|
268
|
-
*
|
|
269
|
-
* Note: if working in a workspaces monorepo, then the vlt.json file MUST
|
|
270
|
-
* be in the same folder as the vlt.json file, because we stop
|
|
271
|
-
* looking when we find either one.
|
|
272
191
|
*/
|
|
273
192
|
loadConfigFile(): Promise<this>;
|
|
274
193
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/config/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAGH,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AACxD,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAClD,OAAO,EAAE,
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GAAG,CAAC,CAAC,SAAS,MAAM,cAAc,CAAC,iBAAiB,CAAC,EACnD,CAAC,EAAE,CAAC,GACH,cAAc,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC;IAKvC;;OAEG;IACG,eAAe,CACnB,IAAI,EAAE,YAAY,EAClB,KAAK,EAAE,WAAW,EAClB,MAAM,EAAE,WAAW,CAAC,cAAc,CAAC;IAKrC;;;OAGG;IACG,eAAe,CACnB,IAAI,EAAE,YAAY,EAClB,KAAK,EAAE,WAAW,EAClB,MAAM,EAAE,WAAW,CAAC,cAAc,CAAC;IAqDrC;;;OAGG;IACG,gBAAgB,CACpB,IAAI,EAAE,YAAY,EAClB,KAAK,EAAE,WAAW,EAClB,MAAM,EAAE,MAAM,EAAE;IAwClB;;;;;;;;;OASG;IACG,cAAc,CAClB,IAAI,EAAE,YAAY,EAClB,KAAK,EAAE,WAAW,EAClB,IAAI,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI;IAmC9C;;;OAGG;IACG,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC;IAYrC;;;OAGG;WACU,IAAI,CACf,WAAW,SAAgB,EAC3B,IAAI,WAAe;IACnB;;;OAGG;IACH,MAAM,UAAQ,GACb,OAAO,CAAC,YAAY,CAAC;CAOzB;AAKD,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG;IAClC,OAAO,EAAE,WAAW,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAA;IACvC,MAAM,EAAE,cAAc,CAAC,iBAAiB,CAAC,CAAA;IACzC,WAAW,EAAE,MAAM,EAAE,CAAA;CACtB,CAAA;AAED;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,YAAY,CAAA"}
|
package/dist/esm/config/index.js
CHANGED
|
@@ -23,15 +23,12 @@
|
|
|
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 { assertRecordStringString, assertRecordStringT, isRecordStringString, } from '@vltpkg/types';
|
|
27
|
+
import { find, load, reload, save } from '@vltpkg/vlt-json';
|
|
26
28
|
import { Monorepo } from '@vltpkg/workspaces';
|
|
27
|
-
import {
|
|
28
|
-
import {
|
|
29
|
-
import { lstat, mkdir, readFile, writeFile } from 'node:fs/promises';
|
|
30
|
-
import { homedir } from 'node:os';
|
|
31
|
-
import { dirname, resolve } from 'node:path';
|
|
29
|
+
import { readFile, rm, writeFile } from 'node:fs/promises';
|
|
30
|
+
import { dirname } from 'node:path';
|
|
32
31
|
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
32
|
import { commands, definition, getCommand, isRecordField, recordFields, } from "./definition.js";
|
|
36
33
|
import { merge } from "./merge.js";
|
|
37
34
|
export { commands, definition, isRecordField, recordFields, };
|
|
@@ -86,9 +83,6 @@ export const recordsToPairs = (obj) => {
|
|
|
86
83
|
]));
|
|
87
84
|
};
|
|
88
85
|
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
86
|
/**
|
|
93
87
|
* Class that handles configuration for vlt.
|
|
94
88
|
*
|
|
@@ -100,8 +94,6 @@ export class Config {
|
|
|
100
94
|
* representing vlt's configuration
|
|
101
95
|
*/
|
|
102
96
|
jack;
|
|
103
|
-
stringifyOptions = { [kIndent]: ' ', [kNewline]: '\n' };
|
|
104
|
-
configFiles = {};
|
|
105
97
|
/**
|
|
106
98
|
* Parsed values in effect
|
|
107
99
|
*/
|
|
@@ -127,6 +119,8 @@ export class Config {
|
|
|
127
119
|
scurry,
|
|
128
120
|
packageJson,
|
|
129
121
|
}),
|
|
122
|
+
catalog: load('catalog', assertRecordStringString),
|
|
123
|
+
catalogs: load('catalogs', o => assertRecordStringT(o, isRecordStringString, 'Record<string, Record<string, string>>')),
|
|
130
124
|
};
|
|
131
125
|
const options = Object.assign(asRecords, extras);
|
|
132
126
|
this.#options = Object.assign(options, {
|
|
@@ -250,90 +244,52 @@ export class Config {
|
|
|
250
244
|
* Write the config values to the user or project config file.
|
|
251
245
|
*/
|
|
252
246
|
async writeConfigFile(which, values) {
|
|
253
|
-
|
|
254
|
-
await mkdir(dirname(f), { recursive: true });
|
|
255
|
-
const vals = Object.assign(pairsToRecords(values), this.stringifyOptions);
|
|
256
|
-
const data = await readFile(f, 'utf8')
|
|
257
|
-
.then(data => jsonParse(data))
|
|
258
|
-
.catch(() => ({ config: {} }));
|
|
259
|
-
data.config = vals;
|
|
260
|
-
await writeFile(f, jsonStringify(data));
|
|
261
|
-
this.configFiles[f] = vals;
|
|
262
|
-
return values;
|
|
247
|
+
return save('config', pairsToRecords(values), which);
|
|
263
248
|
}
|
|
264
249
|
/**
|
|
265
250
|
* Fold in the provided fields with the existing properties
|
|
266
251
|
* in the config file.
|
|
267
252
|
*/
|
|
268
253
|
async addConfigToFile(which, values) {
|
|
269
|
-
|
|
270
|
-
return this.writeConfigFile(which, merge((await this.#maybeLoadConfigFile(f)) ?? {}, values));
|
|
254
|
+
return this.writeConfigFile(which, merge((await this.#maybeLoadConfigFile(which)) ?? {}, values));
|
|
271
255
|
}
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
if (
|
|
279
|
-
|
|
280
|
-
if (command) {
|
|
281
|
-
for (const [c, opts] of Object.entries(command)) {
|
|
282
|
-
const cmd = getCommand(c);
|
|
283
|
-
if (cmd) {
|
|
284
|
-
this.commandValues[cmd] = merge(this.commandValues[cmd] ?? {}, opts);
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
this.jack.setConfigValues(values, file);
|
|
289
|
-
return result;
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
async #readConfigFile(file) {
|
|
293
|
-
if (this.configFiles[file])
|
|
294
|
-
return this.configFiles[file];
|
|
295
|
-
const data = await readFile(file, 'utf8').catch(() => { });
|
|
296
|
-
if (!data)
|
|
297
|
-
return undefined;
|
|
298
|
-
let result;
|
|
299
|
-
try {
|
|
300
|
-
result = jsonParse(data);
|
|
301
|
-
if (result && typeof result === 'object') {
|
|
302
|
-
if (result[kIndent] !== undefined)
|
|
303
|
-
this.stringifyOptions[kIndent] = result[kIndent];
|
|
304
|
-
if (result[kNewline] !== undefined)
|
|
305
|
-
this.stringifyOptions[kNewline] = result[kNewline];
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
catch (er) {
|
|
309
|
-
throw error('failed to parse vlt config file', {
|
|
256
|
+
// called in this weird bound way so that it can be used by the
|
|
257
|
+
// vlt-json config loading module.
|
|
258
|
+
#validator = function (c, file) {
|
|
259
|
+
this.#validateConfig(c, file);
|
|
260
|
+
}.bind(this);
|
|
261
|
+
#validateConfig(c, file) {
|
|
262
|
+
if (!c || typeof c !== 'object' || Array.isArray(c)) {
|
|
263
|
+
throw error('invalid config, expected object', {
|
|
310
264
|
path: file,
|
|
311
|
-
|
|
265
|
+
found: c,
|
|
266
|
+
wanted: 'ConfigFileData',
|
|
312
267
|
});
|
|
313
268
|
}
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
found: result,
|
|
323
|
-
wanted: '{ "config"?: ConfigFileData }',
|
|
324
|
-
});
|
|
269
|
+
const { command, ...values } = recordsToPairs(c);
|
|
270
|
+
if (command) {
|
|
271
|
+
for (const [c, opts] of Object.entries(command)) {
|
|
272
|
+
const cmd = getCommand(c);
|
|
273
|
+
if (cmd) {
|
|
274
|
+
this.commandValues[cmd] = merge(this.commandValues[cmd] ?? {}, opts);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
325
277
|
}
|
|
326
|
-
this.
|
|
327
|
-
return this.configFiles[file];
|
|
278
|
+
this.jack.setConfigValues(values, file);
|
|
328
279
|
}
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
280
|
+
/**
|
|
281
|
+
* if the file exists, parse and load it. returns object if data was
|
|
282
|
+
* loaded, or undefined if not.
|
|
283
|
+
*/
|
|
284
|
+
async #maybeLoadConfigFile(whichConfig) {
|
|
285
|
+
return load('config', this.#validator, whichConfig);
|
|
333
286
|
}
|
|
287
|
+
/**
|
|
288
|
+
* Deletes the specified config fields from the named file
|
|
289
|
+
* Returns `true` if anything was changed.
|
|
290
|
+
*/
|
|
334
291
|
async deleteConfigKeys(which, fields) {
|
|
335
|
-
const
|
|
336
|
-
const data = await this.#maybeLoadConfigFile(file);
|
|
292
|
+
const data = await this.#maybeLoadConfigFile(which);
|
|
337
293
|
if (!data)
|
|
338
294
|
return false;
|
|
339
295
|
let didSomething = false;
|
|
@@ -369,7 +325,8 @@ export class Config {
|
|
|
369
325
|
delete data[k];
|
|
370
326
|
}
|
|
371
327
|
}
|
|
372
|
-
|
|
328
|
+
if (didSomething)
|
|
329
|
+
await this.writeConfigFile(which, data);
|
|
373
330
|
return didSomething;
|
|
374
331
|
}
|
|
375
332
|
/**
|
|
@@ -383,42 +340,33 @@ export class Config {
|
|
|
383
340
|
* mean deleting the file.
|
|
384
341
|
*/
|
|
385
342
|
async editConfigFile(which, edit) {
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
343
|
+
// load the file as a backup
|
|
344
|
+
// call the edit function
|
|
345
|
+
// reload it
|
|
346
|
+
const file = find(which);
|
|
347
|
+
const backup = await readFile(file, 'utf8').catch(() => undefined);
|
|
390
348
|
if (!backup) {
|
|
391
|
-
|
|
349
|
+
await writeFile(file, JSON.stringify({ config: {} }, null, 2) + '\n');
|
|
392
350
|
}
|
|
393
351
|
let valid = false;
|
|
394
352
|
try {
|
|
395
353
|
await edit(file);
|
|
396
|
-
|
|
397
|
-
if
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
('config' in res &&
|
|
401
|
-
(!res.config || typeof res.config !== 'object'))) {
|
|
402
|
-
throw error('Invalid configuration, expected object with config member', {
|
|
403
|
-
path: file,
|
|
404
|
-
found: res,
|
|
405
|
-
wanted: '{ config: ConfigData }',
|
|
406
|
-
});
|
|
407
|
-
}
|
|
408
|
-
const { config } = res;
|
|
409
|
-
if (config) {
|
|
410
|
-
this.jack.setConfigValues(recordsToPairs(config));
|
|
411
|
-
this.configFiles[file] = config;
|
|
412
|
-
}
|
|
354
|
+
// force it to reload the file and validate it again
|
|
355
|
+
// if this fails, we roll back.
|
|
356
|
+
const result = reload('config', which);
|
|
357
|
+
save('config', result ?? {}, which);
|
|
413
358
|
valid = true;
|
|
414
359
|
}
|
|
415
360
|
finally {
|
|
416
361
|
if (!valid) {
|
|
362
|
+
// TODO: maybe write the file to a re-edit backup location?
|
|
363
|
+
// then you could do `vlt config edit retry` or something.
|
|
417
364
|
if (backup) {
|
|
418
|
-
|
|
365
|
+
await writeFile(file, backup);
|
|
366
|
+
reload(which);
|
|
419
367
|
}
|
|
420
368
|
else {
|
|
421
|
-
|
|
369
|
+
await rm(file, { force: true });
|
|
422
370
|
}
|
|
423
371
|
}
|
|
424
372
|
}
|
|
@@ -426,45 +374,11 @@ export class Config {
|
|
|
426
374
|
/**
|
|
427
375
|
* Find the local config file and load both it and the user-level config in
|
|
428
376
|
* the XDG config home.
|
|
429
|
-
*
|
|
430
|
-
* Note: if working in a workspaces monorepo, then the vlt.json file MUST
|
|
431
|
-
* be in the same folder as the vlt.json file, because we stop
|
|
432
|
-
* looking when we find either one.
|
|
433
377
|
*/
|
|
434
378
|
async loadConfigFile() {
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
for (const dir of walkUp(this.projectRoot)) {
|
|
439
|
-
// don't look in ~
|
|
440
|
-
if (dir === home)
|
|
441
|
-
break;
|
|
442
|
-
// finding a project config file stops the search
|
|
443
|
-
const projectConfig = resolve(dir, 'vlt.json');
|
|
444
|
-
if (projectConfig === userConfig)
|
|
445
|
-
break;
|
|
446
|
-
if ((await exists(projectConfig)) &&
|
|
447
|
-
(await this.#maybeLoadConfigFile(projectConfig))) {
|
|
448
|
-
lastKnownRoot = dir;
|
|
449
|
-
break;
|
|
450
|
-
}
|
|
451
|
-
// stat existence of these files
|
|
452
|
-
const [hasPackage, hasModules, hasProject, hasGit] = await Promise.all([
|
|
453
|
-
exists(resolve(dir, 'package.json')),
|
|
454
|
-
exists(resolve(dir, 'node_modules')),
|
|
455
|
-
exists(resolve(dir, 'vlt.json')),
|
|
456
|
-
exists(resolve(dir, '.git')),
|
|
457
|
-
]);
|
|
458
|
-
// treat these as potential roots
|
|
459
|
-
if (hasPackage || hasModules || hasProject) {
|
|
460
|
-
lastKnownRoot = dir;
|
|
461
|
-
}
|
|
462
|
-
// define backstops
|
|
463
|
-
if (hasProject || hasGit) {
|
|
464
|
-
break;
|
|
465
|
-
}
|
|
466
|
-
}
|
|
467
|
-
this.projectRoot = lastKnownRoot;
|
|
379
|
+
await this.#maybeLoadConfigFile('user');
|
|
380
|
+
this.projectRoot = dirname(find('project', this.projectRoot));
|
|
381
|
+
await this.#maybeLoadConfigFile('project');
|
|
468
382
|
return this;
|
|
469
383
|
}
|
|
470
384
|
/**
|