@vltpkg/cli-sdk 0.0.0-9 → 1.0.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/commands/build.d.ts +25 -0
- package/dist/esm/commands/build.d.ts.map +1 -0
- package/dist/esm/commands/build.js +102 -0
- package/dist/esm/commands/build.js.map +1 -0
- package/dist/esm/commands/cache.d.ts +18 -0
- package/dist/esm/commands/cache.d.ts.map +1 -1
- package/dist/esm/commands/cache.js +48 -2
- package/dist/esm/commands/cache.js.map +1 -1
- package/dist/esm/commands/ci.d.ts +11 -0
- package/dist/esm/commands/ci.d.ts.map +1 -0
- package/dist/esm/commands/ci.js +32 -0
- package/dist/esm/commands/ci.js.map +1 -0
- package/dist/esm/commands/config.d.ts +3 -2
- package/dist/esm/commands/config.d.ts.map +1 -1
- package/dist/esm/commands/config.js +372 -101
- package/dist/esm/commands/config.js.map +1 -1
- package/dist/esm/commands/docs.d.ts +18 -0
- package/dist/esm/commands/docs.d.ts.map +1 -0
- package/dist/esm/commands/docs.js +154 -0
- package/dist/esm/commands/docs.js.map +1 -0
- package/dist/esm/commands/exec-cache.d.ts +49 -0
- package/dist/esm/commands/exec-cache.d.ts.map +1 -0
- package/dist/esm/commands/exec-cache.js +146 -0
- package/dist/esm/commands/exec-cache.js.map +1 -0
- package/dist/esm/commands/exec-local.d.ts +1 -0
- package/dist/esm/commands/exec-local.d.ts.map +1 -1
- package/dist/esm/commands/exec-local.js +2 -0
- package/dist/esm/commands/exec-local.js.map +1 -1
- package/dist/esm/commands/exec.d.ts +6 -1
- package/dist/esm/commands/exec.d.ts.map +1 -1
- package/dist/esm/commands/exec.js +79 -5
- package/dist/esm/commands/exec.js.map +1 -1
- package/dist/esm/commands/help.d.ts +1 -1
- package/dist/esm/commands/help.d.ts.map +1 -1
- package/dist/esm/commands/help.js +32 -3
- package/dist/esm/commands/help.js.map +1 -1
- package/dist/esm/commands/init.d.ts +3 -3
- package/dist/esm/commands/init.d.ts.map +1 -1
- package/dist/esm/commands/init.js +95 -9
- package/dist/esm/commands/init.js.map +1 -1
- package/dist/esm/commands/install/reporter.d.ts +3 -2
- package/dist/esm/commands/install/reporter.d.ts.map +1 -1
- package/dist/esm/commands/install/reporter.js +42 -15
- package/dist/esm/commands/install/reporter.js.map +1 -1
- package/dist/esm/commands/install.d.ts +21 -3
- package/dist/esm/commands/install.d.ts.map +1 -1
- package/dist/esm/commands/install.js +27 -3
- package/dist/esm/commands/install.js.map +1 -1
- package/dist/esm/commands/list.d.ts +2 -2
- package/dist/esm/commands/list.d.ts.map +1 -1
- package/dist/esm/commands/list.js +149 -49
- package/dist/esm/commands/list.js.map +1 -1
- package/dist/esm/commands/pack.d.ts +32 -0
- package/dist/esm/commands/pack.d.ts.map +1 -0
- package/dist/esm/commands/pack.js +147 -0
- package/dist/esm/commands/pack.js.map +1 -0
- package/dist/esm/commands/pkg.d.ts +1 -2
- package/dist/esm/commands/pkg.d.ts.map +1 -1
- package/dist/esm/commands/pkg.js +123 -38
- package/dist/esm/commands/pkg.js.map +1 -1
- package/dist/esm/commands/publish.d.ts +22 -0
- package/dist/esm/commands/publish.d.ts.map +1 -0
- package/dist/esm/commands/publish.js +245 -0
- package/dist/esm/commands/publish.js.map +1 -0
- package/dist/esm/commands/query.d.ts +2 -3
- package/dist/esm/commands/query.d.ts.map +1 -1
- package/dist/esm/commands/query.js +132 -38
- package/dist/esm/commands/query.js.map +1 -1
- package/dist/esm/commands/run-exec.d.ts +1 -0
- package/dist/esm/commands/run-exec.d.ts.map +1 -1
- package/dist/esm/commands/run-exec.js +1 -0
- package/dist/esm/commands/run-exec.js.map +1 -1
- package/dist/esm/commands/run.d.ts +1 -0
- package/dist/esm/commands/run.d.ts.map +1 -1
- package/dist/esm/commands/run.js +13 -16
- package/dist/esm/commands/run.js.map +1 -1
- package/dist/esm/commands/serve.d.ts +14 -0
- package/dist/esm/commands/serve.d.ts.map +1 -0
- package/dist/esm/commands/serve.js +103 -0
- package/dist/esm/commands/serve.js.map +1 -0
- package/dist/esm/commands/uninstall.d.ts +8 -2
- package/dist/esm/commands/uninstall.d.ts.map +1 -1
- package/dist/esm/commands/uninstall.js +8 -3
- package/dist/esm/commands/uninstall.js.map +1 -1
- package/dist/esm/commands/update.d.ts +14 -0
- package/dist/esm/commands/update.d.ts.map +1 -0
- package/dist/esm/commands/update.js +41 -0
- package/dist/esm/commands/update.js.map +1 -0
- package/dist/esm/commands/version.d.ts +26 -0
- package/dist/esm/commands/version.d.ts.map +1 -0
- package/dist/esm/commands/version.js +226 -0
- package/dist/esm/commands/version.js.map +1 -0
- package/dist/esm/config/definition.d.ts +118 -15
- package/dist/esm/config/definition.d.ts.map +1 -1
- package/dist/esm/config/definition.js +185 -37
- package/dist/esm/config/definition.js.map +1 -1
- package/dist/esm/config/index.d.ts +41 -37
- package/dist/esm/config/index.d.ts.map +1 -1
- package/dist/esm/config/index.js +109 -172
- package/dist/esm/config/index.js.map +1 -1
- package/dist/esm/config/merge.d.ts +3 -1
- package/dist/esm/config/merge.d.ts.map +1 -1
- package/dist/esm/config/merge.js +11 -6
- package/dist/esm/config/merge.js.map +1 -1
- package/dist/esm/custom-help.d.ts +9 -0
- package/dist/esm/custom-help.d.ts.map +1 -0
- package/dist/esm/custom-help.js +400 -0
- package/dist/esm/custom-help.js.map +1 -0
- package/dist/esm/exec-command.d.ts +33 -14
- package/dist/esm/exec-command.d.ts.map +1 -1
- package/dist/esm/exec-command.js +213 -64
- package/dist/esm/exec-command.js.map +1 -1
- package/dist/esm/index.d.ts +1 -14
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +45 -19
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/load-command.d.ts +16 -0
- package/dist/esm/load-command.d.ts.map +1 -0
- package/dist/esm/load-command.js +21 -0
- package/dist/esm/load-command.js.map +1 -0
- package/dist/esm/output.d.ts +6 -11
- package/dist/esm/output.d.ts.map +1 -1
- package/dist/esm/output.js +64 -27
- package/dist/esm/output.js.map +1 -1
- package/dist/esm/pack-tarball.d.ts +22 -0
- package/dist/esm/pack-tarball.d.ts.map +1 -0
- package/dist/esm/pack-tarball.js +249 -0
- package/dist/esm/pack-tarball.js.map +1 -0
- package/dist/esm/print-err.d.ts +9 -2
- package/dist/esm/print-err.d.ts.map +1 -1
- package/dist/esm/print-err.js +130 -46
- package/dist/esm/print-err.js.map +1 -1
- package/dist/esm/query-host-contexts.d.ts +16 -0
- package/dist/esm/query-host-contexts.d.ts.map +1 -0
- package/dist/esm/query-host-contexts.js +135 -0
- package/dist/esm/query-host-contexts.js.map +1 -0
- package/dist/esm/start-gui.d.ts +1 -0
- package/dist/esm/start-gui.d.ts.map +1 -1
- package/dist/esm/start-gui.js +25 -6
- package/dist/esm/start-gui.js.map +1 -1
- package/dist/esm/view.d.ts +2 -3
- package/dist/esm/view.d.ts.map +1 -1
- package/dist/esm/view.js +1 -1
- package/dist/esm/view.js.map +1 -1
- package/package.json +51 -37
- package/dist/esm/commands/gui.d.ts +0 -6
- package/dist/esm/commands/gui.d.ts.map +0 -1
- package/dist/esm/commands/gui.js +0 -13
- package/dist/esm/commands/gui.js.map +0 -1
|
@@ -1,32 +1,57 @@
|
|
|
1
|
-
import { actual, humanReadableOutput, jsonOutput, mermaidOutput, } from '@vltpkg/graph';
|
|
1
|
+
import { actual, asNode, humanReadableOutput, jsonOutput, mermaidOutput, GraphModifier, } from '@vltpkg/graph';
|
|
2
|
+
import LZString from 'lz-string';
|
|
2
3
|
import { Query } from '@vltpkg/query';
|
|
3
4
|
import { SecurityArchive } from '@vltpkg/security-archive';
|
|
5
|
+
import { error } from '@vltpkg/error-cause';
|
|
4
6
|
import { commandUsage } from "../config/usage.js";
|
|
5
7
|
import { startGUI } from "../start-gui.js";
|
|
8
|
+
import { createHostContextsMap } from "../query-host-contexts.js";
|
|
6
9
|
export const usage = () => commandUsage({
|
|
7
10
|
command: 'ls',
|
|
8
|
-
usage: [
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
11
|
+
usage: [
|
|
12
|
+
'',
|
|
13
|
+
'[package-names...] [--view=human | json | mermaid | gui]',
|
|
14
|
+
'[--scope=<query>] [--target=<query>] [--view=human | json | mermaid | gui]',
|
|
15
|
+
],
|
|
16
|
+
description: `List installed dependencies matching given package names or query selectors.
|
|
17
|
+
|
|
18
|
+
Package names provided as positional arguments will be used to filter
|
|
19
|
+
the results to show only dependencies with those names.
|
|
20
|
+
|
|
21
|
+
The --scope and --target options accepts DSS query selectors to filter
|
|
22
|
+
packages. Using --scope, you can specify which packages to treat as the
|
|
23
|
+
top-level items in the output graph. The --target option allows you to
|
|
24
|
+
filter what dependencies to include in the output. Using both options
|
|
25
|
+
allows you to render subgraphs of the dependency graph.
|
|
26
|
+
|
|
27
|
+
Defaults to listing direct dependencies of a project and any configured
|
|
28
|
+
workspace.`,
|
|
12
29
|
examples: {
|
|
13
30
|
'': {
|
|
14
31
|
description: 'List direct dependencies of the current project / workspace',
|
|
15
32
|
},
|
|
16
|
-
'"*"': {
|
|
17
|
-
description: 'List all dependencies for the current project / workspace',
|
|
18
|
-
},
|
|
19
33
|
'foo bar baz': {
|
|
20
34
|
description: `List all dependencies named 'foo', 'bar', or 'baz'`,
|
|
21
35
|
},
|
|
22
|
-
|
|
23
|
-
description: '
|
|
36
|
+
'--scope=":root > #dependency-name"': {
|
|
37
|
+
description: 'Defines a direct dependency as the output top-level scope',
|
|
38
|
+
},
|
|
39
|
+
'--target="*"': {
|
|
40
|
+
description: 'List all dependencies using a query selector',
|
|
24
41
|
},
|
|
25
|
-
|
|
42
|
+
'--target=":workspace > *:peer"': {
|
|
26
43
|
description: 'List all peer dependencies of all workspaces',
|
|
27
44
|
},
|
|
28
45
|
},
|
|
29
46
|
options: {
|
|
47
|
+
scope: {
|
|
48
|
+
value: '<query>',
|
|
49
|
+
description: 'Query selector to select top-level packages using the DSS query language syntax.',
|
|
50
|
+
},
|
|
51
|
+
target: {
|
|
52
|
+
value: '<query>',
|
|
53
|
+
description: 'Query selector to filter packages using the DSS query language syntax.',
|
|
54
|
+
},
|
|
30
55
|
view: {
|
|
31
56
|
value: '[human | json | mermaid | gui]',
|
|
32
57
|
description: 'Output format. Defaults to human-readable or json if no tty.',
|
|
@@ -38,62 +63,137 @@ export const views = {
|
|
|
38
63
|
mermaid: mermaidOutput,
|
|
39
64
|
human: humanReadableOutput,
|
|
40
65
|
gui: async ({ queryString }, _, conf) => {
|
|
41
|
-
await startGUI(conf,
|
|
66
|
+
await startGUI(conf, `/explore/${LZString.compressToEncodedURIComponent(queryString)}/overview`);
|
|
42
67
|
},
|
|
43
68
|
};
|
|
44
69
|
export const command = async (conf) => {
|
|
70
|
+
const modifiers = GraphModifier.maybeLoad(conf.options);
|
|
45
71
|
const monorepo = conf.options.monorepo;
|
|
46
|
-
const mainManifest = conf.options.packageJson.
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
72
|
+
const mainManifest = conf.options.packageJson.maybeRead(conf.options.projectRoot);
|
|
73
|
+
let graph;
|
|
74
|
+
let securityArchive;
|
|
75
|
+
// optionally load the cwd graph if we found a package.json file
|
|
76
|
+
if (mainManifest) {
|
|
77
|
+
graph = actual.load({
|
|
78
|
+
...conf.options,
|
|
79
|
+
mainManifest,
|
|
80
|
+
modifiers,
|
|
81
|
+
monorepo,
|
|
82
|
+
loadManifests: true,
|
|
83
|
+
});
|
|
84
|
+
securityArchive = await SecurityArchive.start({
|
|
85
|
+
nodes: [...graph.nodes.values()],
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
// Validate positional arguments - only allow package names, not direct queries
|
|
89
|
+
for (const arg of conf.positionals) {
|
|
90
|
+
if (!/^[@\w-]/.test(arg)) {
|
|
91
|
+
throw error(`Direct queries are not supported as positional arguments. Use package names only.`, {
|
|
92
|
+
code: 'EUSAGE',
|
|
93
|
+
cause: `Argument '${arg}' appears to be a query syntax. Only package names are allowed as positional arguments.`,
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
// retrieve default values and set up host contexts
|
|
98
|
+
const positionalQueryString = conf.positionals
|
|
99
|
+
.map(k => `#${k.replace(/\//, '\\/')}`)
|
|
55
100
|
.join(', ');
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
})
|
|
61
|
-
: undefined;
|
|
62
|
-
const query = new Query({
|
|
63
|
-
graph,
|
|
64
|
-
specOptions: conf.options,
|
|
65
|
-
securityArchive,
|
|
66
|
-
});
|
|
67
|
-
const projectQueryString = ':project, :project > *';
|
|
101
|
+
const targetQueryString = conf.get('target');
|
|
102
|
+
const scopeQueryString = conf.get('scope');
|
|
103
|
+
const queryString = targetQueryString || positionalQueryString;
|
|
104
|
+
const projectQueryString = ':workspace, :project > *';
|
|
68
105
|
const selectImporters = [];
|
|
106
|
+
const hostContexts = await createHostContextsMap(conf);
|
|
69
107
|
const importers = new Set();
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
108
|
+
const scopeIDs = [];
|
|
109
|
+
// handle --scope option to add scope nodes as importers
|
|
110
|
+
let scopeNodes;
|
|
111
|
+
if (scopeQueryString) {
|
|
112
|
+
// run scope query to get all matching nodes
|
|
113
|
+
/* c8 ignore start */
|
|
114
|
+
const edges = graph?.edges ?? new Set();
|
|
115
|
+
const nodes = graph?.nodes ?
|
|
116
|
+
new Set(graph.nodes.values())
|
|
117
|
+
: new Set();
|
|
118
|
+
const importers = graph?.importers ?? new Set();
|
|
119
|
+
/* c8 ignore stop */
|
|
120
|
+
const scopeQuery = new Query({
|
|
121
|
+
nodes,
|
|
122
|
+
edges,
|
|
123
|
+
importers,
|
|
124
|
+
securityArchive,
|
|
125
|
+
hostContexts,
|
|
126
|
+
});
|
|
127
|
+
const { nodes: resultNodes } = await scopeQuery.search(scopeQueryString, {
|
|
128
|
+
signal: new AbortController().signal,
|
|
129
|
+
});
|
|
130
|
+
scopeNodes = resultNodes;
|
|
131
|
+
}
|
|
132
|
+
if (scopeQueryString && scopeNodes) {
|
|
133
|
+
// Add all scope nodes to importers Set (treat them as top-level items)
|
|
134
|
+
for (const queryNode of scopeNodes) {
|
|
135
|
+
importers.add(asNode(queryNode));
|
|
78
136
|
}
|
|
79
137
|
}
|
|
80
|
-
if (
|
|
81
|
-
|
|
82
|
-
|
|
138
|
+
else if ('workspace' in conf.values) {
|
|
139
|
+
// if in a workspace environment, select only the specified
|
|
140
|
+
// workspaces as top-level items
|
|
141
|
+
if (monorepo && graph) {
|
|
142
|
+
for (const workspace of monorepo.filter(conf.values)) {
|
|
143
|
+
const w = graph.nodes.get(workspace.id);
|
|
144
|
+
if (w) {
|
|
145
|
+
importers.add(w);
|
|
146
|
+
selectImporters.push(`[name="${w.name}"]`);
|
|
147
|
+
selectImporters.push(`[name="${w.name}"] > *`);
|
|
148
|
+
scopeIDs.push(workspace.id);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
83
151
|
}
|
|
84
152
|
}
|
|
153
|
+
// build a default query string to use in the target search
|
|
85
154
|
const selectImportersQueryString = selectImporters.join(', ');
|
|
86
|
-
const
|
|
155
|
+
const defaultProjectQueryString = (graph &&
|
|
156
|
+
selectImporters.length &&
|
|
87
157
|
selectImporters.length < graph.importers.size) ?
|
|
88
158
|
selectImportersQueryString
|
|
89
159
|
: projectQueryString;
|
|
90
|
-
const
|
|
160
|
+
const defaultLocalScopeQueryString = ':host(local) :root > *';
|
|
161
|
+
// retrieve the selected nodes and edges
|
|
162
|
+
/* c8 ignore start */
|
|
163
|
+
const edges_ = graph?.edges ?? new Set();
|
|
164
|
+
const nodes_ = graph?.nodes ?
|
|
165
|
+
new Set(graph.nodes.values())
|
|
166
|
+
: new Set();
|
|
167
|
+
const importers_ = importers.size === 0 && graph ?
|
|
168
|
+
new Set([graph.mainImporter])
|
|
169
|
+
: importers;
|
|
170
|
+
/* c8 ignore stop */
|
|
171
|
+
const q = new Query({
|
|
172
|
+
nodes: nodes_,
|
|
173
|
+
edges: edges_,
|
|
174
|
+
importers: importers_,
|
|
175
|
+
securityArchive,
|
|
176
|
+
hostContexts,
|
|
177
|
+
});
|
|
178
|
+
const query = queryString ||
|
|
179
|
+
/* c8 ignore next */
|
|
180
|
+
(graph ? defaultProjectQueryString : defaultLocalScopeQueryString);
|
|
181
|
+
const { edges, nodes, importers: queryResultImporters, } = await q.search(query, {
|
|
182
|
+
signal: new AbortController().signal,
|
|
183
|
+
scopeIDs: scopeIDs.length > 0 ? scopeIDs : undefined,
|
|
184
|
+
});
|
|
91
185
|
return {
|
|
92
|
-
importers
|
|
186
|
+
importers: importers.size === 0 ?
|
|
187
|
+
new Set(queryResultImporters)
|
|
188
|
+
: importers,
|
|
93
189
|
edges,
|
|
94
190
|
nodes,
|
|
95
|
-
|
|
96
|
-
|
|
191
|
+
highlightSelection: !!(targetQueryString || positionalQueryString),
|
|
192
|
+
queryString: queryString ||
|
|
193
|
+
(graph ?
|
|
194
|
+
/* c8 ignore next 2 */
|
|
195
|
+
defaultProjectQueryString
|
|
196
|
+
: defaultLocalScopeQueryString),
|
|
97
197
|
};
|
|
98
198
|
};
|
|
99
199
|
//# sourceMappingURL=list.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"list.js","sourceRoot":"","sources":["../../../src/commands/list.ts"],"names":[],"mappings":"AAMA,OAAO,EACL,MAAM,EACN,mBAAmB,EACnB,UAAU,EACV,aAAa,GACd,MAAM,eAAe,CAAA;AACtB,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAA;AACrC,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAA;AAC1D,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAEjD,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAA;AAG1C,MAAM,CAAC,MAAM,KAAK,GAA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I,KAAK,CAAC,EAAE,CAAC;QACzB,KAAK,MAAM,QAAQ,IAAI,KAAK,CAAC,SAAS,EAAE,CAAC;YACvC,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;QACzB,CAAC;IACH,CAAC;IAED,MAAM,0BAA0B,GAAG,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IAC7D,MAAM,kBAAkB,GACtB,CACE,eAAe,CAAC,MAAM;QACtB,eAAe,CAAC,MAAM,GAAG,KAAK,CAAC,SAAS,CAAC,IAAI,CAC9C,CAAC,CAAC;QACD,0BAA0B;QAC5B,CAAC,CAAC,kBAAkB,CAAA;IAEtB,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,MAAM,KAAK,CAAC,MAAM,CACzC,WAAW,IAAI,kBAAkB,CAClC,CAAA;IAED,OAAO;QACL,SAAS;QACT,KAAK;QACL,KAAK;QACL,WAAW,EAAE,WAAW,IAAI,kBAAkB;QAC9C,kBAAkB,EAAE,CAAC,CAAC,WAAW;KAClC,CAAA;AACH,CAAC,CAAA","sourcesContent":["import type {\n HumanReadableOutputGraph,\n JSONOutputGraph,\n MermaidOutputGraph,\n Node,\n} from '@vltpkg/graph'\nimport {\n actual,\n humanReadableOutput,\n jsonOutput,\n mermaidOutput,\n} from '@vltpkg/graph'\nimport { Query } from '@vltpkg/query'\nimport { SecurityArchive } from '@vltpkg/security-archive'\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: 'ls',\n usage: ['', '<query> --view=[human | json | mermaid | gui]'],\n description: `List installed dependencies matching the provided query.\n Defaults to listing direct dependencies of a project and\n any configured workspace.`,\n examples: {\n '': {\n description:\n 'List direct dependencies of the current project / workspace',\n },\n '\"*\"': {\n description:\n 'List all dependencies for the current project / workspace',\n },\n 'foo bar baz': {\n description: `List all dependencies named 'foo', 'bar', or 'baz'`,\n },\n [`'[name=\"@scoped/package\"] > *'`]: {\n description:\n 'Lists direct dependencies of a specific package',\n },\n [`'*.workspace > *.peer'`]: {\n description: 'List all peer dependencies of all workspaces',\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\nexport type ListResult = 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 '/explore?query=' + encodeURIComponent(queryString),\n )\n },\n} as const satisfies Views<ListResult>\n\nexport const command: CommandFn<ListResult> = 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 queryString = conf.positionals\n .map(k => (/^[@\\w-]/.test(k) ? `#${k.replace(/\\//, '\\\\/')}` : k))\n .join(', ')\n const securityArchive =\n Query.hasSecuritySelectors(queryString) ?\n await SecurityArchive.start({\n graph,\n specOptions: conf.options,\n })\n : undefined\n const query = new Query({\n graph,\n specOptions: conf.options,\n securityArchive,\n })\n const projectQueryString = ':project, :project > *'\n const selectImporters: string[] = []\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) {\n importers.add(w)\n selectImporters.push(`[name=\"${w.name}\"]`)\n selectImporters.push(`[name=\"${w.name}\"] > *`)\n }\n }\n }\n if (importers.size === 0) {\n for (const importer of graph.importers) {\n importers.add(importer)\n }\n }\n\n const selectImportersQueryString = selectImporters.join(', ')\n const defaultQueryString =\n (\n selectImporters.length &&\n selectImporters.length < graph.importers.size\n ) ?\n selectImportersQueryString\n : projectQueryString\n\n const { edges, nodes } = await query.search(\n queryString || defaultQueryString,\n )\n\n return {\n importers,\n edges,\n nodes,\n queryString: queryString || defaultQueryString,\n highlightSelection: !!queryString,\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"list.js","sourceRoot":"","sources":["../../../src/commands/list.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EACN,MAAM,EACN,mBAAmB,EACnB,UAAU,EACV,aAAa,EACb,aAAa,GACd,MAAM,eAAe,CAAA;AACtB,OAAO,QAAQ,MAAM,WAAW,CAAA;AAChC,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAA;AACrC,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAA;AAC1D,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AACjD,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAA;AAC1C,OAAO,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAA;AAajE,MAAM,CAAC,MAAM,KAAK,GAAiB,GAAG,EAAE,CACtC,YAAY,CAAC;IACX,OAAO,EAAE,IAAI;IACb,KAAK,EAAE;QACL,EAAE;QACF,0DAA0D;QAC1D,4EAA4E;KAC7E;IACD,WAAW,EAAE;;;;;;;;;;;;iBAYA;IACb,QAAQ,EAAE;QACR,EAAE,EAAE;YACF,WAAW,EACT,6DAA6D;SAChE;QACD,aAAa,EAAE;YACb,WAAW,EAAE,oDAAoD;SAClE;QACD,oCAAoC,EAAE;YACpC,WAAW,EACT,2DAA2D;SAC9D;QACD,cAAc,EAAE;YACd,WAAW,EAAE,8CAA8C;SAC5D;QACD,gCAAgC,EAAE;YAChC,WAAW,EAAE,8CAA8C;SAC5D;KACF;IACD,OAAO,EAAE;QACP,KAAK,EAAE;YACL,KAAK,EAAE,SAAS;YAChB,WAAW,EACT,kFAAkF;SACrF;QACD,MAAM,EAAE;YACN,KAAK,EAAE,SAAS;YAChB,WAA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,CAAC,SAAS;KACrD,CAAC,CAAA;IAEF,OAAO;QACL,SAAS,EACP,SAAS,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC;YACpB,IAAI,GAAG,CAAC,oBAAoB,CAAC;YAC/B,CAAC,CAAC,SAAS;QACb,KAAK;QACL,KAAK;QACL,kBAAkB,EAAE,CAAC,CAAC,CACpB,iBAAiB,IAAI,qBAAqB,CAC3C;QACD,WAAW,EACT,WAAW;YACX,CAAC,KAAK,CAAC,CAAC;gBACN,sBAAsB;gBACtB,yBAAyB;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 LZString from 'lz-string'\nimport { Query } from '@vltpkg/query'\nimport { SecurityArchive } from '@vltpkg/security-archive'\nimport { error } from '@vltpkg/error-cause'\nimport { commandUsage } from '../config/usage.ts'\nimport { startGUI } from '../start-gui.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 { NodeLike } from '@vltpkg/types'\nimport type { CommandFn, CommandUsage } from '../index.ts'\nimport type { Views } from '../view.ts'\n\nexport const usage: CommandUsage = () =>\n commandUsage({\n command: 'ls',\n usage: [\n '',\n '[package-names...] [--view=human | json | mermaid | gui]',\n '[--scope=<query>] [--target=<query>] [--view=human | json | mermaid | gui]',\n ],\n description: `List installed dependencies matching given package names or query selectors.\n\n Package names provided as positional arguments will be used to filter\n the results to show only dependencies with those names.\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 allows you to\n filter what dependencies to include in the output. Using both options\n allows you to render subgraphs of the dependency graph.\n\n Defaults to listing direct dependencies of a project and any configured\n workspace.`,\n examples: {\n '': {\n description:\n 'List direct dependencies of the current project / workspace',\n },\n 'foo bar baz': {\n description: `List all dependencies named 'foo', 'bar', or 'baz'`,\n },\n '--scope=\":root > #dependency-name\"': {\n description:\n 'Defines a direct dependency as the output top-level scope',\n },\n '--target=\"*\"': {\n description: 'List all dependencies using a query selector',\n },\n '--target=\":workspace > *:peer\"': {\n description: 'List all peer dependencies of all workspaces',\n },\n },\n options: {\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 the DSS query language 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\nexport type ListResult = 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 `/explore/${LZString.compressToEncodedURIComponent(queryString)}/overview`,\n )\n },\n} as const satisfies Views<ListResult>\n\nexport const command: CommandFn<ListResult> = 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 // Validate positional arguments - only allow package names, not direct queries\n for (const arg of conf.positionals) {\n if (!/^[@\\w-]/.test(arg)) {\n throw error(\n `Direct queries are not supported as positional arguments. Use package names only.`,\n {\n code: 'EUSAGE',\n cause: `Argument '${arg}' appears to be a query syntax. Only package names are allowed as positional arguments.`,\n },\n )\n }\n }\n\n // retrieve default values and set up host contexts\n const positionalQueryString = conf.positionals\n .map(k => `#${k.replace(/\\//, '\\\\/')}`)\n .join(', ')\n const targetQueryString = conf.get('target')\n const scopeQueryString = conf.get('scope')\n const queryString = targetQueryString || positionalQueryString\n const projectQueryString = ':workspace, :project > *'\n const selectImporters: string[] = []\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 nodes,\n edges,\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 selectImporters.push(`[name=\"${w.name}\"]`)\n selectImporters.push(`[name=\"${w.name}\"] > *`)\n scopeIDs.push(workspace.id)\n }\n }\n }\n }\n\n // build a default query string to use in the target search\n const selectImportersQueryString = selectImporters.join(', ')\n const defaultProjectQueryString =\n (\n graph &&\n selectImporters.length &&\n selectImporters.length < graph.importers.size\n ) ?\n selectImportersQueryString\n : projectQueryString\n const defaultLocalScopeQueryString = ':host(local) :root > *'\n\n // retrieve the selected nodes and edges\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_ =\n importers.size === 0 && graph ?\n new Set([graph.mainImporter])\n : importers\n /* c8 ignore stop */\n const q = new Query({\n nodes: nodes_,\n edges: edges_,\n importers: importers_,\n securityArchive,\n hostContexts,\n })\n const query =\n queryString ||\n /* c8 ignore next */\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 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 /* c8 ignore next 2 */\n defaultProjectQueryString\n : defaultLocalScopeQueryString),\n }\n}\n"]}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { CommandFn, CommandUsage } from '../index.ts';
|
|
2
|
+
import type { LoadedConfig } from '../config/index.ts';
|
|
3
|
+
export declare const usage: CommandUsage;
|
|
4
|
+
export type CommandResultSingle = {
|
|
5
|
+
id: string;
|
|
6
|
+
name: string;
|
|
7
|
+
version: string;
|
|
8
|
+
filename: string;
|
|
9
|
+
files: string[];
|
|
10
|
+
size: number;
|
|
11
|
+
unpackedSize: number;
|
|
12
|
+
shasum?: string;
|
|
13
|
+
integrity?: string;
|
|
14
|
+
};
|
|
15
|
+
export type CommandResult = CommandResultSingle | CommandResultSingle[];
|
|
16
|
+
export declare const views: {
|
|
17
|
+
readonly human: (results: CommandResult) => string;
|
|
18
|
+
readonly json: (r: CommandResult) => CommandResult;
|
|
19
|
+
};
|
|
20
|
+
export declare const command: CommandFn<CommandResult>;
|
|
21
|
+
export declare const commandSingle: (location: string, conf: LoadedConfig) => Promise<{
|
|
22
|
+
id: string;
|
|
23
|
+
name: string;
|
|
24
|
+
version: string;
|
|
25
|
+
filename: string;
|
|
26
|
+
files: string[];
|
|
27
|
+
size: number;
|
|
28
|
+
unpackedSize: number;
|
|
29
|
+
shasum: string | undefined;
|
|
30
|
+
integrity: string | undefined;
|
|
31
|
+
}>;
|
|
32
|
+
//# sourceMappingURL=pack.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pack.d.ts","sourceRoot":"","sources":["../../../src/commands/pack.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAM1D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAItD,eAAO,MAAM,KAAK,EAAE,YAchB,CAAA;AAEJ,MAAM,MAAM,mBAAmB,GAAG;IAChC,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,CAAA;IACf,QAAQ,EAAE,MAAM,CAAA;IAChB,KAAK,EAAE,MAAM,EAAE,CAAA;IACf,IAAI,EAAE,MAAM,CAAA;IACZ,YAAY,EAAE,MAAM,CAAA;IACpB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB,CAAA;AAED,MAAM,MAAM,aAAa,GACrB,mBAAmB,GACnB,mBAAmB,EAAE,CAAA;AAEzB,eAAO,MAAM,KAAK;;;CAoBuB,CAAA;AAEzC,eAAO,MAAM,OAAO,EAAE,SAAS,CAAC,aAAa,CAiE5C,CAAA;AAED,eAAO,MAAM,aAAa,aACd,MAAM,QACV,YAAY;;;;;;;;;;EA0DnB,CAAA"}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { writeFile } from 'node:fs/promises';
|
|
2
|
+
import { dirname, join, resolve } from 'node:path';
|
|
3
|
+
import assert from 'node:assert';
|
|
4
|
+
import { run } from '@vltpkg/run';
|
|
5
|
+
import { commandUsage } from "../config/usage.js";
|
|
6
|
+
import { packTarball } from "../pack-tarball.js";
|
|
7
|
+
import prettyBytes from 'pretty-bytes';
|
|
8
|
+
import { actual } from '@vltpkg/graph';
|
|
9
|
+
import { Query } from '@vltpkg/query';
|
|
10
|
+
import { error } from '@vltpkg/error-cause';
|
|
11
|
+
import { createHostContextsMap } from "../query-host-contexts.js";
|
|
12
|
+
export const usage = () => commandUsage({
|
|
13
|
+
command: 'pack',
|
|
14
|
+
usage: '',
|
|
15
|
+
description: `Create a tarball from a package in the current directory or specified folder.
|
|
16
|
+
|
|
17
|
+
The tarball will be saved to the current directory with the name
|
|
18
|
+
<name>-<version>.tgz.`,
|
|
19
|
+
options: {
|
|
20
|
+
'dry-run': {
|
|
21
|
+
description: 'Show what would be packed without creating a tarball',
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
export const views = {
|
|
26
|
+
human: results => {
|
|
27
|
+
const item = (r) => {
|
|
28
|
+
const lines = [
|
|
29
|
+
`📦 Package: ${r.id}`,
|
|
30
|
+
`📄 File: ${r.filename}`,
|
|
31
|
+
`📁 ${r.files.length} Files`,
|
|
32
|
+
...r.files.map(f => ` - ${f}`),
|
|
33
|
+
`📊 Package Size: ${prettyBytes(r.size)}`,
|
|
34
|
+
`📂 Unpacked Size: ${prettyBytes(r.unpackedSize)}`,
|
|
35
|
+
];
|
|
36
|
+
if (r.shasum)
|
|
37
|
+
lines.push(`🔒 Shasum: ${r.shasum}`);
|
|
38
|
+
if (r.integrity)
|
|
39
|
+
lines.push(`🔐 Integrity: ${r.integrity}`);
|
|
40
|
+
return lines.join('\n');
|
|
41
|
+
};
|
|
42
|
+
return Array.isArray(results) ?
|
|
43
|
+
results.map(item).join('\n\n')
|
|
44
|
+
: item(results);
|
|
45
|
+
},
|
|
46
|
+
json: r => r,
|
|
47
|
+
};
|
|
48
|
+
export const command = async (conf) => {
|
|
49
|
+
const { options, projectRoot } = conf;
|
|
50
|
+
const queryString = conf.get('scope');
|
|
51
|
+
const paths = conf.get('workspace');
|
|
52
|
+
const groups = conf.get('workspace-group');
|
|
53
|
+
const recursive = conf.get('recursive');
|
|
54
|
+
const locations = [];
|
|
55
|
+
let single = null;
|
|
56
|
+
if (queryString) {
|
|
57
|
+
const mainManifest = options.packageJson.maybeRead(projectRoot);
|
|
58
|
+
let graph;
|
|
59
|
+
if (mainManifest) {
|
|
60
|
+
graph = actual.load({
|
|
61
|
+
...options,
|
|
62
|
+
mainManifest,
|
|
63
|
+
monorepo: options.monorepo,
|
|
64
|
+
loadManifests: false,
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
const hostContexts = await createHostContextsMap(conf);
|
|
68
|
+
const query = new Query({
|
|
69
|
+
/* c8 ignore next */
|
|
70
|
+
nodes: graph ? new Set(graph.nodes.values()) : new Set(),
|
|
71
|
+
edges: graph?.edges ?? new Set(),
|
|
72
|
+
importers: graph?.importers ?? new Set(),
|
|
73
|
+
securityArchive: undefined,
|
|
74
|
+
hostContexts,
|
|
75
|
+
});
|
|
76
|
+
const { nodes } = await query.search(queryString, {
|
|
77
|
+
signal: new AbortController().signal,
|
|
78
|
+
});
|
|
79
|
+
for (const node of nodes) {
|
|
80
|
+
const { location } = node.toJSON();
|
|
81
|
+
assert(location, error(`node ${node.id} has no location`, {
|
|
82
|
+
found: node,
|
|
83
|
+
}));
|
|
84
|
+
locations.push(resolve(projectRoot, location));
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
else if (paths?.length || groups?.length || recursive) {
|
|
88
|
+
for (const workspace of options.monorepo ?? []) {
|
|
89
|
+
locations.push(workspace.fullpath);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
single = options.packageJson.find(process.cwd()) ?? projectRoot;
|
|
94
|
+
}
|
|
95
|
+
if (single) {
|
|
96
|
+
return commandSingle(single, conf);
|
|
97
|
+
}
|
|
98
|
+
assert(locations.length > 0, error('No workspaces or query results found'));
|
|
99
|
+
const results = [];
|
|
100
|
+
for (const location of locations) {
|
|
101
|
+
results.push(await commandSingle(location, conf));
|
|
102
|
+
}
|
|
103
|
+
return results;
|
|
104
|
+
};
|
|
105
|
+
export const commandSingle = async (location, conf) => {
|
|
106
|
+
const manifestPath = conf.options.packageJson.find(location);
|
|
107
|
+
assert(manifestPath, 'No package.json found');
|
|
108
|
+
const manifestDir = dirname(manifestPath);
|
|
109
|
+
const manifest = conf.options.packageJson.read(manifestDir);
|
|
110
|
+
const isDryRun = conf.options['dry-run'];
|
|
111
|
+
const runOptions = {
|
|
112
|
+
cwd: manifestDir,
|
|
113
|
+
projectRoot: conf.projectRoot,
|
|
114
|
+
packageJson: conf.options.packageJson,
|
|
115
|
+
manifest,
|
|
116
|
+
ignoreMissing: true,
|
|
117
|
+
ignorePrePost: true,
|
|
118
|
+
};
|
|
119
|
+
await run({
|
|
120
|
+
...runOptions,
|
|
121
|
+
arg0: 'prepack',
|
|
122
|
+
});
|
|
123
|
+
await run({
|
|
124
|
+
...runOptions,
|
|
125
|
+
arg0: 'prepare',
|
|
126
|
+
});
|
|
127
|
+
const { name, version, filename, tarballData, unpackedSize, files, integrity, shasum, } = await packTarball(manifest, manifestDir, conf);
|
|
128
|
+
if (!isDryRun) {
|
|
129
|
+
await writeFile(join(manifestDir, filename), tarballData);
|
|
130
|
+
}
|
|
131
|
+
await run({
|
|
132
|
+
...runOptions,
|
|
133
|
+
arg0: 'postpack',
|
|
134
|
+
});
|
|
135
|
+
return {
|
|
136
|
+
id: `${name}@${version}`,
|
|
137
|
+
name,
|
|
138
|
+
version,
|
|
139
|
+
filename,
|
|
140
|
+
files,
|
|
141
|
+
size: tarballData.length,
|
|
142
|
+
unpackedSize,
|
|
143
|
+
shasum,
|
|
144
|
+
integrity,
|
|
145
|
+
};
|
|
146
|
+
};
|
|
147
|
+
//# sourceMappingURL=pack.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pack.js","sourceRoot":"","sources":["../../../src/commands/pack.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,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AAM,GAAG,CAAC;QACR,GAAG,UAAU;QACb,IAAI,EAAE,SAAS;KAChB,CAAC,CAAA;IAEF,MAAM,GAAG,CAAC;QACR,GAAG,UAAU;QACb,IAAI,EAAE,SAAS;KAChB,CAAC,CAAA;IAEF,MAAM,EACJ,IAAI,EACJ,OAAO,EACP,QAAQ,EACR,WAAW,EACX,YAAY,EACZ,KAAK,EACL,SAAS,EACT,MAAM,GACP,GAAG,MAAM,WAAW,CAAC,QAAQ,EAAE,WAAW,EAAE,IAAI,CAAC,CAAA;IAElD,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,MAAM,SAAS,CAAC,IAAI,CAAC,WAAW,EAAE,QAAQ,CAAC,EAAE,WAAW,CAAC,CAAA;IAC3D,CAAC;IAED,MAAM,GAAG,CAAC;QACR,GAAG,UAAU;QACb,IAAI,EAAE,UAAU;KACjB,CAAC,CAAA;IAEF,OAAO;QACL,EAAE,EAAE,GAAG,IAAI,IAAI,OAAO,EAAE;QACxB,IAAI;QACJ,OAAO;QACP,QAAQ;QACR,KAAK;QACL,IAAI,EAAE,WAAW,CAAC,MAAM;QACxB,YAAY;QACZ,MAAM;QACN,SAAS;KACV,CAAA;AACH,CAAC,CAAA","sourcesContent":["import { writeFile } from 'node:fs/promises'\nimport { dirname, join, resolve } from 'node:path'\nimport assert from 'node:assert'\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 prettyBytes from 'pretty-bytes'\nimport { actual } from '@vltpkg/graph'\nimport { Query } from '@vltpkg/query'\nimport type { LoadedConfig } from '../config/index.ts'\nimport { error } from '@vltpkg/error-cause'\nimport { createHostContextsMap } from '../query-host-contexts.ts'\n\nexport const usage: CommandUsage = () =>\n commandUsage({\n command: 'pack',\n usage: '',\n description: `Create a tarball from a package in the current directory or specified folder.\n \n The tarball will be saved to the current directory with the name\n <name>-<version>.tgz.`,\n options: {\n 'dry-run': {\n description:\n 'Show what would be packed without creating a tarball',\n },\n },\n })\n\nexport type CommandResultSingle = {\n id: string\n name: string\n version: string\n filename: string\n files: string[]\n size: number\n unpackedSize: number\n shasum?: string\n integrity?: 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 `📄 File: ${r.filename}`,\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\nexport const 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 const isDryRun = conf.options['dry-run']\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: 'prepack',\n })\n\n await run({\n ...runOptions,\n arg0: 'prepare',\n })\n\n const {\n name,\n version,\n filename,\n tarballData,\n unpackedSize,\n files,\n integrity,\n shasum,\n } = await packTarball(manifest, manifestDir, conf)\n\n if (!isDryRun) {\n await writeFile(join(manifestDir, filename), tarballData)\n }\n\n await run({\n ...runOptions,\n arg0: 'postpack',\n })\n\n return {\n id: `${name}@${version}`,\n name,\n version,\n filename,\n files,\n size: tarballData.length,\n unpackedSize,\n shasum,\n integrity,\n }\n}\n"]}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import type { LoadedConfig } from '../config/index.ts';
|
|
2
1
|
import type { CommandFn, CommandUsage } from '../index.ts';
|
|
3
2
|
export declare const views: {
|
|
4
|
-
readonly human: (results: unknown,
|
|
3
|
+
readonly human: (results: unknown, _: import("../view.ts").ViewOptions, config: import("../config/index.ts").ParsedConfig) => string;
|
|
5
4
|
};
|
|
6
5
|
export declare const usage: CommandUsage;
|
|
7
6
|
export declare const command: CommandFn;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pkg.d.ts","sourceRoot":"","sources":["../../../src/commands/pkg.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"pkg.d.ts","sourceRoot":"","sources":["../../../src/commands/pkg.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAI1D,eAAO,MAAM,KAAK;;CAgBQ,CAAA;AAE1B,eAAO,MAAM,KAAK,EAAE,YAoChB,CAAA;AAEJ,eAAO,MAAM,OAAO,EAAE,SAqGrB,CAAA"}
|