@vltpkg/cli-sdk 1.0.0-rc.2 → 1.0.0-rc.22

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 (174) hide show
  1. package/package.json +66 -83
  2. package/dist/esm/commands/build.d.ts +0 -25
  3. package/dist/esm/commands/build.d.ts.map +0 -1
  4. package/dist/esm/commands/build.js +0 -102
  5. package/dist/esm/commands/build.js.map +0 -1
  6. package/dist/esm/commands/cache.d.ts +0 -65
  7. package/dist/esm/commands/cache.d.ts.map +0 -1
  8. package/dist/esm/commands/cache.js +0 -257
  9. package/dist/esm/commands/cache.js.map +0 -1
  10. package/dist/esm/commands/ci.d.ts +0 -11
  11. package/dist/esm/commands/ci.d.ts.map +0 -1
  12. package/dist/esm/commands/ci.js +0 -32
  13. package/dist/esm/commands/ci.js.map +0 -1
  14. package/dist/esm/commands/config.d.ts +0 -6
  15. package/dist/esm/commands/config.d.ts.map +0 -1
  16. package/dist/esm/commands/config.js +0 -424
  17. package/dist/esm/commands/config.js.map +0 -1
  18. package/dist/esm/commands/docs.d.ts +0 -18
  19. package/dist/esm/commands/docs.d.ts.map +0 -1
  20. package/dist/esm/commands/docs.js +0 -154
  21. package/dist/esm/commands/docs.js.map +0 -1
  22. package/dist/esm/commands/exec-cache.d.ts +0 -49
  23. package/dist/esm/commands/exec-cache.d.ts.map +0 -1
  24. package/dist/esm/commands/exec-cache.js +0 -146
  25. package/dist/esm/commands/exec-cache.js.map +0 -1
  26. package/dist/esm/commands/exec-local.d.ts +0 -6
  27. package/dist/esm/commands/exec-local.d.ts.map +0 -1
  28. package/dist/esm/commands/exec-local.js +0 -24
  29. package/dist/esm/commands/exec-local.js.map +0 -1
  30. package/dist/esm/commands/exec.d.ts +0 -9
  31. package/dist/esm/commands/exec.d.ts.map +0 -1
  32. package/dist/esm/commands/exec.js +0 -87
  33. package/dist/esm/commands/exec.js.map +0 -1
  34. package/dist/esm/commands/help.d.ts +0 -4
  35. package/dist/esm/commands/help.d.ts.map +0 -1
  36. package/dist/esm/commands/help.js +0 -39
  37. package/dist/esm/commands/help.js.map +0 -1
  38. package/dist/esm/commands/init.d.ts +0 -8
  39. package/dist/esm/commands/init.d.ts.map +0 -1
  40. package/dist/esm/commands/init.js +0 -111
  41. package/dist/esm/commands/init.js.map +0 -1
  42. package/dist/esm/commands/install/reporter.d.ts +0 -11
  43. package/dist/esm/commands/install/reporter.d.ts.map +0 -1
  44. package/dist/esm/commands/install/reporter.js +0 -94
  45. package/dist/esm/commands/install/reporter.js.map +0 -1
  46. package/dist/esm/commands/install.d.ts +0 -28
  47. package/dist/esm/commands/install.d.ts.map +0 -1
  48. package/dist/esm/commands/install.js +0 -45
  49. package/dist/esm/commands/install.js.map +0 -1
  50. package/dist/esm/commands/list.d.ts +0 -15
  51. package/dist/esm/commands/list.d.ts.map +0 -1
  52. package/dist/esm/commands/list.js +0 -199
  53. package/dist/esm/commands/list.js.map +0 -1
  54. package/dist/esm/commands/login.d.ts +0 -4
  55. package/dist/esm/commands/login.d.ts.map +0 -1
  56. package/dist/esm/commands/login.js +0 -13
  57. package/dist/esm/commands/login.js.map +0 -1
  58. package/dist/esm/commands/logout.d.ts +0 -4
  59. package/dist/esm/commands/logout.d.ts.map +0 -1
  60. package/dist/esm/commands/logout.js +0 -13
  61. package/dist/esm/commands/logout.js.map +0 -1
  62. package/dist/esm/commands/pack.d.ts +0 -32
  63. package/dist/esm/commands/pack.d.ts.map +0 -1
  64. package/dist/esm/commands/pack.js +0 -147
  65. package/dist/esm/commands/pack.js.map +0 -1
  66. package/dist/esm/commands/pkg.d.ts +0 -7
  67. package/dist/esm/commands/pkg.d.ts.map +0 -1
  68. package/dist/esm/commands/pkg.js +0 -206
  69. package/dist/esm/commands/pkg.js.map +0 -1
  70. package/dist/esm/commands/publish.d.ts +0 -22
  71. package/dist/esm/commands/publish.d.ts.map +0 -1
  72. package/dist/esm/commands/publish.js +0 -245
  73. package/dist/esm/commands/publish.js.map +0 -1
  74. package/dist/esm/commands/query.d.ts +0 -16
  75. package/dist/esm/commands/query.d.ts.map +0 -1
  76. package/dist/esm/commands/query.js +0 -214
  77. package/dist/esm/commands/query.js.map +0 -1
  78. package/dist/esm/commands/run-exec.d.ts +0 -6
  79. package/dist/esm/commands/run-exec.d.ts.map +0 -1
  80. package/dist/esm/commands/run-exec.js +0 -14
  81. package/dist/esm/commands/run-exec.js.map +0 -1
  82. package/dist/esm/commands/run.d.ts +0 -6
  83. package/dist/esm/commands/run.d.ts.map +0 -1
  84. package/dist/esm/commands/run.js +0 -36
  85. package/dist/esm/commands/run.js.map +0 -1
  86. package/dist/esm/commands/serve.d.ts +0 -14
  87. package/dist/esm/commands/serve.d.ts.map +0 -1
  88. package/dist/esm/commands/serve.js +0 -103
  89. package/dist/esm/commands/serve.js.map +0 -1
  90. package/dist/esm/commands/token.d.ts +0 -4
  91. package/dist/esm/commands/token.d.ts.map +0 -1
  92. package/dist/esm/commands/token.js +0 -30
  93. package/dist/esm/commands/token.js.map +0 -1
  94. package/dist/esm/commands/uninstall.d.ts +0 -16
  95. package/dist/esm/commands/uninstall.d.ts.map +0 -1
  96. package/dist/esm/commands/uninstall.js +0 -26
  97. package/dist/esm/commands/uninstall.js.map +0 -1
  98. package/dist/esm/commands/update.d.ts +0 -14
  99. package/dist/esm/commands/update.d.ts.map +0 -1
  100. package/dist/esm/commands/update.js +0 -41
  101. package/dist/esm/commands/update.js.map +0 -1
  102. package/dist/esm/commands/version.d.ts +0 -26
  103. package/dist/esm/commands/version.d.ts.map +0 -1
  104. package/dist/esm/commands/version.js +0 -226
  105. package/dist/esm/commands/version.js.map +0 -1
  106. package/dist/esm/commands/whoami.d.ts +0 -13
  107. package/dist/esm/commands/whoami.d.ts.map +0 -1
  108. package/dist/esm/commands/whoami.js +0 -19
  109. package/dist/esm/commands/whoami.js.map +0 -1
  110. package/dist/esm/config/definition.d.ts +0 -404
  111. package/dist/esm/config/definition.d.ts.map +0 -1
  112. package/dist/esm/config/definition.js +0 -657
  113. package/dist/esm/config/definition.js.map +0 -1
  114. package/dist/esm/config/index.d.ts +0 -219
  115. package/dist/esm/config/index.d.ts.map +0 -1
  116. package/dist/esm/config/index.js +0 -454
  117. package/dist/esm/config/index.js.map +0 -1
  118. package/dist/esm/config/merge.d.ts +0 -4
  119. package/dist/esm/config/merge.d.ts.map +0 -1
  120. package/dist/esm/config/merge.js +0 -28
  121. package/dist/esm/config/merge.js.map +0 -1
  122. package/dist/esm/config/usage.d.ts +0 -19
  123. package/dist/esm/config/usage.d.ts.map +0 -1
  124. package/dist/esm/config/usage.js +0 -40
  125. package/dist/esm/config/usage.js.map +0 -1
  126. package/dist/esm/custom-help.d.ts +0 -9
  127. package/dist/esm/custom-help.d.ts.map +0 -1
  128. package/dist/esm/custom-help.js +0 -400
  129. package/dist/esm/custom-help.js.map +0 -1
  130. package/dist/esm/exec-command.d.ts +0 -53
  131. package/dist/esm/exec-command.d.ts.map +0 -1
  132. package/dist/esm/exec-command.js +0 -308
  133. package/dist/esm/exec-command.js.map +0 -1
  134. package/dist/esm/index.d.ts +0 -4
  135. package/dist/esm/index.d.ts.map +0 -1
  136. package/dist/esm/index.js +0 -73
  137. package/dist/esm/index.js.map +0 -1
  138. package/dist/esm/load-command.d.ts +0 -16
  139. package/dist/esm/load-command.d.ts.map +0 -1
  140. package/dist/esm/load-command.js +0 -21
  141. package/dist/esm/load-command.js.map +0 -1
  142. package/dist/esm/output.d.ts +0 -21
  143. package/dist/esm/output.d.ts.map +0 -1
  144. package/dist/esm/output.js +0 -126
  145. package/dist/esm/output.js.map +0 -1
  146. package/dist/esm/pack-tarball.d.ts +0 -22
  147. package/dist/esm/pack-tarball.d.ts.map +0 -1
  148. package/dist/esm/pack-tarball.js +0 -249
  149. package/dist/esm/pack-tarball.js.map +0 -1
  150. package/dist/esm/package.json +0 -3
  151. package/dist/esm/parse-add-remove-args.d.ts +0 -22
  152. package/dist/esm/parse-add-remove-args.d.ts.map +0 -1
  153. package/dist/esm/parse-add-remove-args.js +0 -71
  154. package/dist/esm/parse-add-remove-args.js.map +0 -1
  155. package/dist/esm/print-err.d.ts +0 -14
  156. package/dist/esm/print-err.d.ts.map +0 -1
  157. package/dist/esm/print-err.js +0 -178
  158. package/dist/esm/print-err.js.map +0 -1
  159. package/dist/esm/query-host-contexts.d.ts +0 -16
  160. package/dist/esm/query-host-contexts.d.ts.map +0 -1
  161. package/dist/esm/query-host-contexts.js +0 -135
  162. package/dist/esm/query-host-contexts.js.map +0 -1
  163. package/dist/esm/read-password.d.ts +0 -8
  164. package/dist/esm/read-password.d.ts.map +0 -1
  165. package/dist/esm/read-password.js +0 -33
  166. package/dist/esm/read-password.js.map +0 -1
  167. package/dist/esm/start-gui.d.ts +0 -10
  168. package/dist/esm/start-gui.d.ts.map +0 -1
  169. package/dist/esm/start-gui.js +0 -60
  170. package/dist/esm/start-gui.js.map +0 -1
  171. package/dist/esm/view.d.ts +0 -30
  172. package/dist/esm/view.d.ts.map +0 -1
  173. package/dist/esm/view.js +0 -31
  174. package/dist/esm/view.js.map +0 -1
