@vltpkg/cli-sdk 0.0.0-2 → 0.0.0-21

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 (153) hide show
  1. package/README.md +3 -0
  2. package/dist/esm/commands/cache.d.ts +65 -0
  3. package/dist/esm/commands/cache.d.ts.map +1 -0
  4. package/dist/esm/commands/cache.js +257 -0
  5. package/dist/esm/commands/cache.js.map +1 -0
  6. package/dist/esm/commands/ci.d.ts +10 -0
  7. package/dist/esm/commands/ci.d.ts.map +1 -0
  8. package/dist/esm/commands/ci.js +29 -0
  9. package/dist/esm/commands/ci.js.map +1 -0
  10. package/dist/esm/commands/config.d.ts.map +1 -1
  11. package/dist/esm/commands/config.js +2 -52
  12. package/dist/esm/commands/config.js.map +1 -1
  13. package/dist/esm/commands/exec-cache.d.ts +49 -0
  14. package/dist/esm/commands/exec-cache.d.ts.map +1 -0
  15. package/dist/esm/commands/exec-cache.js +134 -0
  16. package/dist/esm/commands/exec-cache.js.map +1 -0
  17. package/dist/esm/commands/exec-local.d.ts +6 -0
  18. package/dist/esm/commands/exec-local.d.ts.map +1 -0
  19. package/dist/esm/commands/exec-local.js +24 -0
  20. package/dist/esm/commands/exec-local.js.map +1 -0
  21. package/dist/esm/commands/exec.d.ts +4 -0
  22. package/dist/esm/commands/exec.d.ts.map +1 -1
  23. package/dist/esm/commands/exec.js +69 -10
  24. package/dist/esm/commands/exec.js.map +1 -1
  25. package/dist/esm/commands/gui.d.ts.map +1 -1
  26. package/dist/esm/commands/gui.js +1 -2
  27. package/dist/esm/commands/gui.js.map +1 -1
  28. package/dist/esm/commands/help.d.ts +1 -1
  29. package/dist/esm/commands/help.d.ts.map +1 -1
  30. package/dist/esm/commands/help.js +25 -3
  31. package/dist/esm/commands/help.js.map +1 -1
  32. package/dist/esm/commands/init.d.ts +4 -5
  33. package/dist/esm/commands/init.d.ts.map +1 -1
  34. package/dist/esm/commands/init.js +95 -9
  35. package/dist/esm/commands/init.js.map +1 -1
  36. package/dist/esm/commands/install/reporter.d.ts.map +1 -1
  37. package/dist/esm/commands/install/reporter.js +2 -1
  38. package/dist/esm/commands/install/reporter.js.map +1 -1
  39. package/dist/esm/commands/install.d.ts +5 -2
  40. package/dist/esm/commands/install.d.ts.map +1 -1
  41. package/dist/esm/commands/install.js +7 -1
  42. package/dist/esm/commands/install.js.map +1 -1
  43. package/dist/esm/commands/list.d.ts +2 -2
  44. package/dist/esm/commands/list.d.ts.map +1 -1
  45. package/dist/esm/commands/list.js +108 -31
  46. package/dist/esm/commands/list.js.map +1 -1
  47. package/dist/esm/commands/pack.d.ts +20 -0
  48. package/dist/esm/commands/pack.d.ts.map +1 -0
  49. package/dist/esm/commands/pack.js +81 -0
  50. package/dist/esm/commands/pack.js.map +1 -0
  51. package/dist/esm/commands/pkg.d.ts +2 -3
  52. package/dist/esm/commands/pkg.d.ts.map +1 -1
  53. package/dist/esm/commands/pkg.js +136 -34
  54. package/dist/esm/commands/pkg.js.map +1 -1
  55. package/dist/esm/commands/publish.d.ts +21 -0
  56. package/dist/esm/commands/publish.d.ts.map +1 -0
  57. package/dist/esm/commands/publish.js +169 -0
  58. package/dist/esm/commands/publish.js.map +1 -0
  59. package/dist/esm/commands/query.d.ts +2 -2
  60. package/dist/esm/commands/query.d.ts.map +1 -1
  61. package/dist/esm/commands/query.js +134 -21
  62. package/dist/esm/commands/query.js.map +1 -1
  63. package/dist/esm/commands/run-exec.d.ts +1 -0
  64. package/dist/esm/commands/run-exec.d.ts.map +1 -1
  65. package/dist/esm/commands/run-exec.js +1 -0
  66. package/dist/esm/commands/run-exec.js.map +1 -1
  67. package/dist/esm/commands/run.d.ts +1 -0
  68. package/dist/esm/commands/run.d.ts.map +1 -1
  69. package/dist/esm/commands/run.js +13 -16
  70. package/dist/esm/commands/run.js.map +1 -1
  71. package/dist/esm/commands/uninstall.d.ts +7 -1
  72. package/dist/esm/commands/uninstall.d.ts.map +1 -1
  73. package/dist/esm/commands/uninstall.js +7 -1
  74. package/dist/esm/commands/uninstall.js.map +1 -1
  75. package/dist/esm/commands/update.d.ts +10 -0
  76. package/dist/esm/commands/update.d.ts.map +1 -0
  77. package/dist/esm/commands/update.js +25 -0
  78. package/dist/esm/commands/update.js.map +1 -0
  79. package/dist/esm/commands/version.d.ts +22 -0
  80. package/dist/esm/commands/version.d.ts.map +1 -0
  81. package/dist/esm/commands/version.js +151 -0
  82. package/dist/esm/commands/version.js.map +1 -0
  83. package/dist/esm/commands/whoami.d.ts +4 -2
  84. package/dist/esm/commands/whoami.d.ts.map +1 -1
  85. package/dist/esm/commands/whoami.js +1 -1
  86. package/dist/esm/commands/whoami.js.map +1 -1
  87. package/dist/esm/config/definition.d.ts +85 -7
  88. package/dist/esm/config/definition.d.ts.map +1 -1
  89. package/dist/esm/config/definition.js +152 -23
  90. package/dist/esm/config/definition.js.map +1 -1
  91. package/dist/esm/config/index.d.ts +46 -40
  92. package/dist/esm/config/index.d.ts.map +1 -1
  93. package/dist/esm/config/index.js +124 -176
  94. package/dist/esm/config/index.js.map +1 -1
  95. package/dist/esm/config/merge.d.ts +3 -1
  96. package/dist/esm/config/merge.d.ts.map +1 -1
  97. package/dist/esm/config/merge.js +11 -6
  98. package/dist/esm/config/merge.js.map +1 -1
  99. package/dist/esm/config/usage.d.ts +3 -2
  100. package/dist/esm/config/usage.d.ts.map +1 -1
  101. package/dist/esm/config/usage.js.map +1 -1
  102. package/dist/esm/exec-command.d.ts +32 -14
  103. package/dist/esm/exec-command.d.ts.map +1 -1
  104. package/dist/esm/exec-command.js +195 -63
  105. package/dist/esm/exec-command.js.map +1 -1
  106. package/dist/esm/index.d.ts +1 -14
  107. package/dist/esm/index.d.ts.map +1 -1
  108. package/dist/esm/index.js +46 -20
  109. package/dist/esm/index.js.map +1 -1
  110. package/dist/esm/load-command.d.ts +16 -0
  111. package/dist/esm/load-command.d.ts.map +1 -0
  112. package/dist/esm/load-command.js +21 -0
  113. package/dist/esm/load-command.js.map +1 -0
  114. package/dist/esm/output.d.ts +6 -10
  115. package/dist/esm/output.d.ts.map +1 -1
  116. package/dist/esm/output.js +62 -32
  117. package/dist/esm/output.js.map +1 -1
  118. package/dist/esm/pack-tarball.d.ts +22 -0
  119. package/dist/esm/pack-tarball.d.ts.map +1 -0
  120. package/dist/esm/pack-tarball.js +247 -0
  121. package/dist/esm/pack-tarball.js.map +1 -0
  122. package/dist/esm/parse-add-remove-args.d.ts +1 -1
  123. package/dist/esm/parse-add-remove-args.d.ts.map +1 -1
  124. package/dist/esm/parse-add-remove-args.js +1 -1
  125. package/dist/esm/parse-add-remove-args.js.map +1 -1
  126. package/dist/esm/print-err.d.ts +12 -1
  127. package/dist/esm/print-err.d.ts.map +1 -1
  128. package/dist/esm/print-err.js +157 -26
  129. package/dist/esm/print-err.js.map +1 -1
  130. package/dist/esm/start-gui.d.ts +7 -33
  131. package/dist/esm/start-gui.d.ts.map +1 -1
  132. package/dist/esm/start-gui.js +33 -347
  133. package/dist/esm/start-gui.js.map +1 -1
  134. package/dist/esm/view.d.ts +2 -3
  135. package/dist/esm/view.d.ts.map +1 -1
  136. package/dist/esm/view.js.map +1 -1
  137. package/package.json +69 -44
  138. package/dist/esm/commands/install-exec.d.ts +0 -4
  139. package/dist/esm/commands/install-exec.d.ts.map +0 -1
  140. package/dist/esm/commands/install-exec.js +0 -13
  141. package/dist/esm/commands/install-exec.js.map +0 -1
  142. package/dist/esm/ignored-homedir-folder-names.d.ts +0 -7
  143. package/dist/esm/ignored-homedir-folder-names.d.ts.map +0 -1
  144. package/dist/esm/ignored-homedir-folder-names.js +0 -35
  145. package/dist/esm/ignored-homedir-folder-names.js.map +0 -1
  146. package/dist/esm/project-info.d.ts +0 -32
  147. package/dist/esm/project-info.d.ts.map +0 -1
  148. package/dist/esm/project-info.js +0 -90
  149. package/dist/esm/project-info.js.map +0 -1
  150. package/dist/esm/read-project-folders.d.ts +0 -27
  151. package/dist/esm/read-project-folders.d.ts.map +0 -1
  152. package/dist/esm/read-project-folders.js +0 -66
  153. package/dist/esm/read-project-folders.js.map +0 -1
