@oclif/core 3.26.4 → 4.0.0-beta.2
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/lib/command.js +6 -6
- package/lib/config/config.d.ts +3 -4
- package/lib/config/config.js +42 -39
- package/lib/config/ts-path.js +5 -5
- package/lib/errors/error.js +2 -5
- package/lib/errors/errors/cli.js +3 -3
- package/lib/errors/exit.d.ts +1 -0
- package/lib/errors/exit.js +8 -0
- package/lib/errors/index.d.ts +1 -1
- package/lib/errors/index.js +5 -8
- package/lib/errors/logger.js +5 -2
- package/lib/errors/warn.d.ts +13 -2
- package/lib/errors/warn.js +15 -11
- package/lib/execute.js +1 -1
- package/lib/{cli-ux/flush.js → flush.js} +1 -1
- package/lib/help/command.js +6 -5
- package/lib/help/formatter.js +8 -9
- package/lib/help/index.js +6 -9
- package/lib/help/root.js +3 -3
- package/lib/index.d.ts +2 -3
- package/lib/index.js +6 -12
- package/lib/interfaces/config.d.ts +1 -0
- package/lib/interfaces/pjson.d.ts +1 -1
- package/lib/interfaces/theme.d.ts +30 -19
- package/lib/interfaces/theme.js +2 -19
- package/lib/main.js +2 -2
- package/lib/parser/errors.js +5 -5
- package/lib/parser/help.js +2 -2
- package/lib/util/read-tsconfig.js +1 -1
- package/lib/{cli-ux → ux}/action/base.d.ts +5 -7
- package/lib/{cli-ux → ux}/action/base.js +0 -3
- package/lib/{cli-ux → ux}/action/spinner.d.ts +5 -4
- package/lib/{cli-ux → ux}/action/spinner.js +16 -39
- package/lib/ux/action/types.d.ts +5 -0
- package/lib/ux/colorize-json.d.ts +28 -0
- package/lib/ux/colorize-json.js +67 -0
- package/lib/ux/index.d.ts +64 -0
- package/lib/ux/index.js +76 -0
- package/lib/{cli-ux → ux}/list.d.ts +1 -1
- package/lib/{cli-ux → ux}/list.js +1 -2
- package/lib/ux/theme.d.ts +9 -0
- package/lib/ux/theme.js +43 -0
- package/lib/ux/write.d.ts +2 -0
- package/lib/ux/write.js +22 -0
- package/package.json +11 -33
- package/lib/cli-ux/action/spinners.d.ts +0 -251
- package/lib/cli-ux/action/spinners.js +0 -374
- package/lib/cli-ux/action/types.d.ts +0 -5
- package/lib/cli-ux/config.d.ts +0 -25
- package/lib/cli-ux/config.js +0 -52
- package/lib/cli-ux/exit.d.ts +0 -8
- package/lib/cli-ux/exit.js +0 -16
- package/lib/cli-ux/index.d.ts +0 -133
- package/lib/cli-ux/index.js +0 -183
- package/lib/cli-ux/prompt.d.ts +0 -32
- package/lib/cli-ux/prompt.js +0 -185
- package/lib/cli-ux/stream.d.ts +0 -23
- package/lib/cli-ux/stream.js +0 -43
- package/lib/cli-ux/styled/index.d.ts +0 -4
- package/lib/cli-ux/styled/index.js +0 -36
- package/lib/cli-ux/styled/object.d.ts +0 -1
- package/lib/cli-ux/styled/object.js +0 -39
- package/lib/cli-ux/styled/progress.d.ts +0 -2
- package/lib/cli-ux/styled/progress.js +0 -8
- package/lib/cli-ux/styled/table.d.ts +0 -45
- package/lib/cli-ux/styled/table.js +0 -345
- package/lib/cli-ux/styled/tree.d.ts +0 -9
- package/lib/cli-ux/styled/tree.js +0 -37
- package/lib/cli-ux/theme.d.ts +0 -11
- package/lib/cli-ux/theme.js +0 -61
- package/lib/cli-ux/wait.d.ts +0 -2
- package/lib/cli-ux/wait.js +0 -5
- package/lib/cli-ux/write.d.ts +0 -8
- package/lib/cli-ux/write.js +0 -15
- /package/lib/{cli-ux/flush.d.ts → flush.d.ts} +0 -0
- /package/lib/{cli-ux → ux}/action/simple.d.ts +0 -0
- /package/lib/{cli-ux → ux}/action/simple.js +0 -0
- /package/lib/{cli-ux → ux}/action/types.js +0 -0
package/lib/command.js
CHANGED
|
@@ -27,11 +27,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
29
|
exports.Command = void 0;
|
|
30
|
-
const
|
|
30
|
+
const ansis_1 = __importDefault(require("ansis"));
|
|
31
31
|
const node_url_1 = require("node:url");
|
|
32
32
|
const node_util_1 = require("node:util");
|
|
33
33
|
const cache_1 = __importDefault(require("./cache"));
|
|
34
|
-
const cli_ux_1 = require("./cli-ux");
|
|
35
34
|
const config_1 = require("./config");
|
|
36
35
|
const Errors = __importStar(require("./errors"));
|
|
37
36
|
const util_1 = require("./help/util");
|
|
@@ -39,6 +38,7 @@ const Parser = __importStar(require("./parser"));
|
|
|
39
38
|
const aggregate_flags_1 = require("./util/aggregate-flags");
|
|
40
39
|
const ids_1 = require("./util/ids");
|
|
41
40
|
const util_2 = require("./util/util");
|
|
41
|
+
const ux_1 = __importDefault(require("./ux"));
|
|
42
42
|
const pjson = cache_1.default.getInstance().get('@oclif/core');
|
|
43
43
|
/**
|
|
44
44
|
* swallows stdout epipe errors
|
|
@@ -167,7 +167,7 @@ class Command {
|
|
|
167
167
|
if (!err.message)
|
|
168
168
|
throw err;
|
|
169
169
|
try {
|
|
170
|
-
|
|
170
|
+
ux_1.default.action.stop(ansis_1.default.bold.red('!'));
|
|
171
171
|
}
|
|
172
172
|
catch { }
|
|
173
173
|
throw err;
|
|
@@ -223,16 +223,16 @@ class Command {
|
|
|
223
223
|
log(message = '', ...args) {
|
|
224
224
|
if (!this.jsonEnabled()) {
|
|
225
225
|
message = typeof message === 'string' ? message : (0, node_util_1.inspect)(message);
|
|
226
|
-
|
|
226
|
+
ux_1.default.stdout(message, ...args);
|
|
227
227
|
}
|
|
228
228
|
}
|
|
229
229
|
logJson(json) {
|
|
230
|
-
|
|
230
|
+
ux_1.default.stdout(ux_1.default.colorizeJson(json, { pretty: true, theme: this.config.theme?.json }));
|
|
231
231
|
}
|
|
232
232
|
logToStderr(message = '', ...args) {
|
|
233
233
|
if (!this.jsonEnabled()) {
|
|
234
234
|
message = typeof message === 'string' ? message : (0, node_util_1.inspect)(message);
|
|
235
|
-
|
|
235
|
+
ux_1.default.stderr(message, ...args);
|
|
236
236
|
}
|
|
237
237
|
}
|
|
238
238
|
async parse(options, argv = this.argv) {
|
package/lib/config/config.d.ts
CHANGED
|
@@ -29,6 +29,7 @@ export declare class Config implements IConfig {
|
|
|
29
29
|
shell: string;
|
|
30
30
|
theme?: Theme;
|
|
31
31
|
topicSeparator: ' ' | ':';
|
|
32
|
+
updateConfig: NonNullable<PJSON.CLI['oclif']['update']>;
|
|
32
33
|
userAgent: string;
|
|
33
34
|
userPJSON?: PJSON.User;
|
|
34
35
|
valid: boolean;
|
|
@@ -93,10 +94,7 @@ export declare class Config implements IConfig {
|
|
|
93
94
|
loadPluginsAndCommands(opts?: {
|
|
94
95
|
force: boolean;
|
|
95
96
|
}): Promise<void>;
|
|
96
|
-
|
|
97
|
-
file: string | undefined;
|
|
98
|
-
theme: Theme | undefined;
|
|
99
|
-
}>;
|
|
97
|
+
loadTheme(): Promise<Theme | undefined>;
|
|
100
98
|
protected macosCacheDir(): string | undefined;
|
|
101
99
|
runCommand<T = unknown>(id: string, argv?: string[], cachedCommand?: Command.Loadable | null): Promise<T>;
|
|
102
100
|
runHook<T extends keyof Hooks>(event: T, opts: Hooks[T]['options'], timeout?: number, captureErrors?: boolean): Promise<Hook.Result<Hooks[T]['return']>>;
|
|
@@ -125,6 +123,7 @@ export declare class Config implements IConfig {
|
|
|
125
123
|
protected windowsUserprofileHome(): string | undefined;
|
|
126
124
|
protected _debug(): number;
|
|
127
125
|
protected _shell(): string;
|
|
126
|
+
private buildS3Config;
|
|
128
127
|
/**
|
|
129
128
|
* This method is responsible for locating the correct plugin to use for a named command id
|
|
130
129
|
* It searches the {Config} registered commands to match either the raw command id or the command alias
|
package/lib/config/config.js
CHANGED
|
@@ -33,8 +33,6 @@ const node_os_1 = require("node:os");
|
|
|
33
33
|
const node_path_1 = require("node:path");
|
|
34
34
|
const node_url_1 = require("node:url");
|
|
35
35
|
const cache_1 = __importDefault(require("../cache"));
|
|
36
|
-
const cli_ux_1 = require("../cli-ux");
|
|
37
|
-
const theme_1 = require("../cli-ux/theme");
|
|
38
36
|
const errors_1 = require("../errors");
|
|
39
37
|
const util_1 = require("../help/util");
|
|
40
38
|
const module_loader_1 = require("../module-loader");
|
|
@@ -43,6 +41,8 @@ const settings_1 = require("../settings");
|
|
|
43
41
|
const fs_1 = require("../util/fs");
|
|
44
42
|
const os_1 = require("../util/os");
|
|
45
43
|
const util_2 = require("../util/util");
|
|
44
|
+
const ux_1 = __importDefault(require("../ux"));
|
|
45
|
+
const theme_1 = require("../ux/theme");
|
|
46
46
|
const plugin_loader_1 = __importDefault(require("./plugin-loader"));
|
|
47
47
|
const ts_path_1 = require("./ts-path");
|
|
48
48
|
const util_3 = require("./util");
|
|
@@ -110,6 +110,7 @@ class Config {
|
|
|
110
110
|
shell;
|
|
111
111
|
theme;
|
|
112
112
|
topicSeparator = ':';
|
|
113
|
+
updateConfig;
|
|
113
114
|
userAgent;
|
|
114
115
|
userPJSON;
|
|
115
116
|
valid;
|
|
@@ -302,33 +303,11 @@ class Config {
|
|
|
302
303
|
this.errlog = (0, node_path_1.join)(this.cacheDir, 'error.log');
|
|
303
304
|
this.binPath = this.scopedEnvVar('BINPATH');
|
|
304
305
|
this.npmRegistry = this.scopedEnvVar('NPM_REGISTRY') || this.pjson.oclif.npmRegistry;
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
this.
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
this.pjson.oclif.update.node = this.pjson.oclif.update.node || {};
|
|
311
|
-
const s3 = this.pjson.oclif.update.s3 || {};
|
|
312
|
-
this.pjson.oclif.update.s3 = s3;
|
|
313
|
-
s3.bucket = this.scopedEnvVar('S3_BUCKET') || s3.bucket;
|
|
314
|
-
if (s3.bucket && !s3.host)
|
|
315
|
-
s3.host = `https://${s3.bucket}.s3.amazonaws.com`;
|
|
316
|
-
s3.templates = {
|
|
317
|
-
...s3.templates,
|
|
318
|
-
target: {
|
|
319
|
-
baseDir: '<%- bin %>',
|
|
320
|
-
manifest: "<%- channel === 'stable' ? '' : 'channels/' + channel + '/' %><%- platform %>-<%- arch %>",
|
|
321
|
-
unversioned: "<%- channel === 'stable' ? '' : 'channels/' + channel + '/' %><%- bin %>-<%- platform %>-<%- arch %><%- ext %>",
|
|
322
|
-
versioned: "<%- channel === 'stable' ? '' : 'channels/' + channel + '/' %><%- bin %>-v<%- version %>/<%- bin %>-v<%- version %>-<%- platform %>-<%- arch %><%- ext %>",
|
|
323
|
-
...(s3.templates && s3.templates.target),
|
|
324
|
-
},
|
|
325
|
-
vanilla: {
|
|
326
|
-
baseDir: '<%- bin %>',
|
|
327
|
-
manifest: "<%- channel === 'stable' ? '' : 'channels/' + channel + '/' %>version",
|
|
328
|
-
unversioned: "<%- channel === 'stable' ? '' : 'channels/' + channel + '/' %><%- bin %><%- ext %>",
|
|
329
|
-
versioned: "<%- channel === 'stable' ? '' : 'channels/' + channel + '/' %><%- bin %>-v<%- version %>/<%- bin %>-v<%- version %><%- ext %>",
|
|
330
|
-
...(s3.templates && s3.templates.vanilla),
|
|
331
|
-
},
|
|
306
|
+
this.theme = await this.loadTheme();
|
|
307
|
+
this.updateConfig = {
|
|
308
|
+
...this.pjson.oclif.update,
|
|
309
|
+
node: this.pjson.oclif.update?.node ?? {},
|
|
310
|
+
s3: this.buildS3Config(),
|
|
332
311
|
};
|
|
333
312
|
this.isSingleCommandCLI = Boolean(this.pjson.oclif.default ||
|
|
334
313
|
(typeof this.pjson.oclif.commands !== 'string' &&
|
|
@@ -366,7 +345,9 @@ class Config {
|
|
|
366
345
|
this.warn(error);
|
|
367
346
|
}
|
|
368
347
|
}
|
|
369
|
-
async
|
|
348
|
+
async loadTheme() {
|
|
349
|
+
if (this.scopedEnvVarTrue('DISABLE_THEME'))
|
|
350
|
+
return;
|
|
370
351
|
const defaultThemeFile = this.pjson.oclif.theme
|
|
371
352
|
? (0, node_path_1.resolve)(this.root, this.pjson.oclif.theme)
|
|
372
353
|
: this.pjson.oclif.theme;
|
|
@@ -377,12 +358,7 @@ class Config {
|
|
|
377
358
|
]);
|
|
378
359
|
// Merge the default theme with the user theme, giving the user theme precedence.
|
|
379
360
|
const merged = { ...defaultTheme, ...userTheme };
|
|
380
|
-
return
|
|
381
|
-
// Point to the user file if it exists, otherwise use the default file.
|
|
382
|
-
// This doesn't really serve a purpose to anyone but removing it would be a breaking change.
|
|
383
|
-
file: userTheme ? userThemeFile : defaultThemeFile,
|
|
384
|
-
theme: Object.keys(merged).length > 0 ? (0, theme_1.parseTheme)(merged) : undefined,
|
|
385
|
-
};
|
|
361
|
+
return Object.keys(merged).length > 0 ? (0, theme_1.parseTheme)(merged) : undefined;
|
|
386
362
|
}
|
|
387
363
|
macosCacheDir() {
|
|
388
364
|
return (this.platform === 'darwin' && (0, node_path_1.join)(this.home, 'Library', 'Caches', this.dirname)) || undefined;
|
|
@@ -482,7 +458,7 @@ class Config {
|
|
|
482
458
|
(0, errors_1.exit)(code);
|
|
483
459
|
},
|
|
484
460
|
log(message, ...args) {
|
|
485
|
-
|
|
461
|
+
ux_1.default.stdout(message, ...args);
|
|
486
462
|
},
|
|
487
463
|
warn(message) {
|
|
488
464
|
(0, errors_1.warn)(message);
|
|
@@ -542,11 +518,11 @@ class Config {
|
|
|
542
518
|
options = ext;
|
|
543
519
|
else if (ext)
|
|
544
520
|
options.ext = ext;
|
|
545
|
-
const template = this.
|
|
521
|
+
const template = this.updateConfig.s3.templates[options.platform ? 'target' : 'vanilla'][type] ?? '';
|
|
546
522
|
return ejs.render(template, { ...this, ...options });
|
|
547
523
|
}
|
|
548
524
|
s3Url(key) {
|
|
549
|
-
const { host } = this.
|
|
525
|
+
const { host } = this.updateConfig.s3 ?? { host: undefined };
|
|
550
526
|
if (!host)
|
|
551
527
|
throw new Error('no s3 host is set');
|
|
552
528
|
const url = new node_url_1.URL(host);
|
|
@@ -650,6 +626,33 @@ class Config {
|
|
|
650
626
|
}
|
|
651
627
|
return shellPath.at(-1) ?? 'unknown';
|
|
652
628
|
}
|
|
629
|
+
buildS3Config() {
|
|
630
|
+
const s3 = this.pjson.oclif.update?.s3;
|
|
631
|
+
const bucket = this.scopedEnvVar('S3_BUCKET') ?? s3?.bucket;
|
|
632
|
+
const host = s3?.host ?? (bucket && `https://${bucket}.s3.amazonaws.com`);
|
|
633
|
+
const templates = {
|
|
634
|
+
...s3?.templates,
|
|
635
|
+
target: {
|
|
636
|
+
baseDir: '<%- bin %>',
|
|
637
|
+
manifest: "<%- channel === 'stable' ? '' : 'channels/' + channel + '/' %><%- platform %>-<%- arch %>",
|
|
638
|
+
unversioned: "<%- channel === 'stable' ? '' : 'channels/' + channel + '/' %><%- bin %>-<%- platform %>-<%- arch %><%- ext %>",
|
|
639
|
+
versioned: "<%- channel === 'stable' ? '' : 'channels/' + channel + '/' %><%- bin %>-v<%- version %>/<%- bin %>-v<%- version %>-<%- platform %>-<%- arch %><%- ext %>",
|
|
640
|
+
...(s3?.templates && s3?.templates.target),
|
|
641
|
+
},
|
|
642
|
+
vanilla: {
|
|
643
|
+
baseDir: '<%- bin %>',
|
|
644
|
+
manifest: "<%- channel === 'stable' ? '' : 'channels/' + channel + '/' %>version",
|
|
645
|
+
unversioned: "<%- channel === 'stable' ? '' : 'channels/' + channel + '/' %><%- bin %><%- ext %>",
|
|
646
|
+
versioned: "<%- channel === 'stable' ? '' : 'channels/' + channel + '/' %><%- bin %>-v<%- version %>/<%- bin %>-v<%- version %><%- ext %>",
|
|
647
|
+
...(s3?.templates && s3?.templates.vanilla),
|
|
648
|
+
},
|
|
649
|
+
};
|
|
650
|
+
return {
|
|
651
|
+
bucket,
|
|
652
|
+
host,
|
|
653
|
+
templates,
|
|
654
|
+
};
|
|
655
|
+
}
|
|
653
656
|
/**
|
|
654
657
|
* This method is responsible for locating the correct plugin to use for a named command id
|
|
655
658
|
* It searches the {Config} registered commands to match either the raw command id or the command alias
|
package/lib/config/ts-path.js
CHANGED
|
@@ -76,7 +76,7 @@ async function loadTSConfig(root) {
|
|
|
76
76
|
if (isErrno(error))
|
|
77
77
|
return;
|
|
78
78
|
debug(`Could not parse tsconfig.json. Skipping typescript path lookup for ${root}.`);
|
|
79
|
-
(0, warn_1.
|
|
79
|
+
(0, warn_1.warn)(`Could not parse tsconfig.json for ${root}. Falling back to compiled source.`);
|
|
80
80
|
}
|
|
81
81
|
}
|
|
82
82
|
async function registerTSNode(root, tsconfig) {
|
|
@@ -91,7 +91,7 @@ async function registerTSNode(root, tsconfig) {
|
|
|
91
91
|
}
|
|
92
92
|
catch {
|
|
93
93
|
debug(`Could not find ts-node at ${tsNodePath}. Skipping ts-node registration for ${root}.`);
|
|
94
|
-
(0, warn_1.
|
|
94
|
+
(0, warn_1.warn)(`Could not find ts-node at ${tsNodePath}. Please ensure that ts-node is a devDependency. Falling back to compiled source.`);
|
|
95
95
|
return;
|
|
96
96
|
}
|
|
97
97
|
const typeRoots = [(0, node_path_1.join)(root, 'node_modules', '@types')];
|
|
@@ -220,7 +220,7 @@ async function determinePath(root, orig) {
|
|
|
220
220
|
}
|
|
221
221
|
debug(`No source file found. Returning default path ${orig}`);
|
|
222
222
|
if (!(0, util_1.isProd)())
|
|
223
|
-
(0, warn_1.
|
|
223
|
+
(0, warn_1.warn)(`Could not find source for ${orig} based on tsconfig. Defaulting to compiled source.`);
|
|
224
224
|
return orig;
|
|
225
225
|
}
|
|
226
226
|
async function tsPath(root, orig, plugin) {
|
|
@@ -243,12 +243,12 @@ async function tsPath(root, orig, plugin) {
|
|
|
243
243
|
if (cannotTranspileEsm(rootPlugin, plugin, isProduction)) {
|
|
244
244
|
debug(`Skipping typescript path lookup for ${root} because it's an ESM module (NODE_ENV: ${process.env.NODE_ENV}, root plugin module type: ${rootPlugin?.moduleType})`);
|
|
245
245
|
if (plugin?.type === 'link')
|
|
246
|
-
(0, warn_1.
|
|
246
|
+
(0, warn_1.warn)(`${plugin?.name} is a linked ESM module and cannot be auto-transpiled. Existing compiled source will be used instead.`);
|
|
247
247
|
return orig;
|
|
248
248
|
}
|
|
249
249
|
if (cannotUseTsNode(root, plugin, isProduction)) {
|
|
250
250
|
debug(`Skipping typescript path lookup for ${root} because ts-node is run in node version ${process.version}"`);
|
|
251
|
-
(0, warn_1.
|
|
251
|
+
(0, warn_1.warn)(`ts-node executable cannot transpile ESM in Node 20. Existing compiled source will be used instead. See https://github.com/oclif/core/issues/817.`);
|
|
252
252
|
return orig;
|
|
253
253
|
}
|
|
254
254
|
try {
|
package/lib/errors/error.js
CHANGED
|
@@ -22,12 +22,9 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
22
22
|
__setModuleDefault(result, mod);
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
-
};
|
|
28
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
26
|
exports.error = void 0;
|
|
30
|
-
const write_1 =
|
|
27
|
+
const write_1 = require("../ux/write");
|
|
31
28
|
const config_1 = require("./config");
|
|
32
29
|
const cli_1 = require("./errors/cli");
|
|
33
30
|
const pretty_print_1 = __importStar(require("./errors/pretty-print"));
|
|
@@ -46,7 +43,7 @@ function error(input, options = {}) {
|
|
|
46
43
|
if (options.exit === false) {
|
|
47
44
|
const message = (0, pretty_print_1.default)(err);
|
|
48
45
|
if (message)
|
|
49
|
-
write_1.
|
|
46
|
+
(0, write_1.stderr)(message);
|
|
50
47
|
if (config_1.config.errorLogger)
|
|
51
48
|
config_1.config.errorLogger.log(err?.stack ?? '');
|
|
52
49
|
}
|
package/lib/errors/errors/cli.js
CHANGED
|
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.CLIError = exports.addOclifExitCode = void 0;
|
|
7
|
-
const
|
|
7
|
+
const ansis_1 = __importDefault(require("ansis"));
|
|
8
8
|
const clean_stack_1 = __importDefault(require("clean-stack"));
|
|
9
9
|
const indent_string_1 = __importDefault(require("indent-string"));
|
|
10
10
|
const wrap_ansi_1 = __importDefault(require("wrap-ansi"));
|
|
@@ -36,7 +36,7 @@ class CLIError extends Error {
|
|
|
36
36
|
}
|
|
37
37
|
get bang() {
|
|
38
38
|
try {
|
|
39
|
-
return
|
|
39
|
+
return ansis_1.default.red(process.platform === 'win32' ? '»' : '›');
|
|
40
40
|
}
|
|
41
41
|
catch { }
|
|
42
42
|
}
|
|
@@ -68,7 +68,7 @@ exports.CLIError = CLIError;
|
|
|
68
68
|
}
|
|
69
69
|
get bang() {
|
|
70
70
|
try {
|
|
71
|
-
return
|
|
71
|
+
return ansis_1.default.yellow(process.platform === 'win32' ? '»' : '›');
|
|
72
72
|
}
|
|
73
73
|
catch { }
|
|
74
74
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function exit(code?: number): never;
|
package/lib/errors/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export { error } from './error';
|
|
|
4
4
|
export { CLIError } from './errors/cli';
|
|
5
5
|
export { ExitError } from './errors/exit';
|
|
6
6
|
export { ModuleLoadError } from './errors/module-load';
|
|
7
|
+
export { exit } from './exit';
|
|
7
8
|
export { handle } from './handle';
|
|
8
9
|
export { Logger } from './logger';
|
|
9
|
-
export declare function exit(code?: number): never;
|
|
10
10
|
export { warn } from './warn';
|
package/lib/errors/index.js
CHANGED
|
@@ -1,24 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.warn = exports.
|
|
4
|
-
const exit_1 = require("./errors/exit");
|
|
3
|
+
exports.warn = exports.Logger = exports.handle = exports.exit = exports.ModuleLoadError = exports.ExitError = exports.CLIError = exports.error = exports.config = void 0;
|
|
5
4
|
var config_1 = require("./config");
|
|
6
5
|
Object.defineProperty(exports, "config", { enumerable: true, get: function () { return config_1.config; } });
|
|
7
6
|
var error_1 = require("./error");
|
|
8
7
|
Object.defineProperty(exports, "error", { enumerable: true, get: function () { return error_1.error; } });
|
|
9
8
|
var cli_1 = require("./errors/cli");
|
|
10
9
|
Object.defineProperty(exports, "CLIError", { enumerable: true, get: function () { return cli_1.CLIError; } });
|
|
11
|
-
var
|
|
12
|
-
Object.defineProperty(exports, "ExitError", { enumerable: true, get: function () { return
|
|
10
|
+
var exit_1 = require("./errors/exit");
|
|
11
|
+
Object.defineProperty(exports, "ExitError", { enumerable: true, get: function () { return exit_1.ExitError; } });
|
|
13
12
|
var module_load_1 = require("./errors/module-load");
|
|
14
13
|
Object.defineProperty(exports, "ModuleLoadError", { enumerable: true, get: function () { return module_load_1.ModuleLoadError; } });
|
|
14
|
+
var exit_2 = require("./exit");
|
|
15
|
+
Object.defineProperty(exports, "exit", { enumerable: true, get: function () { return exit_2.exit; } });
|
|
15
16
|
var handle_1 = require("./handle");
|
|
16
17
|
Object.defineProperty(exports, "handle", { enumerable: true, get: function () { return handle_1.handle; } });
|
|
17
18
|
var logger_1 = require("./logger");
|
|
18
19
|
Object.defineProperty(exports, "Logger", { enumerable: true, get: function () { return logger_1.Logger; } });
|
|
19
|
-
function exit(code = 0) {
|
|
20
|
-
throw new exit_1.ExitError(code);
|
|
21
|
-
}
|
|
22
|
-
exports.exit = exit;
|
|
23
20
|
var warn_1 = require("./warn");
|
|
24
21
|
Object.defineProperty(exports, "warn", { enumerable: true, get: function () { return warn_1.warn; } });
|
package/lib/errors/logger.js
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.Logger = void 0;
|
|
7
|
+
const ansis_1 = __importDefault(require("ansis"));
|
|
4
8
|
const promises_1 = require("node:fs/promises");
|
|
5
9
|
const node_path_1 = require("node:path");
|
|
6
|
-
const stripAnsi = require("strip-ansi");
|
|
7
10
|
const timestamp = () => new Date().toISOString();
|
|
8
11
|
let timer;
|
|
9
12
|
const wait = (ms) => new Promise((resolve) => {
|
|
@@ -36,7 +39,7 @@ class Logger {
|
|
|
36
39
|
await this.flushing;
|
|
37
40
|
}
|
|
38
41
|
log(msg) {
|
|
39
|
-
msg =
|
|
42
|
+
msg = ansis_1.default.strip(chomp(msg));
|
|
40
43
|
const lines = msg.split('\n').map((l) => `${timestamp()} ${l}`.trimEnd());
|
|
41
44
|
this.buffer.push(...lines);
|
|
42
45
|
this.flush(50).catch(console.error);
|
package/lib/errors/warn.d.ts
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
type Options = {
|
|
2
|
+
/**
|
|
3
|
+
* If true, will only print the same warning once.
|
|
4
|
+
*/
|
|
5
|
+
ignoreDuplicates?: boolean;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Prints a pretty warning message to stderr.
|
|
9
|
+
*
|
|
10
|
+
* @param input The error or string to print.
|
|
11
|
+
* @param options.ignoreDuplicates If true, will only print the same warning once.
|
|
12
|
+
*/
|
|
13
|
+
export declare function warn(input: Error | string, options?: Options): void;
|
|
3
14
|
export default warn;
|
package/lib/errors/warn.js
CHANGED
|
@@ -3,12 +3,23 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
7
|
-
const write_1 =
|
|
6
|
+
exports.warn = void 0;
|
|
7
|
+
const write_1 = require("../ux/write");
|
|
8
8
|
const config_1 = require("./config");
|
|
9
9
|
const cli_1 = require("./errors/cli");
|
|
10
10
|
const pretty_print_1 = __importDefault(require("./errors/pretty-print"));
|
|
11
|
-
|
|
11
|
+
const WARNINGS = new Set();
|
|
12
|
+
/**
|
|
13
|
+
* Prints a pretty warning message to stderr.
|
|
14
|
+
*
|
|
15
|
+
* @param input The error or string to print.
|
|
16
|
+
* @param options.ignoreDuplicates If true, will only print the same warning once.
|
|
17
|
+
*/
|
|
18
|
+
function warn(input, options) {
|
|
19
|
+
const ignoreDuplicates = options?.ignoreDuplicates ?? true;
|
|
20
|
+
if (ignoreDuplicates && WARNINGS.has(input))
|
|
21
|
+
return;
|
|
22
|
+
WARNINGS.add(input);
|
|
12
23
|
let err;
|
|
13
24
|
if (typeof input === 'string') {
|
|
14
25
|
err = new cli_1.CLIError.Warn(input);
|
|
@@ -21,16 +32,9 @@ function warn(input) {
|
|
|
21
32
|
}
|
|
22
33
|
const message = (0, pretty_print_1.default)(err);
|
|
23
34
|
if (message)
|
|
24
|
-
write_1.
|
|
35
|
+
(0, write_1.stderr)(message);
|
|
25
36
|
if (config_1.config.errorLogger)
|
|
26
37
|
config_1.config.errorLogger.log(err?.stack ?? '');
|
|
27
38
|
}
|
|
28
39
|
exports.warn = warn;
|
|
29
|
-
const WARNINGS = new Set();
|
|
30
|
-
function memoizedWarn(input) {
|
|
31
|
-
if (!WARNINGS.has(input))
|
|
32
|
-
warn(input);
|
|
33
|
-
WARNINGS.add(input);
|
|
34
|
-
}
|
|
35
|
-
exports.memoizedWarn = memoizedWarn;
|
|
36
40
|
exports.default = warn;
|
package/lib/execute.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.execute = void 0;
|
|
4
|
-
const flush_1 = require("./cli-ux/flush");
|
|
5
4
|
const errors_1 = require("./errors");
|
|
6
5
|
const handle_1 = require("./errors/handle");
|
|
6
|
+
const flush_1 = require("./flush");
|
|
7
7
|
const main_1 = require("./main");
|
|
8
8
|
const settings_1 = require("./settings");
|
|
9
9
|
/**
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.flush = void 0;
|
|
4
|
-
const errors_1 = require("
|
|
4
|
+
const errors_1 = require("./errors");
|
|
5
5
|
function timeout(p, ms) {
|
|
6
6
|
function wait(ms, unref = false) {
|
|
7
7
|
return new Promise((resolve) => {
|
package/lib/help/command.js
CHANGED
|
@@ -4,12 +4,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.CommandHelp = void 0;
|
|
7
|
-
const
|
|
8
|
-
const strip_ansi_1 = __importDefault(require("strip-ansi"));
|
|
9
|
-
const theme_1 = require("../cli-ux/theme");
|
|
7
|
+
const ansis_1 = __importDefault(require("ansis"));
|
|
10
8
|
const ensure_arg_object_1 = require("../util/ensure-arg-object");
|
|
11
9
|
const ids_1 = require("../util/ids");
|
|
12
10
|
const util_1 = require("../util/util");
|
|
11
|
+
const theme_1 = require("../ux/theme");
|
|
13
12
|
const docopts_1 = require("./docopts");
|
|
14
13
|
const formatter_1 = require("./formatter");
|
|
15
14
|
// Don't use os.EOL because we need to ensure that a string
|
|
@@ -161,7 +160,7 @@ class CommandHelp extends formatter_1.HelpFormatter {
|
|
|
161
160
|
if (flag.multiple)
|
|
162
161
|
value += '...';
|
|
163
162
|
if (!value.includes('|'))
|
|
164
|
-
value =
|
|
163
|
+
value = ansis_1.default.underline(value);
|
|
165
164
|
label += `=${value}`;
|
|
166
165
|
}
|
|
167
166
|
return (0, theme_1.colorize)(this.config.theme?.flag, label);
|
|
@@ -328,7 +327,9 @@ class CommandHelp extends formatter_1.HelpFormatter {
|
|
|
328
327
|
return example;
|
|
329
328
|
}
|
|
330
329
|
isCommand(example) {
|
|
331
|
-
return
|
|
330
|
+
return ansis_1.default
|
|
331
|
+
.strip(this.formatIfCommand(example))
|
|
332
|
+
.startsWith(`${(0, theme_1.colorize)(this.config?.theme?.dollarSign, '$')} ${this.config.bin}`);
|
|
332
333
|
}
|
|
333
334
|
}
|
|
334
335
|
exports.CommandHelp = CommandHelp;
|
package/lib/help/formatter.js
CHANGED
|
@@ -4,14 +4,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.HelpFormatter = void 0;
|
|
7
|
-
const
|
|
7
|
+
const ansis_1 = __importDefault(require("ansis"));
|
|
8
8
|
const indent_string_1 = __importDefault(require("indent-string"));
|
|
9
9
|
const string_width_1 = __importDefault(require("string-width"));
|
|
10
|
-
const strip_ansi_1 = __importDefault(require("strip-ansi"));
|
|
11
10
|
const widest_line_1 = __importDefault(require("widest-line"));
|
|
12
11
|
const wrap_ansi_1 = __importDefault(require("wrap-ansi"));
|
|
13
|
-
const theme_1 = require("../cli-ux/theme");
|
|
14
12
|
const screen_1 = require("../screen");
|
|
13
|
+
const theme_1 = require("../ux/theme");
|
|
15
14
|
const util_1 = require("./util");
|
|
16
15
|
class HelpFormatter {
|
|
17
16
|
config;
|
|
@@ -74,12 +73,12 @@ class HelpFormatter {
|
|
|
74
73
|
continue;
|
|
75
74
|
if (left) {
|
|
76
75
|
if (opts.stripAnsi)
|
|
77
|
-
left =
|
|
76
|
+
left = ansis_1.default.strip(left);
|
|
78
77
|
output += this.wrap(left.trim(), opts.indentation);
|
|
79
78
|
}
|
|
80
79
|
if (right) {
|
|
81
80
|
if (opts.stripAnsi)
|
|
82
|
-
right =
|
|
81
|
+
right = ansis_1.default.strip(right);
|
|
83
82
|
output += '\n';
|
|
84
83
|
output += this.indent(this.wrap(right.trim(), opts.indentation + 2), 4);
|
|
85
84
|
}
|
|
@@ -101,13 +100,13 @@ class HelpFormatter {
|
|
|
101
100
|
}
|
|
102
101
|
cur = left || '';
|
|
103
102
|
if (opts.stripAnsi)
|
|
104
|
-
cur =
|
|
103
|
+
cur = ansis_1.default.strip(cur);
|
|
105
104
|
if (!right) {
|
|
106
105
|
cur = cur.trim();
|
|
107
106
|
continue;
|
|
108
107
|
}
|
|
109
108
|
if (opts.stripAnsi)
|
|
110
|
-
right =
|
|
109
|
+
right = ansis_1.default.strip(right);
|
|
111
110
|
right = this.wrap(right.trim(), opts.indentation + maxLength + 2);
|
|
112
111
|
const [first, ...lines] = right.split('\n').map((s) => s.trim());
|
|
113
112
|
cur += ' '.repeat(maxLength - (0, string_width_1.default)(cur) + 2);
|
|
@@ -155,10 +154,10 @@ class HelpFormatter {
|
|
|
155
154
|
.map(([left, right]) => [this.render(left), right && this.render(right)]);
|
|
156
155
|
}
|
|
157
156
|
const output = [
|
|
158
|
-
(0, theme_1.colorize)(this.config?.theme?.sectionHeader,
|
|
157
|
+
(0, theme_1.colorize)(this.config?.theme?.sectionHeader, ansis_1.default.bold(header)),
|
|
159
158
|
(0, theme_1.colorize)(this.config?.theme?.sectionDescription, this.indent(Array.isArray(newBody) ? this.renderList(newBody, { indentation: 2, stripAnsi: this.opts.stripAnsi }) : newBody)),
|
|
160
159
|
].join('\n');
|
|
161
|
-
return this.opts.stripAnsi ?
|
|
160
|
+
return this.opts.stripAnsi ? ansis_1.default.strip(output) : output;
|
|
162
161
|
}
|
|
163
162
|
/**
|
|
164
163
|
* Wrap text according to `opts.maxWidth` which is typically set to the terminal width. All text
|
package/lib/help/index.js
CHANGED
|
@@ -4,10 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.loadHelpClass = exports.Help = exports.HelpBase = exports.standardizeIDFromArgv = exports.normalizeArgv = exports.getHelpFlagAdditions = exports.CommandHelp = void 0;
|
|
7
|
-
const
|
|
8
|
-
const strip_ansi_1 = __importDefault(require("strip-ansi"));
|
|
9
|
-
const theme_1 = require("../cli-ux/theme");
|
|
10
|
-
const write_1 = __importDefault(require("../cli-ux/write"));
|
|
7
|
+
const ansis_1 = __importDefault(require("ansis"));
|
|
11
8
|
const ts_path_1 = require("../config/ts-path");
|
|
12
9
|
const error_1 = require("../errors/error");
|
|
13
10
|
const module_loader_1 = require("../module-loader");
|
|
@@ -15,6 +12,8 @@ const symbols_1 = require("../symbols");
|
|
|
15
12
|
const cache_default_value_1 = require("../util/cache-default-value");
|
|
16
13
|
const ids_1 = require("../util/ids");
|
|
17
14
|
const util_1 = require("../util/util");
|
|
15
|
+
const ux_1 = __importDefault(require("../ux"));
|
|
16
|
+
const theme_1 = require("../ux/theme");
|
|
18
17
|
const command_1 = require("./command");
|
|
19
18
|
const formatter_1 = require("./formatter");
|
|
20
19
|
const root_1 = __importDefault(require("./root"));
|
|
@@ -94,7 +93,7 @@ class Help extends HelpBase {
|
|
|
94
93
|
const summary = this.summary(c);
|
|
95
94
|
return [
|
|
96
95
|
(0, theme_1.colorize)(this.config?.theme?.command, c.id),
|
|
97
|
-
summary && (0, theme_1.colorize)(this.config?.theme?.sectionDescription,
|
|
96
|
+
summary && (0, theme_1.colorize)(this.config?.theme?.sectionDescription, ansis_1.default.strip(summary)),
|
|
98
97
|
];
|
|
99
98
|
}), {
|
|
100
99
|
indentation: 2,
|
|
@@ -121,7 +120,7 @@ class Help extends HelpBase {
|
|
|
121
120
|
this.section('DESCRIPTION', this.wrap((0, theme_1.colorize)(this.config?.theme?.sectionDescription, description))),
|
|
122
121
|
]).join('\n\n');
|
|
123
122
|
if (this.opts.stripAnsi)
|
|
124
|
-
output =
|
|
123
|
+
output = ansis_1.default.strip(output);
|
|
125
124
|
return output + '\n';
|
|
126
125
|
}
|
|
127
126
|
formatTopics(topics) {
|
|
@@ -145,9 +144,7 @@ class Help extends HelpBase {
|
|
|
145
144
|
return new this.CommandHelpClass(command, this.config, this.opts);
|
|
146
145
|
}
|
|
147
146
|
log(...args) {
|
|
148
|
-
this.opts.sendToStderr
|
|
149
|
-
? write_1.default.stderr(node_util_1.format.apply(this, args) + '\n')
|
|
150
|
-
: write_1.default.stdout(node_util_1.format.apply(this, args) + '\n');
|
|
147
|
+
this.opts.sendToStderr ? ux_1.default.stderr(args) : ux_1.default.stdout(args);
|
|
151
148
|
}
|
|
152
149
|
async showCommandHelp(command) {
|
|
153
150
|
const name = command.id;
|
package/lib/help/root.js
CHANGED
|
@@ -3,9 +3,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const
|
|
7
|
-
const theme_1 = require("../cli-ux/theme");
|
|
6
|
+
const ansis_1 = __importDefault(require("ansis"));
|
|
8
7
|
const util_1 = require("../util/util");
|
|
8
|
+
const theme_1 = require("../ux/theme");
|
|
9
9
|
const formatter_1 = require("./formatter");
|
|
10
10
|
class RootHelp extends formatter_1.HelpFormatter {
|
|
11
11
|
config;
|
|
@@ -34,7 +34,7 @@ class RootHelp extends formatter_1.HelpFormatter {
|
|
|
34
34
|
this.description(),
|
|
35
35
|
]).join('\n\n');
|
|
36
36
|
if (this.opts.stripAnsi)
|
|
37
|
-
output =
|
|
37
|
+
output = ansis_1.default.strip(output);
|
|
38
38
|
return output;
|
|
39
39
|
}
|
|
40
40
|
usage() {
|