@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.
Files changed (132) hide show
  1. package/LICENSE +15 -0
  2. package/README.md +23 -0
  3. package/dist/esm/commands/cache.d.ts +65 -0
  4. package/dist/esm/commands/cache.d.ts.map +1 -0
  5. package/dist/esm/commands/cache.js +256 -0
  6. package/dist/esm/commands/cache.js.map +1 -0
  7. package/dist/esm/commands/config.d.ts +5 -0
  8. package/dist/esm/commands/config.d.ts.map +1 -0
  9. package/dist/esm/commands/config.js +153 -0
  10. package/dist/esm/commands/config.js.map +1 -0
  11. package/dist/esm/commands/exec-cache.d.ts +49 -0
  12. package/dist/esm/commands/exec-cache.d.ts.map +1 -0
  13. package/dist/esm/commands/exec-cache.js +125 -0
  14. package/dist/esm/commands/exec-cache.js.map +1 -0
  15. package/dist/esm/commands/exec-local.d.ts +6 -0
  16. package/dist/esm/commands/exec-local.d.ts.map +1 -0
  17. package/dist/esm/commands/exec-local.js +24 -0
  18. package/dist/esm/commands/exec-local.js.map +1 -0
  19. package/dist/esm/commands/exec.d.ts +9 -0
  20. package/dist/esm/commands/exec.d.ts.map +1 -0
  21. package/dist/esm/commands/exec.js +78 -0
  22. package/dist/esm/commands/exec.js.map +1 -0
  23. package/dist/esm/commands/gui.d.ts +6 -0
  24. package/dist/esm/commands/gui.d.ts.map +1 -0
  25. package/dist/esm/commands/gui.js +13 -0
  26. package/dist/esm/commands/gui.js.map +1 -0
  27. package/dist/esm/commands/help.d.ts +4 -0
  28. package/dist/esm/commands/help.d.ts.map +1 -0
  29. package/dist/esm/commands/help.js +10 -0
  30. package/dist/esm/commands/help.js.map +1 -0
  31. package/dist/esm/commands/init.d.ts +8 -0
  32. package/dist/esm/commands/init.d.ts.map +1 -0
  33. package/dist/esm/commands/init.js +25 -0
  34. package/dist/esm/commands/init.js.map +1 -0
  35. package/dist/esm/commands/install/reporter.d.ts +10 -0
  36. package/dist/esm/commands/install/reporter.d.ts.map +1 -0
  37. package/dist/esm/commands/install/reporter.js +67 -0
  38. package/dist/esm/commands/install/reporter.js.map +1 -0
  39. package/dist/esm/commands/install.d.ts +10 -0
  40. package/dist/esm/commands/install.d.ts.map +1 -0
  41. package/dist/esm/commands/install.js +21 -0
  42. package/dist/esm/commands/install.js.map +1 -0
  43. package/dist/esm/commands/list.d.ts +15 -0
  44. package/dist/esm/commands/list.d.ts.map +1 -0
  45. package/dist/esm/commands/list.js +109 -0
  46. package/dist/esm/commands/list.js.map +1 -0
  47. package/dist/esm/commands/login.d.ts +4 -0
  48. package/dist/esm/commands/login.d.ts.map +1 -0
  49. package/dist/esm/commands/login.js +13 -0
  50. package/dist/esm/commands/login.js.map +1 -0
  51. package/dist/esm/commands/logout.d.ts +4 -0
  52. package/dist/esm/commands/logout.d.ts.map +1 -0
  53. package/dist/esm/commands/logout.js +13 -0
  54. package/dist/esm/commands/logout.js.map +1 -0
  55. package/dist/esm/commands/pkg.d.ts +7 -0
  56. package/dist/esm/commands/pkg.d.ts.map +1 -0
  57. package/dist/esm/commands/pkg.js +123 -0
  58. package/dist/esm/commands/pkg.js.map +1 -0
  59. package/dist/esm/commands/query.d.ts +16 -0
  60. package/dist/esm/commands/query.d.ts.map +1 -0
  61. package/dist/esm/commands/query.js +124 -0
  62. package/dist/esm/commands/query.js.map +1 -0
  63. package/dist/esm/commands/run-exec.d.ts +6 -0
  64. package/dist/esm/commands/run-exec.d.ts.map +1 -0
  65. package/dist/esm/commands/run-exec.js +14 -0
  66. package/dist/esm/commands/run-exec.js.map +1 -0
  67. package/dist/esm/commands/run.d.ts +6 -0
  68. package/dist/esm/commands/run.d.ts.map +1 -0
  69. package/dist/esm/commands/run.js +37 -0
  70. package/dist/esm/commands/run.js.map +1 -0
  71. package/dist/esm/commands/token.d.ts +4 -0
  72. package/dist/esm/commands/token.d.ts.map +1 -0
  73. package/dist/esm/commands/token.js +30 -0
  74. package/dist/esm/commands/token.js.map +1 -0
  75. package/dist/esm/commands/uninstall.d.ts +10 -0
  76. package/dist/esm/commands/uninstall.d.ts.map +1 -0
  77. package/dist/esm/commands/uninstall.js +21 -0
  78. package/dist/esm/commands/uninstall.js.map +1 -0
  79. package/dist/esm/commands/whoami.d.ts +13 -0
  80. package/dist/esm/commands/whoami.d.ts.map +1 -0
  81. package/dist/esm/commands/whoami.js +19 -0
  82. package/dist/esm/commands/whoami.js.map +1 -0
  83. package/dist/esm/config/definition.d.ts +306 -0
  84. package/dist/esm/config/definition.d.ts.map +1 -0
  85. package/dist/esm/config/definition.js +517 -0
  86. package/dist/esm/config/definition.js.map +1 -0
  87. package/dist/esm/config/index.d.ts +206 -0
  88. package/dist/esm/config/index.d.ts.map +1 -0
  89. package/dist/esm/config/index.js +489 -0
  90. package/dist/esm/config/index.js.map +1 -0
  91. package/dist/esm/config/merge.d.ts +2 -0
  92. package/dist/esm/config/merge.d.ts.map +1 -0
  93. package/dist/esm/config/merge.js +23 -0
  94. package/dist/esm/config/merge.js.map +1 -0
  95. package/dist/esm/config/usage.d.ts +19 -0
  96. package/dist/esm/config/usage.d.ts.map +1 -0
  97. package/dist/esm/config/usage.js +40 -0
  98. package/dist/esm/config/usage.js.map +1 -0
  99. package/dist/esm/exec-command.d.ts +51 -0
  100. package/dist/esm/exec-command.d.ts.map +1 -0
  101. package/dist/esm/exec-command.js +199 -0
  102. package/dist/esm/exec-command.js.map +1 -0
  103. package/dist/esm/index.d.ts +17 -0
  104. package/dist/esm/index.d.ts.map +1 -0
  105. package/dist/esm/index.js +47 -0
  106. package/dist/esm/index.js.map +1 -0
  107. package/dist/esm/output.d.ts +21 -0
  108. package/dist/esm/output.d.ts.map +1 -0
  109. package/dist/esm/output.js +121 -0
  110. package/dist/esm/output.js.map +1 -0
  111. package/dist/esm/package.json +3 -0
  112. package/dist/esm/parse-add-remove-args.d.ts +22 -0
  113. package/dist/esm/parse-add-remove-args.d.ts.map +1 -0
  114. package/dist/esm/parse-add-remove-args.js +71 -0
  115. package/dist/esm/parse-add-remove-args.js.map +1 -0
  116. package/dist/esm/print-err.d.ts +7 -0
  117. package/dist/esm/print-err.d.ts.map +1 -0
  118. package/dist/esm/print-err.js +115 -0
  119. package/dist/esm/print-err.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/start-gui.d.ts +9 -0
  125. package/dist/esm/start-gui.d.ts.map +1 -0
  126. package/dist/esm/start-gui.js +40 -0
  127. package/dist/esm/start-gui.js.map +1 -0
  128. package/dist/esm/view.d.ts +30 -0
  129. package/dist/esm/view.d.ts.map +1 -0
  130. package/dist/esm/view.js +31 -0
  131. package/dist/esm/view.js.map +1 -0
  132. package/package.json +125 -0
