@vltpkg/cli-sdk 0.0.0-8 → 1.0.0-rc.1

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 (164) hide show
  1. package/dist/esm/commands/build.d.ts +25 -0
  2. package/dist/esm/commands/build.d.ts.map +1 -0
  3. package/dist/esm/commands/build.js +102 -0
  4. package/dist/esm/commands/build.js.map +1 -0
  5. package/dist/esm/commands/cache.d.ts +65 -0
  6. package/dist/esm/commands/cache.d.ts.map +1 -0
  7. package/dist/esm/commands/cache.js +257 -0
  8. package/dist/esm/commands/cache.js.map +1 -0
  9. package/dist/esm/commands/ci.d.ts +11 -0
  10. package/dist/esm/commands/ci.d.ts.map +1 -0
  11. package/dist/esm/commands/ci.js +32 -0
  12. package/dist/esm/commands/ci.js.map +1 -0
  13. package/dist/esm/commands/config.d.ts +3 -2
  14. package/dist/esm/commands/config.d.ts.map +1 -1
  15. package/dist/esm/commands/config.js +372 -101
  16. package/dist/esm/commands/config.js.map +1 -1
  17. package/dist/esm/commands/docs.d.ts +18 -0
  18. package/dist/esm/commands/docs.d.ts.map +1 -0
  19. package/dist/esm/commands/docs.js +154 -0
  20. package/dist/esm/commands/docs.js.map +1 -0
  21. package/dist/esm/commands/exec-cache.d.ts +49 -0
  22. package/dist/esm/commands/exec-cache.d.ts.map +1 -0
  23. package/dist/esm/commands/exec-cache.js +146 -0
  24. package/dist/esm/commands/exec-cache.js.map +1 -0
  25. package/dist/esm/commands/exec-local.d.ts +6 -0
  26. package/dist/esm/commands/exec-local.d.ts.map +1 -0
  27. package/dist/esm/commands/exec-local.js +24 -0
  28. package/dist/esm/commands/exec-local.js.map +1 -0
  29. package/dist/esm/commands/exec.d.ts +4 -0
  30. package/dist/esm/commands/exec.d.ts.map +1 -1
  31. package/dist/esm/commands/exec.js +75 -10
  32. package/dist/esm/commands/exec.js.map +1 -1
  33. package/dist/esm/commands/help.d.ts +1 -1
  34. package/dist/esm/commands/help.d.ts.map +1 -1
  35. package/dist/esm/commands/help.js +32 -3
  36. package/dist/esm/commands/help.js.map +1 -1
  37. package/dist/esm/commands/init.d.ts +4 -5
  38. package/dist/esm/commands/init.d.ts.map +1 -1
  39. package/dist/esm/commands/init.js +95 -9
  40. package/dist/esm/commands/init.js.map +1 -1
  41. package/dist/esm/commands/install/reporter.d.ts +3 -2
  42. package/dist/esm/commands/install/reporter.d.ts.map +1 -1
  43. package/dist/esm/commands/install/reporter.js +43 -15
  44. package/dist/esm/commands/install/reporter.js.map +1 -1
  45. package/dist/esm/commands/install.d.ts +24 -3
  46. package/dist/esm/commands/install.d.ts.map +1 -1
  47. package/dist/esm/commands/install.js +27 -3
  48. package/dist/esm/commands/install.js.map +1 -1
  49. package/dist/esm/commands/list.d.ts +2 -2
  50. package/dist/esm/commands/list.d.ts.map +1 -1
  51. package/dist/esm/commands/list.js +149 -49
  52. package/dist/esm/commands/list.js.map +1 -1
  53. package/dist/esm/commands/pack.d.ts +32 -0
  54. package/dist/esm/commands/pack.d.ts.map +1 -0
  55. package/dist/esm/commands/pack.js +147 -0
  56. package/dist/esm/commands/pack.js.map +1 -0
  57. package/dist/esm/commands/pkg.d.ts +2 -3
  58. package/dist/esm/commands/pkg.d.ts.map +1 -1
  59. package/dist/esm/commands/pkg.js +123 -38
  60. package/dist/esm/commands/pkg.js.map +1 -1
  61. package/dist/esm/commands/publish.d.ts +22 -0
  62. package/dist/esm/commands/publish.d.ts.map +1 -0
  63. package/dist/esm/commands/publish.js +245 -0
  64. package/dist/esm/commands/publish.js.map +1 -0
  65. package/dist/esm/commands/query.d.ts +2 -2
  66. package/dist/esm/commands/query.d.ts.map +1 -1
  67. package/dist/esm/commands/query.js +170 -39
  68. package/dist/esm/commands/query.js.map +1 -1
  69. package/dist/esm/commands/run-exec.d.ts +1 -0
  70. package/dist/esm/commands/run-exec.d.ts.map +1 -1
  71. package/dist/esm/commands/run-exec.js +1 -0
  72. package/dist/esm/commands/run-exec.js.map +1 -1
  73. package/dist/esm/commands/run.d.ts +1 -0
  74. package/dist/esm/commands/run.d.ts.map +1 -1
  75. package/dist/esm/commands/run.js +13 -16
  76. package/dist/esm/commands/run.js.map +1 -1
  77. package/dist/esm/commands/serve.d.ts +14 -0
  78. package/dist/esm/commands/serve.d.ts.map +1 -0
  79. package/dist/esm/commands/serve.js +103 -0
  80. package/dist/esm/commands/serve.js.map +1 -0
  81. package/dist/esm/commands/uninstall.d.ts +12 -3
  82. package/dist/esm/commands/uninstall.d.ts.map +1 -1
  83. package/dist/esm/commands/uninstall.js +8 -3
  84. package/dist/esm/commands/uninstall.js.map +1 -1
  85. package/dist/esm/commands/update.d.ts +14 -0
  86. package/dist/esm/commands/update.d.ts.map +1 -0
  87. package/dist/esm/commands/update.js +41 -0
  88. package/dist/esm/commands/update.js.map +1 -0
  89. package/dist/esm/commands/version.d.ts +26 -0
  90. package/dist/esm/commands/version.d.ts.map +1 -0
  91. package/dist/esm/commands/version.js +226 -0
  92. package/dist/esm/commands/version.js.map +1 -0
  93. package/dist/esm/commands/whoami.d.ts +4 -2
  94. package/dist/esm/commands/whoami.d.ts.map +1 -1
  95. package/dist/esm/commands/whoami.js +1 -1
  96. package/dist/esm/commands/whoami.js.map +1 -1
  97. package/dist/esm/config/definition.d.ts +123 -11
  98. package/dist/esm/config/definition.d.ts.map +1 -1
  99. package/dist/esm/config/definition.js +197 -34
  100. package/dist/esm/config/definition.js.map +1 -1
  101. package/dist/esm/config/index.d.ts +42 -37
  102. package/dist/esm/config/index.d.ts.map +1 -1
  103. package/dist/esm/config/index.js +116 -172
  104. package/dist/esm/config/index.js.map +1 -1
  105. package/dist/esm/config/merge.d.ts +3 -1
  106. package/dist/esm/config/merge.d.ts.map +1 -1
  107. package/dist/esm/config/merge.js +11 -6
  108. package/dist/esm/config/merge.js.map +1 -1
  109. package/dist/esm/config/usage.d.ts +3 -2
  110. package/dist/esm/config/usage.d.ts.map +1 -1
  111. package/dist/esm/config/usage.js.map +1 -1
  112. package/dist/esm/custom-help.d.ts +9 -0
  113. package/dist/esm/custom-help.d.ts.map +1 -0
  114. package/dist/esm/custom-help.js +400 -0
  115. package/dist/esm/custom-help.js.map +1 -0
  116. package/dist/esm/exec-command.d.ts +33 -14
  117. package/dist/esm/exec-command.d.ts.map +1 -1
  118. package/dist/esm/exec-command.js +214 -65
  119. package/dist/esm/exec-command.js.map +1 -1
  120. package/dist/esm/index.d.ts +1 -14
  121. package/dist/esm/index.d.ts.map +1 -1
  122. package/dist/esm/index.js +46 -20
  123. package/dist/esm/index.js.map +1 -1
  124. package/dist/esm/load-command.d.ts +16 -0
  125. package/dist/esm/load-command.d.ts.map +1 -0
  126. package/dist/esm/load-command.js +21 -0
  127. package/dist/esm/load-command.js.map +1 -0
  128. package/dist/esm/output.d.ts +6 -10
  129. package/dist/esm/output.d.ts.map +1 -1
  130. package/dist/esm/output.js +73 -35
  131. package/dist/esm/output.js.map +1 -1
  132. package/dist/esm/pack-tarball.d.ts +22 -0
  133. package/dist/esm/pack-tarball.d.ts.map +1 -0
  134. package/dist/esm/pack-tarball.js +249 -0
  135. package/dist/esm/pack-tarball.js.map +1 -0
  136. package/dist/esm/parse-add-remove-args.d.ts +1 -1
  137. package/dist/esm/parse-add-remove-args.d.ts.map +1 -1
  138. package/dist/esm/parse-add-remove-args.js +1 -1
  139. package/dist/esm/parse-add-remove-args.js.map +1 -1
  140. package/dist/esm/print-err.d.ts +12 -1
  141. package/dist/esm/print-err.d.ts.map +1 -1
  142. package/dist/esm/print-err.js +157 -26
  143. package/dist/esm/print-err.js.map +1 -1
  144. package/dist/esm/query-host-contexts.d.ts +16 -0
  145. package/dist/esm/query-host-contexts.d.ts.map +1 -0
  146. package/dist/esm/query-host-contexts.js +135 -0
  147. package/dist/esm/query-host-contexts.js.map +1 -0
  148. package/dist/esm/start-gui.d.ts +1 -0
  149. package/dist/esm/start-gui.d.ts.map +1 -1
  150. package/dist/esm/start-gui.js +25 -6
  151. package/dist/esm/start-gui.js.map +1 -1
  152. package/dist/esm/view.d.ts +2 -3
  153. package/dist/esm/view.d.ts.map +1 -1
  154. package/dist/esm/view.js +1 -1
  155. package/dist/esm/view.js.map +1 -1
  156. package/package.json +51 -35
  157. package/dist/esm/commands/gui.d.ts +0 -6
  158. package/dist/esm/commands/gui.d.ts.map +0 -1
  159. package/dist/esm/commands/gui.js +0 -13
  160. package/dist/esm/commands/gui.js.map +0 -1
  161. package/dist/esm/commands/install-exec.d.ts +0 -4
  162. package/dist/esm/commands/install-exec.d.ts.map +0 -1
  163. package/dist/esm/commands/install-exec.js +0 -13
  164. package/dist/esm/commands/install-exec.js.map +0 -1
