@vltpkg/cli-sdk 1.0.2 → 1.0.3

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.
@@ -140,7 +140,7 @@ const info = async (conf, keys, view) => {
140
140
  }, view);
141
141
  };
142
142
  const fetchAll = async (conf, test) => {
143
- const rc = conf.options.packageInfo.registryClient;
143
+ const rc = await conf.options.packageInfo.getRegistryClient();
144
144
  const { cache } = rc;
145
145
  const map = {};
146
146
  for await (const [key, val] of cache) {
@@ -152,7 +152,7 @@ const fetchAll = async (conf, test) => {
152
152
  return map;
153
153
  };
154
154
  const fetchKeys = async (conf, keys, test, view) => {
155
- const rc = conf.options.packageInfo.registryClient;
155
+ const rc = await conf.options.packageInfo.getRegistryClient();
156
156
  const { cache } = rc;
157
157
  const map = {};
158
158
  const results = await Promise.all(keys.map(async (key) => {
@@ -172,7 +172,7 @@ const fetchKeys = async (conf, keys, test, view) => {
172
172
  return map;
173
173
  };
174
174
  const deleteEntries = async (conf, keys, test, view) => {
175
- const rc = conf.options.packageInfo.registryClient;
175
+ const rc = await conf.options.packageInfo.getRegistryClient();
176
176
  const { cache } = rc;
177
177
  let count = 0;
178
178
  let size = 0;
@@ -223,7 +223,7 @@ const deleteKeys = async (conf, keys, view) => {
223
223
  return deleteEntries(conf, keys, () => true, view);
224
224
  };
225
225
  const deleteAll = async (conf, _, view) => {
226
- const { cache } = conf.options.packageInfo.registryClient;
226
+ const { cache } = await conf.options.packageInfo.getRegistryClient();
227
227
  await rm(cache.path(), { recursive: true, force: true });
228
228
  await mkdir(cache.path(), { recursive: true });
229
229
  view?.stdout('Deleted all cache entries.');
@@ -243,7 +243,7 @@ const add = async (conf, specs, view) => {
243
243
  })
244
244
  .then(async (r) => {
245
245
  const { resolved, integrity } = r;
246
- await packageInfo.registryClient.request(resolved, {
246
+ await (await packageInfo.getRegistryClient()).request(resolved, {
247
247
  ...conf.options,
248
248
  integrity,
249
249
  staleWhileRevalidate: false,
@@ -1,4 +1,3 @@
1
- import { InstallReporter } from './install/reporter.ts';
2
1
  import type { CommandFn, CommandUsage } from '../index.ts';
3
2
  import type { InstallResult } from './install.ts';
4
3
  export type CIResult = Omit<InstallResult, 'buildQueue'>;
@@ -6,6 +5,6 @@ export declare const needsRegistry = true;
6
5
  export declare const usage: CommandUsage;
7
6
  export declare const views: {
8
7
  readonly json: (i: CIResult) => import("@vltpkg/graph").LockfileData;
9
- readonly human: typeof InstallReporter;
8
+ readonly human: import("../view.ts").LazyView<InstallResult>;
10
9
  };
11
10
  export declare const command: CommandFn<CIResult>;
@@ -1,6 +1,6 @@
1
1
  import { install } from '@vltpkg/graph';
2
2
  import { commandUsage } from "../config/usage.js";
3
- import { InstallReporter } from "./install/reporter.js";
3
+ import { lazyView } from "../view.js";
4
4
  export const needsRegistry = true;
5
5
  export const usage = () => commandUsage({
6
6
  command: 'ci',
@@ -24,7 +24,7 @@ export const usage = () => commandUsage({
24
24
  });
25
25
  export const views = {
26
26
  json: i => i.graph.toJSON(),
27
- human: InstallReporter,
27
+ human: lazyView(async () => (await import('./install/reporter.ts')).InstallReporter),
28
28
  };
29
29
  export const command = async (conf) => {
30
30
  const ciOptions = {
@@ -1,4 +1,3 @@
1
- import { InstallReporter } from './install/reporter.ts';
2
1
  import type { DepID } from '@vltpkg/dep-id';
3
2
  import type { Diff, Graph } from '@vltpkg/graph';
4
3
  import type { CommandFn, CommandUsage } from '../index.ts';
@@ -42,6 +41,6 @@ export declare const views: {
42
41
  }[];
43
42
  removed: number;
44
43
  };
45
- readonly human: typeof InstallReporter;
44
+ readonly human: import("../view.ts").LazyView<InstallResult>;
46
45
  };
47
46
  export declare const command: CommandFn<InstallResult>;
@@ -1,8 +1,8 @@
1
1
  import { commandUsage } from "../config/usage.js";
2
2
  import { install } from '@vltpkg/graph';
3
3
  import { parseAddArgs } from "../parse-add-remove-args.js";
4
- import { InstallReporter } from "./install/reporter.js";
5
4
  import { trackInstall } from "../telemetry.js";
5
+ import { lazyView } from "../view.js";
6
6
  export const needsRegistry = true;
7
7
  export const usage = () => commandUsage({
8
8
  command: 'install',
@@ -112,7 +112,7 @@ export const views = {
112
112
  : null),
113
113
  };
114
114
  },
115
- human: InstallReporter,
115
+ human: lazyView(async () => (await import('./install/reporter.ts')).InstallReporter),
116
116
  };
117
117
  export const command = async (conf) => {
118
118
  // TODO: we should probably throw an error if the user
@@ -1,6 +1,5 @@
1
1
  import type { Graph } from '@vltpkg/graph';
2
2
  import type { CommandFn, CommandUsage } from '../index.ts';
3
- import { InstallReporter } from './install/reporter.ts';
4
3
  export type UninstallResult = {
5
4
  /**
6
5
  * The resulting graph structure at the end of an uninstall.
@@ -11,6 +10,6 @@ export declare const needsRegistry = true;
11
10
  export declare const usage: CommandUsage;
12
11
  export declare const views: {
13
12
  readonly json: (i: UninstallResult) => import("@vltpkg/graph").LockfileData;
14
- readonly human: typeof InstallReporter;
13
+ readonly human: import("../view.ts").LazyView<import("./install.ts").InstallResult>;
15
14
  };
16
15
  export declare const command: CommandFn<UninstallResult>;
@@ -1,7 +1,7 @@
1
1
  import { uninstall } from '@vltpkg/graph';
2
2
  import { commandUsage } from "../config/usage.js";
3
3
  import { parseRemoveArgs } from "../parse-add-remove-args.js";
4
- import { InstallReporter } from "./install/reporter.js";
4
+ import { lazyView } from "../view.js";
5
5
  export const needsRegistry = true;
6
6
  export const usage = () => commandUsage({
7
7
  command: 'uninstall',
@@ -25,7 +25,7 @@ export const usage = () => commandUsage({
25
25
  });
26
26
  export const views = {
27
27
  json: i => i.graph.toJSON(),
28
- human: InstallReporter,
28
+ human: lazyView(async () => (await import('./install/reporter.ts')).InstallReporter),
29
29
  };
30
30
  export const command = async (conf) => {
31
31
  const { monorepo, scurry } = conf.options;
@@ -1,5 +1,4 @@
1
1
  import type { CommandFn, CommandUsage } from '../index.ts';
2
- import { InstallReporter } from './install/reporter.ts';
3
2
  import type { InstallResult } from './install.ts';
4
3
  export declare const needsRegistry = true;
5
4
  export declare const usage: CommandUsage;
@@ -9,6 +8,6 @@ export declare const views: {
9
8
  buildQueue?: import("@vltpkg/dep-id").DepID[] | undefined;
10
9
  message?: string | undefined;
11
10
  };
12
- readonly human: typeof InstallReporter;
11
+ readonly human: import("../view.ts").LazyView<InstallResult>;
13
12
  };
14
13
  export declare const command: CommandFn<InstallResult>;
@@ -1,7 +1,7 @@
1
1
  import { update } from '@vltpkg/graph';
2
2
  import { error } from '@vltpkg/error-cause';
3
3
  import { commandUsage } from "../config/usage.js";
4
- import { InstallReporter } from "./install/reporter.js";
4
+ import { lazyView } from "../view.js";
5
5
  export const needsRegistry = true;
6
6
  export const usage = () => commandUsage({
7
7
  command: 'update',
@@ -25,7 +25,7 @@ export const views = {
25
25
  : null),
26
26
  graph: i.graph.toJSON(),
27
27
  }),
28
- human: InstallReporter,
28
+ human: lazyView(async () => (await import('./install/reporter.ts')).InstallReporter),
29
29
  };
30
30
  export const command = async (conf) => {
31
31
  // Throw error if any arguments are provided
package/dist/output.d.ts CHANGED
@@ -7,7 +7,7 @@ export declare const stderr: (...args: unknown[]) => void;
7
7
  type StyleTextFn = (format: Parameters<typeof utilStyleText>[0], s: string) => string;
8
8
  export declare let styleTextStdout: StyleTextFn;
9
9
  export declare let styleTextStderr: StyleTextFn;
10
- export declare const getView: <T>(conf: LoadedConfig, views?: Views<T>) => View<T>;
10
+ export declare const getView: <T>(conf: LoadedConfig, views?: Views<T>) => Promise<View<T>>;
11
11
  export type OnDone<T> = (result: T) => Promise<unknown>;
12
12
  /**
13
13
  * Main export. Run the command appropriately, displaying output using
package/dist/output.js CHANGED
@@ -3,7 +3,7 @@ import { createSupportsColor } from 'supports-color';
3
3
  import { defaultView } from "./config/definition.js";
4
4
  import { printErr, formatOptions } from "./print-err.js";
5
5
  import { hasConfiguredRegistry, missingRegistryError, } from "./require-registry.js";
6
- import { isViewClass } from "./view.js";
6
+ import { isLazyView, isViewClass, loadLazyView } from "./view.js";
7
7
  import { generateDefaultHelp, generateFullHelp, } from "./custom-help.js";
8
8
  import { flush as flushTelemetry, trackCommand, trackError, } from "./telemetry.js";
9
9
  import { startRequestLog } from "./verbose-log.js";
@@ -36,13 +36,20 @@ export let styleTextStdout = (_, s) => s;
36
36
  export let styleTextStderr = (_, s) => s;
37
37
  /* c8 ignore stop */
38
38
  const identity = (x) => x;
39
- export const getView = (conf, views) => {
40
- const viewName = conf.values.view;
41
- const viewFn = viewName === 'inspect' ? identity
42
- : viewName === 'silent' ? () => undefined
43
- : typeof views === 'function' ? views
44
- : views && typeof views === 'object' ? views[viewName]
45
- : identity;
39
+ const selectView = (viewName, views) => {
40
+ if (viewName === 'inspect')
41
+ return identity;
42
+ if (viewName === 'silent')
43
+ return () => undefined;
44
+ if (isLazyView(views) || typeof views === 'function') {
45
+ return views;
46
+ }
47
+ if (views)
48
+ return views[viewName];
49
+ return identity;
50
+ };
51
+ export const getView = async (conf, views) => {
52
+ const viewFn = selectView(conf.values.view, views);
46
53
  // if the user specified a view that doesn't exist, then set it back to the
47
54
  // default, and try again. This will fall back to identity if it's also
48
55
  // missing. We also always treat 'json' as a valid view that falls back to
@@ -56,14 +63,18 @@ export const getView = (conf, views) => {
56
63
  process.env.VLT_VIEW = defaultView;
57
64
  return getView(conf, views);
58
65
  }
59
- return viewFn ?? identity;
66
+ const resolved = viewFn ?? identity;
67
+ if (isLazyView(resolved)) {
68
+ return loadLazyView(resolved);
69
+ }
70
+ return resolved;
60
71
  };
61
72
  /**
62
73
  * If the view is a View class, then instantiate and start it.
63
74
  * If it's a view function, then just define the onDone method.
64
75
  */
65
- const startView = (conf, opts, views, { start } = { start: Date.now() }) => {
66
- const View = getView(conf, views);
76
+ const startView = async (conf, opts, views, { start } = { start: Date.now() }) => {
77
+ const View = await getView(conf, views);
67
78
  if (isViewClass(View)) {
68
79
  const view = new View(opts, conf);
69
80
  view.start();
@@ -116,7 +127,7 @@ export const outputCommand = async (cliCommand, conf, { start, vltVersion } = {
116
127
  // Stream per-request diagnostics to stderr when `--loglevel` is verbose
117
128
  // or higher (e.g. via `--verbose`). No-op otherwise.
118
129
  const stopRequestLog = startRequestLog(conf.values.loglevel, line => stderr(line), styleTextStderr);
119
- const { onDone, onError } = startView(conf,
130
+ const { onDone, onError } = await startView(conf,
120
131
  // assume views will always output to stdout so use color support from there
121
132
  { colors: stdoutColor }, views, { start });
122
133
  const telemetryEnabled = conf.values.telemetry;
package/dist/view.d.ts CHANGED
@@ -26,4 +26,12 @@ export declare class ViewClass<T = unknown> {
26
26
  export type ViewFn<T = unknown> = (result: T, options: ViewOptions, conf: LoadedConfig) => unknown;
27
27
  export type View<T = unknown> = ViewFn<T> | typeof ViewClass<T>;
28
28
  export declare const isViewClass: <T = unknown>(view: View<T>) => view is typeof ViewClass<T>;
29
- export type Views<T = unknown> = View<T> | Record<string, View<T>>;
29
+ declare const kLazyView: unique symbol;
30
+ export type LazyView<T = unknown> = {
31
+ readonly [kLazyView]: () => Promise<View<T>>;
32
+ };
33
+ export declare const lazyView: <T>(load: () => Promise<View<T>>) => LazyView<T>;
34
+ export declare const isLazyView: <T = unknown>(v: unknown) => v is LazyView<T>;
35
+ export declare const loadLazyView: <T>(v: LazyView<T>) => Promise<View<T>>;
36
+ export type Views<T = unknown> = View<T> | LazyView<T> | Record<string, View<T> | LazyView<T>>;
37
+ export {};
package/dist/view.js CHANGED
@@ -28,3 +28,7 @@ export class ViewClass {
28
28
  export const isViewClass = (view) => typeof view === 'function' &&
29
29
  'prototype' in view &&
30
30
  view.prototype instanceof ViewClass;
31
+ const kLazyView = Symbol.for('vlt.lazyView');
32
+ export const lazyView = (load) => ({ [kLazyView]: load });
33
+ export const isLazyView = (v) => !!v && typeof v === 'object' && kLazyView in v;
34
+ export const loadLazyView = (v) => v[kLazyView]();
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vltpkg/cli-sdk",
3
3
  "description": "The source for the vlt CLI",
4
- "version": "1.0.2",
4
+ "version": "1.0.3",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/vltpkg/vltpkg.git",
@@ -14,30 +14,30 @@
14
14
  },
15
15
  "dependencies": {
16
16
  "@resvg/resvg-wasm": "^2.6.2",
17
- "@vltpkg/config": "1.0.2",
18
- "@vltpkg/dep-id": "1.0.2",
19
- "@vltpkg/dot-prop": "1.0.2",
20
- "@vltpkg/error-cause": "1.0.2",
21
- "@vltpkg/git": "1.0.2",
22
- "@vltpkg/graph": "1.0.2",
23
- "@vltpkg/graph-run": "1.0.2",
24
- "@vltpkg/init": "1.0.2",
25
- "@vltpkg/output": "1.0.2",
26
- "@vltpkg/package-info": "1.0.2",
27
- "@vltpkg/package-json": "1.0.2",
28
- "@vltpkg/promise-spawn": "1.0.2",
29
- "@vltpkg/query": "1.0.2",
30
- "@vltpkg/registry-client": "1.0.2",
31
- "@vltpkg/rollback-remove": "1.0.2",
32
- "@vltpkg/run": "1.0.2",
33
- "@vltpkg/security-archive": "1.0.2",
34
- "@vltpkg/spec": "1.0.2",
35
- "@vltpkg/types": "1.0.2",
36
- "@vltpkg/url-open": "1.0.2",
37
- "@vltpkg/vlt-json": "1.0.2",
38
- "@vltpkg/vlx": "1.0.2",
39
- "@vltpkg/workspaces": "1.0.2",
40
- "@vltpkg/xdg": "1.0.2",
17
+ "@vltpkg/config": "1.0.3",
18
+ "@vltpkg/dep-id": "1.0.3",
19
+ "@vltpkg/dot-prop": "1.0.3",
20
+ "@vltpkg/error-cause": "1.0.3",
21
+ "@vltpkg/git": "1.0.3",
22
+ "@vltpkg/graph": "1.0.3",
23
+ "@vltpkg/graph-run": "1.0.3",
24
+ "@vltpkg/init": "1.0.3",
25
+ "@vltpkg/output": "1.0.3",
26
+ "@vltpkg/package-info": "1.0.3",
27
+ "@vltpkg/package-json": "1.0.3",
28
+ "@vltpkg/promise-spawn": "1.0.3",
29
+ "@vltpkg/query": "1.0.3",
30
+ "@vltpkg/registry-client": "1.0.3",
31
+ "@vltpkg/rollback-remove": "1.0.3",
32
+ "@vltpkg/run": "1.0.3",
33
+ "@vltpkg/security-archive": "1.0.3",
34
+ "@vltpkg/spec": "1.0.3",
35
+ "@vltpkg/types": "1.0.3",
36
+ "@vltpkg/url-open": "1.0.3",
37
+ "@vltpkg/vlt-json": "1.0.3",
38
+ "@vltpkg/vlx": "1.0.3",
39
+ "@vltpkg/workspaces": "1.0.3",
40
+ "@vltpkg/xdg": "1.0.3",
41
41
  "ansi-to-pre": "^1.0.6",
42
42
  "beautiful-mermaid": "^1.1.3",
43
43
  "chalk": "^5.6.2",