@@ -1,36 +1,10 @@
1
- import type { AddImportersDependenciesMap, InstallOptions, RemoveImportersDependenciesMap, UninstallOptions } from '@vltpkg/graph';
2
- import type { PackageJson } from '@vltpkg/package-json';
3
- import type { SpecOptions } from '@vltpkg/spec';
4
- import type { DependencyTypeShort } from '@vltpkg/types';
5
- import type { IncomingMessage, Server, ServerResponse } from 'node:http';
6
- import type { PathBase, PathScurry } from 'path-scurry';
1
+ import type { PathScurry } from 'path-scurry';
7
2
  import type { LoadedConfig } from './config/index.ts';
8
- import type { DashboardProjectData } from './project-info.ts';
9
- export type GUIInstallOptions = Record<string, Record<string, {
10
- version: string;
11
- type: DependencyTypeShort;
12
- }>>;
13
- export type GUIUninstallOptions = Record<string, Set<string>>;
14
- export type StartGUIOptions = {
15
- assetsDir?: string;
16
- conf: LoadedConfig;
17
- port?: number;
3
+ export declare const getDefaultStartingRoute: (options: {
4
+ queryString?: string;
18
5
  startingRoute?: string;
19
- tmpDir?: string;
20
- };
21
- export type DashboardLocation = {
22
- path: string;
23
- readablePath: string;
24
- };
25
- export type DashboardData = {
26
- cwd: string;
27
- buildVersion: string;
28
- dashboardProjectLocations: DashboardLocation[];
29
- defaultAuthor: string;
30
- projects: DashboardProjectData[];
31
- };
32
- export declare const parseInstallOptions: (options: InstallOptions & SpecOptions, args: GUIInstallOptions) => [InstallOptions, AddImportersDependenciesMap];
33
- export declare const parseUninstallOptions: (options: UninstallOptions, args: GUIUninstallOptions) => [UninstallOptions, RemoveImportersDependenciesMap];
34
- export declare const formatDashboardJson: (projectFolders: PathBase[], dashboardRoot: string[], scurry: PathScurry, packageJson: PackageJson) => Promise<DashboardData>;
35
- export declare const startGUI: ({ conf, assetsDir, port, startingRoute, tmpDir, }: StartGUIOptions) => Promise<Server<typeof IncomingMessage, typeof ServerResponse>>;
6
+ projectRoot: string;
7
+ scurry: PathScurry;
8
+ }) => Promise<string>;
9
+ export declare const startGUI: (conf: LoadedConfig, startingRoute?: string) => Promise<import("@vltpkg/server").VltServer>;
36
10
  //# sourceMappingURL=start-gui.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"start-gui.d.ts","sourceRoot":"","sources":["../../src/start-gui.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAEV,2BAA2B,EAE3B,cAAc,EACd,8BAA8B,EAC9B,gBAAgB,EACjB,MAAM,eAAe,CAAA;AAQtB,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AACvD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAE/C,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAA;AAUxD,OAAO,KAAK,EACV,eAAe,EACf,MAAM,EACN,cAAc,EACf,MAAM,WAAW,CAAA;AAMlB,OAAO,KAAK,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAEvD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAErD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAA;AAkB7D,MAAM,MAAM,iBAAiB,GAAG,MAAM,CACpC,MAAM,EACN,MAAM,CAAC,MAAM,EAAE;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,mBAAmB,CAAA;CAAE,CAAC,CAC/D,CAAA;AAED,MAAM,MAAM,mBAAmB,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,CAAA;AAE7D,MAAM,MAAM,eAAe,GAAG;IAC5B,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,IAAI,EAAE,YAAY,CAAA;IAClB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB,CAAA;AAED,MAAM,MAAM,iBAAiB,GAAG;IAC9B,IAAI,EAAE,MAAM,CAAA;IACZ,YAAY,EAAE,MAAM,CAAA;CACrB,CAAA;AAED,MAAM,MAAM,aAAa,GAAG;IAC1B,GAAG,EAAE,MAAM,CAAA;IACX,YAAY,EAAE,MAAM,CAAA;IACpB,yBAAyB,EAAE,iBAAiB,EAAE,CAAA;IAC9C,aAAa,EAAE,MAAM,CAAA;IACrB,QAAQ,EAAE,oBAAoB,EAAE,CAAA;CACjC,CAAA;AAgBD,eAAO,MAAM,mBAAmB,YACrB,cAAc,GAAG,WAAW,QAC/B,iBAAiB,KACtB,CAAC,cAAc,EAAE,2BAA2B,CAiB9C,CAAA;AAED,eAAO,MAAM,qBAAqB,YACvB,gBAAgB,QACnB,mBAAmB,KACxB,CAAC,gBAAgB,EAAE,8BAA8B,CAWnD,CAAA;AAED,eAAO,MAAM,mBAAmB,mBACd,QAAQ,EAAE,iBACX,MAAM,EAAE,UACf,UAAU,eACL,WAAW,2BA6CzB,CAAA;AAqLD,eAAO,MAAM,QAAQ,sDAMlB,eAAe,mEAwLjB,CAAA"}
