@vltpkg/cli-sdk 1.4.0 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/print-err.js CHANGED
@@ -223,8 +223,11 @@ const printCode = (err, usage, stderr, format) => {
223
223
  return {};
224
224
  }
225
225
  case 'ECONFIG': {
226
- const { found, wanted, validOptions } = err.cause;
226
+ const { found, wanted, validOptions, from } = err.cause;
227
227
  stderr(`Config Error: ${err.message}`);
228
+ if (from) {
229
+ stderr(indent(`From: ${format(from)}`));
230
+ }
228
231
  if (found) {
229
232
  stderr(indent(`Found: ${format(found)}`));
230
233
  }
@@ -0,0 +1,9 @@
1
+ import type { NormalizedManifest } from '@vltpkg/types';
2
+ type PublishConfig = {
3
+ directory?: string;
4
+ registry?: string;
5
+ access?: string;
6
+ tag?: string;
7
+ };
8
+ export declare const getPublishConfig: (manifest: NormalizedManifest) => PublishConfig | undefined;
9
+ export {};
@@ -0,0 +1,8 @@
1
+ export const getPublishConfig = (manifest) => {
2
+ const pc = manifest
3
+ .publishConfig;
4
+ if (pc && typeof pc === 'object') {
5
+ return pc;
6
+ }
7
+ return undefined;
8
+ };
@@ -0,0 +1,28 @@
1
+ /** Streams to prompt on; default stdin and stdout. */
2
+ export type PromptStreams = {
3
+ input?: NodeJS.ReadableStream;
4
+ output?: NodeJS.WritableStream;
5
+ };
6
+ /** Prompts can be answered: stdin is a TTY. */
7
+ export declare const interactive: () => boolean;
8
+ /**
9
+ * `[y/N]` question: true on `y`/`yes` (any case), else false. Closed
10
+ * input (EOF, ctrl+C/D): undefined (cancel).
11
+ */
12
+ export declare const confirm: (question: string, s?: PromptStreams) => Promise<boolean | undefined>;
13
+ export type EditQueryOptions = PromptStreams & {
14
+ /** stored query, shown above the prompt; unset: nothing stored */
15
+ current?: string;
16
+ /** editable answer */
17
+ prefill: string;
18
+ /**
19
+ * throws on an invalid query: its message is printed and the
20
+ * question asked again
21
+ */
22
+ check: (q: string) => Promise<unknown>;
23
+ };
24
+ /**
25
+ * Ask for a new `allow-skills`, prefilled. Empty answer or closed
26
+ * input: undefined (cancel).
27
+ */
28
+ export declare const editQuery: ({ current, prefill, check, ...s }: EditQueryOptions) => Promise<string | undefined>;
@@ -0,0 +1,78 @@
1
+ import { createInterface } from 'node:readline/promises';
2
+ import { asError } from '@vltpkg/types';
3
+ import { styleTextStdout } from "./output.js";
4
+ /** Prompts can be answered: stdin is a TTY. */
5
+ export const interactive = () => process.stdin.isTTY;
6
+ const open = (s) => {
7
+ const rl = createInterface({
8
+ input: s.input ?? process.stdin,
9
+ output: s.output ?? process.stdout,
10
+ // prefill and line editing
11
+ terminal: true,
12
+ });
13
+ // ctrl+C cancels
14
+ rl.on('SIGINT', () => rl.close());
15
+ let done = false;
16
+ const closed = new Promise(r => rl.once('close', () => {
17
+ done = true;
18
+ r(undefined);
19
+ }));
20
+ // the answer; undefined once the input is closed (EOF, ctrl+C/D)
21
+ const ask = async (query, prefill) => {
22
+ if (done)
23
+ return undefined;
24
+ const q = rl.question(query).catch(() => undefined);
25
+ if (prefill)
26
+ rl.write(prefill);
27
+ return Promise.race([q, closed]);
28
+ };
29
+ return { rl, ask };
30
+ };
31
+ /**
32
+ * `[y/N]` question: true on `y`/`yes` (any case), else false. Closed
33
+ * input (EOF, ctrl+C/D): undefined (cancel).
34
+ */
35
+ export const confirm = async (question, s = {}) => {
36
+ const { rl, ask } = open(s);
37
+ try {
38
+ const a = await ask(question);
39
+ return a === undefined ? undefined : /^y(es)?$/i.test(a.trim());
40
+ }
41
+ finally {
42
+ rl.close();
43
+ }
44
+ };
45
+ /**
46
+ * Ask for a new `allow-skills`, prefilled. Empty answer or closed
47
+ * input: undefined (cancel).
48
+ */
49
+ export const editQuery = async ({ current, prefill, check, ...s }) => {
50
+ const output = s.output ?? process.stdout;
51
+ if (current !== undefined) {
52
+ output.write('\n⚠️ The new allow-skills replaces the current one. Make sure it still\n' +
53
+ 'selects every skill you want: skills it no longer selects are unlinked.\n\n' +
54
+ styleTextStdout('yellow', `Current allow-skills: ${current}`) +
55
+ '\n');
56
+ }
57
+ const prompt = styleTextStdout('cyan', 'New allow-skills: ');
58
+ const { rl, ask } = open(s);
59
+ try {
60
+ let fill = prefill;
61
+ for (;;) {
62
+ const a = (await ask(prompt, fill))?.trim();
63
+ if (!a)
64
+ return undefined;
65
+ try {
66
+ await check(a);
67
+ return a;
68
+ }
69
+ catch (e) {
70
+ output.write(`${asError(e).message}\n`);
71
+ fill = a;
72
+ }
73
+ }
74
+ }
75
+ finally {
76
+ rl.close();
77
+ }
78
+ };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vltpkg/cli-sdk",
3
3
  "description": "The source for the vlt CLI",
4
- "version": "1.4.0",
4
+ "version": "1.5.0",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/vltpkg/vltpkg.git",
@@ -14,33 +14,33 @@
14
14
  },
