@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.
Files changed (149) hide show
  1. package/dist/esm/commands/build.d.ts +25 -0
  2. package/dist/esm/commands/build.d.ts.map +1 -0
  3. package/dist/esm/commands/build.js +102 -0
  4. package/dist/esm/commands/build.js.map +1 -0
  5. package/dist/esm/commands/cache.d.ts +18 -0
  6. package/dist/esm/commands/cache.d.ts.map +1 -1
  7. package/dist/esm/commands/cache.js +48 -2
  8. package/dist/esm/commands/cache.js.map +1 -1
  9. package/dist/esm/commands/ci.d.ts +11 -0
  10. package/dist/esm/commands/ci.d.ts.map +1 -0
  11. package/dist/esm/commands/ci.js +32 -0
  12. package/dist/esm/commands/ci.js.map +1 -0
  13. package/dist/esm/commands/config.d.ts +3 -2
  14. package/dist/esm/commands/config.d.ts.map +1 -1
  15. package/dist/esm/commands/config.js +372 -101
  16. package/dist/esm/commands/config.js.map +1 -1
  17. package/dist/esm/commands/docs.d.ts +18 -0
  18. package/dist/esm/commands/docs.d.ts.map +1 -0
  19. package/dist/esm/commands/docs.js +154 -0
  20. package/dist/esm/commands/docs.js.map +1 -0
  21. package/dist/esm/commands/exec-cache.d.ts +49 -0
  22. package/dist/esm/commands/exec-cache.d.ts.map +1 -0
  23. package/dist/esm/commands/exec-cache.js +146 -0
  24. package/dist/esm/commands/exec-cache.js.map +1 -0
  25. package/dist/esm/commands/exec-local.d.ts +1 -0
  26. package/dist/esm/commands/exec-local.d.ts.map +1 -1
  27. package/dist/esm/commands/exec-local.js +2 -0
  28. package/dist/esm/commands/exec-local.js.map +1 -1
  29. package/dist/esm/commands/exec.d.ts +6 -1
  30. package/dist/esm/commands/exec.d.ts.map +1 -1
  31. package/dist/esm/commands/exec.js +79 -5
  32. package/dist/esm/commands/exec.js.map +1 -1
  33. package/dist/esm/commands/help.d.ts +1 -1
  34. package/dist/esm/commands/help.d.ts.map +1 -1
  35. package/dist/esm/commands/help.js +32 -3
  36. package/dist/esm/commands/help.js.map +1 -1
  37. package/dist/esm/commands/init.d.ts +3 -3
  38. package/dist/esm/commands/init.d.ts.map +1 -1
  39. package/dist/esm/commands/init.js +95 -9
  40. package/dist/esm/commands/init.js.map +1 -1
  41. package/dist/esm/commands/install/reporter.d.ts +3 -2
  42. package/dist/esm/commands/install/reporter.d.ts.map +1 -1
  43. package/dist/esm/commands/install/reporter.js +42 -15
  44. package/dist/esm/commands/install/reporter.js.map +1 -1
  45. package/dist/esm/commands/install.d.ts +21 -3
  46. package/dist/esm/commands/install.d.ts.map +1 -1
  47. package/dist/esm/commands/install.js +27 -3
  48. package/dist/esm/commands/install.js.map +1 -1
  49. package/dist/esm/commands/list.d.ts +2 -2
  50. package/dist/esm/commands/list.d.ts.map +1 -1
  51. package/dist/esm/commands/list.js +149 -49
  52. package/dist/esm/commands/list.js.map +1 -1
  53. package/dist/esm/commands/pack.d.ts +32 -0
  54. package/dist/esm/commands/pack.d.ts.map +1 -0
  55. package/dist/esm/commands/pack.js +147 -0
  56. package/dist/esm/commands/pack.js.map +1 -0
  57. package/dist/esm/commands/pkg.d.ts +1 -2
  58. package/dist/esm/commands/pkg.d.ts.map +1 -1
  59. package/dist/esm/commands/pkg.js +123 -38
  60. package/dist/esm/commands/pkg.js.map +1 -1
  61. package/dist/esm/commands/publish.d.ts +22 -0
  62. package/dist/esm/commands/publish.d.ts.map +1 -0
  63. package/dist/esm/commands/publish.js +245 -0
  64. package/dist/esm/commands/publish.js.map +1 -0
  65. package/dist/esm/commands/query.d.ts +2 -3
  66. package/dist/esm/commands/query.d.ts.map +1 -1
  67. package/dist/esm/commands/query.js +132 -38
  68. package/dist/esm/commands/query.js.map +1 -1
  69. package/dist/esm/commands/run-exec.d.ts +1 -0
  70. package/dist/esm/commands/run-exec.d.ts.map +1 -1
  71. package/dist/esm/commands/run-exec.js +1 -0
  72. package/dist/esm/commands/run-exec.js.map +1 -1
  73. package/dist/esm/commands/run.d.ts +1 -0
  74. package/dist/esm/commands/run.d.ts.map +1 -1
  75. package/dist/esm/commands/run.js +13 -16
  76. package/dist/esm/commands/run.js.map +1 -1
  77. package/dist/esm/commands/serve.d.ts +14 -0
  78. package/dist/esm/commands/serve.d.ts.map +1 -0
  79. package/dist/esm/commands/serve.js +103 -0
  80. package/dist/esm/commands/serve.js.map +1 -0
  81. package/dist/esm/commands/uninstall.d.ts +8 -2
  82. package/dist/esm/commands/uninstall.d.ts.map +1 -1
  83. package/dist/esm/commands/uninstall.js +8 -3
  84. package/dist/esm/commands/uninstall.js.map +1 -1
  85. package/dist/esm/commands/update.d.ts +14 -0
  86. package/dist/esm/commands/update.d.ts.map +1 -0
  87. package/dist/esm/commands/update.js +41 -0
  88. package/dist/esm/commands/update.js.map +1 -0
  89. package/dist/esm/commands/version.d.ts +26 -0
  90. package/dist/esm/commands/version.d.ts.map +1 -0
  91. package/dist/esm/commands/version.js +226 -0
  92. package/dist/esm/commands/version.js.map +1 -0
  93. package/dist/esm/config/definition.d.ts +118 -15
  94. package/dist/esm/config/definition.d.ts.map +1 -1
  95. package/dist/esm/config/definition.js +185 -37
  96. package/dist/esm/config/definition.js.map +1 -1
  97. package/dist/esm/config/index.d.ts +41 -37
  98. package/dist/esm/config/index.d.ts.map +1 -1
  99. package/dist/esm/config/index.js +109 -172
  100. package/dist/esm/config/index.js.map +1 -1
  101. package/dist/esm/config/merge.d.ts +3 -1
  102. package/dist/esm/config/merge.d.ts.map +1 -1
  103. package/dist/esm/config/merge.js +11 -6
  104. package/dist/esm/config/merge.js.map +1 -1
  105. package/dist/esm/custom-help.d.ts +9 -0
  106. package/dist/esm/custom-help.d.ts.map +1 -0
  107. package/dist/esm/custom-help.js +400 -0
  108. package/dist/esm/custom-help.js.map +1 -0
  109. package/dist/esm/exec-command.d.ts +33 -14
  110. package/dist/esm/exec-command.d.ts.map +1 -1
  111. package/dist/esm/exec-command.js +213 -64
  112. package/dist/esm/exec-command.js.map +1 -1
  113. package/dist/esm/index.d.ts +1 -14
  114. package/dist/esm/index.d.ts.map +1 -1
  115. package/dist/esm/index.js +45 -19
  116. package/dist/esm/index.js.map +1 -1
  117. package/dist/esm/load-command.d.ts +16 -0
  118. package/dist/esm/load-command.d.ts.map +1 -0
  119. package/dist/esm/load-command.js +21 -0
  120. package/dist/esm/load-command.js.map +1 -0
  121. package/dist/esm/output.d.ts +6 -11
  122. package/dist/esm/output.d.ts.map +1 -1
  123. package/dist/esm/output.js +64 -27
  124. package/dist/esm/output.js.map +1 -1
  125. package/dist/esm/pack-tarball.d.ts +22 -0
  126. package/dist/esm/pack-tarball.d.ts.map +1 -0
  127. package/dist/esm/pack-tarball.js +249 -0
  128. package/dist/esm/pack-tarball.js.map +1 -0
  129. package/dist/esm/print-err.d.ts +9 -2
  130. package/dist/esm/print-err.d.ts.map +1 -1
  131. package/dist/esm/print-err.js +130 -46
  132. package/dist/esm/print-err.js.map +1 -1
  133. package/dist/esm/query-host-contexts.d.ts +16 -0
  134. package/dist/esm/query-host-contexts.d.ts.map +1 -0
  135. package/dist/esm/query-host-contexts.js +135 -0
  136. package/dist/esm/query-host-contexts.js.map +1 -0
  137. package/dist/esm/start-gui.d.ts +1 -0
  138. package/dist/esm/start-gui.d.ts.map +1 -1
  139. package/dist/esm/start-gui.js +25 -6
  140. package/dist/esm/start-gui.js.map +1 -1
  141. package/dist/esm/view.d.ts +2 -3
  142. package/dist/esm/view.d.ts.map +1 -1
  143. package/dist/esm/view.js +1 -1
  144. package/dist/esm/view.js.map +1 -1
  145. package/package.json +51 -37
  146. package/dist/esm/commands/gui.d.ts +0 -6
  147. package/dist/esm/commands/gui.d.ts.map +0 -1
  148. package/dist/esm/commands/gui.js +0 -13
  149. package/dist/esm/commands/gui.js.map +0 -1
