@vltpkg/cli-sdk 0.0.0-7 → 0.0.0-9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. package/dist/esm/commands/cache.d.ts +47 -0
  2. package/dist/esm/commands/cache.d.ts.map +1 -0
  3. package/dist/esm/commands/cache.js +211 -0
  4. package/dist/esm/commands/cache.js.map +1 -0
  5. package/dist/esm/commands/exec-local.d.ts +5 -0
  6. package/dist/esm/commands/exec-local.d.ts.map +1 -0
  7. package/dist/esm/commands/exec-local.js +22 -0
  8. package/dist/esm/commands/exec-local.js.map +1 -0
  9. package/dist/esm/commands/exec.d.ts +1 -2
  10. package/dist/esm/commands/exec.d.ts.map +1 -1
  11. package/dist/esm/commands/exec.js +6 -15
  12. package/dist/esm/commands/exec.js.map +1 -1
  13. package/dist/esm/commands/init.d.ts +2 -3
  14. package/dist/esm/commands/init.d.ts.map +1 -1
  15. package/dist/esm/commands/init.js.map +1 -1
  16. package/dist/esm/commands/install/reporter.d.ts.map +1 -1
  17. package/dist/esm/commands/install/reporter.js +2 -1
  18. package/dist/esm/commands/install/reporter.js.map +1 -1
  19. package/dist/esm/commands/install.d.ts +5 -2
  20. package/dist/esm/commands/install.d.ts.map +1 -1
  21. package/dist/esm/commands/install.js.map +1 -1
  22. package/dist/esm/commands/list.d.ts.map +1 -1
  23. package/dist/esm/commands/list.js +2 -4
  24. package/dist/esm/commands/list.js.map +1 -1
  25. package/dist/esm/commands/pkg.d.ts +3 -3
  26. package/dist/esm/commands/pkg.d.ts.map +1 -1
  27. package/dist/esm/commands/pkg.js.map +1 -1
  28. package/dist/esm/commands/query.d.ts +2 -1
  29. package/dist/esm/commands/query.d.ts.map +1 -1
  30. package/dist/esm/commands/query.js +39 -4
  31. package/dist/esm/commands/query.js.map +1 -1
  32. package/dist/esm/commands/uninstall.d.ts +5 -2
  33. package/dist/esm/commands/uninstall.d.ts.map +1 -1
  34. package/dist/esm/commands/uninstall.js.map +1 -1
  35. package/dist/esm/commands/whoami.d.ts +4 -2
  36. package/dist/esm/commands/whoami.d.ts.map +1 -1
  37. package/dist/esm/commands/whoami.js +1 -1
  38. package/dist/esm/commands/whoami.js.map +1 -1
  39. package/dist/esm/config/definition.d.ts +17 -2
  40. package/dist/esm/config/definition.d.ts.map +1 -1
  41. package/dist/esm/config/definition.js +41 -7
  42. package/dist/esm/config/definition.js.map +1 -1
  43. package/dist/esm/config/index.d.ts +1 -0
  44. package/dist/esm/config/index.d.ts.map +1 -1
  45. package/dist/esm/config/index.js +7 -0
  46. package/dist/esm/config/index.js.map +1 -1
  47. package/dist/esm/config/usage.d.ts +3 -2
  48. package/dist/esm/config/usage.d.ts.map +1 -1
  49. package/dist/esm/config/usage.js.map +1 -1
  50. package/dist/esm/exec-command.js +2 -2
  51. package/dist/esm/exec-command.js.map +1 -1
  52. package/dist/esm/index.js +2 -2
  53. package/dist/esm/index.js.map +1 -1
  54. package/dist/esm/output.d.ts +2 -1
  55. package/dist/esm/output.d.ts.map +1 -1
  56. package/dist/esm/output.js +20 -19
  57. package/dist/esm/output.js.map +1 -1
  58. package/dist/esm/parse-add-remove-args.d.ts +1 -1
  59. package/dist/esm/parse-add-remove-args.d.ts.map +1 -1
  60. package/dist/esm/parse-add-remove-args.js +1 -1
  61. package/dist/esm/parse-add-remove-args.js.map +1 -1
  62. package/dist/esm/print-err.d.ts +5 -1
  63. package/dist/esm/print-err.d.ts.map +1 -1
  64. package/dist/esm/print-err.js +68 -21
  65. package/dist/esm/print-err.js.map +1 -1
  66. package/dist/esm/view.d.ts +1 -1
  67. package/dist/esm/view.d.ts.map +1 -1
  68. package/dist/esm/view.js.map +1 -1
  69. package/package.json +23 -21
  70. package/dist/esm/commands/install-exec.d.ts +0 -4
  71. package/dist/esm/commands/install-exec.d.ts.map +0 -1
  72. package/dist/esm/commands/install-exec.js +0 -13
  73. package/dist/esm/commands/install-exec.js.map +0 -1