15
15
  "dependencies": {
16
16
  "@resvg/resvg-wasm": "^2.6.2",
17
- "@vltpkg/config": "1.4.0",
18
- "@vltpkg/dep-id": "1.4.0",
19
- "@vltpkg/dot-prop": "1.4.0",
20
- "@vltpkg/error-cause": "1.4.0",
21
- "@vltpkg/git": "1.4.0",
22
- "@vltpkg/graph": "1.4.0",
23
- "@vltpkg/graph-run": "1.4.0",
24
- "@vltpkg/init": "1.4.0",
25
- "@vltpkg/output": "1.4.0",
26
- "@vltpkg/package-info": "1.4.0",
27
- "@vltpkg/package-json": "1.4.0",
28
- "@vltpkg/pick-manifest": "1.4.0",
29
- "@vltpkg/promise-spawn": "1.4.0",
30
- "@vltpkg/query": "1.4.0",
31
- "@vltpkg/registry-client": "1.4.0",
32
- "@vltpkg/rollback-remove": "1.4.0",
33
- "@vltpkg/run": "1.4.0",
34
- "@vltpkg/security-archive": "1.4.0",
35
- "@vltpkg/semver": "1.4.0",
36
- "@vltpkg/spec": "1.4.0",
37
- "@vltpkg/tar": "1.4.0",
38
- "@vltpkg/types": "1.4.0",
39
- "@vltpkg/url-open": "1.4.0",
40
- "@vltpkg/vlt-json": "1.4.0",
41
- "@vltpkg/vlx": "1.4.0",
42
- "@vltpkg/workspaces": "1.4.0",
43
- "@vltpkg/xdg": "1.4.0",
17
+ "@vltpkg/config": "1.5.0",
18
+ "@vltpkg/dep-id": "1.5.0",
19
+ "@vltpkg/dot-prop": "1.5.0",
20
+ "@vltpkg/error-cause": "1.5.0",
21
+ "@vltpkg/git": "1.5.0",
22
+ "@vltpkg/graph": "1.5.0",
23
+ "@vltpkg/graph-run": "1.5.0",
24
+ "@vltpkg/init": "1.5.0",
25
+ "@vltpkg/output": "1.5.0",
26
+ "@vltpkg/package-info": "1.5.0",
27
+ "@vltpkg/package-json": "1.5.0",
28
+ "@vltpkg/pick-manifest": "1.5.0",
29
+ "@vltpkg/promise-spawn": "1.5.0",
30
+ "@vltpkg/query": "1.5.0",
31
+ "@vltpkg/registry-client": "1.5.0",
32
+ "@vltpkg/rollback-remove": "1.5.0",
33
+ "@vltpkg/run": "1.5.0",
34
+ "@vltpkg/security-archive": "1.5.0",
35
+ "@vltpkg/semver": "1.5.0",
36
+ "@vltpkg/spec": "1.5.0",
37
+ "@vltpkg/tar": "1.5.0",
38
+ "@vltpkg/types": "1.5.0",
39
+ "@vltpkg/url-open": "1.5.0",
40
+ "@vltpkg/vlt-json": "1.5.0",
41
+ "@vltpkg/vlx": "1.5.0",
42
+ "@vltpkg/workspaces": "1.5.0",
43
+ "@vltpkg/xdg": "1.5.0",
44
44
  "ansi-to-pre": "^1.0.6",
45
45
  "beautiful-mermaid": "^1.1.3",
46
46
  "chalk": "^5.6.2",