@vltpkg/cli-sdk 0.0.0-9 → 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.
- package/dist/esm/commands/build.d.ts +25 -0
- package/dist/esm/commands/build.d.ts.map +1 -0
- package/dist/esm/commands/build.js +102 -0
- package/dist/esm/commands/build.js.map +1 -0
- package/dist/esm/commands/cache.d.ts +18 -0
- package/dist/esm/commands/cache.d.ts.map +1 -1
- package/dist/esm/commands/cache.js +48 -2
- package/dist/esm/commands/cache.js.map +1 -1
- package/dist/esm/commands/ci.d.ts +11 -0
- package/dist/esm/commands/ci.d.ts.map +1 -0
- package/dist/esm/commands/ci.js +32 -0
- package/dist/esm/commands/ci.js.map +1 -0
- package/dist/esm/commands/config.d.ts +3 -2
- package/dist/esm/commands/config.d.ts.map +1 -1
- package/dist/esm/commands/config.js +372 -101
- package/dist/esm/commands/config.js.map +1 -1
- package/dist/esm/commands/docs.d.ts +18 -0
- package/dist/esm/commands/docs.d.ts.map +1 -0
- package/dist/esm/commands/docs.js +154 -0
- package/dist/esm/commands/docs.js.map +1 -0
- package/dist/esm/commands/exec-cache.d.ts +49 -0
- package/dist/esm/commands/exec-cache.d.ts.map +1 -0
- package/dist/esm/commands/exec-cache.js +146 -0
- package/dist/esm/commands/exec-cache.js.map +1 -0
- package/dist/esm/commands/exec-local.d.ts +1 -0
- package/dist/esm/commands/exec-local.d.ts.map +1 -1
- package/dist/esm/commands/exec-local.js +2 -0
- package/dist/esm/commands/exec-local.js.map +1 -1
- package/dist/esm/commands/exec.d.ts +6 -1
- package/dist/esm/commands/exec.d.ts.map +1 -1
- package/dist/esm/commands/exec.js +79 -5
- package/dist/esm/commands/exec.js.map +1 -1
- package/dist/esm/commands/help.d.ts +1 -1
- package/dist/esm/commands/help.d.ts.map +1 -1
- package/dist/esm/commands/help.js +32 -3
- package/dist/esm/commands/help.js.map +1 -1
- package/dist/esm/commands/init.d.ts +3 -3
- package/dist/esm/commands/init.d.ts.map +1 -1
- package/dist/esm/commands/init.js +95 -9
- package/dist/esm/commands/init.js.map +1 -1
- package/dist/esm/commands/install/reporter.d.ts +3 -2
- package/dist/esm/commands/install/reporter.d.ts.map +1 -1
- package/dist/esm/commands/install/reporter.js +42 -15
- package/dist/esm/commands/install/reporter.js.map +1 -1
- package/dist/esm/commands/install.d.ts +21 -3
- package/dist/esm/commands/install.d.ts.map +1 -1
- package/dist/esm/commands/install.js +27 -3
- package/dist/esm/commands/install.js.map +1 -1
- package/dist/esm/commands/list.d.ts +2 -2
- package/dist/esm/commands/list.d.ts.map +1 -1
- package/dist/esm/commands/list.js +149 -49
- package/dist/esm/commands/list.js.map +1 -1
- package/dist/esm/commands/pack.d.ts +32 -0
- package/dist/esm/commands/pack.d.ts.map +1 -0
- package/dist/esm/commands/pack.js +147 -0
- package/dist/esm/commands/pack.js.map +1 -0
- package/dist/esm/commands/pkg.d.ts +1 -2
- package/dist/esm/commands/pkg.d.ts.map +1 -1
- package/dist/esm/commands/pkg.js +123 -38
- package/dist/esm/commands/pkg.js.map +1 -1
- package/dist/esm/commands/publish.d.ts +22 -0
- package/dist/esm/commands/publish.d.ts.map +1 -0
- package/dist/esm/commands/publish.js +245 -0
- package/dist/esm/commands/publish.js.map +1 -0
- package/dist/esm/commands/query.d.ts +2 -3
- package/dist/esm/commands/query.d.ts.map +1 -1
- package/dist/esm/commands/query.js +132 -38
- package/dist/esm/commands/query.js.map +1 -1
- package/dist/esm/commands/run-exec.d.ts +1 -0
- package/dist/esm/commands/run-exec.d.ts.map +1 -1
- package/dist/esm/commands/run-exec.js +1 -0
- package/dist/esm/commands/run-exec.js.map +1 -1
- package/dist/esm/commands/run.d.ts +1 -0
- package/dist/esm/commands/run.d.ts.map +1 -1
- package/dist/esm/commands/run.js +13 -16
- package/dist/esm/commands/run.js.map +1 -1
- package/dist/esm/commands/serve.d.ts +14 -0
- package/dist/esm/commands/serve.d.ts.map +1 -0
- package/dist/esm/commands/serve.js +103 -0
- package/dist/esm/commands/serve.js.map +1 -0
- package/dist/esm/commands/uninstall.d.ts +8 -2
- package/dist/esm/commands/uninstall.d.ts.map +1 -1
- package/dist/esm/commands/uninstall.js +8 -3
- package/dist/esm/commands/uninstall.js.map +1 -1
- package/dist/esm/commands/update.d.ts +14 -0
- package/dist/esm/commands/update.d.ts.map +1 -0
- package/dist/esm/commands/update.js +41 -0
- package/dist/esm/commands/update.js.map +1 -0
- package/dist/esm/commands/version.d.ts +26 -0
- package/dist/esm/commands/version.d.ts.map +1 -0
- package/dist/esm/commands/version.js +226 -0
- package/dist/esm/commands/version.js.map +1 -0
- package/dist/esm/config/definition.d.ts +118 -15
- package/dist/esm/config/definition.d.ts.map +1 -1
- package/dist/esm/config/definition.js +185 -37
- package/dist/esm/config/definition.js.map +1 -1
- package/dist/esm/config/index.d.ts +41 -37
- package/dist/esm/config/index.d.ts.map +1 -1
- package/dist/esm/config/index.js +109 -172
- package/dist/esm/config/index.js.map +1 -1
- package/dist/esm/config/merge.d.ts +3 -1
- package/dist/esm/config/merge.d.ts.map +1 -1
- package/dist/esm/config/merge.js +11 -6
- package/dist/esm/config/merge.js.map +1 -1
- package/dist/esm/custom-help.d.ts +9 -0
- package/dist/esm/custom-help.d.ts.map +1 -0
- package/dist/esm/custom-help.js +400 -0
- package/dist/esm/custom-help.js.map +1 -0
- package/dist/esm/exec-command.d.ts +33 -14
- package/dist/esm/exec-command.d.ts.map +1 -1
- package/dist/esm/exec-command.js +213 -64
- package/dist/esm/exec-command.js.map +1 -1
- package/dist/esm/index.d.ts +1 -14
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +45 -19
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/load-command.d.ts +16 -0
- package/dist/esm/load-command.d.ts.map +1 -0
- package/dist/esm/load-command.js +21 -0
- package/dist/esm/load-command.js.map +1 -0
- package/dist/esm/output.d.ts +6 -11
- package/dist/esm/output.d.ts.map +1 -1
- package/dist/esm/output.js +64 -27
- package/dist/esm/output.js.map +1 -1
- package/dist/esm/pack-tarball.d.ts +22 -0
- package/dist/esm/pack-tarball.d.ts.map +1 -0
- package/dist/esm/pack-tarball.js +249 -0
- package/dist/esm/pack-tarball.js.map +1 -0
- package/dist/esm/print-err.d.ts +9 -2
- package/dist/esm/print-err.d.ts.map +1 -1
- package/dist/esm/print-err.js +130 -46
- package/dist/esm/print-err.js.map +1 -1
- package/dist/esm/query-host-contexts.d.ts +16 -0
- package/dist/esm/query-host-contexts.d.ts.map +1 -0
- package/dist/esm/query-host-contexts.js +135 -0
- package/dist/esm/query-host-contexts.js.map +1 -0
- package/dist/esm/start-gui.d.ts +1 -0
- package/dist/esm/start-gui.d.ts.map +1 -1
- package/dist/esm/start-gui.js +25 -6
- package/dist/esm/start-gui.js.map +1 -1
- package/dist/esm/view.d.ts +2 -3
- package/dist/esm/view.d.ts.map +1 -1
- package/dist/esm/view.js +1 -1
- package/dist/esm/view.js.map +1 -1
- package/package.json +51 -37
- package/dist/esm/commands/gui.d.ts +0 -6
- package/dist/esm/commands/gui.d.ts.map +0 -1
- package/dist/esm/commands/gui.js +0 -13
- package/dist/esm/commands/gui.js.map +0 -1
package/dist/esm/exec-command.js
CHANGED
|
@@ -1,95 +1,217 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* impl for `vlt run`, `vlt run-exec`, `vlt exec-local`, `vlt exec`
|
|
3
|
+
* @module
|
|
3
4
|
*/
|
|
4
|
-
import { error
|
|
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';
|
|
5
9
|
import { isRunResult } from '@vltpkg/run';
|
|
6
10
|
import { Monorepo } from '@vltpkg/workspaces';
|
|
7
11
|
import { ansiToAnsi } from 'ansi-to-pre';
|
|
8
|
-
import
|
|
9
|
-
import
|
|
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
|
+
};
|
|
10
53
|
export class ExecCommand {
|
|
11
54
|
bg;
|
|
12
55
|
fg;
|
|
13
56
|
arg0;
|
|
14
57
|
args;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
58
|
+
env;
|
|
59
|
+
#monorepo;
|
|
60
|
+
#nodes;
|
|
61
|
+
#defaultIgnoreMissing = false;
|
|
18
62
|
conf;
|
|
19
63
|
projectRoot;
|
|
64
|
+
view;
|
|
65
|
+
validViewValues = new Map([
|
|
66
|
+
['human', 'human'],
|
|
67
|
+
['json', 'json'],
|
|
68
|
+
['inspect', 'inspect'],
|
|
69
|
+
['silent', 'silent'],
|
|
70
|
+
]);
|
|
20
71
|
constructor(conf, bg, fg) {
|
|
21
72
|
this.conf = conf;
|
|
22
73
|
this.bg = bg;
|
|
23
74
|
this.fg = fg;
|
|
75
|
+
this.view = this.validViewValues.get(conf.values.view) ?? 'human';
|
|
24
76
|
const { projectRoot, positionals: [arg0, ...args], } = conf;
|
|
25
77
|
this.arg0 = arg0;
|
|
26
78
|
this.args = args;
|
|
27
|
-
const paths = conf.get('workspace');
|
|
28
|
-
const groups = conf.get('workspace-group');
|
|
29
|
-
const recursive = conf.get('recursive');
|
|
30
|
-
this.monorepo =
|
|
31
|
-
paths?.length || groups?.length || recursive ?
|
|
32
|
-
Monorepo.load(projectRoot, { load: { paths, groups } })
|
|
33
|
-
: undefined;
|
|
34
|
-
this.spaces = this.monorepo?.size ?? 1;
|
|
35
79
|
this.projectRoot = projectRoot;
|
|
36
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
|
+
}
|
|
37
89
|
async run() {
|
|
38
|
-
|
|
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) {
|
|
39
137
|
const arg = this.fgArg();
|
|
40
138
|
if (!arg)
|
|
41
|
-
return;
|
|
139
|
+
return this.noArgsSingle();
|
|
42
140
|
const result = await this.fg(arg);
|
|
43
|
-
stdout(result);
|
|
44
141
|
if (isRunResult(result)) {
|
|
45
|
-
|
|
142
|
+
setExitCode(result);
|
|
46
143
|
}
|
|
47
144
|
return result;
|
|
48
145
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
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
|
+
}
|
|
55
158
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
this.noArgsMulti();
|
|
59
|
-
return;
|
|
159
|
+
if (!this.hasArg0()) {
|
|
160
|
+
return this.noArgsMulti();
|
|
60
161
|
}
|
|
61
162
|
// run across workspaces
|
|
62
163
|
let failed = false;
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
stderr(`${ws.path} ${arg0}`);
|
|
66
|
-
const result = await this.bg(this.bgArg(ws)).catch((er) => {
|
|
164
|
+
const runInDir = async (cwd, label) => {
|
|
165
|
+
const result = await this.bg(this.bgArg(cwd)).catch((er) => {
|
|
67
166
|
if (isErrorWithCause(er) && isRunResult(er.cause)) {
|
|
68
|
-
this.printResult(
|
|
167
|
+
this.printResult(label, er.cause);
|
|
69
168
|
}
|
|
70
169
|
failed = true;
|
|
71
170
|
throw er;
|
|
72
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;
|
|
73
177
|
if (!failed)
|
|
74
|
-
this.printResult(
|
|
178
|
+
this.printResult(label, result);
|
|
75
179
|
return result;
|
|
76
|
-
}
|
|
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
|
+
}
|
|
77
196
|
const results = {};
|
|
78
|
-
for (const [
|
|
197
|
+
for (const [path, result] of resultMap) {
|
|
79
198
|
if (result.status === 0 && result.signal === null) {
|
|
80
199
|
result.stdout = '';
|
|
81
200
|
result.stderr = '';
|
|
82
201
|
}
|
|
83
|
-
results[
|
|
202
|
+
results[path] = result;
|
|
84
203
|
}
|
|
85
204
|
return results;
|
|
86
205
|
}
|
|
87
|
-
printResult(
|
|
206
|
+
printResult(path, result) {
|
|
207
|
+
// non-human results just get printed at the end
|
|
208
|
+
if (this.view !== 'human')
|
|
209
|
+
return;
|
|
88
210
|
if (result.status === 0 && result.signal === null) {
|
|
89
|
-
stdout(
|
|
211
|
+
stdout(path, 'ok');
|
|
90
212
|
}
|
|
91
213
|
else {
|
|
92
|
-
stdout(
|
|
214
|
+
stdout(styleTextStdout(['bgWhiteBright', 'black', 'bold'], path + ' failure'), {
|
|
93
215
|
status: result.status,
|
|
94
216
|
signal: result.signal,
|
|
95
217
|
});
|
|
@@ -99,13 +221,9 @@ export class ExecCommand {
|
|
|
99
221
|
if (result.stdout)
|
|
100
222
|
stdout(ansiToAnsi(result.stdout));
|
|
101
223
|
/* c8 ignore stop */
|
|
102
|
-
|
|
224
|
+
setExitCode(result);
|
|
103
225
|
}
|
|
104
226
|
}
|
|
105
|
-
setExitCode(result) {
|
|
106
|
-
/* c8 ignore next */
|
|
107
|
-
process.exitCode = process.exitCode || (result.status ?? 1);
|
|
108
|
-
}
|
|
109
227
|
/* c8 ignore start - env specific */
|
|
110
228
|
interactiveShell() {
|
|
111
229
|
return (process.env.SHELL ??
|
|
@@ -113,47 +231,78 @@ export class ExecCommand {
|
|
|
113
231
|
(process.platform === 'win32' ? 'cmd.exe' : '/bin/sh'));
|
|
114
232
|
}
|
|
115
233
|
/* c8 ignore stop */
|
|
116
|
-
// overridden by 'vlt run'
|
|
234
|
+
// overridden by 'vlt run' which returns undefined
|
|
117
235
|
defaultArg0() {
|
|
118
236
|
return this.interactiveShell();
|
|
119
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
|
+
}
|
|
120
247
|
fgArg() {
|
|
121
|
-
const
|
|
122
|
-
const cwd = ws?.fullpath ?? this.projectRoot;
|
|
248
|
+
const cwd = this.getCwd();
|
|
123
249
|
const arg0 = this.arg0 ?? this.defaultArg0();
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
250
|
+
// return undefined so noArgsSingle will be called instead
|
|
251
|
+
if (typeof arg0 !== 'string')
|
|
252
|
+
return;
|
|
127
253
|
return {
|
|
128
254
|
cwd,
|
|
129
|
-
/* c8 ignore next - already guarded */
|
|
130
255
|
arg0,
|
|
131
256
|
args: this.args,
|
|
257
|
+
env: this.env,
|
|
132
258
|
projectRoot: this.projectRoot,
|
|
133
|
-
packageJson: this.
|
|
259
|
+
packageJson: this.conf.options.packageJson,
|
|
134
260
|
'script-shell': this.arg0 ? this.conf.get('script-shell') : false,
|
|
135
261
|
};
|
|
136
262
|
}
|
|
137
|
-
|
|
138
|
-
bgArg(ws) {
|
|
139
|
-
/* c8 ignore start - already guarded */
|
|
140
|
-
if (!this.arg0)
|
|
141
|
-
throw error('Cannot spawn interactive shells in multiple workspaces');
|
|
142
|
-
/* c8 ignore stop */
|
|
263
|
+
bgArg(cwd) {
|
|
143
264
|
return {
|
|
144
|
-
cwd
|
|
265
|
+
cwd,
|
|
145
266
|
acceptFail: !this.conf.get('bail'),
|
|
146
|
-
ignoreMissing:
|
|
267
|
+
ignoreMissing: this.conf.get('if-present') ?? this.#defaultIgnoreMissing,
|
|
147
268
|
arg0: this.arg0,
|
|
148
269
|
args: this.args,
|
|
270
|
+
env: this.env,
|
|
149
271
|
projectRoot: this.projectRoot,
|
|
150
|
-
packageJson: this.
|
|
272
|
+
packageJson: this.conf.options.packageJson,
|
|
151
273
|
'script-shell': this.conf.get('script-shell'),
|
|
152
274
|
};
|
|
153
275
|
}
|
|
154
|
-
|
|
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 */
|
|
155
281
|
noArgsMulti() {
|
|
156
282
|
throw error('Cannot spawn interactive shells in multiple workspaces');
|
|
157
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
|
+
}
|
|
158
307
|
}
|
|
159
308
|
//# sourceMappingURL=exec-command.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":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AAA;QAC5C,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,WAAW,EAAE,CAAA;QAC5C,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,OAAO,SAAS,CAAA;QAClB,CAAC;QAED,OAAO;YACL,GAAG;YACH,sCAAsC;YACtC,IAAI;YACJ,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,WAAW,EAAE,IAAI,CAAC,WAAW;YAC7B,WAAW,EAAE,IAAI,CAAC,QAAQ,EAAE,WAAW;YACvC,cAAc,EACZ,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,KAAK;SACpD,CAAA;IACH,CAAC;IAED,oDAAoD;IACpD,KAAK,CAAC,EAAa;QACjB,uCAAuC;QACvC,IAAI,CAAC,IAAI,CAAC,IAAI;YACZ,MAAM,KAAK,CACT,wDAAwD,CACzD,CAAA;QACH,oBAAoB;QAEpB,OAAO;YACL,GAAG,EAAE,EAAE,CAAC,QAAQ;YAChB,UAAU,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC;YAClC,aAAa,EAAE,IAAI;YACnB,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,WAAW,EAAE,IAAI,CAAC,WAAW;YAC7B,WAAW,EAAE,IAAI,CAAC,QAAQ,EAAE,WAAW;YACvC,cAAc,EAAE,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,cAAc,CAAC;SAC9C,CAAA;IACH,CAAC;IAED,qDAAqD;IACrD,WAAW;QACT,MAAM,KAAK,CACT,wDAAwD,CACzD,CAAA;IACH,CAAC;CACF","sourcesContent":["/**\n * Implementation shared between `vlt run`, `vlt run-exec`, and `vlt exec`\n */\n\nimport { error, isErrorWithCause } from '@vltpkg/error-cause'\nimport { isRunResult } from '@vltpkg/run'\nimport type {\n exec,\n execFG,\n ExecOptions,\n run,\n runExec,\n runExecFG,\n RunExecOptions,\n runFG,\n RunOptions,\n RunResult,\n} from '@vltpkg/run'\nimport { Monorepo } from '@vltpkg/workspaces'\nimport type { Workspace } from '@vltpkg/workspaces'\nimport { ansiToAnsi } from 'ansi-to-pre'\nimport chalk from 'chalk'\nimport type { LoadedConfig } from './config/index.ts'\nimport { stdout, stderr } from './output.ts'\nimport type { SpawnResultNoStdio } from '@vltpkg/promise-spawn'\n\nexport type RunnerBG = typeof exec | typeof run | typeof runExec\nexport type RunnerFG = typeof execFG | typeof runExecFG | typeof runFG\nexport type RunnerOptions = ExecOptions & RunExecOptions & RunOptions\nexport type ExecResult =\n | undefined\n | SpawnResultNoStdio\n | Record<string, RunResult>\n\nexport class ExecCommand<B extends RunnerBG, F extends RunnerFG> {\n bg: B\n fg: F\n arg0?: string\n args: string[]\n monorepo?: Monorepo\n /** how many places are we doing things in? */\n spaces: number\n conf: LoadedConfig\n projectRoot: string\n\n constructor(conf: LoadedConfig, bg: B, fg: F) {\n this.conf = conf\n this.bg = bg\n this.fg = fg\n const {\n projectRoot,\n positionals: [arg0, ...args],\n } = conf\n this.arg0 = arg0\n this.args = args\n\n const paths = conf.get('workspace')\n const groups = conf.get('workspace-group')\n const recursive = conf.get('recursive')\n this.monorepo =\n paths?.length || groups?.length || recursive ?\n Monorepo.load(projectRoot, { load: { paths, groups } })\n : undefined\n this.spaces = this.monorepo?.size ?? 1\n this.projectRoot = projectRoot\n }\n\n async run(): Promise<ExecResult> {\n if (this.spaces === 1) {\n const arg = this.fgArg()\n if (!arg) return\n const result = await this.fg(arg)\n stdout(result)\n if (isRunResult(result)) {\n this.setExitCode(result)\n }\n return result\n }\n const m = this.monorepo\n if (!m || this.spaces === 0) {\n throw error('no matching workspaces found', {\n /* c8 ignore next - already guarded */\n validOptions: [...(this.monorepo?.load().paths() ?? [])],\n })\n }\n const arg0 = this.arg0\n if (!arg0) {\n this.noArgsMulti()\n return\n }\n // run across workspaces\n let failed = false\n const resultMap = await m.run(async ws => {\n if (!failed) stderr(`${ws.path} ${arg0}`)\n const result = await this.bg(this.bgArg(ws)).catch(\n (er: unknown) => {\n if (isErrorWithCause(er) && isRunResult(er.cause)) {\n this.printResult(ws, er.cause)\n }\n failed = true\n throw er\n },\n )\n if (!failed) this.printResult(ws, result)\n return result\n })\n\n const results: Record<string, RunResult> = {}\n for (const [ws, result] of resultMap) {\n if (result.status === 0 && result.signal === null) {\n result.stdout = ''\n result.stderr = ''\n }\n results[ws.path] = result\n }\n return results\n }\n\n printResult(ws: Workspace, result: RunResult) {\n if (result.status === 0 && result.signal === null) {\n stdout(ws.path, 'ok')\n } else {\n stdout(chalk.bgWhiteBright.black.bold(ws.path + ' failure'), {\n status: result.status,\n signal: result.signal,\n })\n /* c8 ignore start */\n if (result.stderr) stderr(ansiToAnsi(result.stderr))\n if (result.stdout) stdout(ansiToAnsi(result.stdout))\n /* c8 ignore stop */\n this.setExitCode(result)\n }\n }\n\n setExitCode(result: RunResult) {\n /* c8 ignore next */\n process.exitCode = process.exitCode || (result.status ?? 1)\n }\n\n /* c8 ignore start - env specific */\n interactiveShell(): string {\n return (\n process.env.SHELL ??\n this.conf.get('script-shell') ??\n (process.platform === 'win32' ? 'cmd.exe' : '/bin/sh')\n )\n }\n /* c8 ignore stop */\n\n // overridden by 'vlt run' to print options and return undefined\n defaultArg0(): string | undefined {\n return this.interactiveShell()\n }\n\n fgArg(): RunnerOptions | undefined {\n const ws = this.monorepo?.values().next().value\n const cwd = ws?.fullpath ?? this.projectRoot\n const arg0 = this.arg0 ?? this.defaultArg0()\n if (!arg0) {\n return undefined\n }\n\n return {\n cwd,\n /* c8 ignore next - already guarded */\n arg0,\n args: this.args,\n projectRoot: this.projectRoot,\n packageJson: this.monorepo?.packageJson,\n 'script-shell':\n this.arg0 ? this.conf.get('script-shell') : false,\n }\n }\n\n /** If this returns undefined, then nothing to do */\n bgArg(ws: Workspace): RunnerOptions {\n /* c8 ignore start - already guarded */\n if (!this.arg0)\n throw error(\n 'Cannot spawn interactive shells in multiple workspaces',\n )\n /* c8 ignore stop */\n\n return {\n cwd: ws.fullpath,\n acceptFail: !this.conf.get('bail'),\n ignoreMissing: true,\n arg0: this.arg0,\n args: this.args,\n projectRoot: this.projectRoot,\n packageJson: this.monorepo?.packageJson,\n 'script-shell': this.conf.get('script-shell'),\n }\n }\n\n // overridden in `vlt run` to print available scripts\n noArgsMulti() {\n throw error(\n 'Cannot spawn interactive shells in multiple workspaces',\n )\n }\n}\n"]}
|
|
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,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAA;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAExC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAG7D,OAAO,MAAM,MAAM,aAAa,CAAA;AAChC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACnC,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAA;AAchE,MAAM,WAAW,GAAG,CAAC,CAAU,EAAkB,EAAE;IACjD,IAAI,CAAC,CAAC,IAAI,OAAO,CAAC,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAA;IAC7C,KAAK,MAAM,CAAC,IAAI,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC;QACjC,IAAI,OAAO,CAAC,KAAK,QAAQ;YAAE,OAAO,K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CAAC,CAAA;IAC/D,CAAC;IACD,sDAAsD;IAEtD,WAAW;QACT,MAAM,KAAK,CACT,wDAAwD,CACzD,CAAA;IACH,CAAC;IAED,UAAU;QAKR,MAAM,OAAO,GAAG,EAAE,CAAA;QAClB,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;YAChB,KAAK,MAAM,QAAQ,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;gBACnC,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;gBAC7D,MAAM,KAAK;gBACT,oBAAoB;gBACpB,QAAQ,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAA;gBAC1D,MAAM,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAA;gBAC/C,OAAO,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"]}
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,17 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
import type { LoadedConfig } from './config/index.ts';
|
|
3
|
-
import type { Views } from './view.ts';
|
|
4
|
-
export type CommandUsage = () => Jack;
|
|
5
|
-
/**
|
|
6
|
-
* A command function that may return a result of `T`.
|
|
7
|
-
* If the result is `undefined`, no final output will be displayed by default.
|
|
8
|
-
*/
|
|
9
|
-
export type CommandFn<T = unknown> = (conf: LoadedConfig) => Promise<T>;
|
|
10
|
-
export type Command<T> = {
|
|
11
|
-
command: CommandFn<T>;
|
|
12
|
-
usage: CommandUsage;
|
|
13
|
-
views: Views<T>;
|
|
14
|
-
};
|
|
1
|
+
export type { Command, CommandFn, CommandUsage, } from './load-command.ts';
|
|
15
2
|
declare const run: () => Promise<void>;
|
|
16
3
|
export default run;
|
|
17
4
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/esm/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"
|
|
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
CHANGED
|
@@ -1,33 +1,47 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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';
|
|
1
|
+
import { format } from 'node:util';
|
|
2
|
+
import { asRootError } from '@vltpkg/output/error';
|
|
10
3
|
import { loadPackageJson } from 'package-json-from-dist';
|
|
4
|
+
import { getSortedCliOptions, getSortedKeys, } from "./config/definition.js";
|
|
11
5
|
import { Config } from "./config/index.js";
|
|
12
|
-
import { outputCommand, stdout } from "./output.js";
|
|
6
|
+
import { outputCommand, stderr, stdout } from "./output.js";
|
|
7
|
+
import { indent } from "./print-err.js";
|
|
8
|
+
import { loadCommand } from "./load-command.js";
|
|
13
9
|
const { version } = loadPackageJson(import.meta.filename, process.env.__VLT_INTERNAL_CLI_PACKAGE_JSON);
|
|
14
|
-
const
|
|
10
|
+
const loadVlt = async (cwd, argv) => {
|
|
15
11
|
try {
|
|
16
|
-
return
|
|
17
|
-
/* c8 ignore start - should not be possible, just a failsafe */
|
|
12
|
+
return await Config.load(cwd, argv);
|
|
18
13
|
}
|
|
19
14
|
catch (e) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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);
|
|
24
39
|
}
|
|
25
|
-
/* c8 ignore stop */
|
|
26
40
|
};
|
|
27
41
|
const run = async () => {
|
|
28
42
|
const start = Date.now();
|
|
29
43
|
const cwd = process.cwd();
|
|
30
|
-
const vlt = await
|
|
44
|
+
const vlt = await loadVlt(cwd, process.argv);
|
|
31
45
|
if (vlt.get('version')) {
|
|
32
46
|
return stdout(version);
|
|
33
47
|
}
|
|
@@ -40,6 +54,18 @@ const run = async () => {
|
|
|
40
54
|
vlt.options.workspace = [ws.path];
|
|
41
55
|
}
|
|
42
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
|
+
}
|
|
43
69
|
const command = await loadCommand(vlt.command);
|
|
44
70
|
await outputCommand(command, vlt, { start });
|
|
45
71
|
};
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"
|
|
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,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,CAAA;IACrC,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,MAAM,GAAG,GAAG,WAAW,CAAC,CAAC,EAAE,EAAE,IAAI,EAAE,WAAW,EAAE,CAAC,CAAA;QACjD,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,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,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"]}
|
|
@@ -0,0 +1,16 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,21 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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"]}
|