veodl 1.8.3 → 1.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/uninstall.js CHANGED
@@ -1,221 +1,222 @@
1
- import path from 'node:path';
2
- import { spawn } from 'node:child_process';
3
- import { rm } from 'node:fs/promises';
4
- import { commandOutput } from './output.js';
5
- import { cacheBase, configBase } from './paths.js';
6
- import { cleanText, readableError } from './utils.js';
7
- import { removeAlias, validateAliasName, listAliases } from './alias.js';
8
-
9
- const PACKAGE = 'veodl';
10
-
11
- export const UNINSTALL_HELP = `veo uninstall - remove veo completely or one command alias
12
-
13
- Usage:
14
- veo uninstall [-p|--prefix <name>] [--json]
15
- Remove one alias (e.g. veo uninstall -p veodl)
16
- veo uninstall [--yes] [--keep-cache] [--keep-config] [--keep-aliases] [--json]
17
- Remove everything: aliases, package, cache, config
18
- veo uninstall --help Show this help
19
-
20
- With -p/--prefix, only that alias is deleted; veo itself stays installed.
21
- Without -p, veo prints what would be removed. Add --yes to delete everything:
22
- custom wrappers created with veo alias add, the ${PACKAGE} package itself
23
- (commands veo, veodl) with npm, veo's cache directory (downloads, jobs,
24
- backend tools, history, statistics) and the config file. Use --keep-cache,
25
- --keep-config or --keep-aliases to preserve one part. The config file is
26
- deleted by default; its path is shown before and after.
27
- `;
28
-
29
- export function npmUninstallCommand({ platform = process.platform } = {}) {
30
- const args = ['uninstall', '-g', PACKAGE];
31
- if (platform === 'win32') {
32
- return {
33
- command: 'cmd.exe',
34
- args: ['/d', '/s', '/c', `npm ${args.join(' ')}`],
35
- shell: false,
36
- windowsVerbatimArguments: true,
37
- };
38
- }
39
- return { command: 'npm', args, shell: false };
40
- }
41
-
42
- export function runNpmUninstall({ spawnImpl = spawn, platform = process.platform, signal, timeoutMs = 600_000 } = {}) {
43
- const { command, args, ...spawnOptions } = npmUninstallCommand({ platform });
44
- return new Promise((resolve, reject) => {
45
- const child = spawnImpl(command, args, { ...spawnOptions, stdio: 'inherit', windowsHide: true, signal: signal ? AbortSignal.any([signal, AbortSignal.timeout(timeoutMs)]) : AbortSignal.timeout(timeoutMs) });
46
- child.once('error', reject);
47
- child.once('close', resolve);
48
- });
49
- }
50
-
51
- function parseUninstallArgs(args) {
52
- let prefix;
53
- let yes = false;
54
- let keepCache = false;
55
- let keepConfig = false;
56
- let keepAliases = false;
57
- let json = false;
58
- let binDir;
59
- const rest = [];
60
- for (let index = 0; index < args.length; index++) {
61
- const token = args[index];
62
- if (token === '-p' || token === '--prefix') {
63
- prefix = args[++index];
64
- if (!prefix) throw new Error('--prefix requires an alias name. Use: veo uninstall -p veodl');
65
- } else if (token.startsWith('-p=')) {
66
- prefix = token.slice(3) || undefined;
67
- if (!prefix) throw new Error('--prefix requires an alias name. Use: veo uninstall -p veodl');
68
- } else if (token.startsWith('--prefix=')) {
69
- prefix = token.slice(9) || undefined;
70
- if (!prefix) throw new Error('--prefix requires an alias name. Use: veo uninstall -p veodl');
71
- } else if (token === '--yes') yes = true;
72
- else if (token === '--purge') {
73
- // Deprecated: full cleanup is now the default. Kept so older commands keep working.
74
- } else if (token === '--keep-cache') keepCache = true;
75
- else if (token === '--keep-config') keepConfig = true;
76
- else if (token === '--keep-aliases') keepAliases = true;
77
- else if (token === '--json') json = true;
78
- else if (token === '--bin-dir') {
79
- binDir = args[++index];
80
- if (!binDir) throw new Error('--bin-dir requires a directory.');
81
- } else if (token.startsWith('--bin-dir=')) {
82
- binDir = token.slice(10) || undefined;
83
- if (!binDir) throw new Error('--bin-dir requires a directory.');
84
- } else rest.push(token);
85
- }
86
- return { prefix, yes, keepCache, keepConfig, keepAliases, json, binDir, rest };
87
- }
88
-
89
- export async function uninstallMain(args = [], {
90
- stdout = process.stdout,
91
- stderr = process.stderr,
92
- platform = process.platform,
93
- env = process.env,
94
- spawnImpl = spawn,
95
- rmImpl = rm,
96
- cacheRoot,
97
- configFile,
98
- listImpl = listAliases,
99
- removeImpl = removeAlias,
100
- } = {}) {
101
- [args, stdout, stderr] = commandOutput(args, stdout, stderr);
102
- const { prefix, yes, keepCache, keepConfig, keepAliases, json, binDir, rest } = parseUninstallArgs(args);
103
- if (rest.includes('-h') || rest.includes('--help')) {
104
- stdout.write(UNINSTALL_HELP);
105
- return 0;
106
- }
107
- if (rest.length) throw new Error(`Unknown option for veo uninstall: ${rest.join(' ')}. Use: veo uninstall --help`);
108
-
109
- if (prefix) {
110
- if (keepCache || keepConfig || keepAliases) throw new Error('--keep-* cannot be combined with --prefix. Remove one alias or uninstall veo itself.');
111
- const valid = validateAliasName(prefix);
112
- const removed = await removeImpl(valid, { binDir, platform, env });
113
- if (json) {
114
- stdout.write(`${JSON.stringify({ status: 'removed', ...removed })}\n`);
115
- return 0;
116
- }
117
- stdout.write(`Alias removed: ${removed.name} (${removed.removed.length} file(s) in ${removed.binDir})\n`);
118
- if (removed.builtin) stdout.write('Note: veo update recreates the shipped veodl name.\n');
119
- return 0;
120
- }
121
-
122
- const cache = cacheRoot || cacheBase({ platform, env });
123
- const config = configFile || path.join(configBase({ platform, env }), 'config.json');
124
- const manual = `npm uninstall -g ${PACKAGE}`;
125
-
126
- // Custom wrappers first so the plan names them; npm removes veo/veodl itself.
127
- let customAliases = [];
128
- let aliasDir = binDir ? path.resolve(binDir) : null;
129
- try {
130
- const listed = await listImpl({ binDir: binDir || undefined, platform, env });
131
- aliasDir = listed.binDir;
132
- customAliases = listed.aliases.filter(entry => entry.present && entry.managed && !entry.builtin).map(entry => entry.name);
133
- } catch {
134
- // No bin directory (e.g. running from source without a global install):
135
- // npm uninstall still works, alias cleanup is reported as skipped.
136
- }
137
-
138
- if (!yes) {
139
- if (json) {
140
- stdout.write(`${JSON.stringify({ status: 'planned', package: PACKAGE, manual, aliases: customAliases, binDir: aliasDir, cache, config })}\n`);
141
- return 0;
142
- }
143
- stdout.write(`This removes everything: the ${PACKAGE} package with npm (commands veo, veodl).\n`);
144
- if (!keepAliases) {
145
- stdout.write(customAliases.length
146
- ? `Custom wrappers to delete: ${customAliases.join(', ')} (${aliasDir})\n`
147
- : `Custom wrappers: none found${aliasDir ? ` (${aliasDir})` : ''}.\n`);
148
- }
149
- if (!keepCache) stdout.write(`Cache to delete: ${cache}\n`);
150
- if (!keepConfig) stdout.write(`Config to delete: ${config}\n`);
151
- if (keepCache || keepConfig || keepAliases) {
152
- const kept = [
153
- keepAliases && 'aliases',
154
- keepCache && 'cache',
155
- keepConfig && 'config',
156
- ].filter(Boolean).join(', ');
157
- stdout.write(`Kept: ${kept}.\n`);
158
- }
159
- const keepFlags = `${keepAliases ? ' --keep-aliases' : ''}${keepCache ? ' --keep-cache' : ''}${keepConfig ? ' --keep-config' : ''}`;
160
- stdout.write(`Run with --yes to proceed: veo uninstall --yes${keepFlags}\n`);
161
- stdout.write(`Manual command: ${manual}\n`);
162
- return 0;
163
- }
164
-
165
- let code;
166
- try {
167
- stdout.write(`Uninstalling ${PACKAGE} with npm…\n`);
168
- code = await runNpmUninstall({ spawnImpl, platform, signal: AbortSignal.timeout(600_000) });
169
- } catch (error) {
170
- const reason = error.code === 'ENOENT' ? 'npm was not found. Install Node.js/npm, or uninstall manually.' : `Could not run npm: ${readableError(error)}`;
171
- stderr.write(`veo: ${reason}\nManual command: ${manual}\n`);
172
- return 1;
173
- }
174
- if (code !== 0) {
175
- stderr.write(`veo: npm exited with code ${code}. Uninstall manually with: ${manual}\n`);
176
- return 1;
177
- }
178
-
179
- const removedAliases = [];
180
- if (!keepAliases) {
181
- for (const name of customAliases) {
182
- try {
183
- await removeImpl(name, { binDir: aliasDir, platform, env });
184
- removedAliases.push(name);
185
- } catch (error) {
186
- stderr.write(`veo: removed the package but could not delete alias ${name}: ${readableError(error)}\n`);
187
- return 1;
188
- }
189
- }
190
- }
191
- let cacheDeleted = false;
192
- if (!keepCache) {
193
- try {
194
- await rmImpl(cache, { recursive: true, force: true });
195
- cacheDeleted = true;
196
- } catch (error) {
197
- stderr.write(`veo: removed the package but could not delete the cache ${cache}: ${readableError(error)}\n`);
198
- return 1;
199
- }
200
- }
201
- let configDeleted = false;
202
- if (!keepConfig) {
203
- try {
204
- await rmImpl(config, { force: true });
205
- configDeleted = true;
206
- } catch (error) {
207
- stderr.write(`veo: removed the package but could not delete the config ${config}: ${readableError(error)}\n`);
208
- return 1;
209
- }
210
- }
211
- if (json) {
212
- stdout.write(`${JSON.stringify({ status: 'uninstalled', package: PACKAGE, aliases: removedAliases, binDir: aliasDir, cacheDeleted, cache, configDeleted, config })}\n`);
213
- return 0;
214
- }
215
- stdout.write(`veo uninstalled (${PACKAGE}).`);
216
- if (!keepAliases) stdout.write(removedAliases.length ? ` Aliases deleted: ${removedAliases.join(', ')}.` : ' No custom wrappers found.');
217
- stdout.write(cacheDeleted ? ` Cache deleted: ${cache}.` : ` Cache kept: ${cache}.`);
218
- stdout.write(configDeleted ? ` Config deleted: ${config}.` : ` Config kept: ${config}.`);
219
- stdout.write('\n');
220
- return 0;
221
- }
1
+ import path from 'node:path';
2
+ import { spawn } from 'node:child_process';
3
+ import { rm } from 'node:fs/promises';
4
+ import { commandOutput } from './output.js';
5
+ import { cacheBase } from './paths.js';
6
+ import { configFile as resolveConfigFile } from './config.js';
7
+ import { cleanText, readableError } from './utils.js';
8
+ import { removeAlias, validateAliasName, listAliases } from './alias.js';
9
+
10
+ const PACKAGE = 'veodl';
11
+
12
+ export const UNINSTALL_HELP = `veo uninstall - remove veo completely or one command alias
13
+
14
+ Usage:
15
+ veo uninstall [-p|--prefix <name>] [--json]
16
+ Remove one alias (e.g. veo uninstall -p veodl)
17
+ veo uninstall [--yes] [--keep-cache] [--keep-config] [--keep-aliases] [--json]
18
+ Remove everything: aliases, package, cache, config
19
+ veo uninstall --help Show this help
20
+
21
+ With -p/--prefix, only that alias is deleted; veo itself stays installed.
22
+ Without -p, veo prints what would be removed. Add --yes to delete everything:
23
+ custom wrappers created with veo alias add, the ${PACKAGE} package itself
24
+ (commands veo, veodl) with npm, veo's cache directory (downloads, jobs,
25
+ backend tools, history, statistics) and the config file. Use --keep-cache,
26
+ --keep-config or --keep-aliases to preserve one part. The config file is
27
+ deleted by default; its path is shown before and after.
28
+ `;
29
+
30
+ export function npmUninstallCommand({ platform = process.platform } = {}) {
31
+ const args = ['uninstall', '-g', PACKAGE];
32
+ if (platform === 'win32') {
33
+ return {
34
+ command: 'cmd.exe',
35
+ args: ['/d', '/s', '/c', `npm ${args.join(' ')}`],
36
+ shell: false,
37
+ windowsVerbatimArguments: true,
38
+ };
39
+ }
40
+ return { command: 'npm', args, shell: false };
41
+ }
42
+
43
+ export function runNpmUninstall({ spawnImpl = spawn, platform = process.platform, signal, timeoutMs = 600_000 } = {}) {
44
+ const { command, args, ...spawnOptions } = npmUninstallCommand({ platform });
45
+ return new Promise((resolve, reject) => {
46
+ const child = spawnImpl(command, args, { ...spawnOptions, stdio: 'inherit', windowsHide: true, signal: signal ? AbortSignal.any([signal, AbortSignal.timeout(timeoutMs)]) : AbortSignal.timeout(timeoutMs) });
47
+ child.once('error', reject);
48
+ child.once('close', resolve);
49
+ });
50
+ }
51
+
52
+ function parseUninstallArgs(args) {
53
+ let prefix;
54
+ let yes = false;
55
+ let keepCache = false;
56
+ let keepConfig = false;
57
+ let keepAliases = false;
58
+ let json = false;
59
+ let binDir;
60
+ const rest = [];
61
+ for (let index = 0; index < args.length; index++) {
62
+ const token = args[index];
63
+ if (token === '-p' || token === '--prefix') {
64
+ prefix = args[++index];
65
+ if (!prefix) throw new Error('--prefix requires an alias name. Use: veo uninstall -p veodl');
66
+ } else if (token.startsWith('-p=')) {
67
+ prefix = token.slice(3) || undefined;
68
+ if (!prefix) throw new Error('--prefix requires an alias name. Use: veo uninstall -p veodl');
69
+ } else if (token.startsWith('--prefix=')) {
70
+ prefix = token.slice(9) || undefined;
71
+ if (!prefix) throw new Error('--prefix requires an alias name. Use: veo uninstall -p veodl');
72
+ } else if (token === '--yes') yes = true;
73
+ else if (token === '--purge') {
74
+ // Deprecated: full cleanup is now the default. Kept so older commands keep working.
75
+ } else if (token === '--keep-cache') keepCache = true;
76
+ else if (token === '--keep-config') keepConfig = true;
77
+ else if (token === '--keep-aliases') keepAliases = true;
78
+ else if (token === '--json') json = true;
79
+ else if (token === '--bin-dir') {
80
+ binDir = args[++index];
81
+ if (!binDir) throw new Error('--bin-dir requires a directory.');
82
+ } else if (token.startsWith('--bin-dir=')) {
83
+ binDir = token.slice(10) || undefined;
84
+ if (!binDir) throw new Error('--bin-dir requires a directory.');
85
+ } else rest.push(token);
86
+ }
87
+ return { prefix, yes, keepCache, keepConfig, keepAliases, json, binDir, rest };
88
+ }
89
+
90
+ export async function uninstallMain(args = [], {
91
+ stdout = process.stdout,
92
+ stderr = process.stderr,
93
+ platform = process.platform,
94
+ env = process.env,
95
+ spawnImpl = spawn,
96
+ rmImpl = rm,
97
+ cacheRoot,
98
+ configFile,
99
+ listImpl = listAliases,
100
+ removeImpl = removeAlias,
101
+ } = {}) {
102
+ [args, stdout, stderr] = commandOutput(args, stdout, stderr);
103
+ const { prefix, yes, keepCache, keepConfig, keepAliases, json, binDir, rest } = parseUninstallArgs(args);
104
+ if (rest.includes('-h') || rest.includes('--help')) {
105
+ stdout.write(UNINSTALL_HELP);
106
+ return 0;
107
+ }
108
+ if (rest.length) throw new Error(`Unknown option for veo uninstall: ${rest.join(' ')}. Use: veo uninstall --help`);
109
+
110
+ if (prefix) {
111
+ if (keepCache || keepConfig || keepAliases) throw new Error('--keep-* cannot be combined with --prefix. Remove one alias or uninstall veo itself.');
112
+ const valid = validateAliasName(prefix);
113
+ const removed = await removeImpl(valid, { binDir, platform, env });
114
+ if (json) {
115
+ stdout.write(`${JSON.stringify({ status: 'removed', ...removed })}\n`);
116
+ return 0;
117
+ }
118
+ stdout.write(`Alias removed: ${removed.name} (${removed.removed.length} file(s) in ${removed.binDir})\n`);
119
+ if (removed.builtin) stdout.write('Note: veo update recreates the shipped veodl name.\n');
120
+ return 0;
121
+ }
122
+
123
+ const cache = cacheRoot || cacheBase({ platform, env });
124
+ const config = configFile || resolveConfigFile({ platform, env });
125
+ const manual = `npm uninstall -g ${PACKAGE}`;
126
+
127
+ // Custom wrappers first so the plan names them; npm removes veo/veodl itself.
128
+ let customAliases = [];
129
+ let aliasDir = binDir ? path.resolve(binDir) : null;
130
+ try {
131
+ const listed = await listImpl({ binDir: binDir || undefined, platform, env });
132
+ aliasDir = listed.binDir;
133
+ customAliases = listed.aliases.filter(entry => entry.present && entry.managed && !entry.builtin).map(entry => entry.name);
134
+ } catch {
135
+ // No bin directory (e.g. running from source without a global install):
136
+ // npm uninstall still works, alias cleanup is reported as skipped.
137
+ }
138
+
139
+ if (!yes) {
140
+ if (json) {
141
+ stdout.write(`${JSON.stringify({ status: 'planned', package: PACKAGE, manual, aliases: customAliases, binDir: aliasDir, cache, config })}\n`);
142
+ return 0;
143
+ }
144
+ stdout.write(`This removes everything: the ${PACKAGE} package with npm (commands veo, veodl).\n`);
145
+ if (!keepAliases) {
146
+ stdout.write(customAliases.length
147
+ ? `Custom wrappers to delete: ${customAliases.join(', ')} (${aliasDir})\n`
148
+ : `Custom wrappers: none found${aliasDir ? ` (${aliasDir})` : ''}.\n`);
149
+ }
150
+ if (!keepCache) stdout.write(`Cache to delete: ${cache}\n`);
151
+ if (!keepConfig) stdout.write(`Config to delete: ${config}\n`);
152
+ if (keepCache || keepConfig || keepAliases) {
153
+ const kept = [
154
+ keepAliases && 'aliases',
155
+ keepCache && 'cache',
156
+ keepConfig && 'config',
157
+ ].filter(Boolean).join(', ');
158
+ stdout.write(`Kept: ${kept}.\n`);
159
+ }
160
+ const keepFlags = `${keepAliases ? ' --keep-aliases' : ''}${keepCache ? ' --keep-cache' : ''}${keepConfig ? ' --keep-config' : ''}`;
161
+ stdout.write(`Run with --yes to proceed: veo uninstall --yes${keepFlags}\n`);
162
+ stdout.write(`Manual command: ${manual}\n`);
163
+ return 0;
164
+ }
165
+
166
+ let code;
167
+ try {
168
+ stdout.write(`Uninstalling ${PACKAGE} with npm…\n`);
169
+ code = await runNpmUninstall({ spawnImpl, platform, signal: AbortSignal.timeout(600_000) });
170
+ } catch (error) {
171
+ const reason = error.code === 'ENOENT' ? 'npm was not found. Install Node.js/npm, or uninstall manually.' : `Could not run npm: ${readableError(error)}`;
172
+ stderr.write(`veo: ${reason}\nManual command: ${manual}\n`);
173
+ return 1;
174
+ }
175
+ if (code !== 0) {
176
+ stderr.write(`veo: npm exited with code ${code}. Uninstall manually with: ${manual}\n`);
177
+ return 1;
178
+ }
179
+
180
+ const removedAliases = [];
181
+ if (!keepAliases) {
182
+ for (const name of customAliases) {
183
+ try {
184
+ await removeImpl(name, { binDir: aliasDir, platform, env });
185
+ removedAliases.push(name);
186
+ } catch (error) {
187
+ stderr.write(`veo: removed the package but could not delete alias ${name}: ${readableError(error)}\n`);
188
+ return 1;
189
+ }
190
+ }
191
+ }
192
+ let cacheDeleted = false;
193
+ if (!keepCache) {
194
+ try {
195
+ await rmImpl(cache, { recursive: true, force: true });
196
+ cacheDeleted = true;
197
+ } catch (error) {
198
+ stderr.write(`veo: removed the package but could not delete the cache ${cache}: ${readableError(error)}\n`);
199
+ return 1;
200
+ }
201
+ }
202
+ let configDeleted = false;
203
+ if (!keepConfig) {
204
+ try {
205
+ await rmImpl(config, { force: true });
206
+ configDeleted = true;
207
+ } catch (error) {
208
+ stderr.write(`veo: removed the package but could not delete the config ${config}: ${readableError(error)}\n`);
209
+ return 1;
210
+ }
211
+ }
212
+ if (json) {
213
+ stdout.write(`${JSON.stringify({ status: 'uninstalled', package: PACKAGE, aliases: removedAliases, binDir: aliasDir, cacheDeleted, cache, configDeleted, config })}\n`);
214
+ return 0;
215
+ }
216
+ stdout.write(`veo uninstalled (${PACKAGE}).`);
217
+ if (!keepAliases) stdout.write(removedAliases.length ? ` Aliases deleted: ${removedAliases.join(', ')}.` : ' No custom wrappers found.');
218
+ stdout.write(cacheDeleted ? ` Cache deleted: ${cache}.` : ` Cache kept: ${cache}.`);
219
+ stdout.write(configDeleted ? ` Config deleted: ${config}.` : ` Config kept: ${config}.`);
220
+ stdout.write('\n');
221
+ return 0;
222
+ }