1
+ {"version":3,"file":"start-gui.d.ts","sourceRoot":"","sources":["../../src/start-gui.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAC7C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAGrD,eAAO,MAAM,uBAAuB,YAAmB;IACrD,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,WAAW,EAAE,MAAM,CAAA;IACnB,MAAM,EAAE,UAAU,CAAA;CACnB,oBAYA,CAAA;AAaD,eAAO,MAAM,QAAQ,SACb,YAAY,kBACF,MAAM,gDAyBvB,CAAA"}
@@ -1,357 +1,43 @@
1
- import { asDepID } from '@vltpkg/dep-id';
2
- import { getUser } from '@vltpkg/git';
3
- import { actual, asDependency, install, uninstall, } from '@vltpkg/graph';
4
- import { getAuthorFromGitUser, init } from '@vltpkg/init';
5
- import { Spec } from '@vltpkg/spec';
1
+ import { resolve } from 'node:path';
2
+ import LZString from 'lz-string';
3
+ import { createServer } from '@vltpkg/server';
6
4
  import { urlOpen } from '@vltpkg/url-open';
7
- import assert from 'node:assert';
8
- import { mkdirSync, readdirSync, readFileSync, rmSync, writeFileSync, } from 'node:fs';
9
- import { createServer, request } from 'node:http';
10
- import { homedir, tmpdir } from 'node:os';
11
- import { dirname, relative, resolve } from 'node:path';
12
- import { fileURLToPath } from 'node:url';
13
- import { loadPackageJson } from 'package-json-from-dist';
14
- import handler from 'serve-handler';
15
- import { stderr, stdout } from "./output.js";
16
- import { getDashboardProjectData, getGraphProjectData, getReadablePath, } from "./project-info.js";
17
- import { readProjectFolders } from "./read-project-folders.js";
18
- const HOST = 'localhost';
19
- const PORT = 7017;
20
- const { version } = loadPackageJson(import.meta.filename, process.env.__VLT_INTERNAL_CLI_PACKAGE_JSON);
21
- class AddImportersDependenciesMapImpl extends Map {
22
- modifiedDependencies = false;
23
- }
24
- class RemoveImportersDependenciesMapImpl extends Map {
25
- modifiedDependencies = false;
26
- }
27
- export const parseInstallOptions = (options, args) => {
28
- const addArgs = new AddImportersDependenciesMapImpl();
29
- for (const [importerId, deps] of Object.entries(args)) {
30
- const depMap = new Map();
31
- for (const [name, { version, type }] of Object.entries(deps)) {
32
- depMap.set(name, asDependency({
33
- spec: Spec.parse(name, version, options),
34
- type,
35
- }));
36
- addArgs.modifiedDependencies = true;
37
- }
38
- addArgs.set(asDepID(importerId), depMap);
39
- }
40
- return [options, addArgs];
41
- };
42
- export const parseUninstallOptions = (options, args) => {
43
- const removeArgs = new RemoveImportersDependenciesMapImpl();
44
- for (const [importerId, deps] of Object.entries(args)) {
45
- const depMap = new Set();
46
- for (const name of deps) {
47
- depMap.add(name);
48
- }
49
- removeArgs.set(asDepID(importerId), depMap);
50
- removeArgs.modifiedDependencies = true;
51
- }
52
- return [options, removeArgs];
53
- };
54
- export const formatDashboardJson = async (projectFolders, dashboardRoot, scurry, packageJson) => {
55
- const userDefinedProjectPaths = (dashboardRoot.length ? dashboardRoot : [homedir()]).map(path => ({
56
- path,
57
- readablePath: getReadablePath(path),
58
- }));
59
- const result = {
60
- cwd: process.cwd(),
61
- buildVersion: version,
62
- dashboardProjectLocations: projectFolders
63
- .map((dir) => {
64
- const path = dirname(dir.fullpath());
65
- const res = {
66
- path,
67
- readablePath: getReadablePath(path),
68
- };
69
- return res;
70
- })
71
- .concat(userDefinedProjectPaths)
72
- .reduce((acc, curr) => {
73
- if (acc.every(obj => obj.path !== curr.path)) {
74
- acc.push(curr);
75
- }
76
- return acc;
77
- }, [])
78
- .sort((a, b) => a.readablePath.length - b.readablePath.length),
79
- defaultAuthor: getAuthorFromGitUser(await getUser().catch(() => undefined)),
80
- projects: [],
81
- };
82
- for (const folder of projectFolders) {
83
- const projectData = getDashboardProjectData(folder, {
84
- scurry,
85
- packageJson,
86
- });
87
- if (projectData) {
88
- result.projects.push(projectData);
89
- }
90
- }
91
- return result;
92
- };
93
- const updateGraphData = (tmp, options, hasDashboard) => {
94
- const { packageJson, projectRoot, scurry } = options;
95
- const mainManifest = packageJson.read(projectRoot);
96
- const graph = actual.load({
97
- ...options,
98
- mainManifest,
99
- loadManifests: true,
100
- });
101
- const importers = [...graph.importers];
102
- const folder = scurry.lstatSync(projectRoot);
103
- const graphJson = JSON.stringify({
104
- hasDashboard,
105
- importers,
106
- lockfile: graph,
107
- projectInfo: getGraphProjectData({ packageJson, scurry }, folder),
108
- }, null, 2);
109
- rmSync(resolve(tmp, 'graph.json'), { force: true });
110
- writeFileSync(resolve(tmp, 'graph.json'), graphJson);
111
- };
112
- const updateDashboardData = async (tmp, options) => {
113
- const { 'dashboard-root': userDefinedProjectPaths = [], scurry, packageJson, } = options;
114
- const dashboard = await formatDashboardJson(await readProjectFolders({
115
- scurry,
116
- userDefinedProjectPaths,
117
- }), userDefinedProjectPaths, scurry, packageJson);
118
- const dashboardJson = JSON.stringify(dashboard, null, 2);
119
- writeFileSync(resolve(tmp, 'dashboard.json'), dashboardJson);
120
- return dashboard.projects.length > 0;
121
- };
122
- const getDefaultStartingRoute = (options) => {
123
- const { projectRoot, scurry } = options;
124
- const stat = scurry.lstatSync(`${projectRoot}/package.json`);
5
+ import { stdout } from "./output.js";
6
+ export const getDefaultStartingRoute = async (options) => {
7
+ const { queryString = ':root', startingRoute, projectRoot, scurry, } = options;
8
+ if (startingRoute)
9
+ return startingRoute;
10
+ const stat = await scurry.lstat(`${projectRoot}/package.json`);
125
11
  return stat?.isFile() && !stat.isSymbolicLink() ?
126
- `/explore?query=${encodeURIComponent(':root')}`
127
- : '/dashboard';
128
- };
129
- /* c8 ignore start */
130
- const createStaticHandler = ({ assetsDir, publicDir, }) => {
131
- const opts = {
132
- cleanUrls: true,
133
- public: publicDir,
134
- rewrites: [
135
- { source: '/', destination: '/index.html' },
136
- { source: '/error', destination: '/index.html' },
137
- { source: '/explore', destination: '/index.html' },
138
- { source: '/dashboard', destination: '/index.html' },
139
- { source: '/queries', destination: '/index.html' },
140
- { source: '/labels', destination: '/index.html' },
141
- { source: '/new-project', destination: '/index.html' },
142
- ],
143
- };
144
- const errHandler = (err, res) => {
145
- stderr(err);
146
- res.statusCode = 500;
147
- res.end('Internal server error');
148
- };
149
- const staticHandler = (req, res) => handler(req, res, opts).catch((err) => errHandler(err, res));
150
- // It's important for this guard to check to not be destructured
151
- // because `infra/build` will replace the whole thing with `false`
152
- // causing it to be stripped entirely from production builds.
153
- if (process.env.__VLT_INTERNAL_LIVE_RELOAD) {
154
- // Generate a set of routes that should be proxied to the esbuild server
155
- const proxyRoutes = new Set([
156
- // `/esbuild` is an SSE endpoint served by esbuild
157
- 'esbuild',
158
- // Also proxy anything that currently exists in the assets dir
159
- ...readdirSync(assetsDir, {
160
- withFileTypes: true,
161
- recursive: true,
162
- })
163
- .filter(f => f.isFile())
164
- .map(f => relative(assetsDir, resolve(f.parentPath, f.name))),
165
- ].map(p => `/${p}`));
166
- return (req, res) => req.url && proxyRoutes.has(req.url) ?
167
- void req.pipe(request({
168
- hostname: HOST,
169
- port: 7018,
170
- path: req.url,
171
- method: req.method,
172
- headers: req.headers,
173
- }, proxy => {
174
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
175
- res.writeHead(proxy.statusCode, proxy.headers);
176
- proxy.pipe(res, { end: true });
177
- }).on('error', err => {
178
- // If we get an ECONNREFUSED error, fallback to the static handler
179
- // since the esbuild server is not running
180
- if (err instanceof Error &&
181
- 'code' in err &&
182
- err.code === 'ECONNREFUSED') {
183
- // In this case the /esbuild route is expected to fail so the
184
- // EventSource in the browser will be closed
185
- if (req.url === '/esbuild') {
186
- res.statusCode = 404;
187
- return res.end();
188
- }
189
- return staticHandler(req, res);
190
- }
191
- errHandler(err, res);
192
- }), { end: true })
193
- : staticHandler(req, res);
194
- }
195
- return staticHandler;
12
+ `/explore/${LZString.compressToEncodedURIComponent(queryString)}/overview`
13
+ : '/';
196
14
  };
197
- /* c8 ignore start */
198
15
  const getAssetsDir = () => {
199
- const fromEnv = process.env.__VLT_INTERNAL_GUI_ASSETS_DIR;
200
- // workaround for the import.meta.resolve issue not working with tap
201
- if (process.env.TAP) {
202
- assert(fromEnv, 'assets dir must be set from environment variable when running tests');
16
+ /* c8 ignore start */
17
+ if (process.env.__VLT_INTERNAL_GUI_ASSETS_DIR) {
18
+ return resolve(import.meta.dirname, process.env.__VLT_INTERNAL_GUI_ASSETS_DIR);
203
19
  }
204
- if (fromEnv) {
205
- return resolve(import.meta.dirname, fromEnv);
206
- }
207
- return fileURLToPath(import.meta.resolve('@vltpkg/gui'));
20
+ /* c8 ignore stop */
208
21
  };
209
- /* c8 ignore stop */
210
- export const startGUI = async ({ conf, assetsDir = getAssetsDir(), port = PORT, startingRoute = undefined, tmpDir = tmpdir(), }) => {
211
- const tmp = resolve(tmpDir, 'vltgui');
212
- rmSync(tmp, { recursive: true, force: true });
213
- mkdirSync(tmp, { recursive: true });
214
- // This is the same as `cpSync(assetsDir, tmp, { recursive: true })`
215
- // but that does not work in Deno yet (https://github.com/denoland/deno/issues/27494).
216
- for (const asset of readdirSync(assetsDir, {
217
- withFileTypes: true,
218
- recursive: true,
219
- })) {
220
- if (!asset.isFile())
221
- continue;
222
- const source = resolve(asset.parentPath, asset.name);
223
- const target = resolve(tmp, relative(assetsDir, source));
224
- mkdirSync(dirname(target), { recursive: true });
225
- writeFileSync(target, readFileSync(source));
226
- }
227
- // dashboard data is optional since the GUI might be started from a
228
- // project in order to just explore its graph data
229
- let hasDashboard = false;
230
- const { scurry, 'dashboard-root': dashboardRoot, packageJson, } = conf.options;
231
- const updateDashboard = async () => {
232
- try {
233
- hasDashboard = await updateDashboardData(tmp, {
234
- scurry,
235
- 'dashboard-root': dashboardRoot,
236
- packageJson,
237
- });
238
- /* c8 ignore next */
239
- }
240
- catch { }
241
- if (!hasDashboard) {
242
- rmSync(resolve(tmp, 'dashboard.json'), { force: true });
243
- }
244
- };
245
- await updateDashboard();
246
- // reading graph data is optional since the command might be run from a
247
- // parend directory of any given project root, in which case the GUI is
248
- // going to render only the dashboard to start with
249
- try {
250
- updateGraphData(tmp, conf.options, hasDashboard);
251
- }
252
- catch {
253
- rmSync(resolve(tmp, 'graph.json'), { force: true });
254
- }
255
- const staticHandler = createStaticHandler({
256
- publicDir: tmp,
257
- assetsDir,
22
+ export const startGUI = async (conf, startingRoute) => {
23
+ const server = createServer({
24
+ ...conf.options,
25
+ assetsDir: getAssetsDir(),
26
+ loadedConfig: conf,
258
27
  });
259
- const server = createServer(async (req, res) => {
260
- const json = () => new Promise(resolve => {
261
- req.setEncoding('utf8');
262
- let json = '';
263
- req.on('data', (d) => (json += d));
264
- req.on('end', () => resolve(JSON.parse(json)));
265
- });
266
- const jsonError = (errType, err, code) => {
267
- stderr(err);
268
- res.statusCode = code;
269
- res.end(JSON.stringify(`${errType}\n${err}`));
270
- };
271
- const jsonOk = (result) => {
272
- res.writeHead(200, { 'Content-Type': 'application/json' });
273
- res.end(JSON.stringify(result));
274
- };
275
- switch (`${req.method} ${req.url}`) {
276
- case 'POST /select-project': {
277
- const data = await json();
278
- conf.resetOptions(String(data.path));
279
- await updateDashboard();
280
- updateGraphData(tmp, conf.options, hasDashboard);
281
- return jsonOk('ok');
282
- }
283
- case 'POST /create-project': {
284
- const data = await json();
285
- if (typeof data.path !== 'string') {
286
- return jsonError('Bad request.', 'Project path must be a string', 400);
287
- }
288
- if (!/^[a-z0-9-]+$/.test(String(data.name)) ||
289
- String(data.name).length > 128) {
290
- return jsonError('Bad request.', 'Project name must be lowercase, alphanumeric, and may contain hyphens', 400);
291
- }
292
- const path = String(data.path);
293
- const name = String(data.name);
294
- const author = String(data.author);
295
- try {
296
- const cwd = resolve(path, name);
297
- mkdirSync(cwd, { recursive: true });
298
- await init({ cwd, author });
299
- conf.resetOptions(cwd);
300
- await install(conf.options);
301
- conf.resetOptions(conf.options.projectRoot);
302
- await updateDashboard();
303
- updateGraphData(tmp, conf.options, hasDashboard);
304
- }
305
- catch (err) {
306
- // eslint-disable-next-line no-console
307
- console.error(err);
308
- return jsonError('CLI Error', err.message, 500);
309
- }
310
- return jsonOk('ok');
311
- }
312
- case `POST /install`: {
313
- const { add } = await json();
314
- if (!add) {
315
- return jsonError('Bad request.', 'GUI install endpoint called without add argument', 400);
316
- }
317
- try {
318
- await install(...parseInstallOptions(conf.options, add));
319
- conf.resetOptions(conf.options.projectRoot);
320
- updateGraphData(tmp, conf.options, hasDashboard);
321
- return jsonOk('ok');
322
- }
323
- catch (err) {
324
- return jsonError('Install failed', err, 500);
325
- }
326
- }
327
- case `POST /uninstall`: {
328
- const { remove } = await json();
329
- if (!remove) {
330
- return jsonError('Bad request.', 'GUI uninstall endpoint called with no arguments', 400);
331
- }
332
- try {
333
- await uninstall(...parseUninstallOptions(conf.options, remove));
334
- conf.resetOptions(conf.options.projectRoot);
335
- updateGraphData(tmp, conf.options, hasDashboard);
336
- return jsonOk('ok');
337
- }
338
- catch (err) {
339
- return jsonError('Uninstall failed', err, 500);
340
- }
341
- }
342
- /* c8 ignore next 3 */
343
- default: {
344
- return staticHandler(req, res);
345
- }
346
- }
347
- });
348
- return new Promise(res => {
349
- const route = startingRoute || getDefaultStartingRoute(conf.options);
350
- server.listen(port, 'localhost', () => {
351
- stdout(`⚡️ vlt GUI running at http://${HOST}:${port}`);
352
- void urlOpen(`http://${HOST}:${port}${route}`);
353
- res(server);
354
- });
28
+ server.on('needConfigUpdate', dir => {
29
+ conf.resetOptions(dir);
30
+ server.updateOptions(conf.options);
355
31
  });
32
+ const { projectRoot, scurry } = conf.options;
33
+ await server.start();
34
+ stdout(`⚡️ vlt GUI running at ${server.address()}`);
35
+ void urlOpen(server.address(await getDefaultStartingRoute({
36
+ queryString: conf.values.target,
37
+ startingRoute,
38
+ projectRoot,
39
+ scurry,
40
+ })));
41
+ return server;
356
42
  };
357
43
  //# sourceMappingURL=start-gui.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"start-gui.js","sourceRoot":"","sources":["../../src/start-gui.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAA;AACxC,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AASrC,OAAO,EACL,MAAM,EACN,YAAY,EACZ,OAAO,EACP,SAAS,GACV,MAAM,eAAe,CAAA;AACtB,OAAO,EAAE,oBAAoB,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AAGzD,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AAEnC,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA;AAC1C,OAAO,MAAM,MAAM,aAAa,CAAA;AAChC,OAAO,EACL,SAAS,EACT,WAAW,EACX,YAAY,EACZ,MAAM,EACN,aAAa,GACd,MAAM,SAAS,CAAA;AAMhB,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACjD,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AACzC,OAAO,EAAE,OAAO,EAAE,QAAQ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YAAY,CAAC,CAAA;oBAChD,OAAO,MAAM,CAAC,IAAI,CAAC,CAAA;gBACrB,CAAC;gBAAC,OAAO,GAAG,EAAE,CAAC;oBACb,OAAO,SAAS,CAAC,kBAAkB,EAAE,GAAG,EAAE,GAAG,CAAC,CAAA;gBAChD,CAAC;YACH,CAAC;YACD,sBAAsB;YACtB,OAAO,CAAC,CAAC,CAAC;gBACR,OAAO,aAAa,CAAC,GAAG,EAAE,GAAG,CAAC,CAAA;YAChC,CAAC;QACH,CAAC;IACH,CAAC,CAAC,CAAA;IAEF,OAAO,IAAI,OAAO,CAAS,GAAG,CAAC,EAAE;QAC/B,MAAM,KAAK,GACT,aAAa,IAAI,uBAAuB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;QACxD,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,WAAW,EAAE,GAAG,EAAE;YACpC,MAAM,CAAC,gCAAgC,IAAI,IAAI,IAAI,EAAE,CAAC,CAAA;YACtD,KAAK,OAAO,CAAC,UAAU,IAAI,IAAI,IAAI,GAAG,KAAK,EAAE,CAAC,CAAA;YAC9C,GAAG,CAAC,MAAM,CAAC,CAAA;QACb,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC,CAAA","sourcesContent":["import { asDepID } from '@vltpkg/dep-id'\nimport { getUser } from '@vltpkg/git'\nimport type {\n ActualLoadOptions,\n AddImportersDependenciesMap,\n Dependency,\n InstallOptions,\n RemoveImportersDependenciesMap,\n UninstallOptions,\n} from '@vltpkg/graph'\nimport {\n actual,\n asDependency,\n install,\n uninstall,\n} from '@vltpkg/graph'\nimport { getAuthorFromGitUser, init } from '@vltpkg/init'\nimport type { PackageJson } from '@vltpkg/package-json'\nimport type { SpecOptions } from '@vltpkg/spec'\nimport { Spec } from '@vltpkg/spec'\nimport type { DependencyTypeShort } from '@vltpkg/types'\nimport { urlOpen } from '@vltpkg/url-open'\nimport assert from 'node:assert'\nimport {\n mkdirSync,\n readdirSync,\n readFileSync,\n rmSync,\n writeFileSync,\n} from 'node:fs'\nimport type {\n IncomingMessage,\n Server,\n ServerResponse,\n} from 'node:http'\nimport { createServer, request } from 'node:http'\nimport { homedir, tmpdir } from 'node:os'\nimport { dirname, relative, resolve } from 'node:path'\nimport { fileURLToPath } from 'node:url'\nimport { loadPackageJson } from 'package-json-from-dist'\nimport type { PathBase, PathScurry } from 'path-scurry'\nimport handler from 'serve-handler'\nimport type { LoadedConfig } from './config/index.ts'\nimport { stderr, stdout } from './output.ts'\nimport type { DashboardProjectData } from './project-info.ts'\nimport {\n getDashboardProjectData,\n getGraphProjectData,\n getReadablePath,\n} from './project-info.ts'\nimport { readProjectFolders } from './read-project-folders.ts'\n\nconst HOST = 'localhost'\nconst PORT = 7017\n\nconst { version } = loadPackageJson(\n import.meta.filename,\n process.env.__VLT_INTERNAL_CLI_PACKAGE_JSON,\n) as {\n version: string\n}\n\nexport type GUIInstallOptions = Record<\n string,\n Record<string, { version: string; type: DependencyTypeShort }>\n>\n\nexport type GUIUninstallOptions = Record<string, Set<string>>\n\nexport type StartGUIOptions = {\n assetsDir?: string\n conf: LoadedConfig\n port?: number\n startingRoute?: string\n tmpDir?: string\n}\n\nexport type DashboardLocation = {\n path: string\n readablePath: string\n}\n\nexport type DashboardData = {\n cwd: string\n buildVersion: string\n dashboardProjectLocations: DashboardLocation[]\n defaultAuthor: string\n projects: DashboardProjectData[]\n}\n\nclass AddImportersDependenciesMapImpl\n extends Map\n implements AddImportersDependenciesMap\n{\n modifiedDependencies = false\n}\n\nclass RemoveImportersDependenciesMapImpl\n extends Map\n implements RemoveImportersDependenciesMap\n{\n modifiedDependencies = false\n}\n\nexport const parseInstallOptions = (\n options: InstallOptions & SpecOptions,\n args: GUIInstallOptions,\n): [InstallOptions, AddImportersDependenciesMap] => {\n const addArgs = new AddImportersDependenciesMapImpl()\n for (const [importerId, deps] of Object.entries(args)) {\n const depMap = new Map<string, Dependency>()\n for (const [name, { version, type }] of Object.entries(deps)) {\n depMap.set(\n name,\n asDependency({\n spec: Spec.parse(name, version, options),\n type,\n }),\n )\n addArgs.modifiedDependencies = true\n }\n addArgs.set(asDepID(importerId), depMap)\n }\n return [options, addArgs]\n}\n\nexport const parseUninstallOptions = (\n options: UninstallOptions,\n args: GUIUninstallOptions,\n): [UninstallOptions, RemoveImportersDependenciesMap] => {\n const removeArgs = new RemoveImportersDependenciesMapImpl()\n for (const [importerId, deps] of Object.entries(args)) {\n const depMap = new Set<string>()\n for (const name of deps) {\n depMap.add(name)\n }\n removeArgs.set(asDepID(importerId), depMap)\n removeArgs.modifiedDependencies = true\n }\n return [options, removeArgs]\n}\n\nexport const formatDashboardJson = async (\n projectFolders: PathBase[],\n dashboardRoot: string[],\n scurry: PathScurry,\n packageJson: PackageJson,\n) => {\n const userDefinedProjectPaths = (\n dashboardRoot.length ? dashboardRoot : [homedir()]).map(\n path =>\n ({\n path,\n readablePath: getReadablePath(path),\n }) as DashboardLocation,\n )\n const result: DashboardData = {\n cwd: process.cwd(),\n buildVersion: version,\n dashboardProjectLocations: projectFolders\n .map((dir: PathBase) => {\n const path = dirname(dir.fullpath())\n const res: DashboardLocation = {\n path,\n readablePath: getReadablePath(path),\n }\n return res\n })\n .concat(userDefinedProjectPaths)\n .reduce<DashboardLocation[]>((acc, curr) => {\n if (acc.every(obj => obj.path !== curr.path)) {\n acc.push(curr)\n }\n return acc\n }, [])\n .sort((a, b) => a.readablePath.length - b.readablePath.length),\n defaultAuthor: getAuthorFromGitUser(\n await getUser().catch(() => undefined),\n ),\n projects: [],\n }\n for (const folder of projectFolders) {\n const projectData = getDashboardProjectData(folder, {\n scurry,\n packageJson,\n })\n if (projectData) {\n result.projects.push(projectData)\n }\n }\n return result\n}\n\nconst updateGraphData = (\n tmp: string,\n options: ActualLoadOptions,\n hasDashboard: boolean,\n) => {\n const { packageJson, projectRoot, scurry } = options\n const mainManifest = packageJson.read(projectRoot)\n const graph = actual.load({\n ...options,\n mainManifest,\n loadManifests: true,\n })\n const importers = [...graph.importers]\n const folder = scurry.lstatSync(projectRoot)\n const graphJson = JSON.stringify(\n {\n hasDashboard,\n importers,\n lockfile: graph,\n projectInfo: getGraphProjectData(\n { packageJson, scurry },\n folder,\n ),\n },\n null,\n 2,\n )\n rmSync(resolve(tmp, 'graph.json'), { force: true })\n writeFileSync(resolve(tmp, 'graph.json'), graphJson)\n}\n\nconst updateDashboardData = async (\n tmp: string,\n options: {\n scurry: PathScurry\n 'dashboard-root'?: string[]\n packageJson: PackageJson\n },\n) => {\n const {\n 'dashboard-root': userDefinedProjectPaths = [],\n scurry,\n packageJson,\n } = options\n const dashboard = await formatDashboardJson(\n await readProjectFolders({\n scurry,\n userDefinedProjectPaths,\n }),\n userDefinedProjectPaths,\n scurry,\n packageJson,\n )\n const dashboardJson = JSON.stringify(dashboard, null, 2)\n writeFileSync(resolve(tmp, 'dashboard.json'), dashboardJson)\n return dashboard.projects.length > 0\n}\n\nconst getDefaultStartingRoute = (options: {\n projectRoot: string\n scurry: PathScurry\n}) => {\n const { projectRoot, scurry } = options\n const stat = scurry.lstatSync(`${projectRoot}/package.json`)\n return stat?.isFile() && !stat.isSymbolicLink() ?\n `/explore?query=${encodeURIComponent(':root')}`\n : '/dashboard'\n}\n\n/* c8 ignore start */\nconst createStaticHandler = ({\n assetsDir,\n publicDir,\n}: {\n assetsDir: string\n publicDir: string\n}) => {\n const opts = {\n cleanUrls: true,\n public: publicDir,\n rewrites: [\n { source: '/', destination: '/index.html' },\n { source: '/error', destination: '/index.html' },\n { source: '/explore', destination: '/index.html' },\n { source: '/dashboard', destination: '/index.html' },\n { source: '/queries', destination: '/index.html' },\n { source: '/labels', destination: '/index.html' },\n { source: '/new-project', destination: '/index.html' },\n ],\n }\n const errHandler = (err: unknown, res: ServerResponse) => {\n stderr(err)\n res.statusCode = 500\n res.end('Internal server error')\n }\n const staticHandler = (req: IncomingMessage, res: ServerResponse) =>\n handler(req, res, opts).catch((err: unknown) =>\n errHandler(err, res),\n )\n\n // It's important for this guard to check to not be destructured\n // because `infra/build` will replace the whole thing with `false`\n // causing it to be stripped entirely from production builds.\n if (process.env.__VLT_INTERNAL_LIVE_RELOAD) {\n // Generate a set of routes that should be proxied to the esbuild server\n const proxyRoutes = new Set(\n [\n // `/esbuild` is an SSE endpoint served by esbuild\n 'esbuild',\n // Also proxy anything that currently exists in the assets dir\n ...readdirSync(assetsDir, {\n withFileTypes: true,\n recursive: true,\n })\n .filter(f => f.isFile())\n .map(f =>\n relative(assetsDir, resolve(f.parentPath, f.name)),\n ),\n ].map(p => `/${p}`),\n )\n return (req: IncomingMessage, res: ServerResponse) =>\n req.url && proxyRoutes.has(req.url) ?\n void req.pipe(\n request(\n {\n hostname: HOST,\n port: 7018,\n path: req.url,\n method: req.method,\n headers: req.headers,\n },\n proxy => {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n res.writeHead(proxy.statusCode!, proxy.headers)\n proxy.pipe(res, { end: true })\n },\n ).on('error', err => {\n // If we get an ECONNREFUSED error, fallback to the static handler\n // since the esbuild server is not running\n if (\n err instanceof Error &&\n 'code' in err &&\n err.code === 'ECONNREFUSED'\n ) {\n // In this case the /esbuild route is expected to fail so the\n // EventSource in the browser will be closed\n if (req.url === '/esbuild') {\n res.statusCode = 404\n return res.end()\n }\n return staticHandler(req, res)\n }\n errHandler(err, res)\n }),\n { end: true },\n )\n : staticHandler(req, res)\n }\n\n return staticHandler\n}\n\n/* c8 ignore start */\nconst getAssetsDir = () => {\n const fromEnv = process.env.__VLT_INTERNAL_GUI_ASSETS_DIR\n // workaround for the import.meta.resolve issue not working with tap\n if (process.env.TAP) {\n assert(\n fromEnv,\n 'assets dir must be set from environment variable when running tests',\n )\n }\n if (fromEnv) {\n return resolve(import.meta.dirname, fromEnv)\n }\n return fileURLToPath(import.meta.resolve('@vltpkg/gui'))\n}\n/* c8 ignore stop */\n\nexport const startGUI = async ({\n conf,\n assetsDir = getAssetsDir(),\n port = PORT,\n startingRoute = undefined,\n tmpDir = tmpdir(),\n}: StartGUIOptions) => {\n const tmp = resolve(tmpDir, 'vltgui')\n rmSync(tmp, { recursive: true, force: true })\n mkdirSync(tmp, { recursive: true })\n // This is the same as `cpSync(assetsDir, tmp, { recursive: true })`\n // but that does not work in Deno yet (https://github.com/denoland/deno/issues/27494).\n for (const asset of readdirSync(assetsDir, {\n withFileTypes: true,\n recursive: true,\n })) {\n if (!asset.isFile()) continue\n const source = resolve(asset.parentPath, asset.name)\n const target = resolve(tmp, relative(assetsDir, source))\n mkdirSync(dirname(target), { recursive: true })\n writeFileSync(target, readFileSync(source))\n }\n\n // dashboard data is optional since the GUI might be started from a\n // project in order to just explore its graph data\n let hasDashboard = false\n\n const {\n scurry,\n 'dashboard-root': dashboardRoot,\n packageJson,\n } = conf.options\n\n const updateDashboard = async () => {\n try {\n hasDashboard = await updateDashboardData(tmp, {\n scurry,\n 'dashboard-root': dashboardRoot,\n packageJson,\n })\n /* c8 ignore next */\n } catch {}\n if (!hasDashboard) {\n rmSync(resolve(tmp, 'dashboard.json'), { force: true })\n }\n }\n\n await updateDashboard()\n\n // reading graph data is optional since the command might be run from a\n // parend directory of any given project root, in which case the GUI is\n // going to render only the dashboard to start with\n try {\n updateGraphData(tmp, conf.options, hasDashboard)\n } catch {\n rmSync(resolve(tmp, 'graph.json'), { force: true })\n }\n\n const staticHandler = createStaticHandler({\n publicDir: tmp,\n assetsDir,\n })\n\n const server = createServer(async (req, res) => {\n const json = <T>(): Promise<T> =>\n new Promise(resolve => {\n req.setEncoding('utf8')\n let json = ''\n req.on('data', (d: string) => (json += d))\n req.on('end', () => resolve(JSON.parse(json) as T))\n })\n const jsonError = (\n errType: string,\n err: unknown,\n code: number,\n ) => {\n stderr(err)\n res.statusCode = code\n res.end(JSON.stringify(`${errType}\\n${err}`))\n }\n const jsonOk = (result: string) => {\n res.writeHead(200, { 'Content-Type': 'application/json' })\n res.end(JSON.stringify(result))\n }\n switch (`${req.method} ${req.url}`) {\n case 'POST /select-project': {\n const data = await json<{ path: unknown }>()\n conf.resetOptions(String(data.path))\n await updateDashboard()\n updateGraphData(tmp, conf.options, hasDashboard)\n return jsonOk('ok')\n }\n case 'POST /create-project': {\n const data = await json<{\n path: unknown\n name: unknown\n author: unknown\n }>()\n if (typeof data.path !== 'string') {\n return jsonError(\n 'Bad request.',\n 'Project path must be a string',\n 400,\n )\n }\n if (\n !/^[a-z0-9-]+$/.test(String(data.name)) ||\n String(data.name).length > 128\n ) {\n return jsonError(\n 'Bad request.',\n 'Project name must be lowercase, alphanumeric, and may contain hyphens',\n 400,\n )\n }\n const path = String(data.path)\n const name = String(data.name)\n const author = String(data.author)\n try {\n const cwd = resolve(path, name)\n mkdirSync(cwd, { recursive: true })\n await init({ cwd, author })\n conf.resetOptions(cwd)\n await install(conf.options)\n conf.resetOptions(conf.options.projectRoot)\n await updateDashboard()\n updateGraphData(tmp, conf.options, hasDashboard)\n } catch (err) {\n // eslint-disable-next-line no-console\n console.error(err)\n return jsonError('CLI Error', (err as Error).message, 500)\n }\n return jsonOk('ok')\n }\n case `POST /install`: {\n const { add } = await json<{ add?: GUIInstallOptions }>()\n if (!add) {\n return jsonError(\n 'Bad request.',\n 'GUI install endpoint called without add argument',\n 400,\n )\n }\n try {\n await install(...parseInstallOptions(conf.options, add))\n conf.resetOptions(conf.options.projectRoot)\n updateGraphData(tmp, conf.options, hasDashboard)\n return jsonOk('ok')\n } catch (err) {\n return jsonError('Install failed', err, 500)\n }\n }\n case `POST /uninstall`: {\n const { remove } = await json<{\n remove?: GUIUninstallOptions\n }>()\n if (!remove) {\n return jsonError(\n 'Bad request.',\n 'GUI uninstall endpoint called with no arguments',\n 400,\n )\n }\n try {\n await uninstall(\n ...parseUninstallOptions(conf.options, remove),\n )\n conf.resetOptions(conf.options.projectRoot)\n updateGraphData(tmp, conf.options, hasDashboard)\n return jsonOk('ok')\n } catch (err) {\n return jsonError('Uninstall failed', err, 500)\n }\n }\n /* c8 ignore next 3 */\n default: {\n return staticHandler(req, res)\n }\n }\n })\n\n return new Promise<Server>(res => {\n const route =\n startingRoute || getDefaultStartingRoute(conf.options)\n server.listen(port, 'localhost', () => {\n stdout(`⚡️ vlt GUI running at http://${HOST}:${port}`)\n void urlOpen(`http://${HOST}:${port}${route}`)\n res(server)\n })\n })\n}\n"]}
1
+ {"version":3,"file":"start-gui.js","sourceRoot":"","sources":["../../src/start-gui.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACnC,OAAO,QAAQ,MAAM,WAAW,CAAA;AAChC,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAC7C,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA;AAC1C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAKpC,MAAM,CAAC,MAAM,uBAAuB,GAAG,KAAK,EAAE,OAK7C,EAAE,EAAE;IACH,MAAM,EACJ,WAAW,GAAG,OAAO,EACrB,aAAa,EACb,WAAW,EACX,MAAM,GACP,GAAG,OAAO,CAAA;IACX,IAAI,aAAa;QAAE,OAAO,aAAa,CAAA;IACvC,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,KAAK,CAAC,GAAG,WAAW,eAAe,CAAC,CAAA;IAC9D,OAAO,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,CAAC,CAAC;QAC7C,YAAY,QAAQ,CAAC,6BAA6B,CAAC,WAAW,CAAC,WAAW;QAC5E,CAAC,CAAC,GAAG,CAAA;AACT,CAAC,CAAA;AAED,MAAM,YAAY,GAAG,GAAG,EAAE;IACxB,qBAAqB;IACrB,IAAI,OAAO,CAAC,GAAG,CAAC,6BAA6B,EAAE,CAAC;QAC9C,OAAO,OAAO,CACZ,MAAM,CAAC,IAAI,CAAC,OAAO,EACnB,OAAO,CAAC,GAAG,CAAC,6BAA6B,CAC1C,CAAA;IACH,CAAC;IACD,oBAAoB;AACtB,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,QAAQ,GAAG,KAAK,EAC3B,IAAkB,EAClB,aAAsB,EACtB,EAAE;IACF,MAAM,MAAM,GAAG,YAAY,CAAC;QAC1B,GAAG,IAAI,CAAC,OAAO;QACf,SAAS,EAAE,YAAY,EAAE;QACzB,YAAY,EAAE,IAAI;KACnB,CAAC,CAAA;IACF,MAAM,CAAC,EAAE,CAAC,kBAAkB,EAAE,GAAG,CAAC,EAAE;QAClC,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,CACrB;QAAC,MAA6B,CAAC,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;IAC7D,CAAC,CAAC,CAAA;IACF,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC,OAAO,CAAA;IAC5C,MAAM,MAAM,CAAC,KAAK,EAAE,CAAA;IACpB,MAAM,CAAC,yBAAyB,MAAM,CAAC,OAAO,EAAE,EAAE,CAAC,CAAA;IACnD,KAAK,OAAO,CACV,MAAM,CAAC,OAAO,CACZ,MAAM,uBAAuB,CAAC;QAC5B,WAAW,EAAE,IAAI,CAAC,MAAM,CAAC,MAAM;QAC/B,aAAa;QACb,WAAW;QACX,MAAM;KACP,CAAC,CACH,CACF,CAAA;IACD,OAAO,MAAM,CAAA;AACf,CAAC,CAAA","sourcesContent":["import { resolve } from 'node:path'\nimport LZString from 'lz-string'\nimport { createServer } from '@vltpkg/server'\nimport { urlOpen } from '@vltpkg/url-open'\nimport { stdout } from './output.ts'\nimport type { PathScurry } from 'path-scurry'\nimport type { LoadedConfig } from './config/index.ts'\nimport type { VltServerListening } from '@vltpkg/server'\n\nexport const getDefaultStartingRoute = async (options: {\n queryString?: string\n startingRoute?: string\n projectRoot: string\n scurry: PathScurry\n}) => {\n const {\n queryString = ':root',\n startingRoute,\n projectRoot,\n scurry,\n } = options\n if (startingRoute) return startingRoute\n const stat = await scurry.lstat(`${projectRoot}/package.json`)\n return stat?.isFile() && !stat.isSymbolicLink() ?\n `/explore/${LZString.compressToEncodedURIComponent(queryString)}/overview`\n : '/'\n}\n\nconst getAssetsDir = () => {\n /* c8 ignore start */\n if (process.env.__VLT_INTERNAL_GUI_ASSETS_DIR) {\n return resolve(\n import.meta.dirname,\n process.env.__VLT_INTERNAL_GUI_ASSETS_DIR,\n )\n }\n /* c8 ignore stop */\n}\n\nexport const startGUI = async (\n conf: LoadedConfig,\n startingRoute?: string,\n) => {\n const server = createServer({\n ...conf.options,\n assetsDir: getAssetsDir(),\n loadedConfig: conf,\n })\n server.on('needConfigUpdate', dir => {\n conf.resetOptions(dir)\n ;(server as VltServerListening).updateOptions(conf.options)\n })\n const { projectRoot, scurry } = conf.options\n await server.start()\n stdout(`⚡️ vlt GUI running at ${server.address()}`)\n void urlOpen(\n server.address(\n await getDefaultStartingRoute({\n queryString: conf.values.target,\n startingRoute,\n projectRoot,\n scurry,\n }),\n ),\n )\n return server\n}\n"]}
@@ -1,7 +1,6 @@
1
- import type { ChalkInstance } from 'chalk';
2
1
  import type { LoadedConfig } from './config/index.ts';
3
2
  export type ViewOptions = {
4
- colors?: ChalkInstance;
3
+ colors?: boolean;
5
4
  };
6
5
  /**
7
6
  * The base class for all View classes
@@ -21,7 +20,7 @@ export declare class ViewClass<T = unknown> {
21
20
  start(): void;
22
21
  done(_result: T, _opts: {
23
22
  time: number;
24
- }): undefined | string;
23
+ }): unknown;
25
24
  error(_err: unknown): void;
26
25
  }
27
26
  export type ViewFn<T = unknown> = (result: T, options: ViewOptions, conf: LoadedConfig) => unknown;
@@ -1 +1 @@
1
- {"version":3,"file":"view.d.ts","sourceRoot":"","sources":["../../src/view.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAA;AAC1C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAErD,MAAM,MAAM,WAAW,GAAG;IAAE,MAAM,CAAC,EAAE,aAAa,CAAA;CAAE,CAAA;AAEpD;;;;;;;;;;GAUG;AACH,qBAAa,SAAS,CA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AAI;IACnB,IAAI,CAAC,SAAS,YAAY,SAAS,CAAA","sourcesContent":["import type { ChalkInstance } from 'chalk'\nimport type { LoadedConfig } from './config/index.ts'\n\nexport type ViewOptions = { colors?: ChalkInstance }\n\n/**\n * The base class for all View classes\n *\n * Do not override the constructor, just provide start/done/error methods.\n *\n * These classes should be used as one or more of the exported views for\n * commands that need to know when the processing starts, handle errors in\n * various ways, etc. Fancy stuff.\n *\n * For simple use cases, usually better to create a {@link ViewFn} instead.\n */\nexport class ViewClass<T = unknown> {\n options: ViewOptions\n config: LoadedConfig\n\n constructor(options: ViewOptions, config: LoadedConfig) {\n this.options = options\n this.config = config\n }\n\n // TODO: maybe have start() return a flag to say \"i got this, do not\n // run the command\", for example to have the gui just open a web browser\n // to the page relevant to a given thing, rather than computing it twice\n start() {}\n done(_result: T, _opts: { time: number }): undefined | string {\n return\n }\n error(_err: unknown) {}\n}\n\nexport type ViewFn<T = unknown> = (\n result: T,\n options: ViewOptions,\n conf: LoadedConfig,\n) => unknown\n\nexport type View<T = unknown> = ViewFn<T> | typeof ViewClass<T>\n\nexport const isViewClass = <T = unknown>(\n view: View<T>,\n): view is typeof ViewClass<T> =>\n typeof view === 'function' &&\n 'prototype' in view &&\n view.prototype instanceof ViewClass\n\nexport type Views<T = unknown> = View<T> | Record<string, View<T>>\n"]}
1
+ {"version":3,"file":"view.js","sourceRoot":"","sources":["../../src/view.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;GAUG;AACH,MAAM,OAAO,SAAS;IACpB,OAAO,CAAa;IACpB,MAAM,CAAc;IAEpB,YAAY,OAAoB,EAAE,MAAoB;QACpD,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;IACtB,CAAC;IAED,oEAAoE;IACpE,wEAAwE;IACxE,wEAAwE;IACxE,KAAK,KAAI,CAAC;IACV,IAAI,CAAC,OAAU,EAAE,KAAuB;QACtC,OAAM;IACR,CAAC;IACD,KAAK,CAAC,IAAa,IAAG,CAAC;CACxB;AAUD,MAAM,CAAC,MAAM,WAAW,GAAG,CACzB,IAAa,EACgB,EAAE,CAC/B,OAAO,IAAI,KAAK,UAAU;IAC1B,WAAW,IAAI,IAAI;IACnB,IAAI,CAAC,SAAS,YAAY,SAAS,CAAA","sourcesContent":["import type { LoadedConfig } from './config/index.ts'\n\nexport type ViewOptions = { colors?: boolean }\n\n/**\n * The base class for all View classes\n *\n * Do not override the constructor, just provide start/done/error methods.\n *\n * These classes should be used as one or more of the exported views for\n * commands that need to know when the processing starts, handle errors in\n * various ways, etc. Fancy stuff.\n *\n * For simple use cases, usually better to create a {@link ViewFn} instead.\n */\nexport class ViewClass<T = unknown> {\n options: ViewOptions\n config: LoadedConfig\n\n constructor(options: ViewOptions, config: LoadedConfig) {\n this.options = options\n this.config = config\n }\n\n // TODO: maybe have start() return a flag to say \"i got this, do not\n // run the command\", for example to have the gui just open a web browser\n // to the page relevant to a given thing, rather than computing it twice\n start() {}\n done(_result: T, _opts: { time: number }): unknown {\n return\n }\n error(_err: unknown) {}\n}\n\nexport type ViewFn<T = unknown> = (\n result: T,\n options: ViewOptions,\n conf: LoadedConfig,\n) => unknown\n\nexport type View<T = unknown> = ViewFn<T> | typeof ViewClass<T>\n\nexport const isViewClass = <T = unknown>(\n view: View<T>,\n): view is typeof ViewClass<T> =>\n typeof view === 'function' &&\n 'prototype' in view &&\n view.prototype instanceof ViewClass\n\nexport type Views<T = unknown> = View<T> | Record<string, View<T>>\n"]}