@vltpkg/cli-sdk 1.0.0-rc.22 → 1.0.0-rc.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (103) hide show
  1. package/dist/commands/bugs.d.ts +17 -0
  2. package/dist/commands/bugs.js +163 -0
  3. package/dist/commands/build.d.ts +24 -0
  4. package/dist/commands/build.js +101 -0
  5. package/dist/commands/cache.d.ts +64 -0
  6. package/dist/commands/cache.js +256 -0
  7. package/dist/commands/ci.d.ts +10 -0
  8. package/dist/commands/ci.js +40 -0
  9. package/dist/commands/config.d.ts +5 -0
  10. package/dist/commands/config.js +429 -0
  11. package/dist/commands/create.d.ts +8 -0
  12. package/dist/commands/create.js +102 -0
  13. package/dist/commands/docs.d.ts +17 -0
  14. package/dist/commands/docs.js +153 -0
  15. package/dist/commands/exec-cache.d.ts +48 -0
  16. package/dist/commands/exec-cache.js +145 -0
  17. package/dist/commands/exec-local.d.ts +5 -0
  18. package/dist/commands/exec-local.js +46 -0
  19. package/dist/commands/exec.d.ts +8 -0
  20. package/dist/commands/exec.js +161 -0
  21. package/dist/commands/help.d.ts +3 -0
  22. package/dist/commands/help.js +43 -0
  23. package/dist/commands/init.d.ts +7 -0
  24. package/dist/commands/init.js +116 -0
  25. package/dist/commands/install/reporter.d.ts +10 -0
  26. package/dist/commands/install/reporter.js +93 -0
  27. package/dist/commands/install.d.ts +27 -0
  28. package/dist/commands/install.js +80 -0
  29. package/dist/commands/list.d.ts +17 -0
  30. package/dist/commands/list.js +197 -0
  31. package/dist/commands/login.d.ts +3 -0
  32. package/dist/commands/login.js +22 -0
  33. package/dist/commands/logout.d.ts +3 -0
  34. package/dist/commands/logout.js +22 -0
  35. package/dist/commands/pack.d.ts +31 -0
  36. package/dist/commands/pack.js +205 -0
  37. package/dist/commands/ping.d.ts +17 -0
  38. package/dist/commands/ping.js +114 -0
  39. package/dist/commands/pkg.d.ts +6 -0
  40. package/dist/commands/pkg.js +232 -0
  41. package/dist/commands/publish.d.ts +21 -0
  42. package/dist/commands/publish.js +282 -0
  43. package/dist/commands/query.d.ts +18 -0
  44. package/dist/commands/query.js +216 -0
  45. package/dist/commands/repo.d.ts +17 -0
  46. package/dist/commands/repo.js +157 -0
  47. package/dist/commands/run-exec.d.ts +5 -0
  48. package/dist/commands/run-exec.js +40 -0
  49. package/dist/commands/run.d.ts +5 -0
  50. package/dist/commands/run.js +62 -0
  51. package/dist/commands/token.d.ts +3 -0
  52. package/dist/commands/token.js +39 -0
  53. package/dist/commands/uninstall.d.ts +15 -0
  54. package/dist/commands/uninstall.js +39 -0
  55. package/dist/commands/update.d.ts +13 -0
  56. package/dist/commands/update.js +46 -0
  57. package/dist/commands/version.d.ts +25 -0
  58. package/dist/commands/version.js +252 -0
  59. package/dist/commands/view.d.ts +22 -0
  60. package/dist/commands/view.js +334 -0
  61. package/dist/commands/whoami.d.ts +12 -0
  62. package/dist/commands/whoami.js +28 -0
  63. package/dist/config/definition.d.ts +407 -0
  64. package/dist/config/definition.js +684 -0
  65. package/dist/config/index.d.ts +218 -0
  66. package/dist/config/index.js +488 -0
  67. package/dist/config/merge.d.ts +3 -0
  68. package/dist/config/merge.js +27 -0
  69. package/dist/config/usage.d.ts +18 -0
  70. package/dist/config/usage.js +39 -0
  71. package/dist/custom-help.d.ts +8 -0
  72. package/dist/custom-help.js +419 -0
  73. package/dist/exec-command.d.ts +52 -0
  74. package/dist/exec-command.js +313 -0
  75. package/dist/index.d.ts +3 -0
  76. package/dist/index.js +72 -0
  77. package/dist/load-command.d.ts +15 -0
  78. package/dist/load-command.js +20 -0
  79. package/dist/mermaid-image-view.d.ts +18 -0
  80. package/dist/mermaid-image-view.js +36 -0
  81. package/dist/output.d.ts +20 -0
  82. package/dist/output.js +125 -0
  83. package/dist/pack-tarball.d.ts +23 -0
  84. package/dist/pack-tarball.js +256 -0
  85. package/dist/parse-add-remove-args.d.ts +28 -0
  86. package/dist/parse-add-remove-args.js +103 -0
  87. package/dist/print-err.d.ts +13 -0
  88. package/dist/print-err.js +193 -0
  89. package/dist/query-diff-files.d.ts +17 -0
  90. package/dist/query-diff-files.js +63 -0
  91. package/dist/query-host-contexts.d.ts +15 -0
  92. package/dist/query-host-contexts.js +136 -0
  93. package/dist/read-password.d.ts +7 -0
  94. package/dist/read-password.js +32 -0
  95. package/dist/read-project-folders.d.ts +17 -0
  96. package/dist/read-project-folders.js +100 -0
  97. package/dist/reload-config.d.ts +2 -0
  98. package/dist/reload-config.js +11 -0
  99. package/dist/render-mermaid.d.ts +22 -0
  100. package/dist/render-mermaid.js +68 -0
  101. package/dist/view.d.ts +29 -0
  102. package/dist/view.js +30 -0
  103. package/package.json +30 -30
