@vltpkg/cli-sdk 0.0.0-3 → 0.0.0-31
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/README.md +3 -0
- 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 +65 -0
- package/dist/esm/commands/cache.d.ts.map +1 -0
- package/dist/esm/commands/cache.js +257 -0
- package/dist/esm/commands/cache.js.map +1 -0
- 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/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 +6 -0
- package/dist/esm/commands/exec-local.d.ts.map +1 -0
- package/dist/esm/commands/exec-local.js +24 -0
- package/dist/esm/commands/exec-local.js.map +1 -0
- package/dist/esm/commands/exec.d.ts +4 -0
- package/dist/esm/commands/exec.d.ts.map +1 -1
- package/dist/esm/commands/exec.js +75 -10
- 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 +25 -3
- package/dist/esm/commands/help.js.map +1 -1
- package/dist/esm/commands/init.d.ts +4 -5
- 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 +43 -15
- package/dist/esm/commands/install/reporter.js.map +1 -1
- package/dist/esm/commands/install.d.ts +24 -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 +1 -1
- package/dist/esm/commands/list.d.ts.map +1 -1
- package/dist/esm/commands/list.js +150 -42
- 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 +2 -3
- 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 +239 -0
- package/dist/esm/commands/publish.js.map +1 -0
- package/dist/esm/commands/query.d.ts +1 -1
- package/dist/esm/commands/query.d.ts.map +1 -1
- package/dist/esm/commands/query.js +171 -32
- 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 +13 -1
- package/dist/esm/commands/uninstall.d.ts.map +1 -1
- package/dist/esm/commands/uninstall.js +12 -1
- 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/commands/whoami.d.ts +4 -2
- package/dist/esm/commands/whoami.d.ts.map +1 -1
- package/dist/esm/commands/whoami.js +1 -1
- package/dist/esm/commands/whoami.js.map +1 -1
- package/dist/esm/config/definition.d.ts +117 -10
- package/dist/esm/config/definition.d.ts.map +1 -1
- package/dist/esm/config/definition.js +203 -31
- package/dist/esm/config/definition.js.map +1 -1
- package/dist/esm/config/index.d.ts +46 -40
- package/dist/esm/config/index.d.ts.map +1 -1
- package/dist/esm/config/index.js +126 -176
- 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/config/usage.d.ts +3 -2
- package/dist/esm/config/usage.d.ts.map +1 -1
- package/dist/esm/config/usage.js.map +1 -1
- 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 +214 -65
- 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 +46 -20
- 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 -10
- package/dist/esm/output.d.ts.map +1 -1
- package/dist/esm/output.js +63 -33
- 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 +247 -0
- package/dist/esm/pack-tarball.js.map +1 -0
- package/dist/esm/parse-add-remove-args.d.ts +1 -1
- package/dist/esm/parse-add-remove-args.d.ts.map +1 -1
- package/dist/esm/parse-add-remove-args.js +1 -1
- package/dist/esm/parse-add-remove-args.js.map +1 -1
- package/dist/esm/print-err.d.ts +12 -1
- package/dist/esm/print-err.d.ts.map +1 -1
- package/dist/esm/print-err.js +157 -26
- 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 +7 -33
- package/dist/esm/start-gui.d.ts.map +1 -1
- package/dist/esm/start-gui.js +51 -349
- 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 +73 -45
- 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 -14
- package/dist/esm/commands/gui.js.map +0 -1
- package/dist/esm/commands/install-exec.d.ts +0 -4
- package/dist/esm/commands/install-exec.d.ts.map +0 -1
- package/dist/esm/commands/install-exec.js +0 -13
- package/dist/esm/commands/install-exec.js.map +0 -1
- package/dist/esm/ignored-homedir-folder-names.d.ts +0 -7
- package/dist/esm/ignored-homedir-folder-names.d.ts.map +0 -1
- package/dist/esm/ignored-homedir-folder-names.js +0 -35
- package/dist/esm/ignored-homedir-folder-names.js.map +0 -1
- package/dist/esm/project-info.d.ts +0 -32
- package/dist/esm/project-info.d.ts.map +0 -1
- package/dist/esm/project-info.js +0 -90
- package/dist/esm/project-info.js.map +0 -1
- package/dist/esm/read-project-folders.d.ts +0 -27
- package/dist/esm/read-project-folders.d.ts.map +0 -1
- package/dist/esm/read-project-folders.js +0 -66
- package/dist/esm/read-project-folders.js.map +0 -1
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
import { error } from '@vltpkg/error-cause';
|
|
2
|
+
import { RegistryClient } from '@vltpkg/registry-client';
|
|
3
|
+
import { run } from '@vltpkg/run';
|
|
4
|
+
import { commandUsage } from "../config/usage.js";
|
|
5
|
+
import { packTarball } from "../pack-tarball.js";
|
|
6
|
+
import assert from 'node:assert';
|
|
7
|
+
import { asError } from '@vltpkg/types';
|
|
8
|
+
import { dirname, resolve } from 'node:path';
|
|
9
|
+
import prettyBytes from 'pretty-bytes';
|
|
10
|
+
import { actual } from '@vltpkg/graph';
|
|
11
|
+
import { Query } from '@vltpkg/query';
|
|
12
|
+
import { createHostContextsMap } from "../query-host-contexts.js";
|
|
13
|
+
export const usage = () => commandUsage({
|
|
14
|
+
command: 'publish',
|
|
15
|
+
usage: '',
|
|
16
|
+
description: `Create a tarball from a package and publish it to the configured registry.
|
|
17
|
+
|
|
18
|
+
This command will pack the package in the current directory or specified folder,
|
|
19
|
+
and then upload it to the configured registry.`,
|
|
20
|
+
options: {
|
|
21
|
+
tag: {
|
|
22
|
+
description: 'Publish the package with the given tag',
|
|
23
|
+
value: '<tag>',
|
|
24
|
+
},
|
|
25
|
+
access: {
|
|
26
|
+
description: 'Set access level (public or restricted)',
|
|
27
|
+
value: '<level>',
|
|
28
|
+
},
|
|
29
|
+
otp: {
|
|
30
|
+
description: `Provide an OTP to use when publishing a package.`,
|
|
31
|
+
value: '<otp>',
|
|
32
|
+
},
|
|
33
|
+
'publish-directory': {
|
|
34
|
+
description: `Directory to use for pack and publish operations instead of the current directory.
|
|
35
|
+
The directory must exist and nothing will be copied to it.`,
|
|
36
|
+
value: '<path>',
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
export const views = {
|
|
41
|
+
human: results => {
|
|
42
|
+
const item = (r) => {
|
|
43
|
+
const lines = [
|
|
44
|
+
`📦 Package: ${r.id}`,
|
|
45
|
+
`🏷️ Tag: ${r.tag}`,
|
|
46
|
+
`📡 Registry: ${r.registry}`,
|
|
47
|
+
`📁 ${r.files.length} Files`,
|
|
48
|
+
...r.files.map(f => ` - ${f}`),
|
|
49
|
+
`📊 Package Size: ${prettyBytes(r.size)}`,
|
|
50
|
+
`📂 Unpacked Size: ${prettyBytes(r.unpackedSize)}`,
|
|
51
|
+
];
|
|
52
|
+
if (r.shasum)
|
|
53
|
+
lines.push(`🔒 Shasum: ${r.shasum}`);
|
|
54
|
+
if (r.integrity)
|
|
55
|
+
lines.push(`🔐 Integrity: ${r.integrity}`);
|
|
56
|
+
return lines.join('\n');
|
|
57
|
+
};
|
|
58
|
+
return Array.isArray(results) ?
|
|
59
|
+
results.map(item).join('\n\n')
|
|
60
|
+
: item(results);
|
|
61
|
+
},
|
|
62
|
+
json: r => r,
|
|
63
|
+
};
|
|
64
|
+
export const command = async (conf) => {
|
|
65
|
+
const { options, projectRoot } = conf;
|
|
66
|
+
const queryString = conf.get('scope');
|
|
67
|
+
const paths = conf.get('workspace');
|
|
68
|
+
const groups = conf.get('workspace-group');
|
|
69
|
+
const recursive = conf.get('recursive');
|
|
70
|
+
const locations = [];
|
|
71
|
+
let single = null;
|
|
72
|
+
if (queryString) {
|
|
73
|
+
const mainManifest = options.packageJson.maybeRead(projectRoot);
|
|
74
|
+
let graph;
|
|
75
|
+
if (mainManifest) {
|
|
76
|
+
graph = actual.load({
|
|
77
|
+
...options,
|
|
78
|
+
mainManifest,
|
|
79
|
+
monorepo: options.monorepo,
|
|
80
|
+
loadManifests: false,
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
const hostContexts = await createHostContextsMap(conf);
|
|
84
|
+
const query = new Query({
|
|
85
|
+
/* c8 ignore next */
|
|
86
|
+
nodes: graph ? new Set(graph.nodes.values()) : new Set(),
|
|
87
|
+
edges: graph?.edges ?? new Set(),
|
|
88
|
+
importers: graph?.importers ?? new Set(),
|
|
89
|
+
securityArchive: undefined,
|
|
90
|
+
hostContexts,
|
|
91
|
+
});
|
|
92
|
+
const { nodes } = await query.search(queryString, {
|
|
93
|
+
signal: new AbortController().signal,
|
|
94
|
+
});
|
|
95
|
+
for (const node of nodes) {
|
|
96
|
+
const { location } = node.toJSON();
|
|
97
|
+
assert(location, error(`node ${node.id} has no location`, {
|
|
98
|
+
found: node,
|
|
99
|
+
}));
|
|
100
|
+
locations.push(resolve(projectRoot, location));
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
else if (paths?.length || groups?.length || recursive) {
|
|
104
|
+
for (const workspace of options.monorepo ?? []) {
|
|
105
|
+
locations.push(workspace.fullpath);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
single = options.packageJson.find(process.cwd()) ?? projectRoot;
|
|
110
|
+
}
|
|
111
|
+
if (single) {
|
|
112
|
+
return commandSingle(single, conf);
|
|
113
|
+
}
|
|
114
|
+
assert(locations.length > 0, error('No workspaces or query results found'));
|
|
115
|
+
const results = [];
|
|
116
|
+
for (const location of locations) {
|
|
117
|
+
results.push(await commandSingle(location, conf));
|
|
118
|
+
}
|
|
119
|
+
return results;
|
|
120
|
+
};
|
|
121
|
+
const commandSingle = async (location, conf) => {
|
|
122
|
+
const manifestPath = conf.options.packageJson.find(location);
|
|
123
|
+
assert(manifestPath, 'No package.json found');
|
|
124
|
+
const manifestDir = dirname(manifestPath);
|
|
125
|
+
const manifest = conf.options.packageJson.read(manifestDir);
|
|
126
|
+
assert(!manifest.private, error('Package has been marked as private'));
|
|
127
|
+
const { tag = 'latest', access, registry, 'dry-run': dry = false, otp, } = conf.options;
|
|
128
|
+
const registryUrl = new URL(registry);
|
|
129
|
+
const runOptions = {
|
|
130
|
+
cwd: manifestDir,
|
|
131
|
+
projectRoot: conf.projectRoot,
|
|
132
|
+
packageJson: conf.options.packageJson,
|
|
133
|
+
manifest,
|
|
134
|
+
ignoreMissing: true,
|
|
135
|
+
ignorePrePost: true,
|
|
136
|
+
};
|
|
137
|
+
await run({
|
|
138
|
+
...runOptions,
|
|
139
|
+
arg0: 'prepublishOnly',
|
|
140
|
+
});
|
|
141
|
+
await run({
|
|
142
|
+
...runOptions,
|
|
143
|
+
arg0: 'prepublish',
|
|
144
|
+
});
|
|
145
|
+
await run({
|
|
146
|
+
...runOptions,
|
|
147
|
+
arg0: 'prepack',
|
|
148
|
+
});
|
|
149
|
+
await run({
|
|
150
|
+
...runOptions,
|
|
151
|
+
arg0: 'prepare',
|
|
152
|
+
});
|
|
153
|
+
const { name, version, tarballName, tarballData, unpackedSize, files, integrity, shasum, } = await packTarball(manifest, manifestDir, conf);
|
|
154
|
+
await run({
|
|
155
|
+
...runOptions,
|
|
156
|
+
arg0: 'postpack',
|
|
157
|
+
});
|
|
158
|
+
await run({
|
|
159
|
+
...runOptions,
|
|
160
|
+
arg0: 'publish',
|
|
161
|
+
});
|
|
162
|
+
const publishMetadata = {
|
|
163
|
+
_id: name,
|
|
164
|
+
name,
|
|
165
|
+
description: manifest.description || '',
|
|
166
|
+
'dist-tags': {
|
|
167
|
+
[tag]: version,
|
|
168
|
+
},
|
|
169
|
+
versions: {
|
|
170
|
+
[version]: {
|
|
171
|
+
...manifest,
|
|
172
|
+
_id: `${name}@${version}`,
|
|
173
|
+
_nodeVersion: process.versions.node,
|
|
174
|
+
dist: {
|
|
175
|
+
...manifest.dist,
|
|
176
|
+
integrity,
|
|
177
|
+
shasum,
|
|
178
|
+
tarball: new URL(`${name}/-/${tarballName}`, registryUrl)
|
|
179
|
+
.href,
|
|
180
|
+
},
|
|
181
|
+
},
|
|
182
|
+
},
|
|
183
|
+
access,
|
|
184
|
+
_attachments: {
|
|
185
|
+
[tarballName]: {
|
|
186
|
+
content_type: 'application/octet-stream',
|
|
187
|
+
data: tarballData.toString('base64'),
|
|
188
|
+
length: tarballData.length,
|
|
189
|
+
},
|
|
190
|
+
},
|
|
191
|
+
};
|
|
192
|
+
const rc = new RegistryClient(conf.options);
|
|
193
|
+
const publishUrl = new URL(name.startsWith('@') ? name.replace('/', '%2F') : name, registryUrl);
|
|
194
|
+
if (!dry) {
|
|
195
|
+
let response;
|
|
196
|
+
try {
|
|
197
|
+
response = await rc.request(publishUrl, {
|
|
198
|
+
method: 'PUT',
|
|
199
|
+
headers: {
|
|
200
|
+
'content-type': 'application/json',
|
|
201
|
+
// These control what type of OTP auth flow is used
|
|
202
|
+
'npm-auth-type': 'web',
|
|
203
|
+
'npm-command': 'publish',
|
|
204
|
+
},
|
|
205
|
+
body: JSON.stringify(publishMetadata),
|
|
206
|
+
otp,
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
catch (err) {
|
|
210
|
+
throw error('Failed to publish package', {
|
|
211
|
+
cause: asError(err),
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
if (response.statusCode !== 200 && response.statusCode !== 201) {
|
|
215
|
+
throw error('Failed to publish package', {
|
|
216
|
+
url: publishUrl,
|
|
217
|
+
response,
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
await run({
|
|
222
|
+
...runOptions,
|
|
223
|
+
arg0: 'postpublish',
|
|
224
|
+
});
|
|
225
|
+
return {
|
|
226
|
+
id: `${name}@${version}`,
|
|
227
|
+
name,
|
|
228
|
+
version,
|
|
229
|
+
tag,
|
|
230
|
+
access,
|
|
231
|
+
registry: registryUrl.origin,
|
|
232
|
+
integrity,
|
|
233
|
+
shasum,
|
|
234
|
+
size: tarballData.length,
|
|
235
|
+
unpackedSize,
|
|
236
|
+
files,
|
|
237
|
+
};
|
|
238
|
+
};
|
|
239
|
+
//# sourceMappingURL=publish.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"publish.js","sourceRoot":"","sources":["../../../src/commands/publish.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB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I,EAAE,IAAI,CAAC,SAAS,CAAC,eAAe,CAAC;gBACrC,GAAG;aACJ,CAAC,CAAA;QACJ,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,MAAM,KAAK,CAAC,2BAA2B,EAAE;gBACvC,KAAK,EAAE,OAAO,CAAC,GAAG,CAAC;aACpB,CAAC,CAAA;QACJ,CAAC;QAED,IAAI,QAAQ,CAAC,UAAU,KAAK,GAAG,IAAI,QAAQ,CAAC,UAAU,KAAK,GAAG,EAAE,CAAC;YAC/D,MAAM,KAAK,CAAC,2BAA2B,EAAE;gBACvC,GAAG,EAAE,UAAU;gBACf,QAAQ;aACT,CAAC,CAAA;QACJ,CAAC;IACH,CAAC;IAED,MAAM,GAAG,CAAC;QACR,GAAG,UAAU;QACb,IAAI,EAAE,aAAa;KACpB,CAAC,CAAA;IAEF,OAAO;QACL,EAAE,EAAE,GAAG,IAAI,IAAI,OAAO,EAAE;QACxB,IAAI;QACJ,OAAO;QACP,GAAG;QACH,MAAM;QACN,QAAQ,EAAE,WAAW,CAAC,MAAM;QAC5B,SAAS;QACT,MAAM;QACN,IAAI,EAAE,WAAW,CAAC,MAAM;QACxB,YAAY;QACZ,KAAK;KACN,CAAA;AACH,CAAC,CAAA","sourcesContent":["import { error } from '@vltpkg/error-cause'\nimport { RegistryClient } from '@vltpkg/registry-client'\nimport type { CacheEntry } from '@vltpkg/registry-client'\nimport { run } from '@vltpkg/run'\nimport { commandUsage } from '../config/usage.ts'\nimport type { CommandFn, CommandUsage } from '../index.ts'\nimport { packTarball } from '../pack-tarball.ts'\nimport type { Views } from '../view.ts'\nimport assert from 'node:assert'\nimport { asError } from '@vltpkg/types'\nimport { dirname, resolve } from 'node:path'\nimport prettyBytes from 'pretty-bytes'\nimport { actual } from '@vltpkg/graph'\nimport { Query } from '@vltpkg/query'\nimport type { LoadedConfig } from '../config/index.ts'\nimport { createHostContextsMap } from '../query-host-contexts.ts'\n\nexport const usage: CommandUsage = () =>\n commandUsage({\n command: 'publish',\n usage: '',\n description: `Create a tarball from a package and publish it to the configured registry.\n \n This command will pack the package in the current directory or specified folder,\n and then upload it to the configured registry.`,\n options: {\n tag: {\n description: 'Publish the package with the given tag',\n value: '<tag>',\n },\n access: {\n description: 'Set access level (public or restricted)',\n value: '<level>',\n },\n otp: {\n description: `Provide an OTP to use when publishing a package.`,\n value: '<otp>',\n },\n 'publish-directory': {\n description: `Directory to use for pack and publish operations instead of the current directory.\n The directory must exist and nothing will be copied to it.`,\n value: '<path>',\n },\n },\n })\n\nexport type CommandResultSingle = {\n id: string\n name: string\n version: string\n tag: string\n registry: string\n shasum?: string\n integrity?: string\n size: number\n access: string\n unpackedSize: number\n files: string[]\n}\n\nexport type CommandResult =\n | CommandResultSingle\n | CommandResultSingle[]\n\nexport const views = {\n human: results => {\n const item = (r: CommandResultSingle) => {\n const lines = [\n `📦 Package: ${r.id}`,\n `🏷️ Tag: ${r.tag}`,\n `📡 Registry: ${r.registry}`,\n `📁 ${r.files.length} Files`,\n ...r.files.map(f => ` - ${f}`),\n `📊 Package Size: ${prettyBytes(r.size)}`,\n `📂 Unpacked Size: ${prettyBytes(r.unpackedSize)}`,\n ]\n if (r.shasum) lines.push(`🔒 Shasum: ${r.shasum}`)\n if (r.integrity) lines.push(`🔐 Integrity: ${r.integrity}`)\n return lines.join('\\n')\n }\n return Array.isArray(results) ?\n results.map(item).join('\\n\\n')\n : item(results)\n },\n json: r => r,\n} as const satisfies Views<CommandResult>\n\nexport const command: CommandFn<CommandResult> = async conf => {\n const { options, projectRoot } = conf\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 const locations: string[] = []\n let single: string | null = null\n\n if (queryString) {\n const mainManifest = options.packageJson.maybeRead(projectRoot)\n let graph\n if (mainManifest) {\n graph = actual.load({\n ...options,\n mainManifest,\n monorepo: options.monorepo,\n loadManifests: false,\n })\n }\n const hostContexts = await createHostContextsMap(conf)\n const query = new Query({\n /* c8 ignore next */\n nodes: graph ? new Set(graph.nodes.values()) : new Set(),\n edges: graph?.edges ?? new Set(),\n importers: graph?.importers ?? new Set(),\n securityArchive: undefined,\n hostContexts,\n })\n const { nodes } = await query.search(queryString, {\n signal: new AbortController().signal,\n })\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 locations.push(resolve(projectRoot, location))\n }\n } else if (paths?.length || groups?.length || recursive) {\n for (const workspace of options.monorepo ?? []) {\n locations.push(workspace.fullpath)\n }\n } else {\n single = options.packageJson.find(process.cwd()) ?? projectRoot\n }\n\n if (single) {\n return commandSingle(single, conf)\n }\n\n assert(\n locations.length > 0,\n error('No workspaces or query results found'),\n )\n\n const results: CommandResultSingle[] = []\n for (const location of locations) {\n results.push(await commandSingle(location, conf))\n }\n return results\n}\n\nconst commandSingle = async (\n location: string,\n conf: LoadedConfig,\n) => {\n const manifestPath = conf.options.packageJson.find(location)\n assert(manifestPath, 'No package.json found')\n const manifestDir = dirname(manifestPath)\n const manifest = conf.options.packageJson.read(manifestDir)\n\n assert(\n !manifest.private,\n error('Package has been marked as private'),\n )\n\n const {\n tag = 'latest',\n access,\n registry,\n 'dry-run': dry = false,\n otp,\n } = conf.options\n const registryUrl = new URL(registry)\n\n const runOptions = {\n cwd: manifestDir,\n projectRoot: conf.projectRoot,\n packageJson: conf.options.packageJson,\n manifest,\n ignoreMissing: true,\n ignorePrePost: true,\n }\n\n await run({\n ...runOptions,\n arg0: 'prepublishOnly',\n })\n\n await run({\n ...runOptions,\n arg0: 'prepublish',\n })\n\n await run({\n ...runOptions,\n arg0: 'prepack',\n })\n\n await run({\n ...runOptions,\n arg0: 'prepare',\n })\n\n const {\n name,\n version,\n tarballName,\n tarballData,\n unpackedSize,\n files,\n integrity,\n shasum,\n } = await packTarball(manifest, manifestDir, conf)\n\n await run({\n ...runOptions,\n arg0: 'postpack',\n })\n\n await run({\n ...runOptions,\n arg0: 'publish',\n })\n\n const publishMetadata = {\n _id: name,\n name,\n description: manifest.description || '',\n 'dist-tags': {\n [tag]: version,\n },\n versions: {\n [version]: {\n ...manifest,\n _id: `${name}@${version}`,\n _nodeVersion: process.versions.node,\n dist: {\n ...manifest.dist,\n integrity,\n shasum,\n tarball: new URL(`${name}/-/${tarballName}`, registryUrl)\n .href,\n },\n },\n },\n access,\n _attachments: {\n [tarballName]: {\n content_type: 'application/octet-stream',\n data: tarballData.toString('base64'),\n length: tarballData.length,\n },\n },\n }\n\n const rc = new RegistryClient(conf.options)\n const publishUrl = new URL(\n name.startsWith('@') ? name.replace('/', '%2F') : name,\n registryUrl,\n )\n\n if (!dry) {\n let response: CacheEntry\n try {\n response = await rc.request(publishUrl, {\n method: 'PUT',\n headers: {\n 'content-type': 'application/json',\n // These control what type of OTP auth flow is used\n 'npm-auth-type': 'web',\n 'npm-command': 'publish',\n },\n body: JSON.stringify(publishMetadata),\n otp,\n })\n } catch (err) {\n throw error('Failed to publish package', {\n cause: asError(err),\n })\n }\n\n if (response.statusCode !== 200 && response.statusCode !== 201) {\n throw error('Failed to publish package', {\n url: publishUrl,\n response,\n })\n }\n }\n\n await run({\n ...runOptions,\n arg0: 'postpublish',\n })\n\n return {\n id: `${name}@${version}`,\n name,\n version,\n tag,\n access,\n registry: registryUrl.origin,\n integrity,\n shasum,\n size: tarballData.length,\n unpackedSize,\n files,\n }\n}\n"]}
|
|
@@ -9,7 +9,7 @@ export declare const views: {
|
|
|
9
9
|
readonly json: typeof jsonOutput;
|
|
10
10
|
readonly mermaid: typeof mermaidOutput;
|
|
11
11
|
readonly human: typeof humanReadableOutput;
|
|
12
|
-
readonly gui: ({ queryString }: QueryResult, _: import("../view.ts").ViewOptions, conf: import("../config/index.ts").
|
|
12
|
+
readonly gui: ({ queryString }: QueryResult, _: import("../view.ts").ViewOptions, conf: import("../config/index.ts").ParsedConfig) => Promise<void>;
|
|
13
13
|
};
|
|
14
14
|
export declare const command: CommandFn<QueryResult>;
|
|
15
15
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../../../src/commands/query.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../../../src/commands/query.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,mBAAmB,EACnB,UAAU,EACV,aAAa,EAEd,MAAM,eAAe,CAAA;AAQtB,OAAO,KAAK,EACV,wBAAwB,EACxB,eAAe,EACf,kBAAkB,EAGnB,MAAM,eAAe,CAAA;AAGtB,OAAO,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAI1D,eAAO,MAAM,KAAK,EAAE,YA4EhB,CAAA;AAEJ,KAAK,WAAW,GAAG,eAAe,GAChC,kBAAkB,GAClB,wBAAwB,GAAG;IAAE,WAAW,EAAE,MAAM,CAAA;CAAE,CAAA;AAqBpD,eAAO,MAAM,KAAK;;;;;CAUqB,CAAA;AAEvC,eAAO,MAAM,OAAO,EAAE,SAAS,CAAC,WAAW,CAqI1C,CAAA"}
|
|
@@ -1,16 +1,38 @@
|
|
|
1
|
-
import { actual, humanReadableOutput, jsonOutput, mermaidOutput, } from '@vltpkg/graph';
|
|
1
|
+
import { actual, asNode, humanReadableOutput, jsonOutput, mermaidOutput, GraphModifier, } from '@vltpkg/graph';
|
|
2
|
+
import { error } from '@vltpkg/error-cause';
|
|
3
|
+
import LZString from 'lz-string';
|
|
2
4
|
import { Query } from '@vltpkg/query';
|
|
3
|
-
import {
|
|
5
|
+
import { SecurityArchive } from '@vltpkg/security-archive';
|
|
4
6
|
import { startGUI } from "../start-gui.js";
|
|
7
|
+
import { commandUsage } from "../config/usage.js";
|
|
8
|
+
import { createHostContextsMap } from "../query-host-contexts.js";
|
|
5
9
|
export const usage = () => commandUsage({
|
|
6
10
|
command: 'query',
|
|
7
|
-
usage: [
|
|
8
|
-
|
|
11
|
+
usage: [
|
|
12
|
+
'',
|
|
13
|
+
'<query> --view=<human | json | mermaid | gui>',
|
|
14
|
+
'<query> --expect-results=<comparison string>',
|
|
15
|
+
'--target=<query> --view=<human | json | mermaid | gui>',
|
|
16
|
+
],
|
|
17
|
+
description: `List installed dependencies matching the provided query.
|
|
18
|
+
|
|
19
|
+
The vlt Dependency Selector Syntax is a CSS-like query language that
|
|
20
|
+
allows you to filter installed dependencies using a variety of metadata
|
|
21
|
+
in the form of CSS-like attributes, pseudo selectors & combinators.
|
|
22
|
+
|
|
23
|
+
The --scope and --target options accepts DSS query selectors to filter
|
|
24
|
+
packages. Using --scope, you can specify which packages to treat as the
|
|
25
|
+
top-level items in the output graph. The --target option can be used as
|
|
26
|
+
an alternative to positional arguments, it allows you to filter what
|
|
27
|
+
dependencies to include in the output. Using both options allows you to
|
|
28
|
+
render subgraphs of the dependency graph.
|
|
29
|
+
|
|
30
|
+
Defaults to listing all dependencies of the project root and workspaces.`,
|
|
9
31
|
examples: {
|
|
10
32
|
[`'#foo'`]: {
|
|
11
|
-
description: 'Query
|
|
33
|
+
description: 'Query dependencies declared as "foo"',
|
|
12
34
|
},
|
|
13
|
-
[`'
|
|
35
|
+
[`'*:workspace > *:peer'`]: {
|
|
14
36
|
description: 'Query all peer dependencies of workspaces',
|
|
15
37
|
},
|
|
16
38
|
[`':project > *:attr(scripts, [build])'`]: {
|
|
@@ -19,57 +41,174 @@ export const usage = () => commandUsage({
|
|
|
19
41
|
[`'[name^="@vltpkg"]'`]: {
|
|
20
42
|
description: 'Query packages with names starting with "@vltpkg"',
|
|
21
43
|
},
|
|
44
|
+
[`'*:license(copyleft) --expect-results=0'`]: {
|
|
45
|
+
description: 'Errors if a copyleft licensed package is found',
|
|
46
|
+
},
|
|
47
|
+
'--scope=":root > #dependency-name"': {
|
|
48
|
+
description: 'Defines a direct dependency as the output top-level scope',
|
|
49
|
+
},
|
|
50
|
+
[`'--target="*"'`]: {
|
|
51
|
+
description: 'Query all dependencies using the target option',
|
|
52
|
+
},
|
|
53
|
+
[`'--target=":workspace > *:peer"'`]: {
|
|
54
|
+
description: 'Query all peer dependencies of workspaces using target option',
|
|
55
|
+
},
|
|
22
56
|
},
|
|
23
57
|
options: {
|
|
58
|
+
'expect-results': {
|
|
59
|
+
value: '[number | string]',
|
|
60
|
+
description: 'Sets an expected number of resulting items. Errors if the number of resulting items does not match the set value. Accepts a specific numeric value or a string value starting with either ">", "<", ">=" or "<=" followed by a numeric value to be compared.',
|
|
61
|
+
},
|
|
62
|
+
scope: {
|
|
63
|
+
value: '<query>',
|
|
64
|
+
description: 'Query selector to select top-level packages using the DSS query language syntax.',
|
|
65
|
+
},
|
|
66
|
+
target: {
|
|
67
|
+
value: '<query>',
|
|
68
|
+
description: 'Query selector to filter packages using DSS syntax.',
|
|
69
|
+
},
|
|
24
70
|
view: {
|
|
25
71
|
value: '[human | json | mermaid | gui]',
|
|
26
72
|
description: 'Output format. Defaults to human-readable or json if no tty.',
|
|
27
73
|
},
|
|
28
74
|
},
|
|
29
75
|
});
|
|
76
|
+
const validateExpectedResult = (conf, edges) => {
|
|
77
|
+
const expectResults = conf.values['expect-results'];
|
|
78
|
+
if (expectResults?.startsWith('>=')) {
|
|
79
|
+
return edges.length >= parseInt(expectResults.slice(2).trim(), 10);
|
|
80
|
+
}
|
|
81
|
+
else if (expectResults?.startsWith('<=')) {
|
|
82
|
+
return edges.length <= parseInt(expectResults.slice(2).trim(), 10);
|
|
83
|
+
}
|
|
84
|
+
else if (expectResults?.startsWith('>')) {
|
|
85
|
+
return edges.length > parseInt(expectResults.slice(1).trim(), 10);
|
|
86
|
+
}
|
|
87
|
+
else if (expectResults?.startsWith('<')) {
|
|
88
|
+
return edges.length < parseInt(expectResults.slice(1).trim(), 10);
|
|
89
|
+
}
|
|
90
|
+
else if (expectResults) {
|
|
91
|
+
return edges.length === parseInt(expectResults.trim(), 10);
|
|
92
|
+
}
|
|
93
|
+
return true;
|
|
94
|
+
};
|
|
30
95
|
export const views = {
|
|
31
96
|
json: jsonOutput,
|
|
32
97
|
mermaid: mermaidOutput,
|
|
33
98
|
human: humanReadableOutput,
|
|
34
99
|
gui: async ({ queryString }, _, conf) => {
|
|
35
|
-
await startGUI({
|
|
36
|
-
conf,
|
|
37
|
-
startingRoute: '/explore?query=' + encodeURIComponent(queryString),
|
|
38
|
-
});
|
|
100
|
+
await startGUI(conf, `/explore/${LZString.compressToEncodedURIComponent(queryString)}/overview`);
|
|
39
101
|
},
|
|
40
102
|
};
|
|
41
103
|
export const command = async (conf) => {
|
|
104
|
+
const modifiers = GraphModifier.maybeLoad(conf.options);
|
|
42
105
|
const monorepo = conf.options.monorepo;
|
|
43
|
-
const mainManifest = conf.options.packageJson.
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
106
|
+
const mainManifest = conf.options.packageJson.maybeRead(conf.options.projectRoot);
|
|
107
|
+
let graph;
|
|
108
|
+
let securityArchive;
|
|
109
|
+
// optionally load the cwd graph if we found a package.json file
|
|
110
|
+
if (mainManifest) {
|
|
111
|
+
graph = actual.load({
|
|
112
|
+
...conf.options,
|
|
113
|
+
mainManifest,
|
|
114
|
+
modifiers,
|
|
115
|
+
monorepo,
|
|
116
|
+
loadManifests: true,
|
|
117
|
+
});
|
|
118
|
+
securityArchive = await SecurityArchive.start({
|
|
119
|
+
nodes: [...graph.nodes.values()],
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
// retrieve default values and set up host contexts
|
|
123
|
+
const defaultProjectQueryString = '*';
|
|
124
|
+
const defaultLocalScopeQueryString = ':host(local) *';
|
|
125
|
+
const positionalQueryString = conf.positionals[0];
|
|
126
|
+
const targetQueryString = conf.get('target');
|
|
127
|
+
const scopeQueryString = conf.get('scope');
|
|
128
|
+
const queryString = targetQueryString || positionalQueryString;
|
|
129
|
+
const hostContexts = await createHostContextsMap(conf);
|
|
54
130
|
const importers = new Set();
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
131
|
+
const scopeIDs = [];
|
|
132
|
+
// Handle --scope option to add scope nodes as importers
|
|
133
|
+
let scopeNodes;
|
|
134
|
+
if (scopeQueryString) {
|
|
135
|
+
// Run scope query to get all matching nodes
|
|
136
|
+
/* c8 ignore start */
|
|
137
|
+
const edges = graph?.edges ?? new Set();
|
|
138
|
+
const nodes = graph?.nodes ?
|
|
139
|
+
new Set(graph.nodes.values())
|
|
140
|
+
: new Set();
|
|
141
|
+
const importers = graph?.importers ?? new Set();
|
|
142
|
+
/* c8 ignore stop */
|
|
143
|
+
const scopeQuery = new Query({
|
|
144
|
+
edges,
|
|
145
|
+
nodes,
|
|
146
|
+
importers,
|
|
147
|
+
securityArchive,
|
|
148
|
+
hostContexts,
|
|
149
|
+
});
|
|
150
|
+
const { nodes: resultNodes } = await scopeQuery.search(scopeQueryString, {
|
|
151
|
+
signal: new AbortController().signal,
|
|
152
|
+
});
|
|
153
|
+
scopeNodes = resultNodes;
|
|
154
|
+
}
|
|
155
|
+
if (scopeQueryString && scopeNodes) {
|
|
156
|
+
// Add all scope nodes to importers Set (treat them as top-level items)
|
|
157
|
+
for (const queryNode of scopeNodes) {
|
|
158
|
+
importers.add(asNode(queryNode));
|
|
60
159
|
}
|
|
61
160
|
}
|
|
62
|
-
if (
|
|
63
|
-
|
|
64
|
-
|
|
161
|
+
else if ('workspace' in conf.values) {
|
|
162
|
+
// if in a workspace environment, select only the specified
|
|
163
|
+
// workspaces as top-level items
|
|
164
|
+
if (monorepo && graph) {
|
|
165
|
+
for (const workspace of monorepo.filter(conf.values)) {
|
|
166
|
+
const w = graph.nodes.get(workspace.id);
|
|
167
|
+
if (w) {
|
|
168
|
+
importers.add(w);
|
|
169
|
+
scopeIDs.push(workspace.id);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
65
172
|
}
|
|
66
173
|
}
|
|
174
|
+
// retrieve the selected nodes and edges
|
|
175
|
+
const edges_ = graph?.edges ?? new Set();
|
|
176
|
+
const nodes_ = graph?.nodes ?
|
|
177
|
+
new Set(graph.nodes.values())
|
|
178
|
+
: new Set();
|
|
179
|
+
const importers_ = importers.size === 0 && graph ?
|
|
180
|
+
new Set([graph.mainImporter])
|
|
181
|
+
: importers;
|
|
182
|
+
const q = new Query({
|
|
183
|
+
edges: edges_,
|
|
184
|
+
nodes: nodes_,
|
|
185
|
+
importers: importers_,
|
|
186
|
+
securityArchive,
|
|
187
|
+
hostContexts,
|
|
188
|
+
});
|
|
189
|
+
const query = queryString ||
|
|
190
|
+
(graph ? defaultProjectQueryString : defaultLocalScopeQueryString);
|
|
191
|
+
const { edges, nodes, importers: queryResultImporters, } = await q.search(query, {
|
|
192
|
+
signal: new AbortController().signal,
|
|
193
|
+
scopeIDs: scopeIDs.length > 0 ? scopeIDs : undefined,
|
|
194
|
+
});
|
|
195
|
+
if (!validateExpectedResult(conf, edges)) {
|
|
196
|
+
throw error('Unexpected number of items', {
|
|
197
|
+
found: edges.length,
|
|
198
|
+
wanted: conf.values['expect-results'],
|
|
199
|
+
});
|
|
200
|
+
}
|
|
67
201
|
return {
|
|
68
|
-
importers
|
|
202
|
+
importers: importers.size === 0 ?
|
|
203
|
+
new Set(queryResultImporters)
|
|
204
|
+
: importers,
|
|
69
205
|
edges,
|
|
70
206
|
nodes,
|
|
71
|
-
highlightSelection: !!
|
|
72
|
-
queryString: queryString ||
|
|
207
|
+
highlightSelection: !!(targetQueryString || positionalQueryString),
|
|
208
|
+
queryString: queryString ||
|
|
209
|
+
(graph ?
|
|
210
|
+
defaultProjectQueryString
|
|
211
|
+
: defaultLocalScopeQueryString),
|
|
73
212
|
};
|
|
74
213
|
};
|
|
75
214
|
//# sourceMappingURL=query.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"query.js","sourceRoot":"","sources":["../../../src/commands/query.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EACN,mBAAmB,EACnB,UAAU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AACH,CAAC,CAAA","sourcesContent":["import {\n actual,\n humanReadableOutput,\n jsonOutput,\n mermaidOutput,\n} from '@vltpkg/graph'\nimport type {\n HumanReadableOutputGraph,\n JSONOutputGraph,\n MermaidOutputGraph,\n Node,\n} from '@vltpkg/graph'\nimport { Query } from '@vltpkg/query'\nimport { commandUsage } from '../config/usage.ts'\nimport type { CommandFn, CommandUsage } from '../index.ts'\nimport { startGUI } from '../start-gui.ts'\nimport type { Views } from '../view.ts'\n\nexport const usage: CommandUsage = () =>\n commandUsage({\n command: 'query',\n usage: ['', '<query> --view=[human | json | mermaid | gui]'],\n description:\n 'List installed dependencies matching the provided query.',\n examples: {\n [`'#foo'`]: {\n description: 'Query packages with the name \"foo\"',\n },\n [`'*.workspace > *.peer'`]: {\n description: 'Query all peer dependencies of workspaces',\n },\n [`':project > *:attr(scripts, [build])'`]: {\n description:\n 'Query all direct project dependencies with a \"build\" script',\n },\n [`'[name^=\"@vltpkg\"]'`]: {\n description:\n 'Query packages with names starting with \"@vltpkg\"',\n },\n },\n options: {\n view: {\n value: '[human | json | mermaid | gui]',\n description:\n 'Output format. Defaults to human-readable or json if no tty.',\n },\n },\n })\n\ntype QueryResult = JSONOutputGraph &\n MermaidOutputGraph &\n HumanReadableOutputGraph & { queryString: string }\n\nexport const views = {\n json: jsonOutput,\n mermaid: mermaidOutput,\n human: humanReadableOutput,\n gui: async ({ queryString }, _, conf) => {\n await startGUI({\n conf,\n startingRoute:\n '/explore?query=' + encodeURIComponent(queryString),\n })\n },\n} as const satisfies Views<QueryResult>\n\nexport const command: CommandFn<QueryResult> = async conf => {\n const monorepo = conf.options.monorepo\n const mainManifest = conf.options.packageJson.read(\n conf.options.projectRoot,\n )\n const graph = actual.load({\n ...conf.options,\n mainManifest,\n monorepo,\n loadManifests: true,\n })\n\n const defaultQueryString = '*'\n const queryString = conf.positionals[0]\n const query = new Query({ graph, specOptions: conf.options })\n const { edges, nodes } = await query.search(\n queryString || defaultQueryString,\n )\n\n const importers = new Set<Node>()\n if (monorepo) {\n for (const workspace of monorepo.filter(conf.values)) {\n const w: Node | undefined = graph.nodes.get(workspace.id)\n if (w) importers.add(w)\n }\n }\n if (importers.size === 0) {\n for (const importer of graph.importers) {\n importers.add(importer)\n }\n }\n\n return {\n importers,\n edges,\n nodes,\n highlightSelection: !!queryString,\n queryString: queryString || defaultQueryString,\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"query.js","sourceRoot":"","sources":["../../../src/commands/query.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EACN,MAAM,EACN,mBAAmB,EACnB,UAAU,EACV,aAAa,EACb,aAAa,GACd,MAAM,eAAe,CAAA;AACtB,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAC3C,OAAO,QAAQ,MAAM,WAAW,CAAA;AAChC,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAA;AACrC,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAA;AAC1D,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAA;AAC1C,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AACjD,OAAO,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAA;AAcjE,MAAM,CAAC,MAAM,KAAK,GAAiB,GAAG,EAAE,CACtC,YAAY,CAAC;IACX,OAAO,EAAE,OAAO;IAChB,KAAK,EAAE;QACL,EAAE;QACF,+CAA+C;QAC/C,8CAA8C;QAC9C,wDAAwD;KACzD;IACD,WAAW,EAAE;;;;;;;;;;;;;+EAa8D;IAE3E,QAAQ,EAAE;QACR,CAAC,QAAQ,CAAC,EAAE;YACV,WAAW,EAAE,sCAAsC;SACpD;QACD,CAAC,wBAAwB,CAAC,EAAE;YAC1B,WAAW,EAAE,2CAA2C;SACzD;QACD,CAAC,uCAAuC,CAAC,EAAE;YACzC,WAAW,EACT,6DAA6D;SAChE;QACD,CAAC,qBAAqB,CAAC,EAAE;YACvB,WAAW,EACT,mD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;gBAC3B,CAAC,CAAC,4BAA4B,CAAC;KAClC,CAAA;AACH,CAAC,CAAA","sourcesContent":["import {\n actual,\n asNode,\n humanReadableOutput,\n jsonOutput,\n mermaidOutput,\n GraphModifier,\n} from '@vltpkg/graph'\nimport { error } from '@vltpkg/error-cause'\nimport LZString from 'lz-string'\nimport { Query } from '@vltpkg/query'\nimport { SecurityArchive } from '@vltpkg/security-archive'\nimport { startGUI } from '../start-gui.ts'\nimport { commandUsage } from '../config/usage.ts'\nimport { createHostContextsMap } from '../query-host-contexts.ts'\nimport type {\n HumanReadableOutputGraph,\n JSONOutputGraph,\n MermaidOutputGraph,\n Node,\n Graph,\n} from '@vltpkg/graph'\nimport type { DepID } from '@vltpkg/dep-id'\nimport type { EdgeLike, NodeLike } from '@vltpkg/types'\nimport type { CommandFn, CommandUsage } from '../index.ts'\nimport type { Views } from '../view.ts'\nimport type { LoadedConfig } from '../config/index.ts'\n\nexport const usage: CommandUsage = () =>\n commandUsage({\n command: 'query',\n usage: [\n '',\n '<query> --view=<human | json | mermaid | gui>',\n '<query> --expect-results=<comparison string>',\n '--target=<query> --view=<human | json | mermaid | gui>',\n ],\n description: `List installed dependencies matching the provided query.\n\n The vlt Dependency Selector Syntax is a CSS-like query language that\n allows you to filter installed dependencies using a variety of metadata\n in the form of CSS-like attributes, pseudo selectors & combinators.\n\n The --scope and --target options accepts DSS query selectors to filter\n packages. Using --scope, you can specify which packages to treat as the\n top-level items in the output graph. The --target option can be used as\n an alternative to positional arguments, it allows you to filter what\n dependencies to include in the output. Using both options allows you to\n render subgraphs of the dependency graph.\n\n Defaults to listing all dependencies of the project root and workspaces.`,\n\n examples: {\n [`'#foo'`]: {\n description: 'Query dependencies declared as \"foo\"',\n },\n [`'*:workspace > *:peer'`]: {\n description: 'Query all peer dependencies of workspaces',\n },\n [`':project > *:attr(scripts, [build])'`]: {\n description:\n 'Query all direct project dependencies with a \"build\" script',\n },\n [`'[name^=\"@vltpkg\"]'`]: {\n description:\n 'Query packages with names starting with \"@vltpkg\"',\n },\n [`'*:license(copyleft) --expect-results=0'`]: {\n description: 'Errors if a copyleft licensed package is found',\n },\n '--scope=\":root > #dependency-name\"': {\n description:\n 'Defines a direct dependency as the output top-level scope',\n },\n [`'--target=\"*\"'`]: {\n description: 'Query all dependencies using the target option',\n },\n [`'--target=\":workspace > *:peer\"'`]: {\n description:\n 'Query all peer dependencies of workspaces using target option',\n },\n },\n options: {\n 'expect-results': {\n value: '[number | string]',\n description:\n 'Sets an expected number of resulting items. Errors if the number of resulting items does not match the set value. Accepts a specific numeric value or a string value starting with either \">\", \"<\", \">=\" or \"<=\" followed by a numeric value to be compared.',\n },\n scope: {\n value: '<query>',\n description:\n 'Query selector to select top-level packages using the DSS query language syntax.',\n },\n target: {\n value: '<query>',\n description:\n 'Query selector to filter packages using DSS syntax.',\n },\n view: {\n value: '[human | json | mermaid | gui]',\n description:\n 'Output format. Defaults to human-readable or json if no tty.',\n },\n },\n })\n\ntype QueryResult = JSONOutputGraph &\n MermaidOutputGraph &\n HumanReadableOutputGraph & { queryString: string }\n\nconst validateExpectedResult = (\n conf: LoadedConfig,\n edges: EdgeLike[],\n): boolean => {\n const expectResults = conf.values['expect-results']\n if (expectResults?.startsWith('>=')) {\n return edges.length >= parseInt(expectResults.slice(2).trim(), 10)\n } else if (expectResults?.startsWith('<=')) {\n return edges.length <= parseInt(expectResults.slice(2).trim(), 10)\n } else if (expectResults?.startsWith('>')) {\n return edges.length > parseInt(expectResults.slice(1).trim(), 10)\n } else if (expectResults?.startsWith('<')) {\n return edges.length < parseInt(expectResults.slice(1).trim(), 10)\n } else if (expectResults) {\n return edges.length === parseInt(expectResults.trim(), 10)\n }\n return true\n}\n\nexport const views = {\n json: jsonOutput,\n mermaid: mermaidOutput,\n human: humanReadableOutput,\n gui: async ({ queryString }, _, conf) => {\n await startGUI(\n conf,\n `/explore/${LZString.compressToEncodedURIComponent(queryString)}/overview`,\n )\n },\n} as const satisfies Views<QueryResult>\n\nexport const command: CommandFn<QueryResult> = async conf => {\n const modifiers = GraphModifier.maybeLoad(conf.options)\n const monorepo = conf.options.monorepo\n const mainManifest = conf.options.packageJson.maybeRead(\n conf.options.projectRoot,\n )\n let graph: Graph | undefined\n let securityArchive: SecurityArchive | undefined\n\n // optionally load the cwd graph if we found a package.json file\n if (mainManifest) {\n graph = actual.load({\n ...conf.options,\n mainManifest,\n modifiers,\n monorepo,\n loadManifests: true,\n })\n securityArchive = await SecurityArchive.start({\n nodes: [...graph.nodes.values()],\n })\n }\n\n // retrieve default values and set up host contexts\n const defaultProjectQueryString = '*'\n const defaultLocalScopeQueryString = ':host(local) *'\n const positionalQueryString = conf.positionals[0]\n const targetQueryString = conf.get('target')\n const scopeQueryString = conf.get('scope')\n const queryString = targetQueryString || positionalQueryString\n const hostContexts = await createHostContextsMap(conf)\n const importers = new Set<Node>()\n const scopeIDs: DepID[] = []\n\n // Handle --scope option to add scope nodes as importers\n let scopeNodes\n if (scopeQueryString) {\n // Run scope query to get all matching nodes\n /* c8 ignore start */\n const edges = graph?.edges ?? new Set()\n const nodes =\n graph?.nodes ?\n new Set<NodeLike>(graph.nodes.values())\n : new Set<NodeLike>()\n const importers = graph?.importers ?? new Set()\n /* c8 ignore stop */\n const scopeQuery = new Query({\n edges,\n nodes,\n importers,\n securityArchive,\n hostContexts,\n })\n const { nodes: resultNodes } = await scopeQuery.search(\n scopeQueryString,\n {\n signal: new AbortController().signal,\n },\n )\n scopeNodes = resultNodes\n }\n\n if (scopeQueryString && scopeNodes) {\n // Add all scope nodes to importers Set (treat them as top-level items)\n for (const queryNode of scopeNodes) {\n importers.add(asNode(queryNode))\n }\n } else if ('workspace' in conf.values) {\n // if in a workspace environment, select only the specified\n // workspaces as top-level items\n if (monorepo && graph) {\n for (const workspace of monorepo.filter(conf.values)) {\n const w: Node | undefined = graph.nodes.get(workspace.id)\n if (w) {\n importers.add(w)\n scopeIDs.push(workspace.id)\n }\n }\n }\n }\n\n // retrieve the selected nodes and edges\n const edges_ = graph?.edges ?? new Set()\n const nodes_ =\n graph?.nodes ?\n new Set<NodeLike>(graph.nodes.values())\n : new Set<NodeLike>()\n const importers_ =\n importers.size === 0 && graph ?\n new Set([graph.mainImporter])\n : importers\n const q = new Query({\n edges: edges_,\n nodes: nodes_,\n importers: importers_,\n securityArchive,\n hostContexts,\n })\n const query =\n queryString ||\n (graph ? defaultProjectQueryString : defaultLocalScopeQueryString)\n const {\n edges,\n nodes,\n importers: queryResultImporters,\n } = await q.search(query, {\n signal: new AbortController().signal,\n scopeIDs: scopeIDs.length > 0 ? scopeIDs : undefined,\n })\n\n if (!validateExpectedResult(conf, edges)) {\n throw error('Unexpected number of items', {\n found: edges.length,\n wanted: conf.values['expect-results'],\n })\n }\n\n return {\n importers:\n importers.size === 0 ?\n new Set(queryResultImporters)\n : importers,\n edges,\n nodes,\n highlightSelection: !!(\n targetQueryString || positionalQueryString\n ),\n queryString:\n queryString ||\n (graph ?\n defaultProjectQueryString\n : defaultLocalScopeQueryString),\n }\n}\n"]}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ExecResult } from '../exec-command.ts';
|
|
2
2
|
import type { CommandFn, CommandUsage } from '../index.ts';
|
|
3
|
+
export { views } from '../exec-command.ts';
|
|
3
4
|
export declare const usage: CommandUsage;
|
|
4
5
|
export declare const command: CommandFn<ExecResult>;
|
|
5
6
|
//# sourceMappingURL=run-exec.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run-exec.d.ts","sourceRoot":"","sources":["../../../src/commands/run-exec.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"run-exec.d.ts","sourceRoot":"","sources":["../../../src/commands/run-exec.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AAEpD,OAAO,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAC1D,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAA;AAE1C,eAAO,MAAM,KAAK,EAAE,YAQhB,CAAA;AAEJ,eAAO,MAAM,OAAO,EAAE,SAAS,CAAC,UAAU,CACa,CAAA"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { runExec, runExecFG } from '@vltpkg/run';
|
|
2
2
|
import { commandUsage } from "../config/usage.js";
|
|
3
3
|
import { ExecCommand } from "../exec-command.js";
|
|
4
|
+
export { views } from "../exec-command.js";
|
|
4
5
|
export const usage = () => commandUsage({
|
|
5
6
|
command: 'run-exec',
|
|
6
7
|
usage: '[command ...]',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run-exec.js","sourceRoot":"","sources":["../../../src/commands/run-exec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;
|
|
1
|
+
{"version":3,"file":"run-exec.js","sourceRoot":"","sources":["../../../src/commands/run-exec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAEjD,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAEhD,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAA;AAE1C,MAAM,CAAC,MAAM,KAAK,GAAiB,GAAG,EAAE,CACtC,YAAY,CAAC;IACX,OAAO,EAAE,UAAU;IACnB,KAAK,EAAE,eAAe;IACtB,WAAW,EAAE;;;mEAGkD;CAChE,CAAC,CAAA;AAEJ,MAAM,CAAC,MAAM,OAAO,GAA0B,KAAK,EAAC,IAAI,EAAC,EAAE,CACzD,MAAM,IAAI,WAAW,CAAC,IAAI,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC,GAAG,EAAE,CAAA","sourcesContent":["import { runExec, runExecFG } from '@vltpkg/run'\nimport { commandUsage } from '../config/usage.ts'\nimport type { ExecResult } from '../exec-command.ts'\nimport { ExecCommand } from '../exec-command.ts'\nimport type { CommandFn, CommandUsage } from '../index.ts'\nexport { views } from '../exec-command.ts'\n\nexport const usage: CommandUsage = () =>\n commandUsage({\n command: 'run-exec',\n usage: '[command ...]',\n description: `If the first argument is a defined script in package.json, then this is\n equivalent to \\`vlt run\\`.\n\n If not, then this is equivalent to \\`vlt exec\\`.`,\n })\n\nexport const command: CommandFn<ExecResult> = async conf =>\n await new ExecCommand(conf, runExec, runExecFG).run()\n"]}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ExecResult } from '../exec-command.ts';
|
|
2
2
|
import type { CommandFn, CommandUsage } from '../index.ts';
|
|
3
|
+
export { views } from '../exec-command.ts';
|
|
3
4
|
export declare const usage: CommandUsage;
|
|
4
5
|
export declare const command: CommandFn<ExecResult>;
|
|
5
6
|
//# sourceMappingURL=run.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../../../src/commands/run.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../../../src/commands/run.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,UAAU,EAGX,MAAM,oBAAoB,CAAA;AAE3B,OAAO,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAE1D,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAA;AAE1C,eAAO,MAAM,KAAK,EAAE,YAQhB,CAAA;AA2BJ,eAAO,MAAM,OAAO,EAAE,SAAS,CAAC,UAAU,CACR,CAAA"}
|