@vltpkg/cli-sdk 1.4.0 → 1.6.0

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 (74) hide show
  1. package/dist/allow-skills.d.ts +36 -0
  2. package/dist/allow-skills.js +49 -0
  3. package/dist/commands/build.d.ts +15 -4
  4. package/dist/commands/build.js +50 -12
  5. package/dist/commands/ci.d.ts +2 -2
  6. package/dist/commands/ci.js +10 -2
  7. package/dist/commands/create.d.ts +2 -1
  8. package/dist/commands/create.js +2 -3
  9. package/dist/commands/exec.d.ts +2 -1
  10. package/dist/commands/exec.js +2 -3
  11. package/dist/commands/init.js +4 -3
  12. package/dist/commands/install/reporter.d.ts +1 -1
  13. package/dist/commands/install/reporter.js +91 -5
  14. package/dist/commands/install.d.ts +50 -4
  15. package/dist/commands/install.js +107 -25
  16. package/dist/commands/list.js +8 -2
  17. package/dist/commands/publish.d.ts +0 -1
  18. package/dist/commands/publish.js +27 -16
  19. package/dist/commands/query.js +8 -2
  20. package/dist/commands/setup.d.ts +28 -2
  21. package/dist/commands/setup.js +185 -3
  22. package/dist/commands/skills.d.ts +56 -0
  23. package/dist/commands/skills.js +267 -0
  24. package/dist/commands/token.js +1 -1
  25. package/dist/commands/uninstall.d.ts +15 -4
  26. package/dist/commands/uninstall.js +32 -4
  27. package/dist/commands/unpublish.d.ts +0 -1
  28. package/dist/commands/unpublish.js +17 -4
  29. package/dist/commands/update.d.ts +13 -1
  30. package/dist/commands/update.js +18 -1
  31. package/dist/config/definition.d.ts +52 -0
  32. package/dist/config/definition.js +109 -1
  33. package/dist/config/index.d.ts +26 -3
  34. package/dist/config/index.js +149 -7
  35. package/dist/custom-help.js +4 -0
  36. package/dist/global-bin-dir.d.ts +37 -0
  37. package/dist/global-bin-dir.js +138 -0
  38. package/dist/global-project.d.ts +18 -0
  39. package/dist/global-project.js +67 -0
  40. package/dist/global-state.d.ts +24 -0
  41. package/dist/global-state.js +94 -0
  42. package/dist/global.d.ts +78 -0
  43. package/dist/global.js +409 -0
  44. package/dist/index.js +14 -3
  45. package/dist/install-receipt.d.ts +40 -0
  46. package/dist/install-receipt.js +69 -0
  47. package/dist/load-command.d.ts +2 -0
  48. package/dist/migrate-workspaces.d.ts +16 -0
  49. package/dist/migrate-workspaces.js +44 -0
  50. package/dist/output.js +13 -0
  51. package/dist/parse-add-remove-args.js +2 -14
  52. package/dist/print-err.js +4 -1
  53. package/dist/publish-config.d.ts +9 -0
  54. package/dist/publish-config.js +8 -0
  55. package/dist/query-auth.d.ts +3 -2
  56. package/dist/query-auth.js +6 -4
  57. package/dist/reload-config.js +2 -1
  58. package/dist/require-registry.d.ts +7 -0
  59. package/dist/require-registry.js +13 -1
  60. package/dist/self-update.d.ts +74 -0
  61. package/dist/self-update.js +401 -0
  62. package/dist/shell-setup/env.d.ts +9 -0
  63. package/dist/shell-setup/env.js +25 -0
  64. package/dist/shell-setup/index.d.ts +69 -0
  65. package/dist/shell-setup/index.js +213 -0
  66. package/dist/shell-setup/posix.d.ts +36 -0
  67. package/dist/shell-setup/posix.js +158 -0
  68. package/dist/shell-setup/windows.d.ts +39 -0
  69. package/dist/shell-setup/windows.js +151 -0
  70. package/dist/shell.d.ts +18 -0
  71. package/dist/shell.js +110 -0
  72. package/dist/skills-prompt.d.ts +28 -0
  73. package/dist/skills-prompt.js +78 -0
  74. package/package.json +30 -28