@@ -0,0 +1,17 @@
1
+ import type { CommandFn, CommandUsage } from '../index.ts';
2
+ export declare const usage: CommandUsage;
3
+ type CommandResultSingle = {
4
+ url: string;
5
+ name: string;
6
+ };
7
+ type CommandResultMultiple = {
8
+ url: string;
9
+ name: string;
10
+ }[];
11
+ export type CommandResult = CommandResultSingle | CommandResultMultiple;
12
+ export declare const views: {
13
+ readonly human: (r: CommandResult) => string;
14
+ readonly json: (r: CommandResult) => CommandResult;
15
+ };
16
+ export declare const command: CommandFn<CommandResult>;
17
+ export {};
@@ -0,0 +1,163 @@
1
+ import { error } from '@vltpkg/error-cause';
2
+ import { PackageInfoClient } from '@vltpkg/package-info';
3
+ import { Spec } from '@vltpkg/spec';
4
+ import { urlOpen } from '@vltpkg/url-open';
5
+ import { actual } from '@vltpkg/graph';
6
+ import { Query } from '@vltpkg/query';
7
+ import { SecurityArchive } from '@vltpkg/security-archive';
8
+ import { createHostContextsMap } from "../query-host-contexts.js";
9
+ import { commandUsage } from "../config/usage.js";
10
+ import hostedGitInfo from 'hosted-git-info';
11
+ const { fromUrl: hostedGitInfoFromUrl } = hostedGitInfo;
12
+ export const usage = () => commandUsage({
13
+ command: 'bugs',
14
+ usage: ['[<spec>]', '[--target=<query>]'],
15
+ description: `Open bug tracker for a package in a web browser.
16
+ Reads bug tracker information from package.json or fetches
17
+ manifest data for the specified package.`,
18
+ options: {
19
+ target: {
20
+ value: '<query>',
21
+ description: 'Query selector to filter packages using DSS syntax.',
22
+ },
23
+ },
24
+ examples: {
25
+ '': {
26
+ description: 'Open bugs for the current package (reads local package.json)',
27
+ },
28
+ 'abbrev@2.0.0': {
29
+ description: 'Open bugs for a specific package version',
30
+ },
31
+ '--target=":root > *"': {
32
+ description: 'List bug tracker URLs for all direct dependencies',
33
+ },
34
+ },
35
+ });
36
+ export const views = {
37
+ human: r => {
38
+ if (Array.isArray(r)) {
39
+ let msg = 'Multiple package bug trackers found:\n';
40
+ msg += r.map(item => `• ${item.name}: ${item.url}`).join('\n');
41
+ return msg;
42
+ }
43
+ return '';
44
+ },
45
+ json: r => r,
46
+ };
47
+ const getUrlFromManifest = (manifest) => {
48
+ const { name, bugs, repository } = manifest;
49
+ if (!name) {
50
+ throw error('No package name found');
51
+ }
52
+ let url;
53
+ // Check bugs field first
54
+ if (bugs) {
55
+ if (typeof bugs === 'string') {
56
+ url = bugs;
57
+ }
58
+ else if (typeof bugs === 'object') {
59
+ if ('url' in bugs && bugs.url) {
60
+ url = bugs.url;
61
+ }
62
+ else if ('email' in bugs && bugs.email) {
63
+ url = `mailto:${bugs.email}`;
64
+ }
65
+ }
66
+ }
67
+ // Try repository if no bugs field
68
+ if (!url && repository) {
69
+ const repoUrl = typeof repository === 'string' ? repository
70
+ : typeof repository === 'object' && 'url' in repository ?
71
+ repository.url
72
+ : /* c8 ignore next */ undefined;
73
+ if (repoUrl) {
74
+ const info = hostedGitInfoFromUrl(repoUrl.replace(/^git\+/, ''));
75
+ if (info?.bugs && typeof info.bugs === 'function') {
76
+ url = info.bugs();
77
+ }
78
+ }
79
+ }
80
+ // Fallback to vlt.io package page
81
+ if (!url) {
82
+ url = `https://vlt.io/explore/npm/${name}/overview`;
83
+ }
84
+ return url;
85
+ };
86
+ export const command = async (conf) => {
87
+ const { projectRoot, packageJson } = conf.options;
88
+ const targetOption = conf.get('target');
89
+ // Handle --target query
90
+ if (targetOption) {
91
+ const mainManifest = packageJson.maybeRead(projectRoot);
92
+ if (!mainManifest) {
93
+ throw error('No package.json found in project root', {
94
+ path: projectRoot,
95
+ });
96
+ }
97
+ const graph = actual.load({
98
+ ...conf.options,
99
+ mainManifest,
100
+ monorepo: conf.options.monorepo,
101
+ loadManifests: true,
102
+ });
103
+ const securityArchive = Query.hasSecuritySelectors(targetOption) ?
104
+ await SecurityArchive.start({
105
+ nodes: [...graph.nodes.values()],
106
+ })
107
+ : undefined;
108
+ const hostContexts = await createHostContextsMap(conf);
109
+ const query = new Query({
110
+ nodes: new Set(graph.nodes.values()),
111
+ edges: graph.edges,
112
+ importers: graph.importers,
113
+ securityArchive,
114
+ hostContexts,
115
+ });
116
+ const { nodes } = await query.search(targetOption, {
117
+ signal: new AbortController().signal,
118
+ });
119
+ const results = [];
120
+ for (const node of nodes) {
121
+ if (!node.manifest)
122
+ continue;
123
+ const url = getUrlFromManifest(node.manifest);
124
+ results.push({
125
+ url,
126
+ name: node.name /* c8 ignore next */ ?? '(unknown)',
127
+ });
128
+ }
129
+ if (results.length === 0) {
130
+ throw error('No packages found matching target query', {
131
+ found: targetOption,
132
+ });
133
+ }
134
+ // If single result, open it
135
+ if (results.length === 1) {
136
+ const result = results[0];
137
+ /* c8 ignore next 3 */
138
+ if (!result) {
139
+ throw error('Unexpected empty result');
140
+ }
141
+ await urlOpen(result.url);
142
+ return result;
143
+ }
144
+ // Multiple results, return the list
145
+ return results;
146
+ }
147
+ // read the package spec from a positional argument or local package.json
148
+ const specArg = conf.positionals[0];
149
+ const manifest = conf.positionals.length === 0 ? packageJson.read(projectRoot)
150
+ : specArg ?
151
+ await new PackageInfoClient(conf.options).manifest(Spec.parseArgs(specArg, conf.options))
152
+ : /* c8 ignore next */ packageJson.read(projectRoot);
153
+ const url = getUrlFromManifest(manifest);
154
+ const { name } = manifest;
155
+ /* c8 ignore start - getUrlFromManifest already validates name */
156
+ if (!name) {
157
+ throw error('No package name found');
158
+ }
159
+ /* c8 ignore stop */
160
+ // Open the URL
161
+ await urlOpen(url);
162
+ return { url, name };
163
+ };
@@ -0,0 +1,24 @@
1
+ import type { BuildResult } from '@vltpkg/graph';
2
+ import type { CommandFn, CommandUsage } from '../index.ts';
3
+ export declare const views: {
4
+ readonly human: (result: BuildResult) => string;
5
+ readonly json: (result: BuildResult) => {
6
+ success: {
7
+ id: import("@vltpkg/dep-id").DepID;
8
+ name: string;
9
+ version: string | undefined;
10
+ }[];
11
+ failure: {
12
+ id: import("@vltpkg/dep-id").DepID;
13
+ name: string;
14
+ version: string | undefined;
15
+ }[];
16
+ message: string;
17
+ };
18
+ };
19
+ export declare const usage: CommandUsage;
20
+ /**
21
+ * Build command implementation. Runs any required "postinstall"
22
+ * lifecycle scripts and binary linking.
23
+ */
24
+ export declare const command: CommandFn<BuildResult>;
@@ -0,0 +1,101 @@
1
+ import { build } from '@vltpkg/graph';
2
+ import { error } from '@vltpkg/error-cause';
3
+ import { commandUsage } from "../config/usage.js";
4
+ import { isErrorWithCause } from '@vltpkg/types';
5
+ export const views = {
6
+ human: (result) => {
7
+ const successCount = result.success.length;
8
+ const failureCount = result.failure.length;
9
+ const messages = [];
10
+ if (successCount > 0) {
11
+ messages.push(`🔨 Built ${successCount} package${successCount === 1 ? '' : 's'} successfully.`);
12
+ }
13
+ else {
14
+ messages.push('📦 All packages are already built.');
15
+ }
16
+ if (failureCount > 0) {
17
+ messages.push(`🔎 ${failureCount} optional package${ /* c8 ignore next */failureCount === 1 ? '' : 's'} failed to build.`);
18
+ }
19
+ return messages.join('\n');
20
+ },
21
+ json: (result) => {
22
+ const successList = result.success.map(node => ({
23
+ id: node.id,
24
+ name: node.name,
25
+ version: node.version,
26
+ }));
27
+ const failureList = result.failure.map(node => ({
28
+ id: node.id,
29
+ name: node.name,
30
+ version: node.version,
31
+ }));
32
+ return {
33
+ success: successList,
34
+ failure: failureList,
35
+ message: successList.length > 0 ?
36
+ `Built ${successList.length} package${successList.length === 1 ? '' : 's'}.`
37
+ : 'No packages needed building.',
38
+ };
39
+ },
40
+ };
41
+ export const usage = () => commandUsage({
42
+ command: 'build',
43
+ usage: ['[query]', '[--target=<query>]'],
44
+ description: `Build the project based on the current dependency graph.
45
+
46
+ This command processes the installed packages in node_modules and runs
47
+ any necessary build steps, such as lifecycle scripts and binary linking.
48
+
49
+ The build process is idempotent and will only perform work that is
50
+ actually needed based on the current state of the dependency graph.
51
+
52
+ Use --target option or provide a query as a positional argument to filter
53
+ packages using DSS query language syntax, otherwise it will target
54
+ all packages with scripts (:scripts) by default.`,
55
+ options: {
56
+ target: {
57
+ value: '<query>',
58
+ description: 'Query selector to filter packages using DSS syntax.',
59
+ },
60
+ },
61
+ });
62
+ const isGraphRunError = (error) => typeof error === 'object' &&
63
+ error !== null &&
64
+ 'code' in error &&
65
+ error.code === 'GRAPHRUN_TRAVERSAL' &&
66
+ 'node' in error;
67
+ /**
68
+ * Build command implementation. Runs any required "postinstall"
69
+ * lifecycle scripts and binary linking.
70
+ */
71
+ export const command = async (conf) => {
72
+ const { options, projectRoot } = conf;
73
+ try {
74
+ // Get target from option or first positional, default to all scripts
75
+ const targetOption = conf.get('target');
76
+ const targetPositional = conf.positionals[0];
77
+ const target = targetOption ||
78
+ targetPositional ||
79
+ ':scripts:not(:built):not(:malware)';
80
+ // Run the build process using the graph build function
81
+ const result = await build({
82
+ ...options,
83
+ projectRoot,
84
+ packageJson: options.packageJson,
85
+ monorepo: options.monorepo,
86
+ scurry: options.scurry,
87
+ target,
88
+ });
89
+ return result;
90
+ }
91
+ catch (cause) {
92
+ const graphRunError = isErrorWithCause(cause) && isGraphRunError(cause.cause) ?
93
+ cause.cause
94
+ : undefined;
95
+ if (graphRunError?.code === 'GRAPHRUN_TRAVERSAL') {
96
+ throw error('Build failed:\n Failed to build package: ' +
97
+ `${graphRunError.node.name}@${graphRunError.node.version}`, { cause });
98
+ }
99
+ throw error('Build failed', { cause });
100
+ }
101
+ };
@@ -0,0 +1,64 @@
1
+ import { CacheEntry } from '@vltpkg/registry-client';
2
+ import type { LoadedConfig } from '../config/index.ts';
3
+ import type { CommandFn, CommandUsage } from '../index.ts';
4
+ import type { ViewOptions, Views } from '../view.ts';
5
+ import { ViewClass } from '../view.ts';
6
+ export type CacheMap = Record<string, ReturnType<CacheEntry['toJSON']>>;
7
+ export type CacheSubcommands = keyof (typeof usageDef)['subcommands'];
8
+ export declare class CacheView extends ViewClass {
9
+ constructor(options: ViewOptions, conf: LoadedConfig);
10
+ stdout(...args: unknown[]): void;
11
+ }
12
+ export declare const views: Views<void | CacheMap>;
13
+ declare const usageDef: {
14
+ readonly command: "cache";
15
+ readonly usage: "<command> [flags]";
16
+ readonly description: "Work with vlt cache folders";
17
+ readonly subcommands: {
18
+ readonly add: {
19
+ readonly usage: "<package-spec> [<package-spec>...]";
20
+ readonly description: "Resolve the referenced package identifiers and ensure they\n are cached.";
21
+ };
22
+ readonly ls: {
23
+ readonly usage: "[<key>...]";
24
+ readonly description: "Show cache entries. If no keys are provided, then a list of\n available keys will be printed. If one or more keys are\n provided, then details will be shown for the specified\n items.";
25
+ };
26
+ readonly info: {
27
+ readonly usage: "<key>";
28
+ readonly description: "Print metadata details for the specified cache key to\n stderr, and the response body to stdout.";
29
+ };
30
+ readonly clean: {
31
+ readonly usage: "[<key>...]";
32
+ readonly description: "Purge expired cache entries. If one or more keys are\n provided, then only those cache entries will be\n considered.";
33
+ };
34
+ readonly delete: {
35
+ readonly usage: "<key> [<key>...]";
36
+ readonly description: "Purge items explicitly, whether expired or not. If one or\n more keys are provided, then only those cache entries will\n be considered.";
37
+ };
38
+ readonly 'delete-before': {
39
+ readonly usage: "<date>";
40
+ readonly description: "Purge all cache items from before a given date. Date can be\n provided in any format that JavaScript can parse.";
41
+ };
42
+ readonly 'delete-all': {
43
+ readonly usage: "";
44
+ readonly description: "Delete the entire cache folder to make vlt slower.";
45
+ };
46
+ };
47
+ readonly examples: {
48
+ readonly 'vlt cache ls https://registry.npmjs.org/typescript': {
49
+ readonly description: "Show cache metadata for a given registry URL";
50
+ };
51
+ readonly 'vlt cache add eslint@latest': {
52
+ readonly description: "Add a given package specifier to the cache by fetching\n its resolved value.";
53
+ };
54
+ readonly 'vlt cache info https://registry.npmjs.org/eslint/-/eslint-9.25.1.tgz > eslint.tgz': {
55
+ readonly description: "Print the cache metadata to stderr, and write the tarball\n on stdout, redirecting to a file.";
56
+ };
57
+ readonly 'vlt cache delete-before 2025-01-01': {
58
+ readonly description: "Delete all entries created before Jan 1, 2025";
59
+ };
60
+ };
61
+ };
62
+ export declare const usage: CommandUsage;
63
+ export declare const command: CommandFn<void | CacheMap>;
64
+ export {};
@@ -0,0 +1,256 @@
1
+ import { error } from '@vltpkg/error-cause';
2
+ import { CacheEntry } from '@vltpkg/registry-client';
3
+ import { Spec } from '@vltpkg/spec';
4
+ import { mkdir, rm } from 'node:fs/promises';
5
+ import prettyBytes from 'pretty-bytes';
6
+ import { commandUsage } from "../config/usage.js";
7
+ import { stderr, stdout } from "../output.js";
8
+ import { ViewClass } from "../view.js";
9
+ let view;
10
+ export class CacheView extends ViewClass {
11
+ constructor(options, conf) {
12
+ super(options, conf);
13
+ view = this;
14
+ }
15
+ stdout(...args) {
16
+ stdout(...args);
17
+ }
18
+ }
19
+ export const views = {
20
+ human: CacheView,
21
+ };
22
+ const usageDef = {
23
+ command: 'cache',
24
+ usage: '<command> [flags]',
25
+ description: 'Work with vlt cache folders',
26
+ subcommands: {
27
+ add: {
28
+ usage: '<package-spec> [<package-spec>...]',
29
+ description: `Resolve the referenced package identifiers and ensure they
30
+ are cached.`,
31
+ },
32
+ ls: {
33
+ usage: '[<key>...]',
34
+ description: `Show cache entries. If no keys are provided, then a list of
35
+ available keys will be printed. If one or more keys are
36
+ provided, then details will be shown for the specified
37
+ items.`,
38
+ },
39
+ info: {
40
+ usage: '<key>',
41
+ description: `Print metadata details for the specified cache key to
42
+ stderr, and the response body to stdout.`,
43
+ },
44
+ clean: {
45
+ usage: '[<key>...]',
46
+ description: `Purge expired cache entries. If one or more keys are
47
+ provided, then only those cache entries will be
48
+ considered.`,
49
+ },
50
+ delete: {
51
+ usage: '<key> [<key>...]',
52
+ description: `Purge items explicitly, whether expired or not. If one or
53
+ more keys are provided, then only those cache entries will
54
+ be considered.`,
55
+ },
56
+ 'delete-before': {
57
+ usage: '<date>',
58
+ description: `Purge all cache items from before a given date. Date can be
59
+ provided in any format that JavaScript can parse.`,
60
+ },
61
+ 'delete-all': {
62
+ usage: '',
63
+ description: `Delete the entire cache folder to make vlt slower.`,
64
+ },
65
+ },
66
+ examples: {
67
+ 'vlt cache ls https://registry.npmjs.org/typescript': {
68
+ description: `Show cache metadata for a given registry URL`,
69
+ },
70
+ 'vlt cache add eslint@latest': {
71
+ description: `Add a given package specifier to the cache by fetching
72
+ its resolved value.`,
73
+ },
74
+ 'vlt cache info https://registry.npmjs.org/eslint/-/eslint-9.25.1.tgz > eslint.tgz': {
75
+ description: `Print the cache metadata to stderr, and write the tarball
76
+ on stdout, redirecting to a file.`,
77
+ },
78
+ 'vlt cache delete-before 2025-01-01': {
79
+ description: 'Delete all entries created before Jan 1, 2025',
80
+ },
81
+ },
82
+ };
83
+ export const usage = () => commandUsage(usageDef);
84
+ export const command = async (conf) => {
85
+ const [sub, ...args] = conf.positionals;
86
+ switch (sub) {
87
+ case 'ls':
88
+ return ls(conf, args, view);
89
+ case 'info':
90
+ return info(conf, args, view);
91
+ case 'add':
92
+ return add(conf, args, view);
93
+ case 'clean':
94
+ return clean(conf, args, view);
95
+ case 'delete':
96
+ return deleteKeys(conf, args, view);
97
+ case 'delete-before':
98
+ return deleteBefore(conf, args, view);
99
+ case 'delete-all':
100
+ return deleteAll(conf, args, view);
101
+ default: {
102
+ throw error('Unrecognized cache command', {
103
+ code: 'EUSAGE',
104
+ found: sub,
105
+ validOptions: Object.keys(usageDef.subcommands),
106
+ });
107
+ }
108
+ }
109
+ };
110
+ const ls = async (conf, keys, view) => keys.length ?
111
+ await fetchKeys(conf, keys, (entry, key) => {
112
+ view?.stdout(key.includes(' ') ? JSON.stringify(key) : key, entry);
113
+ return true;
114
+ }, view)
115
+ : await fetchAll(conf, (_, key) => {
116
+ view?.stdout(key.includes(' ') ? JSON.stringify(key) : key);
117
+ return true;
118
+ });
119
+ const info = async (conf, keys, view) => {
120
+ const [key] = keys;
121
+ if (keys.length !== 1 || !key) {
122
+ throw error('Must provide exactly one cache key', {
123
+ code: 'EUSAGE',
124
+ });
125
+ }
126
+ await fetchKeys(conf, [key], (entry, key) => {
127
+ stderr(
128
+ /* c8 ignore next */
129
+ key.includes(' ') ? JSON.stringify(key) : key, entry);
130
+ if (entry.isJSON) {
131
+ stdout(JSON.stringify(entry.body, null, 2));
132
+ /* c8 ignore start - annoying to test, corrupts TAP output */
133
+ }
134
+ else {
135
+ process.stdout.write(entry.body);
136
+ }
137
+ /* c8 ignore stop */
138
+ return true;
139
+ }, view);
140
+ };
141
+ const fetchAll = async (conf, test) => {
142
+ const rc = conf.options.packageInfo.registryClient;
143
+ const { cache } = rc;
144
+ const map = {};
145
+ for await (const [key, val] of cache) {
146
+ const entry = CacheEntry.decode(val);
147
+ if (!test(entry, key, val))
148
+ continue;
149
+ map[key] = entry.toJSON();
150
+ }
151
+ return map;
152
+ };
153
+ const fetchKeys = async (conf, keys, test, view) => {
154
+ const rc = conf.options.packageInfo.registryClient;
155
+ const { cache } = rc;
156
+ const map = {};
157
+ const results = await Promise.all(keys.map(async (key) => {
158
+ return [key, await cache.fetch(key)];
159
+ }));
160
+ for (const [key, val] of results) {
161
+ if (!val) {
162
+ view?.stdout('Not found:', key);
163
+ }
164
+ else {
165
+ const entry = CacheEntry.decode(val);
166
+ if (!test(entry, key, val))
167
+ continue;
168
+ map[key] = entry.toJSON();
169
+ }
170
+ }
171
+ return map;
172
+ };
173
+ const deleteEntries = async (conf, keys, test, view) => {
174
+ const rc = conf.options.packageInfo.registryClient;
175
+ const { cache } = rc;
176
+ let count = 0;
177
+ let size = 0;
178
+ const testAction = (entry, key, val) => {
179
+ if (!test(entry)) {
180
+ return false;
181
+ }
182
+ count++;
183
+ const s = val.byteLength + key.length;
184
+ cache.delete(key, true, entry.integrity);
185
+ const k = key.includes(' ') ? JSON.stringify(key) : key;
186
+ view?.stdout('-', k, s);
187
+ size += s;
188
+ return true;
189
+ };
190
+ const map = await (keys.length ?
191
+ fetchKeys(conf, keys, testAction, view)
192
+ : fetchAll(conf, testAction));
193
+ const pb = prettyBytes(size, { binary: true });
194
+ const s = count === 1 ? '' : 's';
195
+ await cache.promise();
196
+ view?.stdout(`Removed ${count} item${s} totalling ${pb}`);
197
+ return map;
198
+ };
199
+ const clean = async (conf, keys, view) => deleteEntries(conf, keys, entry => !entry.valid, view);
200
+ const deleteBefore = async (conf, args, view) => {
201
+ if (!args.length) {
202
+ throw error('Must provide a date to delete before', {
203
+ code: 'EUSAGE',
204
+ });
205
+ }
206
+ const now = new Date();
207
+ const before = new Date(args.join(' '));
208
+ if (before >= now) {
209
+ throw error('Cannot delete cache entries from the future', {
210
+ code: 'EUSAGE',
211
+ found: before,
212
+ });
213
+ }
214
+ return deleteEntries(conf, [], entry => !!entry.date && entry.date < before, view);
215
+ };
216
+ const deleteKeys = async (conf, keys, view) => {
217
+ if (!keys.length) {
218
+ throw error('Must provide cache keys to delete', {
219
+ code: 'EUSAGE',
220
+ });
221
+ }
222
+ return deleteEntries(conf, keys, () => true, view);
223
+ };
224
+ const deleteAll = async (conf, _, view) => {
225
+ const { cache } = conf.options.packageInfo.registryClient;
226
+ await rm(cache.path(), { recursive: true, force: true });
227
+ await mkdir(cache.path(), { recursive: true });
228
+ view?.stdout('Deleted all cache entries.');
229
+ };
230
+ const add = async (conf, specs, view) => {
231
+ if (!specs.length) {
232
+ throw error('Must provide specs to add to the cache', {
233
+ code: 'EUSAGE',
234
+ });
235
+ }
236
+ const { packageInfo } = conf.options;
237
+ const promises = [];
238
+ for (const spec of specs) {
239
+ const p = packageInfo
240
+ .resolve(Spec.parseArgs(spec, conf.options), {
241
+ staleWhileRevalidate: false,
242
+ })
243
+ .then(async (r) => {
244
+ const { resolved, integrity } = r;
245
+ await packageInfo.registryClient.request(resolved, {
246
+ ...conf.options,
247
+ integrity,
248
+ staleWhileRevalidate: false,
249
+ query: undefined,
250
+ });
251
+ view?.stdout('+', spec, r.resolved);
252
+ });
253
+ promises.push(p);
254
+ }
255
+ await Promise.all(promises);
256
+ };
@@ -0,0 +1,10 @@
1
+ import { InstallReporter } from './install/reporter.ts';
2
+ import type { CommandFn, CommandUsage } from '../index.ts';
3
+ import type { InstallResult } from './install.ts';
4
+ export type CIResult = Omit<InstallResult, 'buildQueue'>;
5
+ export declare const usage: CommandUsage;
6
+ export declare const views: {
7
+ readonly json: (i: CIResult) => import("@vltpkg/graph").LockfileData;
8
+ readonly human: typeof InstallReporter;
9
+ };
10
+ export declare const command: CommandFn<CIResult>;
@@ -0,0 +1,40 @@
1
+ import { install } from '@vltpkg/graph';
2
+ import { commandUsage } from "../config/usage.js";
3
+ import { InstallReporter } from "./install/reporter.js";
4
+ export const usage = () => commandUsage({
5
+ command: 'ci',
6
+ usage: '',
7
+ description: `Clean install from lockfile. Deletes node_modules and installs
8
+ dependencies exactly as specified in vlt-lock.json. This is
9
+ similar to running 'vlt install --expect-lockfile' but performs
10
+ a clean install by removing node_modules first.`,
11
+ examples: {
12
+ '': { description: 'Clean install from lockfile' },
13
+ },
14
+ options: {
15
+ 'allow-scripts': {
16
+ value: '<query>',
17
+ description: 'Filter which packages are allowed to run lifecycle scripts using DSS query syntax.',
18
+ },
19
+ 'lockfile-only': {
20
+ description: 'Only update lockfile and package.json files; skip node_modules operations.',
21
+ },
22
+ },
23
+ });
24
+ export const views = {
25
+ json: i => i.graph.toJSON(),
26
+ human: InstallReporter,
27
+ };
28
+ export const command = async (conf) => {
29
+ const ciOptions = {
30
+ ...conf.options,
31
+ // allow scripts but filter out malware via security archive
32
+ allowScripts: conf.get('allow-scripts') ?? ':scripts:not(:malware)',
33
+ expectLockfile: true,
34
+ frozenLockfile: true,
35
+ cleanInstall: true,
36
+ lockfileOnly: conf.options['lockfile-only'],
37
+ };
38
+ const { graph } = await install(ciOptions);
39
+ return { graph };
40
+ };
@@ -0,0 +1,5 @@
1
+ import type { CommandFn, CommandUsage } from '../index.ts';
2
+ import type { Views } from '../view.ts';
3
+ export declare const views: Views;
4
+ export declare const usage: CommandUsage;
5
+ export declare const command: CommandFn;