@@ -1,308 +0,0 @@
1
- /**
2
- * impl for `vlt run`, `vlt run-exec`, `vlt exec-local`, `vlt exec`
3
- * @module
4
- */
5
- import { error } from '@vltpkg/error-cause';
6
- import { isErrorWithCause } from '@vltpkg/types';
7
- import { Query } from '@vltpkg/query';
8
- import { actual } from '@vltpkg/graph';
9
- import { isRunResult } from '@vltpkg/run';
10
- import { Monorepo } from '@vltpkg/workspaces';
11
- import { ansiToAnsi } from 'ansi-to-pre';
12
- import { stderr, stdout, styleTextStdout } from "./output.js";
13
- import assert from 'node:assert';
14
- import { resolve } from 'node:path';
15
- import { createHostContextsMap } from "./query-host-contexts.js";
16
- const isScriptSet = (o) => {
17
- if (!o || typeof o !== 'object')
18
- return false;
19
- for (const v of Object.values(o)) {
20
- if (typeof v !== 'string')
21
- return false;
22
- }
23
- return true;
24
- };
25
- const isMultiScriptSet = (o) => {
26
- for (const v of Object.values(o)) {
27
- if (!isScriptSet(v))
28
- return false;
29
- }
30
- return true;
31
- };
32
- const isSingleSuccess = (o) => o.signal === null && o.status === 0;
33
- const setExitCode = (result) => {
34
- /* c8 ignore next */
35
- process.exitCode ||= result.status ?? 1;
36
- };
37
- export const views = {
38
- // run results for single or multiple will be printed along the way.
39
- human: result => {
40
- if (isScriptSet(result))
41
- stdout('Scripts available:', result);
42
- else if (isMultiScriptSet(result)) {
43
- stdout('Scripts available:');
44
- for (const [path, scripts] of Object.entries(result)) {
45
- stdout(path, scripts);
46
- }
47
- }
48
- },
49
- json: result => isRunResult(result) && isSingleSuccess(result) ?
50
- undefined
51
- : result,
52
- };
53
- export class ExecCommand {
54
- bg;
55
- fg;
56
- arg0;
57
- args;
58
- env;
59
- #monorepo;
60
- #nodes;
61
- #defaultIgnoreMissing = false;
62
- conf;
63
- projectRoot;
64
- view;
65
- validViewValues = new Map([
66
- ['human', 'human'],
67
- ['json', 'json'],
68
- ['inspect', 'inspect'],
69
- ['silent', 'silent'],
70
- ]);
71
- constructor(conf, bg, fg) {
72
- this.conf = conf;
73
- this.bg = bg;
74
- this.fg = fg;
75
- this.view = this.validViewValues.get(conf.values.view) ?? 'human';
76
- const { projectRoot, positionals: [arg0, ...args], } = conf;
77
- this.arg0 = arg0;
78
- this.args = args;
79
- this.projectRoot = projectRoot;
80
- }
81
- #targetCount() {
82
- if (this.#nodes)
83
- return this.#nodes.length;
84
- return this.#monorepo?.size ?? 1;
85
- }
86
- hasArg0() {
87
- return !!this.arg0;
88
- }
89
- async run() {
90
- const { conf } = this;
91
- const queryString = conf.get('scope');
92
- const paths = conf.get('workspace');
93
- const groups = conf.get('workspace-group');
94
- const recursive = conf.get('recursive');
95
- // scope takes precedence over workspaces or groups
96
- if (queryString) {
97
- this.#defaultIgnoreMissing = true;
98
- const mainManifest = conf.options.packageJson.maybeRead(this.projectRoot);
99
- let graph;
100
- if (mainManifest) {
101
- graph = actual.load({
102
- ...conf.options,
103
- mainManifest,
104
- monorepo: Monorepo.load(this.projectRoot),
105
- loadManifests: false,
106
- });
107
- }
108
- const hostContexts = await createHostContextsMap(conf);
109
- const query = new Query({
110
- /* c8 ignore start */
111
- nodes: graph ? new Set(graph.nodes.values()) : new Set(),
112
- edges: graph?.edges ?? new Set(),
113
- importers: graph?.importers ?? new Set(),
114
- /* c8 ignore stop */
115
- securityArchive: undefined,
116
- hostContexts,
117
- });
118
- const { nodes } = await query.search(queryString, {
119
- signal: new AbortController().signal,
120
- });
121
- this.#nodes = [];
122
- for (const node of nodes) {
123
- const { location } = node.toJSON();
124
- assert(location, error(`node ${node.id} has no location`, {
125
- found: node,
126
- }));
127
- this.#nodes.push(location);
128
- }
129
- }
130
- else if (paths?.length || groups?.length || recursive) {
131
- this.#defaultIgnoreMissing = true;
132
- this.#monorepo = Monorepo.load(this.projectRoot, {
133
- load: { paths, groups },
134
- });
135
- }
136
- if (this.#targetCount() === 1) {
137
- const arg = this.fgArg();
138
- if (!arg)
139
- return this.noArgsSingle();
140
- const result = await this.fg(arg);
141
- if (isRunResult(result)) {
142
- setExitCode(result);
143
- }
144
- return result;
145
- }
146
- if (this.#targetCount() === 0) {
147
- if (queryString) {
148
- throw error('no matching nodes found for query', {
149
- found: queryString,
150
- });
151
- }
152
- else {
153
- throw error('no matching workspaces found', {
154
- /* c8 ignore next - already guarded */
155
- validOptions: [...(this.#monorepo?.load().paths() ?? [])],
156
- });
157
- }
158
- }
159
- if (!this.hasArg0()) {
160
- return this.noArgsMulti();
161
- }
162
- // run across workspaces
163
- let failed = false;
164
- const runInDir = async (cwd, label) => {
165
- const result = await this.bg(this.bgArg(cwd)).catch((er) => {
166
- if (isErrorWithCause(er) && isRunResult(er.cause)) {
167
- this.printResult(label, er.cause);
168
- }
169
- failed = true;
170
- throw er;
171
- });
172
- // If we are allowed to ignore missing commands, then command might be
173
- // an emptry string. If so, we don't print anything and return null to
174
- // be filtered out later.
175
- if (!result.command)
176
- return null;
177
- if (!failed)
178
- this.printResult(label, result);
179
- return result;
180
- };
181
- const resultMap = new Map();
182
- if (this.#nodes) {
183
- for (const { label, cwd } of this.getTargets()) {
184
- const result = await runInDir(cwd, label);
185
- if (result)
186
- resultMap.set(label, result);
187
- }
188
- }
189
- else if (this.#monorepo) {
190
- const wsResultMap = await this.#monorepo.run(ws => runInDir(ws.fullpath, ws.path));
191
- for (const [ws, result] of wsResultMap) {
192
- if (result)
193
- resultMap.set(ws.path, result);
194
- }
195
- }
196
- const results = {};
197
- for (const [path, result] of resultMap) {
198
- if (result.status === 0 && result.signal === null) {
199
- result.stdout = '';
200
- result.stderr = '';
201
- }
202
- results[path] = result;
203
- }
204
- return results;
205
- }
206
- printResult(path, result) {
207
- // non-human results just get printed at the end
208
- if (this.view !== 'human')
209
- return;
210
- if (result.status === 0 && result.signal === null) {
211
- stdout(path, 'ok');
212
- }
213
- else {
214
- stdout(styleTextStdout(['bgWhiteBright', 'black', 'bold'], path + ' failure'), {
215
- status: result.status,
216
- signal: result.signal,
217
- });
218
- /* c8 ignore start */
219
- if (result.stderr)
220
- stderr(ansiToAnsi(result.stderr));
221
- if (result.stdout)
222
- stdout(ansiToAnsi(result.stdout));
223
- /* c8 ignore stop */
224
- setExitCode(result);
225
- }
226
- }
227
- /* c8 ignore start - env specific */
228
- interactiveShell() {
229
- return (process.env.SHELL ??
230
- this.conf.get('script-shell') ??
231
- (process.platform === 'win32' ? 'cmd.exe' : '/bin/sh'));
232
- }
233
- /* c8 ignore stop */
234
- // overridden by 'vlt run' which returns undefined
235
- defaultArg0() {
236
- return this.interactiveShell();
237
- }
238
- getCwd() {
239
- if (this.#nodes) {
240
- const [first] = this.#nodes;
241
- assert(first, error('no nodes found'));
242
- return resolve(this.projectRoot, first);
243
- }
244
- return (this.#monorepo?.values().next().value?.fullpath ??
245
- this.projectRoot);
246
- }
247
- fgArg() {
248
- const cwd = this.getCwd();
249
- const arg0 = this.arg0 ?? this.defaultArg0();
250
- // return undefined so noArgsSingle will be called instead
251
- if (typeof arg0 !== 'string')
252
- return;
253
- return {
254
- cwd,
255
- arg0,
256
- args: this.args,
257
- env: this.env,
258
- projectRoot: this.projectRoot,
259
- packageJson: this.conf.options.packageJson,
260
- 'script-shell': this.arg0 ? this.conf.get('script-shell') : false,
261
- };
262
- }
263
- bgArg(cwd) {
264
- return {
265
- cwd,
266
- acceptFail: !this.conf.get('bail'),
267
- ignoreMissing: this.conf.get('if-present') ?? this.#defaultIgnoreMissing,
268
- arg0: this.arg0,
269
- args: this.args,
270
- env: this.env,
271
- projectRoot: this.projectRoot,
272
- packageJson: this.conf.options.packageJson,
273
- 'script-shell': this.conf.get('script-shell'),
274
- };
275
- }
276
- /* c8 ignore start - not used, only here to override */
277
- noArgsSingle() {
278
- throw error('Failed to determine interactive shell to spawn');
279
- }
280
- /* c8 ignore stop - not used, only here to override */
281
- noArgsMulti() {
282
- throw error('Cannot spawn interactive shells in multiple workspaces');
283
- }
284
- getTargets() {
285
- const targets = [];
286
- if (this.#nodes) {
287
- for (const location of this.#nodes) {
288
- const manifest = this.conf.options.packageJson.read(location);
289
- const label =
290
- /* c8 ignore next */
291
- location.startsWith('./') ? location.slice(2) : location;
292
- const cwd = resolve(this.projectRoot, location);
293
- targets.push({ label, cwd, manifest });
294
- }
295
- }
296
- else if (this.#monorepo) {
297
- this.#monorepo.runSync(ws => {
298
- targets.push({
299
- label: ws.path,
300
- cwd: ws.fullpath,
301
- manifest: ws.manifest,
302
- });
303
- });
304
- }
305
- return targets;
306
- }
307
- }
308
- //# sourceMappingURL=exec-command.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"exec-command.js","sourceRoot":"","sources":["../../src/exec-command.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAC3C,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAA;AAehD,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAA;AACrC,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAA;AACtC,OAA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CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,QAAQ,EAAE,CAAC,CAAA;YACxC,CAAC;QACH,CAAC;aAAM,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;YAC1B,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE;gBAC1B,OAAO,CAAC,IAAI,CAAC;oBACX,KAAK,EAAE,EAAE,CAAC,IAAI;oBACd,GAAG,EAAE,EAAE,CAAC,QAAQ;oBAChB,QAAQ,EAAE,EAAE,CAAC,QAAQ;iBACtB,CAAC,CAAA;YACJ,CAAC,CAAC,CAAA;QACJ,CAAC;QACD,OAAO,OAAO,CAAA;IAChB,CAAC;CACF","sourcesContent":["/**\n * impl for `vlt run`, `vlt run-exec`, `vlt exec-local`, `vlt exec`\n * @module\n */\n\nimport { error } from '@vltpkg/error-cause'\nimport { isErrorWithCause } from '@vltpkg/types'\nimport type { NormalizedManifest } from '@vltpkg/types'\nimport type {\n exec,\n execFG,\n ExecOptions,\n run,\n runExec,\n runExecFG,\n RunExecOptions,\n runFG,\n RunFGResult,\n RunOptions,\n RunResult,\n} from '@vltpkg/run'\nimport { Query } from '@vltpkg/query'\nimport { actual } from '@vltpkg/graph'\nimport { isRunResult } from '@vltpkg/run'\nimport { Monorepo } from '@vltpkg/workspaces'\nimport { ansiToAnsi } from 'ansi-to-pre'\nimport type { LoadedConfig } from './config/index.ts'\nimport { stderr, stdout, styleTextStdout } from './output.ts'\nimport type { Views } from './view.ts'\nimport type { SpawnResultStdioStrings } from '@vltpkg/promise-spawn'\nimport assert from 'node:assert'\nimport { resolve } from 'node:path'\nimport { createHostContextsMap } from './query-host-contexts.ts'\n\nexport type RunnerBG = typeof exec | typeof run | typeof runExec\nexport type RunnerFG = typeof execFG | typeof runExecFG | typeof runFG\nexport type RunnerOptions = ExecOptions & RunExecOptions & RunOptions\nexport type MultiRunResult = Record<string, RunResult>\nexport type ScriptSet = Record<string, string>\nexport type MultiScriptSet = Record<string, ScriptSet>\nexport type ExecResult =\n | RunFGResult\n | MultiRunResult\n | ScriptSet\n | MultiScriptSet\n\nconst isScriptSet = (o: unknown): o is ScriptSet => {\n if (!o || typeof o !== 'object') return false\n for (const v of Object.values(o)) {\n if (typeof v !== 'string') return false\n }\n return true\n}\n\nconst isMultiScriptSet = (\n o: ExecResult,\n): o is Record<string, ScriptSet> => {\n for (const v of Object.values(o)) {\n if (!isScriptSet(v)) return false\n }\n return true\n}\n\nconst isSingleSuccess = (\n o: RunResult,\n): o is RunResult & { status: 0; signal: null } =>\n o.signal === null && o.status === 0\n\nconst setExitCode = (result: RunResult) => {\n /* c8 ignore next */\n process.exitCode ||= result.status ?? 1\n}\n\nexport const views = {\n // run results for single or multiple will be printed along the way.\n human: result => {\n if (isScriptSet(result)) stdout('Scripts available:', result)\n else if (isMultiScriptSet(result)) {\n stdout('Scripts available:')\n for (const [path, scripts] of Object.entries(result)) {\n stdout(path, scripts)\n }\n }\n },\n json: result =>\n isRunResult(result) && isSingleSuccess(result) ?\n undefined\n : result,\n} as const satisfies Views<ExecResult>\n\ntype ViewValues = 'human' | 'json' | 'inspect' | 'silent'\n\nexport class ExecCommand<B extends RunnerBG, F extends RunnerFG> {\n bg: B\n fg: F\n arg0?: string\n args: string[]\n env?: NodeJS.ProcessEnv\n #monorepo?: Monorepo\n #nodes?: string[]\n #defaultIgnoreMissing = false\n conf: LoadedConfig\n projectRoot: string\n view: ViewValues\n validViewValues = new Map<string, ViewValues>([\n ['human', 'human'],\n ['json', 'json'],\n ['inspect', 'inspect'],\n ['silent', 'silent'],\n ])\n\n constructor(conf: LoadedConfig, bg: B, fg: F) {\n this.conf = conf\n this.bg = bg\n this.fg = fg\n this.view = this.validViewValues.get(conf.values.view) ?? 'human'\n const {\n projectRoot,\n positionals: [arg0, ...args],\n } = conf\n this.arg0 = arg0\n this.args = args\n this.projectRoot = projectRoot\n }\n\n #targetCount(): number {\n if (this.#nodes) return this.#nodes.length\n return this.#monorepo?.size ?? 1\n }\n\n hasArg0(): this is this & { arg0: string } {\n return !!this.arg0\n }\n\n async run(): Promise<ExecResult> {\n const { conf } = this\n\n const queryString = conf.get('scope')\n const paths = conf.get('workspace')\n const groups = conf.get('workspace-group')\n const recursive = conf.get('recursive')\n\n // scope takes precedence over workspaces or groups\n if (queryString) {\n this.#defaultIgnoreMissing = true\n const mainManifest = conf.options.packageJson.maybeRead(\n this.projectRoot,\n )\n let graph\n if (mainManifest) {\n graph = actual.load({\n ...conf.options,\n mainManifest,\n monorepo: Monorepo.load(this.projectRoot),\n loadManifests: false,\n })\n }\n const hostContexts = await createHostContextsMap(conf)\n const query = new Query({\n /* c8 ignore start */\n nodes: graph ? new Set(graph.nodes.values()) : new Set(),\n edges: graph?.edges ?? new Set(),\n importers: graph?.importers ?? new Set(),\n /* c8 ignore stop */\n securityArchive: undefined,\n hostContexts,\n })\n const { nodes } = await query.search(queryString, {\n signal: new AbortController().signal,\n })\n this.#nodes = []\n for (const node of nodes) {\n const { location } = node.toJSON()\n assert(\n location,\n error(`node ${node.id} has no location`, {\n found: node,\n }),\n )\n this.#nodes.push(location)\n }\n } else if (paths?.length || groups?.length || recursive) {\n this.#defaultIgnoreMissing = true\n this.#monorepo = Monorepo.load(this.projectRoot, {\n load: { paths, groups },\n })\n }\n\n if (this.#targetCount() === 1) {\n const arg = this.fgArg()\n if (!arg) return this.noArgsSingle()\n const result = await this.fg(arg)\n if (isRunResult(result)) {\n setExitCode(result)\n }\n return result\n }\n\n if (this.#targetCount() === 0) {\n if (queryString) {\n throw error('no matching nodes found for query', {\n found: queryString,\n })\n } else {\n throw error('no matching workspaces found', {\n /* c8 ignore next - already guarded */\n validOptions: [...(this.#monorepo?.load().paths() ?? [])],\n })\n }\n }\n\n if (!this.hasArg0()) {\n return this.noArgsMulti()\n }\n\n // run across workspaces\n let failed = false as boolean\n const runInDir = async (cwd: string, label: string) => {\n const result = await this.bg(this.bgArg(cwd)).catch(\n (er: unknown) => {\n if (isErrorWithCause(er) && isRunResult(er.cause)) {\n this.printResult(label, er.cause)\n }\n failed = true\n throw er\n },\n )\n // If we are allowed to ignore missing commands, then command might be\n // an emptry string. If so, we don't print anything and return null to\n // be filtered out later.\n if (!result.command) return null\n if (!failed) this.printResult(label, result)\n return result\n }\n\n const resultMap = new Map<string, SpawnResultStdioStrings>()\n if (this.#nodes) {\n for (const { label, cwd } of this.getTargets()) {\n const result = await runInDir(cwd, label)\n if (result) resultMap.set(label, result)\n }\n } else if (this.#monorepo) {\n const wsResultMap = await this.#monorepo.run(ws =>\n runInDir(ws.fullpath, ws.path),\n )\n for (const [ws, result] of wsResultMap) {\n if (result) resultMap.set(ws.path, result)\n }\n }\n\n const results: Record<string, RunResult> = {}\n for (const [path, result] of resultMap) {\n if (result.status === 0 && result.signal === null) {\n result.stdout = ''\n result.stderr = ''\n }\n results[path] = result\n }\n return results\n }\n\n printResult(path: string, result: RunResult) {\n // non-human results just get printed at the end\n if (this.view !== 'human') return\n\n if (result.status === 0 && result.signal === null) {\n stdout(path, 'ok')\n } else {\n stdout(\n styleTextStdout(\n ['bgWhiteBright', 'black', 'bold'],\n path + ' failure',\n ),\n {\n status: result.status,\n signal: result.signal,\n },\n )\n /* c8 ignore start */\n if (result.stderr) stderr(ansiToAnsi(result.stderr))\n if (result.stdout) stdout(ansiToAnsi(result.stdout))\n /* c8 ignore stop */\n setExitCode(result)\n }\n }\n\n /* c8 ignore start - env specific */\n interactiveShell(): string {\n return (\n process.env.SHELL ??\n this.conf.get('script-shell') ??\n (process.platform === 'win32' ? 'cmd.exe' : '/bin/sh')\n )\n }\n /* c8 ignore stop */\n\n // overridden by 'vlt run' which returns undefined\n defaultArg0(): string | undefined {\n return this.interactiveShell()\n }\n\n getCwd(): string {\n if (this.#nodes) {\n const [first] = this.#nodes\n assert(first, error('no nodes found'))\n return resolve(this.projectRoot, first)\n }\n return (\n this.#monorepo?.values().next().value?.fullpath ??\n this.projectRoot\n )\n }\n\n fgArg(): RunnerOptions | undefined {\n const cwd = this.getCwd()\n const arg0 = this.arg0 ?? this.defaultArg0()\n\n // return undefined so noArgsSingle will be called instead\n if (typeof arg0 !== 'string') return\n\n return {\n cwd,\n arg0,\n args: this.args,\n env: this.env,\n projectRoot: this.projectRoot,\n packageJson: this.conf.options.packageJson,\n 'script-shell':\n this.arg0 ? this.conf.get('script-shell') : false,\n }\n }\n\n bgArg(this: this & { arg0: string }, cwd: string): RunnerOptions {\n return {\n cwd,\n acceptFail: !this.conf.get('bail'),\n ignoreMissing:\n this.conf.get('if-present') ?? this.#defaultIgnoreMissing,\n arg0: this.arg0,\n args: this.args,\n env: this.env,\n projectRoot: this.projectRoot,\n packageJson: this.conf.options.packageJson,\n 'script-shell': this.conf.get('script-shell'),\n }\n }\n\n /* c8 ignore start - not used, only here to override */\n noArgsSingle(): ScriptSet {\n throw error('Failed to determine interactive shell to spawn')\n }\n /* c8 ignore stop - not used, only here to override */\n\n noArgsMulti(): MultiScriptSet {\n throw error(\n 'Cannot spawn interactive shells in multiple workspaces',\n )\n }\n\n getTargets(): {\n label: string\n cwd: string\n manifest: NormalizedManifest\n }[] {\n const targets = []\n if (this.#nodes) {\n for (const location of this.#nodes) {\n const manifest = this.conf.options.packageJson.read(location)\n const label =\n /* c8 ignore next */\n location.startsWith('./') ? location.slice(2) : location\n const cwd = resolve(this.projectRoot, location)\n targets.push({ label, cwd, manifest })\n }\n } else if (this.#monorepo) {\n this.#monorepo.runSync(ws => {\n targets.push({\n label: ws.path,\n cwd: ws.fullpath,\n manifest: ws.manifest,\n })\n })\n }\n return targets\n }\n}\n"]}
@@ -1,4 +0,0 @@
1
- export type { Command, CommandFn, CommandUsage, } from './load-command.ts';
2
- declare const run: () => Promise<void>;
3
- export default run;
4
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAYA,YAAY,EACV,OAAO,EACP,SAAS,EACT,YAAY,GACb,MAAM,mBAAmB,CAAA;AAgD1B,QAAA,MAAM,GAAG,qBA2CR,CAAA;AAED,eAAe,GAAG,CAAA"}
package/dist/esm/index.js DELETED
@@ -1,73 +0,0 @@
1
- import { format } from 'node:util';
2
- import { asRootError } from '@vltpkg/output/error';
3
- import { loadPackageJson } from 'package-json-from-dist';
4
- import { getSortedCliOptions, getSortedKeys, } from "./config/definition.js";
5
- import { Config } from "./config/index.js";
6
- import { outputCommand, stderr, stdout } from "./output.js";
7
- import { indent } from "./print-err.js";
8
- import { loadCommand } from "./load-command.js";
9
- const { version } = loadPackageJson(import.meta.filename, process.env.__VLT_INTERNAL_CLI_PACKAGE_JSON);
10
- const loadVlt = async (cwd, argv) => {
11
- try {
12
- return await Config.load(cwd, argv);
13
- }
14
- catch (e) {
15
- const err = asRootError(e, { code: 'JACKSPEAK' });
16
- const { found, path, wanted, name } = err.cause;
17
- const isConfigFile = typeof path === 'string';
18
- const msg = isConfigFile ?
19
- `Problem in Config File ${path}`
20
- : 'Invalid Option Flag';
21
- const validOptions = wanted ? undefined
22
- : isConfigFile ? getSortedKeys()
23
- : getSortedCliOptions();
24
- stderr(msg);
25
- stderr(err.message);
26
- if (name)
27
- stderr(indent(`Field: ${format(name)}`));
28
- if (found) {
29
- stderr(indent(`Found: ${isConfigFile ? JSON.stringify(found) : format(found)}`));
30
- }
31
- if (wanted)
32
- stderr(indent(`Wanted: ${format(wanted)}`));
33
- if (validOptions) {
34
- stderr(indent('Valid Options:'));
35
- stderr(indent(validOptions.join('\n'), 4));
36
- }
37
- stderr(indent(`Run 'vlt help' for more information about available options.`));
38
- return process.exit(process.exitCode || 1);
39
- }
40
- };
41
- const run = async () => {
42
- const start = Date.now();
43
- const cwd = process.cwd();
44
- const vlt = await loadVlt(cwd, process.argv);
45
- if (vlt.get('version')) {
46
- return stdout(version);
47
- }
48
- const { monorepo } = vlt.options;
49
- // Infer the workspace by being in that directory.
50
- if (vlt.get('workspace') === undefined) {
51
- const ws = monorepo?.get(cwd);
52
- if (ws) {
53
- vlt.values.workspace = [ws.path];
54
- vlt.options.workspace = [ws.path];
55
- }
56
- }
57
- if (vlt.command !== 'init' &&
58
- (vlt.get('workspace') || vlt.get('workspace-group')) &&
59
- ![...(monorepo?.values() ?? [])].length) {
60
- stderr(`Error: No matching workspaces found. Make sure the vlt.json config contains the correct workspaces.`);
61
- if (vlt.get('workspace')) {
62
- stderr(indent(`Workspace: ${format(vlt.get('workspace'))}`));
63
- }
64
- if (vlt.get('workspace-group')) {
65
- stderr(indent(`Workspace Group: ${format(vlt.get('workspace-group'))}`));
66
- }
67
- return process.exit(process.exitCode || 1);
68
- }
69
- const command = await loadCommand(vlt.command);
70
- await outputCommand(command, vlt, { start });
71
- };
72
- export default run;
73
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AAClC,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AACxD,OAAO,EACL,mBAAmB,EACnB,aAAa,GACd,MAAM,wBAAwB,CAAA;AAC/B,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAC3D,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AACvC,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAQ/C,MAAM,EAAE,OAAO,EAAE,GAAG,eAAe,CACjC,MAAM,CAAC,IAAI,CAAC,QAAQ,EACpB,OAAO,CAAC,GAAG,CAAC,+BAA+B,CAG5C,CAAA;AAED,MAAM,OAAO,GAAG,KAAK,EAAE,GAAW,EAAE,IAAc,EAAE,EAAE;IACpD,IAAI,CAAC;QACH,OAAO,MAAM,MAAM,CAAC,IA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G,CAAA;QACD,IAAI,GAAG,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE,CAAC;YACzB,MAAM,CAAC,MAAM,CAAC,cAAc,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;QAC9D,CAAC;QACD,IAAI,GAAG,CAAC,GAAG,CAAC,iBAAiB,CAAC,EAAE,CAAC;YAC/B,MAAM,CACJ,MAAM,CACJ,oBAAoB,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC,EAAE,CACzD,CACF,CAAA;QACH,CAAC;QACD,OAAO,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,IAAI,CAAC,CAAC,CAAA;IAC5C,CAAC;IAED,MAAM,OAAO,GAAG,MAAM,WAAW,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;IAC9C,MAAM,aAAa,CAAC,OAAO,EAAE,GAAG,EAAE,EAAE,KAAK,EAAE,CAAC,CAAA;AAC9C,CAAC,CAAA;AAED,eAAe,GAAG,CAAA","sourcesContent":["import { format } from 'node:util'\nimport { asRootError } from '@vltpkg/output/error'\nimport { loadPackageJson } from 'package-json-from-dist'\nimport {\n getSortedCliOptions,\n getSortedKeys,\n} from './config/definition.ts'\nimport { Config } from './config/index.ts'\nimport { outputCommand, stderr, stdout } from './output.ts'\nimport { indent } from './print-err.ts'\nimport { loadCommand } from './load-command.ts'\n\nexport type {\n Command,\n CommandFn,\n CommandUsage,\n} from './load-command.ts'\n\nconst { version } = loadPackageJson(\n import.meta.filename,\n process.env.__VLT_INTERNAL_CLI_PACKAGE_JSON,\n) as {\n version: string\n}\n\nconst loadVlt = async (cwd: string, argv: string[]) => {\n try {\n return await Config.load(cwd, argv)\n } catch (e) {\n const err = asRootError(e, { code: 'JACKSPEAK' })\n const { found, path, wanted, name } = err.cause\n const isConfigFile = typeof path === 'string'\n const msg =\n isConfigFile ?\n `Problem in Config File ${path}`\n : 'Invalid Option Flag'\n const validOptions =\n wanted ? undefined\n : isConfigFile ? getSortedKeys()\n : getSortedCliOptions()\n stderr(msg)\n stderr(err.message)\n if (name) stderr(indent(`Field: ${format(name)}`))\n if (found) {\n stderr(\n indent(\n `Found: ${isConfigFile ? JSON.stringify(found) : format(found)}`,\n ),\n )\n }\n if (wanted) stderr(indent(`Wanted: ${format(wanted)}`))\n if (validOptions) {\n stderr(indent('Valid Options:'))\n stderr(indent(validOptions.join('\\n'), 4))\n }\n stderr(\n indent(\n `Run 'vlt help' for more information about available options.`,\n ),\n )\n return process.exit(process.exitCode || 1)\n }\n}\n\nconst run = async () => {\n const start = Date.now()\n const cwd = process.cwd()\n const vlt = await loadVlt(cwd, process.argv)\n\n if (vlt.get('version')) {\n return stdout(version)\n }\n\n const { monorepo } = vlt.options\n\n // Infer the workspace by being in that directory.\n if (vlt.get('workspace') === undefined) {\n const ws = monorepo?.get(cwd)\n if (ws) {\n vlt.values.workspace = [ws.path]\n vlt.options.workspace = [ws.path]\n }\n }\n\n if (\n vlt.command !== 'init' &&\n (vlt.get('workspace') || vlt.get('workspace-group')) &&\n ![...(monorepo?.values() ?? [])].length\n ) {\n stderr(\n `Error: No matching workspaces found. Make sure the vlt.json config contains the correct workspaces.`,\n )\n if (vlt.get('workspace')) {\n stderr(indent(`Workspace: ${format(vlt.get('workspace'))}`))\n }\n if (vlt.get('workspace-group')) {\n stderr(\n indent(\n `Workspace Group: ${format(vlt.get('workspace-group'))}`,\n ),\n )\n }\n return process.exit(process.exitCode || 1)\n }\n\n const command = await loadCommand(vlt.command)\n await outputCommand(command, vlt, { start })\n}\n\nexport default run\n"]}
@@ -1,16 +0,0 @@
1
- import type { Jack } from 'jackspeak';
2
- import type { Commands, LoadedConfig } from './config/index.ts';
3
- import type { Views } from './view.ts';
4
- export type CommandUsage = () => Jack;
5
- /**
6
- * A command function that may return a result of `T`.
7
- * If the result is `undefined`, no final output will be displayed by default.
8
- */
9
- export type CommandFn<T = unknown> = (conf: LoadedConfig) => Promise<T>;
10
- export type Command<T> = {
11
- command: CommandFn<T>;
12
- usage: CommandUsage;
13
- views: Views<T>;
14
- };
15
- export declare const loadCommand: <T>(command: Commands[keyof Commands] | undefined) => Promise<Command<T>>;
16
- //# sourceMappingURL=load-command.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"load-command.d.ts","sourceRoot":"","sources":["../../src/load-command.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AACrC,OAAO,KAAK,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAC/D,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,WAAW,CAAA;AAEtC,MAAM,MAAM,YAAY,GAAG,MAAM,IAAI,CAAA;AAErC;;;GAGG;AACH,MAAM,MAAM,SAAS,CAAC,CAAC,GAAG,OAAO,IAAI,CACnC,IAAI,EAAE,YAAY,KACf,OAAO,CAAC,CAAC,CAAC,CAAA;AAEf,MAAM,MAAM,OAAO,CAAC,CAAC,IAAI;IACvB,OAAO,EAAE,SAAS,CAAC,CAAC,CAAC,CAAA;IACrB,KAAK,EAAE,YAAY,CAAA;IACnB,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,CAAA;CAChB,CAAA;AAED,eAAO,MAAM,WAAW,GAAU,CAAC,WACxB,QAAQ,CAAC,MAAM,QAAQ,CAAC,GAAG,SAAS,KAC5C,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CASpB,CAAA"}
@@ -1,21 +0,0 @@
1
- var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) {
2
- if (typeof path === "string" && /^\.\.?\//.test(path)) {
3
- return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
4
- return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js");
5
- });
6
- }
7
- return path;
8
- };
9
- import { error } from '@vltpkg/error-cause';
10
- export const loadCommand = async (command) => {
11
- try {
12
- return (await import(__rewriteRelativeImportExtension(`./commands/${command}.ts`)));
13
- }
14
- catch (e) {
15
- throw error('Could not load command', {
16
- found: command,
17
- cause: e,
18
- });
19
- }
20
- };
21
- //# sourceMappingURL=load-command.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"load-command.js","sourceRoot":"","sources":["../../src/load-command.ts"],"names":[],"mappings":";;;;;;;;AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAqB3C,MAAM,CAAC,MAAM,WAAW,GAAG,KAAK,EAC9B,OAA6C,EACxB,EAAE;IACvB,IAAI,CAAC;QACH,OAAO,CAAC,MAAM,MAAM,kCAAC,cAAc,OAAO,KAAK,EAAC,CAAe,CAAA;IACjE,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,MAAM,KAAK,CAAC,wBAAwB,EAAE;YACpC,KAAK,EAAE,OAAO;YACd,KAAK,EAAE,CAAC;SACT,CAAC,CAAA;IACJ,CAAC;AACH,CAAC,CAAA","sourcesContent":["import { error } from '@vltpkg/error-cause'\nimport type { Jack } from 'jackspeak'\nimport type { Commands, LoadedConfig } from './config/index.ts'\nimport type { Views } from './view.ts'\n\nexport type CommandUsage = () => Jack\n\n/**\n * A command function that may return a result of `T`.\n * If the result is `undefined`, no final output will be displayed by default.\n */\nexport type CommandFn<T = unknown> = (\n conf: LoadedConfig,\n) => Promise<T>\n\nexport type Command<T> = {\n command: CommandFn<T>\n usage: CommandUsage\n views: Views<T>\n}\n\nexport const loadCommand = async <T>(\n command: Commands[keyof Commands] | undefined,\n): Promise<Command<T>> => {\n try {\n return (await import(`./commands/${command}.ts`)) as Command<T>\n } catch (e) {\n throw error('Could not load command', {\n found: command,\n cause: e,\n })\n }\n}\n"]}
@@ -1,21 +0,0 @@
1
- import { styleText as utilStyleText } from 'node:util';
2
- import type { LoadedConfig } from './config/index.ts';
3
- import type { Command } from './index.ts';
4
- import type { View, Views } from './view.ts';
5
- export declare const stdout: (...args: unknown[]) => void;
6
- export declare const stderr: (...args: unknown[]) => void;
7
- type StyleTextFn = (format: Parameters<typeof utilStyleText>[0], s: string) => string;
8
- export declare let styleTextStdout: StyleTextFn;
9
- export declare let styleTextStderr: StyleTextFn;
10
- export declare const getView: <T>(conf: LoadedConfig, views?: Views<T>) => View<T>;
11
- export type OnDone<T> = (result: T) => Promise<unknown>;
12
- /**
13
- * Main export. Run the command appropriately, displaying output using
14
- * the user-requested view, or the default if the user requested a view
15
- * that is not defined for this command.
16
- */
17
- export declare const outputCommand: <T>(cliCommand: Command<T>, conf: LoadedConfig, { start }?: {
18
- start: number;
19
- }) => Promise<void>;
20
- export {};
21
- //# sourceMappingURL=output.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"output.d.ts","sourceRoot":"","sources":["../../src/output.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,SAAS,IAAI,aAAa,EAC3B,MAAM,WAAW,CAAA;AAGlB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AACrD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AAEzC,OAAO,KAAK,EAAE,IAAI,EAAe,KAAK,EAAE,MAAM,WAAW,CAAA;AAezD,eAAO,MAAM,MAAM,YAAa,OAAO,EAAE,SAAyB,CAAA;AAElE,eAAO,MAAM,MAAM,YAAa,OAAO,EAAE,SAA2B,CAAA;AAEpE,KAAK,WAAW,GAAG,CACjB,MAAM,EAAE,UAAU,CAAC,OAAO,aAAa,CAAC,CAAC,CAAC,CAAC,EAC3C,CAAC,EAAE,MAAM,KACN,MAAM,CAAA;AASX,eAAO,IAAI,eAAe,EAAE,WAAyB,CAAA;AACrD,eAAO,IAAI,eAAe,EAAE,WAAyB,CAAA;AAKrD,eAAO,MAAM,OAAO,GAAI,CAAC,QACjB,YAAY,UACV,KAAK,CAAC,CAAC,CAAC,KACf,IAAI,CAAC,CAAC,CA2BR,CAAA;AAED,MAAM,MAAM,MAAM,CAAC,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA;AAsCvD;;;;GAIG;AACH,eAAO,MAAM,aAAa,GAAU,CAAC,cACvB,OAAO,CAAC,CAAC,CAAC,QAChB,YAAY,cACP;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,kBA6D7B,CAAA"}
@@ -1,126 +0,0 @@
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, formatOptions } from "./print-err.js";
5
- import { isViewClass } from "./view.js";
6
- import { generateDefaultHelp, generateFullHelp, } from "./custom-help.js";
7
- const supportsColor = (stream) => {
8
- const res = createSupportsColor(stream, { sniffFlags: false });
9
- if (res === false)
10
- return false;
11
- /* c8 ignore next */
12
- return res.level > 0;
13
- };
14
- // eslint-disable-next-line no-console
15
- export const stdout = (...args) => console.log(...args);
16
- // eslint-disable-next-line no-console
17
- export const stderr = (...args) => console.error(...args);
18
- /* c8 ignore start */
19
- const styleText = (f, s) => utilStyleText(f, s, { validateStream: false });
20
- /* c8 ignore stop */
21
- // TODO: stop exporting mutable variables once exec output is refactored
22
- /* c8 ignore start */
23
- export let styleTextStdout = (_, s) => s;
24
- export let styleTextStderr = (_, s) => s;
25
- /* c8 ignore stop */
26
- const identity = (x) => x;
27
- export const getView = (conf, views) => {
28
- const viewName = conf.values.view;
29
- const viewFn = viewName === 'inspect' ? identity
30
- : viewName === 'silent' ? () => undefined
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 !== 'silent') {
43
- conf.values.view = defaultView;
44
- process.env.VLT_VIEW = defaultView;
45
- return getView(conf, views);
46
- }
47
- return viewFn ?? identity;
48
- };
49
- /**
50
- * If the view is a View class, then instantiate and start it.
51
- * If it's a view function, then just define the onDone method.
52
- */
53
- const startView = (conf, opts, views, { start } = { start: Date.now() }) => {
54
- const View = getView(conf, views);
55
- if (isViewClass(View)) {
56
- const view = new View(opts, conf);
57
- view.start();
58
- return {
59
- async onDone(r) {
60
- return view.done(r, { time: Date.now() - start });
61
- },
62
- onError(err) {
63
- view.error(err);
64
- },
65
- };
66
- }
67
- return {
68
- async onDone(r) {
69
- if (r === undefined)
70
- return;
71
- return View(r, opts, conf);
72
- },
73
- };
74
- };
75
- /**
76
- * Main export. Run the command appropriately, displaying output using
77
- * the user-requested view, or the default if the user requested a view
78
- * that is not defined for this command.
79
- */
80
- export const outputCommand = async (cliCommand, conf, { start } = { start: Date.now() }) => {
81
- const { usage, views, command } = cliCommand;
82
- const stdoutColor = conf.values.color ?? supportsColor(process.stdout);
83
- const stderrColor = conf.values.color ?? supportsColor(process.stderr);
84
- if (conf.values.help) {
85
- // Show custom help for main vlt command
86
- /* c8 ignore start */
87
- if (conf.command === 'help' && conf.positionals.length === 0) {
88
- if (conf.get('all')) {
89
- return stdout(generateFullHelp(stdoutColor));
90
- }
91
- return stdout(generateDefaultHelp(stdoutColor));
92
- }
93
- /* c8 ignore stop */
94
- return stdout(usage().usage());
95
- }
96
- /* c8 ignore start */
97
- if (stdoutColor)
98
- styleTextStdout = styleText;
99
- if (stderrColor)
100
- styleTextStderr = styleText;
101
- /* c8 ignore stop */
102
- const { onDone, onError } = startView(conf,
103
- // assume views will always output to stdout so use color support from there
104
- { colors: stdoutColor }, views, { start });
105
- try {
106
- const output = await onDone(await command(conf));
107
- if (output !== undefined && conf.values.view !== 'silent') {
108
- stdout(conf.values.view === 'json' ?
109
- JSON.stringify(output, null, 2)
110
- : formatWithOptions({
111
- ...formatOptions,
112
- colors: stdoutColor,
113
- }, output));
114
- }
115
- }
116
- catch (err) {
117
- onError?.(err);
118
- process.exitCode ||= 1;
119
- printErr(err, usage, stderr, {
120
- ...formatOptions,
121
- colors: stderrColor,
122
- });
123
- process.exit(process.exitCode);
124
- }
125
- };
126
- //# sourceMappingURL=output.js.map