@vltpkg/cli-sdk 1.0.0-rc.22 → 1.0.0-rc.24
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.
- package/dist/commands/bugs.d.ts +17 -0
- package/dist/commands/bugs.js +163 -0
- package/dist/commands/build.d.ts +24 -0
- package/dist/commands/build.js +101 -0
- package/dist/commands/cache.d.ts +64 -0
- package/dist/commands/cache.js +256 -0
- package/dist/commands/ci.d.ts +10 -0
- package/dist/commands/ci.js +40 -0
- package/dist/commands/config.d.ts +5 -0
- package/dist/commands/config.js +429 -0
- package/dist/commands/create.d.ts +8 -0
- package/dist/commands/create.js +102 -0
- package/dist/commands/docs.d.ts +17 -0
- package/dist/commands/docs.js +153 -0
- package/dist/commands/exec-cache.d.ts +48 -0
- package/dist/commands/exec-cache.js +145 -0
- package/dist/commands/exec-local.d.ts +5 -0
- package/dist/commands/exec-local.js +46 -0
- package/dist/commands/exec.d.ts +8 -0
- package/dist/commands/exec.js +161 -0
- package/dist/commands/help.d.ts +3 -0
- package/dist/commands/help.js +43 -0
- package/dist/commands/init.d.ts +7 -0
- package/dist/commands/init.js +116 -0
- package/dist/commands/install/reporter.d.ts +10 -0
- package/dist/commands/install/reporter.js +93 -0
- package/dist/commands/install.d.ts +27 -0
- package/dist/commands/install.js +80 -0
- package/dist/commands/list.d.ts +17 -0
- package/dist/commands/list.js +197 -0
- package/dist/commands/login.d.ts +3 -0
- package/dist/commands/login.js +22 -0
- package/dist/commands/logout.d.ts +3 -0
- package/dist/commands/logout.js +22 -0
- package/dist/commands/pack.d.ts +31 -0
- package/dist/commands/pack.js +205 -0
- package/dist/commands/ping.d.ts +17 -0
- package/dist/commands/ping.js +114 -0
- package/dist/commands/pkg.d.ts +6 -0
- package/dist/commands/pkg.js +232 -0
- package/dist/commands/publish.d.ts +21 -0
- package/dist/commands/publish.js +282 -0
- package/dist/commands/query.d.ts +18 -0
- package/dist/commands/query.js +216 -0
- package/dist/commands/repo.d.ts +17 -0
- package/dist/commands/repo.js +157 -0
- package/dist/commands/run-exec.d.ts +5 -0
- package/dist/commands/run-exec.js +40 -0
- package/dist/commands/run.d.ts +5 -0
- package/dist/commands/run.js +62 -0
- package/dist/commands/token.d.ts +3 -0
- package/dist/commands/token.js +39 -0
- package/dist/commands/uninstall.d.ts +15 -0
- package/dist/commands/uninstall.js +39 -0
- package/dist/commands/update.d.ts +13 -0
- package/dist/commands/update.js +46 -0
- package/dist/commands/version.d.ts +25 -0
- package/dist/commands/version.js +252 -0
- package/dist/commands/view.d.ts +22 -0
- package/dist/commands/view.js +334 -0
- package/dist/commands/whoami.d.ts +12 -0
- package/dist/commands/whoami.js +28 -0
- package/dist/config/definition.d.ts +407 -0
- package/dist/config/definition.js +684 -0
- package/dist/config/index.d.ts +218 -0
- package/dist/config/index.js +488 -0
- package/dist/config/merge.d.ts +3 -0
- package/dist/config/merge.js +27 -0
- package/dist/config/usage.d.ts +18 -0
- package/dist/config/usage.js +39 -0
- package/dist/custom-help.d.ts +8 -0
- package/dist/custom-help.js +419 -0
- package/dist/exec-command.d.ts +52 -0
- package/dist/exec-command.js +313 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +72 -0
- package/dist/load-command.d.ts +15 -0
- package/dist/load-command.js +20 -0
- package/dist/mermaid-image-view.d.ts +18 -0
- package/dist/mermaid-image-view.js +36 -0
- package/dist/output.d.ts +20 -0
- package/dist/output.js +125 -0
- package/dist/pack-tarball.d.ts +23 -0
- package/dist/pack-tarball.js +256 -0
- package/dist/parse-add-remove-args.d.ts +28 -0
- package/dist/parse-add-remove-args.js +103 -0
- package/dist/print-err.d.ts +13 -0
- package/dist/print-err.js +193 -0
- package/dist/query-diff-files.d.ts +17 -0
- package/dist/query-diff-files.js +63 -0
- package/dist/query-host-contexts.d.ts +15 -0
- package/dist/query-host-contexts.js +136 -0
- package/dist/read-password.d.ts +7 -0
- package/dist/read-password.js +32 -0
- package/dist/read-project-folders.d.ts +17 -0
- package/dist/read-project-folders.js +100 -0
- package/dist/reload-config.d.ts +2 -0
- package/dist/reload-config.js +11 -0
- package/dist/render-mermaid.d.ts +22 -0
- package/dist/render-mermaid.js +68 -0
- package/dist/view.d.ts +29 -0
- package/dist/view.js +30 -0
- package/package.json +30 -30
|
@@ -0,0 +1,313 @@
|
|
|
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 { createDiffFilesProvider } from "./query-diff-files.js";
|
|
9
|
+
import { actual } from '@vltpkg/graph';
|
|
10
|
+
import { isRunResult } from '@vltpkg/run';
|
|
11
|
+
import { Monorepo } from '@vltpkg/workspaces';
|
|
12
|
+
import { ansiToAnsi } from 'ansi-to-pre';
|
|
13
|
+
import { stderr, stdout, styleTextStdout } from "./output.js";
|
|
14
|
+
import assert from 'node:assert';
|
|
15
|
+
import { resolve } from 'node:path';
|
|
16
|
+
import { createHostContextsMap } from "./query-host-contexts.js";
|
|
17
|
+
const isScriptSet = (o) => {
|
|
18
|
+
if (!o || typeof o !== 'object')
|
|
19
|
+
return false;
|
|
20
|
+
for (const v of Object.values(o)) {
|
|
21
|
+
if (typeof v !== 'string')
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
return true;
|
|
25
|
+
};
|
|
26
|
+
const isMultiScriptSet = (o) => {
|
|
27
|
+
for (const v of Object.values(o)) {
|
|
28
|
+
if (!isScriptSet(v))
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
return true;
|
|
32
|
+
};
|
|
33
|
+
const isSingleSuccess = (o) => o.signal === null && o.status === 0;
|
|
34
|
+
const setExitCode = (result) => {
|
|
35
|
+
/* c8 ignore next */
|
|
36
|
+
process.exitCode ||= result.status ?? 1;
|
|
37
|
+
};
|
|
38
|
+
export const views = {
|
|
39
|
+
// run results for single or multiple will be printed along the way.
|
|
40
|
+
human: result => {
|
|
41
|
+
if (isScriptSet(result))
|
|
42
|
+
stdout('Scripts available:', result);
|
|
43
|
+
else if (isMultiScriptSet(result)) {
|
|
44
|
+
stdout('Scripts available:');
|
|
45
|
+
for (const [path, scripts] of Object.entries(result)) {
|
|
46
|
+
stdout(path, scripts);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
json: result => isRunResult(result) && isSingleSuccess(result) ?
|
|
51
|
+
undefined
|
|
52
|
+
: result,
|
|
53
|
+
};
|
|
54
|
+
export class ExecCommand {
|
|
55
|
+
bg;
|
|
56
|
+
fg;
|
|
57
|
+
arg0;
|
|
58
|
+
args;
|
|
59
|
+
env;
|
|
60
|
+
#monorepo;
|
|
61
|
+
#nodes;
|
|
62
|
+
#defaultIgnoreMissing = false;
|
|
63
|
+
conf;
|
|
64
|
+
projectRoot;
|
|
65
|
+
view;
|
|
66
|
+
validViewValues = new Map([
|
|
67
|
+
['human', 'human'],
|
|
68
|
+
['json', 'json'],
|
|
69
|
+
['inspect', 'inspect'],
|
|
70
|
+
['silent', 'silent'],
|
|
71
|
+
]);
|
|
72
|
+
constructor(conf, bg, fg) {
|
|
73
|
+
this.conf = conf;
|
|
74
|
+
this.bg = bg;
|
|
75
|
+
this.fg = fg;
|
|
76
|
+
this.view = this.validViewValues.get(conf.values.view) ?? 'human';
|
|
77
|
+
const { projectRoot, positionals: [arg0, ...args], } = conf;
|
|
78
|
+
this.arg0 = arg0;
|
|
79
|
+
this.args = args;
|
|
80
|
+
this.projectRoot = projectRoot;
|
|
81
|
+
}
|
|
82
|
+
#targetCount() {
|
|
83
|
+
if (this.#nodes)
|
|
84
|
+
return this.#nodes.length;
|
|
85
|
+
return this.#monorepo?.size ?? 1;
|
|
86
|
+
}
|
|
87
|
+
hasArg0() {
|
|
88
|
+
return !!this.arg0;
|
|
89
|
+
}
|
|
90
|
+
async run() {
|
|
91
|
+
const { conf } = this;
|
|
92
|
+
const queryString = conf.get('scope');
|
|
93
|
+
const paths = conf.get('workspace');
|
|
94
|
+
const groups = conf.get('workspace-group');
|
|
95
|
+
const recursive = conf.get('recursive');
|
|
96
|
+
// scope takes precedence over workspaces or groups
|
|
97
|
+
if (queryString) {
|
|
98
|
+
this.#defaultIgnoreMissing = true;
|
|
99
|
+
const mainManifest = conf.options.packageJson.maybeRead(this.projectRoot);
|
|
100
|
+
let graph;
|
|
101
|
+
if (mainManifest) {
|
|
102
|
+
graph = actual.load({
|
|
103
|
+
...conf.options,
|
|
104
|
+
mainManifest,
|
|
105
|
+
monorepo: Monorepo.load(this.projectRoot),
|
|
106
|
+
loadManifests: false,
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
const hostContexts = await createHostContextsMap(conf);
|
|
110
|
+
const query = new Query({
|
|
111
|
+
/* c8 ignore start */
|
|
112
|
+
nodes: graph ? new Set(graph.nodes.values()) : new Set(),
|
|
113
|
+
edges: graph?.edges ?? new Set(),
|
|
114
|
+
importers: graph?.importers ?? new Set(),
|
|
115
|
+
/* c8 ignore stop */
|
|
116
|
+
securityArchive: undefined,
|
|
117
|
+
hostContexts,
|
|
118
|
+
diffFiles: createDiffFilesProvider(this.projectRoot),
|
|
119
|
+
});
|
|
120
|
+
const { nodes } = await query.search(queryString, {
|
|
121
|
+
signal: new AbortController().signal,
|
|
122
|
+
});
|
|
123
|
+
this.#nodes = [];
|
|
124
|
+
for (const node of nodes) {
|
|
125
|
+
const { location } = node.toJSON();
|
|
126
|
+
assert(location, error(`node ${node.id} has no location`, {
|
|
127
|
+
found: node,
|
|
128
|
+
}));
|
|
129
|
+
this.#nodes.push(location);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
else if (paths?.length || groups?.length || recursive) {
|
|
133
|
+
this.#defaultIgnoreMissing = true;
|
|
134
|
+
this.#monorepo = Monorepo.load(this.projectRoot, {
|
|
135
|
+
load: { paths, groups },
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
if (this.#targetCount() === 1) {
|
|
139
|
+
const arg = this.fgArg();
|
|
140
|
+
if (!arg)
|
|
141
|
+
return this.noArgsSingle();
|
|
142
|
+
const result = await this.fg(arg);
|
|
143
|
+
if (isRunResult(result)) {
|
|
144
|
+
setExitCode(result);
|
|
145
|
+
}
|
|
146
|
+
return result;
|
|
147
|
+
}
|
|
148
|
+
if (this.#targetCount() === 0) {
|
|
149
|
+
if (queryString) {
|
|
150
|
+
throw error('no matching nodes found for query', {
|
|
151
|
+
found: queryString,
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
throw error('no matching workspaces found', {
|
|
156
|
+
/* c8 ignore next - already guarded */
|
|
157
|
+
validOptions: [...(this.#monorepo?.load().paths() ?? [])],
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
if (!this.hasArg0()) {
|
|
162
|
+
return this.noArgsMulti();
|
|
163
|
+
}
|
|
164
|
+
// run across workspaces
|
|
165
|
+
let failed = false;
|
|
166
|
+
const runInDir = async (cwd, label) => {
|
|
167
|
+
const result = await this.bg(this.bgArg(cwd)).catch((er) => {
|
|
168
|
+
if (isErrorWithCause(er) && isRunResult(er.cause)) {
|
|
169
|
+
this.printResult(label, er.cause);
|
|
170
|
+
}
|
|
171
|
+
failed = true;
|
|
172
|
+
throw er;
|
|
173
|
+
});
|
|
174
|
+
// If we are allowed to ignore missing commands, then command might be
|
|
175
|
+
// an emptry string. If so, we don't print anything and return null to
|
|
176
|
+
// be filtered out later.
|
|
177
|
+
if (!result.command)
|
|
178
|
+
return null;
|
|
179
|
+
if (!failed)
|
|
180
|
+
this.printResult(label, result);
|
|
181
|
+
return result;
|
|
182
|
+
};
|
|
183
|
+
const resultMap = new Map();
|
|
184
|
+
if (this.#nodes) {
|
|
185
|
+
for (const { label, cwd } of this.getTargets()) {
|
|
186
|
+
const result = await runInDir(cwd, label);
|
|
187
|
+
if (result)
|
|
188
|
+
resultMap.set(label, result);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
else if (this.#monorepo) {
|
|
192
|
+
const wsResultMap = await this.#monorepo.run(ws => runInDir(ws.fullpath, ws.path));
|
|
193
|
+
for (const [ws, result] of wsResultMap) {
|
|
194
|
+
if (result)
|
|
195
|
+
resultMap.set(ws.path, result);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
const results = {};
|
|
199
|
+
for (const [path, result] of resultMap) {
|
|
200
|
+
results[path] = result;
|
|
201
|
+
}
|
|
202
|
+
return results;
|
|
203
|
+
}
|
|
204
|
+
printResult(path, result) {
|
|
205
|
+
// non-human results just get printed at the end
|
|
206
|
+
if (this.view !== 'human')
|
|
207
|
+
return;
|
|
208
|
+
if (result.status === 0 && result.signal === null) {
|
|
209
|
+
/* c8 ignore start */
|
|
210
|
+
if (result.stderr)
|
|
211
|
+
stderr(ansiToAnsi(result.stderr));
|
|
212
|
+
if (result.stdout)
|
|
213
|
+
stdout(ansiToAnsi(result.stdout));
|
|
214
|
+
/* c8 ignore stop */
|
|
215
|
+
stdout(path, 'ok');
|
|
216
|
+
}
|
|
217
|
+
else {
|
|
218
|
+
stdout(styleTextStdout(['bgWhiteBright', 'black', 'bold'], path + ' failure'), {
|
|
219
|
+
status: result.status,
|
|
220
|
+
signal: result.signal,
|
|
221
|
+
});
|
|
222
|
+
/* c8 ignore start */
|
|
223
|
+
if (result.stderr)
|
|
224
|
+
stderr(ansiToAnsi(result.stderr));
|
|
225
|
+
if (result.stdout)
|
|
226
|
+
stdout(ansiToAnsi(result.stdout));
|
|
227
|
+
/* c8 ignore stop */
|
|
228
|
+
setExitCode(result);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
/* c8 ignore start - env specific */
|
|
232
|
+
interactiveShell() {
|
|
233
|
+
return (process.env.SHELL ??
|
|
234
|
+
this.conf.get('script-shell') ??
|
|
235
|
+
(process.platform === 'win32' ? 'cmd.exe' : '/bin/sh'));
|
|
236
|
+
}
|
|
237
|
+
/* c8 ignore stop */
|
|
238
|
+
// overridden by 'vlt run' which returns undefined
|
|
239
|
+
defaultArg0() {
|
|
240
|
+
return this.interactiveShell();
|
|
241
|
+
}
|
|
242
|
+
getCwd() {
|
|
243
|
+
if (this.#nodes) {
|
|
244
|
+
const [first] = this.#nodes;
|
|
245
|
+
assert(first, error('no nodes found'));
|
|
246
|
+
return resolve(this.projectRoot, first);
|
|
247
|
+
}
|
|
248
|
+
// When no workspace/monorepo targeting is specified, use the current
|
|
249
|
+
// working directory. This matches npx behavior and is required for
|
|
250
|
+
// tools like node-gyp that must run in the correct directory.
|
|
251
|
+
return (this.#monorepo?.values().next().value?.fullpath ?? process.cwd());
|
|
252
|
+
}
|
|
253
|
+
fgArg() {
|
|
254
|
+
const cwd = this.getCwd();
|
|
255
|
+
const arg0 = this.arg0 ?? this.defaultArg0();
|
|
256
|
+
// return undefined so noArgsSingle will be called instead
|
|
257
|
+
if (typeof arg0 !== 'string')
|
|
258
|
+
return;
|
|
259
|
+
return {
|
|
260
|
+
cwd,
|
|
261
|
+
arg0,
|
|
262
|
+
args: this.args,
|
|
263
|
+
env: this.env,
|
|
264
|
+
projectRoot: this.projectRoot,
|
|
265
|
+
packageJson: this.conf.options.packageJson,
|
|
266
|
+
'script-shell': this.arg0 ? this.conf.get('script-shell') : false,
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
bgArg(cwd) {
|
|
270
|
+
return {
|
|
271
|
+
cwd,
|
|
272
|
+
acceptFail: !this.conf.get('bail'),
|
|
273
|
+
ignoreMissing: this.conf.get('if-present') ?? this.#defaultIgnoreMissing,
|
|
274
|
+
arg0: this.arg0,
|
|
275
|
+
args: this.args,
|
|
276
|
+
env: this.env,
|
|
277
|
+
projectRoot: this.projectRoot,
|
|
278
|
+
packageJson: this.conf.options.packageJson,
|
|
279
|
+
'script-shell': this.conf.get('script-shell'),
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
/* c8 ignore start - not used, only here to override */
|
|
283
|
+
noArgsSingle() {
|
|
284
|
+
throw error('Failed to determine interactive shell to spawn');
|
|
285
|
+
}
|
|
286
|
+
/* c8 ignore stop - not used, only here to override */
|
|
287
|
+
noArgsMulti() {
|
|
288
|
+
throw error('Cannot spawn interactive shells in multiple workspaces');
|
|
289
|
+
}
|
|
290
|
+
getTargets() {
|
|
291
|
+
const targets = [];
|
|
292
|
+
if (this.#nodes) {
|
|
293
|
+
for (const location of this.#nodes) {
|
|
294
|
+
const manifest = this.conf.options.packageJson.read(location);
|
|
295
|
+
const label =
|
|
296
|
+
/* c8 ignore next */
|
|
297
|
+
location.startsWith('./') ? location.slice(2) : location;
|
|
298
|
+
const cwd = resolve(this.projectRoot, location);
|
|
299
|
+
targets.push({ label, cwd, manifest });
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
else if (this.#monorepo) {
|
|
303
|
+
this.#monorepo.runSync(ws => {
|
|
304
|
+
targets.push({
|
|
305
|
+
label: ws.path,
|
|
306
|
+
cwd: ws.fullpath,
|
|
307
|
+
manifest: ws.manifest,
|
|
308
|
+
});
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
return targets;
|
|
312
|
+
}
|
|
313
|
+
}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
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;
|
|
@@ -0,0 +1,15 @@
|
|
|
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>>;
|
|
@@ -0,0 +1,20 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ViewClass } from './view.ts';
|
|
2
|
+
import type { OutputFormat } from './render-mermaid.ts';
|
|
3
|
+
import type { MermaidOutputGraph } from '@vltpkg/graph';
|
|
4
|
+
/**
|
|
5
|
+
* A ViewClass that renders mermaid output as SVG or PNG
|
|
6
|
+
* (saved to a temp file and opened).
|
|
7
|
+
*
|
|
8
|
+
* Uses `beautiful-mermaid` for SVG rendering and
|
|
9
|
+
* `@resvg/resvg-wasm` for PNG conversion — no external
|
|
10
|
+
* process spawning.
|
|
11
|
+
*/
|
|
12
|
+
export declare class MermaidImageView extends ViewClass<MermaidOutputGraph> {
|
|
13
|
+
format: OutputFormat;
|
|
14
|
+
constructor(...args: ConstructorParameters<typeof ViewClass<MermaidOutputGraph>>);
|
|
15
|
+
done(result: MermaidOutputGraph, _opts: {
|
|
16
|
+
time: number;
|
|
17
|
+
}): Promise<void>;
|
|
18
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { mermaidOutput } from '@vltpkg/graph';
|
|
2
|
+
import { urlOpen } from '@vltpkg/url-open';
|
|
3
|
+
import { stderr } from "./output.js";
|
|
4
|
+
import { ViewClass } from "./view.js";
|
|
5
|
+
/**
|
|
6
|
+
* A ViewClass that renders mermaid output as SVG or PNG
|
|
7
|
+
* (saved to a temp file and opened).
|
|
8
|
+
*
|
|
9
|
+
* Uses `beautiful-mermaid` for SVG rendering and
|
|
10
|
+
* `@resvg/resvg-wasm` for PNG conversion — no external
|
|
11
|
+
* process spawning.
|
|
12
|
+
*/
|
|
13
|
+
export class MermaidImageView extends ViewClass {
|
|
14
|
+
format;
|
|
15
|
+
constructor(...args) {
|
|
16
|
+
super(...args);
|
|
17
|
+
this.format = this.config.values.view;
|
|
18
|
+
}
|
|
19
|
+
async done(result, _opts) {
|
|
20
|
+
const mermaidText = mermaidOutput(result);
|
|
21
|
+
// Dynamic import to avoid loading render-mermaid eagerly
|
|
22
|
+
const { renderMermaidToFile, renderMermaidToPng } = await import("./render-mermaid.js");
|
|
23
|
+
if (this.format === 'png') {
|
|
24
|
+
stderr(`Generating PNG image...`);
|
|
25
|
+
const filePath = await renderMermaidToPng(mermaidText);
|
|
26
|
+
stderr(`Image saved to: ${filePath}`);
|
|
27
|
+
await urlOpen(filePath);
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
stderr(`Generating SVG image...`);
|
|
31
|
+
const filePath = await renderMermaidToFile(mermaidText);
|
|
32
|
+
stderr(`Image saved to: ${filePath}`);
|
|
33
|
+
await urlOpen(filePath);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
package/dist/output.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
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 {};
|
package/dist/output.js
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { NormalizedManifest } from '@vltpkg/types';
|
|
2
|
+
import type { LoadedConfig } from './config/index.ts';
|
|
3
|
+
export type PackTarballResult = {
|
|
4
|
+
name: string;
|
|
5
|
+
version: string;
|
|
6
|
+
filename: string;
|
|
7
|
+
tarballName: string;
|
|
8
|
+
tarballData: Buffer;
|
|
9
|
+
unpackedSize: number;
|
|
10
|
+
files: string[];
|
|
11
|
+
integrity?: string;
|
|
12
|
+
shasum?: string;
|
|
13
|
+
/** The manifest used for packing (may differ from input when publishConfig.directory is set). */
|
|
14
|
+
resolvedManifest: NormalizedManifest;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Create a tarball from a package directory
|
|
18
|
+
* @param {NormalizedManifest} manifest - The manifest of the package to pack
|
|
19
|
+
* @param {string} dir - The directory containing the package to pack
|
|
20
|
+
* @param {LoadedConfig} [config] - The loaded configuration (for workspace/catalog resolution)
|
|
21
|
+
* @returns {Promise<PackTarballResult>} The manifest, filename, and tarball data (unless dry run)
|
|
22
|
+
*/
|
|
23
|
+
export declare const packTarball: (manifest: NormalizedManifest, dir: string, config: LoadedConfig) => Promise<PackTarballResult>;
|