@vltpkg/cli-sdk 1.5.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 (55) hide show
  1. package/dist/commands/build.d.ts +8 -3
  2. package/dist/commands/build.js +31 -3
  3. package/dist/commands/ci.d.ts +1 -1
  4. package/dist/commands/create.d.ts +2 -1
  5. package/dist/commands/create.js +2 -3
  6. package/dist/commands/exec.d.ts +2 -1
  7. package/dist/commands/exec.js +2 -3
  8. package/dist/commands/install/reporter.d.ts +1 -1
  9. package/dist/commands/install/reporter.js +45 -5
  10. package/dist/commands/install.d.ts +21 -3
  11. package/dist/commands/install.js +84 -30
  12. package/dist/commands/list.js +5 -1
  13. package/dist/commands/query.js +5 -1
  14. package/dist/commands/setup.d.ts +28 -2
  15. package/dist/commands/setup.js +185 -3
  16. package/dist/commands/skills.js +2 -3
  17. package/dist/commands/token.js +1 -1
  18. package/dist/commands/uninstall.d.ts +10 -3
  19. package/dist/commands/uninstall.js +28 -2
  20. package/dist/commands/update.d.ts +1 -1
  21. package/dist/config/definition.d.ts +32 -0
  22. package/dist/config/definition.js +60 -0
  23. package/dist/config/index.d.ts +26 -3
  24. package/dist/config/index.js +149 -7
  25. package/dist/global-bin-dir.d.ts +37 -0
  26. package/dist/global-bin-dir.js +138 -0
  27. package/dist/global-project.d.ts +18 -0
  28. package/dist/global-project.js +67 -0
  29. package/dist/global-state.d.ts +24 -0
  30. package/dist/global-state.js +94 -0
  31. package/dist/global.d.ts +78 -0
  32. package/dist/global.js +409 -0
  33. package/dist/index.js +7 -2
  34. package/dist/install-receipt.d.ts +40 -0
  35. package/dist/install-receipt.js +69 -0
  36. package/dist/output.js +13 -0
  37. package/dist/parse-add-remove-args.js +2 -14
  38. package/dist/query-auth.d.ts +3 -2
  39. package/dist/query-auth.js +6 -4
  40. package/dist/reload-config.js +2 -1
  41. package/dist/require-registry.d.ts +7 -0
  42. package/dist/require-registry.js +13 -1
  43. package/dist/self-update.d.ts +74 -0
  44. package/dist/self-update.js +401 -0
  45. package/dist/shell-setup/env.d.ts +9 -0
  46. package/dist/shell-setup/env.js +25 -0
  47. package/dist/shell-setup/index.d.ts +69 -0
  48. package/dist/shell-setup/index.js +213 -0
  49. package/dist/shell-setup/posix.d.ts +36 -0
  50. package/dist/shell-setup/posix.js +158 -0
  51. package/dist/shell-setup/windows.d.ts +39 -0
  52. package/dist/shell-setup/windows.js +151 -0
  53. package/dist/shell.d.ts +18 -0
  54. package/dist/shell.js +110 -0
  55. package/package.json +30 -28
