@vltpkg/cli-sdk 0.0.0-2 → 0.0.0-21
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/README.md +3 -0
- package/dist/esm/commands/cache.d.ts +65 -0
- package/dist/esm/commands/cache.d.ts.map +1 -0
- package/dist/esm/commands/cache.js +257 -0
- package/dist/esm/commands/cache.js.map +1 -0
- package/dist/esm/commands/ci.d.ts +10 -0
- package/dist/esm/commands/ci.d.ts.map +1 -0
- package/dist/esm/commands/ci.js +29 -0
- package/dist/esm/commands/ci.js.map +1 -0
- package/dist/esm/commands/config.d.ts.map +1 -1
- package/dist/esm/commands/config.js +2 -52
- package/dist/esm/commands/config.js.map +1 -1
- package/dist/esm/commands/exec-cache.d.ts +49 -0
- package/dist/esm/commands/exec-cache.d.ts.map +1 -0
- package/dist/esm/commands/exec-cache.js +134 -0
- package/dist/esm/commands/exec-cache.js.map +1 -0
- package/dist/esm/commands/exec-local.d.ts +6 -0
- package/dist/esm/commands/exec-local.d.ts.map +1 -0
- package/dist/esm/commands/exec-local.js +24 -0
- package/dist/esm/commands/exec-local.js.map +1 -0
- package/dist/esm/commands/exec.d.ts +4 -0
- package/dist/esm/commands/exec.d.ts.map +1 -1
- package/dist/esm/commands/exec.js +69 -10
- package/dist/esm/commands/exec.js.map +1 -1
- package/dist/esm/commands/gui.d.ts.map +1 -1
- package/dist/esm/commands/gui.js +1 -2
- package/dist/esm/commands/gui.js.map +1 -1
- package/dist/esm/commands/help.d.ts +1 -1
- package/dist/esm/commands/help.d.ts.map +1 -1
- package/dist/esm/commands/help.js +25 -3
- package/dist/esm/commands/help.js.map +1 -1
- package/dist/esm/commands/init.d.ts +4 -5
- package/dist/esm/commands/init.d.ts.map +1 -1
- package/dist/esm/commands/init.js +95 -9
- package/dist/esm/commands/init.js.map +1 -1
- package/dist/esm/commands/install/reporter.d.ts.map +1 -1
- package/dist/esm/commands/install/reporter.js +2 -1
- package/dist/esm/commands/install/reporter.js.map +1 -1
- package/dist/esm/commands/install.d.ts +5 -2
- package/dist/esm/commands/install.d.ts.map +1 -1
- package/dist/esm/commands/install.js +7 -1
- package/dist/esm/commands/install.js.map +1 -1
- package/dist/esm/commands/list.d.ts +2 -2
- package/dist/esm/commands/list.d.ts.map +1 -1
- package/dist/esm/commands/list.js +108 -31
- package/dist/esm/commands/list.js.map +1 -1
- package/dist/esm/commands/pack.d.ts +20 -0
- package/dist/esm/commands/pack.d.ts.map +1 -0
- package/dist/esm/commands/pack.js +81 -0
- package/dist/esm/commands/pack.js.map +1 -0
- package/dist/esm/commands/pkg.d.ts +2 -3
- package/dist/esm/commands/pkg.d.ts.map +1 -1
- package/dist/esm/commands/pkg.js +136 -34
- package/dist/esm/commands/pkg.js.map +1 -1
- package/dist/esm/commands/publish.d.ts +21 -0
- package/dist/esm/commands/publish.d.ts.map +1 -0
- package/dist/esm/commands/publish.js +169 -0
- package/dist/esm/commands/publish.js.map +1 -0
- package/dist/esm/commands/query.d.ts +2 -2
- package/dist/esm/commands/query.d.ts.map +1 -1
- package/dist/esm/commands/query.js +134 -21
- package/dist/esm/commands/query.js.map +1 -1
- package/dist/esm/commands/run-exec.d.ts +1 -0
- package/dist/esm/commands/run-exec.d.ts.map +1 -1
- package/dist/esm/commands/run-exec.js +1 -0
- package/dist/esm/commands/run-exec.js.map +1 -1
- package/dist/esm/commands/run.d.ts +1 -0
- package/dist/esm/commands/run.d.ts.map +1 -1
- package/dist/esm/commands/run.js +13 -16
- package/dist/esm/commands/run.js.map +1 -1
- package/dist/esm/commands/uninstall.d.ts +7 -1
- package/dist/esm/commands/uninstall.d.ts.map +1 -1
- package/dist/esm/commands/uninstall.js +7 -1
- package/dist/esm/commands/uninstall.js.map +1 -1
- package/dist/esm/commands/update.d.ts +10 -0
- package/dist/esm/commands/update.d.ts.map +1 -0
- package/dist/esm/commands/update.js +25 -0
- package/dist/esm/commands/update.js.map +1 -0
- package/dist/esm/commands/version.d.ts +22 -0
- package/dist/esm/commands/version.d.ts.map +1 -0
- package/dist/esm/commands/version.js +151 -0
- package/dist/esm/commands/version.js.map +1 -0
- package/dist/esm/commands/whoami.d.ts +4 -2
- package/dist/esm/commands/whoami.d.ts.map +1 -1
- package/dist/esm/commands/whoami.js +1 -1
- package/dist/esm/commands/whoami.js.map +1 -1
- package/dist/esm/config/definition.d.ts +85 -7
- package/dist/esm/config/definition.d.ts.map +1 -1
- package/dist/esm/config/definition.js +152 -23
- package/dist/esm/config/definition.js.map +1 -1
- package/dist/esm/config/index.d.ts +46 -40
- package/dist/esm/config/index.d.ts.map +1 -1
- package/dist/esm/config/index.js +124 -176
- package/dist/esm/config/index.js.map +1 -1
- package/dist/esm/config/merge.d.ts +3 -1
- package/dist/esm/config/merge.d.ts.map +1 -1
- package/dist/esm/config/merge.js +11 -6
- package/dist/esm/config/merge.js.map +1 -1
- package/dist/esm/config/usage.d.ts +3 -2
- package/dist/esm/config/usage.d.ts.map +1 -1
- package/dist/esm/config/usage.js.map +1 -1
- package/dist/esm/exec-command.d.ts +32 -14
- package/dist/esm/exec-command.d.ts.map +1 -1
- package/dist/esm/exec-command.js +195 -63
- package/dist/esm/exec-command.js.map +1 -1
- package/dist/esm/index.d.ts +1 -14
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +46 -20
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/load-command.d.ts +16 -0
- package/dist/esm/load-command.d.ts.map +1 -0
- package/dist/esm/load-command.js +21 -0
- package/dist/esm/load-command.js.map +1 -0
- package/dist/esm/output.d.ts +6 -10
- package/dist/esm/output.d.ts.map +1 -1
- package/dist/esm/output.js +62 -32
- package/dist/esm/output.js.map +1 -1
- package/dist/esm/pack-tarball.d.ts +22 -0
- package/dist/esm/pack-tarball.d.ts.map +1 -0
- package/dist/esm/pack-tarball.js +247 -0
- package/dist/esm/pack-tarball.js.map +1 -0
- package/dist/esm/parse-add-remove-args.d.ts +1 -1
- package/dist/esm/parse-add-remove-args.d.ts.map +1 -1
- package/dist/esm/parse-add-remove-args.js +1 -1
- package/dist/esm/parse-add-remove-args.js.map +1 -1
- package/dist/esm/print-err.d.ts +12 -1
- package/dist/esm/print-err.d.ts.map +1 -1
- package/dist/esm/print-err.js +157 -26
- package/dist/esm/print-err.js.map +1 -1
- package/dist/esm/start-gui.d.ts +7 -33
- package/dist/esm/start-gui.d.ts.map +1 -1
- package/dist/esm/start-gui.js +33 -347
- package/dist/esm/start-gui.js.map +1 -1
- package/dist/esm/view.d.ts +2 -3
- package/dist/esm/view.d.ts.map +1 -1
- package/dist/esm/view.js.map +1 -1
- package/package.json +69 -44
- package/dist/esm/commands/install-exec.d.ts +0 -4
- package/dist/esm/commands/install-exec.d.ts.map +0 -1
- package/dist/esm/commands/install-exec.js +0 -13
- package/dist/esm/commands/install-exec.js.map +0 -1
- package/dist/esm/ignored-homedir-folder-names.d.ts +0 -7
- package/dist/esm/ignored-homedir-folder-names.d.ts.map +0 -1
- package/dist/esm/ignored-homedir-folder-names.js +0 -35
- package/dist/esm/ignored-homedir-folder-names.js.map +0 -1
- package/dist/esm/project-info.d.ts +0 -32
- package/dist/esm/project-info.d.ts.map +0 -1
- package/dist/esm/project-info.js +0 -90
- package/dist/esm/project-info.js.map +0 -1
- package/dist/esm/read-project-folders.d.ts +0 -27
- package/dist/esm/read-project-folders.d.ts.map +0 -1
- package/dist/esm/read-project-folders.js +0 -66
- package/dist/esm/read-project-folders.js.map +0 -1
package/README.md
CHANGED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { CacheEntry } from '@vltpkg/registry-client';
|
|
2
|
+
import type { LoadedConfig } from '../config/index.ts';
|
|
3
|
+
import type { CommandFn, CommandUsage } from '../index.ts';
|
|
4
|
+
import type { ViewOptions, Views } from '../view.ts';
|
|
5
|
+
import { ViewClass } from '../view.ts';
|
|
6
|
+
export type CacheMap = Record<string, ReturnType<CacheEntry['toJSON']>>;
|
|
7
|
+
export type CacheSubcommands = keyof (typeof usageDef)['subcommands'];
|
|
8
|
+
export declare class CacheView extends ViewClass {
|
|
9
|
+
constructor(options: ViewOptions, conf: LoadedConfig);
|
|
10
|
+
stdout(...args: unknown[]): void;
|
|
11
|
+
}
|
|
12
|
+
export declare const views: Views<void | CacheMap>;
|
|
13
|
+
declare const usageDef: {
|
|
14
|
+
readonly command: "cache";
|
|
15
|
+
readonly usage: "<command> [flags]";
|
|
16
|
+
readonly description: "Work with vlt cache folders";
|
|
17
|
+
readonly subcommands: {
|
|
18
|
+
readonly add: {
|
|
19
|
+
readonly usage: "<package-spec> [<package-spec>...]";
|
|
20
|
+
readonly description: "Resolve the referenced package identifiers and ensure they\n are cached.";
|
|
21
|
+
};
|
|
22
|
+
readonly ls: {
|
|
23
|
+
readonly usage: "[<key>...]";
|
|
24
|
+
readonly description: "Show cache entries. If no keys are provided, then a list of\n available keys will be printed. If one or more keys are\n provided, then details will be shown for the specified\n items.";
|
|
25
|
+
};
|
|
26
|
+
readonly info: {
|
|
27
|
+
readonly usage: "<key>";
|
|
28
|
+
readonly description: "Print metadata details for the specified cache key to\n stderr, and the response body to stdout.";
|
|
29
|
+
};
|
|
30
|
+
readonly clean: {
|
|
31
|
+
readonly usage: "[<key>...]";
|
|
32
|
+
readonly description: "Purge expired cache entries. If one or more keys are\n provided, then only those cache entries will be\n considered.";
|
|
33
|
+
};
|
|
34
|
+
readonly delete: {
|
|
35
|
+
readonly usage: "<key> [<key>...]";
|
|
36
|
+
readonly description: "Purge items explicitly, whether expired or not. If one or\n more keys are provided, then only those cache entries will\n be considered.";
|
|
37
|
+
};
|
|
38
|
+
readonly 'delete-before': {
|
|
39
|
+
readonly usage: "<date>";
|
|
40
|
+
readonly description: "Purge all cache items from before a given date. Date can be\n provided in any format that JavaScript can parse.";
|
|
41
|
+
};
|
|
42
|
+
readonly 'delete-all': {
|
|
43
|
+
readonly usage: "";
|
|
44
|
+
readonly description: "Delete the entire cache folder to make vlt slower.";
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
readonly examples: {
|
|
48
|
+
readonly 'vlt cache ls https://registry.npmjs.org/typescript': {
|
|
49
|
+
readonly description: "Show cache metadata for a given registry URL";
|
|
50
|
+
};
|
|
51
|
+
readonly 'vlt cache add eslint@latest': {
|
|
52
|
+
readonly description: "Add a given package specifier to the cache by fetching\n its resolved value.";
|
|
53
|
+
};
|
|
54
|
+
readonly 'vlt cache info https://registry.npmjs.org/eslint/-/eslint-9.25.1.tgz > eslint.tgz': {
|
|
55
|
+
readonly description: "Print the cache metadata to stderr, and write the tarball\n on stdout, redirecting to a file.";
|
|
56
|
+
};
|
|
57
|
+
readonly 'vlt cache delete-before 2025-01-01': {
|
|
58
|
+
readonly description: "Delete all entries created before Jan 1, 2025";
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
export declare const usage: CommandUsage;
|
|
63
|
+
export declare const command: CommandFn<void | CacheMap>;
|
|
64
|
+
export {};
|
|
65
|
+
//# sourceMappingURL=cache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../../../src/commands/cache.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAA;AAIpD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAGtD,OAAO,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAE1D,OAAO,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AACpD,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AAEtC,MAAM,MAAM,QAAQ,GAAG,MAAM,CAC3B,MAAM,EACN,UAAU,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,CACjC,CAAA;AAED,MAAM,MAAM,gBAAgB,GAAG,MAAM,CAAC,OAAO,QAAQ,CAAC,CAAC,aAAa,CAAC,CAAA;AAGrE,qBAAa,SAAU,SAAQ,SAAS;gBAC1B,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,YAAY;IAIpD,MAAM,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE;CAG1B;AAED,eAAO,MAAM,KAAK,EAAE,KAAK,CAAC,IAAI,GAAG,QAAQ,CAExC,CAAA;AAED,QAAA,MAAM,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAoE6B,CAAA;AAE3C,eAAO,MAAM,KAAK,EAAE,YAA2C,CAAA;AAE/D,eAAO,MAAM,OAAO,EAAE,SAAS,CAAC,IAAI,GAAG,QAAQ,CAgC9C,CAAA"}
|
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
import { error } from '@vltpkg/error-cause';
|
|
2
|
+
import { CacheEntry } from '@vltpkg/registry-client';
|
|
3
|
+
import { Spec } from '@vltpkg/spec';
|
|
4
|
+
import { mkdir, rm } from 'node:fs/promises';
|
|
5
|
+
import prettyBytes from 'pretty-bytes';
|
|
6
|
+
import { commandUsage } from "../config/usage.js";
|
|
7
|
+
import { stderr, stdout } from "../output.js";
|
|
8
|
+
import { ViewClass } from "../view.js";
|
|
9
|
+
let view;
|
|
10
|
+
export class CacheView extends ViewClass {
|
|
11
|
+
constructor(options, conf) {
|
|
12
|
+
super(options, conf);
|
|
13
|
+
view = this;
|
|
14
|
+
}
|
|
15
|
+
stdout(...args) {
|
|
16
|
+
stdout(...args);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
export const views = {
|
|
20
|
+
human: CacheView,
|
|
21
|
+
};
|
|
22
|
+
const usageDef = {
|
|
23
|
+
command: 'cache',
|
|
24
|
+
usage: '<command> [flags]',
|
|
25
|
+
description: 'Work with vlt cache folders',
|
|
26
|
+
subcommands: {
|
|
27
|
+
add: {
|
|
28
|
+
usage: '<package-spec> [<package-spec>...]',
|
|
29
|
+
description: `Resolve the referenced package identifiers and ensure they
|
|
30
|
+
are cached.`,
|
|
31
|
+
},
|
|
32
|
+
ls: {
|
|
33
|
+
usage: '[<key>...]',
|
|
34
|
+
description: `Show cache entries. If no keys are provided, then a list of
|
|
35
|
+
available keys will be printed. If one or more keys are
|
|
36
|
+
provided, then details will be shown for the specified
|
|
37
|
+
items.`,
|
|
38
|
+
},
|
|
39
|
+
info: {
|
|
40
|
+
usage: '<key>',
|
|
41
|
+
description: `Print metadata details for the specified cache key to
|
|
42
|
+
stderr, and the response body to stdout.`,
|
|
43
|
+
},
|
|
44
|
+
clean: {
|
|
45
|
+
usage: '[<key>...]',
|
|
46
|
+
description: `Purge expired cache entries. If one or more keys are
|
|
47
|
+
provided, then only those cache entries will be
|
|
48
|
+
considered.`,
|
|
49
|
+
},
|
|
50
|
+
delete: {
|
|
51
|
+
usage: '<key> [<key>...]',
|
|
52
|
+
description: `Purge items explicitly, whether expired or not. If one or
|
|
53
|
+
more keys are provided, then only those cache entries will
|
|
54
|
+
be considered.`,
|
|
55
|
+
},
|
|
56
|
+
'delete-before': {
|
|
57
|
+
usage: '<date>',
|
|
58
|
+
description: `Purge all cache items from before a given date. Date can be
|
|
59
|
+
provided in any format that JavaScript can parse.`,
|
|
60
|
+
},
|
|
61
|
+
'delete-all': {
|
|
62
|
+
usage: '',
|
|
63
|
+
description: `Delete the entire cache folder to make vlt slower.`,
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
examples: {
|
|
67
|
+
'vlt cache ls https://registry.npmjs.org/typescript': {
|
|
68
|
+
description: `Show cache metadata for a given registry URL`,
|
|
69
|
+
},
|
|
70
|
+
'vlt cache add eslint@latest': {
|
|
71
|
+
description: `Add a given package specifier to the cache by fetching
|
|
72
|
+
its resolved value.`,
|
|
73
|
+
},
|
|
74
|
+
'vlt cache info https://registry.npmjs.org/eslint/-/eslint-9.25.1.tgz > eslint.tgz': {
|
|
75
|
+
description: `Print the cache metadata to stderr, and write the tarball
|
|
76
|
+
on stdout, redirecting to a file.`,
|
|
77
|
+
},
|
|
78
|
+
'vlt cache delete-before 2025-01-01': {
|
|
79
|
+
description: 'Delete all entries created before Jan 1, 2025',
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
export const usage = () => commandUsage(usageDef);
|
|
84
|
+
export const command = async (conf) => {
|
|
85
|
+
const [sub, ...args] = conf.positionals;
|
|
86
|
+
switch (sub) {
|
|
87
|
+
case 'ls':
|
|
88
|
+
return ls(conf, args, view);
|
|
89
|
+
case 'info':
|
|
90
|
+
return info(conf, args, view);
|
|
91
|
+
case 'add':
|
|
92
|
+
return add(conf, args, view);
|
|
93
|
+
case 'clean':
|
|
94
|
+
return clean(conf, args, view);
|
|
95
|
+
case 'delete':
|
|
96
|
+
return deleteKeys(conf, args, view);
|
|
97
|
+
case 'delete-before':
|
|
98
|
+
return deleteBefore(conf, args, view);
|
|
99
|
+
case 'delete-all':
|
|
100
|
+
return deleteAll(conf, args, view);
|
|
101
|
+
default: {
|
|
102
|
+
throw error('Unrecognized cache command', {
|
|
103
|
+
code: 'EUSAGE',
|
|
104
|
+
found: sub,
|
|
105
|
+
validOptions: Object.keys(usageDef.subcommands),
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
const ls = async (conf, keys, view) => keys.length ?
|
|
111
|
+
await fetchKeys(conf, keys, (entry, key) => {
|
|
112
|
+
view?.stdout(key.includes(' ') ? JSON.stringify(key) : key, entry);
|
|
113
|
+
return true;
|
|
114
|
+
}, view)
|
|
115
|
+
: await fetchAll(conf, (_, key) => {
|
|
116
|
+
view?.stdout(key.includes(' ') ? JSON.stringify(key) : key);
|
|
117
|
+
return true;
|
|
118
|
+
});
|
|
119
|
+
const info = async (conf, keys, view) => {
|
|
120
|
+
const [key] = keys;
|
|
121
|
+
if (keys.length !== 1 || !key) {
|
|
122
|
+
throw error('Must provide exactly one cache key', {
|
|
123
|
+
code: 'EUSAGE',
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
await fetchKeys(conf, [key], (entry, key) => {
|
|
127
|
+
stderr(
|
|
128
|
+
/* c8 ignore next */
|
|
129
|
+
key.includes(' ') ? JSON.stringify(key) : key, entry);
|
|
130
|
+
if (entry.isJSON) {
|
|
131
|
+
stdout(JSON.stringify(entry.body, null, 2));
|
|
132
|
+
/* c8 ignore start - annoying to test, corrupts TAP output */
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
process.stdout.write(entry.body);
|
|
136
|
+
}
|
|
137
|
+
/* c8 ignore stop */
|
|
138
|
+
return true;
|
|
139
|
+
}, view);
|
|
140
|
+
};
|
|
141
|
+
const fetchAll = async (conf, test) => {
|
|
142
|
+
const rc = conf.options.packageInfo.registryClient;
|
|
143
|
+
const { cache } = rc;
|
|
144
|
+
const map = {};
|
|
145
|
+
for await (const [key, val] of cache) {
|
|
146
|
+
const entry = CacheEntry.decode(val);
|
|
147
|
+
if (!test(entry, key, val))
|
|
148
|
+
continue;
|
|
149
|
+
map[key] = entry.toJSON();
|
|
150
|
+
}
|
|
151
|
+
return map;
|
|
152
|
+
};
|
|
153
|
+
const fetchKeys = async (conf, keys, test, view) => {
|
|
154
|
+
const rc = conf.options.packageInfo.registryClient;
|
|
155
|
+
const { cache } = rc;
|
|
156
|
+
const map = {};
|
|
157
|
+
const results = await Promise.all(keys.map(async (key) => {
|
|
158
|
+
return [key, await cache.fetch(key)];
|
|
159
|
+
}));
|
|
160
|
+
for (const [key, val] of results) {
|
|
161
|
+
if (!val) {
|
|
162
|
+
view?.stdout('Not found:', key);
|
|
163
|
+
}
|
|
164
|
+
else {
|
|
165
|
+
const entry = CacheEntry.decode(val);
|
|
166
|
+
if (!test(entry, key, val))
|
|
167
|
+
continue;
|
|
168
|
+
map[key] = entry.toJSON();
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
return map;
|
|
172
|
+
};
|
|
173
|
+
const deleteEntries = async (conf, keys, test, view) => {
|
|
174
|
+
const rc = conf.options.packageInfo.registryClient;
|
|
175
|
+
const { cache } = rc;
|
|
176
|
+
let count = 0;
|
|
177
|
+
let size = 0;
|
|
178
|
+
const testAction = (entry, key, val) => {
|
|
179
|
+
if (!test(entry)) {
|
|
180
|
+
return false;
|
|
181
|
+
}
|
|
182
|
+
count++;
|
|
183
|
+
const s = val.byteLength + key.length;
|
|
184
|
+
cache.delete(key, true, entry.integrity);
|
|
185
|
+
const k = key.includes(' ') ? JSON.stringify(key) : key;
|
|
186
|
+
view?.stdout('-', k, s);
|
|
187
|
+
size += s;
|
|
188
|
+
return true;
|
|
189
|
+
};
|
|
190
|
+
const map = await (keys.length ?
|
|
191
|
+
fetchKeys(conf, keys, testAction, view)
|
|
192
|
+
: fetchAll(conf, testAction));
|
|
193
|
+
const pb = prettyBytes(size, { binary: true });
|
|
194
|
+
const s = count === 1 ? '' : 's';
|
|
195
|
+
await cache.promise();
|
|
196
|
+
view?.stdout(`Removed ${count} item${s} totalling ${pb}`);
|
|
197
|
+
return map;
|
|
198
|
+
};
|
|
199
|
+
const clean = async (conf, keys, view) => deleteEntries(conf, keys, entry => !entry.valid, view);
|
|
200
|
+
const deleteBefore = async (conf, args, view) => {
|
|
201
|
+
if (!args.length) {
|
|
202
|
+
throw error('Must provide a date to delete before', {
|
|
203
|
+
code: 'EUSAGE',
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
const now = new Date();
|
|
207
|
+
const before = new Date(args.join(' '));
|
|
208
|
+
if (before >= now) {
|
|
209
|
+
throw error('Cannot delete cache entries from the future', {
|
|
210
|
+
code: 'EUSAGE',
|
|
211
|
+
found: before,
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
return deleteEntries(conf, [], entry => !!entry.date && entry.date < before, view);
|
|
215
|
+
};
|
|
216
|
+
const deleteKeys = async (conf, keys, view) => {
|
|
217
|
+
if (!keys.length) {
|
|
218
|
+
throw error('Must provide cache keys to delete', {
|
|
219
|
+
code: 'EUSAGE',
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
return deleteEntries(conf, keys, () => true, view);
|
|
223
|
+
};
|
|
224
|
+
const deleteAll = async (conf, _, view) => {
|
|
225
|
+
const { cache } = conf.options.packageInfo.registryClient;
|
|
226
|
+
await rm(cache.path(), { recursive: true, force: true });
|
|
227
|
+
await mkdir(cache.path(), { recursive: true });
|
|
228
|
+
view?.stdout('Deleted all cache entries.');
|
|
229
|
+
};
|
|
230
|
+
const add = async (conf, specs, view) => {
|
|
231
|
+
if (!specs.length) {
|
|
232
|
+
throw error('Must provide specs to add to the cache', {
|
|
233
|
+
code: 'EUSAGE',
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
const { packageInfo } = conf.options;
|
|
237
|
+
const promises = [];
|
|
238
|
+
for (const spec of specs) {
|
|
239
|
+
const p = packageInfo
|
|
240
|
+
.resolve(Spec.parseArgs(spec, conf.options), {
|
|
241
|
+
staleWhileRevalidate: false,
|
|
242
|
+
})
|
|
243
|
+
.then(async (r) => {
|
|
244
|
+
const { resolved, integrity } = r;
|
|
245
|
+
await packageInfo.registryClient.request(resolved, {
|
|
246
|
+
...conf.options,
|
|
247
|
+
integrity,
|
|
248
|
+
staleWhileRevalidate: false,
|
|
249
|
+
query: undefined,
|
|
250
|
+
});
|
|
251
|
+
view?.stdout('+', spec, r.resolved);
|
|
252
|
+
});
|
|
253
|
+
promises.push(p);
|
|
254
|
+
}
|
|
255
|
+
await Promise.all(promises);
|
|
256
|
+
};
|
|
257
|
+
//# sourceMappingURL=cache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache.js","sourceRoot":"","sources":["../../../src/commands/cache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAA;AACpD,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AACnC,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAA;AAC5C,OAAO,WAAW,MAAM,cAAc,CAAA;AAGt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nimport { Spec } from '@vltpkg/spec'\nimport { mkdir, rm } from 'node:fs/promises'\nimport prettyBytes from 'pretty-bytes'\nimport type { LoadedConfig } from '../config/index.ts'\nimport type { CommandUsageDefinition } from '../config/usage.ts'\nimport { commandUsage } from '../config/usage.ts'\nimport type { CommandFn, CommandUsage } from '../index.ts'\nimport { stderr, stdout } from '../output.ts'\nimport type { ViewOptions, Views } from '../view.ts'\nimport { ViewClass } from '../view.ts'\n\nexport type CacheMap = Record<\n string,\n ReturnType<CacheEntry['toJSON']>\n>\n\nexport type CacheSubcommands = keyof (typeof usageDef)['subcommands']\n\nlet view: CacheView\nexport class CacheView extends ViewClass {\n constructor(options: ViewOptions, conf: LoadedConfig) {\n super(options, conf)\n view = this\n }\n stdout(...args: unknown[]) {\n stdout(...args)\n }\n}\n\nexport const views: Views<void | CacheMap> = {\n human: CacheView,\n}\n\nconst usageDef = {\n command: 'cache',\n usage: '<command> [flags]',\n description: 'Work with vlt cache folders',\n\n subcommands: {\n add: {\n usage: '<package-spec> [<package-spec>...]',\n description: `Resolve the referenced package identifiers and ensure they\n are cached.`,\n },\n\n ls: {\n usage: '[<key>...]',\n description: `Show cache entries. If no keys are provided, then a list of\n available keys will be printed. If one or more keys are\n provided, then details will be shown for the specified\n items.`,\n },\n\n info: {\n usage: '<key>',\n description: `Print metadata details for the specified cache key to\n stderr, and the response body to stdout.`,\n },\n\n clean: {\n usage: '[<key>...]',\n description: `Purge expired cache entries. If one or more keys are\n provided, then only those cache entries will be\n considered.`,\n },\n\n delete: {\n usage: '<key> [<key>...]',\n description: `Purge items explicitly, whether expired or not. If one or\n more keys are provided, then only those cache entries will\n be considered.`,\n },\n\n 'delete-before': {\n usage: '<date>',\n description: `Purge all cache items from before a given date. Date can be\n provided in any format that JavaScript can parse.`,\n },\n\n 'delete-all': {\n usage: '',\n description: `Delete the entire cache folder to make vlt slower.`,\n },\n },\n examples: {\n 'vlt cache ls https://registry.npmjs.org/typescript': {\n description: `Show cache metadata for a given registry URL`,\n },\n 'vlt cache add eslint@latest': {\n description: `Add a given package specifier to the cache by fetching\n its resolved value.`,\n },\n 'vlt cache info https://registry.npmjs.org/eslint/-/eslint-9.25.1.tgz > eslint.tgz':\n {\n description: `Print the cache metadata to stderr, and write the tarball\n on stdout, redirecting to a file.`,\n },\n 'vlt cache delete-before 2025-01-01': {\n description: 'Delete all entries created before Jan 1, 2025',\n },\n },\n} as const satisfies CommandUsageDefinition\n\nexport const usage: CommandUsage = () => commandUsage(usageDef)\n\nexport const command: CommandFn<void | CacheMap> = async conf => {\n const [sub, ...args] = conf.positionals\n switch (sub) {\n case 'ls':\n return ls(conf, args, view)\n\n case 'info':\n return info(conf, args, view)\n\n case 'add':\n return add(conf, args, view)\n\n case 'clean':\n return clean(conf, args, view)\n\n case 'delete':\n return deleteKeys(conf, args, view)\n\n case 'delete-before':\n return deleteBefore(conf, args, view)\n\n case 'delete-all':\n return deleteAll(conf, args, view)\n\n default: {\n throw error('Unrecognized cache command', {\n code: 'EUSAGE',\n found: sub,\n validOptions: Object.keys(usageDef.subcommands),\n })\n }\n }\n}\n\nconst ls = async (\n conf: LoadedConfig,\n keys: string[],\n view?: CacheView,\n): Promise<CacheMap> =>\n keys.length ?\n await fetchKeys(\n conf,\n keys,\n (entry: CacheEntry, key: string) => {\n view?.stdout(\n key.includes(' ') ? JSON.stringify(key) : key,\n entry,\n )\n return true\n },\n view,\n )\n : await fetchAll(conf, (_, key) => {\n view?.stdout(key.includes(' ') ? JSON.stringify(key) : key)\n return true\n })\n\nconst info = async (\n conf: LoadedConfig,\n keys: string[],\n view?: CacheView,\n): Promise<void> => {\n const [key] = keys\n if (keys.length !== 1 || !key) {\n throw error('Must provide exactly one cache key', {\n code: 'EUSAGE',\n })\n }\n await fetchKeys(\n conf,\n [key],\n (entry: CacheEntry, key: string) => {\n stderr(\n /* c8 ignore next */\n key.includes(' ') ? JSON.stringify(key) : key,\n entry,\n )\n if (entry.isJSON) {\n stdout(JSON.stringify(entry.body, null, 2))\n /* c8 ignore start - annoying to test, corrupts TAP output */\n } else {\n process.stdout.write(entry.body as Buffer)\n }\n /* c8 ignore stop */\n return true\n },\n view,\n )\n}\n\nconst fetchAll = async (\n conf: LoadedConfig,\n test: (entry: CacheEntry, key: string, val: Buffer) => boolean,\n) => {\n const rc = conf.options.packageInfo.registryClient\n const { cache } = rc\n const map: CacheMap = {}\n for await (const [key, val] of cache) {\n const entry = CacheEntry.decode(val)\n if (!test(entry, key, val)) continue\n map[key] = entry.toJSON()\n }\n return map\n}\n\nconst fetchKeys = async (\n conf: LoadedConfig,\n keys: string[],\n test: (entry: CacheEntry, key: string, buf: Buffer) => boolean,\n view?: CacheView,\n) => {\n const rc = conf.options.packageInfo.registryClient\n const { cache } = rc\n const map: CacheMap = {}\n const results: [string, Buffer | undefined][] = await Promise.all(\n keys.map(async key => {\n return [key, await cache.fetch(key)]\n }),\n )\n for (const [key, val] of results) {\n if (!val) {\n view?.stdout('Not found:', key)\n } else {\n const entry = CacheEntry.decode(val)\n if (!test(entry, key, val)) continue\n map[key] = entry.toJSON()\n }\n }\n\n return map\n}\n\nconst deleteEntries = async (\n conf: LoadedConfig,\n keys: string[],\n test: (entry: CacheEntry) => boolean,\n view?: CacheView,\n) => {\n const rc = conf.options.packageInfo.registryClient\n const { cache } = rc\n\n let count = 0\n let size = 0\n const testAction = (\n entry: CacheEntry,\n key: string,\n val: Buffer,\n ) => {\n if (!test(entry)) {\n return false\n }\n count++\n const s = val.byteLength + key.length\n cache.delete(key, true, entry.integrity)\n const k = key.includes(' ') ? JSON.stringify(key) : key\n view?.stdout('-', k, s)\n size += s\n return true\n }\n\n const map = await (keys.length ?\n fetchKeys(conf, keys, testAction, view)\n : fetchAll(conf, testAction))\n\n const pb = prettyBytes(size, { binary: true })\n\n const s = count === 1 ? '' : 's'\n await cache.promise()\n view?.stdout(`Removed ${count} item${s} totalling ${pb}`)\n return map\n}\n\nconst clean = async (\n conf: LoadedConfig,\n keys: string[],\n view?: CacheView,\n) => deleteEntries(conf, keys, entry => !entry.valid, view)\n\nconst deleteBefore = async (\n conf: LoadedConfig,\n args: string[],\n view?: CacheView,\n) => {\n if (!args.length) {\n throw error('Must provide a date to delete before', {\n code: 'EUSAGE',\n })\n }\n const now = new Date()\n const before = new Date(args.join(' '))\n if (before >= now) {\n throw error('Cannot delete cache entries from the future', {\n code: 'EUSAGE',\n found: before,\n })\n }\n return deleteEntries(\n conf,\n [],\n entry => !!entry.date && entry.date < before,\n view,\n )\n}\n\nconst deleteKeys = async (\n conf: LoadedConfig,\n keys: string[],\n view?: CacheView,\n) => {\n if (!keys.length) {\n throw error('Must provide cache keys to delete', {\n code: 'EUSAGE',\n })\n }\n return deleteEntries(conf, keys, () => true, view)\n}\n\nconst deleteAll = async (\n conf: LoadedConfig,\n _: string[],\n view?: CacheView,\n) => {\n const { cache } = conf.options.packageInfo.registryClient\n await rm(cache.path(), { recursive: true, force: true })\n await mkdir(cache.path(), { recursive: true })\n view?.stdout('Deleted all cache entries.')\n}\n\nconst add = async (\n conf: LoadedConfig,\n specs: string[],\n view?: CacheView,\n) => {\n if (!specs.length) {\n throw error('Must provide specs to add to the cache', {\n code: 'EUSAGE',\n })\n }\n const { packageInfo } = conf.options\n const promises: Promise<void>[] = []\n\n for (const spec of specs) {\n const p = packageInfo\n .resolve(Spec.parseArgs(spec, conf.options), {\n staleWhileRevalidate: false,\n })\n .then(async r => {\n const { resolved, integrity } = r\n await packageInfo.registryClient.request(resolved, {\n ...conf.options,\n integrity,\n staleWhileRevalidate: false,\n query: undefined,\n })\n view?.stdout('+', spec, r.resolved)\n })\n\n promises.push(p)\n }\n\n await Promise.all(promises)\n}\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Graph } from '@vltpkg/graph';
|
|
2
|
+
import type { CommandFn, CommandUsage } from '../index.ts';
|
|
3
|
+
import { InstallReporter } from './install/reporter.ts';
|
|
4
|
+
export declare const usage: CommandUsage;
|
|
5
|
+
export declare const views: {
|
|
6
|
+
readonly json: (g: Graph) => import("@vltpkg/graph").LockfileData;
|
|
7
|
+
readonly human: typeof InstallReporter;
|
|
8
|
+
};
|
|
9
|
+
export declare const command: CommandFn<Graph>;
|
|
10
|
+
//# sourceMappingURL=ci.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ci.d.ts","sourceRoot":"","sources":["../../../src/commands/ci.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,eAAe,CAAA;AAE1C,OAAO,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAG1D,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AAEvD,eAAO,MAAM,KAAK,EAAE,YAWhB,CAAA;AAEJ,eAAO,MAAM,KAAK;;;CAGe,CAAA;AAEjC,eAAO,MAAM,OAAO,EAAE,SAAS,CAAC,KAAK,CAUpC,CAAA"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { commandUsage } from "../config/usage.js";
|
|
2
|
+
import { install } from '@vltpkg/graph';
|
|
3
|
+
import { InstallReporter } from "./install/reporter.js";
|
|
4
|
+
export const usage = () => commandUsage({
|
|
5
|
+
command: 'ci',
|
|
6
|
+
usage: '',
|
|
7
|
+
description: `Clean install from lockfile. Deletes node_modules and installs
|
|
8
|
+
dependencies exactly as specified in vlt-lock.json. This is
|
|
9
|
+
similar to running 'vlt install --expect-lockfile' but performs
|
|
10
|
+
a clean install by removing node_modules first.`,
|
|
11
|
+
examples: {
|
|
12
|
+
'': { description: 'Clean install from lockfile' },
|
|
13
|
+
},
|
|
14
|
+
});
|
|
15
|
+
export const views = {
|
|
16
|
+
json: g => g.toJSON(),
|
|
17
|
+
human: InstallReporter,
|
|
18
|
+
};
|
|
19
|
+
export const command = async (conf) => {
|
|
20
|
+
const ciOptions = {
|
|
21
|
+
...conf.options,
|
|
22
|
+
expectLockfile: true,
|
|
23
|
+
frozenLockfile: true,
|
|
24
|
+
cleanInstall: true,
|
|
25
|
+
};
|
|
26
|
+
const { graph } = await install(ciOptions);
|
|
27
|
+
return graph;
|
|
28
|
+
};
|
|
29
|
+
//# sourceMappingURL=ci.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ci.js","sourceRoot":"","sources":["../../../src/commands/ci.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAEjD,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAEvC,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AAEvD,MAAM,CAAC,MAAM,KAAK,GAAiB,GAAG,EAAE,CACtC,YAAY,CAAC;IACX,OAAO,EAAE,IAAI;IACb,KAAK,EAAE,EAAE;IACT,WAAW,EAAE;;;kEAGiD;IAC9D,QAAQ,EAAE;QACR,EAAE,EAAE,EAAE,WAAW,EAAE,6BAA6B,EAAE;KACnD;CACF,CAAC,CAAA;AAEJ,MAAM,CAAC,MAAM,KAAK,GAAG;IACnB,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,EAAE;IACrB,KAAK,EAAE,eAAe;CACS,CAAA;AAEjC,MAAM,CAAC,MAAM,OAAO,GAAqB,KAAK,EAAC,IAAI,EAAC,EAAE;IACpD,MAAM,SAAS,GAAG;QAChB,GAAG,IAAI,CAAC,OAAO;QACf,cAAc,EAAE,IAAI;QACpB,cAAc,EAAE,IAAI;QACpB,YAAY,EAAE,IAAI;KACnB,CAAA;IAED,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,OAAO,CAAC,SAAS,CAAC,CAAA;IAC1C,OAAO,KAAK,CAAA;AACd,CAAC,CAAA","sourcesContent":["import type { Graph } from '@vltpkg/graph'\nimport { commandUsage } from '../config/usage.ts'\nimport type { CommandFn, CommandUsage } from '../index.ts'\nimport { install } from '@vltpkg/graph'\nimport type { Views } from '../view.ts'\nimport { InstallReporter } from './install/reporter.ts'\n\nexport const usage: CommandUsage = () =>\n commandUsage({\n command: 'ci',\n usage: '',\n description: `Clean install from lockfile. Deletes node_modules and installs \n dependencies exactly as specified in vlt-lock.json. This is \n similar to running 'vlt install --expect-lockfile' but performs \n a clean install by removing node_modules first.`,\n examples: {\n '': { description: 'Clean install from lockfile' },\n },\n })\n\nexport const views = {\n json: g => g.toJSON(),\n human: InstallReporter,\n} as const satisfies Views<Graph>\n\nexport const command: CommandFn<Graph> = async conf => {\n const ciOptions = {\n ...conf.options,\n expectLockfile: true,\n frozenLockfile: true,\n cleanInstall: true,\n }\n\n const { graph } = await install(ciOptions)\n return graph\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../src/commands/config.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../src/commands/config.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAgB,WAAW,EAAE,MAAM,oBAAoB,CAAA;AACnE,OAAO,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAE1D,eAAO,MAAM,KAAK,EAAE,YA8ChB,CAAA;AAEJ,eAAO,MAAM,OAAO,EAAE,SAAS,CAC7B,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,MAAM,EAAE,GAAG,WAAW,CA+B1D,CAAA"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { error } from '@vltpkg/error-cause';
|
|
2
|
-
import { spawnSync } from 'child_process';
|
|
3
|
-
import { definition, isRecordField, pairsToRecords, recordsToPairs, } from "../config/index.js";
|
|
4
2
|
import { commandUsage } from "../config/usage.js";
|
|
3
|
+
import { isRecordField, definition } from "../config/index.js";
|
|
4
|
+
import { get, set, edit, list, del } from '@vltpkg/config';
|
|
5
5
|
export const usage = () => commandUsage({
|
|
6
6
|
command: 'config',
|
|
7
7
|
usage: '<command> [flags]',
|
|
@@ -100,54 +100,4 @@ const help = (conf) => {
|
|
|
100
100
|
}
|
|
101
101
|
return res.join('\n');
|
|
102
102
|
};
|
|
103
|
-
const list = (conf) => {
|
|
104
|
-
return recordsToPairs(conf.options);
|
|
105
|
-
};
|
|
106
|
-
const del = async (conf) => {
|
|
107
|
-
const fields = conf.positionals.slice(1);
|
|
108
|
-
if (!fields.length) {
|
|
109
|
-
throw error('At least one key is required', {
|
|
110
|
-
code: 'EUSAGE',
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
await conf.deleteConfigKeys(conf.get('config'), fields);
|
|
114
|
-
};
|
|
115
|
-
const get = async (conf) => {
|
|
116
|
-
const keys = conf.positionals.slice(1);
|
|
117
|
-
const k = keys[0];
|
|
118
|
-
if (!k || keys.length > 1) {
|
|
119
|
-
throw error('Exactly one key is required', {
|
|
120
|
-
code: 'EUSAGE',
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
return conf.get(k);
|
|
124
|
-
};
|
|
125
|
-
const edit = async (conf) => {
|
|
126
|
-
const [command, ...args] = conf.get('editor').split(' ');
|
|
127
|
-
if (!command) {
|
|
128
|
-
throw error(`editor is empty`);
|
|
129
|
-
}
|
|
130
|
-
await conf.editConfigFile(conf.get('config'), file => {
|
|
131
|
-
args.push(file);
|
|
132
|
-
const res = spawnSync(command, args, {
|
|
133
|
-
stdio: 'inherit',
|
|
134
|
-
});
|
|
135
|
-
if (res.status !== 0) {
|
|
136
|
-
throw error(`${command} command failed`, {
|
|
137
|
-
...res,
|
|
138
|
-
command,
|
|
139
|
-
args,
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
});
|
|
143
|
-
};
|
|
144
|
-
const set = async (conf) => {
|
|
145
|
-
const pairs = conf.positionals.slice(1);
|
|
146
|
-
if (!pairs.length) {
|
|
147
|
-
throw error('At least one key=value pair is required', {
|
|
148
|
-
code: 'EUSAGE',
|
|
149
|
-
});
|
|
150
|
-
}
|
|
151
|
-
await conf.addConfigToFile(conf.get('config'), pairsToRecords(conf.jack.parseRaw(pairs.map(kv => `--${kv}`)).values));
|
|
152
|
-
};
|
|
153
103
|
//# sourceMappingURL=config.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../../src/commands/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAC3C,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../../src/commands/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AACjD,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AAC9D,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAA;AAI1D,MAAM,CAAC,MAAM,KAAK,GAAiB,GAAG,EAAE,CACtC,YAAY,CAAC;IACX,OAAO,EAAE,QAAQ;IACjB,KAAK,EAAE,mBAAmB;IAC1B,WAAW,EAAE,6BAA6B;IAE1C,WAAW,EAAE;QACX,GAAG,EAAE;YACH,KAAK,EAAE,mBAAmB;YAC1B,WAAW,EAAE,8BAA8B;SAC5C;QAED,IAAI,EAAE;YACJ,WAAW,EACT,sDAAsD;SACzD;QAED,GAAG,EAAE;YACH,KAAK,EACH,+DAA+D;YACjE,WAAW,EAAE;;;2DAGsC;SACpD;QAED,GAAG,EAAE;YACH,KAAK,EAAE,+CAA+C;YACtD,WAAW,EAAE;;;;8DAIyC;SACvD;QAED,IAAI,EAAE;YACJ,KAAK,EAAE,6BAA6B;YACpC,WAAW,EAAE,6BAA6B;SAC3C;QAED,IAAI,EAAE;YACJ,KAAK,EAAE,aAAa;YACpB,WAAW,EAAE;mDAC8B;SAC5C;KACF;CACF,CAAC,CAAA;AAEJ,MA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vltpkg/error-cause'\nimport { commandUsage } from '../config/usage.ts'\nimport { isRecordField, definition } from '../config/index.ts'\nimport { get, set, edit, list, del } from '@vltpkg/config'\nimport type { LoadedConfig, RecordPairs } from '../config/index.ts'\nimport type { CommandFn, CommandUsage } from '../index.ts'\n\nexport const usage: CommandUsage = () =>\n commandUsage({\n command: 'config',\n usage: '<command> [flags]',\n description: 'Work with vlt configuration',\n\n subcommands: {\n get: {\n usage: '<key> [<key> ...]',\n description: 'Print the named config value',\n },\n\n list: {\n description:\n 'Print all configuration settings currently in effect',\n },\n\n set: {\n usage:\n '<key>=<value> [<key>=<value> ...] [--config=<user | project>]',\n description: `Set config values. By default, these are\n written to the project config file, \\`vlt.json\\`\n in the root of the project. To set things for all\n projects, run with \\`--config=user\\``,\n },\n\n del: {\n usage: '<key> [<key> ...] [--config=<user | project>]',\n description: `Delete the named config fields. If no values remain in\n the config file, delete the file as well. By default,\n operates on the \\`vlt.json\\` file in the root of the\n current project. To delete a config field from the user\n config file, specify \\`--config=user\\`.`,\n },\n\n edit: {\n usage: '[--config=<user | project>]',\n description: 'Edit the configuration file',\n },\n\n help: {\n usage: '[field ...]',\n description: `Get information about a config field, or show a list\n of known config field names.`,\n },\n },\n })\n\nexport const command: CommandFn<\n string | number | boolean | void | string[] | RecordPairs\n> = async conf => {\n const sub = conf.positionals[0]\n switch (sub) {\n case 'set':\n return set(conf)\n\n case 'get':\n return get(conf)\n\n case 'ls':\n case 'list':\n return list(conf)\n\n case 'edit':\n return edit(conf)\n\n case 'help':\n return help(conf)\n\n case 'del':\n return del(conf)\n\n default: {\n throw error('Unrecognized config command', {\n code: 'EUSAGE',\n found: sub,\n validOptions: ['set', 'get', 'list', 'edit', 'help', 'del'],\n })\n }\n }\n}\n\nconst help = (conf: LoadedConfig) => {\n const j = definition.toJSON()\n const fields = conf.positionals.slice(1)\n if (!fields.length) {\n return [\n 'Specify one or more options to see information:',\n ...Object.keys(j)\n .sort((a, b) => a.localeCompare(b, 'en'))\n .map(c => ` ${c}`),\n ].join('\\n')\n }\n\n // TODO: some kind of fuzzy search?\n const res: string[] = []\n for (const f of fields) {\n const def = j[f]\n if (!def) {\n res.push(`unknown config field: ${f}`)\n } else {\n const hint = def.hint ? `=<${def.hint}>` : ''\n const type =\n isRecordField(f) ?\n 'Record<string, string>'\n : def.type + (def.multiple ? '[]' : '')\n\n res.push(`--${f}${hint}`)\n res.push(` type: ${type}`)\n if (def.default) {\n res.push(` default: ${JSON.stringify(def.default)}`)\n }\n if (def.description) {\n res.push(def.description)\n }\n }\n }\n return res.join('\\n')\n}\n"]}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { VlxInfo } from '@vltpkg/vlx';
|
|
2
|
+
import type { LoadedConfig } from '../config/index.ts';
|
|
3
|
+
import type { CommandFn, CommandUsage } from '../index.ts';
|
|
4
|
+
import type { ViewOptions, Views } from '../view.ts';
|
|
5
|
+
import { ViewClass } from '../view.ts';
|
|
6
|
+
export type ExecCacheSubcommands = keyof (typeof usageDef)['subcommands'];
|
|
7
|
+
export declare class ExecCacheView extends ViewClass {
|
|
8
|
+
constructor(options: ViewOptions, conf: LoadedConfig);
|
|
9
|
+
stdout(...args: unknown[]): void;
|
|
10
|
+
}
|
|
11
|
+
export declare const views: Views<void | string[] | VlxInfo[]>;
|
|
12
|
+
declare const usageDef: {
|
|
13
|
+
readonly command: "exec-cache";
|
|
14
|
+
readonly usage: "<command> [flags]";
|
|
15
|
+
readonly description: "Work with vlt exec-cache folders";
|
|
16
|
+
readonly subcommands: {
|
|
17
|
+
readonly ls: {
|
|
18
|
+
readonly usage: "";
|
|
19
|
+
readonly description: "Show previously installed packages used for `vlt exec`.\n Key provided can be either the package name, or the full\n key.";
|
|
20
|
+
};
|
|
21
|
+
readonly delete: {
|
|
22
|
+
readonly usage: "[<key>...]";
|
|
23
|
+
readonly description: "Delete previously installed packages used for\n `vlt exec`. If no keys are provided, then all entries\n will be deleted.";
|
|
24
|
+
};
|
|
25
|
+
readonly info: {
|
|
26
|
+
readonly usage: "<key>";
|
|
27
|
+
readonly description: "Show extended information about a given `vlt exec`\n installation.";
|
|
28
|
+
};
|
|
29
|
+
readonly install: {
|
|
30
|
+
readonly usage: "<spec>...";
|
|
31
|
+
readonly description: "Install the specified package(s) in the `vlt exec`\n central cache location. Metadata info about each\n installation will be printed.";
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
readonly examples: {
|
|
35
|
+
readonly ls: {
|
|
36
|
+
readonly description: "Show all the keys for the installations in the `vlt exec`\n cache.";
|
|
37
|
+
};
|
|
38
|
+
readonly 'delete typescript': {
|
|
39
|
+
readonly description: "Delete all versions of typescript installed for vlt exec";
|
|
40
|
+
};
|
|
41
|
+
readonly 'info typescript-695bf962': {
|
|
42
|
+
readonly description: "Show extended info about a specific version of typescript";
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
export declare const usage: CommandUsage;
|
|
47
|
+
export declare const command: CommandFn<string[] | VlxInfo[]>;
|
|
48
|
+
export {};
|
|
49
|
+
//# sourceMappingURL=exec-cache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exec-cache.d.ts","sourceRoot":"","sources":["../../../src/commands/exec-cache.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AAG1C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAGtD,OAAO,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAE1D,OAAO,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AACpD,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AAEtC,MAAM,MAAM,oBAAoB,GAC9B,MAAM,CAAC,OAAO,QAAQ,CAAC,CAAC,aAAa,CAAC,CAAA;AAGxC,qBAAa,aAAc,SAAQ,SAAS;gBAC9B,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,YAAY;IAIpD,MAAM,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE;CAG1B;AAED,eAAO,MAAM,KAAK,EAAE,KAAK,CAAC,IAAI,GAAG,MAAM,EAAE,GAAG,OAAO,EAAE,CAEpD,CAAA;AAED,QAAA,MAAM,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA8C6B,CAAA;AAE3C,eAAO,MAAM,KAAK,EAAE,YAA2C,CAAA;AAE/D,eAAO,MAAM,OAAO,EAAE,SAAS,CAC7B,MAAM,EAAE,GAAG,OAAO,EAAE,CAwBrB,CAAA"}
|