@@ -0,0 +1,121 @@
1
+ import { formatWithOptions, styleText as utilStyleText, } from 'node:util';
2
+ import { createSupportsColor } from 'supports-color';
3
+ import { defaultView } from "./config/definition.js";
4
+ import { printErr } from "./print-err.js";
5
+ import { isViewClass } from "./view.js";
6
+ const supportsColor = (stream) => {
7
+ const res = createSupportsColor(stream, { sniffFlags: false });
8
+ if (res === false)
9
+ return false;
10
+ /* c8 ignore next */
11
+ return res.level > 0;
12
+ };
13
+ // eslint-disable-next-line no-console
14
+ export const stdout = (...args) => console.log(...args);
15
+ // eslint-disable-next-line no-console
16
+ export const stderr = (...args) => console.error(...args);
17
+ /* c8 ignore start */
18
+ const styleText = (f, s) =>
19
+ // @ts-expect-error -- styleText 3rd argument is not in types/node
20
+ utilStyleText(f, s, { validateStream: false });
21
+ /* c8 ignore stop */
22
+ // TODO: stop exporting mutable variables once exec output is refactored
23
+ /* c8 ignore start */
24
+ export let styleTextStdout = (_, s) => s;
25
+ export let styleTextStderr = (_, s) => s;
26
+ /* c8 ignore stop */
27
+ const identity = (x) => x;
28
+ export const getView = (conf, views) => {
29
+ const viewName = conf.values.view;
30
+ const viewFn = viewName === 'inspect' ? identity
31
+ : typeof views === 'function' ? views
32
+ : views && typeof views === 'object' ? views[viewName]
33
+ : identity;
34
+ // if the user specified a view that doesn't exist, then set it back to the
35
+ // default, and try again. This will fall back to identity if it's also
36
+ // missing. We also always treat 'json' as a valid view that falls back to
37
+ // identity. This allows the explicit use of `--view=json` to work even
38
+ // when the default view is `human`.
39
+ if (!viewFn &&
40
+ conf.values.view !== defaultView &&
41
+ conf.values.view !== 'json') {
42
+ conf.values.view = defaultView;
43
+ process.env.VLT_VIEW = defaultView;
44
+ return getView(conf, views);
45
+ }
46
+ return viewFn ?? identity;
47
+ };
48
+ /**
49
+ * If the view is a View class, then instantiate and start it.
50
+ * If it's a view function, then just define the onDone method.
51
+ */
52
+ const startView = (conf, opts, views, { start } = { start: Date.now() }) => {
53
+ const View = getView(conf, views);
54
+ if (isViewClass(View)) {
55
+ const view = new View(opts, conf);
56
+ view.start();
57
+ return {
58
+ onDone(r) {
59
+ return view.done(r, { time: Date.now() - start });
60
+ },
61
+ onError(err) {
62
+ view.error(err);
63
+ },
64
+ };
65
+ }
66
+ return {
67
+ async onDone(r) {
68
+ if (r === undefined)
69
+ return;
70
+ return View(r, opts, conf);
71
+ },
72
+ };
73
+ };
74
+ /**
75
+ * Main export. Run the command appropriately, displaying output using
76
+ * the user-requested view, or the default if the user requested a view
77
+ * that is not defined for this command.
78
+ */
79
+ export const outputCommand = async (cliCommand, conf, { start } = { start: Date.now() }) => {
80
+ const { usage, views, command } = cliCommand;
81
+ if (conf.values.help) {
82
+ return stdout(usage().usage());
83
+ }
84
+ const stdoutColor = conf.values.color ?? supportsColor(process.stdout);
85
+ const stderrColor = conf.values.color ?? supportsColor(process.stderr);
86
+ /* c8 ignore start */
87
+ if (stdoutColor)
88
+ styleTextStdout = styleText;
89
+ if (stderrColor)
90
+ styleTextStderr = styleText;
91
+ /* c8 ignore stop */
92
+ const formatOptions = {
93
+ depth: Infinity,
94
+ maxArrayLength: Infinity,
95
+ maxStringLength: Infinity,
96
+ };
97
+ const { onDone, onError } = startView(conf,
98
+ // assume views will always output to stdout so use color support from there
99
+ { colors: stdoutColor }, views, { start });
100
+ try {
101
+ const output = await onDone(await command(conf));
102
+ if (output !== undefined) {
103
+ stdout(conf.values.view === 'json' ?
104
+ JSON.stringify(output, null, 2)
105
+ : formatWithOptions({
106
+ ...formatOptions,
107
+ colors: stdoutColor,
108
+ }, output));
109
+ }
110
+ }
111
+ catch (err) {
112
+ onError?.(err);
113
+ process.exitCode ||= 1;
114
+ printErr(err, usage, stderr, {
115
+ ...formatOptions,
116
+ colors: stderrColor,
117
+ });
118
+ process.exit(process.exitCode);
119
+ }
120
+ };
121
+ //# sourceMappingURL=output.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"output.js","sourceRoot":"","sources":["../../src/output.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,iBAAiB,EACjB,SAAS,IAAI,aAAa,GAC3B,MAAM,WAAW,CAAA;AAClB,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAA;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAA;AAGpD,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AAEzC,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAA;AAEvC,MAAM,aAAa,GAAG,CAAC,MAAmB,EAAE,EAAE;IAC5C,MAAM,GAAG,GAAG,mBAAmB,CAAC,MAAM,EAAE,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC,CAAA;IAC9D,IAAI,GAAG,KAAK,KAAK;QAAE,OAAO,KAAK,CAAA;IAC/B,oBAAoB;IACpB,OAAO,GAAG,CAAC,KAAK,GAAG,CAAC,CAAA;AACtB,CAAC,CAAA;AAED,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,CAA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EAAE,CAAC;QACb,OAAO,EAAE,CAAC,GAAG,CAAC,CAAA;QACd,OAAO,CAAC,QAAQ,KAAK,CAAC,CAAA;QAEtB,QAAQ,CAAC,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE;YAC3B,GAAG,aAAa;YAChB,MAAM,EAAE,WAAW;SACpB,CAAC,CAAA;QAEF,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAA;IAChC,CAAC;AACH,CAAC,CAAA","sourcesContent":["import type { WriteStream } from 'node:tty'\nimport type { InspectOptions } from 'node:util'\nimport {\n formatWithOptions,\n styleText as utilStyleText,\n} from 'node:util'\nimport { createSupportsColor } from 'supports-color'\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 type { View, ViewOptions, Views } from './view.ts'\nimport { isViewClass } from './view.ts'\n\nconst supportsColor = (stream: WriteStream) => {\n const res = createSupportsColor(stream, { sniffFlags: false })\n if (res === false) return false\n /* c8 ignore next */\n return res.level > 0\n}\n\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\ntype StyleTextFn = (\n format: Parameters<typeof utilStyleText>[0],\n s: string,\n) => string\n\n/* c8 ignore start */\nconst styleText: StyleTextFn = (f, s) =>\n // @ts-expect-error -- styleText 3rd argument is not in types/node\n utilStyleText(f, s, { validateStream: false })\n/* c8 ignore stop */\n\n// TODO: stop exporting mutable variables once exec output is refactored\n/* c8 ignore start */\nexport let styleTextStdout: StyleTextFn = (_, s) => s\nexport let styleTextStderr: StyleTextFn = (_, s) => s\n/* c8 ignore stop */\n\nconst identity = <T>(x: T): T => x\n\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, then set it back to the\n // default, and try again. This will fall back to identity if it's also\n // missing. We also always treat 'json' as a valid view that falls back to\n // identity. This allows the explicit use of `--view=json` to work even\n // when the default view is `human`.\n if (\n !viewFn &&\n conf.values.view !== defaultView &&\n conf.values.view !== 'json'\n ) {\n conf.values.view = defaultView\n process.env.VLT_VIEW = defaultView\n return getView(conf, views)\n }\n\n return viewFn ?? identity\n}\n\nexport type OnDone<T> =\n | ((result: T) => Promise<unknown>)\n | ((result: T) => unknown)\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 */\nconst startView = <T>(\n conf: LoadedConfig,\n opts: ViewOptions,\n views?: Views<T>,\n { start }: { start: number } = { start: Date.now() },\n): {\n onDone: OnDone<T>\n onError?: (err: unknown) => void\n} => {\n const View = getView<T>(conf, views)\n\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 }\n\n return {\n async onDone(r) {\n if (r === undefined) return\n return View(r, opts, conf)\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\n if (conf.values.help) {\n return stdout(usage().usage())\n }\n\n const stdoutColor =\n conf.values.color ?? supportsColor(process.stdout)\n const stderrColor =\n conf.values.color ?? supportsColor(process.stderr)\n\n /* c8 ignore start */\n if (stdoutColor) styleTextStdout = styleText\n if (stderrColor) styleTextStderr = styleText\n /* c8 ignore stop */\n\n const formatOptions = {\n depth: Infinity,\n maxArrayLength: Infinity,\n maxStringLength: Infinity,\n } as const satisfies InspectOptions\n\n const { onDone, onError } = startView(\n conf,\n // assume views will always output to stdout so use color support from there\n { colors: stdoutColor },\n views,\n { start },\n )\n\n try {\n const output = await onDone(await command(conf))\n if (output !== undefined) {\n stdout(\n conf.values.view === 'json' ?\n JSON.stringify(output, null, 2)\n : formatWithOptions(\n {\n ...formatOptions,\n colors: stdoutColor,\n },\n output,\n ),\n )\n }\n } catch (err) {\n onError?.(err)\n process.exitCode ||= 1\n\n printErr(err, usage, stderr, {\n ...formatOptions,\n colors: stderrColor,\n })\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 { Monorepo } from '@vltpkg/workspaces';
3
+ import type { LoadedConfig } from './config/index.ts';
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":"AAEA,OAAO,KAAK,EACV,2BAA2B,EAE3B,8BAA8B,EAC/B,MAAM,eAAe,CAAA;AAKtB,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAA;AAClD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAErD,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
+ : 'implicit';
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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parse-add-remove-args.js","sourceRoot":"","sources":["../../src/parse-add-remove-args.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAM/C,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAE5C,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AAyBnC,MAAM,SAAS,GAAG,cAAc,CAAC,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAA;AAE/C;;;GAGG;AACH,MAAM,YAAY,GAAG,CACnB,IAAoB,EACpB,QAAmB,EACP,EAAE;IACd,MAAM,GAAG,G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QACL,MAAM;KACP,CAAA;AACH,CAAC,CAAA","sourcesContent":["import type { DepID } from '@vltpkg/dep-id'\nimport { joinDepIDTuple } from '@vltpkg/dep-id'\nimport type {\n AddImportersDependenciesMap,\n Dependency,\n RemoveImportersDependenciesMap,\n} from '@vltpkg/graph'\nimport { asDependency } from '@vltpkg/graph'\nimport type { SpecOptions } from '@vltpkg/spec'\nimport { Spec } from '@vltpkg/spec'\nimport type { DependencySaveType } from '@vltpkg/types'\nimport type { Monorepo } from '@vltpkg/workspaces'\nimport type { LoadedConfig } from './config/index.ts'\n\nexport type ParsedAddArgs = {\n add: AddImportersDependenciesMap\n}\n\nexport type ParsedRemoveArgs = {\n remove: RemoveImportersDependenciesMap\n}\n\nexport type SaveTypes = {\n 'save-dev'?: boolean\n 'save-optional'?: boolean\n 'save-peer'?: boolean\n 'save-prod'?: boolean\n}\n\nexport type WorkspaceTypes = {\n workspace?: string[]\n 'workspace-group'?: string[]\n}\n\nconst rootDepID = joinDepIDTuple(['file', '.'])\n\n/**\n * Get the list of importers that are currently selected\n * in {@link WorkspaceTypes}.\n */\nconst getImporters = (\n opts: WorkspaceTypes,\n monorepo?: Monorepo,\n): Set<DepID> => {\n const res = new Set<DepID>()\n\n // collects DepID references to any selected workspace\n if (monorepo) {\n for (const ws of monorepo.filter(opts)) {\n res.add(ws.id)\n }\n }\n\n // if no references were found, default behavior is to point to project root\n if (!res.size) {\n res.add(rootDepID)\n }\n\n return res\n}\n\nconst getType = (opts: SaveTypes): DependencySaveType =>\n opts['save-prod'] ? 'prod'\n : opts['save-dev'] ? 'dev'\n : opts['save-peer'] ?\n opts['save-optional'] ?\n 'peerOptional'\n : 'peer'\n : opts['save-optional'] ? 'optional'\n : 'implicit'\n\nclass AddImportersDependenciesMapImpl\n extends Map\n implements AddImportersDependenciesMap\n{\n modifiedDependencies = false\n}\n\nclass RemoveImportersDependenciesMapImpl\n extends Map\n implements RemoveImportersDependenciesMap\n{\n modifiedDependencies = false\n}\n\nexport const parseAddArgs = (\n config: LoadedConfig,\n monorepo?: Monorepo,\n): ParsedAddArgs => {\n const add: AddImportersDependenciesMap =\n new AddImportersDependenciesMapImpl()\n const items = config.positionals\n const type = getType(config.values)\n const importers = getImporters(config.values, monorepo)\n const newDependencies = new Map<string, Dependency>()\n const specOptions: SpecOptions = config.options\n\n // nameless spec definitions will need to use their full\n // stringified spec result instead of their name in order\n // to have an unique key name in the resulting Map\n const getName = (s: Spec): string =>\n s.name === '(unknown)' ? s.spec : s.name\n\n for (const item of items) {\n const spec = Spec.parseArgs(item, specOptions)\n newDependencies.set(getName(spec), asDependency({ spec, type }))\n add.modifiedDependencies = true\n }\n\n for (const importer of importers) {\n add.set(importer, newDependencies)\n }\n\n return {\n add,\n }\n}\n\nexport const parseRemoveArgs = (\n config: LoadedConfig,\n monorepo?: Monorepo,\n): ParsedRemoveArgs => {\n const remove: RemoveImportersDependenciesMap =\n new RemoveImportersDependenciesMapImpl()\n const importers = getImporters(config.values, monorepo)\n\n for (const importer of importers) {\n remove.set(importer, new Set(config.positionals))\n remove.modifiedDependencies = true\n }\n\n return {\n remove,\n }\n}\n"]}
@@ -0,0 +1,7 @@
1
+ import type { CommandUsage } from './index.ts';
2
+ import type { InspectOptions } from 'node:util';
3
+ export type ErrorFormatOptions = InspectOptions & {
4
+ maxLines?: number;
5
+ };
6
+ export declare const printErr: (err: unknown, usage: CommandUsage, stderr: (...a: string[]) => void, baseOpts?: ErrorFormatOptions) => void;
7
+ //# sourceMappingURL=print-err.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"print-err.d.ts","sourceRoot":"","sources":["../../src/print-err.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAC9C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,WAAW,CAAA;AAG/C,MAAM,MAAM,kBAAkB,GAAG,cAAc,GAAG;IAChD,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB,CAAA;AA4BD,eAAO,MAAM,QAAQ,QACd,OAAO,SACL,YAAY,UACX,CAAC,GAAG,CAAC,EAAE,MAAM,EAAE,KAAK,IAAI,aACrB,kBAAkB,SAkD9B,CAAA"}
@@ -0,0 +1,115 @@
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
+ const isErrorWithProps = (value) => value instanceof Error && Object.keys(value).length > 0;
17
+ export const printErr = (err, usage, stderr, baseOpts) => {
18
+ const format = (arg, opts) => {
19
+ const { maxLines = 200, ...rest } = { ...baseOpts, ...opts };
20
+ const lines = formatWithOptions(rest, arg).split('\n');
21
+ const totalLines = lines.length;
22
+ if (totalLines > maxLines) {
23
+ lines.length = maxLines;
24
+ lines.push(`... ${totalLines - maxLines} lines hidden ...`);
25
+ }
26
+ return lines.join('\n');
27
+ };
28
+ // This is an error with a cause, check if it we know about its
29
+ // code and try to print it. If it did not print then fallback
30
+ // to the next option.
31
+ if (isErrorWithCode(err) && print(err, usage, stderr, format)) {
32
+ return;
33
+ }
34
+ // We have a real but we dont know anything special about its
35
+ // properties. Just print the standard error properties as best we can.
36
+ if (err instanceof Error) {
37
+ stderr(`${err.name}: ${err.message}`);
38
+ if ('cause' in err) {
39
+ stderr(`Cause:`);
40
+ if (err.cause instanceof Error) {
41
+ stderr(indent(format(err.cause)));
42
+ }
43
+ else if (err.cause && typeof err.cause === 'object') {
44
+ for (const key in err.cause) {
45
+ stderr(indent(`${key}: ${format(err.cause[key])}`));
46
+ }
47
+ }
48
+ else {
49
+ stderr(indent(format(err.cause)));
50
+ }
51
+ }
52
+ const stack = trimStack(err);
53
+ if (stack) {
54
+ stderr(`Stack:`);
55
+ stderr(indent(format(stack)));
56
+ }
57
+ return;
58
+ }
59
+ // We don't know what this is, just print it.
60
+ stderr(`Unknown Error:`, format(err));
61
+ };
62
+ const print = (err, usage, stderr, format) => {
63
+ switch (err.cause.code) {
64
+ case 'EUSAGE': {
65
+ const { found, validOptions } = err.cause;
66
+ stderr(usage().usage());
67
+ stderr(`Usage Error: ${err.message}`);
68
+ if (found) {
69
+ stderr(indent(`Found: ${format(found)}`));
70
+ }
71
+ if (validOptions) {
72
+ stderr(indent(`Valid options: ${format(validOptions.join(', '))}`));
73
+ }
74
+ return true;
75
+ }
76
+ case 'ERESOLVE': {
77
+ const { url, from, response, spec } = err.cause;
78
+ stderr(`Resolve Error: ${err.message}`);
79
+ if (url) {
80
+ stderr(indent(`While fetching: ${url}`));
81
+ }
82
+ if (spec) {
83
+ stderr(indent(`To satisfy: ${format(spec)}`));
84
+ }
85
+ if (from) {
86
+ stderr(indent(`From: ${format(from)}`));
87
+ }
88
+ if (response) {
89
+ stderr(indent(`Response: ${format(response)}`));
90
+ }
91
+ return true;
92
+ }
93
+ case 'EREQUEST': {
94
+ const { url, method } = err.cause;
95
+ const { code, syscall } = isErrorWithProps(err.cause.cause) ?
96
+ err.cause.cause
97
+ : {};
98
+ stderr(`Request Error: ${err.message}`);
99
+ if (code) {
100
+ stderr(indent(`Code: ${format(code)}`));
101
+ }
102
+ if (syscall) {
103
+ stderr(indent(`Syscall: ${format(syscall)}`));
104
+ }
105
+ if (url) {
106
+ stderr(indent(`URL: ${url}`));
107
+ }
108
+ if (method) {
109
+ stderr(indent(`Method: ${format(method)}`));
110
+ }
111
+ return true;
112
+ }
113
+ }
114
+ };
115
+ //# sourceMappingURL=print-err.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"print-err.js","sourceRoot":"","sources":["../../src/print-err.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AA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AC,CAAC,CAAA;YAC/C,CAAC;YACD,IAAI,GAAG,EAAE,CAAC;gBACR,MAAM,CAAC,MAAM,CAAC,QAAQ,GAAG,EAAE,CAAC,CAAC,CAAA;YAC/B,CAAC;YACD,IAAI,MAAM,EAAE,CAAC;gBACX,MAAM,CAAC,MAAM,CAAC,WAAW,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAA;YAC7C,CAAC;YAED,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\nconst isErrorWithProps = (\n value: unknown,\n): value is Error & Record<string, unknown> =>\n value instanceof Error && Object.keys(value).length > 0\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 case 'EREQUEST': {\n const { url, method } = err.cause\n const { code, syscall } =\n isErrorWithProps(err.cause.cause) ?\n err.cause.cause\n : ({} as Record<string, unknown>)\n stderr(`Request Error: ${err.message}`)\n if (code) {\n stderr(indent(`Code: ${format(code)}`))\n }\n if (syscall) {\n stderr(indent(`Syscall: ${format(syscall)}`))\n }\n if (url) {\n stderr(indent(`URL: ${url}`))\n }\n if (method) {\n stderr(indent(`Method: ${format(method)}`))\n }\n\n return true\n }\n }\n}\n"]}
@@ -0,0 +1,8 @@
1
+ export type Streams = {
2
+ stdin: NodeJS.ReadableStream & {
3
+ setRawMode(mode: boolean): void;
4
+ };
5
+ stdout: NodeJS.WritableStream;
6
+ };
7
+ export declare const readPassword: (prompt: string, { stdin, stdout }?: Streams) => Promise<string>;
8
+ //# sourceMappingURL=read-password.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"read-password.d.ts","sourceRoot":"","sources":["../../src/read-password.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,OAAO,GAAG;IACpB,KAAK,EAAE,MAAM,CAAC,cAAc,GAAG;QAAE,UAAU,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,CAAA;KAAE,CAAA;IAClE,MAAM,EAAE,MAAM,CAAC,cAAc,CAAA;CAC9B,CAAA;AAED,eAAO,MAAM,YAAY,WACf,MAAM,sBACK,OAAO,KACzB,OAAO,CAAC,MAAM,CA4BhB,CAAA"}
@@ -0,0 +1,33 @@
1
+ import { error } from '@vltpkg/error-cause';
2
+ export const readPassword = async (prompt, { stdin, stdout } = process) => {
3
+ let input = '';
4
+ stdout.write(prompt);
5
+ stdin.setRawMode(true);
6
+ await new Promise((res, rej) => {
7
+ stdin.on('data', (c) => {
8
+ // backspace
9
+ if (c.length === 1 && c[0] === 0x7f) {
10
+ input = input.substring(0, input.length - 1);
11
+ stdout.write('\x1b[1D \x1b[1D');
12
+ return;
13
+ }
14
+ input += String(c);
15
+ if (/\r|\n|\x04|\x03/.test(input)) {
16
+ input = input.replace(/(\r|\n|\x04|\x03)/g, '');
17
+ stdin.setRawMode(false);
18
+ stdin.pause();
19
+ // x03 === ^C
20
+ if (c[c.length - 1] === 3) {
21
+ rej(error('canceled', { signal: 'SIGINT' }));
22
+ }
23
+ else
24
+ res();
25
+ }
26
+ else {
27
+ stdout.write('*'.repeat(c.length));
28
+ }
29
+ });
30
+ });
31
+ return input;
32
+ };
33
+ //# sourceMappingURL=read-password.js.map
@@ -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,CAAC,CAAC,CAAA;gBAC9C,CAAC;;oBAAM,GAAG,EAAE,CAAA;YACd,CAAC;iBAAM,CAAC;gBACN,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAA;YACpC,CAAC;QACH,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;IACF,OAAO,KAAK,CAAA;AACd,CAAC,CAAA","sourcesContent":["import { error } from '@vltpkg/error-cause'\n\nexport type Streams = {\n stdin: NodeJS.ReadableStream & { setRawMode(mode: boolean): void }\n stdout: NodeJS.WritableStream\n}\n\nexport const readPassword = async (\n prompt: string,\n { stdin, stdout }: Streams = process,\n): Promise<string> => {\n let input = ''\n stdout.write(prompt)\n stdin.setRawMode(true)\n await new Promise<void>((res, rej) => {\n stdin.on('data', (c: Buffer) => {\n // backspace\n if (c.length === 1 && c[0] === 0x7f) {\n input = input.substring(0, input.length - 1)\n stdout.write('\\x1b[1D \\x1b[1D')\n return\n }\n\n input += String(c)\n if (/\\r|\\n|\\x04|\\x03/.test(input)) {\n input = input.replace(/(\\r|\\n|\\x04|\\x03)/g, '')\n stdin.setRawMode(false)\n stdin.pause()\n // x03 === ^C\n if (c[c.length - 1] === 3) {\n rej(error('canceled', { signal: 'SIGINT' }))\n } else res()\n } else {\n stdout.write('*'.repeat(c.length))\n }\n })\n })\n return input\n}\n"]}
@@ -0,0 +1,9 @@
1
+ import type { PathScurry } from 'path-scurry';
2
+ import type { LoadedConfig } from './config/index.ts';
3
+ export declare const getDefaultStartingRoute: (options: {
4
+ startingRoute?: string;
5
+ projectRoot: string;
6
+ scurry: PathScurry;
7
+ }) => Promise<string>;
8
+ export declare const startGUI: (conf: LoadedConfig, startingRoute?: string) => Promise<import("@vltpkg/server").VltServer>;
9
+ //# sourceMappingURL=start-gui.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"start-gui.d.ts","sourceRoot":"","sources":["../../src/start-gui.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAC7C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAIrD,eAAO,MAAM,uBAAuB,YAAmB;IACrD,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,WAAW,EAAE,MAAM,CAAA;IACnB,MAAM,EAAE,UAAU,CAAA;CACnB,oBAOA,CAAA;AAaD,eAAO,MAAM,QAAQ,SACb,YAAY,kBACF,MAAM,gDAuBvB,CAAA"}
@@ -0,0 +1,40 @@
1
+ import { createServer } from '@vltpkg/server';
2
+ import { urlOpen } from '@vltpkg/url-open';
3
+ import { stdout } from "./output.js";
4
+ import { resolve } from 'node:path';
5
+ export const getDefaultStartingRoute = async (options) => {
6
+ const { startingRoute, projectRoot, scurry } = options;
7
+ if (startingRoute)
8
+ return startingRoute;
9
+ const stat = await scurry.lstat(`${projectRoot}/package.json`);
10
+ return stat?.isFile() && !stat.isSymbolicLink() ?
11
+ `/explore?query=${encodeURIComponent(':root')}`
12
+ : '/';
13
+ };
14
+ const getAssetsDir = () => {
15
+ /* c8 ignore start */
16
+ if (process.env.__VLT_INTERNAL_GUI_ASSETS_DIR) {
17
+ return resolve(import.meta.dirname, process.env.__VLT_INTERNAL_GUI_ASSETS_DIR);
18
+ }
19
+ /* c8 ignore stop */
20
+ };
21
+ export const startGUI = async (conf, startingRoute) => {
22
+ const server = createServer({
23
+ ...conf.options,
24
+ assetsDir: getAssetsDir(),
25
+ });
26
+ server.on('needConfigUpdate', dir => {
27
+ conf.resetOptions(dir);
28
+ server.updateOptions(conf.options);
29
+ });
30
+ const { projectRoot, scurry } = conf.options;
31
+ await server.start();
32
+ stdout(`⚡️ vlt GUI running at ${server.address()}`);
33
+ void urlOpen(server.address(await getDefaultStartingRoute({
34
+ startingRoute,
35
+ projectRoot,
36
+ scurry,
37
+ })));
38
+ return server;
39
+ };
40
+ //# sourceMappingURL=start-gui.js.map
@@ -0,0 +1 @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QAClC,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,CACrB;QAAC,MAA6B,CAAC,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;IAC7D,CAAC,CAAC,CAAA;IACF,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC,OAAO,CAAA;IAC5C,MAAM,MAAM,CAAC,KAAK,EAAE,CAAA;IACpB,MAAM,CAAC,yBAAyB,MAAM,CAAC,OAAO,EAAE,EAAE,CAAC,CAAA;IACnD,KAAK,OAAO,CACV,MAAM,CAAC,OAAO,CACZ,MAAM,uBAAuB,CAAC;QAC5B,aAAa;QACb,WAAW;QACX,MAAM;KACP,CAAC,CACH,CACF,CAAA;IACD,OAAO,MAAM,CAAA;AACf,CAAC,CAAA","sourcesContent":["import type { VltServerListening } from '@vltpkg/server'\nimport { createServer } from '@vltpkg/server'\nimport { urlOpen } from '@vltpkg/url-open'\nimport type { PathScurry } from 'path-scurry'\nimport type { LoadedConfig } from './config/index.ts'\nimport { stdout } from './output.ts'\nimport { resolve } from 'node:path'\n\nexport const getDefaultStartingRoute = async (options: {\n startingRoute?: string\n projectRoot: string\n scurry: PathScurry\n}) => {\n const { startingRoute, projectRoot, scurry } = options\n if (startingRoute) return startingRoute\n const stat = await scurry.lstat(`${projectRoot}/package.json`)\n return stat?.isFile() && !stat.isSymbolicLink() ?\n `/explore?query=${encodeURIComponent(':root')}`\n : '/'\n}\n\nconst getAssetsDir = () => {\n /* c8 ignore start */\n if (process.env.__VLT_INTERNAL_GUI_ASSETS_DIR) {\n return resolve(\n import.meta.dirname,\n process.env.__VLT_INTERNAL_GUI_ASSETS_DIR,\n )\n }\n /* c8 ignore stop */\n}\n\nexport const startGUI = async (\n conf: LoadedConfig,\n startingRoute?: string,\n) => {\n const server = createServer({\n ...conf.options,\n assetsDir: getAssetsDir(),\n })\n server.on('needConfigUpdate', dir => {\n conf.resetOptions(dir)\n ;(server as VltServerListening).updateOptions(conf.options)\n })\n const { projectRoot, scurry } = conf.options\n await server.start()\n stdout(`⚡️ vlt GUI running at ${server.address()}`)\n void urlOpen(\n server.address(\n await getDefaultStartingRoute({\n startingRoute,\n projectRoot,\n scurry,\n }),\n ),\n )\n return server\n}\n"]}
@@ -0,0 +1,30 @@
1
+ import type { LoadedConfig } from './config/index.ts';
2
+ export type ViewOptions = {
3
+ colors?: boolean;
4
+ };
5
+ /**
6
+ * The base class for all View classes
7
+ *
8
+ * Do not override the constructor, just provide start/done/error methods.
9
+ *
10
+ * These classes should be used as one or more of the exported views for
11
+ * commands that need to know when the processing starts, handle errors in
12
+ * various ways, etc. Fancy stuff.
13
+ *
14
+ * For simple use cases, usually better to create a {@link ViewFn} instead.
15
+ */
16
+ export declare class ViewClass<T = unknown> {
17
+ options: ViewOptions;
18
+ config: LoadedConfig;
19
+ constructor(options: ViewOptions, config: LoadedConfig);
20
+ start(): void;
21
+ done(_result: T, _opts: {
22
+ time: number;
23
+ }): unknown;
24
+ error(_err: unknown): void;
25
+ }
26
+ export type ViewFn<T = unknown> = (result: T, options: ViewOptions, conf: LoadedConfig) => unknown;
27
+ export type View<T = unknown> = ViewFn<T> | typeof ViewClass<T>;
28
+ export declare const isViewClass: <T = unknown>(view: View<T>) => view is typeof ViewClass<T>;
29
+ export type Views<T = unknown> = View<T> | Record<string, View<T>>;
30
+ //# sourceMappingURL=view.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"view.d.ts","sourceRoot":"","sources":["../../src/view.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAErD,MAAM,MAAM,WAAW,GAAG;IAAE,MAAM,CAAC,EAAE,OAAO,CAAA;CAAE,CAAA;AAE9C;;;;;;;;;;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,OAAO;IAGlD,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,KAAK,CAAC,CAAC,GAAG,OAAO,IAAI,IAAI,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,CAAA"}
@@ -0,0 +1,31 @@
1
+ /**
2
+ * The base class for all View classes
3
+ *
4
+ * Do not override the constructor, just provide start/done/error methods.
5
+ *
6
+ * These classes should be used as one or more of the exported views for
7
+ * commands that need to know when the processing starts, handle errors in
8
+ * various ways, etc. Fancy stuff.
9
+ *
10
+ * For simple use cases, usually better to create a {@link ViewFn} instead.
11
+ */
12
+ export class ViewClass {
13
+ options;
14
+ config;
15
+ constructor(options, config) {
16
+ this.options = options;
17
+ this.config = config;
18
+ }
19
+ // TODO: maybe have start() return a flag to say "i got this, do not
20
+ // run the command", for example to have the gui just open a web browser
21
+ // to the page relevant to a given thing, rather than computing it twice
22
+ start() { }
23
+ done(_result, _opts) {
24
+ return;
25
+ }
26
+ error(_err) { }
27
+ }
28
+ export const isViewClass = (view) => typeof view === 'function' &&
29
+ 'prototype' in view &&
30
+ view.prototype instanceof ViewClass;
31
+ //# sourceMappingURL=view.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"view.js","sourceRoot":"","sources":["../../src/view.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;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 { LoadedConfig } from './config/index.ts'\n\nexport type ViewOptions = { colors?: boolean }\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"]}