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