@vltpkg/cli-sdk 0.0.0-10
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/LICENSE +15 -0
- package/README.md +23 -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 +256 -0
- package/dist/esm/commands/cache.js.map +1 -0
- package/dist/esm/commands/config.d.ts +5 -0
- package/dist/esm/commands/config.d.ts.map +1 -0
- package/dist/esm/commands/config.js +153 -0
- package/dist/esm/commands/config.js.map +1 -0
- 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 +125 -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 +9 -0
- package/dist/esm/commands/exec.d.ts.map +1 -0
- package/dist/esm/commands/exec.js +78 -0
- package/dist/esm/commands/exec.js.map +1 -0
- package/dist/esm/commands/gui.d.ts +6 -0
- package/dist/esm/commands/gui.d.ts.map +1 -0
- package/dist/esm/commands/gui.js +13 -0
- package/dist/esm/commands/gui.js.map +1 -0
- package/dist/esm/commands/help.d.ts +4 -0
- package/dist/esm/commands/help.d.ts.map +1 -0
- package/dist/esm/commands/help.js +10 -0
- package/dist/esm/commands/help.js.map +1 -0
- package/dist/esm/commands/init.d.ts +8 -0
- package/dist/esm/commands/init.d.ts.map +1 -0
- package/dist/esm/commands/init.js +25 -0
- package/dist/esm/commands/init.js.map +1 -0
- package/dist/esm/commands/install/reporter.d.ts +10 -0
- package/dist/esm/commands/install/reporter.d.ts.map +1 -0
- package/dist/esm/commands/install/reporter.js +67 -0
- package/dist/esm/commands/install/reporter.js.map +1 -0
- package/dist/esm/commands/install.d.ts +10 -0
- package/dist/esm/commands/install.d.ts.map +1 -0
- package/dist/esm/commands/install.js +21 -0
- package/dist/esm/commands/install.js.map +1 -0
- package/dist/esm/commands/list.d.ts +15 -0
- package/dist/esm/commands/list.d.ts.map +1 -0
- package/dist/esm/commands/list.js +109 -0
- package/dist/esm/commands/list.js.map +1 -0
- package/dist/esm/commands/login.d.ts +4 -0
- package/dist/esm/commands/login.d.ts.map +1 -0
- package/dist/esm/commands/login.js +13 -0
- package/dist/esm/commands/login.js.map +1 -0
- package/dist/esm/commands/logout.d.ts +4 -0
- package/dist/esm/commands/logout.d.ts.map +1 -0
- package/dist/esm/commands/logout.js +13 -0
- package/dist/esm/commands/logout.js.map +1 -0
- package/dist/esm/commands/pkg.d.ts +7 -0
- package/dist/esm/commands/pkg.d.ts.map +1 -0
- package/dist/esm/commands/pkg.js +123 -0
- package/dist/esm/commands/pkg.js.map +1 -0
- package/dist/esm/commands/query.d.ts +16 -0
- package/dist/esm/commands/query.d.ts.map +1 -0
- package/dist/esm/commands/query.js +124 -0
- package/dist/esm/commands/query.js.map +1 -0
- package/dist/esm/commands/run-exec.d.ts +6 -0
- package/dist/esm/commands/run-exec.d.ts.map +1 -0
- package/dist/esm/commands/run-exec.js +14 -0
- package/dist/esm/commands/run-exec.js.map +1 -0
- package/dist/esm/commands/run.d.ts +6 -0
- package/dist/esm/commands/run.d.ts.map +1 -0
- package/dist/esm/commands/run.js +37 -0
- package/dist/esm/commands/run.js.map +1 -0
- package/dist/esm/commands/token.d.ts +4 -0
- package/dist/esm/commands/token.d.ts.map +1 -0
- package/dist/esm/commands/token.js +30 -0
- package/dist/esm/commands/token.js.map +1 -0
- package/dist/esm/commands/uninstall.d.ts +10 -0
- package/dist/esm/commands/uninstall.d.ts.map +1 -0
- package/dist/esm/commands/uninstall.js +21 -0
- package/dist/esm/commands/uninstall.js.map +1 -0
- package/dist/esm/commands/whoami.d.ts +13 -0
- package/dist/esm/commands/whoami.d.ts.map +1 -0
- package/dist/esm/commands/whoami.js +19 -0
- package/dist/esm/commands/whoami.js.map +1 -0
- package/dist/esm/config/definition.d.ts +306 -0
- package/dist/esm/config/definition.d.ts.map +1 -0
- package/dist/esm/config/definition.js +517 -0
- package/dist/esm/config/definition.js.map +1 -0
- package/dist/esm/config/index.d.ts +206 -0
- package/dist/esm/config/index.d.ts.map +1 -0
- package/dist/esm/config/index.js +489 -0
- package/dist/esm/config/index.js.map +1 -0
- package/dist/esm/config/merge.d.ts +2 -0
- package/dist/esm/config/merge.d.ts.map +1 -0
- package/dist/esm/config/merge.js +23 -0
- package/dist/esm/config/merge.js.map +1 -0
- package/dist/esm/config/usage.d.ts +19 -0
- package/dist/esm/config/usage.d.ts.map +1 -0
- package/dist/esm/config/usage.js +40 -0
- package/dist/esm/config/usage.js.map +1 -0
- package/dist/esm/exec-command.d.ts +51 -0
- package/dist/esm/exec-command.d.ts.map +1 -0
- package/dist/esm/exec-command.js +199 -0
- package/dist/esm/exec-command.js.map +1 -0
- package/dist/esm/index.d.ts +17 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +47 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/output.d.ts +21 -0
- package/dist/esm/output.d.ts.map +1 -0
- package/dist/esm/output.js +121 -0
- package/dist/esm/output.js.map +1 -0
- package/dist/esm/package.json +3 -0
- package/dist/esm/parse-add-remove-args.d.ts +22 -0
- package/dist/esm/parse-add-remove-args.d.ts.map +1 -0
- package/dist/esm/parse-add-remove-args.js +71 -0
- package/dist/esm/parse-add-remove-args.js.map +1 -0
- package/dist/esm/print-err.d.ts +7 -0
- package/dist/esm/print-err.d.ts.map +1 -0
- package/dist/esm/print-err.js +115 -0
- package/dist/esm/print-err.js.map +1 -0
- package/dist/esm/read-password.d.ts +8 -0
- package/dist/esm/read-password.d.ts.map +1 -0
- package/dist/esm/read-password.js +33 -0
- package/dist/esm/read-password.js.map +1 -0
- package/dist/esm/start-gui.d.ts +9 -0
- package/dist/esm/start-gui.d.ts.map +1 -0
- package/dist/esm/start-gui.js +40 -0
- package/dist/esm/start-gui.js.map +1 -0
- package/dist/esm/view.d.ts +30 -0
- package/dist/esm/view.d.ts.map +1 -0
- package/dist/esm/view.js +31 -0
- package/dist/esm/view.js.map +1 -0
- package/package.json +125 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
Copyright (c) vlt technology, Inc.
|
|
2
|
+
|
|
3
|
+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
|
4
|
+
|
|
5
|
+
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
|
6
|
+
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
|
7
|
+
Subject to the terms and conditions of this license, each copyright holder and contributor hereby grants to those receiving rights under this license a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except for failure to satisfy the conditions of this license) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer this software, where such license applies only to those patent claims, already acquired or hereafter acquired, licensable by such copyright holder or contributor that are necessarily infringed by:
|
|
8
|
+
|
|
9
|
+
(a) their Contribution(s) (the licensed copyrights of copyright holders and non-copyrightable additions of contributors, in source or binary form) alone; or
|
|
10
|
+
(b) combination of their Contribution(s) with the work of authorship to which such Contribution(s) was added by such copyright holder or contributor, if, at the time the Contribution is added, such addition causes such combination to be necessarily infringed. The patent license shall not apply to any other combinations which include the Contribution.
|
|
11
|
+
Except as expressly stated above, no rights or licenses from any copyright holder or contributor is granted under this license, whether expressly, by implication, estoppel or otherwise.
|
|
12
|
+
|
|
13
|
+
DISCLAIMER
|
|
14
|
+
|
|
15
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
package/README.md
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+