@@ -1,3 +1,14 @@
1
+ import type { InspectOptions } from 'node:util';
1
2
  import type { CommandUsage } from './index.ts';
2
- export declare const printErr: (err: unknown, usage: CommandUsage, stderr: (...a: unknown[]) => void) => void;
3
+ export declare const formatOptions: {
4
+ readonly depth: number;
5
+ readonly maxArrayLength: number;
6
+ readonly maxStringLength: number;
7
+ };
8
+ export type ErrorFormatOptions = InspectOptions & {
9
+ maxLines?: number;
10
+ };
11
+ export type Formatter = (arg: unknown, options?: ErrorFormatOptions) => string;
12
+ export declare const indent: (lines: string, num?: number) => string;
13
+ export declare const printErr: (e: unknown, usage: CommandUsage, stderr: (...a: string[]) => void, baseOpts?: ErrorFormatOptions) => void;
3
14
  //# sourceMappingURL=print-err.d.ts.map
@@ -1 +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;AAI9C,eAAO,MAAM,QAAQ,QACd,OAAO,SACL,YAAY,UACX,CAAC,GAAG,CAAC,EAAE,OAAO,EAAE,KAAK,IAAI,SAUlC,CAAA"}
1
+ {"version":3,"file":"print-err.d.ts","sourceRoot":"","sources":["../../src/print-err.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,WAAW,CAAA;AAE/C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAE9C,eAAO,MAAM,aAAa;;;;CAIS,CAAA;AAEnC,MAAM,MAAM,kBAAkB,GAAG,cAAc,GAAG;IAChD,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB,CAAA;AAED,MAAM,MAAM,SAAS,GAAG,CACtB,GAAG,EAAE,OAAO,EACZ,OAAO,CAAC,EAAE,kBAAkB,KACzB,MAAM,CAAA;AAWX,eAAO,MAAM,MAAM,UAAW,MAAM,yBAIrB,CAAA;AAoBf,eAAO,MAAM,QAAQ,MAChB,OAAO,SACH,YAAY,UACX,CAAC,GAAG,CAAC,EAAE,MAAM,EAAE,KAAK,IAAI,aACrB,kBAAkB,SAwC9B,CAAA"}
@@ -1,47 +1,178 @@
1
- import { isErrorRoot } from '@vltpkg/error-cause';
2
- // returns true if error was printed nicely already
3
- export const printErr = (err, usage, stderr) => {
4
- if (!isErrorRoot(err)) {
5
- // TODO: print _something_ here, but we're in weird broken territory
6
- // don't just dump it and flood the terminal, though, maybe sniff for code
7
- // message, stack, etc?
8
- return;
1
+ import { splitDepID } from '@vltpkg/dep-id';
2
+ import { parseError } from '@vltpkg/output/error';
3
+ import { isErrorWithCause, isObject } from '@vltpkg/types';
4
+ import { XDG } from '@vltpkg/xdg';
5
+ import { isGraphRunError } from 'graph-run';
6
+ import { mkdirSync, writeFileSync } from 'node:fs';
7
+ import { join } from 'node:path';
8
+ import { formatWithOptions } from 'node:util';
9
+ export const formatOptions = {
10
+ depth: Infinity,
11
+ maxArrayLength: Infinity,
12
+ maxStringLength: Infinity,
13
+ };
14
+ const isNonEmptyString = (v) => !!v && typeof v === 'string';
15
+ const formatURL = (v, format) => v instanceof URL ? v.toString() : /* c8 ignore next */ format(v);
16
+ const formatArray = (v, format, joiner = ', ') => Array.isArray(v) ? v.join(joiner) : /* c8 ignore next */ format(v);
17
+ export const indent = (lines, num = 2) => lines
18
+ .split('\n')
19
+ .map(l => ' '.repeat(num) + l)
20
+ .join('\n');
21
+ const writeErrorLog = (e, format) => {
22
+ try {
23
+ const dir = new XDG('vlt/error-logs').data();
24
+ const file = join(dir, `error-${process.pid}.log`);
25
+ mkdirSync(dir, { recursive: true });
26
+ writeFileSync(file, format(e, {
27
+ colors: false,
28
+ maxLines: Infinity,
29
+ }));
30
+ return file;
31
+ }
32
+ catch {
33
+ return null;
9
34
  }
10
- if (isErrorRoot(err) && print(err, usage, stderr))
11
- return;
12
- stderr(err);
13
35
  };
14
- const print = (err, usage, stderr) => {
15
- switch (err.cause.code) {
36
+ export const printErr = (e, usage, stderr, baseOpts) => {
37
+ const format = (arg, opts) => {
38
+ const { maxLines = 200, ...rest } = {
39
+ ...formatOptions,
40
+ ...baseOpts,
41
+ ...opts,
42
+ };
43
+ const lines = formatWithOptions(rest, arg).split('\n');
44
+ const totalLines = lines.length;
45
+ if (totalLines > maxLines) {
46
+ lines.length = maxLines;
47
+ lines.push(`... ${totalLines - maxLines} lines hidden ...`);
48
+ }
49
+ return lines.join('\n');
50
+ };
51
+ const err = parseError(e);
52
+ const knownError = printCode(err, usage, stderr, format);
53
+ const fileWritten = !knownError || knownError.file ? writeErrorLog(e, format) : null;
54
+ // We could not write an error log and its not a know error,
55
+ // so we print the entire formatted value.
56
+ if (!fileWritten && !knownError) {
57
+ return stderr(format(e));
58
+ }
59
+ if (err && !knownError) {
60
+ stderr(`${err.name}: ${err.message}`);
61
+ }
62
+ if (fileWritten) {
63
+ stderr('');
64
+ stderr(`Full details written to: ${fileWritten}`);
65
+ }
66
+ if (!knownError || knownError.bug) {
67
+ stderr('');
68
+ stderr('Open an issue with the full error details at:');
69
+ stderr(indent('https://github.com/vltpkg/vltpkg/issues/new'));
70
+ }
71
+ };
72
+ const printCode = (err, usage, stderr, format) => {
73
+ if (!err)
74
+ return;
75
+ switch (err.cause?.code) {
76
+ case 'GRAPHRUN_TRAVERSAL': {
77
+ if (!isGraphRunError(err))
78
+ break;
79
+ const { node, path, cause } = err.cause;
80
+ stderr(`Graph traversal failure at: ${splitDepID(node.id).join(' ')}`);
81
+ if (Array.isArray(path) && path.length) {
82
+ stderr(indent(`Path: ${path.map(n => n.id).join(',')}`));
83
+ }
84
+ if (isErrorWithCause(cause) &&
85
+ isObject(cause.cause) &&
86
+ 'command' in cause.cause &&
87
+ 'stdout' in cause.cause &&
88
+ 'stderr' in cause.cause &&
89
+ 'status' in cause.cause &&
90
+ 'signal' in cause.cause &&
91
+ 'cwd' in cause.cause) {
92
+ const { command, args, cwd, stdout: cmdStdout, stderr: cmdStderr, status, signal, } = cause.cause;
93
+ stderr(`Command: ${command}`);
94
+ if (args && Array.isArray(args) && args.length) {
95
+ stderr(`Args: ${args.map(a => JSON.stringify(a)).join(', ')}`);
96
+ }
97
+ stderr(`Cwd: ${cwd}`);
98
+ if (cmdStderr || cmdStdout) {
99
+ stderr('');
100
+ if (isNonEmptyString(cmdStderr)) {
101
+ stderr(cmdStderr);
102
+ }
103
+ if (isNonEmptyString(cmdStdout)) {
104
+ stderr(cmdStdout);
105
+ }
106
+ stderr('');
107
+ }
108
+ if (signal !== null)
109
+ stderr(`Signal: ${format(signal)}`);
110
+ if (status !== null)
111
+ stderr(`Status: ${format(status)}`);
112
+ }
113
+ return { file: true };
114
+ }
16
115
  case 'EUSAGE': {
116
+ const { found, validOptions } = err.cause;
17
117
  stderr(usage().usage());
18
- stderr(`Error: ${err.message}`);
19
- if (err.cause.found) {
20
- stderr(` Found: ${err.cause.found}`);
118
+ stderr(`Usage Error: ${err.message}`);
119
+ if (found) {
120
+ stderr(indent(`Found: ${format(found)}`));
21
121
  }
22
- if (err.cause.validOptions) {
23
- stderr(` Valid options: ${err.cause.validOptions.join(', ')}`);
122
+ if (validOptions) {
123
+ stderr(indent(`Valid options: ${formatArray(validOptions, format)}`));
24
124
  }
25
- return true;
125
+ return {};
26
126
  }
27
127
  case 'ERESOLVE': {
28
- stderr(`Resolve Error: ${err.message}`);
29
128
  const { url, from, response, spec } = err.cause;
129
+ stderr(`Resolve Error: ${err.message}`);
30
130
  if (url) {
31
- stderr(` While fetching: ${url}`);
131
+ stderr(indent(`While fetching: ${formatURL(url, format)}`));
32
132
  }
33
133
  if (spec) {
34
- stderr(` To satisfy: ${spec}`);
134
+ stderr(indent(`To satisfy: ${format(spec)}`));
35
135
  }
36
136
  if (from) {
37
- stderr(` From: ${from}`);
137
+ stderr(indent(`From: ${format(from)}`));
38
138
  }
39
139
  if (response) {
40
- stderr('Response:', response);
140
+ stderr(indent(`Response: ${format(response)}`));
141
+ }
142
+ return { file: true };
143
+ }
144
+ case 'EREQUEST': {
145
+ const { url, method } = err.cause;
146
+ const { code, syscall } = err.cause.cause ?? {};
147
+ stderr(`Request Error: ${err.message}`);
148
+ if (code) {
149
+ stderr(indent(`Code: ${format(code)}`));
150
+ }
151
+ if (syscall) {
152
+ stderr(indent(`Syscall: ${format(syscall)}`));
153
+ }
154
+ if (url) {
155
+ stderr(indent(`URL: ${formatURL(url, format)}`));
156
+ }
157
+ if (method) {
158
+ stderr(indent(`Method: ${format(method)}`));
159
+ }
160
+ return { file: true };
161
+ }
162
+ case 'ECONFIG': {
163
+ const { found, wanted, validOptions } = err.cause;
164
+ stderr(`Config Error: ${err.message}`);
165
+ if (found) {
166
+ stderr(indent(`Found: ${format(found)}`));
167
+ }
168
+ if (wanted) {
169
+ stderr(indent(`Wanted: ${format(wanted)}`));
170
+ }
171
+ if (validOptions) {
172
+ stderr(indent(`Valid Options: ${format(validOptions)}`));
41
173
  }
42
- return true;
174
+ return {};
43
175
  }
44
176
  }
45
- return false;
46
177
  };
47
178
  //# sourceMappingURL=print-err.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"print-err.js","sourceRoot":"","sources":["../../src/print-err.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AAKjD,mDAAmD;AACnD,MAAM,CAAC,MAAM,QAAQ,GAAG,CACtB,GAAY,EACZ,KAAmB,EACnB,MAAiC,EACjC,EAAE;IACF,IAAI,C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AiB,IAAqB,EAAE,CAAC,CAAA;YAClD,CAAC;YACD,IAAI,IAAI,EAAE,CAAC;gBACT,MAAM,CAAC,WAAW,IAAI,EAAE,CAAC,CAAA;YAC3B,CAAC;YACD,IAAI,QAAQ,EAAE,CAAC;gBACb,MAAM,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAA;YAC/B,CAAC;YACD,OAAO,IAAI,CAAA;QACb,CAAC;IACH,CAAC;IAED,OAAO,KAAK,CAAA;AACd,CAAC,CAAA","sourcesContent":["import { isErrorRoot } from '@vltpkg/error-cause'\nimport type { ErrorWithCauseObject } from '@vltpkg/error-cause'\nimport type { CommandUsage } from './index.ts'\nimport type { Spec } from '@vltpkg/spec'\n\n// returns true if error was printed nicely already\nexport const printErr = (\n err: unknown,\n usage: CommandUsage,\n stderr: (...a: unknown[]) => void,\n) => {\n if (!isErrorRoot(err)) {\n // TODO: print _something_ here, but we're in weird broken territory\n // don't just dump it and flood the terminal, though, maybe sniff for code\n // message, stack, etc?\n return\n }\n if (isErrorRoot(err) && print(err, usage, stderr)) return\n stderr(err)\n}\n\nconst print = (\n err: ErrorWithCauseObject,\n usage: CommandUsage,\n stderr: (...a: unknown[]) => void,\n): boolean => {\n switch (err.cause.code) {\n case 'EUSAGE': {\n stderr(usage().usage())\n stderr(`Error: ${err.message}`)\n if (err.cause.found) {\n stderr(` Found: ${err.cause.found}`)\n }\n if (err.cause.validOptions) {\n stderr(\n ` Valid options: ${err.cause.validOptions.join(', ')}`,\n )\n }\n return true\n }\n\n case 'ERESOLVE': {\n stderr(`Resolve Error: ${err.message}`)\n const { url, from, response, spec } = err.cause\n if (url) {\n stderr(` While fetching: ${url}`)\n }\n if (spec) {\n stderr(` To satisfy: ${spec as string | Spec}`)\n }\n if (from) {\n stderr(` From: ${from}`)\n }\n if (response) {\n stderr('Response:', response)\n }\n return true\n }\n }\n\n return false\n}\n"]}
1
+ {"version":3,"file":"print-err.js","sourceRoot":"","sources":["../../src/print-err.ts"],"names":[],"mappings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CAAA;YACzC,CAAC;YACD,IAAI,OAAO,EAAE,CAAC;gBACZ,MAAM,CAAC,MAAM,CAAC,YAAY,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAA;YAC/C,CAAC;YACD,IAAI,GAAG,EAAE,CAAC;gBACR,MAAM,CAAC,MAAM,CAAC,QAAQ,SAAS,CAAC,GAAG,EAAE,MAAM,CAAC,EAAE,CAAC,CAAC,CAAA;YAClD,CAAC;YACD,IAAI,MAAM,EAAE,CAAC;gBACX,MAAM,CAAC,MAAM,CAAC,WAAW,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAA;YAC7C,CAAC;YACD,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,CAAA;QACvB,CAAC;QAED,KAAK,SAAS,CAAC,CAAC,CAAC;YACf,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,GAAG,GAAG,CAAC,KAAK,CAAA;YACjD,MAAM,CAAC,iBAAiB,GAAG,CAAC,OAAO,EAAE,CAAC,CAAA;YACtC,IAAI,KAAK,EAAE,CAAC;gBACV,MAAM,CAAC,MAAM,CAAC,UAAU,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAA;YAC3C,CAAC;YACD,IAAI,MAAM,EAAE,CAAC;gBACX,MAAM,CAAC,MAAM,CAAC,WAAW,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAA;YAC7C,CAAC;YACD,IAAI,YAAY,EAAE,CAAC;gBACjB,MAAM,CAAC,MAAM,CAAC,kBAAkB,MAAM,CAAC,YAAY,CAAC,EAAE,CAAC,CAAC,CAAA;YAC1D,CAAC;YACD,OAAO,EAAE,CAAA;QACX,CAAC;IACH,CAAC;AACH,CAAC,CAAA","sourcesContent":["import { splitDepID } from '@vltpkg/dep-id'\nimport type { Node } from '@vltpkg/graph'\nimport type { ParsedError } from '@vltpkg/output/error'\nimport { parseError } from '@vltpkg/output/error'\nimport { isErrorWithCause, isObject } from '@vltpkg/types'\nimport { XDG } from '@vltpkg/xdg'\nimport { isGraphRunError } from 'graph-run'\nimport { mkdirSync, writeFileSync } from 'node:fs'\nimport { join } from 'node:path'\nimport type { InspectOptions } from 'node:util'\nimport { formatWithOptions } from 'node:util'\nimport type { CommandUsage } from './index.ts'\n\nexport const formatOptions = {\n depth: Infinity,\n maxArrayLength: Infinity,\n maxStringLength: Infinity,\n} as const satisfies InspectOptions\n\nexport type ErrorFormatOptions = InspectOptions & {\n maxLines?: number\n}\n\nexport type Formatter = (\n arg: unknown,\n options?: ErrorFormatOptions,\n) => string\n\nconst isNonEmptyString = (v: unknown): v is string =>\n !!v && typeof v === 'string'\n\nconst formatURL = (v: unknown, format: Formatter) =>\n v instanceof URL ? v.toString() : /* c8 ignore next */ format(v)\n\nconst formatArray = (v: unknown, format: Formatter, joiner = ', ') =>\n Array.isArray(v) ? v.join(joiner) : /* c8 ignore next */ format(v)\n\nexport const indent = (lines: string, num = 2) =>\n lines\n .split('\\n')\n .map(l => ' '.repeat(num) + l)\n .join('\\n')\n\nconst writeErrorLog = (e: unknown, format: Formatter) => {\n try {\n const dir = new XDG('vlt/error-logs').data()\n const file = join(dir, `error-${process.pid}.log`)\n mkdirSync(dir, { recursive: true })\n writeFileSync(\n file,\n format(e, {\n colors: false,\n maxLines: Infinity,\n }),\n )\n return file\n } catch {\n return null\n }\n}\n\nexport const printErr = (\n e: 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 } = {\n ...formatOptions,\n ...baseOpts,\n ...opts,\n }\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 const err = parseError(e)\n const knownError = printCode(err, usage, stderr, format)\n const fileWritten =\n !knownError || knownError.file ? writeErrorLog(e, format) : null\n\n // We could not write an error log and its not a know error,\n // so we print the entire formatted value.\n if (!fileWritten && !knownError) {\n return stderr(format(e))\n }\n\n if (err && !knownError) {\n stderr(`${err.name}: ${err.message}`)\n }\n if (fileWritten) {\n stderr('')\n stderr(`Full details written to: ${fileWritten}`)\n }\n if (!knownError || knownError.bug) {\n stderr('')\n stderr('Open an issue with the full error details at:')\n stderr(indent('https://github.com/vltpkg/vltpkg/issues/new'))\n }\n}\n\nconst printCode = (\n err: ParsedError | null,\n usage: CommandUsage,\n stderr: (...a: string[]) => void,\n format: Formatter,\n): void | { bug?: boolean; file?: boolean } => {\n if (!err) return\n\n switch (err.cause?.code) {\n case 'GRAPHRUN_TRAVERSAL': {\n if (!isGraphRunError<Node>(err)) break\n const { node, path, cause } = err.cause\n stderr(\n `Graph traversal failure at: ${splitDepID(node.id).join(' ')}`,\n )\n if (Array.isArray(path) && path.length) {\n stderr(indent(`Path: ${path.map(n => n.id).join(',')}`))\n }\n if (\n isErrorWithCause(cause) &&\n isObject(cause.cause) &&\n 'command' in cause.cause &&\n 'stdout' in cause.cause &&\n 'stderr' in cause.cause &&\n 'status' in cause.cause &&\n 'signal' in cause.cause &&\n 'cwd' in cause.cause\n ) {\n const {\n command,\n args,\n cwd,\n stdout: cmdStdout,\n stderr: cmdStderr,\n status,\n signal,\n } = cause.cause\n stderr(`Command: ${command}`)\n if (args && Array.isArray(args) && args.length) {\n stderr(\n `Args: ${args.map(a => JSON.stringify(a)).join(', ')}`,\n )\n }\n stderr(`Cwd: ${cwd}`)\n\n if (cmdStderr || cmdStdout) {\n stderr('')\n if (isNonEmptyString(cmdStderr)) {\n stderr(cmdStderr)\n }\n if (isNonEmptyString(cmdStdout)) {\n stderr(cmdStdout)\n }\n stderr('')\n }\n\n if (signal !== null) stderr(`Signal: ${format(signal)}`)\n if (status !== null) stderr(`Status: ${format(status)}`)\n }\n return { file: true }\n }\n\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(\n `Valid options: ${formatArray(validOptions, format)}`,\n ),\n )\n }\n return {}\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: ${formatURL(url, format)}`))\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 { file: true }\n }\n\n case 'EREQUEST': {\n const { url, method } = err.cause\n const { code, syscall } = err.cause.cause ?? {}\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: ${formatURL(url, format)}`))\n }\n if (method) {\n stderr(indent(`Method: ${format(method)}`))\n }\n return { file: true }\n }\n\n case 'ECONFIG': {\n const { found, wanted, validOptions } = err.cause\n stderr(`Config Error: ${err.message}`)\n if (found) {\n stderr(indent(`Found: ${format(found)}`))\n }\n if (wanted) {\n stderr(indent(`Wanted: ${format(wanted)}`))\n }\n if (validOptions) {\n stderr(indent(`Valid Options: ${format(validOptions)}`))\n }\n return {}\n }\n }\n}\n"]}
@@ -0,0 +1,16 @@
1
+ import { SecurityArchive } from '@vltpkg/security-archive';
2
+ import type { EdgeLike, NodeLike } from '@vltpkg/types';
3
+ import type { LoadedConfig } from './config/index.ts';
4
+ export type HostContextsMapResult = {
5
+ initialEdges: EdgeLike[];
6
+ initialNodes: NodeLike[];
7
+ edges: EdgeLike[];
8
+ nodes: NodeLike[];
9
+ securityArchive: SecurityArchive;
10
+ };
11
+ /**
12
+ * Creates a Map of host context functions that can be used by the :host
13
+ * pseudo selector to dynamically load graphs from different sources.
14
+ */
15
+ export declare const createHostContextsMap: (conf: LoadedConfig) => Promise<Map<string, () => Promise<HostContextsMapResult>>>;
16
+ //# sourceMappingURL=query-host-contexts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"query-host-contexts.d.ts","sourceRoot":"","sources":["../../src/query-host-contexts.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAA;AAG1D,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACvD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAErD,MAAM,MAAM,qBAAqB,GAAG;IAClC,YAAY,EAAE,QAAQ,EAAE,CAAA;IACxB,YAAY,EAAE,QAAQ,EAAE,CAAA;IACxB,KAAK,EAAE,QAAQ,EAAE,CAAA;IACjB,KAAK,EAAE,QAAQ,EAAE,CAAA;IACjB,eAAe,EAAE,eAAe,CAAA;CACjC,CAAA;AA8CD;;;GAGG;AACH,eAAO,MAAM,qBAAqB,SAC1B,YAAY,KACjB,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,OAAO,CAAC,qBAAqB,CAAC,CAAC,CAiH3D,CAAA"}
@@ -0,0 +1,135 @@
1
+ import { homedir } from 'node:os';
2
+ import { parse, posix } from 'node:path';
3
+ import { getProjectData, readProjectFolders, reloadConfig, } from '@vltpkg/server';
4
+ import { actual, createVirtualRoot } from '@vltpkg/graph';
5
+ import { SecurityArchive } from '@vltpkg/security-archive';
6
+ import { error } from '@vltpkg/error-cause';
7
+ // In restricted environments (like locked-down Codespaces),
8
+ // homedir() might fail. Fall back to parent directory.
9
+ let foundHome;
10
+ try {
11
+ foundHome = posix.format(parse(homedir()));
12
+ /* c8 ignore next 3 */
13
+ }
14
+ catch { }
15
+ const home = foundHome ?? posix.dirname(posix.format(parse(process.cwd())));
16
+ /**
17
+ * Generates possible project keys for a given folder.
18
+ */
19
+ const getPossibleProjectKeys = (folder, scurry) => {
20
+ const relativePath = posix.relative(scurry.cwd.fullpathPosix(), folder.fullpathPosix());
21
+ const absolutePath = folder.fullpathPosix();
22
+ const homeRelativePath = posix.relative(scurry.resolvePosix(home), folder.fullpathPosix());
23
+ const dotRelativeKey = relativePath === '' ? 'file:.' : `file:./${relativePath}`;
24
+ const relativeKey = `file:${relativePath}`;
25
+ const absoluteKey = `file:${absolutePath}`;
26
+ const homeRelativeKey = `file:~/${homeRelativePath}`;
27
+ const keys = [
28
+ relativeKey,
29
+ dotRelativeKey,
30
+ absoluteKey,
31
+ homeRelativeKey,
32
+ `${relativeKey}/`,
33
+ `${dotRelativeKey}/`,
34
+ `${absoluteKey}/`,
35
+ `${homeRelativeKey}/`,
36
+ ];
37
+ return new Set(keys);
38
+ };
39
+ /**
40
+ * Creates a Map of host context functions that can be used by the :host
41
+ * pseudo selector to dynamically load graphs from different sources.
42
+ */
43
+ export const createHostContextsMap = async (conf) => {
44
+ const hostContexts = new Map();
45
+ // Read all project folders from the configured paths
46
+ const { scurry } = conf.options;
47
+ const projectFolders = await readProjectFolders({
48
+ scurry,
49
+ userDefinedProjectPaths: conf.options['dashboard-root'] ?? [],
50
+ });
51
+ for (const folder of projectFolders) {
52
+ const retrieveProjectGraph = async () => {
53
+ const initialEdges = [];
54
+ const initialNodes = [];
55
+ const config = await reloadConfig(folder.fullpath());
56
+ // load each individual graph
57
+ const graph = actual.load({
58
+ ...config.options,
59
+ projectRoot: folder.fullpath(),
60
+ skipLoadingNodesOnModifiersChange: false,
61
+ });
62
+ initialEdges.push(...graph.edges);
63
+ initialNodes.push(...graph.nodes.values());
64
+ // Initialize security archive with all loaded nodes
65
+ const securityArchive = await SecurityArchive.start({
66
+ nodes: initialNodes,
67
+ });
68
+ return {
69
+ initialEdges,
70
+ initialNodes,
71
+ edges: [],
72
+ nodes: [graph.mainImporter],
73
+ securityArchive,
74
+ };
75
+ };
76
+ // add multiple keys for each project folder
77
+ for (const path of getPossibleProjectKeys(folder, scurry)) {
78
+ if (!hostContexts.has(path)) {
79
+ hostContexts.set(path, retrieveProjectGraph);
80
+ }
81
+ }
82
+ }
83
+ // Define local context - loads graphs from all projects in user's project paths
84
+ hostContexts.set('local', async () => {
85
+ // Load graphs from each project folder
86
+ const initialEdges = [];
87
+ const initialNodes = [];
88
+ const mainImporters = [];
89
+ for (const folder of projectFolders) {
90
+ try {
91
+ const config = await reloadConfig(folder.fullpath());
92
+ const projectInfo = getProjectData({
93
+ packageJson: config.options.packageJson,
94
+ scurry: config.options.scurry,
95
+ }, folder);
96
+ // only include projects that are vlt-installed
97
+ if (!projectInfo.vltInstalled) {
98
+ continue;
99
+ }
100
+ // load each individual graph
101
+ const graph = actual.load({
102
+ ...config.options,
103
+ projectRoot: folder.fullpath(),
104
+ skipLoadingNodesOnModifiersChange: false,
105
+ });
106
+ initialEdges.push(...graph.edges);
107
+ initialNodes.push(...graph.nodes.values());
108
+ mainImporters.push(graph.mainImporter);
109
+ }
110
+ catch (_error) {
111
+ // Skip projects that fail to load
112
+ // This might happen for projects without proper package.json
113
+ // or other loading issues
114
+ continue;
115
+ }
116
+ }
117
+ // Initialize security archive with all loaded nodes
118
+ const securityArchive = await SecurityArchive.start({
119
+ nodes: initialNodes,
120
+ });
121
+ const virtualRoot = createVirtualRoot('local', conf.options, mainImporters);
122
+ if (!virtualRoot) {
123
+ throw error('Failed to create virtual root for local context');
124
+ }
125
+ return {
126
+ initialEdges,
127
+ initialNodes,
128
+ edges: [],
129
+ nodes: [virtualRoot],
130
+ securityArchive,
131
+ };
132
+ });
133
+ return hostContexts;
134
+ };
135
+ //# sourceMappingURL=query-host-contexts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"query-host-contexts.js","sourceRoot":"","sources":["../../src/query-host-contexts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AACjC,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,WAAW,CAAA;AACxC,OAAO,EACL,cAAc,EACd,kBAAkB,EAClB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gBACF,YAAY,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,CAAA;gBACjC,YAAY,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,CAAA;gBAC1C,aAAa,CAAC,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,CAAA;YACxC,CAAC;YAAC,OAAO,MAAM,EAAE,CAAC;gBAChB,kCAAkC;gBAClC,6DAA6D;gBAC7D,0BAA0B;gBAC1B,SAAQ;YACV,CAAC;QACH,CAAC;QAED,oDAAoD;QACpD,MAAM,eAAe,GAAG,MAAM,eAAe,CAAC,KAAK,CAAC;YAClD,KAAK,EAAE,YAAY;SACpB,CAAC,CAAA;QAEF,MAAM,WAAW,GAAG,iBAAiB,CACnC,OAAO,EACP,IAAI,CAAC,OAAO,EACZ,aAAa,CACd,CAAA;QAED,IAAI,CAAC,WAAW,EAAE,CAAC;YACjB,MAAM,KAAK,CAAC,iDAAiD,CAAC,CAAA;QAChE,CAAC;QAED,OAAO;YACL,YAAY;YACZ,YAAY;YACZ,KAAK,EAAE,EAAE;YACT,KAAK,EAAE,CAAC,WAAW,CAAC;YACpB,eAAe;SAChB,CAAA;IACH,CAAC,CAAC,CAAA;IAEF,OAAO,YAAY,CAAA;AACrB,CAAC,CAAA","sourcesContent":["import { homedir } from 'node:os'\nimport { parse, posix } from 'node:path'\nimport {\n getProjectData,\n readProjectFolders,\n reloadConfig,\n} from '@vltpkg/server'\nimport { actual, createVirtualRoot } from '@vltpkg/graph'\nimport { SecurityArchive } from '@vltpkg/security-archive'\nimport { error } from '@vltpkg/error-cause'\nimport type { PathBase, PathScurry } from 'path-scurry'\nimport type { EdgeLike, NodeLike } from '@vltpkg/types'\nimport type { LoadedConfig } from './config/index.ts'\n\nexport type HostContextsMapResult = {\n initialEdges: EdgeLike[]\n initialNodes: NodeLike[]\n edges: EdgeLike[]\n nodes: NodeLike[]\n securityArchive: SecurityArchive\n}\n\n// In restricted environments (like locked-down Codespaces),\n// homedir() might fail. Fall back to parent directory.\nlet foundHome\ntry {\n foundHome = posix.format(parse(homedir()))\n /* c8 ignore next 3 */\n} catch {}\nconst home =\n foundHome ?? posix.dirname(posix.format(parse(process.cwd())))\n\n/**\n * Generates possible project keys for a given folder.\n */\nconst getPossibleProjectKeys = (\n folder: PathBase,\n scurry: PathScurry,\n): Set<string> => {\n const relativePath = posix.relative(\n scurry.cwd.fullpathPosix(),\n folder.fullpathPosix(),\n )\n const absolutePath = folder.fullpathPosix()\n const homeRelativePath = posix.relative(\n scurry.resolvePosix(home),\n folder.fullpathPosix(),\n )\n const dotRelativeKey =\n relativePath === '' ? 'file:.' : `file:./${relativePath}`\n const relativeKey = `file:${relativePath}`\n const absoluteKey = `file:${absolutePath}`\n const homeRelativeKey = `file:~/${homeRelativePath}`\n const keys = [\n relativeKey,\n dotRelativeKey,\n absoluteKey,\n homeRelativeKey,\n `${relativeKey}/`,\n `${dotRelativeKey}/`,\n `${absoluteKey}/`,\n `${homeRelativeKey}/`,\n ]\n return new Set(keys)\n}\n\n/**\n * Creates a Map of host context functions that can be used by the :host\n * pseudo selector to dynamically load graphs from different sources.\n */\nexport const createHostContextsMap = async (\n conf: LoadedConfig,\n): Promise<Map<string, () => Promise<HostContextsMapResult>>> => {\n const hostContexts = new Map<\n string,\n () => Promise<HostContextsMapResult>\n >()\n // Read all project folders from the configured paths\n const { scurry } = conf.options\n const projectFolders = await readProjectFolders({\n scurry,\n userDefinedProjectPaths: conf.options['dashboard-root'] ?? [],\n })\n\n for (const folder of projectFolders) {\n const retrieveProjectGraph = async () => {\n const initialEdges: EdgeLike[] = []\n const initialNodes: NodeLike[] = []\n const config = await reloadConfig(folder.fullpath())\n\n // load each individual graph\n const graph = actual.load({\n ...config.options,\n projectRoot: folder.fullpath(),\n skipLoadingNodesOnModifiersChange: false,\n })\n initialEdges.push(...graph.edges)\n initialNodes.push(...graph.nodes.values())\n\n // Initialize security archive with all loaded nodes\n const securityArchive = await SecurityArchive.start({\n nodes: initialNodes,\n })\n\n return {\n initialEdges,\n initialNodes,\n edges: [],\n nodes: [graph.mainImporter],\n securityArchive,\n }\n }\n\n // add multiple keys for each project folder\n for (const path of getPossibleProjectKeys(folder, scurry)) {\n if (!hostContexts.has(path)) {\n hostContexts.set(path, retrieveProjectGraph)\n }\n }\n }\n\n // Define local context - loads graphs from all projects in user's project paths\n hostContexts.set('local', async () => {\n // Load graphs from each project folder\n const initialEdges: EdgeLike[] = []\n const initialNodes: NodeLike[] = []\n const mainImporters: NodeLike[] = []\n for (const folder of projectFolders) {\n try {\n const config = await reloadConfig(folder.fullpath())\n const projectInfo = getProjectData(\n {\n packageJson: config.options.packageJson,\n scurry: config.options.scurry,\n },\n folder,\n )\n\n // only include projects that are vlt-installed\n if (!projectInfo.vltInstalled) {\n continue\n }\n\n // load each individual graph\n const graph = actual.load({\n ...config.options,\n projectRoot: folder.fullpath(),\n skipLoadingNodesOnModifiersChange: false,\n })\n initialEdges.push(...graph.edges)\n initialNodes.push(...graph.nodes.values())\n mainImporters.push(graph.mainImporter)\n } catch (_error) {\n // Skip projects that fail to load\n // This might happen for projects without proper package.json\n // or other loading issues\n continue\n }\n }\n\n // Initialize security archive with all loaded nodes\n const securityArchive = await SecurityArchive.start({\n nodes: initialNodes,\n })\n\n const virtualRoot = createVirtualRoot(\n 'local',\n conf.options,\n mainImporters,\n )\n\n if (!virtualRoot) {\n throw error('Failed to create virtual root for local context')\n }\n\n return {\n initialEdges,\n initialNodes,\n edges: [],\n nodes: [virtualRoot],\n securityArchive,\n }\n })\n\n return hostContexts\n}\n"]}
@@ -1,6 +1,7 @@
1
1
  import type { PathScurry } from 'path-scurry';
2
2
  import type { LoadedConfig } from './config/index.ts';
3
3
  export declare const getDefaultStartingRoute: (options: {
4
+ queryString?: string;
4
5
  startingRoute?: string;
5
6
  projectRoot: string;
6
7
  scurry: PathScurry;
@@ -1 +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"}
1
+ {"version":3,"file":"start-gui.d.ts","sourceRoot":"","sources":["../../src/start-gui.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAC7C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAGrD,eAAO,MAAM,uBAAuB,YAAmB;IACrD,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,WAAW,EAAE,MAAM,CAAA;IACnB,MAAM,EAAE,UAAU,CAAA;CACnB,oBAYA,CAAA;AAaD,eAAO,MAAM,QAAQ,SACb,YAAY,kBACF,MAAM,gDA0CvB,CAAA"}
@@ -1,14 +1,15 @@
1
+ import { resolve } from 'node:path';
2
+ import LZString from 'lz-string';
1
3
  import { createServer } from '@vltpkg/server';
2
4
  import { urlOpen } from '@vltpkg/url-open';
3
5
  import { stdout } from "./output.js";
4
- import { resolve } from 'node:path';
5
6
  export const getDefaultStartingRoute = async (options) => {
6
- const { startingRoute, projectRoot, scurry } = options;
7
+ const { queryString = ':root', startingRoute, projectRoot, scurry, } = options;
7
8
  if (startingRoute)
8
9
  return startingRoute;
9
10
  const stat = await scurry.lstat(`${projectRoot}/package.json`);
10
11
  return stat?.isFile() && !stat.isSymbolicLink() ?
11
- `/explore?query=${encodeURIComponent(':root')}`
12
+ `/explore/${LZString.compressToEncodedURIComponent(queryString)}/overview`
12
13
  : '/';
13
14
  };
14
15
  const getAssetsDir = () => {
@@ -19,18 +20,36 @@ const getAssetsDir = () => {
19
20
  /* c8 ignore stop */
20
21
  };
21
22
  export const startGUI = async (conf, startingRoute) => {
23
+ /* c8 ignore start */
24
+ const allowScripts = conf.get('allow-scripts') ?
25
+ String(conf.get('allow-scripts'))
26
+ : ':not(*)';
27
+ /* c8 ignore stop */
22
28
  const server = createServer({
23
29
  ...conf.options,
24
30
  assetsDir: getAssetsDir(),
31
+ loadedConfig: conf,
32
+ allowScripts,
25
33
  });
26
- server.on('needConfigUpdate', dir => {
34
+ server.on('needConfigUpdate', async (dir) => {
27
35
  conf.resetOptions(dir);
28
- server.updateOptions(conf.options);
36
+ const listeningServer = server;
37
+ listeningServer.updateOptions({ ...conf.options, allowScripts });
38
+ await conf
39
+ .reloadFromDisk()
40
+ .then(() => {
41
+ listeningServer.updateOptions({
42
+ ...conf.options,
43
+ allowScripts,
44
+ });
45
+ })
46
+ .catch(() => { });
29
47
  });
30
48
  const { projectRoot, scurry } = conf.options;
31
49
  await server.start();
32
- stdout(`⚡️ vlt GUI running at ${server.address()}`);
50
+ stdout(`⚡️ vlt UI running at ${server.address()}`);
33
51
  void urlOpen(server.address(await getDefaultStartingRoute({
52
+ queryString: conf.values.target,
34
53
  startingRoute,
35
54
  projectRoot,
36
55
  scurry,
@@ -1 +1 @@
1
- {"version":3,"file":"start-gui.js","sourceRoot":"","sources":["../../src/start-gui.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAC7C,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA;AAG1C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAEnC,MAAM,CAAC,MAAM,uBAAuB,GAAG,KAAK,EAAE,OAI7C,EAAE,EAAE;IACH,MAAM,EAAE,aAAa,EAAE,WAAW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uB,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"]}
1
+ {"version":3,"file":"start-gui.js","sourceRoot":"","sources":["../../src/start-gui.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACnC,OAAO,QAAQ,MAAM,WAAW,CAAA;AAChC,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAC7C,OAAO,EAAE,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AAA;IACF,MAAM,CAAC,EAAE,CAAC,kBAAkB,EAAE,KAAK,EAAC,GAAG,EAAC,EAAE;QACxC,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,CAAA;QACtB,MAAM,eAAe,GAAG,MAA4B,CAAA;QACpD,eAAe,CAAC,aAAa,CAAC,EAAE,GAAG,IAAI,CAAC,OAAO,EAAE,YAAY,EAAE,CAAC,CAAA;QAChE,MAAM,IAAI;aACP,cAAc,EAAE;aAChB,IAAI,CAAC,GAAG,EAAE;YACT,eAAe,CAAC,aAAa,CAAC;gBAC5B,GAAG,IAAI,CAAC,OAAO;gBACf,YAAY;aACb,CAAC,CAAA;QACJ,CAAC,CAAC;aACD,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAA;IACpB,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,wBAAwB,MAAM,CAAC,OAAO,EAAE,EAAE,CAAC,CAAA;IAClD,KAAK,OAAO,CACV,MAAM,CAAC,OAAO,CACZ,MAAM,uBAAuB,CAAC;QAC5B,WAAW,EAAE,IAAI,CAAC,MAAM,CAAC,MAAM;QAC/B,aAAa;QACb,WAAW;QACX,MAAM;KACP,CAAC,CACH,CACF,CAAA;IACD,OAAO,MAAM,CAAA;AACf,CAAC,CAAA","sourcesContent":["import { resolve } from 'node:path'\nimport LZString from 'lz-string'\nimport { createServer } from '@vltpkg/server'\nimport { urlOpen } from '@vltpkg/url-open'\nimport { stdout } from './output.ts'\nimport type { PathScurry } from 'path-scurry'\nimport type { LoadedConfig } from './config/index.ts'\nimport type { VltServerListening } from '@vltpkg/server'\n\nexport const getDefaultStartingRoute = async (options: {\n queryString?: string\n startingRoute?: string\n projectRoot: string\n scurry: PathScurry\n}) => {\n const {\n queryString = ':root',\n startingRoute,\n projectRoot,\n scurry,\n } = options\n if (startingRoute) return startingRoute\n const stat = await scurry.lstat(`${projectRoot}/package.json`)\n return stat?.isFile() && !stat.isSymbolicLink() ?\n `/explore/${LZString.compressToEncodedURIComponent(queryString)}/overview`\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 /* c8 ignore start */\n const allowScripts =\n conf.get('allow-scripts') ?\n String(conf.get('allow-scripts'))\n : ':not(*)'\n /* c8 ignore stop */\n const server = createServer({\n ...conf.options,\n assetsDir: getAssetsDir(),\n loadedConfig: conf,\n allowScripts,\n })\n server.on('needConfigUpdate', async dir => {\n conf.resetOptions(dir)\n const listeningServer = server as VltServerListening\n listeningServer.updateOptions({ ...conf.options, allowScripts })\n await conf\n .reloadFromDisk()\n .then(() => {\n listeningServer.updateOptions({\n ...conf.options,\n allowScripts,\n })\n })\n .catch(() => {})\n })\n const { projectRoot, scurry } = conf.options\n await server.start()\n stdout(`⚡️ vlt UI running at ${server.address()}`)\n void urlOpen(\n server.address(\n await getDefaultStartingRoute({\n queryString: conf.values.target,\n startingRoute,\n projectRoot,\n scurry,\n }),\n ),\n )\n return server\n}\n"]}
@@ -1,7 +1,6 @@
1
- import type { ChalkInstance } from 'chalk';
2
1
  import type { LoadedConfig } from './config/index.ts';
3
2
  export type ViewOptions = {
4
- colors?: ChalkInstance;
3
+ colors?: boolean;
5
4
  };
6
5
  /**
7
6
  * The base class for all View classes
@@ -21,7 +20,7 @@ export declare class ViewClass<T = unknown> {
21
20
  start(): void;
22
21
  done(_result: T, _opts: {
23
22
  time: number;
24
- }): undefined | string;
23
+ }): Promise<unknown>;
25
24
  error(_err: unknown): void;
26
25
  }
27
26
  export type ViewFn<T = unknown> = (result: T, options: ViewOptions, conf: LoadedConfig) => unknown;
@@ -1 +1 @@
1
- {"version":3,"file":"view.d.ts","sourceRoot":"","sources":["../../src/view.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAA;AAC1C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAErD,MAAM,MAAM,WAAW,GAAG;IAAE,MAAM,CAAC,EAAE,aAAa,CAAA;CAAE,CAAA;AAEpD;;;;;;;;;;GAUG;AACH,qBAAa,SAAS,CAAC,CAAC,GAAG,OAAO;IAChC,OAAO,EAAE,WAAW,CAAA;IACpB,MAAM,EAAE,YAAY,CAAA;gBAER,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,YAAY;IAQtD,KAAK;IACL,IAAI,CAAC,OAAO,EAAE,CAAC,EAAE,KAAK,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,GAAG,SAAS,GAAG,MAAM;IAG7D,KAAK,CAAC,IAAI,EAAE,OAAO;CACpB;AAED,MAAM,MAAM,MAAM,CAAC,CAAC,GAAG,OAAO,IAAI,CAChC,MAAM,EAAE,CAAC,EACT,OAAO,EAAE,WAAW,EACpB,IAAI,EAAE,YAAY,KACf,OAAO,CAAA;AAEZ,MAAM,MAAM,IAAI,CAAC,CAAC,GAAG,OAAO,IAAI,MAAM,CAAC,CAAC,CAAC,GAAG,OAAO,SAAS,CAAC,CAAC,CAAC,CAAA;AAE/D,eAAO,MAAM,WAAW,GAAI,CAAC,kBACrB,IAAI,CAAC,CAAC,CAAC,KACZ,IAAI,IAAI,OAAO,SAAS,CAAC,CAAC,CAGQ,CAAA;AAErC,MAAM,MAAM,KAAK,CAAC,CAAC,GAAG,OAAO,IAAI,IAAI,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,CAAA"}
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;IACC,IAAI,CAAC,OAAO,EAAE,CAAC,EAAE,KAAK,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,OAAO,CAAC;IAGjE,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"}
package/dist/esm/view.js CHANGED
@@ -20,7 +20,7 @@ export class ViewClass {
20
20
  // run the command", for example to have the gui just open a web browser
21
21
  // to the page relevant to a given thing, rather than computing it twice
22
22
  start() { }
23
- done(_result, _opts) {
23
+ async done(_result, _opts) {
24
24
  return;
25
25
  }
26
26
  error(_err) { }
@@ -1 +1 @@
1
- {"version":3,"file":"view.js","sourceRoot":"","sources":["../../src/view.ts"],"names":[],"mappings":"AAKA;;;;;;;;;;GAUG;AACH,MAAM,OAAO,SAAS;IACpB,OAAO,CAAa;IACpB,MAAM,CAAc;IAEpB,YAAY,OAAoB,EAAE,MAAoB;QACpD,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;IACtB,CAAC;IAED,oEAAoE;IACpE,wEAAwE;IACxE,wEAAwE;IACxE,KAAK,KAAI,CAAC;IACV,IAAI,CAAC,OAAU,EAAE,KAAuB;QACtC,OAAM;IACR,CAAC;IACD,KAAK,CAAC,IAAa,IAAG,CAAC;CACxB;AAUD,MAAM,CAAC,MAAM,WAAW,GAAG,CACzB,IAAa,EACgB,EAAE,CAC/B,OAAO,IAAI,KAAK,UAAU;IAC1B,WAAW,IAAI,IAAI;IACnB,IAAI,CAAC,SAAS,YAAY,SAAS,CAAA","sourcesContent":["import type { ChalkInstance } from 'chalk'\nimport type { LoadedConfig } from './config/index.ts'\n\nexport type ViewOptions = { colors?: ChalkInstance }\n\n/**\n * The base class for all View classes\n *\n * Do not override the constructor, just provide start/done/error methods.\n *\n * These classes should be used as one or more of the exported views for\n * commands that need to know when the processing starts, handle errors in\n * various ways, etc. Fancy stuff.\n *\n * For simple use cases, usually better to create a {@link ViewFn} instead.\n */\nexport class ViewClass<T = unknown> {\n options: ViewOptions\n config: LoadedConfig\n\n constructor(options: ViewOptions, config: LoadedConfig) {\n this.options = options\n this.config = config\n }\n\n // TODO: maybe have start() return a flag to say \"i got this, do not\n // run the command\", for example to have the gui just open a web browser\n // to the page relevant to a given thing, rather than computing it twice\n start() {}\n done(_result: T, _opts: { time: number }): undefined | string {\n return\n }\n error(_err: unknown) {}\n}\n\nexport type ViewFn<T = unknown> = (\n result: T,\n options: ViewOptions,\n conf: LoadedConfig,\n) => unknown\n\nexport type View<T = unknown> = ViewFn<T> | typeof ViewClass<T>\n\nexport const isViewClass = <T = unknown>(\n view: View<T>,\n): view is typeof ViewClass<T> =>\n typeof view === 'function' &&\n 'prototype' in view &&\n view.prototype instanceof ViewClass\n\nexport type Views<T = unknown> = View<T> | Record<string, View<T>>\n"]}
1
+ {"version":3,"file":"view.js","sourceRoot":"","sources":["../../src/view.ts"],"names":[],"mappings":"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,KAAK,CAAC,IAAI,CAAC,OAAU,EAAE,KAAuB;QAC5C,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 async done(_result: T, _opts: { time: number }): Promise<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"]}