@@ -0,0 +1,154 @@
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: 'docs',
14
+ usage: ['[<spec>]', '[--target=<query>]'],
15
+ description: `Open documentation for a package in a web browser.
16
+ Reads repository 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 docs for the current package (reads local package.json)',
27
+ },
28
+ 'abbrev@2.0.0': {
29
+ description: 'Open docs for a specific package version',
30
+ },
31
+ '--target=":root > *"': {
32
+ description: 'List documentation 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 docs 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, homepage, repository } = manifest;
49
+ if (!name) {
50
+ throw error('No package name found');
51
+ }
52
+ // Extract repository URL
53
+ let url;
54
+ if (homepage) {
55
+ url = homepage;
56
+ }
57
+ else if (repository) {
58
+ const repoUrl = typeof repository === 'string' ? repository
59
+ : typeof repository === 'object' && 'url' in repository ?
60
+ repository.url
61
+ : /* c8 ignore next */ undefined;
62
+ if (repoUrl) {
63
+ // Try to get hosted git info
64
+ const info = hostedGitInfoFromUrl(repoUrl.replace(/^git\+/, ''));
65
+ if (info?.docs && typeof info.docs === 'function') {
66
+ url = info.docs();
67
+ }
68
+ }
69
+ }
70
+ // Fallback to npmjs.com package page
71
+ if (!url) {
72
+ url = `https://www.npmjs.com/package/${name}`;
73
+ }
74
+ return url;
75
+ };
76
+ export const command = async (conf) => {
77
+ const { projectRoot, packageJson } = conf.options;
78
+ const targetOption = conf.get('target');
79
+ // Handle --target query
80
+ if (targetOption) {
81
+ const mainManifest = packageJson.maybeRead(projectRoot);
82
+ if (!mainManifest) {
83
+ throw error('No package.json found in project root', {
84
+ path: projectRoot,
85
+ });
86
+ }
87
+ const graph = actual.load({
88
+ ...conf.options,
89
+ mainManifest,
90
+ monorepo: conf.options.monorepo,
91
+ loadManifests: true,
92
+ });
93
+ const securityArchive = Query.hasSecuritySelectors(targetOption) ?
94
+ await SecurityArchive.start({
95
+ nodes: [...graph.nodes.values()],
96
+ })
97
+ : undefined;
98
+ const hostContexts = await createHostContextsMap(conf);
99
+ const query = new Query({
100
+ nodes: new Set(graph.nodes.values()),
101
+ edges: graph.edges,
102
+ importers: graph.importers,
103
+ securityArchive,
104
+ hostContexts,
105
+ });
106
+ const { nodes } = await query.search(targetOption, {
107
+ signal: new AbortController().signal,
108
+ });
109
+ const results = [];
110
+ for (const node of nodes) {
111
+ if (!node.manifest)
112
+ continue;
113
+ const url = getUrlFromManifest(node.manifest);
114
+ results.push({
115
+ url,
116
+ name: node.name /* c8 ignore next */ ?? '(unknown)',
117
+ });
118
+ }
119
+ if (results.length === 0) {
120
+ throw error('No packages found matching target query', {
121
+ found: targetOption,
122
+ });
123
+ }
124
+ // If single result, open it
125
+ if (results.length === 1) {
126
+ const result = results[0];
127
+ /* c8 ignore next 3 */
128
+ if (!result) {
129
+ throw error('Unexpected empty result');
130
+ }
131
+ await urlOpen(result.url);
132
+ return result;
133
+ }
134
+ // Multiple results, return the list
135
+ return results;
136
+ }
137
+ // read the package spec from a positional argument or local package.json
138
+ const specArg = conf.positionals[0];
139
+ const manifest = conf.positionals.length === 0 ? packageJson.read(projectRoot)
140
+ : specArg ?
141
+ await new PackageInfoClient(conf.options).manifest(Spec.parseArgs(specArg, conf.options))
142
+ : /* c8 ignore next */ packageJson.read(projectRoot);
143
+ const url = getUrlFromManifest(manifest);
144
+ const { name } = manifest;
145
+ /* c8 ignore start - getUrlFromManifest already validates name */
146
+ if (!name) {
147
+ throw error('No package name found');
148
+ }
149
+ /* c8 ignore stop */
150
+ // Open the URL
151
+ await urlOpen(url);
152
+ return { url, name };
153
+ };
154
+ //# sourceMappingURL=docs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"docs.js","sourceRoot":"","sources":["../../../src/commands/docs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAC3C,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AACxD,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AACnC,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA;AAC1C,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAA;AACtC,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAA;AACrC,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAA;AAC1D,OAAO,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAA;AACjE,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAIjD,OAAO,aAAa,MAAM,iBAAiB,CAAA;AAC3C,MAAM,EAAE,OAAO,EAAE,oBAAoB,EAAE,GAAG,aAEzC,CAAA;AAED,MAAM,CAAC,MAAM,KAAK,GAAiB,GAAG,EAAE,CACtC,YAAY,CAAC;IACX,OAAO,EAAE,MAAM;IACf,KAAK,EAAE,CAAC,UAAU,EAAE,oBAAoB,CAAC;IACzC,WAAW,EAAE;;2DAE0C;IACvD,OAAO,EAAE;QACP,MAAM,EAAE;YACN,KAAK,EAAE,SAAS;YAChB,WAAW,EACT,qDAAqD;SACxD;KACF;IACD,QAAQ,EAAE;QACR,EAAE,EAAE;YACF,WAAW,EACT,8DAA8D;SACjE;Q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AAC,CAAA;YACzB,OAAO,MAAM,CAAA;QACf,CAAC;QAED,oCAAoC;QACpC,OAAO,OAAO,CAAA;IAChB,CAAC;IAED,yEAAyE;IACzE,MAAM,OAAO,GAAG,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,CAAA;IACnC,MAAM,QAAQ,GACZ,IAAI,CAAC,WAAW,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,IAAI,CAAC,WAAW,CAAC;QAC7D,CAAC,CAAC,OAAO,CAAC,CAAC;YACT,MAAM,IAAI,iBAAiB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,QAAQ,CAChD,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,CACtC;YACH,CAAC,CAAC,oBAAoB,CAAC,WAAW,CAAC,IAAI,CAAC,WAAW,CAAC,CAAA;IAEtD,MAAM,GAAG,GAAG,kBAAkB,CAAC,QAAQ,CAAC,CAAA;IACxC,MAAM,EAAE,IAAI,EAAE,GAAG,QAAQ,CAAA;IACzB,iEAAiE;IACjE,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,MAAM,KAAK,CAAC,uBAAuB,CAAC,CAAA;IACtC,CAAC;IACD,oBAAoB;IACpB,eAAe;IACf,MAAM,OAAO,CAAC,GAAG,CAAC,CAAA;IAElB,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,CAAA;AACtB,CAAC,CAAA","sourcesContent":["import { error } from '@vltpkg/error-cause'\nimport { PackageInfoClient } from '@vltpkg/package-info'\nimport { Spec } from '@vltpkg/spec'\nimport { urlOpen } from '@vltpkg/url-open'\nimport { actual } from '@vltpkg/graph'\nimport { Query } from '@vltpkg/query'\nimport { SecurityArchive } from '@vltpkg/security-archive'\nimport { createHostContextsMap } from '../query-host-contexts.ts'\nimport { commandUsage } from '../config/usage.ts'\nimport type { CommandFn, CommandUsage } from '../index.ts'\nimport type { Views } from '../view.ts'\nimport type { Manifest, NormalizedManifest } from '@vltpkg/types'\nimport hostedGitInfo from 'hosted-git-info'\nconst { fromUrl: hostedGitInfoFromUrl } = hostedGitInfo as {\n fromUrl: (url: string) => { docs?: () => string } | null\n}\n\nexport const usage: CommandUsage = () =>\n commandUsage({\n command: 'docs',\n usage: ['[<spec>]', '[--target=<query>]'],\n description: `Open documentation for a package in a web browser.\n Reads repository information from package.json or fetches\n manifest data for the specified package.`,\n options: {\n target: {\n value: '<query>',\n description:\n 'Query selector to filter packages using DSS syntax.',\n },\n },\n examples: {\n '': {\n description:\n 'Open docs for the current package (reads local package.json)',\n },\n 'abbrev@2.0.0': {\n description: 'Open docs for a specific package version',\n },\n '--target=\":root > *\"': {\n description:\n 'List documentation URLs for all direct dependencies',\n },\n },\n })\n\ntype CommandResultSingle = {\n url: string\n name: string\n}\n\ntype CommandResultMultiple = {\n url: string\n name: string\n}[]\n\nexport type CommandResult =\n | CommandResultSingle\n | CommandResultMultiple\n\nexport const views = {\n human: r => {\n if (Array.isArray(r)) {\n let msg = 'Multiple package docs found:\\n'\n msg += r.map(item => `• ${item.name}: ${item.url}`).join('\\n')\n return msg\n }\n return ''\n },\n json: r => r,\n} as const satisfies Views<CommandResult>\n\nconst getUrlFromManifest = (\n manifest: Manifest | NormalizedManifest,\n): string => {\n const { name, homepage, repository } = manifest\n\n if (!name) {\n throw error('No package name found')\n }\n\n // Extract repository URL\n let url: string | undefined\n\n if (homepage) {\n url = homepage\n } else if (repository) {\n const repoUrl =\n typeof repository === 'string' ? repository\n : typeof repository === 'object' && 'url' in repository ?\n repository.url\n : /* c8 ignore next */ undefined\n\n if (repoUrl) {\n // Try to get hosted git info\n\n const info = hostedGitInfoFromUrl(repoUrl.replace(/^git\\+/, ''))\n\n if (info?.docs && typeof info.docs === 'function') {\n url = info.docs()\n }\n }\n }\n\n // Fallback to npmjs.com package page\n if (!url) {\n url = `https://www.npmjs.com/package/${name}`\n }\n\n return url\n}\n\nexport const command: CommandFn<CommandResult> = async conf => {\n const { projectRoot, packageJson } = conf.options\n const targetOption = conf.get('target')\n\n // Handle --target query\n if (targetOption) {\n const mainManifest = packageJson.maybeRead(projectRoot)\n if (!mainManifest) {\n throw error('No package.json found in project root', {\n path: projectRoot,\n })\n }\n\n const graph = actual.load({\n ...conf.options,\n mainManifest,\n monorepo: conf.options.monorepo,\n loadManifests: true,\n })\n\n const securityArchive =\n Query.hasSecuritySelectors(targetOption) ?\n await SecurityArchive.start({\n nodes: [...graph.nodes.values()],\n })\n : undefined\n\n const hostContexts = await createHostContextsMap(conf)\n const query = new Query({\n nodes: new Set(graph.nodes.values()),\n edges: graph.edges,\n importers: graph.importers,\n securityArchive,\n hostContexts,\n })\n\n const { nodes } = await query.search(targetOption, {\n signal: new AbortController().signal,\n })\n\n const results: CommandResultMultiple = []\n for (const node of nodes) {\n if (!node.manifest) continue\n const url = getUrlFromManifest(node.manifest)\n results.push({\n url,\n name: node.name /* c8 ignore next */ ?? '(unknown)',\n })\n }\n\n if (results.length === 0) {\n throw error('No packages found matching target query', {\n found: targetOption,\n })\n }\n\n // If single result, open it\n if (results.length === 1) {\n const result = results[0]\n /* c8 ignore next 3 */\n if (!result) {\n throw error('Unexpected empty result')\n }\n await urlOpen(result.url)\n return result\n }\n\n // Multiple results, return the list\n return results\n }\n\n // read the package spec from a positional argument or local package.json\n const specArg = conf.positionals[0]\n const manifest =\n conf.positionals.length === 0 ? packageJson.read(projectRoot)\n : specArg ?\n await new PackageInfoClient(conf.options).manifest(\n Spec.parseArgs(specArg, conf.options),\n )\n : /* c8 ignore next */ packageJson.read(projectRoot)\n\n const url = getUrlFromManifest(manifest)\n const { name } = manifest\n /* c8 ignore start - getUrlFromManifest already validates name */\n if (!name) {\n throw error('No package name found')\n }\n /* c8 ignore stop */\n // Open the URL\n await urlOpen(url)\n\n return { url, name }\n}\n"]}
@@ -0,0 +1,49 @@
1
+ import type { VlxInfo } from '@vltpkg/vlx';
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 ExecCacheSubcommands = keyof (typeof usageDef)['subcommands'];
7
+ export declare class ExecCacheView extends ViewClass {
8
+ constructor(options: ViewOptions, conf: LoadedConfig);
9
+ stdout(...args: unknown[]): void;
10
+ }
11
+ export declare const views: Views<void | string[] | VlxInfo[]>;
12
+ declare const usageDef: {
13
+ readonly command: "exec-cache";
14
+ readonly usage: "<command> [flags]";
15
+ readonly description: "Work with vlt exec-cache folders";
16
+ readonly subcommands: {
17
+ readonly ls: {
18
+ readonly usage: "";
19
+ readonly description: "Show previously installed packages used for `vlt exec`.\n Key provided can be either the package name, or the full\n key.";
20
+ };
21
+ readonly delete: {
22
+ readonly usage: "[<key>...]";
23
+ readonly description: "Delete previously installed packages used for\n `vlt exec`. If no keys are provided, then all entries\n will be deleted.";
24
+ };
25
+ readonly info: {
26
+ readonly usage: "<key>";
27
+ readonly description: "Show extended information about a given `vlt exec`\n installation.";
28
+ };
29
+ readonly install: {
30
+ readonly usage: "<spec>...";
31
+ readonly description: "Install the specified package(s) in the `vlt exec`\n central cache location. Metadata info about each\n installation will be printed.";
32
+ };
33
+ };
34
+ readonly examples: {
35
+ readonly ls: {
36
+ readonly description: "Show all the keys for the installations in the `vlt exec`\n cache.";
37
+ };
38
+ readonly 'delete typescript': {
39
+ readonly description: "Delete all versions of typescript installed for vlt exec";
40
+ };
41
+ readonly 'info typescript-695bf962': {
42
+ readonly description: "Show extended info about a specific version of typescript";
43
+ };
44
+ };
45
+ };
46
+ export declare const usage: CommandUsage;
47
+ export declare const command: CommandFn<string[] | VlxInfo[]>;
48
+ export {};
49
+ //# sourceMappingURL=exec-cache.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exec-cache.d.ts","sourceRoot":"","sources":["../../../src/commands/exec-cache.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AAG1C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAGtD,OAAO,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAE1D,OAAO,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AACpD,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AAEtC,MAAM,MAAM,oBAAoB,GAC9B,MAAM,CAAC,OAAO,QAAQ,CAAC,CAAC,aAAa,CAAC,CAAA;AAGxC,qBAAa,aAAc,SAAQ,SAAS;gBAC9B,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,YAAY;IAIpD,MAAM,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE;CAG1B;AAED,eAAO,MAAM,KAAK,EAAE,KAAK,CAAC,IAAI,GAAG,MAAM,EAAE,GAAG,OAAO,EAAE,CAEpD,CAAA;AAED,QAAA,MAAM,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA8C6B,CAAA;AAE3C,eAAO,MAAM,KAAK,EAAE,YAA2C,CAAA;AAE/D,eAAO,MAAM,OAAO,EAAE,SAAS,CAC7B,MAAM,EAAE,GAAG,OAAO,EAAE,CAwBrB,CAAA"}
@@ -0,0 +1,146 @@
1
+ import { error } from '@vltpkg/error-cause';
2
+ import { RollbackRemove } from '@vltpkg/rollback-remove';
3
+ import * as vlx from '@vltpkg/vlx';
4
+ import { basename } from 'node:path';
5
+ import { commandUsage } from "../config/usage.js";
6
+ import { stdout } from "../output.js";
7
+ import { ViewClass } from "../view.js";
8
+ let view;
9
+ export class ExecCacheView extends ViewClass {
10
+ constructor(options, conf) {
11
+ super(options, conf);
12
+ view = this;
13
+ }
14
+ stdout(...args) {
15
+ stdout(...args);
16
+ }
17
+ }
18
+ export const views = {
19
+ human: ExecCacheView,
20
+ };
21
+ const usageDef = {
22
+ command: 'exec-cache',
23
+ usage: '<command> [flags]',
24
+ description: 'Work with vlt exec-cache folders',
25
+ subcommands: {
26
+ ls: {
27
+ usage: '',
28
+ description: `Show previously installed packages used for \`vlt exec\`.
29
+ Key provided can be either the package name, or the full
30
+ key.`,
31
+ },
32
+ delete: {
33
+ usage: '[<key>...]',
34
+ description: `Delete previously installed packages used for
35
+ \`vlt exec\`. If no keys are provided, then all entries
36
+ will be deleted.`,
37
+ },
38
+ info: {
39
+ usage: '<key>',
40
+ description: `Show extended information about a given \`vlt exec\`
41
+ installation.`,
42
+ },
43
+ install: {
44
+ usage: '<spec>...',
45
+ description: `Install the specified package(s) in the \`vlt exec\`
46
+ central cache location. Metadata info about each
47
+ installation will be printed.`,
48
+ },
49
+ },
50
+ examples: {
51
+ ls: {
52
+ description: `Show all the keys for the installations in the \`vlt exec\`
53
+ cache.`,
54
+ },
55
+ 'delete typescript': {
56
+ description: `Delete all versions of typescript installed for vlt exec`,
57
+ },
58
+ 'info typescript-695bf962': {
59
+ description: `Show extended info about a specific version of typescript`,
60
+ },
61
+ },
62
+ };
63
+ export const usage = () => commandUsage(usageDef);
64
+ export const command = async (conf) => {
65
+ const [sub, ...args] = conf.positionals;
66
+ switch (sub) {
67
+ case 'ls':
68
+ return ls(conf, args, view);
69
+ case 'info':
70
+ return info(conf, args, view);
71
+ case 'install':
72
+ return install(conf, args, view);
73
+ case 'delete':
74
+ return deleteEntries(conf, args, view);
75
+ default: {
76
+ throw error('Unrecognized exec-cache command', {
77
+ code: 'EUSAGE',
78
+ found: sub,
79
+ validOptions: Object.keys(usageDef.subcommands),
80
+ });
81
+ }
82
+ }
83
+ };
84
+ const install = async (conf, keys, view) => {
85
+ if (!keys.length) {
86
+ throw error('Must supply a package spec to install', {
87
+ code: 'EUSAGE',
88
+ });
89
+ }
90
+ const allowScripts = conf.get('allow-scripts') ?
91
+ String(conf.get('allow-scripts'))
92
+ : ':not(*)';
93
+ return Promise.all(keys.map(async (key) => {
94
+ const info = await vlx.install(key, {
95
+ ...conf.options,
96
+ query: undefined,
97
+ allowScripts,
98
+ });
99
+ view?.stdout(info);
100
+ return info.path;
101
+ }));
102
+ };
103
+ const ls = async (_conf, args, view) => {
104
+ const results = [];
105
+ for await (const path of vlx.list()) {
106
+ const key = basename(path);
107
+ if (args.length && !args.some(a => key.includes(a)))
108
+ continue;
109
+ results.push(key);
110
+ view?.stdout(key);
111
+ }
112
+ return results;
113
+ };
114
+ const info = async (conf, keys, view) => {
115
+ const allowScripts = conf.get('allow-scripts') ?
116
+ String(conf.get('allow-scripts'))
117
+ : ':not(*)';
118
+ const results = [];
119
+ for await (const key of keys.length ? keys : vlx.list()) {
120
+ const info = vlx.info(key, {
121
+ ...conf.options,
122
+ query: undefined,
123
+ allowScripts,
124
+ });
125
+ results.push(info);
126
+ view?.stdout(info);
127
+ }
128
+ return results;
129
+ };
130
+ const deleteEntries = async (conf, keys, view) => {
131
+ const allowScripts = conf.get('allow-scripts') ?
132
+ String(conf.get('allow-scripts'))
133
+ : ':not(*)';
134
+ const remover = new RollbackRemove();
135
+ const removed = (await vlx.delete(keys, remover, {
136
+ ...conf.options,
137
+ query: undefined,
138
+ allowScripts,
139
+ })).map(path => {
140
+ view?.stdout(`- ${basename(path)}`);
141
+ return path;
142
+ });
143
+ remover.confirm();
144
+ return removed;
145
+ };
146
+ //# sourceMappingURL=exec-cache.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exec-cache.js","sourceRoot":"","sources":["../../../src/commands/exec-cache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAC3C,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAA;AAExD,OAAO,KAAK,GAAG,MAAM,aAAa,CAAA;AAClC,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;AAGpC,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAEjD,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AAErC,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AAKtC,IAAI,I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CAAC,IAAI,CAAC,CAAA;IACpB,CAAC;IACD,OAAO,OAAO,CAAA;AAChB,CAAC,CAAA;AAED,MAAM,aAAa,GAAG,KAAK,EACzB,IAAkB,EAClB,IAAc,EACd,IAAoB,EACD,EAAE;IACrB,MAAM,YAAY,GAChB,IAAI,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC,CAAC;QACzB,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;QACnC,CAAC,CAAC,SAAS,CAAA;IACb,MAAM,OAAO,GAAG,IAAI,cAAc,EAAE,CAAA;IACpC,MAAM,OAAO,GAAG,CACd,MAAM,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,OAAO,EAAE;QAC9B,GAAG,IAAI,CAAC,OAAO;QACf,KAAK,EAAE,SAAS;QAChB,YAAY;KACb,CAAC,CACH,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE;QACX,IAAI,EAAE,MAAM,CAAC,KAAK,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;QACnC,OAAO,IAAI,CAAA;IACb,CAAC,CAAC,CAAA;IACF,OAAO,CAAC,OAAO,EAAE,CAAA;IACjB,OAAO,OAAO,CAAA;AAChB,CAAC,CAAA","sourcesContent":["import { error } from '@vltpkg/error-cause'\nimport { RollbackRemove } from '@vltpkg/rollback-remove'\nimport type { VlxInfo } from '@vltpkg/vlx'\nimport * as vlx from '@vltpkg/vlx'\nimport { basename } from 'node:path'\nimport type { LoadedConfig } from '../config/index.ts'\nimport type { CommandUsageDefinition } from '../config/usage.ts'\nimport { commandUsage } from '../config/usage.ts'\nimport type { CommandFn, CommandUsage } from '../index.ts'\nimport { stdout } from '../output.ts'\nimport type { ViewOptions, Views } from '../view.ts'\nimport { ViewClass } from '../view.ts'\n\nexport type ExecCacheSubcommands =\n keyof (typeof usageDef)['subcommands']\n\nlet view: ExecCacheView\nexport class ExecCacheView extends ViewClass {\n constructor(options: ViewOptions, conf: LoadedConfig) {\n super(options, conf)\n view = this\n }\n stdout(...args: unknown[]) {\n stdout(...args)\n }\n}\n\nexport const views: Views<void | string[] | VlxInfo[]> = {\n human: ExecCacheView,\n}\n\nconst usageDef = {\n command: 'exec-cache',\n usage: '<command> [flags]',\n description: 'Work with vlt exec-cache folders',\n\n subcommands: {\n ls: {\n usage: '',\n description: `Show previously installed packages used for \\`vlt exec\\`.\n Key provided can be either the package name, or the full\n key.`,\n },\n\n delete: {\n usage: '[<key>...]',\n description: `Delete previously installed packages used for\n \\`vlt exec\\`. If no keys are provided, then all entries\n will be deleted.`,\n },\n\n info: {\n usage: '<key>',\n description: `Show extended information about a given \\`vlt exec\\`\n installation.`,\n },\n\n install: {\n usage: '<spec>...',\n description: `Install the specified package(s) in the \\`vlt exec\\`\n central cache location. Metadata info about each\n installation will be printed.`,\n },\n },\n\n examples: {\n ls: {\n description: `Show all the keys for the installations in the \\`vlt exec\\`\n cache.`,\n },\n 'delete typescript': {\n description: `Delete all versions of typescript installed for vlt exec`,\n },\n 'info typescript-695bf962': {\n description: `Show extended info about a specific version of typescript`,\n },\n },\n} as const satisfies CommandUsageDefinition\n\nexport const usage: CommandUsage = () => commandUsage(usageDef)\n\nexport const command: CommandFn<\n string[] | VlxInfo[]\n> = async conf => {\n const [sub, ...args] = conf.positionals\n switch (sub) {\n case 'ls':\n return ls(conf, args, view)\n\n case 'info':\n return info(conf, args, view)\n\n case 'install':\n return install(conf, args, view)\n\n case 'delete':\n return deleteEntries(conf, args, view)\n\n default: {\n throw error('Unrecognized exec-cache command', {\n code: 'EUSAGE',\n found: sub,\n validOptions: Object.keys(usageDef.subcommands),\n })\n }\n }\n}\n\nconst install = async (\n conf: LoadedConfig,\n keys: string[],\n view?: ExecCacheView,\n): Promise<string[]> => {\n if (!keys.length) {\n throw error('Must supply a package spec to install', {\n code: 'EUSAGE',\n })\n }\n const allowScripts =\n conf.get('allow-scripts') ?\n String(conf.get('allow-scripts'))\n : ':not(*)'\n return Promise.all(\n keys.map(async key => {\n const info = await vlx.install(key, {\n ...conf.options,\n query: undefined,\n allowScripts,\n })\n view?.stdout(info)\n return info.path\n }),\n )\n}\n\nconst ls = async (\n _conf: LoadedConfig,\n args: string[],\n view?: ExecCacheView,\n): Promise<string[]> => {\n const results: string[] = []\n for await (const path of vlx.list()) {\n const key = basename(path)\n if (args.length && !args.some(a => key.includes(a))) continue\n results.push(key)\n view?.stdout(key)\n }\n return results\n}\n\nconst info = async (\n conf: LoadedConfig,\n keys: string[],\n view?: ExecCacheView,\n): Promise<VlxInfo[]> => {\n const allowScripts =\n conf.get('allow-scripts') ?\n String(conf.get('allow-scripts'))\n : ':not(*)'\n const results: VlxInfo[] = []\n for await (const key of keys.length ? keys : vlx.list()) {\n const info = vlx.info(key, {\n ...conf.options,\n query: undefined,\n allowScripts,\n })\n results.push(info)\n view?.stdout(info)\n }\n return results\n}\n\nconst deleteEntries = async (\n conf: LoadedConfig,\n keys: string[],\n view?: ExecCacheView,\n): Promise<string[]> => {\n const allowScripts =\n conf.get('allow-scripts') ?\n String(conf.get('allow-scripts'))\n : ':not(*)'\n const remover = new RollbackRemove()\n const removed = (\n await vlx.delete(keys, remover, {\n ...conf.options,\n query: undefined,\n allowScripts,\n })\n ).map(path => {\n view?.stdout(`- ${basename(path)}`)\n return path\n })\n remover.confirm()\n return removed\n}\n"]}
@@ -1,5 +1,6 @@
1
1
  import type { ExecResult } from '../exec-command.ts';
