@vltpkg/cli-sdk 0.0.0-2

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 (136) hide show
  1. package/LICENSE +15 -0
  2. package/README.md +20 -0
  3. package/dist/esm/commands/config.d.ts +5 -0
  4. package/dist/esm/commands/config.d.ts.map +1 -0
  5. package/dist/esm/commands/config.js +153 -0
  6. package/dist/esm/commands/config.js.map +1 -0
  7. package/dist/esm/commands/exec.d.ts +5 -0
  8. package/dist/esm/commands/exec.d.ts.map +1 -0
  9. package/dist/esm/commands/exec.js +22 -0
  10. package/dist/esm/commands/exec.js.map +1 -0
  11. package/dist/esm/commands/gui.d.ts +6 -0
  12. package/dist/esm/commands/gui.d.ts.map +1 -0
  13. package/dist/esm/commands/gui.js +14 -0
  14. package/dist/esm/commands/gui.js.map +1 -0
  15. package/dist/esm/commands/help.d.ts +4 -0
  16. package/dist/esm/commands/help.d.ts.map +1 -0
  17. package/dist/esm/commands/help.js +10 -0
  18. package/dist/esm/commands/help.js.map +1 -0
  19. package/dist/esm/commands/init.d.ts +9 -0
  20. package/dist/esm/commands/init.d.ts.map +1 -0
  21. package/dist/esm/commands/init.js +25 -0
  22. package/dist/esm/commands/init.js.map +1 -0
  23. package/dist/esm/commands/install/reporter.d.ts +10 -0
  24. package/dist/esm/commands/install/reporter.d.ts.map +1 -0
  25. package/dist/esm/commands/install/reporter.js +66 -0
  26. package/dist/esm/commands/install/reporter.js.map +1 -0
  27. package/dist/esm/commands/install-exec.d.ts +4 -0
  28. package/dist/esm/commands/install-exec.d.ts.map +1 -0
  29. package/dist/esm/commands/install-exec.js +13 -0
  30. package/dist/esm/commands/install-exec.js.map +1 -0
  31. package/dist/esm/commands/install.d.ts +7 -0
  32. package/dist/esm/commands/install.d.ts.map +1 -0
  33. package/dist/esm/commands/install.js +21 -0
  34. package/dist/esm/commands/install.js.map +1 -0
  35. package/dist/esm/commands/list.d.ts +15 -0
  36. package/dist/esm/commands/list.d.ts.map +1 -0
  37. package/dist/esm/commands/list.js +91 -0
  38. package/dist/esm/commands/list.js.map +1 -0
  39. package/dist/esm/commands/login.d.ts +4 -0
  40. package/dist/esm/commands/login.d.ts.map +1 -0
  41. package/dist/esm/commands/login.js +13 -0
  42. package/dist/esm/commands/login.js.map +1 -0
  43. package/dist/esm/commands/logout.d.ts +4 -0
  44. package/dist/esm/commands/logout.d.ts.map +1 -0
  45. package/dist/esm/commands/logout.js +13 -0
  46. package/dist/esm/commands/logout.js.map +1 -0
  47. package/dist/esm/commands/pkg.d.ts +8 -0
  48. package/dist/esm/commands/pkg.d.ts.map +1 -0
  49. package/dist/esm/commands/pkg.js +121 -0
  50. package/dist/esm/commands/pkg.js.map +1 -0
  51. package/dist/esm/commands/query.d.ts +16 -0
  52. package/dist/esm/commands/query.d.ts.map +1 -0
  53. package/dist/esm/commands/query.js +75 -0
  54. package/dist/esm/commands/query.js.map +1 -0
  55. package/dist/esm/commands/run-exec.d.ts +5 -0
  56. package/dist/esm/commands/run-exec.d.ts.map +1 -0
  57. package/dist/esm/commands/run-exec.js +13 -0
  58. package/dist/esm/commands/run-exec.js.map +1 -0
  59. package/dist/esm/commands/run.d.ts +5 -0
  60. package/dist/esm/commands/run.d.ts.map +1 -0
  61. package/dist/esm/commands/run.js +39 -0
  62. package/dist/esm/commands/run.js.map +1 -0
  63. package/dist/esm/commands/token.d.ts +4 -0
  64. package/dist/esm/commands/token.d.ts.map +1 -0
  65. package/dist/esm/commands/token.js +30 -0
  66. package/dist/esm/commands/token.js.map +1 -0
  67. package/dist/esm/commands/uninstall.d.ts +4 -0
  68. package/dist/esm/commands/uninstall.d.ts.map +1 -0
  69. package/dist/esm/commands/uninstall.js +15 -0
  70. package/dist/esm/commands/uninstall.js.map +1 -0
  71. package/dist/esm/commands/whoami.d.ts +11 -0
  72. package/dist/esm/commands/whoami.d.ts.map +1 -0
  73. package/dist/esm/commands/whoami.js +19 -0
  74. package/dist/esm/commands/whoami.js.map +1 -0
  75. package/dist/esm/config/definition.d.ts +286 -0
  76. package/dist/esm/config/definition.d.ts.map +1 -0
  77. package/dist/esm/config/definition.js +475 -0
  78. package/dist/esm/config/definition.js.map +1 -0
  79. package/dist/esm/config/index.d.ts +213 -0
  80. package/dist/esm/config/index.d.ts.map +1 -0
  81. package/dist/esm/config/index.js +504 -0
  82. package/dist/esm/config/index.js.map +1 -0
  83. package/dist/esm/config/merge.d.ts +2 -0
  84. package/dist/esm/config/merge.d.ts.map +1 -0
  85. package/dist/esm/config/merge.js +23 -0
  86. package/dist/esm/config/merge.js.map +1 -0
  87. package/dist/esm/config/usage.d.ts +18 -0
  88. package/dist/esm/config/usage.d.ts.map +1 -0
  89. package/dist/esm/config/usage.js +40 -0
  90. package/dist/esm/config/usage.js.map +1 -0
  91. package/dist/esm/exec-command.d.ts +34 -0
  92. package/dist/esm/exec-command.d.ts.map +1 -0
  93. package/dist/esm/exec-command.js +159 -0
  94. package/dist/esm/exec-command.js.map +1 -0
  95. package/dist/esm/ignored-homedir-folder-names.d.ts +7 -0
  96. package/dist/esm/ignored-homedir-folder-names.d.ts.map +1 -0
  97. package/dist/esm/ignored-homedir-folder-names.js +35 -0
  98. package/dist/esm/ignored-homedir-folder-names.js.map +1 -0
  99. package/dist/esm/index.d.ts +17 -0
  100. package/dist/esm/index.d.ts.map +1 -0
  101. package/dist/esm/index.js +47 -0
  102. package/dist/esm/index.js.map +1 -0
  103. package/dist/esm/output.d.ts +25 -0
  104. package/dist/esm/output.d.ts.map +1 -0
  105. package/dist/esm/output.js +86 -0
  106. package/dist/esm/output.js.map +1 -0
  107. package/dist/esm/package.json +3 -0
  108. package/dist/esm/parse-add-remove-args.d.ts +22 -0
  109. package/dist/esm/parse-add-remove-args.d.ts.map +1 -0
  110. package/dist/esm/parse-add-remove-args.js +71 -0
  111. package/dist/esm/parse-add-remove-args.js.map +1 -0
  112. package/dist/esm/print-err.d.ts +3 -0
  113. package/dist/esm/print-err.d.ts.map +1 -0
  114. package/dist/esm/print-err.js +47 -0
  115. package/dist/esm/print-err.js.map +1 -0
  116. package/dist/esm/project-info.d.ts +32 -0
  117. package/dist/esm/project-info.d.ts.map +1 -0
  118. package/dist/esm/project-info.js +90 -0
  119. package/dist/esm/project-info.js.map +1 -0
  120. package/dist/esm/read-password.d.ts +8 -0
  121. package/dist/esm/read-password.d.ts.map +1 -0
  122. package/dist/esm/read-password.js +33 -0
  123. package/dist/esm/read-password.js.map +1 -0
  124. package/dist/esm/read-project-folders.d.ts +27 -0
  125. package/dist/esm/read-project-folders.d.ts.map +1 -0
  126. package/dist/esm/read-project-folders.js +66 -0
  127. package/dist/esm/read-project-folders.js.map +1 -0
  128. package/dist/esm/start-gui.d.ts +36 -0
  129. package/dist/esm/start-gui.d.ts.map +1 -0
  130. package/dist/esm/start-gui.js +357 -0
  131. package/dist/esm/start-gui.js.map +1 -0
  132. package/dist/esm/view.d.ts +31 -0
  133. package/dist/esm/view.d.ts.map +1 -0
  134. package/dist/esm/view.js +31 -0
  135. package/dist/esm/view.js.map +1 -0
  136. package/package.json +107 -0