package/dist/index.js CHANGED
@@ -1,5 +1,7 @@
1
1
  import { format } from 'node:util';
2
2
  import { asRootError, findRootError } from '@vltpkg/output/error';
3
+ import { isError } from '@vltpkg/types';
4
+ import { setVltJsonOnly } from '@vltpkg/workspaces';
3
5
  import { loadPackageJson } from 'package-json-from-dist';
4
6
  import { getSortedCliOptions, getSortedKeys, } from "./config/definition.js";
5
7
  import { Config } from "./config/index.js";
@@ -14,7 +16,7 @@ const loadVlt = async (cwd, argv) => {
14
16
  catch (e) {
15
17
  const code = findRootError(e, { code: 'ECONFIG' }) ? 'ECONFIG' : 'JACKSPEAK';
16
18
  const err = asRootError(e, { code });
17
- const { found, path, wanted, name } = err.cause;
19
+ const { found, path, wanted, name, cause } = err.cause;
18
20
  const isConfigFile = typeof path === 'string';
19
21
  const msg = isConfigFile ? `Problem in Config File ${path}`
20
22
  : code === 'ECONFIG' ? 'Config Error'
@@ -31,6 +33,9 @@ const loadVlt = async (cwd, argv) => {
31
33
  }
32
34
  if (wanted)
33
35
  stderr(indent(`Wanted: ${format(wanted)}`));
36
+ // eg the global project can't be created
37
+ if (isError(cause))
38
+ stderr(indent(`Cause: ${cause.message}`));
34
39
  if (validOptions) {
35
40
  stderr(indent('Valid Options:'));
36
41
  stderr(indent(validOptions.join('\n'), 4));
@@ -49,9 +54,12 @@ const run = async () => {
49
54
  if (vlt.get('version')) {
50
55
  return stdout(version);
51
56
  }
57
+ // ci reads workspaces from vlt.json only; set before options load
58
+ setVltJsonOnly(vlt.command === 'ci');
52
59
  const { monorepo } = vlt.options;
53
60
  // Infer the workspace by being in that directory.
54
- if (vlt.get('workspace') === undefined) {
61
+ // Not for the global project, cwd is unrelated to it.
62
+ if (vlt.get('workspace') === undefined && !vlt.globalRoot) {
55
63
  const ws = monorepo?.get(cwd);
56
64
  if (ws) {
57
65
  vlt.values.workspace = [ws.path];
@@ -61,7 +69,10 @@ const run = async () => {
61
69
  if (vlt.command !== 'init' &&
62
70
  (vlt.get('workspace') || vlt.get('workspace-group')) &&
63
71
  ![...(monorepo?.values() ?? [])].length) {
64
- stderr(`Error: No matching workspaces found. Make sure the vlt.json config, the "workspaces" field of the root package.json, or the "packages" list of pnpm-workspace.yaml contains the correct workspaces.`);
72
+ const where = vlt.command === 'ci' ?
73
+ 'the vlt.json config (vlt ci ignores package.json and pnpm-workspace.yaml)'
74
+ : 'the vlt.json config, the "workspaces" field of the root package.json, or the "packages" list of pnpm-workspace.yaml';
75
+ stderr(`Error: No matching workspaces found. Make sure ${where} contains the correct workspaces.`);
65
76
  if (vlt.get('workspace')) {
66
77
  stderr(indent(`Workspace: ${format(vlt.get('workspace'))}`));
67
78
  }
@@ -0,0 +1,40 @@
1
+ export declare const receiptName = "install-receipt.json";
2
+ /**
3
+ * Written by the official installer, in vlt's config dir or next to
4
+ * (or one dir above) the `vlt` it installed. vlt only updates
5
+ * `version` and `installedAt`.
6
+ */
7
+ export type ReceiptData = {
8
+ receiptVersion: 1;
9
+ /** 'npm' | 'standalone', anything else is a newer installer */
10
+ method: string;
11
+ /** absolute dir holding the entry points */
12
+ binDir: string;
13
+ installer?: {
14
+ name?: string;
15
+ version?: string;
16
+ };
17
+ version?: string;
18
+ /** dist-tag or version asked for */
19
+ channel?: string;
20
+ /** `<os>-<arch>[-<libc>]` of a standalone build */
21
+ target?: string;
22
+ binaries?: string[];
23
+ /** rc files the installer edited */
24
+ modifiedPath?: string[];
25
+ installedAt?: string;
26
+ };
27
+ export type InstallReceipt = {
28
+ file: string;
29
+ data: ReceiptData;
30
+ };
31
+ /**
32
+ * The receipt covering the `vlt` found at `found`: valid, and its
33
+ * `binDir` is the dir of `found`.
34
+ */
35
+ export declare const readInstallReceipt: (found: string, configDir?: string) => Promise<InstallReceipt | undefined>;
36
+ /** set `version` and `installedAt`, keeping all other fields */
37
+ export declare const writeInstallReceipt: (file: string, update: {
38
+ version: string;
39
+ installedAt?: string;
40
+ }) => Promise<void>;
@@ -0,0 +1,69 @@
1
+ import { error } from '@vltpkg/error-cause';
2
+ import { isObject } from '@vltpkg/types';
3
+ import { XDG } from '@vltpkg/xdg';
4
+ import { readFile, realpath } from 'node:fs/promises';
5
+ import { dirname, isAbsolute, resolve } from 'node:path';
6
+ import { samePath } from "./global-project.js";
7
+ import { writeJsonAtomic } from "./global-state.js";
8
+ const xdg = new XDG('vlt');
9
+ export const receiptName = 'install-receipt.json';
10
+ const isStr = (v) => typeof v === 'string';
11
+ const optStr = (v) => v === undefined || isStr(v);
12
+ const optStrs = (v) => v === undefined || (Array.isArray(v) && v.every(isStr));
13
+ const isReceipt = (d) => isObject(d) &&
14
+ d.receiptVersion === 1 &&
15
+ isStr(d.method) &&
16
+ !!d.method &&
17
+ isStr(d.binDir) &&
18
+ isAbsolute(d.binDir) &&
19
+ (d.installer === undefined ||
20
+ (isObject(d.installer) &&
21
+ optStr(d.installer.name) &&
22
+ optStr(d.installer.version))) &&
23
+ optStr(d.version) &&
24
+ optStr(d.channel) &&
25
+ optStr(d.target) &&
26
+ optStrs(d.binaries) &&
27
+ optStrs(d.modifiedPath) &&
28
+ optStr(d.installedAt);
29
+ /**
30
+ * The receipt covering the `vlt` found at `found`: valid, and its
31
+ * `binDir` is the dir of `found`.
32
+ */
33
+ export const readInstallReceipt = async (found, configDir = xdg.config()) => {
34
+ const dir = dirname(found);
35
+ const real = await realpath(dir).catch(() => undefined);
36
+ if (!real)
37
+ return;
38
+ for (const file of [
39
+ resolve(configDir, receiptName),
40
+ resolve(dir, receiptName),
41
+ resolve(dir, '..', receiptName),
42
+ ]) {
43
+ try {
44
+ const data = JSON.parse(await readFile(file, 'utf8'));
45
+ if (isReceipt(data) &&
46
+ samePath(await realpath(data.binDir), real))
47
+ return { file, data };
48
+ }
49
+ catch { }
50
+ }
51
+ };
52
+ /** set `version` and `installedAt`, keeping all other fields */
53
+ export const writeInstallReceipt = async (file, update) => {
54
+ let raw;
55
+ try {
56
+ raw = JSON.parse(await readFile(file, 'utf8'));
57
+ }
58
+ catch (cause) {
59
+ throw error('Invalid install receipt', { path: file, cause });
60
+ }
61
+ if (!isReceipt(raw)) {
62
+ throw error('Invalid install receipt', { path: file });
63
+ }
64
+ await writeJsonAtomic(file, {
65
+ ...raw,
66
+ version: update.version,
67
+ installedAt: update.installedAt ?? new Date().toISOString(),
68
+ });
69
+ };
@@ -15,6 +15,8 @@ export type Command<T> = {
15
15
  * Set to `true` by commands that hit a registry or resolve registry
16
16
  * specs. There is no default registry, so `outputCommand()` fails
17
17
  * early with an `ECONFIG` error when one of these runs unconfigured.
18
+ * `publish`/`unpublish` check in-command instead, since
19
+ * `publishConfig.registry` may suffice.
18
20
  */
19
21
  needsRegistry?: boolean;
20
22
  /**
@@ -0,0 +1,16 @@
1
+ import type { WorkspaceConfigSource } from '@vltpkg/workspaces';
2
+ import type { LoadedConfig } from './config/index.ts';
3
+ export type MigratedWorkspaces = {
4
+ source: WorkspaceConfigSource;
5
+ workspaces: string[];
6
+ };
7
+ /**
8
+ * Save workspaces read from `package.json` or `pnpm-workspace.yaml` to
9
+ * the project `vlt.json`, unless `--no-migrate-workspaces`.
10
+ */
11
+ export declare const migrateWorkspaces: (conf: LoadedConfig) => MigratedWorkspaces | undefined;
12
+ /**
13
+ * Warn when workspaces are declared only outside `vlt.json`, which
14
+ * `vlt ci` ignores.
15
+ */
16
+ export declare const warnIgnoredWorkspaces: (conf: LoadedConfig) => void;
@@ -0,0 +1,44 @@
1
+ import { save } from '@vltpkg/vlt-json';
2
+ import { migratableWSConfig, resolveWSConfig, } from '@vltpkg/workspaces';
3
+ import { stderr } from "./output.js";
4
+ // workspaces declared outside vlt.json, if any
5
+ const found = (conf) => {
6
+ const resolved = resolveWSConfig(conf.options.projectRoot, conf.options.packageJson, false);
7
+ const workspaces = migratableWSConfig(resolved);
8
+ const { source } = resolved;
9
+ if (!workspaces?.length || !source)
10
+ return;
11
+ return { source, workspaces };
12
+ };
13
+ /**
14
+ * Save workspaces read from `package.json` or `pnpm-workspace.yaml` to
15
+ * the project `vlt.json`, unless `--no-migrate-workspaces`.
16
+ */
17
+ export const migrateWorkspaces = (conf) => {
18
+ if (!conf.options['migrate-workspaces'])
19
+ return;
20
+ const migrated = found(conf);
21
+ if (migrated)
22
+ save('workspaces', migrated.workspaces);
23
+ return migrated;
24
+ };
25
+ /**
26
+ * Warn when workspaces are declared only outside `vlt.json`, which
27
+ * `vlt ci` ignores.
28
+ */
29
+ export const warnIgnoredWorkspaces = (conf) => {
30
+ const { loglevel } = conf.values;
31
+ if (loglevel === 'silent' || loglevel === 'error')
32
+ return;
33
+ let migrated;
34
+ try {
35
+ migrated = found(conf);
36
+ }
37
+ catch {
38
+ // invalid workspaces config: nothing to suggest
39
+ return;
40
+ }
41
+ if (!migrated)
42
+ return;
43
+ stderr(`Warning: vlt ci reads workspaces from vlt.json only; ignoring ${migrated.source}, its workspaces are not installed. Run \`vlt install\` to save them to vlt.json, or add them there.`);
44
+ };
package/dist/output.js CHANGED
@@ -1,6 +1,9 @@
1
+ import { error } from '@vltpkg/error-cause';
1
2
  import { formatWithOptions, styleText as utilStyleText, } from 'node:util';
2
3
  import { createSupportsColor } from 'supports-color';
3
4
  import { defaultView } from "./config/definition.js";
5
+ import { globalCommands } from "./global-project.js";
6
+ import { sweepPendingRemove } from "./global-state.js";
4
7
  import { printErr, formatOptions } from "./print-err.js";
5
8
  import { hasConfiguredRegistry, hasNpmRegistry, missingNpmRegistryError, missingRegistryError, } from "./require-registry.js";
6
9
  import { isLazyView, isViewClass, loadLazyView } from "./view.js";
@@ -158,6 +161,14 @@ export const outputCommand = async (cliCommand, conf, { start, vltVersion } = {
158
161
  const telemetryEnabled = conf.values.telemetry;
159
162
  const commandName = conf.command;
160
163
  try {
164
+ // explicit only: `global` in the user config is ignored here
165
+ if (conf.explicit.global && !conf.globalRoot) {
166
+ throw error(`\`vlt ${conf.command}\` does not support --global`, {
167
+ code: 'EUSAGE',
168
+ found: conf.command,
169
+ validOptions: [...globalCommands],
170
+ });
171
+ }
161
172
  // checked here rather than in run() so that the missing-registry
162
173
  // error is rendered, tracked and exited like any other command
163
174
  // error, and so that the `--help` return above still works when
@@ -168,6 +179,8 @@ export const outputCommand = async (cliCommand, conf, { start, vltVersion } = {
168
179
  if (needsNpmRegistry && !hasNpmRegistry(conf)) {
169
180
  throw missingNpmRegistryError(conf.options['default-registry-alias']);
170
181
  }
182
+ if (conf.globalRoot)
183
+ await sweepPendingRemove(conf.globalRoot);
171
184
  const output = await onDone(await command(conf));
172
185
  stopRequestLog();
173
186
  const duration_ms = Date.now() - start;
@@ -2,7 +2,7 @@ import { addKey, asDependency } from '@vltpkg/graph';
2
2
  import { joinDepIDTuple, splitDepID } from '@vltpkg/dep-id';
3
3
  import { Spec } from '@vltpkg/spec';
4
4
  import { isAbsolute, relative, resolve } from 'node:path';
5
- import { asUnknownSpecPrefix } from "./require-registry.js";
5
+ import { parseSpecArg } from "./require-registry.js";
6
6
  const rootDepID = joinDepIDTuple(['file', '.']);
7
7
  /**
8
8
  * Compute a DepID for the current working directory relative to the project
@@ -77,18 +77,6 @@ const rebaseFileSpec = (spec, importerPath, scurryCwd, specOptions, monorepo) =>
77
77
  return spec;
78
78
  return Spec.parseArgs(rebasedPath, specOptions);
79
79
  };
80
- /**
81
- * Parse a positional arg, turning an unknown `name:` prefix into an
82
- * `ECONFIG` that says how to define it.
83
- */
84
- const parseArg = (item, options) => {
85
- try {
86
- return Spec.parseArgs(item, options);
87
- }
88
- catch (er) {
89
- throw asUnknownSpecPrefix(er);
90
- }
91
- };
92
80
  /**
93
81
  * Parses the positional arguments into {@link AddImportersDependenciesMap}.
94
82
  */
@@ -103,7 +91,7 @@ export const parseAddArgs = (config, scurry, monorepo) => {
103
91
  const parsedItems = [];
104
92
  let hasFileSpecs = false;
105
93
  for (const item of items) {
106
- const spec = parseArg(item, specOptions);
94
+ const spec = parseSpecArg(item, specOptions);
107
95
  parsedItems.push({ spec, type });
108
96
  if (spec.type === 'file')
109
97
  hasFileSpecs = true;
package/dist/print-err.js CHANGED
@@ -223,8 +223,11 @@ const printCode = (err, usage, stderr, format) => {
223
223
  return {};
224
224
  }
225
225
  case 'ECONFIG': {
226
- const { found, wanted, validOptions } = err.cause;
226
+ const { found, wanted, validOptions, from } = err.cause;
227
227
  stderr(`Config Error: ${err.message}`);
228
+ if (from) {
229
+ stderr(indent(`From: ${format(from)}`));
230
+ }
228
231
  if (found) {
229
232
  stderr(indent(`Found: ${format(found)}`));
230
233
  }
@@ -0,0 +1,9 @@
1
+ import type { NormalizedManifest } from '@vltpkg/types';
2
+ type PublishConfig = {
3
+ directory?: string;
4
+ registry?: string;
5
+ access?: string;
6
+ tag?: string;
7
+ };
8
+ export declare const getPublishConfig: (manifest: NormalizedManifest) => PublishConfig | undefined;
9
+ export {};
@@ -0,0 +1,8 @@
1
+ export const getPublishConfig = (manifest) => {
2
+ const pc = manifest
3
+ .publishConfig;
4
+ if (pc && typeof pc === 'object') {
5
+ return pc;
6
+ }
7
+ return undefined;
8
+ };
@@ -3,7 +3,8 @@ import type { LoadedConfig } from './config/index.ts';
3
3
  /**
4
4
  * Returns a {@link GetAuthHeader} implementation that looks up
5
5
  * authorization tokens from the local keychain / env (incl.
6
- * `VLT_TOKEN_<key>` for configured registries), used by
7
- * network-reliant query selectors, e.g: `:outdated()`.
6
+ * `VLT_TOKEN` for the default registry and `VLT_TOKEN_<key>` for
7
+ * configured registries), used by network-reliant query selectors,
8
+ * e.g: `:outdated()`.
8
9
  */
9
10
  export declare const createGetAuthHeader: (conf: LoadedConfig) => GetAuthHeader;
@@ -1,11 +1,13 @@
1
- import { getTokenByURL, registryKeys } from '@vltpkg/registry-client';
1
+ import { defaultRegistryKey, getTokenByURL, registryKeys, } from '@vltpkg/registry-client';
2
2
  /**
3
3
  * Returns a {@link GetAuthHeader} implementation that looks up
4
4
  * authorization tokens from the local keychain / env (incl.
5
- * `VLT_TOKEN_<key>` for configured registries), used by
6
- * network-reliant query selectors, e.g: `:outdated()`.
5
+ * `VLT_TOKEN` for the default registry and `VLT_TOKEN_<key>` for
6
+ * configured registries), used by network-reliant query selectors,
7
+ * e.g: `:outdated()`.
7
8
  */
8
9
  export const createGetAuthHeader = (conf) => {
9
10
  const keys = registryKeys(conf.options);
10
- return async (url) => getTokenByURL(url, conf.options.identity, keys);
11
+ const def = defaultRegistryKey(conf.options);
12
+ return async (url) => getTokenByURL(url, conf.options.identity, keys, def);
11
13
  };
@@ -7,5 +7,6 @@ export const reloadConfig = async (folder) => {
7
7
  }
8
8
  catch { }
9
9
  const { Config } = await import("./config/index.js");
10
- return Config.load(folder, process.argv, true);
10
+ // host contexts never switch to the global project
11
+ return Config.load(folder, process.argv, true, false);
11
12
  };
@@ -1,3 +1,5 @@
1
+ import { Spec } from '@vltpkg/spec';
2
+ import type { SpecOptions } from '@vltpkg/spec';
1
3
  import type { RegistryCandidate } from './select-registry.ts';
2
4
  import type { LoadedConfig } from './config/index.ts';
3
5
  /**
@@ -17,6 +19,11 @@ export declare const unknownSpecPrefixError: (prefix: string, spec: string, vali
17
19
  * {@link unknownSpecPrefixError}. Other values are returned as is.
18
20
  */
19
21
  export declare const asUnknownSpecPrefix: (er: unknown) => unknown;
22
+ /**
23
+ * Parse a positional arg, turning an unknown `name:` prefix into an
24
+ * `ECONFIG` that says how to define it.
25
+ */
26
+ export declare const parseSpecArg: (item: string, options: SpecOptions) => Spec;
20
27
  /**
21
28
  * Install-related commands need the alias that bare specs resolve
22
29
  * through (not merely some other configured registry) so packages and
@@ -1,6 +1,6 @@
1
1
  import { error } from '@vltpkg/error-cause';
2
2
  import { isErrorWithCause, isObject } from '@vltpkg/types';
3
- import { defaultRegistries, defaultRegistryName } from '@vltpkg/spec';
3
+ import { defaultRegistries, defaultRegistryName, Spec, } from '@vltpkg/spec';
4
4
  import { selectRegistry } from "./select-registry.js";
5
5
  /**
6
6
  * There is no default registry. This is the single message used
@@ -41,6 +41,18 @@ export const asUnknownSpecPrefix = (er) => {
41
41
  unknownSpecPrefixError(found.slice(0, -1), spec, validOptions)
42
42
  : er;
43
43
  };
44
+ /**
45
+ * Parse a positional arg, turning an unknown `name:` prefix into an
46
+ * `ECONFIG` that says how to define it.
47
+ */
48
+ export const parseSpecArg = (item, options) => {
49
+ try {
50
+ return Spec.parseArgs(item, options);
51
+ }
52
+ catch (er) {
53
+ throw asUnknownSpecPrefix(er);
54
+ }
55
+ };
44
56
  /**
45
57
  * Install-related commands need the alias that bare specs resolve
46
58
  * through (not merely some other configured registry) so packages and
@@ -0,0 +1,74 @@
1
+ import type { DepID } from '@vltpkg/dep-id';
2
+ import type { Graph } from '@vltpkg/graph';
3
+ import type { LoadedConfig } from './config/index.ts';
4
+ import type { GlobalBins } from './global.ts';
5
+ export type SelfUpdateCase = 'standalone' | 'npm' | 'global-project' | 'bootstrap';
6
+ /** `vlt install -g vlt` that ran, or had nothing to do */
7
+ export type SelfUpdated = {
8
+ case: SelfUpdateCase;
9
+ status: 'updated' | 'up-to-date' | 'newer-running' | 'failed';
10
+ /** running version */
11
+ from: string;
12
+ /** resolved version */
13
+ to: string;
14
+ /** dir of the updated vlt */
15
+ dir: string;
16
+ /** newer-running: dist-tag of the implicit spec */
17
+ tag?: string;
18
+ /** bootstrap: the dir that is not writable */
19
+ notWritable?: string;
20
+ /** bootstrap: PATH dir whose vlt still runs first */
21
+ shadowedBy?: string;
22
+ };
23
+ /** vlt can't update this vlt, `message` says how to */
24
+ export type SelfRefused = {
25
+ status: 'refused';
26
+ /** running version */
27
+ from: string;
28
+ /** dir of the running vlt */
29
+ dir: string;
30
+ message: string;
31
+ };
32
+ /** result of `vlt install -g vlt` */
33
+ export type SelfUpdate = SelfUpdated | SelfRefused;
34
+ export type SelfUpdatePlan = {
35
+ done: SelfUpdate;
36
+ }
37
+ /** caller runs the -g install, then `finish` */
38
+ | {
39
+ selfUnwritable: boolean;
40
+ finish: (global?: GlobalBins) => Promise<SelfUpdated>;
41
+ };
42
+ /** `checksum` of the file written to `dest`, `sha512-<base64>` */
43
+ export type Release = {
44
+ checksum: string;
45
+ };
46
+ /** download one standalone entry point to `dest` */
47
+ export type FetchRelease = (o: {
48
+ version: string;
49
+ target: string;
50
+ channel?: string;
51
+ bin: string;
52
+ dest: string;
53
+ }) => Promise<Release>;
54
+ /** `vlt install -g vlt...`, for the human view */
55
+ export declare const isSelfUpdateArgs: (conf: Pick<LoadedConfig, "command" | "globalRoot" | "positionals">) => boolean;
56
+ /**
57
+ * `vlt install -g vlt`: update the vlt on the PATH the way it was
58
+ * installed. Undefined when vlt is not a positional.
59
+ */
60
+ export declare const selfUpdate: (conf: LoadedConfig, { fetchRelease }?: {
61
+ fetchRelease?: FetchRelease;
62
+ }) => Promise<SelfUpdatePlan | undefined>;
63
+ /** `vlt uninstall -g vlt` of a vlt that is not a global package */
64
+ export declare const refuseSelfUninstall: (conf: LoadedConfig) => Promise<SelfRefused | undefined>;
65
+ /** store id of the running vlt, when it runs from the global project */
66
+ export declare const runningStoreDep: (root: string) => Promise<DepID | undefined>;
67
+ /**
68
+ * Record the running vlt's store dir for removal by a later -g
69
+ * command when the graph no longer has it, and forget listed dirs
70
+ * the graph has again.
71
+ */
72
+ export declare const deferSelfRemove: (root: string, graph: Pick<Graph, "nodes">, keep?: DepID) => Promise<void>;
73
+ /** human lines for a self-update */
74
+ export declare const selfUpdateLines: (s: SelfUpdate) => string[];