@@ -1,47 +1,94 @@
1
- import { isErrorRoot } from '@vltpkg/error-cause';
2
- // returns true if error was printed nicely already
3
- export const printErr = (err, usage, stderr) => {
4
- if (!isErrorRoot(err)) {
5
- // TODO: print _something_ here, but we're in weird broken territory
6
- // don't just dump it and flood the terminal, though, maybe sniff for code
7
- // message, stack, etc?
1
+ import { isErrorWithCode } from '@vltpkg/error-cause';
2
+ import { formatWithOptions } from 'node:util';
3
+ const trimStack = (err) => {
4
+ if (err.stack) {
5
+ const lines = err.stack.trim().split('\n');
6
+ if (lines[0] === `${err.name}: ${err.message}`) {
7
+ lines.shift();
8
+ }
9
+ return lines.map(l => l.trim()).join('\n');
10
+ }
11
+ };
12
+ const indent = (lines, num = 2) => lines
13
+ .split('\n')
14
+ .map(l => ' '.repeat(num) + l)
15
+ .join('\n');
16
+ export const printErr = (err, usage, stderr, baseOpts) => {
17
+ const format = (arg, opts) => {
18
+ const { maxLines = 200, ...rest } = { ...baseOpts, ...opts };
19
+ const lines = formatWithOptions(rest, arg).split('\n');
20
+ const totalLines = lines.length;
21
+ if (totalLines > maxLines) {
22
+ lines.length = maxLines;
23
+ lines.push(`... ${totalLines - maxLines} lines hidden ...`);
24
+ }
25
+ return lines.join('\n');
26
+ };
27
+ // This is an error with a cause, check if it we know about its
28
+ // code and try to print it. If it did not print then fallback
29
+ // to the next option.
30
+ if (isErrorWithCode(err) && print(err, usage, stderr, format)) {
8
31
  return;
9
32
  }
10
- if (isErrorRoot(err) && print(err, usage, stderr))
33
+ // We have a real but we dont know anything special about its
34
+ // properties. Just print the standard error properties as best we can.
35
+ if (err instanceof Error) {
36
+ stderr(`${err.name}: ${err.message}`);
37
+ if ('cause' in err) {
38
+ stderr(`Cause:`);
39
+ if (err.cause instanceof Error) {
40
+ stderr(indent(format(err.cause)));
41
+ }
42
+ else if (err.cause && typeof err.cause === 'object') {
43
+ for (const key in err.cause) {
44
+ stderr(indent(`${key}: ${format(err.cause[key])}`));
45
+ }
46
+ }
47
+ else {
48
+ stderr(indent(format(err.cause)));
49
+ }
50
+ }
51
+ const stack = trimStack(err);
52
+ if (stack) {
53
+ stderr(`Stack:`);
54
+ stderr(indent(format(stack)));
55
+ }
11
56
  return;
12
- stderr(err);
57
+ }
58
+ // We don't know what this is, just print it.
59
+ stderr(`Unknown Error:`, format(err));
13
60
  };
14
- const print = (err, usage, stderr) => {
61
+ const print = (err, usage, stderr, format) => {
15
62
  switch (err.cause.code) {
16
63
  case 'EUSAGE': {
64
+ const { found, validOptions } = err.cause;
17
65
  stderr(usage().usage());
18
- stderr(`Error: ${err.message}`);
19
- if (err.cause.found) {
20
- stderr(` Found: ${err.cause.found}`);
66
+ stderr(`Usage Error: ${err.message}`);
67
+ if (found) {
68
+ stderr(indent(`Found: ${format(found)}`));
21
69
  }
22
- if (err.cause.validOptions) {
23
- stderr(` Valid options: ${err.cause.validOptions.join(', ')}`);
70
+ if (validOptions) {
71
+ stderr(indent(`Valid options: ${format(validOptions.join(', '))}`));
24
72
  }
25
73
  return true;
26
74
  }
27
75
  case 'ERESOLVE': {
28
- stderr(`Resolve Error: ${err.message}`);
29
76
  const { url, from, response, spec } = err.cause;
77
+ stderr(`Resolve Error: ${err.message}`);
30
78
  if (url) {
31
- stderr(` While fetching: ${url}`);
79
+ stderr(indent(`While fetching: ${url}`));
32
80
  }
33
81
  if (spec) {
34
- stderr(` To satisfy: ${spec}`);
82
+ stderr(indent(`To satisfy: ${format(spec)}`));
35
83
  }
36
84
  if (from) {
37
- stderr(` From: ${from}`);
85
+ stderr(indent(`From: ${format(from)}`));
38
86
  }
39
87
  if (response) {
40
- stderr('Response:', response);
88
+ stderr(indent(`Response: ${format(response)}`));
41
89
  }
42
90
  return true;
43
91
  }
44
92
  }
45
- return false;
46
93
  };
47
94
  //# sourceMappingURL=print-err.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"print-err.js","sourceRoot":"","sources":["../../src/print-err.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AAKjD,mDAAmD;AACnD,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BAAqB,GAAG,EAAE,CAAC,CAAA;YACpC,CAAC;YACD,IAAI,IAAI,EAAE,CAAC;gBACT,MAAM,CAAC,iBAAiB,IAAqB,EAAE,CAAC,CAAA;YAClD,CAAC;YACD,IAAI,IAAI,EAAE,CAAC;gBACT,MAAM,CAAC,WAAW,IAAI,EAAE,CAAC,CAAA;YAC3B,CAAC;YACD,IAAI,QAAQ,EAAE,CAAC;gBACb,MAAM,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAA;YAC/B,CAAC;YACD,OAAO,IAAI,CAAA;QACb,CAAC;IACH,CAAC;IAED,OAAO,KAAK,CAAA;AACd,CAAC,CAAA","sourcesContent":["import { isErrorRoot } from '@vltpkg/error-cause'\nimport type { ErrorWithCauseObject } from '@vltpkg/error-cause'\nimport type { CommandUsage } from './index.ts'\nimport type { Spec } from '@vltpkg/spec'\n\n// returns true if error was printed nicely already\nexport const printErr = (\n err: unknown,\n usage: CommandUsage,\n stderr: (...a: unknown[]) => void,\n) => {\n if (!isErrorRoot(err)) {\n // TODO: print _something_ here, but we're in weird broken territory\n // don't just dump it and flood the terminal, though, maybe sniff for code\n // message, stack, etc?\n return\n }\n if (isErrorRoot(err) && print(err, usage, stderr)) return\n stderr(err)\n}\n\nconst print = (\n err: ErrorWithCauseObject,\n usage: CommandUsage,\n stderr: (...a: unknown[]) => void,\n): boolean => {\n switch (err.cause.code) {\n case 'EUSAGE': {\n stderr(usage().usage())\n stderr(`Error: ${err.message}`)\n if (err.cause.found) {\n stderr(` Found: ${err.cause.found}`)\n }\n if (err.cause.validOptions) {\n stderr(\n ` Valid options: ${err.cause.validOptions.join(', ')}`,\n )\n }\n return true\n }\n\n case 'ERESOLVE': {\n stderr(`Resolve Error: ${err.message}`)\n const { url, from, response, spec } = err.cause\n if (url) {\n stderr(` While fetching: ${url}`)\n }\n if (spec) {\n stderr(` To satisfy: ${spec as string | Spec}`)\n }\n if (from) {\n stderr(` From: ${from}`)\n }\n if (response) {\n stderr('Response:', response)\n }\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IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG,GAAG,CAAC,KAAK,CAAA;YAC/C,MAAM,CAAC,kBAAkB,GAAG,CAAC,OAAO,EAAE,CAAC,CAAA;YACvC,IAAI,GAAG,EAAE,CAAC;gBACR,MAAM,CAAC,MAAM,CAAC,mBAAmB,GAAG,EAAE,CAAC,CAAC,CAAA;YAC1C,CAAC;YACD,IAAI,IAAI,EAAE,CAAC;gBACT,MAAM,CAAC,MAAM,CAAC,eAAe,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAA;YAC/C,CAAC;YACD,IAAI,IAAI,EAAE,CAAC;gBACT,MAAM,CAAC,MAAM,CAAC,SAAS,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAA;YACzC,CAAC;YACD,IAAI,QAAQ,EAAE,CAAC;gBACb,MAAM,CAAC,MAAM,CAAC,aAAa,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAA;YACjD,CAAC;YACD,OAAO,IAAI,CAAA;QACb,CAAC;IACH,CAAC;AACH,CAAC,CAAA","sourcesContent":["import { isErrorWithCode } from '@vltpkg/error-cause'\nimport type { ErrorWithCode } from '@vltpkg/error-cause'\nimport type { CommandUsage } from './index.ts'\nimport type { InspectOptions } from 'node:util'\nimport { formatWithOptions } from 'node:util'\n\nexport type ErrorFormatOptions = InspectOptions & {\n maxLines?: number\n}\n\ntype Formatter = (\n arg: unknown,\n options?: ErrorFormatOptions,\n) => string\n\nconst trimStack = (err: Error) => {\n if (err.stack) {\n const lines = err.stack.trim().split('\\n')\n if (lines[0] === `${err.name}: ${err.message}`) {\n lines.shift()\n }\n return lines.map(l => l.trim()).join('\\n')\n }\n}\n\nconst indent = (lines: string, num = 2) =>\n lines\n .split('\\n')\n .map(l => ' '.repeat(num) + l)\n .join('\\n')\n\nexport const printErr = (\n err: unknown,\n usage: CommandUsage,\n stderr: (...a: string[]) => void,\n baseOpts?: ErrorFormatOptions,\n) => {\n const format: Formatter = (arg: unknown, opts) => {\n const { maxLines = 200, ...rest } = { ...baseOpts, ...opts }\n const lines = formatWithOptions(rest, arg).split('\\n')\n const totalLines = lines.length\n if (totalLines > maxLines) {\n lines.length = maxLines\n lines.push(`... ${totalLines - maxLines} lines hidden ...`)\n }\n return lines.join('\\n')\n }\n\n // This is an error with a cause, check if it we know about its\n // code and try to print it. If it did not print then fallback\n // to the next option.\n if (isErrorWithCode(err) && print(err, usage, stderr, format)) {\n return\n }\n\n // We have a real but we dont know anything special about its\n // properties. Just print the standard error properties as best we can.\n if (err instanceof Error) {\n stderr(`${err.name}: ${err.message}`)\n if ('cause' in err) {\n stderr(`Cause:`)\n if (err.cause instanceof Error) {\n stderr(indent(format(err.cause)))\n } else if (err.cause && typeof err.cause === 'object') {\n for (const key in err.cause) {\n stderr(\n indent(\n `${key}: ${format((err.cause as Record<string, unknown>)[key])}`,\n ),\n )\n }\n } else {\n stderr(indent(format(err.cause)))\n }\n }\n const stack = trimStack(err)\n if (stack) {\n stderr(`Stack:`)\n stderr(indent(format(stack)))\n }\n return\n }\n\n // We don't know what this is, just print it.\n stderr(`Unknown Error:`, format(err))\n}\n\nconst print = (\n err: ErrorWithCode,\n usage: CommandUsage,\n stderr: (...a: string[]) => void,\n format: Formatter,\n) => {\n switch (err.cause.code) {\n case 'EUSAGE': {\n const { found, validOptions } = err.cause\n stderr(usage().usage())\n stderr(`Usage Error: ${err.message}`)\n if (found) {\n stderr(indent(`Found: ${format(found)}`))\n }\n if (validOptions) {\n stderr(\n indent(`Valid options: ${format(validOptions.join(', '))}`),\n )\n }\n return true\n }\n\n case 'ERESOLVE': {\n const { url, from, response, spec } = err.cause\n stderr(`Resolve Error: ${err.message}`)\n if (url) {\n stderr(indent(`While fetching: ${url}`))\n }\n if (spec) {\n stderr(indent(`To satisfy: ${format(spec)}`))\n }\n if (from) {\n stderr(indent(`From: ${format(from)}`))\n }\n if (response) {\n stderr(indent(`Response: ${format(response)}`))\n }\n return true\n }\n }\n}\n"]}
@@ -21,7 +21,7 @@ export declare class ViewClass<T = unknown> {
21
21
  start(): void;
22
22
  done(_result: T, _opts: {
23
23
  time: number;
24
- }): undefined | string;
24
+ }): unknown;
25
25
  error(_err: unknown): void;
26
26
  }
27
27
  export type ViewFn<T = unknown> = (result: T, options: ViewOptions, conf: LoadedConfig) => unknown;
@@ -1 +1 @@
1
- {"version":3,"file":"view.d.ts","sourceRoot":"","sources":["../../src/view.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAA;AAC1C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAErD,MAAM,MAAM,WAAW,GAAG;IAAE,MAAM,CAAC,EAAE,aAAa,CAAA;CAAE,CAAA;AAEpD;;;;;;;;;;GAUG;AACH,qBAAa,SAAS,CAAC,CAAC,GAAG,OAAO;IAChC,OAAO,EAAE,WAAW,CAAA;IACpB,MAAM,EAAE,YAAY,CAAA;gBAER,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,YAAY;IAQtD,KAAK;IACL,IAAI,CAAC,OAAO,EAAE,CAAC,EAAE,KAAK,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,GAAG,SAAS,GAAG,MAAM;IAG7D,KAAK,CAAC,IAAI,EAAE,OAAO;CACpB;AAED,MAAM,MAAM,MAAM,CAAC,CAAC,GAAG,OAAO,IAAI,CAChC,MAAM,EAAE,CAAC,EACT,OAAO,EAAE,WAAW,EACpB,IAAI,EAAE,YAAY,KACf,OAAO,CAAA;AAEZ,MAAM,MAAM,IAAI,CAAC,CAAC,GAAG,OAAO,IAAI,MAAM,CAAC,CAAC,CAAC,GAAG,OAAO,SAAS,CAAC,CAAC,CAAC,CAAA;AAE/D,eAAO,MAAM,WAAW,GAAI,CAAC,kBACrB,IAAI,CAAC,CAAC,CAAC,KACZ,IAAI,IAAI,OAAO,SAAS,CAAC,CAAC,CAGQ,CAAA;AAErC,MAAM,MAAM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AAC,CAAC,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"view.js","sourceRoot":"","sources":["../../src/view.ts"],"names":[],"mappings":"AAKA;;;;;;;;;;GAUG;AACH,MAAM,OAAO,SAAS;IACpB,OAAO,CAAa;IACpB,MAAM,CAAc;IAEpB,YAAY,OAAoB,EAAE,MAAoB;QACpD,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;IACtB,CAAC;IAED,oEAAoE;IACpE,wEAAwE;IACxE,wEAAwE;IACxE,KAAK,KAAI,CAAC;IACV,IAAI,CAAC,OAAU,EAAE,KAAuB;QACtC,OAAM;IACR,CAAC;IACD,KAAK,CAAC,IAAa,IAAG,CAAC;CACxB;AAUD,MAAM,CAAC,MAAM,WAAW,GAAG,CACzB,IAAa,EACgB,EAAE,CAC/B,OAAO,IAAI,KAAK,UAAU;IAC1B,WAAW,IAAI,IAAI;IACnB,IAAI,CAAC,SAAS,YAAY,SAAS,CAAA","sourcesContent":["import type { ChalkInstance } from 'chalk'\nimport type { LoadedConfig } from './config/index.ts'\n\nexport type ViewOptions = { colors?: ChalkInstance }\n\n/**\n * The base class for all View classes\n *\n * Do not override the constructor, just provide start/done/error methods.\n *\n * These classes should be used as one or more of the exported views for\n * commands that need to know when the processing starts, handle errors in\n * various ways, etc. Fancy stuff.\n *\n * For simple use cases, usually better to create a {@link ViewFn} instead.\n */\nexport class ViewClass<T = unknown> {\n options: ViewOptions\n config: LoadedConfig\n\n constructor(options: ViewOptions, config: LoadedConfig) {\n this.options = options\n this.config = config\n }\n\n // TODO: maybe have start() return a flag to say \"i got this, do not\n // run the command\", for example to have the gui just open a web browser\n // to the page relevant to a given thing, rather than computing it twice\n start() {}\n done(_result: T, _opts: { time: number }): undefined | string {\n return\n }\n error(_err: unknown) {}\n}\n\nexport type ViewFn<T = unknown> = (\n result: T,\n options: ViewOptions,\n conf: LoadedConfig,\n) => unknown\n\nexport type View<T = unknown> = ViewFn<T> | typeof ViewClass<T>\n\nexport const isViewClass = <T = unknown>(\n view: View<T>,\n): view is typeof ViewClass<T> =>\n typeof view === 'function' &&\n 'prototype' in view &&\n view.prototype instanceof ViewClass\n\nexport type Views<T = unknown> = View<T> | Record<string, View<T>>\n"]}
1
+ {"version":3,"file":"view.js","sourceRoot":"","sources":["../../src/view.ts"],"names":[],"mappings":"AAKA;;;;;;;;;;GAUG;AACH,MAAM,OAAO,SAAS;IACpB,OAAO,CAAa;IACpB,MAAM,CAAc;IAEpB,YAAY,OAAoB,EAAE,MAAoB;QACpD,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;IACtB,CAAC;IAED,oEAAoE;IACpE,wEAAwE;IACxE,wEAAwE;IACxE,KAAK,KAAI,CAAC;IACV,IAAI,CAAC,OAAU,EAAE,KAAuB;QACtC,OAAM;IACR,CAAC;IACD,KAAK,CAAC,IAAa,IAAG,CAAC;CACxB;AAUD,MAAM,CAAC,MAAM,WAAW,GAAG,CACzB,IAAa,EACgB,EAAE,CAC/B,OAAO,IAAI,KAAK,UAAU;IAC1B,WAAW,IAAI,IAAI;IACnB,IAAI,CAAC,SAAS,YAAY,SAAS,CAAA","sourcesContent":["import type { ChalkInstance } from 'chalk'\nimport type { LoadedConfig } from './config/index.ts'\n\nexport type ViewOptions = { colors?: ChalkInstance }\n\n/**\n * The base class for all View classes\n *\n * Do not override the constructor, just provide start/done/error methods.\n *\n * These classes should be used as one or more of the exported views for\n * commands that need to know when the processing starts, handle errors in\n * various ways, etc. Fancy stuff.\n *\n * For simple use cases, usually better to create a {@link ViewFn} instead.\n */\nexport class ViewClass<T = unknown> {\n options: ViewOptions\n config: LoadedConfig\n\n constructor(options: ViewOptions, config: LoadedConfig) {\n this.options = options\n this.config = config\n }\n\n // TODO: maybe have start() return a flag to say \"i got this, do not\n // run the command\", for example to have the gui just open a web browser\n // to the page relevant to a given thing, rather than computing it twice\n start() {}\n done(_result: T, _opts: { time: number }): unknown {\n return\n }\n error(_err: unknown) {}\n}\n\nexport type ViewFn<T = unknown> = (\n result: T,\n options: ViewOptions,\n conf: LoadedConfig,\n) => unknown\n\nexport type View<T = unknown> = ViewFn<T> | typeof ViewClass<T>\n\nexport const isViewClass = <T = unknown>(\n view: View<T>,\n): view is typeof ViewClass<T> =>\n typeof view === 'function' &&\n 'prototype' in view &&\n view.prototype instanceof ViewClass\n\nexport type Views<T = unknown> = View<T> | Record<string, View<T>>\n"]}
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": "0.0.0-7",
4
+ "version": "0.0.0-9",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/vltpkg/vltpkg.git",
@@ -24,34 +24,36 @@
24
24
  "dependencies": {
25
25
  "ansi-to-pre": "^1.0.5",
26
26
  "chalk": "^5.3.0",
27
- "ink": "^5.1.0",
27
+ "ink": "^5.2.0",
28
28
  "ink-spinner": "^5.0.0",
29
29
  "jackspeak": "^4.0.3",
30
30
  "package-json-from-dist": "^1.0.0",
31
31
  "path-scurry": "^2.0.0",
32
32
  "polite-json": "^5.0.0",
33
+ "pretty-bytes": "^6.1.1",
33
34
  "react": "^18.3.1",
34
35
  "react-devtools-core": "^4.28.5",
35
36
  "walk-up-path": "^4.0.0",
36
- "@vltpkg/dep-id": "0.0.0-7",
37
- "@vltpkg/dot-prop": "0.0.0-7",
38
- "@vltpkg/error-cause": "0.0.0-7",
39
- "@vltpkg/graph": "0.0.0-7",
40
- "@vltpkg/init": "0.0.0-7",
41
- "@vltpkg/output": "0.0.0-7",
42
- "@vltpkg/package-info": "0.0.0-7",
43
- "@vltpkg/package-json": "0.0.0-7",
44
- "@vltpkg/promise-spawn": "0.0.0-7",
45
- "@vltpkg/query": "0.0.0-7",
46
- "@vltpkg/registry-client": "0.0.0-7",
47
- "@vltpkg/security-archive": "0.0.0-7",
48
- "@vltpkg/server": "0.0.0-7",
49
- "@vltpkg/run": "0.0.0-7",
50
- "@vltpkg/spec": "0.0.0-7",
51
- "@vltpkg/types": "0.0.0-7",
52
- "@vltpkg/workspaces": "0.0.0-7",
53
- "@vltpkg/xdg": "0.0.0-7",
54
- "@vltpkg/url-open": "0.0.0-7"
37
+ "@vltpkg/cache": "0.0.0-9",
38
+ "@vltpkg/dep-id": "0.0.0-9",
39
+ "@vltpkg/dot-prop": "0.0.0-9",
40
+ "@vltpkg/init": "0.0.0-9",
41
+ "@vltpkg/output": "0.0.0-9",
42
+ "@vltpkg/error-cause": "0.0.0-9",
43
+ "@vltpkg/graph": "0.0.0-9",
44
+ "@vltpkg/package-info": "0.0.0-9",
45
+ "@vltpkg/query": "0.0.0-9",
46
+ "@vltpkg/package-json": "0.0.0-9",
47
+ "@vltpkg/promise-spawn": "0.0.0-9",
48
+ "@vltpkg/run": "0.0.0-9",
49
+ "@vltpkg/registry-client": "0.0.0-9",
50
+ "@vltpkg/server": "0.0.0-9",
51
+ "@vltpkg/security-archive": "0.0.0-9",
52
+ "@vltpkg/spec": "0.0.0-9",
53
+ "@vltpkg/types": "0.0.0-9",
54
+ "@vltpkg/url-open": "0.0.0-9",
55
+ "@vltpkg/workspaces": "0.0.0-9",
56
+ "@vltpkg/xdg": "0.0.0-9"
55
57
  },
56
58
  "devDependencies": {
57
59
  "@eslint/js": "^9.20.0",
@@ -1,4 +0,0 @@
1
- import type { CommandFn, CommandUsage } from '../index.ts';
2
- export declare const usage: CommandUsage;
3
- export declare const command: CommandFn<string>;
4
- //# sourceMappingURL=install-exec.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"install-exec.d.ts","sourceRoot":"","sources":["../../../src/commands/install-exec.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAE1D,eAAO,MAAM,KAAK,EAAE,YAMhB,CAAA;AAEJ,eAAO,MAAM,OAAO,EAAE,SAAS,CAAC,MAAM,CAKrC,CAAA"}
@@ -1,13 +0,0 @@
1
- import { commandUsage } from "../config/usage.js";
2
- export const usage = () => commandUsage({
3
- command: 'install-exec',
4
- usage: '[--package=<pkg>] [command...]',
5
- description: 'Run a command defined by a package, installing it if necessary',
6
- });
7
- export const command = async (conf) => {
8
- return [
9
- 'TODO: exec, but install if not present',
10
- ...conf.positionals,
11
- ].join('\n');
12
- };
13
- //# sourceMappingURL=install-exec.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"install-exec.js","sourceRoot":"","sources":["../../../src/commands/install-exec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAGjD,MAAM,CAAC,MAAM,KAAK,GAAiB,GAAG,EAAE,CACtC,YAAY,CAAC;IACX,OAAO,EAAE,cAAc;IACvB,KAAK,EAAE,gCAAgC;IACvC,WAAW,EACT,gEAAgE;CACnE,CAAC,CAAA;AAEJ,MAAM,CAAC,MAAM,OAAO,GAAsB,KAAK,EAAC,IAAI,EAAC,EAAE;IACrD,OAAO;QACL,wCAAwC;QACxC,GAAG,IAAI,CAAC,WAAW;KACpB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;AACd,CAAC,CAAA","sourcesContent":["import { commandUsage } from '../config/usage.ts'\nimport type { CommandFn, CommandUsage } from '../index.ts'\n\nexport const usage: CommandUsage = () =>\n commandUsage({\n command: 'install-exec',\n usage: '[--package=<pkg>] [command...]',\n description:\n 'Run a command defined by a package, installing it if necessary',\n })\n\nexport const command: CommandFn<string> = async conf => {\n return [\n 'TODO: exec, but install if not present',\n ...conf.positionals,\n ].join('\\n')\n}\n"]}