@@ -0,0 +1,40 @@
1
+ import { jack } from 'jackspeak';
2
+ import { commandAliases } from "./definition.js";
3
+ const toArr = (v) => (Array.isArray(v) ? v : [v]);
4
+ const code = (v) => [v, { pre: true }];
5
+ const join = (args, joiner = ' ') => args.filter(Boolean).join(joiner);
6
+ export const commandUsage = ({ command, usage, description, subcommands, examples, options, }) => {
7
+ const vlt = (s) => join([`vlt`, command, s]);
8
+ const joinUsage = (usages) => toArr(usages).map(vlt).filter(Boolean).join('\n');
9
+ const j = jack({ usage: joinUsage(usage) }).description(description);
10
+ const aliases = commandAliases.get(command);
11
+ if (aliases) {
12
+ j.heading('Aliases', 2).description(aliases.join(', '), {
13
+ pre: true,
14
+ });
15
+ }
16
+ if (subcommands) {
17
+ j.heading('Subcommands', 2);
18
+ for (const [k, v] of Object.entries(subcommands)) {
19
+ j.heading(k, 3)
20
+ .description(v.description)
21
+ .description(...code(joinUsage(toArr(v.usage).map(u => join([k, u])))));
22
+ }
23
+ }
24
+ if (examples) {
25
+ j.heading('Examples', 2);
26
+ for (const [k, v] of Object.entries(examples)) {
27
+ j.description(v.description).description(...code(vlt(k)));
28
+ }
29
+ }
30
+ if (options) {
31
+ j.heading('Options', 2);
32
+ for (const [k, v] of Object.entries(options)) {
33
+ j.heading(k, 3)
34
+ .description(v.description)
35
+ .description(...code(join(['--', k, v.value ? '=' : undefined, v.value], '')));
36
+ }
37
+ }
38
+ return j;
39
+ };
40
+ //# sourceMappingURL=usage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"usage.js","sourceRoot":"","sources":["../../../src/config/usage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAEhC,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAEhD,MAAM,KAAK,GAAG,CAAI,CAAU,EAAO,EAAE,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;AAElE,MAAM,IAAI,GAAG,CAAC,CAAS,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,CAAU,CAAA;AAEvD,MAAM,IAAI,GAAG,CAAC,IAA4B,EAAE,MAAM,GAAG,GAAG,EAAE,EAAE,CAC1D,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;AAEnC,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,EAC3B,OAAO,EACP,KAAK,EACL,WAAW,EACX,WAAW,EACX,QAAQ,EACR,OAAO,GAWR,EAA4B,EAAE;IAC7B,MAAM,GAAG,GAAG,CAAC,CAAU,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,CAAA;IAErD,MAAM,SAAS,G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AAC,QAAQ,CAAC,EAAE,CAAC;YAC9C,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,WAAW,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;QAC3D,CAAC;IACH,CAAC;IAED,IAAI,OAAO,EAAE,CAAC;QACZ,CAAC,CAAC,OAAO,CAAC,SAAS,EAAE,CAAC,CAAC,CAAA;QACvB,KAAK,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;YAC7C,CAAC,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC;iBACZ,WAAW,CAAC,CAAC,CAAC,WAAW,CAAC;iBAC1B,WAAW,CACV,GAAG,IAAI,CACL,IAAI,CAAC,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC,KAAK,CAAC,EAAE,EAAE,CAAC,CACxD,CACF,CAAA;QACL,CAAC;IACH,CAAC;IAED,OAAO,CAAC,CAAA;AACV,CAAC,CAAA","sourcesContent":["import { jack } from 'jackspeak'\nimport type { CommandUsage } from '../index.ts'\nimport { commandAliases } from './definition.ts'\n\nconst toArr = <T>(v: T | T[]): T[] => (Array.isArray(v) ? v : [v])\n\nconst code = (v: string) => [v, { pre: true }] as const\n\nconst join = (args: (string | undefined)[], joiner = ' ') =>\n args.filter(Boolean).join(joiner)\n\nexport const commandUsage = ({\n command,\n usage,\n description,\n subcommands,\n examples,\n options,\n}: {\n command: string\n usage: string | string[]\n description: string\n subcommands?: Record<\n string,\n { usage?: string | string[]; description: string }\n >\n examples?: Record<string, { description: string }>\n options?: Record<string, { value?: string; description: string }>\n}): ReturnType<CommandUsage> => {\n const vlt = (s?: string) => join([`vlt`, command, s])\n\n const joinUsage = (usages?: string | string[]) =>\n toArr(usages).map(vlt).filter(Boolean).join('\\n')\n\n const j = jack({ usage: joinUsage(usage) }).description(description)\n\n const aliases = commandAliases.get(command)\n if (aliases) {\n j.heading('Aliases', 2).description(aliases.join(', '), {\n pre: true,\n })\n }\n\n if (subcommands) {\n j.heading('Subcommands', 2)\n for (const [k, v] of Object.entries(subcommands)) {\n j.heading(k, 3)\n .description(v.description)\n .description(\n ...code(joinUsage(toArr(v.usage).map(u => join([k, u])))),\n )\n }\n }\n\n if (examples) {\n j.heading('Examples', 2)\n for (const [k, v] of Object.entries(examples)) {\n j.description(v.description).description(...code(vlt(k)))\n }\n }\n\n if (options) {\n j.heading('Options', 2)\n for (const [k, v] of Object.entries(options)) {\n j.heading(k, 3)\n .description(v.description)\n .description(\n ...code(\n join(['--', k, v.value ? '=' : undefined, v.value], ''),\n ),\n )\n }\n }\n\n return j\n}\n"]}
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Implementation shared between `vlt run`, `vlt run-exec`, and `vlt exec`
3
+ */
4
+ import type { exec, execFG, ExecOptions, run, runExec, runExecFG, RunExecOptions, runFG, RunOptions, RunResult } from '@vltpkg/run';
5
+ import { Monorepo } from '@vltpkg/workspaces';
6
+ import type { Workspace } from '@vltpkg/workspaces';
7
+ import type { LoadedConfig } from './config/index.ts';
8
+ import type { SpawnResultNoStdio } from '@vltpkg/promise-spawn';
9
+ export type RunnerBG = typeof exec | typeof run | typeof runExec;
10
+ export type RunnerFG = typeof execFG | typeof runExecFG | typeof runFG;
11
+ export type RunnerOptions = ExecOptions & RunExecOptions & RunOptions;
12
+ export type ExecResult = undefined | SpawnResultNoStdio | Record<string, RunResult>;
13
+ export declare class ExecCommand<B extends RunnerBG, F extends RunnerFG> {
14
+ bg: B;
15
+ fg: F;
16
+ arg0?: string;
17
+ args: string[];
18
+ monorepo?: Monorepo;
19
+ /** how many places are we doing things in? */
20
+ spaces: number;
21
+ conf: LoadedConfig;
22
+ projectRoot: string;
23
+ constructor(conf: LoadedConfig, bg: B, fg: F);
24
+ run(): Promise<ExecResult>;
25
+ printResult(ws: Workspace, result: RunResult): void;
26
+ setExitCode(result: RunResult): void;
27
+ interactiveShell(): string;
28
+ defaultArg0(): string | undefined;
29
+ fgArg(): RunnerOptions | undefined;
30
+ /** If this returns undefined, then nothing to do */
31
+ bgArg(ws: Workspace): RunnerOptions;
32
+ noArgsMulti(): void;
33
+ }
34
+ //# sourceMappingURL=exec-command.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exec-command.d.ts","sourceRoot":"","sources":["../../src/exec-command.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,OAAO,KAAK,EACV,IAAI,EACJ,MAAM,EACN,WAAW,EACX,GAAG,EACH,OAAO,EACP,SAAS,EACT,cAAc,EACd,KAAK,EACL,UAAU,EACV,SAAS,EACV,MAAM,aAAa,CAAA;AACpB,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAA;AAC7C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAGnD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAErD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAA;AAE/D,MAAM,MAAM,QAAQ,GAAG,OAAO,IAAI,GAAG,OAAO,GAAG,GAAG,OAAO,OAAO,CAAA;AAChE,MAAM,MAAM,QAAQ,GAAG,OAAO,MAAM,GAAG,OAAO,SAAS,GAAG,OAAO,KAAK,CAAA;AACtE,MAAM,MAAM,aAAa,GAAG,WAAW,GAAG,cAAc,GAAG,UAAU,CAAA;AACrE,MAAM,MAAM,UAAU,GAClB,SAAS,GACT,kBAAkB,GAClB,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAA;AAE7B,qBAAa,WAAW,CAAC,CAAC,SAAS,QAAQ,EAAE,CAAC,SAAS,QAAQ;IAC7D,EAAE,EAAE,CAAC,CAAA;IACL,EAAE,EAAE,CAAC,CAAA;IACL,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,IAAI,EAAE,MAAM,EAAE,CAAA;IACd,QAAQ,CAAC,EAAE,QAAQ,CAAA;IACnB,8CAA8C;IAC9C,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,EAAE,YAAY,CAAA;IAClB,WAAW,EAAE,MAAM,CAAA;gBAEP,IAAI,EAAE,YAAY,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC;IAsBtC,GAAG,IAAI,OAAO,CAAC,UAAU,CAAC;IAmDhC,WAAW,CAAC,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS;IAgB5C,WAAW,CAAC,MAAM,EAAE,SAAS;IAM7B,gBAAgB,IAAI,MAAM;IAU1B,WAAW,IAAI,MAAM,GAAG,SAAS;IAIjC,KAAK,IAAI,aAAa,GAAG,SAAS;IAoBlC,oDAAoD;IACpD,KAAK,CAAC,EAAE,EAAE,SAAS,GAAG,aAAa;IAqBnC,WAAW;CAKZ"}
@@ -0,0 +1,159 @@
1
+ /**
2
+ * Implementation shared between `vlt run`, `vlt run-exec`, and `vlt exec`
3
+ */
4
+ import { error, isErrorRoot } from '@vltpkg/error-cause';
5
+ import { isRunResult } from '@vltpkg/run';
6
+ import { Monorepo } from '@vltpkg/workspaces';
7
+ import { ansiToAnsi } from 'ansi-to-pre';
8
+ import chalk from 'chalk';
9
+ import { stdout, stderr } from "./output.js";
10
+ export class ExecCommand {
11
+ bg;
12
+ fg;
13
+ arg0;
14
+ args;
15
+ monorepo;
16
+ /** how many places are we doing things in? */
17
+ spaces;
18
+ conf;
19
+ projectRoot;
20
+ constructor(conf, bg, fg) {
21
+ this.conf = conf;
22
+ this.bg = bg;
23
+ this.fg = fg;
24
+ const { projectRoot, positionals: [arg0, ...args], } = conf;
25
+ this.arg0 = arg0;
26
+ this.args = args;
27
+ const paths = conf.get('workspace');
28
+ const groups = conf.get('workspace-group');
29
+ const recursive = conf.get('recursive');
30
+ this.monorepo =
31
+ paths?.length || groups?.length || recursive ?
32
+ Monorepo.load(projectRoot, { load: { paths, groups } })
33
+ : undefined;
34
+ this.spaces = this.monorepo?.size ?? 1;
35
+ this.projectRoot = projectRoot;
36
+ }
37
+ async run() {
38
+ if (this.spaces === 1) {
39
+ const arg = this.fgArg();
40
+ if (!arg)
41
+ return;
42
+ const result = await this.fg(arg);
43
+ stdout(result);
44
+ if (isRunResult(result)) {
45
+ this.setExitCode(result);
46
+ }
47
+ return result;
48
+ }
49
+ const m = this.monorepo;
50
+ if (!m || this.spaces === 0) {
51
+ throw error('no matching workspaces found', {
52
+ /* c8 ignore next - already guarded */
53
+ validOptions: [...(this.monorepo?.load().paths() ?? [])],
54
+ });
55
+ }
56
+ const arg0 = this.arg0;
57
+ if (!arg0) {
58
+ this.noArgsMulti();
59
+ return;
60
+ }
61
+ // run across workspaces
62
+ let failed = false;
63
+ const resultMap = await m.run(async (ws) => {
64
+ if (!failed)
65
+ stderr(`${ws.path} ${arg0}`);
66
+ const result = await this.bg(this.bgArg(ws)).catch((er) => {
67
+ if (isErrorRoot(er) && isRunResult(er.cause)) {
68
+ this.printResult(ws, er.cause);
69
+ }
70
+ failed = true;
71
+ throw er;
72
+ });
73
+ if (!failed)
74
+ this.printResult(ws, result);
75
+ return result;
76
+ });
77
+ const results = {};
78
+ for (const [ws, result] of resultMap) {
79
+ if (result.status === 0 && result.signal === null) {
80
+ result.stdout = '';
81
+ result.stderr = '';
82
+ }
83
+ results[ws.path] = result;
84
+ }
85
+ return results;
86
+ }
87
+ printResult(ws, result) {
88
+ if (result.status === 0 && result.signal === null) {
89
+ stdout(ws.path, 'ok');
90
+ }
91
+ else {
92
+ stdout(chalk.bgWhiteBright.black.bold(ws.path + ' failure'), {
93
+ status: result.status,
94
+ signal: result.signal,
95
+ });
96
+ /* c8 ignore start */
97
+ if (result.stderr)
98
+ stderr(ansiToAnsi(result.stderr));
99
+ if (result.stdout)
100
+ stdout(ansiToAnsi(result.stdout));
101
+ /* c8 ignore stop */
102
+ this.setExitCode(result);
103
+ }
104
+ }
105
+ setExitCode(result) {
106
+ /* c8 ignore next */
107
+ process.exitCode = process.exitCode || (result.status ?? 1);
108
+ }
109
+ /* c8 ignore start - env specific */
110
+ interactiveShell() {
111
+ return (process.env.SHELL ??
112
+ this.conf.get('script-shell') ??
113
+ (process.platform === 'win32' ? 'cmd.exe' : '/bin/sh'));
114
+ }
115
+ /* c8 ignore stop */
116
+ // overridden by 'vlt run' to print options and return undefined
117
+ defaultArg0() {
118
+ return this.interactiveShell();
119
+ }
120
+ fgArg() {
121
+ const ws = this.monorepo?.values().next().value;
122
+ const cwd = ws?.fullpath ?? this.projectRoot;
123
+ const arg0 = this.arg0 ?? this.defaultArg0();
124
+ if (!arg0) {
125
+ return undefined;
126
+ }
127
+ return {
128
+ cwd,
129
+ /* c8 ignore next - already guarded */
130
+ arg0,
131
+ args: this.args,
132
+ projectRoot: this.projectRoot,
133
+ packageJson: this.monorepo?.packageJson,
134
+ 'script-shell': this.arg0 ? this.conf.get('script-shell') : false,
135
+ };
136
+ }
137
+ /** If this returns undefined, then nothing to do */
138
+ bgArg(ws) {
139
+ /* c8 ignore start - already guarded */
140
+ if (!this.arg0)
141
+ throw error('Cannot spawn interactive shells in multiple workspaces');
142
+ /* c8 ignore stop */
143
+ return {
144
+ cwd: ws.fullpath,
145
+ acceptFail: !this.conf.get('bail'),
146
+ ignoreMissing: true,
147
+ arg0: this.arg0,
148
+ args: this.args,
149
+ projectRoot: this.projectRoot,
150
+ packageJson: this.monorepo?.packageJson,
151
+ 'script-shell': this.conf.get('script-shell'),
152
+ };
153
+ }
154
+ // overridden in `vlt run` to print available scripts
155
+ noArgsMulti() {
156
+ throw error('Cannot spawn interactive shells in multiple workspaces');
157
+ }
158
+ }
159
+ //# sourceMappingURL=exec-command.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exec-command.js","sourceRoot":"","sources":["../../src/exec-command.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,M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YACV,OAAO,SAAS,CAAA;QAClB,CAAC;QAED,OAAO;YACL,GAAG;YACH,sCAAsC;YACtC,IAAI;YACJ,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,WAAW,EAAE,IAAI,CAAC,WAAW;YAC7B,WAAW,EAAE,IAAI,CAAC,QAAQ,EAAE,WAAW;YACvC,cAAc,EACZ,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,KAAK;SACpD,CAAA;IACH,CAAC;IAED,oDAAoD;IACpD,KAAK,CAAC,EAAa;QACjB,uCAAuC;QACvC,IAAI,CAAC,IAAI,CAAC,IAAI;YACZ,MAAM,KAAK,CACT,wDAAwD,CACzD,CAAA;QACH,oBAAoB;QAEpB,OAAO;YACL,GAAG,EAAE,EAAE,CAAC,QAAQ;YAChB,UAAU,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC;YAClC,aAAa,EAAE,IAAI;YACnB,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,WAAW,EAAE,IAAI,CAAC,WAAW;YAC7B,WAAW,EAAE,IAAI,CAAC,QAAQ,EAAE,WAAW;YACvC,cAAc,EAAE,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,cAAc,CAAC;SAC9C,CAAA;IACH,CAAC;IAED,qDAAqD;IACrD,WAAW;QACT,MAAM,KAAK,CACT,wDAAwD,CACzD,CAAA;IACH,CAAC;CACF","sourcesContent":["/**\n * Implementation shared between `vlt run`, `vlt run-exec`, and `vlt exec`\n */\n\nimport { error, isErrorRoot } from '@vltpkg/error-cause'\nimport { isRunResult } from '@vltpkg/run'\nimport type {\n exec,\n execFG,\n ExecOptions,\n run,\n runExec,\n runExecFG,\n RunExecOptions,\n runFG,\n RunOptions,\n RunResult,\n} from '@vltpkg/run'\nimport { Monorepo } from '@vltpkg/workspaces'\nimport type { Workspace } from '@vltpkg/workspaces'\nimport { ansiToAnsi } from 'ansi-to-pre'\nimport chalk from 'chalk'\nimport type { LoadedConfig } from './config/index.ts'\nimport { stdout, stderr } from './output.ts'\nimport type { SpawnResultNoStdio } from '@vltpkg/promise-spawn'\n\nexport type RunnerBG = typeof exec | typeof run | typeof runExec\nexport type RunnerFG = typeof execFG | typeof runExecFG | typeof runFG\nexport type RunnerOptions = ExecOptions & RunExecOptions & RunOptions\nexport type ExecResult =\n | undefined\n | SpawnResultNoStdio\n | Record<string, RunResult>\n\nexport class ExecCommand<B extends RunnerBG, F extends RunnerFG> {\n bg: B\n fg: F\n arg0?: string\n args: string[]\n monorepo?: Monorepo\n /** how many places are we doing things in? */\n spaces: number\n conf: LoadedConfig\n projectRoot: string\n\n constructor(conf: LoadedConfig, bg: B, fg: F) {\n this.conf = conf\n this.bg = bg\n this.fg = fg\n const {\n projectRoot,\n positionals: [arg0, ...args],\n } = conf\n this.arg0 = arg0\n this.args = args\n\n const paths = conf.get('workspace')\n const groups = conf.get('workspace-group')\n const recursive = conf.get('recursive')\n this.monorepo =\n paths?.length || groups?.length || recursive ?\n Monorepo.load(projectRoot, { load: { paths, groups } })\n : undefined\n this.spaces = this.monorepo?.size ?? 1\n this.projectRoot = projectRoot\n }\n\n async run(): Promise<ExecResult> {\n if (this.spaces === 1) {\n const arg = this.fgArg()\n if (!arg) return\n const result = await this.fg(arg)\n stdout(result)\n if (isRunResult(result)) {\n this.setExitCode(result)\n }\n return result\n }\n const m = this.monorepo\n if (!m || this.spaces === 0) {\n throw error('no matching workspaces found', {\n /* c8 ignore next - already guarded */\n validOptions: [...(this.monorepo?.load().paths() ?? [])],\n })\n }\n const arg0 = this.arg0\n if (!arg0) {\n this.noArgsMulti()\n return\n }\n // run across workspaces\n let failed = false\n const resultMap = await m.run(async ws => {\n if (!failed) stderr(`${ws.path} ${arg0}`)\n const result = await this.bg(this.bgArg(ws)).catch(\n (er: unknown) => {\n if (isErrorRoot(er) && isRunResult(er.cause)) {\n this.printResult(ws, er.cause)\n }\n failed = true\n throw er\n },\n )\n if (!failed) this.printResult(ws, result)\n return result\n })\n\n const results: Record<string, RunResult> = {}\n for (const [ws, result] of resultMap) {\n if (result.status === 0 && result.signal === null) {\n result.stdout = ''\n result.stderr = ''\n }\n results[ws.path] = result\n }\n return results\n }\n\n printResult(ws: Workspace, result: RunResult) {\n if (result.status === 0 && result.signal === null) {\n stdout(ws.path, 'ok')\n } else {\n stdout(chalk.bgWhiteBright.black.bold(ws.path + ' failure'), {\n status: result.status,\n signal: result.signal,\n })\n /* c8 ignore start */\n if (result.stderr) stderr(ansiToAnsi(result.stderr))\n if (result.stdout) stdout(ansiToAnsi(result.stdout))\n /* c8 ignore stop */\n this.setExitCode(result)\n }\n }\n\n setExitCode(result: RunResult) {\n /* c8 ignore next */\n process.exitCode = process.exitCode || (result.status ?? 1)\n }\n\n /* c8 ignore start - env specific */\n interactiveShell(): string {\n return (\n process.env.SHELL ??\n this.conf.get('script-shell') ??\n (process.platform === 'win32' ? 'cmd.exe' : '/bin/sh')\n )\n }\n /* c8 ignore stop */\n\n // overridden by 'vlt run' to print options and return undefined\n defaultArg0(): string | undefined {\n return this.interactiveShell()\n }\n\n fgArg(): RunnerOptions | undefined {\n const ws = this.monorepo?.values().next().value\n const cwd = ws?.fullpath ?? this.projectRoot\n const arg0 = this.arg0 ?? this.defaultArg0()\n if (!arg0) {\n return undefined\n }\n\n return {\n cwd,\n /* c8 ignore next - already guarded */\n arg0,\n args: this.args,\n projectRoot: this.projectRoot,\n packageJson: this.monorepo?.packageJson,\n 'script-shell':\n this.arg0 ? this.conf.get('script-shell') : false,\n }\n }\n\n /** If this returns undefined, then nothing to do */\n bgArg(ws: Workspace): RunnerOptions {\n /* c8 ignore start - already guarded */\n if (!this.arg0)\n throw error(\n 'Cannot spawn interactive shells in multiple workspaces',\n )\n /* c8 ignore stop */\n\n return {\n cwd: ws.fullpath,\n acceptFail: !this.conf.get('bail'),\n ignoreMissing: true,\n arg0: this.arg0,\n args: this.args,\n projectRoot: this.projectRoot,\n packageJson: this.monorepo?.packageJson,\n 'script-shell': this.conf.get('script-shell'),\n }\n }\n\n // overridden in `vlt run` to print available scripts\n noArgsMulti() {\n throw error(\n 'Cannot spawn interactive shells in multiple workspaces',\n )\n }\n}\n"]}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * A list of folder names that are ignored when reading the user's home dir.
3
+ *
4
+ * Note: these are lower-case, must be compared case-insensitively.
5
+ */
6
+ export declare const ignoredHomedirFolderNames: string[];
7
+ //# sourceMappingURL=ignored-homedir-folder-names.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ignored-homedir-folder-names.d.ts","sourceRoot":"","sources":["../../src/ignored-homedir-folder-names.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,eAAO,MAAM,yBAAyB,UA8BrC,CAAA"}
@@ -0,0 +1,35 @@
1
+ /**
2
+ * A list of folder names that are ignored when reading the user's home dir.
3
+ *
4
+ * Note: these are lower-case, must be compared case-insensitively.
5
+ */
6
+ export const ignoredHomedirFolderNames = [
7
+ 'downloads',
8
+ 'movies',
9
+ 'music',
10
+ 'pictures',
11
+ 'private',
12
+ 'library',
13
+ 'desktop',
14
+ 'dropbox',
15
+ ].concat(process.platform === 'darwin' ?
16
+ [
17
+ 'public',
18
+ 'private',
19
+ 'applications',
20
+ 'applications (parallels)',
21
+ 'sites',
22
+ 'sync',
23
+ ]
24
+ : process.platform === 'win32' ?
25
+ [
26
+ 'appdata',
27
+ 'application data',
28
+ 'favorites',
29
+ 'links',
30
+ 'videos',
31
+ 'contacts',
32
+ 'searches',
33
+ ]
34
+ : ['videos', 'public']);
35
+ //# sourceMappingURL=ignored-homedir-folder-names.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ignored-homedir-folder-names.js","sourceRoot":"","sources":["../../src/ignored-homedir-folder-names.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG;IACvC,WAAW;IACX,QAAQ;IACR,OAAO;IACP,UAAU;IACV,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;CACV,CAAC,MAAM,CACN,OAAO,CAAC,QAAQ,KAAK,QAAQ,CAAC,CAAC;IAC7B;QACE,QAAQ;QACR,SAAS;QACT,cAAc;QACd,0BAA0B;QAC1B,OAAO;QACP,MAAM;KACP;IACH,CAAC,CAAC,OAAO,CAAC,QAAQ,KAAK,OAAO,CAAC,CAAC;QAC9B;YACE,SAAS;YACT,kBAAkB;YAClB,WAAW;YACX,OAAO;YACP,QAAQ;YACR,UAAU;YACV,UAAU;SACX;QACH,CAAC,CAAC,CAAC,QAAQ,EAAE,QAAQ,CAAC,CACvB,CAAA","sourcesContent":["/**\n * A list of folder names that are ignored when reading the user's home dir.\n *\n * Note: these are lower-case, must be compared case-insensitively.\n */\nexport const ignoredHomedirFolderNames = [\n 'downloads',\n 'movies',\n 'music',\n 'pictures',\n 'private',\n 'library',\n 'desktop',\n 'dropbox',\n].concat(\n process.platform === 'darwin' ?\n [\n 'public',\n 'private',\n 'applications',\n 'applications (parallels)',\n 'sites',\n 'sync',\n ]\n : process.platform === 'win32' ?\n [\n 'appdata',\n 'application data',\n 'favorites',\n 'links',\n 'videos',\n 'contacts',\n 'searches',\n ]\n : ['videos', 'public'],\n)\n"]}
@@ -0,0 +1,17 @@
1
+ import type { Jack } from 'jackspeak';
2
+ import type { LoadedConfig } from './config/index.ts';
3
+ import type { Views } from './view.ts';
4
+ export type CommandUsage = () => Jack;
5
+ /**
6
+ * A command function that may return a result of `T`.
7
+ * If the result is `undefined`, no final output will be displayed by default.
8
+ */
9
+ export type CommandFn<T = unknown> = (conf: LoadedConfig) => Promise<T>;
10
+ export type Command<T> = {
11
+ command: CommandFn<T>;
12
+ usage: CommandUsage;
13
+ views: Views<T>;
14
+ };
15
+ declare const run: () => Promise<void>;
16
+ export default run;
17
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAGrC,OAAO,KAAK,EAAE,YAAY,EAAY,MAAM,mBAAmB,CAAA;AAE/D,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,WAAW,CAAA;AAEtC,MAAM,MAAM,YAAY,GAAG,MAAM,IAAI,CAAA;AAErC;;;GAGG;AACH,MAAM,MAAM,SAAS,CAAC,CAAC,GAAG,OAAO,IAAI,CACnC,IAAI,EAAE,YAAY,KACf,OAAO,CAAC,CAAC,CAAC,CAAA;AAEf,MAAM,MAAM,OAAO,CAAC,CAAC,IAAI;IACvB,OAAO,EAAE,SAAS,CAAC,CAAC,CAAC,CAAA;IACrB,KAAK,EAAE,YAAY,CAAA;IACnB,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,CAAA;CAChB,CAAA;AAwBD,QAAA,MAAM,GAAG,qBAsBR,CAAA;AAED,eAAe,GAAG,CAAA"}
@@ -0,0 +1,47 @@
1
+ var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) {
2
+ if (typeof path === "string" && /^\.\.?\//.test(path)) {
3
+ return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
4
+ return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js");
5
+ });
6
+ }
7
+ return path;
8
+ };
9
+ import { error } from '@vltpkg/error-cause';
10
+ import { loadPackageJson } from 'package-json-from-dist';
11
+ import { Config } from "./config/index.js";
12
+ import { outputCommand, stdout } from "./output.js";
13
+ const { version } = loadPackageJson(import.meta.filename, process.env.__VLT_INTERNAL_CLI_PACKAGE_JSON);
14
+ const loadCommand = async (command) => {
15
+ try {
16
+ return (await import(__rewriteRelativeImportExtension(`./commands/${command}.ts`)));
17
+ /* c8 ignore start - should not be possible, just a failsafe */
18
+ }
19
+ catch (e) {
20
+ throw error('Could not load command', {
21
+ found: command,
22
+ cause: e,
23
+ });
24
+ }
25
+ /* c8 ignore stop */
26
+ };
27
+ const run = async () => {
28
+ const start = Date.now();
29
+ const vlt = await Config.load(process.cwd(), process.argv);
30
+ if (vlt.get('version')) {
31
+ return stdout(version);
32
+ }
33
+ const cwd = process.cwd();
34
+ const { monorepo } = vlt.options;
35
+ // Infer the workspace by being in that directory.
36
+ if (vlt.get('workspace') === undefined) {
37
+ const ws = monorepo?.get(cwd);
38
+ if (ws) {
39
+ vlt.values.workspace = [ws.path];
40
+ vlt.options.workspace = [ws.path];
41
+ }
42
+ }
43
+ const command = await loadCommand(vlt.command);
44
+ await outputCommand(command, vlt, { start });
45
+ };
46
+ export default run;
47
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAE3C,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AACxD,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAE1C,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAmBnD,MAAM,EAAE,OAAO,EAAE,GAAG,eAAe,CACjC,MAAM,CAAC,IAAI,CAAC,QAAQ,EACpB,OAAO,CAAC,GAAG,CAAC,+BAA+B,CAG5C,CAAA;AAED,MAAM,WAAW,GAAG,KAAK,EACvB,OAA6C,EACxB,EAAE;IACvB,IAAI,CAAC;QACH,OAAO,CAAC,MAAM,MAAM,kCAAC,cAAc,OAAO,KAAK,EAAC,CAAe,CAAA;QAC/D,+DAA+D;IACjE,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,MAAM,KAAK,CAAC,wBAAwB,EAAE;YACpC,KAAK,EAAE,OAAO;YACd,KAAK,EAAE,CAAC;SACT,CAAC,CAAA;IACJ,CAAC;IACD,oBAAoB;AACtB,CAAC,CAAA;AAED,MAAM,GAAG,GAAG,KAAK,IAAI,EAAE;IACrB,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;IACxB,MAAM,GAAG,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,OAAO,CAAC,IAAI,CAAC,CAAA;IAE1D,IAAI,GAAG,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE,CAAC;QACvB,OAAO,MAAM,CAAC,OAAO,CAAC,CAAA;IACxB,CAAC;IAED,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,EAAE,CAAA;IACzB,MAAM,EAAE,QAAQ,EAAE,GAAG,GAAG,CAAC,OAAO,CAAA;IAEhC,kDAAkD;IAClD,IAAI,GAAG,CAAC,GAAG,CAAC,WAAW,CAAC,KAAK,SAAS,EAAE,CAAC;QACvC,MAAM,EAAE,GAAG,QAAQ,EAAE,GAAG,CAAC,GAAG,CAAC,CAAA;QAC7B,IAAI,EAAE,EAAE,CAAC;YACP,GAAG,CAAC,MAAM,CAAC,SAAS,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,CAAA;YAChC,GAAG,CAAC,OAAO,CAAC,SAAS,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,CAAA;QACnC,CAAC;IACH,CAAC;IAED,MAAM,OAAO,GAAG,MAAM,WAAW,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;IAC9C,MAAM,aAAa,CAAC,OAAO,EAAE,GAAG,EAAE,EAAE,KAAK,EAAE,CAAC,CAAA;AAC9C,CAAC,CAAA;AAED,eAAe,GAAG,CAAA","sourcesContent":["import { error } from '@vltpkg/error-cause'\nimport type { Jack } from 'jackspeak'\nimport { loadPackageJson } from 'package-json-from-dist'\nimport { Config } from './config/index.ts'\nimport type { LoadedConfig, Commands } from './config/index.ts'\nimport { outputCommand, stdout } from './output.ts'\nimport type { Views } from './view.ts'\n\nexport type CommandUsage = () => Jack\n\n/**\n * A command function that may return a result of `T`.\n * If the result is `undefined`, no final output will be displayed by default.\n */\nexport type CommandFn<T = unknown> = (\n conf: LoadedConfig,\n) => Promise<T>\n\nexport type Command<T> = {\n command: CommandFn<T>\n usage: CommandUsage\n views: Views<T>\n}\n\nconst { version } = loadPackageJson(\n import.meta.filename,\n process.env.__VLT_INTERNAL_CLI_PACKAGE_JSON,\n) as {\n version: string\n}\n\nconst loadCommand = async <T>(\n command: Commands[keyof Commands] | undefined,\n): Promise<Command<T>> => {\n try {\n return (await import(`./commands/${command}.ts`)) as Command<T>\n /* c8 ignore start - should not be possible, just a failsafe */\n } catch (e) {\n throw error('Could not load command', {\n found: command,\n cause: e,\n })\n }\n /* c8 ignore stop */\n}\n\nconst run = async () => {\n const start = Date.now()\n const vlt = await Config.load(process.cwd(), process.argv)\n\n if (vlt.get('version')) {\n return stdout(version)\n }\n\n const cwd = process.cwd()\n const { monorepo } = vlt.options\n\n // Infer the workspace by being in that directory.\n if (vlt.get('workspace') === undefined) {\n const ws = monorepo?.get(cwd)\n if (ws) {\n vlt.values.workspace = [ws.path]\n vlt.options.workspace = [ws.path]\n }\n }\n\n const command = await loadCommand(vlt.command)\n await outputCommand(command, vlt, { start })\n}\n\nexport default run\n"]}
@@ -0,0 +1,25 @@
1
+ import type { LoadedConfig } from './config/index.ts';
2
+ import type { Command } from './index.ts';
3
+ import type { View, Views } from './view.ts';
4
+ export declare const stdout: (...args: unknown[]) => void;
5
+ export declare const stderr: (...args: unknown[]) => void;
6
+ export declare const getView: <T>(conf: LoadedConfig, views?: Views<T>) => View<T>;
7
+ /**
8
+ * If the view is a View class, then instantiate and start it.
9
+ * If it's a view function, then just define the onDone method.
10
+ */
11
+ export declare const startView: <T>(conf: LoadedConfig, views?: Views<T>, { start }?: {
12
+ start: number;
13
+ }) => {
14
+ onDone: (result: T) => Promise<string | undefined> | string | undefined;
15
+ onError?: (err: unknown) => void;
16
+ };
17
+ /**
18
+ * Main export. Run the command appropriately, displaying output using
19
+ * the user-requested view, or the default if the user requested a view
20
+ * that is not defined for this command.
21
+ */
22
+ export declare const outputCommand: <T>(cliCommand: Command<T>, conf: LoadedConfig, { start }?: {
23
+ start: number;
24
+ }) => Promise<void>;
25
+ //# sourceMappingURL=output.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"output.d.ts","sourceRoot":"","sources":["../../src/output.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AACrD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AAGzC,OAAO,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,WAAW,CAAA;AAI5C,eAAO,MAAM,MAAM,YAAa,OAAO,EAAE,SAAyB,CAAA;AAElE,eAAO,MAAM,MAAM,YAAa,OAAO,EAAE,SAA2B,CAAA;AAGpE,eAAO,MAAM,OAAO,GAAI,CAAC,QACjB,YAAY,UACV,KAAK,CAAC,CAAC,CAAC,KACf,IAAI,CAAC,CAAC,CAmBR,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,SAAS,GAAI,CAAC,QACnB,YAAY,UACV,KAAK,CAAC,CAAC,CAAC,cACL;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,KAC3B;IACD,MAAM,EAAE,CACN,MAAM,EAAE,CAAC,KACN,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,GAAG,MAAM,GAAG,SAAS,CAAA;IACrD,OAAO,CAAC,EAAE,CAAC,GAAG,EAAE,OAAO,KAAK,IAAI,CAAA;CA+BjC,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,aAAa,GAAU,CAAC,cACvB,OAAO,CAAC,CAAC,CAAC,QAChB,YAAY,cACP;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,kBAqB7B,CAAA"}
@@ -0,0 +1,86 @@
1
+ import chalk from 'chalk';
2
+ import { formatWithOptions } from 'node:util';
3
+ import { defaultView } from "./config/definition.js";
4
+ import { printErr } from "./print-err.js";
5
+ import { isViewClass } from "./view.js";
6
+ // TODO: make these have log levels etc
7
+ // eslint-disable-next-line no-console
8
+ export const stdout = (...args) => console.log(...args);
9
+ // eslint-disable-next-line no-console
10
+ export const stderr = (...args) => console.error(...args);
11
+ const identity = (x) => x;
12
+ export const getView = (conf, views) => {
13
+ const viewName = conf.values.view;
14
+ const viewFn = viewName === 'inspect' ? identity
15
+ : typeof views === 'function' ? views
16
+ : views && typeof views === 'object' ? views[viewName]
17
+ : identity;
18
+ // if the user specified a view that doesn't exist,
19
+ // then set it back to the default, and try again.
20
+ // This will fall back to identity if it's also missing.
21
+ if (!viewFn && conf.values.view !== defaultView) {
22
+ conf.values.view = defaultView;
23
+ process.env.VLT_VIEW = defaultView;
24
+ return getView(conf, views);
25
+ }
26
+ return viewFn ?? identity;
27
+ };
28
+ /**
29
+ * If the view is a View class, then instantiate and start it.
30
+ * If it's a view function, then just define the onDone method.
31
+ */
32
+ export const startView = (conf, views, { start } = { start: Date.now() }) => {
33
+ const View = getView(conf, views);
34
+ const opts = { colors: conf.values.color ? chalk : undefined };
35
+ if (isViewClass(View)) {
36
+ const view = new View(opts, conf);
37
+ view.start();
38
+ return {
39
+ onDone(r) {
40
+ return view.done(r, { time: Date.now() - start });
41
+ },
42
+ onError(err) {
43
+ view.error(err);
44
+ },
45
+ };
46
+ }
47
+ else {
48
+ return {
49
+ async onDone(r) {
50
+ if (r === undefined && r !== null)
51
+ return;
52
+ const res = await View(r, opts, conf);
53
+ return conf.values.view === 'json' ?
54
+ JSON.stringify(res, null, 2)
55
+ : formatWithOptions({
56
+ colors: conf.values.color,
57
+ }, res);
58
+ },
59
+ };
60
+ }
61
+ };
62
+ /**
63
+ * Main export. Run the command appropriately, displaying output using
64
+ * the user-requested view, or the default if the user requested a view
65
+ * that is not defined for this command.
66
+ */
67
+ export const outputCommand = async (cliCommand, conf, { start } = { start: Date.now() }) => {
68
+ const { usage, views, command } = cliCommand;
69
+ if (conf.get('help')) {
70
+ return stdout(usage().usage());
71
+ }
72
+ const { onDone, onError } = startView(conf, views, { start });
73
+ try {
74
+ const output = await onDone(await command(conf));
75
+ if (output !== undefined) {
76
+ stdout(output);
77
+ }
78
+ }
79
+ catch (err) {
80
+ onError?.(err);
81
+ process.exitCode ||= 1;
82
+ printErr(err, usage, stderr);
83
+ process.exit(process.exitCode);
84
+ }
85
+ };
86
+ //# sourceMappingURL=output.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"output.js","sourceRoot":"","sources":["../../src/output.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAA;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAA;AAGpD,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAA;AAGvC,uCAAuC;AACvC,sCAAsC;AACtC,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,GAAG,IAAe,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,CAAA;AAClE,sCAAsC;AACtC,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,GAAG,IAAe,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,CAAA;AAEpE,MAAM,QAAQ,GAAG,CAAI,CAAI,EAAK,EAAE,CAAC,CAAC,CAAA;AAClC,MAAM,CAAC,MAAM,OAAO,GAAG,CACrB,IAAkB,EAClB,KAAgB,EACP,EAAE;IACX,MAAM,QAAQ,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,CAAA;IAEjC,MAAM,MAAM,GACV,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,QAAQ;QACjC,CAAC,CAAC,OAAO,KAAK,KAAK,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AM,CAAC,MAAM,CAAC,CAAA;QAChB,CAAC;IACH,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,OAAO,EAAE,CAAC,GAAG,CAAC,CAAA;QACd,OAAO,CAAC,QAAQ,KAAK,CAAC,CAAA;QAEtB,QAAQ,CAAC,GAAG,EAAE,KAAK,EAAE,MAAM,CAAC,CAAA;QAE5B,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAA;IAChC,CAAC;AACH,CAAC,CAAA","sourcesContent":["import chalk from 'chalk'\nimport { formatWithOptions } from 'node:util'\nimport { defaultView } from './config/definition.ts'\nimport type { LoadedConfig } from './config/index.ts'\nimport type { Command } from './index.ts'\nimport { printErr } from './print-err.ts'\nimport { isViewClass } from './view.ts'\nimport type { View, Views } from './view.ts'\n\n// TODO: make these have log levels etc\n// eslint-disable-next-line no-console\nexport const stdout = (...args: unknown[]) => console.log(...args)\n// eslint-disable-next-line no-console\nexport const stderr = (...args: unknown[]) => console.error(...args)\n\nconst identity = <T>(x: T): T => x\nexport const getView = <T>(\n conf: LoadedConfig,\n views?: Views<T>,\n): View<T> => {\n const viewName = conf.values.view\n\n const viewFn =\n viewName === 'inspect' ? identity\n : typeof views === 'function' ? views\n : views && typeof views === 'object' ? views[viewName]\n : identity\n\n // if the user specified a view that doesn't exist,\n // then set it back to the default, and try again.\n // This will fall back to identity if it's also missing.\n if (!viewFn && conf.values.view !== defaultView) {\n conf.values.view = defaultView\n process.env.VLT_VIEW = defaultView\n return getView(conf, views)\n }\n\n return viewFn ?? identity\n}\n\n/**\n * If the view is a View class, then instantiate and start it.\n * If it's a view function, then just define the onDone method.\n */\nexport const startView = <T>(\n conf: LoadedConfig,\n views?: Views<T>,\n { start }: { start: number } = { start: Date.now() },\n): {\n onDone: (\n result: T,\n ) => Promise<string | undefined> | string | undefined\n onError?: (err: unknown) => void\n} => {\n const View = getView<T>(conf, views)\n const opts = { colors: conf.values.color ? chalk : undefined }\n if (isViewClass(View)) {\n const view = new View(opts, conf)\n view.start()\n return {\n onDone(r) {\n return view.done(r, { time: Date.now() - start })\n },\n onError(err) {\n view.error(err)\n },\n }\n } else {\n return {\n async onDone(r): Promise<string | undefined> {\n if (r === undefined && r !== null) return\n const res = await View(r, opts, conf)\n return conf.values.view === 'json' ?\n JSON.stringify(res, null, 2)\n : formatWithOptions(\n {\n colors: conf.values.color,\n },\n res,\n )\n },\n }\n }\n}\n\n/**\n * Main export. Run the command appropriately, displaying output using\n * the user-requested view, or the default if the user requested a view\n * that is not defined for this command.\n */\nexport const outputCommand = async <T>(\n cliCommand: Command<T>,\n conf: LoadedConfig,\n { start }: { start: number } = { start: Date.now() },\n) => {\n const { usage, views, command } = cliCommand\n if (conf.get('help')) {\n return stdout(usage().usage())\n }\n const { onDone, onError } = startView(conf, views, { start })\n\n try {\n const output = await onDone(await command(conf))\n if (output !== undefined) {\n stdout(output)\n }\n } catch (err) {\n onError?.(err)\n process.exitCode ||= 1\n\n printErr(err, usage, stderr)\n\n process.exit(process.exitCode)\n }\n}\n"]}
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "module"
3
+ }
@@ -0,0 +1,22 @@
1
+ import type { AddImportersDependenciesMap, RemoveImportersDependenciesMap } from '@vltpkg/graph';
2
+ import type { LoadedConfig } from './config/index.ts';
3
+ import type { Monorepo } from '@vltpkg/workspaces';
4
+ export type ParsedAddArgs = {
5
+ add: AddImportersDependenciesMap;
6
+ };
7
+ export type ParsedRemoveArgs = {
8
+ remove: RemoveImportersDependenciesMap;
9
+ };
10
+ export type SaveTypes = {
11
+ 'save-dev'?: boolean;
12
+ 'save-optional'?: boolean;
13
+ 'save-peer'?: boolean;
14
+ 'save-prod'?: boolean;
15
+ };
16
+ export type WorkspaceTypes = {
17
+ workspace?: string[];
18
+ 'workspace-group'?: string[];
19
+ };
20
+ export declare const parseAddArgs: (config: LoadedConfig, monorepo?: Monorepo) => ParsedAddArgs;
21
+ export declare const parseRemoveArgs: (config: LoadedConfig, monorepo?: Monorepo) => ParsedRemoveArgs;
22
+ //# sourceMappingURL=parse-add-remove-args.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parse-add-remove-args.d.ts","sourceRoot":"","sources":["../../src/parse-add-remove-args.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,2BAA2B,EAE3B,8BAA8B,EAC/B,MAAM,eAAe,CAAA;AACtB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAGrD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAA;AAElD,MAAM,MAAM,aAAa,GAAG;IAC1B,GAAG,EAAE,2BAA2B,CAAA;CACjC,CAAA;AAED,MAAM,MAAM,gBAAgB,GAAG;IAC7B,MAAM,EAAE,8BAA8B,CAAA;CACvC,CAAA;AAED,MAAM,MAAM,SAAS,GAAG;IACtB,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,eAAe,CAAC,EAAE,OAAO,CAAA;IACzB,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB,WAAW,CAAC,EAAE,OAAO,CAAA;CACtB,CAAA;AAED,MAAM,MAAM,cAAc,GAAG;IAC3B,SAAS,CAAC,EAAE,MAAM,EAAE,CAAA;IACpB,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAA;CAC7B,CAAA;AAqDD,eAAO,MAAM,YAAY,WACf,YAAY,aACT,QAAQ,KAClB,aA4BF,CAAA;AAED,eAAO,MAAM,eAAe,WAClB,YAAY,aACT,QAAQ,KAClB,gBAaF,CAAA"}
@@ -0,0 +1,71 @@
1
+ import { joinDepIDTuple } from '@vltpkg/dep-id';
2
+ import { asDependency } from '@vltpkg/graph';
3
+ import { Spec } from '@vltpkg/spec';
4
+ const rootDepID = joinDepIDTuple(['file', '.']);
5
+ /**
6
+ * Get the list of importers that are currently selected
7
+ * in {@link WorkspaceTypes}.
8
+ */
9
+ const getImporters = (opts, monorepo) => {
10
+ const res = new Set();
11
+ // collects DepID references to any selected workspace
12
+ if (monorepo) {
13
+ for (const ws of monorepo.filter(opts)) {
14
+ res.add(ws.id);
15
+ }
16
+ }
17
+ // if no references were found, default behavior is to point to project root
18
+ if (!res.size) {
19
+ res.add(rootDepID);
20
+ }
21
+ return res;
22
+ };
23
+ const getType = (opts) => opts['save-prod'] ? 'prod'
24
+ : opts['save-dev'] ? 'dev'
25
+ : opts['save-peer'] ?
26
+ opts['save-optional'] ?
27
+ 'peerOptional'
28
+ : 'peer'
29
+ : opts['save-optional'] ? 'optional'
30
+ : 'prod';
31
+ class AddImportersDependenciesMapImpl extends Map {
32
+ modifiedDependencies = false;
33
+ }
34
+ class RemoveImportersDependenciesMapImpl extends Map {
35
+ modifiedDependencies = false;
36
+ }
37
+ export const parseAddArgs = (config, monorepo) => {
38
+ const add = new AddImportersDependenciesMapImpl();
39
+ const items = config.positionals;
40
+ const type = getType(config.values);
41
+ const importers = getImporters(config.values, monorepo);
42
+ const newDependencies = new Map();
43
+ const specOptions = config.options;
44
+ // nameless spec definitions will need to use their full
45
+ // stringified spec result instead of their name in order
46
+ // to have an unique key name in the resulting Map
47
+ const getName = (s) => s.name === '(unknown)' ? s.spec : s.name;
48
+ for (const item of items) {
49
+ const spec = Spec.parseArgs(item, specOptions);
50
+ newDependencies.set(getName(spec), asDependency({ spec, type }));
51
+ add.modifiedDependencies = true;
52
+ }
53
+ for (const importer of importers) {
54
+ add.set(importer, newDependencies);
55
+ }
56
+ return {
57
+ add,
58
+ };
59
+ };
60
+ export const parseRemoveArgs = (config, monorepo) => {
61
+ const remove = new RemoveImportersDependenciesMapImpl();
62
+ const importers = getImporters(config.values, monorepo);
63
+ for (const importer of importers) {
64
+ remove.set(importer, new Set(config.positionals));
65
+ remove.modifiedDependencies = true;
66
+ }
67
+ return {
68
+ remove,
69
+ };
70
+ };
71
+ //# sourceMappingURL=parse-add-remove-args.js.map