package/dist/shell.js ADDED
@@ -0,0 +1,110 @@
1
+ import { existsSync } from 'node:fs';
2
+ import { homedir } from 'node:os';
3
+ const shells = new Map([
4
+ ['bash', 'bash'],
5
+ ['zsh', 'zsh'],
6
+ ['fish', 'fish'],
7
+ ['nu', 'nu'],
8
+ ['pwsh', 'pwsh'],
9
+ ['powershell', 'pwsh'],
10
+ ['sh', 'sh'],
11
+ ['dash', 'sh'],
12
+ ['ksh', 'sh'],
13
+ ['mksh', 'sh'],
14
+ ['ash', 'sh'],
15
+ ]);
16
+ const isSep = (c, win32) => c === '/' || (win32 && c === '\\');
17
+ // rest of `path` after `home`: '' for home itself, undefined outside
18
+ const homeRest = (path, home, win32) => !home ? undefined
19
+ : path === home ? ''
20
+ : path.startsWith(home) && isSep(path[home.length], win32) ?
21
+ path.slice(home.length)
22
+ : undefined;
23
+ /** `~/x` for a path under the home dir */
24
+ export const prettyPath = (path, home = homedir(), win32 = process.platform === 'win32') => {
25
+ const rest = homeRest(path, home, win32);
26
+ return rest === undefined ? path : `~${rest}`;
27
+ };
28
+ /** the user's shell, from `SHELL`, or a guess on win32 */
29
+ export const detectShell = (env = process.env, platform = process.platform) => {
30
+ const { SHELL } = env;
31
+ if (SHELL) {
32
+ const name = SHELL.replace(/^.*[\\/]/, '')
33
+ .replace(/\.exe$/i, '')
34
+ .toLowerCase();
35
+ return shells.get(name) ?? 'unknown';
36
+ }
37
+ if (platform !== 'win32')
38
+ return 'unknown';
39
+ // set machine-wide, PowerShell adds the user module dir
40
+ const mods = (env.PSModulePath ?? '').split(';').filter(Boolean);
41
+ return mods.length >= 3 ? 'pwsh' : 'cmd';
42
+ };
43
+ const opts = ({ env = process.env, platform = process.platform, home = homedir(), }) => ({
44
+ env,
45
+ platform,
46
+ home,
47
+ win32: platform === 'win32',
48
+ });
49
+ const escape = (s, chars, esc = '\\') => s.replace(chars, c => esc + c);
50
+ // `$HOME/x`, or the path, `/c/x` style on win32
51
+ const posixInner = (dir, o, chars) => {
52
+ const { home, win32 } = opts(o);
53
+ const slash = (p) => (win32 ? p.replace(/\\/g, '/') : p);
54
+ const rest = homeRest(dir, home, win32);
55
+ if (rest !== undefined)
56
+ return '$HOME' + escape(slash(rest), chars);
57
+ const p = win32 ?
58
+ slash(dir).replace(/^([a-z]):/i, (_, d) => `/${d.toLowerCase()}`)
59
+ : dir;
60
+ return escape(p, chars);
61
+ };
62
+ const shChars = /[\\"$`]/g;
63
+ /** `dir` double-quoted for a POSIX shell, `$HOME` late-bound */
64
+ export const posixPath = (dir, o = {}) => `"${posixInner(dir, o, shChars)}"`;
65
+ /** `dir` double-quoted for fish, `$HOME` late-bound */
66
+ export const fishPath = (dir, o = {}) => `"${posixInner(dir, o, /[\\"$]/g)}"`;
67
+ /** the line that adds `dir` to the `PATH` in `shell` */
68
+ export const shellPathCommand = (shell, dir, o = {}) => {
69
+ const { home, win32 } = opts(o);
70
+ const rest = homeRest(dir, home, win32);
71
+ switch (shell) {
72
+ case 'fish':
73
+ return `fish_add_path ${fishPath(dir, o)}`;
74
+ case 'nu':
75
+ return `$env.PATH = ($env.PATH | prepend "${escape(dir, /[\\"]/g)}")`;
76
+ case 'pwsh': {
77
+ const p = rest === undefined ?
78
+ escape(dir, /[`"$]/g, '`')
79
+ : '$HOME' + escape(rest, /[`"$]/g, '`');
80
+ return `$env:PATH += "${win32 ? ';' : ':'}${p}"`;
81
+ }
82
+ case 'cmd':
83
+ return `set "PATH=%PATH%;${rest === undefined ? dir : '%USERPROFILE%' + rest}"`;
84
+ default:
85
+ return `export PATH="${posixInner(dir, o, shChars)}:$PATH"`;
86
+ }
87
+ };
88
+ /** rc file to add the `PATH` line to, for display */
89
+ export const shellRcFile = (shell, o = {}) => {
90
+ const { env, platform, home, win32 } = opts(o);
91
+ switch (shell) {
92
+ case 'zsh':
93
+ return prettyPath(`${env.ZDOTDIR || home}/.zshrc`, home, win32);
94
+ case 'bash': {
95
+ const has = (f) => existsSync(`${home}/${f}`);
96
+ // like `vlt setup --path`: never a new .bashrc
97
+ if (platform !== 'darwin' && has('.bashrc'))
98
+ return '~/.bashrc';
99
+ // a new .bash_profile would shadow .profile
100
+ const f = ['.bash_profile', '.bash_login'].find(has);
101
+ return `~/${f ?? '.profile'}`;
102
+ }
103
+ case 'sh':
104
+ return env.ENV ? prettyPath(env.ENV, home, win32) : '~/.profile';
105
+ case 'pwsh':
106
+ return '$PROFILE';
107
+ default:
108
+ return undefined;
109
+ }
110
+ };
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.5.0",
4
+ "version": "1.6.0",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/vltpkg/vltpkg.git",
@@ -14,33 +14,35 @@
14
14
  },
15
15
  "dependencies": {
16
16
  "@resvg/resvg-wasm": "^2.6.2",
17
- "@vltpkg/config": "1.5.0",
18
- "@vltpkg/dep-id": "1.5.0",
19
- "@vltpkg/dot-prop": "1.5.0",
20
- "@vltpkg/error-cause": "1.5.0",
21
- "@vltpkg/git": "1.5.0",
22
- "@vltpkg/graph": "1.5.0",
23
- "@vltpkg/graph-run": "1.5.0",
24
- "@vltpkg/init": "1.5.0",
25
- "@vltpkg/output": "1.5.0",
26
- "@vltpkg/package-info": "1.5.0",
27
- "@vltpkg/package-json": "1.5.0",
28
- "@vltpkg/pick-manifest": "1.5.0",
29
- "@vltpkg/promise-spawn": "1.5.0",
30
- "@vltpkg/query": "1.5.0",
31
- "@vltpkg/registry-client": "1.5.0",
32
- "@vltpkg/rollback-remove": "1.5.0",
33
- "@vltpkg/run": "1.5.0",
34
- "@vltpkg/security-archive": "1.5.0",
35
- "@vltpkg/semver": "1.5.0",
36
- "@vltpkg/spec": "1.5.0",
37
- "@vltpkg/tar": "1.5.0",
38
- "@vltpkg/types": "1.5.0",
39
- "@vltpkg/url-open": "1.5.0",
40
- "@vltpkg/vlt-json": "1.5.0",
41
- "@vltpkg/vlx": "1.5.0",
42
- "@vltpkg/workspaces": "1.5.0",
43
- "@vltpkg/xdg": "1.5.0",
17
+ "@vltpkg/cmd-shim": "1.6.0",
18
+ "@vltpkg/config": "1.6.0",
19
+ "@vltpkg/dep-id": "1.6.0",
20
+ "@vltpkg/dot-prop": "1.6.0",
21
+ "@vltpkg/error-cause": "1.6.0",
22
+ "@vltpkg/git": "1.6.0",
23
+ "@vltpkg/graph": "1.6.0",
24
+ "@vltpkg/graph-run": "1.6.0",
25
+ "@vltpkg/init": "1.6.0",
26
+ "@vltpkg/output": "1.6.0",
27
+ "@vltpkg/package-info": "1.6.0",
28
+ "@vltpkg/package-json": "1.6.0",
29
+ "@vltpkg/pick-manifest": "1.6.0",
30
+ "@vltpkg/promise-spawn": "1.6.0",
31
+ "@vltpkg/query": "1.6.0",
32
+ "@vltpkg/registry-client": "1.6.0",
33
+ "@vltpkg/rollback-remove": "1.6.0",
34
+ "@vltpkg/run": "1.6.0",
35
+ "@vltpkg/security-archive": "1.6.0",
36
+ "@vltpkg/semver": "1.6.0",
37
+ "@vltpkg/spec": "1.6.0",
38
+ "@vltpkg/tar": "1.6.0",
39
+ "@vltpkg/types": "1.6.0",
40
+ "@vltpkg/url-open": "1.6.0",
41
+ "@vltpkg/vlt-json": "1.6.0",
42
+ "@vltpkg/vlx": "1.6.0",
43
+ "@vltpkg/which": "1.6.0",
44
+ "@vltpkg/workspaces": "1.6.0",
45
+ "@vltpkg/xdg": "1.6.0",
44
46
  "ansi-to-pre": "^1.0.6",
45
47
  "beautiful-mermaid": "^1.1.3",
46
48
  "chalk": "^5.6.2",