2
2
  import type { CommandFn, CommandUsage } from '../index.ts';
3
+ export { views } from '../exec-command.ts';
3
4
  export declare const usage: CommandUsage;
4
5
  export declare const command: CommandFn<ExecResult>;
5
6
  //# sourceMappingURL=exec-local.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"exec-local.d.ts","sourceRoot":"","sources":["../../../src/commands/exec-local.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AACpD,OAAO,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAE1D,eAAO,MAAM,KAAK,EAAE,YAehB,CAAA;AAEJ,eAAO,MAAM,OAAO,EAAE,SAAS,CAAC,UAAU,CAEzC,CAAA"}
1
+ {"version":3,"file":"exec-local.d.ts","sourceRoot":"","sources":["../../../src/commands/exec-local.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AAEpD,OAAO,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAC1D,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAA;AAE1C,eAAO,MAAM,KAAK,EAAE,YAehB,CAAA;AAEJ,eAAO,MAAM,OAAO,EAAE,SAAS,CAAC,UAAU,CAGzC,CAAA"}
@@ -1,6 +1,7 @@
1
1
  import { exec, execFG } from '@vltpkg/run';
2
2
  import { commandUsage } from "../config/usage.js";
3
3
  import { ExecCommand } from "../exec-command.js";
4
+ export { views } from "../exec-command.js";
4
5
  export const usage = () => commandUsage({
5
6
  command: 'exec-local',
6
7
  usage: '[command]',
@@ -17,6 +18,7 @@ export const usage = () => commandUsage({
17
18
  provided to the exec process.`,
18
19
  });
19
20
  export const command = async (conf) => {
21
+ delete conf.options['script-shell'];
20
22
  return await new ExecCommand(conf, exec, execFG).run();
21
23
  };
22
24
  //# sourceMappingURL=exec-local.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"exec-local.js","sourceRoot":"","sources":["../../../src/commands/exec-local.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAC1C,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AACjD,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAIhD,MAAM,CAAC,MAAM,KAAK,GAAiB,GAAG,EAAE,CACtC,YAAY,CAAC;IACX,OAAO,EAAE,YAAY;IACrB,KAAK,EAAE,WAAW;IAClB,WAAW,EAAE;;;;;;;;;;gDAU+B;CAC7C,CAAC,CAAA;AAEJ,MAAM,CAAC,MAAM,OAAO,GAA0B,KAAK,EAAC,IAAI,EAAC,EAAE;IACzD,OAAO,MAAM,IAAI,WAAW,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC,GAAG,EAAE,CAAA;AACxD,CAAC,CAAA","sourcesContent":["import { exec, execFG } from '@vltpkg/run'\nimport { commandUsage } from '../config/usage.ts'\nimport { ExecCommand } from '../exec-command.ts'\nimport type { ExecResult } from '../exec-command.ts'\nimport type { CommandFn, CommandUsage } from '../index.ts'\n\nexport const usage: CommandUsage = () =>\n commandUsage({\n command: 'exec-local',\n usage: '[command]',\n description: `Run an arbitrary command, with the local installed packages\n first in the PATH. Ie, this will run your locally installed\n package bins.\n\n If no command is provided, then a shell is spawned in the\n current working directory, with the locally installed package\n bins first in the PATH.\n\n Note that any vlt configs must be specified *before* the\n command, as the remainder of the command line options are\n provided to the exec process.`,\n })\n\nexport const command: CommandFn<ExecResult> = async conf => {\n return await new ExecCommand(conf, exec, execFG).run()\n}\n"]}
1
+ {"version":3,"file":"exec-local.js","sourceRoot":"","sources":["../../../src/commands/exec-local.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAC1C,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAEjD,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAEhD,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAA;AAE1C,MAAM,CAAC,MAAM,KAAK,GAAiB,GAAG,EAAE,CACtC,YAAY,CAAC;IACX,OAAO,EAAE,YAAY;IACrB,KAAK,EAAE,WAAW;IAClB,WAAW,EAAE;;;;;;;;;;gDAU+B;CAC7C,CAAC,CAAA;AAEJ,MAAM,CAAC,MAAM,OAAO,GAA0B,KAAK,EAAC,IAAI,EAAC,EAAE;IACzD,OAAO,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,CAAA;IACnC,OAAO,MAAM,IAAI,WAAW,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC,GAAG,EAAE,CAAA;AACxD,CAAC,CAAA","sourcesContent":["import { exec, execFG } from '@vltpkg/run'\nimport { commandUsage } from '../config/usage.ts'\nimport type { ExecResult } from '../exec-command.ts'\nimport { ExecCommand } from '../exec-command.ts'\nimport type { CommandFn, CommandUsage } from '../index.ts'\nexport { views } from '../exec-command.ts'\n\nexport const usage: CommandUsage = () =>\n commandUsage({\n command: 'exec-local',\n usage: '[command]',\n description: `Run an arbitrary command, with the local installed packages\n first in the PATH. Ie, this will run your locally installed\n package bins.\n\n If no command is provided, then a shell is spawned in the\n current working directory, with the locally installed package\n bins first in the PATH.\n\n Note that any vlt configs must be specified *before* the\n command, as the remainder of the command line options are\n provided to the exec process.`,\n })\n\nexport const command: CommandFn<ExecResult> = async conf => {\n delete conf.options['script-shell']\n return await new ExecCommand(conf, exec, execFG).run()\n}\n"]}
@@ -1,4 +1,9 @@
1
+ import type { PromptFn } from '@vltpkg/vlx';
2
+ import type { ExecResult } from '../exec-command.ts';
1
3
  import type { CommandFn, CommandUsage } from '../index.ts';
4
+ export { views } from '../exec-command.ts';
2
5
  export declare const usage: CommandUsage;
3
- export declare const command: CommandFn<string>;
6
+ export declare const prettyPath: (path: string) => string;
7
+ export declare const promptFn: PromptFn;
8
+ export declare const command: CommandFn<ExecResult>;
4
9
  //# sourceMappingURL=exec.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"exec.d.ts","sourceRoot":"","sources":["../../../src/commands/exec.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAE1D,eAAO,MAAM,KAAK,EAAE,YAMhB,CAAA;AAEJ,eAAO,MAAM,OAAO,EAAE,SAAS,CAAC,MAAM,CAKrC,CAAA"}
1
+ {"version":3,"file":"exec.d.ts","sourceRoot":"","sources":["../../../src/commands/exec.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAK3C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AAEpD,OAAO,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAE1D,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAA;AAE1C,eAAO,MAAM,KAAK,EAAE,YAoDhB,CAAA;AAGJ,eAAO,MAAM,UAAU,SAAU,MAAM,WAC2B,CAAA;AAElE,eAAO,MAAM,QAAQ,EAAE,QAyBtB,CAAA;AAED,eAAO,MAAM,OAAO,EAAE,SAAS,CAAC,UAAU,CAoBzC,CAAA"}
@@ -1,13 +1,87 @@
1
+ import { exec, execFG } from '@vltpkg/run';
2
+ import * as vlx from '@vltpkg/vlx';
3
+ import { homedir } from 'node:os';
4
+ import { createInterface } from 'node:readline/promises';
1
5
  import { commandUsage } from "../config/usage.js";
6
+ import { ExecCommand } from "../exec-command.js";
7
+ import { styleTextStdout } from "../output.js";
8
+ export { views } from "../exec-command.js";
2
9
  export const usage = () => commandUsage({
3
10
  command: 'exec',
4
11
  usage: '[--package=<pkg>] [command...]',
5
- description: 'Run a command defined by a package, installing it if necessary',
12
+ description: `Run a command defined by a package, installing it
13
+ if necessary.
14
+
15
+ If the package specifier is provided explicitly via the
16
+ \`--package\` config, then that is what will be used. If
17
+ a satisfying instance of the named package exists in the
18
+ local \`node_mnodules\` folder, then that will be used.
19
+
20
+ If \`--package\` is not set, then vlt will attempt to infer
21
+ the package to be installed if necessary, in the following
22
+ manner:
23
+
24
+ - If the first argument is an executable found in the
25
+ \`node_modules/.bin\` folder (ie, provided by an
26
+ installed direct dependency), then that will be used.
27
+ The search stops, and nothing will be installed.
28
+ - Otherwise, vlt attempts to resolve the first argument
29
+ as if it was a \`--package\` option, and then swap it
30
+ out with the "default" executable provided by that
31
+ package.
32
+
33
+ The "default" executable provided by a package is:
34
+
35
+ - If the package provides a single executable string in the
36
+ \`bin\` field, then that is the executable to use.
37
+ - Otherwise, if there is a \`bin\` with the same name
38
+ as the package (or just the portion after the \`/\` in
39
+ the case of scoped packages), then that will be used.
40
+
41
+ If the appropriate excutable cannot be determined, then
42
+ an error will be raised.
43
+
44
+ At no point will \`vlt exec\` change the locally installed
45
+ dependencies. Any installs it performs is done in vlt's XDG
46
+ data directory.
47
+ `,
48
+ examples: {
49
+ '--package typescript@5 tsc': {
50
+ description: 'Run tsc provided by typescript version 5',
51
+ },
52
+ 'eslint src/file.js': {
53
+ description: 'Run the default bin provided by eslint',
54
+ },
55
+ 'eslint@9.24 src/file.js': {
56
+ description: 'Run the default bin provided by eslint version 9.24',
57
+ },
58
+ },
6
59
  });
60
+ const HOME = homedir();
61
+ export const prettyPath = (path) => path.startsWith(HOME) ? `~${path.substring(HOME.length)}` : path;
62
+ export const promptFn = async (pkgSpec, path, resolution) => {
63
+ const response = await createInterface(process.stdin, process.stdout).question(`About to install: ${styleTextStdout(['bgWhiteBright', 'black', 'bold'], String(pkgSpec))}
64
+ from: ${styleTextStdout(['bgWhiteBright', 'black', 'bold'], resolution)}
65
+ into: ${styleTextStdout(['bgWhiteBright', 'black', 'bold'], prettyPath(path))}
66
+ Is this ok? (y) `);
67
+ process.stdin.pause();
68
+ return response;
69
+ };
7
70
  export const command = async (conf) => {
8
- return [
9
- 'TODO: exec-local, but install if not present',
10
- ...conf.positionals,
11
- ].join('\n');
71
+ /* c8 ignore start */
72
+ const allowScripts = conf.get('allow-scripts') ?
73
+ String(conf.get('allow-scripts'))
74
+ : ':not(*)';
75
+ /* c8 ignore stop */
76
+ const arg0 = await vlx.resolve(conf.positionals, {
77
+ ...conf.options,
78
+ query: undefined,
79
+ allowScripts,
80
+ }, promptFn);
81
+ if (arg0)
82
+ conf.positionals[0] = arg0;
83
+ // now we have arg0! let's gooooo!!
84
+ delete conf.options['script-shell'];
85
+ return await new ExecCommand(conf, exec, execFG).run();
12
86
  };
13
87
  //# sourceMappingURL=exec.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"exec.js","sourceRoot":"","sources":["../../../src/commands/exec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAGjD,MAAM,CAAC,MAAM,KAAK,GAAiB,GAAG,EAAE,CACtC,YAAY,CAAC;IACX,OAAO,EAAE,MAAM;IACf,KAAK,EAAE,gCAAgC;IACvC,WAAW,EACT,gEAAgE;CACnE,CAAC,CAAA;AAEJ,MAAM,CAAC,MAAM,OAAO,GAAsB,KAAK,EAAC,IAAI,EAAC,EAAE;IACrD,OAAO;QACL,8CAA8C;QAC9C,GAAG,IAAI,CAAC,WAAW;KACpB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;AACd,CAAC,CAAA","sourcesContent":["import { commandUsage } from '../config/usage.ts'\nimport type { CommandFn, CommandUsage } from '../index.ts'\n\nexport const usage: CommandUsage = () =>\n commandUsage({\n command: 'exec',\n usage: '[--package=<pkg>] [command...]',\n description:\n 'Run a command defined by a package, installing it if necessary',\n })\n\nexport const command: CommandFn<string> = async conf => {\n return [\n 'TODO: exec-local, but install if not present',\n ...conf.positionals,\n ].join('\\n')\n}\n"]}
1
+ {"version":3,"file":"exec.js","sourceRoot":"","sources":["../../../src/commands/exec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAE1C,OAAO,KAAK,GAAG,MAAM,aAAa,CAAA;AAClC,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AACjC,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAEjD,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAEhD,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAC9C,OAAO,EAAE,KAAK,EAAE,MAAM,oBA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MAAM,OAAO,GAA0B,KAAK,EAAC,IAAI,EAAC,EAAE;IACzD,qBAAqB;IACrB,MAAM,YAAY,GAChB,IAAI,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC,CAAC;QACzB,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;QACnC,CAAC,CAAC,SAAS,CAAA;IACb,oBAAoB;IACpB,MAAM,IAAI,GAAG,MAAM,GAAG,CAAC,OAAO,CAC5B,IAAI,CAAC,WAAW,EAChB;QACE,GAAG,IAAI,CAAC,OAAO;QACf,KAAK,EAAE,SAAS;QAChB,YAAY;KACb,EACD,QAAQ,CACT,CAAA;IACD,IAAI,IAAI;QAAE,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,GAAG,IAAI,CAAA;IACpC,mCAAmC;IACnC,OAAO,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,CAAA;IACnC,OAAO,MAAM,IAAI,WAAW,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC,GAAG,EAAE,CAAA;AACxD,CAAC,CAAA","sourcesContent":["import { exec, execFG } from '@vltpkg/run'\nimport type { PromptFn } from '@vltpkg/vlx'\nimport * as vlx from '@vltpkg/vlx'\nimport { homedir } from 'node:os'\nimport { createInterface } from 'node:readline/promises'\nimport { commandUsage } from '../config/usage.ts'\nimport type { ExecResult } from '../exec-command.ts'\nimport { ExecCommand } from '../exec-command.ts'\nimport type { CommandFn, CommandUsage } from '../index.ts'\nimport { styleTextStdout } from '../output.ts'\nexport { views } from '../exec-command.ts'\n\nexport const usage: CommandUsage = () =>\n commandUsage({\n command: 'exec',\n usage: '[--package=<pkg>] [command...]',\n description: `Run a command defined by a package, installing it\n if necessary.\n\n If the package specifier is provided explicitly via the\n \\`--package\\` config, then that is what will be used. If\n a satisfying instance of the named package exists in the\n local \\`node_mnodules\\` folder, then that will be used.\n\n If \\`--package\\` is not set, then vlt will attempt to infer\n the package to be installed if necessary, in the following\n manner:\n\n - If the first argument is an executable found in the\n \\`node_modules/.bin\\` folder (ie, provided by an\n installed direct dependency), then that will be used.\n The search stops, and nothing will be installed.\n - Otherwise, vlt attempts to resolve the first argument\n as if it was a \\`--package\\` option, and then swap it\n out with the \"default\" executable provided by that\n package.\n\n The \"default\" executable provided by a package is:\n\n - If the package provides a single executable string in the\n \\`bin\\` field, then that is the executable to use.\n - Otherwise, if there is a \\`bin\\` with the same name\n as the package (or just the portion after the \\`/\\` in\n the case of scoped packages), then that will be used.\n\n If the appropriate excutable cannot be determined, then\n an error will be raised.\n\n At no point will \\`vlt exec\\` change the locally installed\n dependencies. Any installs it performs is done in vlt's XDG\n data directory.\n `,\n examples: {\n '--package typescript@5 tsc': {\n description: 'Run tsc provided by typescript version 5',\n },\n 'eslint src/file.js': {\n description: 'Run the default bin provided by eslint',\n },\n 'eslint@9.24 src/file.js': {\n description:\n 'Run the default bin provided by eslint version 9.24',\n },\n },\n })\n\nconst HOME = homedir()\nexport const prettyPath = (path: string) =>\n path.startsWith(HOME) ? `~${path.substring(HOME.length)}` : path\n\nexport const promptFn: PromptFn = async (\n pkgSpec,\n path,\n resolution,\n) => {\n const response = await createInterface(\n process.stdin,\n process.stdout,\n ).question(\n `About to install: ${styleTextStdout(\n ['bgWhiteBright', 'black', 'bold'],\n String(pkgSpec),\n )}\nfrom: ${styleTextStdout(\n ['bgWhiteBright', 'black', 'bold'],\n resolution,\n )}\ninto: ${styleTextStdout(\n ['bgWhiteBright', 'black', 'bold'],\n prettyPath(path),\n )}\nIs this ok? (y) `,\n )\n process.stdin.pause()\n return response\n}\n\nexport const command: CommandFn<ExecResult> = async conf => {\n /* c8 ignore start */\n const allowScripts =\n conf.get('allow-scripts') ?\n String(conf.get('allow-scripts'))\n : ':not(*)'\n /* c8 ignore stop */\n const arg0 = await vlx.resolve(\n conf.positionals,\n {\n ...conf.options,\n query: undefined,\n allowScripts,\n },\n promptFn,\n )\n if (arg0) conf.positionals[0] = arg0\n // now we have arg0! let's gooooo!!\n delete conf.options['script-shell']\n return await new ExecCommand(conf, exec, execFG).run()\n}\n"]}
@@ -1,4 +1,4 @@
1
- import type { CommandFn, CommandUsage } from '../index.ts';
1
+ import type { CommandFn, CommandUsage } from '../load-command.ts';
2
2
  export declare const usage: CommandUsage;
3
3
  export declare const command: CommandFn<string>;
4
4
  //# sourceMappingURL=help.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"help.d.ts","sourceRoot":"","sources":["../../../src/commands/help.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAE1D,eAAO,MAAM,KAAK,EAAE,YAKhB,CAAA;AAEJ,eAAO,MAAM,OAAO,EAAE,SAAS,CAAC,MAAM,CAErC,CAAA"}
1
+ {"version":3,"file":"help.d.ts","sourceRoot":"","sources":["../../../src/commands/help.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAQjE,eAAO,MAAM,KAAK,EAAE,YAWhB,CAAA;AAEJ,eAAO,MAAM,OAAO,EAAE,SAAS,CAAC,MAAM,CA0BrC,CAAA"}
@@ -1,10 +1,39 @@
1
+ import { error } from '@vltpkg/error-cause';
1
2
  import { commandUsage } from "../config/usage.js";
3
+ import { loadCommand } from "../load-command.js";
4
+ import { getCommand } from "../config/definition.js";
5
+ import { generateDefaultHelp, generateFullHelp, } from "../custom-help.js";
2
6
  export const usage = () => commandUsage({
3
7
  command: 'help',
4
- usage: '',
5
- description: 'Print the full help output for the CLI',
8
+ usage: '[<command>]',
9
+ description: 'Print the full help output for the CLI, or help for a specific command',
10
+ examples: {
11
+ '': { description: 'Show general CLI help' },
12
+ install: { description: 'Show help for the install command' },
13
+ run: { description: 'Show help for the run command' },
14
+ },
6
15
  });
7
16
  export const command = async (conf) => {
8
- return conf.jack.usage();
17
+ // If no positional arguments, show general help
18
+ if (conf.positionals.length === 0) {
19
+ // Check for color support (prefer explicit config, fall back to TTY detection)
20
+ const colors = conf.values.color ?? process.stdout.isTTY;
21
+ // Use full custom help if --all flag is set
22
+ if (conf.values.all) {
23
+ return generateFullHelp(colors);
24
+ }
25
+ return generateDefaultHelp(colors);
26
+ }
27
+ // Get the command name from the first positional argument
28
+ const cmdName = conf.positionals[0];
29
+ const canonicalCmd = getCommand(cmdName);
30
+ if (!canonicalCmd) {
31
+ throw error(`Unknown command: ${cmdName}`, {
32
+ found: cmdName,
33
+ code: 'EUSAGE',
34
+ });
35
+ }
36
+ const command = await loadCommand(canonicalCmd);
37
+ return command.usage().usage();
9
38
  };
10
39
  //# sourceMappingURL=help.js.map