|
|
2
|
+
|
|
3
|
+
# @vltpkg/cli-sdk
|
|
4
|
+
|
|
5
|
+
The SDK for the `vlt` command line interface.
|
|
6
|
+
|
|
7
|
+
## Usage
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import vlt from '@vltpkg/cli-sdk'
|
|
11
|
+
process.argv.splice(2, 0, '--version')
|
|
12
|
+
await vlt()
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import vlt from '@vltpkg/cli-sdk'
|
|
17
|
+
process.chdir('/some/vlt/project')
|
|
18
|
+
process.argv.splice(2, 0, 'install')
|
|
19
|
+
await vlt()
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Visit [docs.vlt.sh](https://docs.vlt.sh) to see the full
|
|
23
|
+
documentation.
|
|
@@ -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,256 @@
|
|
|
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
|
+
});
|
|
250
|
+
view?.stdout('+', spec, r.resolved);
|
|
251
|
+
});
|
|
252
|
+
promises.push(p);
|
|
253
|
+
}
|
|
254
|
+
await Promise.all(promises);
|
|
255
|
+
};
|
|
256
|
+
//# 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,K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esContent":["import { error } from '@vltpkg/error-cause'\nimport { CacheEntry } from '@vltpkg/registry-client'\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 })\n view?.stdout('+', spec, r.resolved)\n })\n\n promises.push(p)\n }\n\n await Promise.all(promises)\n}\n"]}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { RecordPairs } from '../config/index.ts';
|
|
2
|
+
import type { CommandFn, CommandUsage } from '../index.ts';
|
|
3
|
+
export declare const usage: CommandUsage;
|
|
4
|
+
export declare const command: CommandFn<string | number | boolean | void | string[] | RecordPairs>;
|
|
5
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../src/commands/config.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAGV,WAAW,EACZ,MAAM,oBAAoB,CAAA;AAE3B,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"}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { error } from '@vltpkg/error-cause';
|
|
2
|
+
import { spawnSync } from 'node:child_process';
|
|
3
|
+
import { definition, isRecordField, pairsToRecords, recordsToPairs, } from "../config/index.js";
|
|
4
|
+
import { commandUsage } from "../config/usage.js";
|
|
5
|
+
export const usage = () => commandUsage({
|
|
6
|
+
command: 'config',
|
|
7
|
+
usage: '<command> [flags]',
|
|
8
|
+
description: 'Work with vlt configuration',
|
|
9
|
+
subcommands: {
|
|
10
|
+
get: {
|
|
11
|
+
usage: '<key> [<key> ...]',
|
|
12
|
+
description: 'Print the named config value',
|
|
13
|
+
},
|
|
14
|
+
list: {
|
|
15
|
+
description: 'Print all configuration settings currently in effect',
|
|
16
|
+
},
|
|
17
|
+
set: {
|
|
18
|
+
usage: '<key>=<value> [<key>=<value> ...] [--config=<user | project>]',
|
|
19
|
+
description: `Set config values. By default, these are
|
|
20
|
+
written to the project config file, \`vlt.json\`
|
|
21
|
+
in the root of the project. To set things for all
|
|
22
|
+
projects, run with \`--config=user\``,
|
|
23
|
+
},
|
|
24
|
+
del: {
|
|
25
|
+
usage: '<key> [<key> ...] [--config=<user | project>]',
|
|
26
|
+
description: `Delete the named config fields. If no values remain in
|
|
27
|
+
the config file, delete the file as well. By default,
|
|
28
|
+
operates on the \`vlt.json\` file in the root of the
|
|
29
|
+
current project. To delete a config field from the user
|
|
30
|
+
config file, specify \`--config=user\`.`,
|
|
31
|
+
},
|
|
32
|
+
edit: {
|
|
33
|
+
usage: '[--config=<user | project>]',
|
|
34
|
+
description: 'Edit the configuration file',
|
|
35
|
+
},
|
|
36
|
+
help: {
|
|
37
|
+
usage: '[field ...]',
|
|
38
|
+
description: `Get information about a config field, or show a list
|
|
39
|
+
of known config field names.`,
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
export const command = async (conf) => {
|
|
44
|
+
const sub = conf.positionals[0];
|
|
45
|
+
switch (sub) {
|
|
46
|
+
case 'set':
|
|
47
|
+
return set(conf);
|
|
48
|
+
case 'get':
|
|
49
|
+
return get(conf);
|
|
50
|
+
case 'ls':
|
|
51
|
+
case 'list':
|
|
52
|
+
return list(conf);
|
|
53
|
+
case 'edit':
|
|
54
|
+
return edit(conf);
|
|
55
|
+
case 'help':
|
|
56
|
+
return help(conf);
|
|
57
|
+
case 'del':
|
|
58
|
+
return del(conf);
|
|
59
|
+
default: {
|
|
60
|
+
throw error('Unrecognized config command', {
|
|
61
|
+
code: 'EUSAGE',
|
|
62
|
+
found: sub,
|
|
63
|
+
validOptions: ['set', 'get', 'list', 'edit', 'help', 'del'],
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
const help = (conf) => {
|
|
69
|
+
const j = definition.toJSON();
|
|
70
|
+
const fields = conf.positionals.slice(1);
|
|
71
|
+
if (!fields.length) {
|
|
72
|
+
return [
|
|
73
|
+
'Specify one or more options to see information:',
|
|
74
|
+
...Object.keys(j)
|
|
75
|
+
.sort((a, b) => a.localeCompare(b, 'en'))
|
|
76
|
+
.map(c => ` ${c}`),
|
|
77
|
+
].join('\n');
|
|
78
|
+
}
|
|
79
|
+
// TODO: some kind of fuzzy search?
|
|
80
|
+
const res = [];
|
|
81
|
+
for (const f of fields) {
|
|
82
|
+
const def = j[f];
|
|
83
|
+
if (!def) {
|
|
84
|
+
res.push(`unknown config field: ${f}`);
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
const hint = def.hint ? `=<${def.hint}>` : '';
|
|
88
|
+
const type = isRecordField(f) ?
|
|
89
|
+
'Record<string, string>'
|
|
90
|
+
: def.type + (def.multiple ? '[]' : '');
|
|
91
|
+
res.push(`--${f}${hint}`);
|
|
92
|
+
res.push(` type: ${type}`);
|
|
93
|
+
if (def.default) {
|
|
94
|
+
res.push(` default: ${JSON.stringify(def.default)}`);
|
|
95
|
+
}
|
|
96
|
+
if (def.description) {
|
|
97
|
+
res.push(def.description);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return res.join('\n');
|
|
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
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +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,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAC9C,OAAO,EACL,UAAU,EACV,aAAa,EACb,cAAc,EACd,cAAc,GACf,MAAM,oBAAoB,CAAA;AAM3B,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAGjD,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+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,CAAC,CAAA","sourcesContent":["import { error } from '@vltpkg/error-cause'\nimport { spawnSync } from 'node:child_process'\nimport {\n definition,\n isRecordField,\n pairsToRecords,\n recordsToPairs,\n} from '../config/index.ts'\nimport type {\n ConfigDefinitions,\n LoadedConfig,\n RecordPairs,\n} from '../config/index.ts'\nimport { commandUsage } from '../config/usage.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\nconst list = (conf: LoadedConfig) => {\n return recordsToPairs(conf.options)\n}\n\nconst del = async (conf: LoadedConfig) => {\n const fields = conf.positionals.slice(1)\n if (!fields.length) {\n throw error('At least one key is required', {\n code: 'EUSAGE',\n })\n }\n await conf.deleteConfigKeys(conf.get('config'), fields)\n}\n\nconst get = async (conf: LoadedConfig) => {\n const keys = conf.positionals.slice(1)\n const k = keys[0]\n if (!k || keys.length > 1) {\n throw error('Exactly one key is required', {\n code: 'EUSAGE',\n })\n }\n return conf.get(k as keyof ConfigDefinitions)\n}\n\nconst edit = async (conf: LoadedConfig) => {\n const [command, ...args] = conf.get('editor').split(' ')\n if (!command) {\n throw error(`editor is empty`)\n }\n await conf.editConfigFile(conf.get('config'), file => {\n args.push(file)\n const res = spawnSync(command, args, {\n stdio: 'inherit',\n })\n if (res.status !== 0) {\n throw error(`${command} command failed`, {\n ...res,\n command,\n args,\n })\n }\n })\n}\n\nconst set = async (conf: LoadedConfig) => {\n const pairs = conf.positionals.slice(1)\n if (!pairs.length) {\n throw error('At least one key=value pair is required', {\n code: 'EUSAGE',\n })\n }\n await conf.addConfigToFile(\n conf.get('config'),\n pairsToRecords(\n conf.jack.parseRaw(pairs.map(kv => `--${kv}`)).values,\n ),\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"}
|